My favorites
▼
|
Sign in
pyodbc
Python ODBC library
Project Home
Downloads
Wiki
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
36
attachment: unicode_strings.diff
(4.9 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
diff -u -r pyodbc-2.1.4.orig/src/connection.cpp pyodbc-2.1.4/src/connection.cpp
--- pyodbc-2.1.4.orig/src/connection.cpp 2008-12-30 16:44:38.000000000 +0200
+++ pyodbc-2.1.4/src/connection.cpp 2009-02-18 19:38:51.000000000 +0200
@@ -136,13 +136,16 @@
}
-PyObject* Connection_New(PyObject* pConnectString, bool fAutoCommit, bool fAnsi)
+PyObject* Connection_New(PyObject* pConnectString, bool fAutoCommit, bool fAnsi, bool fUnicodeStrings)
{
// pConnectString
// A string or unicode object. (This must be checked by the caller.)
//
// fAnsi
// If true, do not attempt a Unicode connection.
+ //
+ // fUnicodeStrings
+ // If true, return strings in rows as unicode objects.
//
// Allocate HDBC and connect
@@ -181,9 +184,10 @@
return 0;
}
- cnxn->hdbc = hdbc;
- cnxn->nAutoCommit = fAutoCommit ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF;
- cnxn->searchescape = 0;
+ cnxn->hdbc = hdbc;
+ cnxn->nAutoCommit = fAutoCommit ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF;
+ cnxn->searchescape = 0;
+ cnxn->unicode_strings = fUnicodeStrings;
//
// Initialize autocommit mode.
diff -u -r pyodbc-2.1.4.orig/src/connection.h pyodbc-2.1.4/src/connection.h
--- pyodbc-2.1.4.orig/src/connection.h 2008-12-06 10:34:24.000000000 +0200
+++ pyodbc-2.1.4/src/connection.h 2009-02-18 19:31:16.000000000 +0200
@@ -39,6 +39,9 @@
// The column size of datetime columns, obtained from SQLGetInfo(), used to determine the datetime precision.
int datetime_precision;
+
+ // If true, then the strings in the rows are returned as unicode objects.
+ bool unicode_strings;
};
#define Connection_Check(op) PyObject_TypeCheck(op, &ConnectionType)
@@ -48,6 +51,6 @@
* 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);
+PyObject* Connection_New(PyObject* pConnectString, bool fAutoCommit, bool fAnsi, bool fUnicodeStrings);
#endif
diff -u -r pyodbc-2.1.4.orig/src/cursor.cpp pyodbc-2.1.4/src/cursor.cpp
--- pyodbc-2.1.4.orig/src/cursor.cpp 2008-12-30 23:45:22.000000000 +0200
+++ pyodbc-2.1.4/src/cursor.cpp 2009-02-18 19:30:08.000000000 +0200
@@ -127,7 +127,7 @@
PyObject*
-PythonTypeFromSqlType(const SQLCHAR* name, SQLSMALLINT type)
+PythonTypeFromSqlType(const SQLCHAR* name, SQLSMALLINT type, bool unicode_strings)
{
// Returns a type object ('int', 'str', etc.) for the given ODBC C type. This is used to populate
// Cursor.description with the type of Python object that will be returned for each column.
@@ -148,7 +148,10 @@
case SQL_VARCHAR:
case SQL_LONGVARCHAR:
case SQL_GUID:
- pytype = (PyObject*)&PyString_Type;
+ if (unicode_strings)
+ pytype = (PyObject*)&PyUnicode_Type;
+ else
+ pytype = (PyObject*)&PyString_Type;
break;
case SQL_DECIMAL:
@@ -268,7 +271,7 @@
if (lower)
_strlwr((char*)name);
- type = PythonTypeFromSqlType(name, nDataType);
+ type = PythonTypeFromSqlType(name, nDataType, cur->cnxn->unicode_strings);
if (!type)
goto done;
diff -u -r pyodbc-2.1.4.orig/src/getdata.cpp pyodbc-2.1.4/src/getdata.cpp
--- pyodbc-2.1.4.orig/src/getdata.cpp 2008-12-30 16:44:38.000000000 +0200
+++ pyodbc-2.1.4/src/getdata.cpp 2009-02-18 19:41:36.000000000 +0200
@@ -252,7 +252,10 @@
case SQL_VARCHAR:
case SQL_LONGVARCHAR:
case SQL_GUID:
- nTargetType = SQL_C_CHAR;
+ if (cur->cnxn->unicode_strings)
+ nTargetType = SQL_C_WCHAR;
+ else
+ nTargetType = SQL_C_CHAR;
break;
case SQL_WCHAR:
diff -u -r pyodbc-2.1.4.orig/src/pyodbcmodule.cpp pyodbc-2.1.4/src/pyodbcmodule.cpp
--- pyodbc-2.1.4.orig/src/pyodbcmodule.cpp 2008-12-31 14:28:44.000000000 +0200
+++ pyodbc-2.1.4/src/pyodbcmodule.cpp 2009-02-18 19:39:08.000000000 +0200
@@ -274,6 +274,7 @@
Object pConnectString = 0;
int fAutoCommit = 0;
int fAnsi = 0; // force ansi
+ int fUnicodeStrings = 0;
int size = args ? PyTuple_Size(args) : 0;
@@ -323,6 +324,11 @@
fAnsi = PyObject_IsTrue(value);
continue;
}
+ if (_strcmpi(szKey, "unicode_strings") == 0)
+ {
+ fUnicodeStrings = PyObject_IsTrue(value);
+ continue;
+ }
// Anything else must be a string that is appended, along with the keyword to the connection string.
@@ -373,7 +379,7 @@
return 0;
}
- return (PyObject*)Connection_New(pConnectString.Get(), fAutoCommit != 0, fAnsi != 0);
+ return (PyObject*)Connection_New(pConnectString.Get(), fAutoCommit != 0, fAnsi != 0, fUnicodeStrings != 0);
}
Powered by
Google Project Hosting