Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2101/win32/src
Modified Files:
odbc.cpp
Log Message:
Add SQLDataSources and related constants, remove 'printf' on error.
Index: odbc.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/odbc.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** odbc.cpp 27 Feb 2006 12:00:57 -0000 1.15
--- odbc.cpp 15 Mar 2006 04:01:35 -0000 1.16
***************
*** 192,196 ****
if (conn && errorType && (errorType->connected == 0))
{
! printf("Disconnected\n");
SQLDisconnect(conn->hdbc);
conn->connected = 0;
--- 192,196 ----
if (conn && errorType && (errorType->connected == 0))
{
! // printf("Disconnected\n");
SQLDisconnect(conn->hdbc);
conn->connected = 0;
***************
*** 1779,1788 ****
--- 1779,1837 ----
}
+ /* @pymethod (name, desc)/None|odbc|SQLDataSources|Enumerates ODBC data sources */
+ // @rdesc The result is None when SQL_NO_DATA is returned from ODBC.
+ static PyObject *odbcSQLDataSources(PyObject *self, PyObject *args)
+ {
+ int direction;
+ // @pyparm int|direction||
+ if (!PyArg_ParseTuple(args, "i:SQLDataSources", &direction))
+ return NULL;
+
+ PyObject *ret;
+ SQLCHAR svr[256];
+ SQLCHAR desc[1024];
+ SQLSMALLINT svr_size = sizeof(svr) / sizeof(svr[0]);
+ SQLSMALLINT desc_size = sizeof(desc) / sizeof(desc[0]);
+ RETCODE rc;
+ Py_BEGIN_ALLOW_THREADS
+ rc = SQLDataSources(Env, direction,
+ svr, svr_size, &svr_size,
+ desc, desc_size, &desc_size);
+ Py_END_ALLOW_THREADS
+
+ if (rc == SQL_NO_DATA) {
+ ret = Py_None;
+ Py_INCREF(Py_None);
+ } else if (unsuccessful(rc)){
+ connectionError(NULL, "SQLDataSources");
+ ret = NULL;
+ } else
+ ret = Py_BuildValue("s#s#", svr, svr_size, desc, desc_size);
+ return ret;
+ }
+
/* @module odbc|A Python wrapper around the ODBC API. */
static PyMethodDef globalMethods[] = {
{ "odbc", odbcLogon, 1} , /* @pymeth odbc|Creates an <o connection> object. */
+ { "SQLDataSources", odbcSQLDataSources, 1}, /* @pymeth SQLDataSources|Enumerates ODBC data sources. */
{0, 0}
};
+ int AddConstant(PyObject *dict, char *key, long value)
+ {
+ PyObject *okey = PyString_FromString(key);
+ PyObject *oval = PyInt_FromLong(value);
+ if (!okey || !oval) {
+ Py_XDECREF(okey);
+ Py_XDECREF(oval);
+ return 1;
+ }
+ int rc = PyDict_SetItem(dict,okey, oval);
+ Py_XDECREF(okey);
+ Py_XDECREF(oval);
+ return rc;
+ }
+ #define ADD_CONSTANT(tok) AddConstant(dict,#tok, tok)
+
extern "C" __declspec(dllexport) void initodbc()
***************
*** 1801,1804 ****
--- 1850,1854 ----
if (m)
{
+ PyObject *dict = PyModule_GetDict (m);
/* The indices go to indices in the ODBC error table */
dbiErrors[0] = DbiNoError;
***************
*** 1808,1812 ****
dbiErrors[4] = DbiDataError;
dbiErrors[5] = DbiInternalError;
! PyDict_SetItemString(PyModule_GetDict (m), "error", odbcError);
}
}
--- 1858,1870 ----
dbiErrors[4] = DbiDataError;
dbiErrors[5] = DbiInternalError;
! PyDict_SetItemString(dict, "error", odbcError);
! ADD_CONSTANT(SQL_FETCH_NEXT);
! ADD_CONSTANT(SQL_FETCH_FIRST);
! ADD_CONSTANT(SQL_FETCH_LAST);
! ADD_CONSTANT(SQL_FETCH_PRIOR);
! ADD_CONSTANT(SQL_FETCH_ABSOLUTE);
! ADD_CONSTANT(SQL_FETCH_RELATIVE);
! ADD_CONSTANT(SQL_FETCH_FIRST_USER);
! ADD_CONSTANT(SQL_FETCH_FIRST_SYSTEM);
}
}
|