Permalink
Browse files

Added readonly keyword to connect.

  • Loading branch information...
1 parent dc35242 commit 7555f7da7d11b1dbe98895a8ce88df20d20a1006 @mkleehammer committed Feb 14, 2012
Showing with 25 additions and 4 deletions.
  1. +16 −1 src/connection.cpp
  2. +1 −1 src/connection.h
  3. +8 −2 src/pyodbcmodule.cpp
View
@@ -140,7 +140,7 @@ static bool Connect(PyObject* pConnectString, HDBC hdbc, bool fAnsi, long timeou
}
-PyObject* Connection_New(PyObject* pConnectString, bool fAutoCommit, bool fAnsi, bool fUnicodeResults, long timeout)
+PyObject* Connection_New(PyObject* pConnectString, bool fAutoCommit, bool fAnsi, bool fUnicodeResults, long timeout, bool fReadOnly)
{
// pConnectString
// A string or unicode object. (This must be checked by the caller.)
@@ -226,6 +226,21 @@ PyObject* Connection_New(PyObject* pConnectString, bool fAutoCommit, bool fAnsi,
}
}
+ if (fReadOnly)
+ {
+ SQLRETURN ret;
+ Py_BEGIN_ALLOW_THREADS
+ ret = SQLSetConnectAttr(cnxn->hdbc, SQL_ATTR_ACCESS_MODE, (SQLPOINTER)SQL_MODE_READ_ONLY, 0);
+ Py_END_ALLOW_THREADS
+
+ if (!SQL_SUCCEEDED(ret))
+ {
+ RaiseErrorFromHandle("SQLSetConnnectAttr(SQL_ATTR_ACCESS_MODE)", cnxn->hdbc, SQL_NULL_HANDLE);
+ Py_DECREF(cnxn);
+ return 0;
+ }
+ }
+
TRACE("cnxn.new cnxn=%p hdbc=%d\n", cnxn, cnxn->hdbc);
//
View
@@ -71,6 +71,6 @@ struct Connection
* Used by the module's connect function to create new connection objects. If unable to connect to the database, an
* exception is set and zero is returned.
*/
-PyObject* Connection_New(PyObject* pConnectString, bool fAutoCommit, bool fAnsi, bool fUnicodeResults, long timeout);
+PyObject* Connection_New(PyObject* pConnectString, bool fAutoCommit, bool fAnsi, bool fUnicodeResults, long timeout, bool fReadOnly);
#endif
View
@@ -252,6 +252,7 @@ static PyObject* mod_connect(PyObject* self, PyObject* args, PyObject* kwargs)
int fAutoCommit = 0;
int fAnsi = 0; // force ansi
int fUnicodeResults = 0;
+ int fReadOnly = 0;
long timeout = 0;
Py_ssize_t size = args ? PyTuple_Size(args) : 0;
@@ -317,7 +318,12 @@ static PyObject* mod_connect(PyObject* self, PyObject* args, PyObject* kwargs)
return 0;
continue;
}
-
+ if (Text_EqualsI(key, "readonly"))
+ {
+ fReadOnly = PyObject_IsTrue(value);
+ continue;
+ }
+
// Map DB API recommended names to ODBC names (e.g. user --> uid).
for (size_t i = 0; i < _countof(keywordmaps); i++)
@@ -362,7 +368,7 @@ static PyObject* mod_connect(PyObject* self, PyObject* args, PyObject* kwargs)
return 0;
}
- return (PyObject*)Connection_New(pConnectString.Get(), fAutoCommit != 0, fAnsi != 0, fUnicodeResults != 0, timeout);
+ return (PyObject*)Connection_New(pConnectString.Get(), fAutoCommit != 0, fAnsi != 0, fUnicodeResults != 0, timeout, fReadOnly != 0);
}

0 comments on commit 7555f7d

Please sign in to comment.