summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases/mssql.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-08-14 21:53:32 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-08-14 21:53:32 +0000
commit087f235c33c1be4e0778231e8344a50dc4005c59 (patch)
treed47c35d1e520e43c05ec869304870c0b6c87f736 /lib/sqlalchemy/databases/mssql.py
parente58063aa91d893d76e9f34fbc3ea21818185844d (diff)
downloadsqlalchemy-087f235c33c1be4e0778231e8344a50dc4005c59.tar.gz
- merged "fasttypes" branch. this branch changes the signature
of convert_bind_param() and convert_result_value() to callable-returning bind_processor() and result_processor() methods. if no callable is returned, no pre/post processing function is called. - hooks added throughout base/sql/defaults to optimize the calling of bind param/result processors so that method call overhead is minimized. special cases added for executemany() scenarios such that unneeded "last row id" logic doesn't kick in, parameters aren't excessively traversed. - new performance tests show a combined mass-insert/mass-select test as having 68% fewer function calls than the same test run against 0.3. - general performance improvement of result set iteration is around 10-20%.
Diffstat (limited to 'lib/sqlalchemy/databases/mssql.py')
-rw-r--r--lib/sqlalchemy/databases/mssql.py180
1 files changed, 101 insertions, 79 deletions
diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py
index 9ec0fbbc3..308a38a76 100644
--- a/lib/sqlalchemy/databases/mssql.py
+++ b/lib/sqlalchemy/databases/mssql.py
@@ -47,16 +47,18 @@ from sqlalchemy.engine import default
import operator
class MSNumeric(sqltypes.Numeric):
- def convert_result_value(self, value, dialect):
- return value
-
- def convert_bind_param(self, value, dialect):
- if value is None:
- # Not sure that this exception is needed
- return value
- else:
- return str(value)
+ def result_processor(self, dialect):
+ return None
+ def bind_processor(self, dialect):
+ def process(value):
+ if value is None:
+ # Not sure that this exception is needed
+ return value
+ else:
+ return str(value)
+ return process
+
def get_col_spec(self):
if self.precision is None:
return "NUMERIC"
@@ -67,12 +69,14 @@ class MSFloat(sqltypes.Float):
def get_col_spec(self):
return "FLOAT(%(precision)s)" % {'precision': self.precision}
- def convert_bind_param(self, value, dialect):
- """By converting to string, we can use Decimal types round-trip."""
- if not value is None:
- return str(value)
- return None
-
+ def bind_processor(self, dialect):
+ def process(value):
+ """By converting to string, we can use Decimal types round-trip."""
+ if not value is None:
+ return str(value)
+ return None
+ return process
+
class MSInteger(sqltypes.Integer):
def get_col_spec(self):
return "INTEGER"
@@ -108,57 +112,71 @@ class MSTime(sqltypes.Time):
def get_col_spec(self):
return "DATETIME"
- def convert_bind_param(self, value, dialect):
- if isinstance(value, datetime.datetime):
- value = datetime.datetime.combine(self.__zero_date, value.time())
- elif isinstance(value, datetime.time):
- value = datetime.datetime.combine(self.__zero_date, value)
- return value
-
- def convert_result_value(self, value, dialect):
- if isinstance(value, datetime.datetime):
- return value.time()
- elif isinstance(value, datetime.date):
- return datetime.time(0, 0, 0)
- return value
-
-class MSDateTime_adodbapi(MSDateTime):
- def convert_result_value(self, value, dialect):
- # adodbapi will return datetimes with empty time values as datetime.date() objects.
- # Promote them back to full datetime.datetime()
- if value and not hasattr(value, 'second'):
- return datetime.datetime(value.year, value.month, value.day)
- return value
-
-class MSDateTime_pyodbc(MSDateTime):
- def convert_bind_param(self, value, dialect):
- if value and not hasattr(value, 'second'):
- return datetime.datetime(value.year, value.month, value.day)
- else:
+ def bind_processor(self, dialect):
+ def process(value):
+ if isinstance(value, datetime.datetime):
+ value = datetime.datetime.combine(self.__zero_date, value.time())
+ elif isinstance(value, datetime.time):
+ value = datetime.datetime.combine(self.__zero_date, value)
return value
-
-class MSDate_pyodbc(MSDate):
- def convert_bind_param(self, value, dialect):
- if value and not hasattr(value, 'second'):
- return datetime.datetime(value.year, value.month, value.day)
- else:
+ return process
+
+ def result_processor(self, dialect):
+ def process(value):
+ if isinstance(value, datetime.datetime):
+ return value.time()
+ elif isinstance(value, datetime.date):
+ return datetime.time(0, 0, 0)
return value
-
- def convert_result_value(self, value, dialect):
- # pyodbc returns SMALLDATETIME values as datetime.datetime(). truncate it back to datetime.date()
- if value and hasattr(value, 'second'):
- return value.date()
- else:
+ return process
+
+class MSDateTime_adodbapi(MSDateTime):
+ def result_processor(self, dialect):
+ def process(value):
+ # adodbapi will return datetimes with empty time values as datetime.date() objects.
+ # Promote them back to full datetime.datetime()
+ if value and not hasattr(value, 'second'):
+ return datetime.datetime(value.year, value.month, value.day)
return value
-
+ return process
+
+class MSDateTime_pyodbc(MSDateTime):
+ def bind_processor(self, dialect):
+ def process(value):
+ if value and not hasattr(value, 'second'):
+ return datetime.datetime(value.year, value.month, value.day)
+ else:
+ return value
+ return process
+
+class MSDate_pyodbc(MSDate):
+ def bind_processor(self, dialect):
+ def process(value):
+ if value and not hasattr(value, 'second'):
+ return datetime.datetime(value.year, value.month, value.day)
+ else:
+ return value
+ return process
+
+ def result_processor(self, dialect):
+ def process(value):
+ # pyodbc returns SMALLDATETIME values as datetime.datetime(). truncate it back to datetime.date()
+ if value and hasattr(value, 'second'):
+ return value.date()
+ else:
+ return value
+ return process
+
class MSDate_pymssql(MSDate):
- def convert_result_value(self, value, dialect):
- # pymssql will return SMALLDATETIME values as datetime.datetime(), truncate it back to datetime.date()
- if value and hasattr(value, 'second'):
- return value.date()
- else:
- return value
-
+ def result_processor(self, dialect):
+ def process(value):
+ # pymssql will return SMALLDATETIME values as datetime.datetime(), truncate it back to datetime.date()
+ if value and hasattr(value, 'second'):
+ return value.date()
+ else:
+ return value
+ return process
+
class MSText(sqltypes.TEXT):
def get_col_spec(self):
if self.dialect.text_as_varchar:
@@ -181,11 +199,11 @@ class MSNVarchar(sqltypes.Unicode):
class AdoMSNVarchar(MSNVarchar):
"""overrides bindparam/result processing to not convert any unicode strings"""
- def convert_bind_param(self, value, dialect):
- return value
+ def bind_processor(self, dialect):
+ return None
- def convert_result_value(self, value, dialect):
- return value
+ def result_processor(self, dialect):
+ return None
class MSChar(sqltypes.CHAR):
def get_col_spec(self):
@@ -203,20 +221,24 @@ class MSBoolean(sqltypes.Boolean):
def get_col_spec(self):
return "BIT"
- def convert_result_value(self, value, dialect):
- if value is None:
- return None
- return value and True or False
-
- def convert_bind_param(self, value, dialect):
- if value is True:
- return 1
- elif value is False:
- return 0
- elif value is None:
- return None
- else:
+ def result_processor(self, dialect):
+ def process(value):
+ if value is None:
+ return None
return value and True or False
+ return process
+
+ def bind_processor(self, dialect):
+ def process(value):
+ if value is True:
+ return 1
+ elif value is False:
+ return 0
+ elif value is None:
+ return None
+ else:
+ return value and True or False
+ return process
class MSTimeStamp(sqltypes.TIMESTAMP):
def get_col_spec(self):