-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This directory contains HTML files that document how to use the APIs found in the <b>ibm_db</b> library. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,258 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"deletable": false, | ||
"editable": false | ||
}, | ||
"source": [ | ||
"# ibm_db.active()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"deletable": false, | ||
"editable": false | ||
}, | ||
"source": [ | ||
"## Purpose:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"deletable": false, | ||
"editable": false | ||
}, | ||
"source": [ | ||
"Determine whether the Db2 server or database connection specified is active." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"deletable": false, | ||
"editable": false | ||
}, | ||
"source": [ | ||
"## Syntax:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"deletable": false, | ||
"editable": false | ||
}, | ||
"source": [ | ||
"`bool ibm_db.active( IBM_DBConnection `*`connection`*` )`" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"deletable": false, | ||
"editable": false | ||
}, | ||
"source": [ | ||
"## Parameters:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"deletable": false, | ||
"editable": false | ||
}, | ||
"source": [ | ||
"* __*connection*__ : A valid Db2 server or database connection." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"deletable": false, | ||
"editable": false | ||
}, | ||
"source": [ | ||
"## Return values:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"deletable": false, | ||
"editable": false | ||
}, | ||
"source": [ | ||
"* `True` : The Db2 server or database connection specified is active. \n", | ||
"* `False` : The Db2 server or database connection specified is not active." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"deletable": false, | ||
"editable": false | ||
}, | ||
"source": [ | ||
"## Description:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"deletable": false, | ||
"editable": false | ||
}, | ||
"source": [ | ||
"The __ibm_db.active()__ API is used to determine if a Db2 server or database connection that was established using the __ibm_db.connect()__ API or __ibm_db.pconnect()__ is active.<p>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"deletable": false, | ||
"editable": false | ||
}, | ||
"source": [ | ||
"## Example:\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"deletable": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\n", | ||
"Connecting to the SAMPLE database ... Done!\n", | ||
"\n", | ||
"The connection to the SAMPLE database is ACTIVE.\n", | ||
"\n", | ||
"Disconnecting from the SAMPLE database ... Done!\n", | ||
"\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"#----------------------------------------------------------------------------------------------#\n", | ||
"# NAME: ibm_db-active.py #\n", | ||
"# #\n", | ||
"# PURPOSE: This program is designed to illustrate how to use the ibm_db.active() API. #\n", | ||
"# #\n", | ||
"#----------------------------------------------------------------------------------------------#\n", | ||
"# DISCLAIMER OF WARRANTIES AND LIMITATION OF LIABILITY #\n", | ||
"# #\n", | ||
"# (C) COPYRIGHT International Business Machines Corp. 2018, 2019 All Rights Reserved #\n", | ||
"# Licensed Materials - Property of IBM #\n", | ||
"# #\n", | ||
"# US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA #\n", | ||
"# ADP Schedule Contract with IBM Corp. #\n", | ||
"# #\n", | ||
"# The following source code (\"Sample\") is owned by International Business Machines #\n", | ||
"# Corporation (\"IBM\") or one of its subsidiaries and is copyrighted and licensed, not sold. #\n", | ||
"# You may use, copy, modify, and distribute the Sample in any form without payment to IBM, #\n", | ||
"# for the purpose of assisting you in the creation of Python applications using the ibm_db #\n", | ||
"# library. #\n", | ||
"# #\n", | ||
"# The Sample code is provided to you on an \"AS IS\" basis, without warranty of any kind. IBM #\n", | ||
"# HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT #\n", | ||
"# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. #\n", | ||
"# Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so #\n", | ||
"# the above limitations or exclusions may not apply to you. IBM shall not be liable for any #\n", | ||
"# damages you suffer as a result of using, copying, modifying or distributing the Sample, #\n", | ||
"# even if IBM has been advised of the possibility of such damages. #\n", | ||
"#----------------------------------------------------------------------------------------------#\n", | ||
"\n", | ||
"# Load The Appropriate Python Modules\n", | ||
"import sys # Provides Information About Python Interpreter Constants And Functions\n", | ||
"import ibm_db # Contains The APIs Needed To Work With Db2 Databases\n", | ||
"\n", | ||
"#----------------------------------------------------------------------------------------------#\n", | ||
"# Import The Db2ConnectionMgr Class Definition, Attributes, And Methods That Have Been Defined #\n", | ||
"# In The File Named \"ibm_db_tools.py\"; This Class Contains The Programming Logic Needed To #\n", | ||
"# Establish And Terminate A Connection To A Db2 Server Or Database #\n", | ||
"#----------------------------------------------------------------------------------------------#\n", | ||
"from ibm_db_tools import Db2ConnectionMgr\n", | ||
"\n", | ||
"#----------------------------------------------------------------------------------------------#\n", | ||
"# Import The ipynb_exit Class Definition, Attributes, And Methods That Have Been Defined In #\n", | ||
"# The File Named \"ipynb_exit.py\"; This Class Contains The Programming Logic Needed To Allow #\n", | ||
"# \"exit()\" Functionality To Work Without Raising An Error Or Stopping The Kernel If The #\n", | ||
"# Application Is Invoked In A Jupyter Notebook #\n", | ||
"#----------------------------------------------------------------------------------------------#\n", | ||
"from ipynb_exit import exit\n", | ||
"\n", | ||
"# Define And Initialize The Appropriate Variables\n", | ||
"dbName = \"SAMPLE\"\n", | ||
"userID = \"db2inst1\"\n", | ||
"passWord = \"Passw0rd\"\n", | ||
"dbConnection = None\n", | ||
"\n", | ||
"# Create An Instance Of The Db2ConnectionMgr Class And Use It To Connect To A Db2 Database\n", | ||
"conn = Db2ConnectionMgr('DB', dbName, '', '', userID, passWord)\n", | ||
"conn.openConnection()\n", | ||
"if conn.returnCode is True:\n", | ||
" dbConnection = conn.connectionID\n", | ||
"else:\n", | ||
" conn.closeConnection()\n", | ||
" exit(-1)\n", | ||
"\n", | ||
"# Determine Whether The Current Database Connection Is Active Or Inactive\n", | ||
"try:\n", | ||
" connState = ibm_db.active(dbConnection)\n", | ||
"except Exception:\n", | ||
" pass\n", | ||
"\n", | ||
"# Display A Status Message That Shows The Current Connection State\n", | ||
"print(\"The connection to the \" + dbName + \" database is \", end=\"\")\n", | ||
"if connState is True:\n", | ||
" print(\"ACTIVE.\\n\")\n", | ||
"elif connState is False:\n", | ||
" print(\"NOT ACTIVE.\\n\")\n", | ||
"\n", | ||
"# Close The Database Connection That Was Opened Earlier\n", | ||
"conn.closeConnection()\n", | ||
"\n", | ||
"# Return Control To The Operating System\n", | ||
"exit()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.1" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |