/* static void _python_ibm_db_check_sql_errors( SQLHANDLE handle, SQLSMALLINT hType, int rc, int cpy_to_global, char* ret_str, int API SQLSMALLINT recno)
*/
static void _python_ibm_db_check_sql_errors( SQLHANDLE handle, SQLSMALLINT hType, int rc, int cpy_to_global, char* ret_str, int API, SQLSMALLINT recno )
{
SQLCHAR msg[SQL_MAX_MESSAGE_LENGTH + 1];
SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1];
SQLCHAR errMsg[DB2_MAX_ERR_MSG_LEN];
SQLINTEGER sqlcode;
SQLSMALLINT length;
char *p;
memset(errMsg, '\0', DB2_MAX_ERR_MSG_LEN);
memset(msg, '\0', SQL_MAX_MESSAGE_LENGTH + 1);
if ( SQLGetDiagRec(hType, handle, recno, sqlstate, &sqlcode, msg,
* Creates a database by using the specified database name, code set, and mode
*
* ===Parameters
*
* ====connection
* A valid database server instance connection resource variable as returned from ibm_db.connect() by specifying the ATTACH keyword.
*
* ====dbName
* Name of the database that is to be created.
*
* ====codeSet
* Database code set information.
* Note: If the value of the codeSet argument not specified, the database is created in the Unicode code page for DB2 data servers and in the UTF-8 code page for IDS data servers.
*
* ====mode
* Database logging mode.
* Note: This value is applicable only to IDS data servers.
*
* ===Return Value
* Returns True on successful creation of database else return None
* Drop and then recreates a database by using the specified database name, code set, and mode
*
* ===Parameters
*
* ====connection
* A valid database server instance connection resource variable as returned from ibm_db.connect() by specifying the ATTACH keyword.
*
* ====dbName
* Name of the database that is to be created.
*
* ====codeSet
* Database code set information.
* Note: If the value of the codeSet argument not specified, the database is created in the Unicode code page for DB2 data servers and in the UTF-8 code page for IDS data servers.
*
* ====mode
* Database logging mode.
* Note: This value is applicable only to IDS data servers.
*
* ===Return Value
* Returns True if specified database created successfully else return None
* Creates the database if not exist by using the specified database name, code set, and mode
*
* ===Parameters
*
* ====connection
* A valid database server instance connection resource variable as returned from ibm_db.connect() by specifying the ATTACH keyword.
*
* ====dbName
* Name of the database that is to be created.
*
* ====codeSet
* Database code set information.
* Note: If the value of the codeSet argument not specified, the database is created in the Unicode code page for DB2 data servers and in the UTF-8 code page for IDS data servers.
*
* ====mode
* Database logging mode.
* Note: This value is applicable only to IDS data servers.
*
* ===Return Value
* Returns True if database already exists or created sucessfully else return None
* long data_type, long precision, long scale, long size)
*/
static PyObject *_python_ibm_db_bind_param_helper(int argc, stmt_handle *stmt_res, SQLUSMALLINT param_no, PyObject *var_pyvalue, long param_type, long data_type, long precision, long scale, long size)
{
SQLSMALLINT sql_data_type = 0;
SQLUINTEGER sql_precision = 0;
SQLSMALLINT sql_scale = 0;
SQLSMALLINT sql_nullable = SQL_NO_NULLS;
char error[DB2_MAX_ERR_MSG_LEN];
int rc = 0;
/* Check for Param options */
switch (argc) {
/* if argc == 3, then the default value for param_type will be used */
* If you plan to interpolate Python variables into the SQL statement,
* understand that this is one of the more common security exposures. Consider
* calling ibm_db.prepare() to prepare an SQL statement with parameter markers * for input values. Then you can call ibm_db.execute() to pass in the input
* values and avoid SQL injection attacks.
*
* If you plan to repeatedly issue the same SQL statement with different
* parameters, consider calling ibm_db.:prepare() and ibm_db.execute() to
* enable the database server to reuse its access plan and increase the
* efficiency of your database access.
*
* ===Parameters
*
* ====connection
*
* A valid database connection resource variable as returned from
* ibm_db.connect() or ibm_db.pconnect().
*
* ====statement
*
* An SQL statement. The statement cannot contain any parameter markers.
*
* ====options
*
* An dictionary containing statement options. You can use this parameter * to request a scrollable cursor on database servers that support this
* functionality.
*
* SQL_ATTR_CURSOR_TYPE
* Passing the SQL_SCROLL_FORWARD_ONLY value requests a forward-only
* cursor for this SQL statement. This is the default type of
* cursor, and it is supported by all database servers. It is also
* much faster than a scrollable cursor.
*
* Passing the SQL_CURSOR_KEYSET_DRIVEN value requests a scrollable * cursor for this SQL statement. This type of cursor enables you to
* fetch rows non-sequentially from the database server. However, it
* is only supported by DB2 servers, and is much slower than
* forward-only cursors.
*
* ===Return Values
*
* Returns a stmt_handle resource if the SQL statement was issued
* successfully, or FALSE if the database failed to execute the SQL statement.
* dictionary ibm_db.fetch_both ( resource stmt [, int row_number] )
*
* Returns a dictionary, indexed by both column name and position, representing * a row in a result set. Note that the row returned by ibm_db.fetch_both()
* requires more memory than the single-indexed dictionaries/arrays returned by * ibm_db.fetch_assoc() or ibm_db.fetch_tuple().
*
* ===Parameters
*
* ====stmt
* A valid stmt resource containing a result set.
*
* ====row_number
* Requests a specific 1-indexed row from the result set. Passing this
* parameter results in a warning if the result set uses a forward-only cursor.
*
* ===Return Values
*
* Returns a dictionary with column values indexed by both the column name and
* 0-indexed column number.
* The dictionary represents the next or requested row in the result set.
* Returns FALSE if there are no rows left in the result set, or if the row
* requested by row_number does not exist in the result set.
PyErr_SetString(PyExc_Exception, "Supplied statement handle is invalid");
return Py_False;
}
}
*/
static int _python_get_variable_type(PyObject *variable_value)
{
if (PyBool_Check(variable_value) && (variable_value == Py_True)){
return PYTHON_TRUE;
}
else if (PyBool_Check(variable_value) && (variable_value == Py_False)){
return PYTHON_FALSE;
}
else if (PyInt_Check(variable_value) || PyLong_Check(variable_value)){
return PYTHON_FIXNUM;
}
else if (PyFloat_Check(variable_value)){
return PYTHON_FLOAT;
}
else if (PyString_Check(variable_value)){
return PYTHON_STRING;
}
else if (PyUnicode_Check(variable_value)){
return PYTHON_UNICODE;
}
else if (PyComplex_Check(variable_value)){
return PYTHON_COMPLEX;
}
else if (PyNumber_Check(variable_value)){
return PYTHON_DECIMAL;
}
else if (variable_value == Py_None){
return PYTHON_NIL;
}
else return 0;
}
/* Listing of ibm_db module functions: */
static PyMethodDef ibm_db_Methods[] = {
/* name, function, argument type, docstring */
{"connect", (PyCFunction)ibm_db_connect, METH_VARARGS | METH_KEYWORDS, "Connect to the database"},
{"pconnect", (PyCFunction)ibm_db_pconnect, METH_VARARGS | METH_KEYWORDS, "Returns a persistent connection to a database"},
{"exec_immediate", (PyCFunction)ibm_db_exec, METH_VARARGS, "Prepares and executes an SQL statement."},
{"prepare", (PyCFunction)ibm_db_prepare, METH_VARARGS, "Prepares an SQL statement."},
{"bind_param", (PyCFunction)ibm_db_bind_param, METH_VARARGS, "Binds a Python variable to an SQL statement parameter"},
{"execute", (PyCFunction)ibm_db_execute, METH_VARARGS, "Executes an SQL statement that was prepared by ibm_db.prepare()"},
{"fetch_tuple", (PyCFunction)ibm_db_fetch_array, METH_VARARGS, "Returns an tuple, indexed by column position, representing a row in a result set"},
{"fetch_assoc", (PyCFunction)ibm_db_fetch_assoc, METH_VARARGS, "Returns a dictionary, indexed by column name, representing a row in a result set"},
{"fetch_both", (PyCFunction)ibm_db_fetch_both, METH_VARARGS, "Returns a dictionary, indexed by both column name and position, representing a row in a result set"},
{"fetch_row", (PyCFunction)ibm_db_fetch_row, METH_VARARGS, "Sets the result set pointer to the next row or requested row"},
{"result", (PyCFunction)ibm_db_result, METH_VARARGS, "Returns a single column from a row in the result set"},
{"active", (PyCFunction)ibm_db_active, METH_VARARGS, "Checks if the specified connection resource is active"},
{"autocommit", (PyCFunction)ibm_db_autocommit, METH_VARARGS, "Returns or sets the AUTOCOMMIT state for a database connection"},
{"callproc", (PyCFunction)ibm_db_callproc, METH_VARARGS, "Returns a tuple containing OUT/INOUT variable value"},
{"check_function_support", (PyCFunction)ibm_db_check_function_support, METH_VARARGS, "return true if fuction is supported otherwise return false"},
{"close", (PyCFunction)ibm_db_close, METH_VARARGS, "Close a database connection"},
{"conn_error", (PyCFunction)ibm_db_conn_error, METH_VARARGS, "Returns a string containing the SQLSTATE returned by the last connection attempt"},
{"conn_errormsg", (PyCFunction)ibm_db_conn_errormsg, METH_VARARGS, "Returns an error message and SQLCODE value representing the reason the last database connection attempt failed"},
{"client_info", (PyCFunction)ibm_db_client_info, METH_VARARGS, "Returns a read-only object with information about the DB2 database client"},
{"column_privileges", (PyCFunction)ibm_db_column_privileges, METH_VARARGS, "Returns a result set listing the columns and associated privileges for a table."},
{"columns", (PyCFunction)ibm_db_columns, METH_VARARGS, "Returns a result set listing the columns and associated metadata for a table"},
{"commit", (PyCFunction)ibm_db_commit, METH_VARARGS, "Commits a transaction"},
{"execute_many", (PyCFunction)ibm_db_execute_many, METH_VARARGS, "Execute SQL with multiple rows."},
{"field_display_size", (PyCFunction)ibm_db_field_display_size, METH_VARARGS, "Returns the maximum number of bytes required to display a column"},
{"field_name", (PyCFunction)ibm_db_field_name, METH_VARARGS, "Returns the name of the column in the result set"},
{"field_num", (PyCFunction)ibm_db_field_num, METH_VARARGS, "Returns the position of the named column in a result set"},
{"field_precision", (PyCFunction)ibm_db_field_precision, METH_VARARGS, "Returns the precision of the indicated column in a result set"},
{"field_scale", (PyCFunction)ibm_db_field_scale , METH_VARARGS, "Returns the scale of the indicated column in a result set"},
{"field_type", (PyCFunction)ibm_db_field_type, METH_VARARGS, "Returns the data type of the indicated column in a result set"},
{"field_width", (PyCFunction)ibm_db_field_width, METH_VARARGS, "Returns the width of the indicated column in a result set"},
{"foreign_keys", (PyCFunction)ibm_db_foreign_keys, METH_VARARGS, "Returns a result set listing the foreign keys for a table"},
{"free_result", (PyCFunction)ibm_db_free_result, METH_VARARGS, "Frees resources associated with a result set"},
{"free_stmt", (PyCFunction)ibm_db_free_stmt, METH_VARARGS, "Frees resources associated with the indicated statement resource"},
{"get_option", (PyCFunction)ibm_db_get_option, METH_VARARGS, "Gets the specified option in the resource."},
{"next_result", (PyCFunction)ibm_db_next_result, METH_VARARGS, "Requests the next result set from a stored procedure"},
{"num_fields", (PyCFunction)ibm_db_num_fields, METH_VARARGS, "Returns the number of fields contained in a result set"},
{"num_rows", (PyCFunction)ibm_db_num_rows, METH_VARARGS, "Returns the number of rows affected by an SQL statement"},
{"get_num_result", (PyCFunction)ibm_db_get_num_result, METH_VARARGS, "Returns the number of rows in a current open non-dynamic scrollable cursor"},
{"primary_keys", (PyCFunction)ibm_db_primary_keys, METH_VARARGS, "Returns a result set listing primary keys for a table"},
{"procedure_columns", (PyCFunction)ibm_db_procedure_columns, METH_VARARGS, "Returns a result set listing the parameters for one or more stored procedures."},
{"procedures", (PyCFunction)ibm_db_procedures, METH_VARARGS, "Returns a result set listing the stored procedures registered in a database"},
{"rollback", (PyCFunction)ibm_db_rollback, METH_VARARGS, "Rolls back a transaction"},
{"server_info", (PyCFunction)ibm_db_server_info, METH_VARARGS, "Returns an object with properties that describe the DB2 database server"},
{"get_db_info", (PyCFunction)ibm_db_get_db_info, METH_VARARGS, "Returns an object with properties that describe the DB2 database server according to the option passed"},
{"set_option", (PyCFunction)ibm_db_set_option, METH_VARARGS, "Sets the specified option in the resource"},
{"special_columns", (PyCFunction)ibm_db_special_columns, METH_VARARGS, "Returns a result set listing the unique row identifier columns for a table"},
{"statistics", (PyCFunction)ibm_db_statistics, METH_VARARGS, "Returns a result set listing the index and statistics for a table"},
{"stmt_error", (PyCFunction)ibm_db_stmt_error, METH_VARARGS, "Returns a string containing the SQLSTATE returned by an SQL statement"},
{"stmt_errormsg", (PyCFunction)ibm_db_stmt_errormsg, METH_VARARGS, "Returns a string containing the last SQL statement error message"},
{"table_privileges", (PyCFunction)ibm_db_table_privileges, METH_VARARGS, "Returns a result set listing the tables and associated privileges in a database"},
{"tables", (PyCFunction)ibm_db_tables, METH_VARARGS, "Returns a result set listing the tables and associated metadata in a database"},
/* An end-of-listing sentinel: */
{NULL, NULL, 0, NULL}
};
#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */