Update gluon/contrib/pypyodbc.py 1.3.0 -> 1.3.3
This commit is contained in:
+35
-17
@@ -25,7 +25,7 @@ pooling = True
|
|||||||
apilevel = '2.0'
|
apilevel = '2.0'
|
||||||
paramstyle = 'qmark'
|
paramstyle = 'qmark'
|
||||||
threadsafety = 1
|
threadsafety = 1
|
||||||
version = '1.3.0'
|
version = '1.3.3'
|
||||||
lowercase=True
|
lowercase=True
|
||||||
|
|
||||||
DEBUG = 0
|
DEBUG = 0
|
||||||
@@ -89,7 +89,7 @@ SQL_ATTR_AUTOCOMMIT = SQL_AUTOCOMMIT = 102
|
|||||||
SQL_MODE_DEFAULT = SQL_MODE_READ_WRITE = 0; SQL_MODE_READ_ONLY = 1
|
SQL_MODE_DEFAULT = SQL_MODE_READ_WRITE = 0; SQL_MODE_READ_ONLY = 1
|
||||||
SQL_AUTOCOMMIT_OFF, SQL_AUTOCOMMIT_ON = 0, 1
|
SQL_AUTOCOMMIT_OFF, SQL_AUTOCOMMIT_ON = 0, 1
|
||||||
SQL_IS_UINTEGER = -5
|
SQL_IS_UINTEGER = -5
|
||||||
SQL_ATTR_LOGIN_TIMEOUT = 103; SQL_ATTR_CONNECTION_TIMEOUT = 113
|
SQL_ATTR_LOGIN_TIMEOUT = 103; SQL_ATTR_CONNECTION_TIMEOUT = 113;SQL_ATTR_QUERY_TIMEOUT = 0
|
||||||
SQL_COMMIT, SQL_ROLLBACK = 0, 1
|
SQL_COMMIT, SQL_ROLLBACK = 0, 1
|
||||||
|
|
||||||
SQL_INDEX_UNIQUE,SQL_INDEX_ALL = 0,1
|
SQL_INDEX_UNIQUE,SQL_INDEX_ALL = 0,1
|
||||||
@@ -565,19 +565,21 @@ def dttm_cvt(x):
|
|||||||
if py_v3:
|
if py_v3:
|
||||||
x = x.decode('ascii')
|
x = x.decode('ascii')
|
||||||
if x == '': return None
|
if x == '': return None
|
||||||
else: return datetime.datetime(int(x[0:4]),int(x[5:7]),int(x[8:10]),int(x[10:13]),int(x[14:16]),int(x[17:19]),int(x[20:].ljust(6,'0')))
|
x = x.ljust(26,'0')
|
||||||
|
return datetime.datetime(int(x[0:4]),int(x[5:7]),int(x[8:10]),int(x[10:13]),int(x[14:16]),int(x[17:19]),int(x[20:26]))
|
||||||
|
|
||||||
def tm_cvt(x):
|
def tm_cvt(x):
|
||||||
if py_v3:
|
if py_v3:
|
||||||
x = x.decode('ascii')
|
x = x.decode('ascii')
|
||||||
if x == '': return None
|
if x == '': return None
|
||||||
else: return datetime.time(int(x[0:2]),int(x[3:5]),int(x[6:8]),int(x[9:].ljust(6,'0')))
|
x = x.ljust(15,'0')
|
||||||
|
return datetime.time(int(x[0:2]),int(x[3:5]),int(x[6:8]),int(x[9:15]))
|
||||||
|
|
||||||
def dt_cvt(x):
|
def dt_cvt(x):
|
||||||
if py_v3:
|
if py_v3:
|
||||||
x = x.decode('ascii')
|
x = x.decode('ascii')
|
||||||
if x == '': return None
|
if x == '': return None
|
||||||
else: return datetime.date(int(x[0:4]),int(x[5:7]),int(x[8:10]))
|
else:return datetime.date(int(x[0:4]),int(x[5:7]),int(x[8:10]))
|
||||||
|
|
||||||
def Decimal_cvt(x):
|
def Decimal_cvt(x):
|
||||||
if py_v3:
|
if py_v3:
|
||||||
@@ -696,6 +698,7 @@ funcs_with_ret = [
|
|||||||
"SQLStatisticsW",
|
"SQLStatisticsW",
|
||||||
"SQLTables",
|
"SQLTables",
|
||||||
"SQLTablesW",
|
"SQLTablesW",
|
||||||
|
"SQLSetStmtAttr"
|
||||||
]
|
]
|
||||||
|
|
||||||
for func_name in funcs_with_ret:
|
for func_name in funcs_with_ret:
|
||||||
@@ -1168,9 +1171,18 @@ class Cursor:
|
|||||||
self.arraysize = 1
|
self.arraysize = 1
|
||||||
ret = ODBC_API.SQLAllocHandle(SQL_HANDLE_STMT, self.connection.dbc_h, ADDR(self.stmt_h))
|
ret = ODBC_API.SQLAllocHandle(SQL_HANDLE_STMT, self.connection.dbc_h, ADDR(self.stmt_h))
|
||||||
check_success(self, ret)
|
check_success(self, ret)
|
||||||
|
|
||||||
|
self.timeout = conx.timeout
|
||||||
|
if self.timeout != 0:
|
||||||
|
self.set_timeout(self.timeout)
|
||||||
|
|
||||||
self._PARAM_SQL_TYPE_LIST = []
|
self._PARAM_SQL_TYPE_LIST = []
|
||||||
self.closed = False
|
self.closed = False
|
||||||
|
|
||||||
|
def set_timeout(self, timeout):
|
||||||
|
self.timeout = timeout
|
||||||
|
ret = ODBC_API.SQLSetStmtAttr(self.stmt_h, SQL_ATTR_QUERY_TIMEOUT, self.timeout, 0)
|
||||||
|
check_success(self, ret)
|
||||||
|
|
||||||
def prepare(self, query_string):
|
def prepare(self, query_string):
|
||||||
"""prepare a query"""
|
"""prepare a query"""
|
||||||
@@ -2369,10 +2381,14 @@ class Cursor:
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# This class implement a odbc connection.
|
# This class implement a odbc connection.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
connection_timeout = 0
|
||||||
|
|
||||||
class Connection:
|
class Connection:
|
||||||
def __init__(self, connectString = '', autocommit = False, ansi = False, timeout = 0, unicode_results = use_unicode, readonly = False, **kargs):
|
def __init__(self, connectString = '', autocommit = False, ansi = False, timeout = 0, unicode_results = use_unicode, readonly = False, **kargs):
|
||||||
@@ -2384,6 +2400,7 @@ class Connection:
|
|||||||
self.dbc_h = ctypes.c_void_p()
|
self.dbc_h = ctypes.c_void_p()
|
||||||
self.autocommit = autocommit
|
self.autocommit = autocommit
|
||||||
self.readonly = False
|
self.readonly = False
|
||||||
|
# the query timeout value
|
||||||
self.timeout = 0
|
self.timeout = 0
|
||||||
# self._cursors = []
|
# self._cursors = []
|
||||||
for key, value in list(kargs.items()):
|
for key, value in list(kargs.items()):
|
||||||
@@ -2409,9 +2426,17 @@ class Connection:
|
|||||||
ret = ODBC_API.SQLAllocHandle(SQL_HANDLE_DBC, shared_env_h, ADDR(self.dbc_h))
|
ret = ODBC_API.SQLAllocHandle(SQL_HANDLE_DBC, shared_env_h, ADDR(self.dbc_h))
|
||||||
check_success(self, ret)
|
check_success(self, ret)
|
||||||
|
|
||||||
|
self.connection_timeout = connection_timeout
|
||||||
|
if self.connection_timeout != 0:
|
||||||
|
self.set_connection_timeout(connection_timeout)
|
||||||
|
|
||||||
|
|
||||||
self.connect(connectString, autocommit, ansi, timeout, unicode_results, readonly)
|
self.connect(connectString, autocommit, ansi, timeout, unicode_results, readonly)
|
||||||
|
|
||||||
|
def set_connection_timeout(self,connection_timeout):
|
||||||
|
self.connection_timeout = connection_timeout
|
||||||
|
ret = ODBC_API.SQLSetConnectAttr(self.dbc_h, SQL_ATTR_CONNECTION_TIMEOUT, connection_timeout, SQL_IS_UINTEGER);
|
||||||
|
check_success(self, ret)
|
||||||
|
|
||||||
def connect(self, connectString = '', autocommit = False, ansi = False, timeout = 0, unicode_results = use_unicode, readonly = False):
|
def connect(self, connectString = '', autocommit = False, ansi = False, timeout = 0, unicode_results = use_unicode, readonly = False):
|
||||||
"""Connect to odbc, using connect strings and set the connection's attributes like autocommit and timeout
|
"""Connect to odbc, using connect strings and set the connection's attributes like autocommit and timeout
|
||||||
@@ -2421,11 +2446,8 @@ class Connection:
|
|||||||
# Before we establish the connection by the connection string
|
# Before we establish the connection by the connection string
|
||||||
# Set the connection's attribute of "timeout" (Actully LOGIN_TIMEOUT)
|
# Set the connection's attribute of "timeout" (Actully LOGIN_TIMEOUT)
|
||||||
if timeout != 0:
|
if timeout != 0:
|
||||||
self.settimeout(timeout)
|
|
||||||
ret = ODBC_API.SQLSetConnectAttr(self.dbc_h, SQL_ATTR_LOGIN_TIMEOUT, timeout, SQL_IS_UINTEGER);
|
ret = ODBC_API.SQLSetConnectAttr(self.dbc_h, SQL_ATTR_LOGIN_TIMEOUT, timeout, SQL_IS_UINTEGER);
|
||||||
check_success(self, ret)
|
check_success(self, ret)
|
||||||
|
|
||||||
|
|
||||||
# Create one connection with a connect string by calling SQLDriverConnect
|
# Create one connection with a connect string by calling SQLDriverConnect
|
||||||
# and make self.dbc_h the handle of this connection
|
# and make self.dbc_h the handle of this connection
|
||||||
|
|
||||||
@@ -2474,9 +2496,9 @@ class Connection:
|
|||||||
# Set the connection's attribute of "readonly"
|
# Set the connection's attribute of "readonly"
|
||||||
#
|
#
|
||||||
self.readonly = readonly
|
self.readonly = readonly
|
||||||
|
if self.readonly == True:
|
||||||
ret = ODBC_API.SQLSetConnectAttr(self.dbc_h, SQL_ATTR_ACCESS_MODE, self.readonly and SQL_MODE_READ_ONLY or SQL_MODE_READ_WRITE, SQL_IS_UINTEGER)
|
ret = ODBC_API.SQLSetConnectAttr(self.dbc_h, SQL_ATTR_ACCESS_MODE, SQL_MODE_READ_ONLY, SQL_IS_UINTEGER)
|
||||||
check_success(self, ret)
|
check_success(self, ret)
|
||||||
|
|
||||||
self.unicode_results = unicode_results
|
self.unicode_results = unicode_results
|
||||||
self.connected = 1
|
self.connected = 1
|
||||||
@@ -2491,10 +2513,6 @@ class Connection:
|
|||||||
def add_output_converter(self, sqltype, func):
|
def add_output_converter(self, sqltype, func):
|
||||||
self.output_converter[sqltype] = func
|
self.output_converter[sqltype] = func
|
||||||
|
|
||||||
def settimeout(self, timeout):
|
|
||||||
ret = ODBC_API.SQLSetConnectAttr(self.dbc_h, SQL_ATTR_CONNECTION_TIMEOUT, timeout, SQL_IS_UINTEGER);
|
|
||||||
check_success(self, ret)
|
|
||||||
self.timeout = timeout
|
|
||||||
|
|
||||||
|
|
||||||
def ConnectByDSN(self, dsn, user, passwd = ''):
|
def ConnectByDSN(self, dsn, user, passwd = ''):
|
||||||
|
|||||||
Reference in New Issue
Block a user