summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases/postgres.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/postgres.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/postgres.py')
-rw-r--r--lib/sqlalchemy/databases/postgres.py68
1 files changed, 43 insertions, 25 deletions
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py
index a30832b43..e4897bba6 100644
--- a/lib/sqlalchemy/databases/postgres.py
+++ b/lib/sqlalchemy/databases/postgres.py
@@ -22,14 +22,19 @@ class PGNumeric(sqltypes.Numeric):
else:
return "NUMERIC(%(precision)s, %(length)s)" % {'precision': self.precision, 'length' : self.length}
- def convert_bind_param(self, value, dialect):
- return value
+ def bind_processor(self, dialect):
+ return None
- def convert_result_value(self, value, dialect):
- if not self.asdecimal and isinstance(value, util.decimal_type):
- return float(value)
+ def result_processor(self, dialect):
+ if self.asdecimal:
+ return None
else:
- return value
+ def process(value):
+ if isinstance(value, util.decimal_type):
+ return float(value)
+ else:
+ return value
+ return process
class PGFloat(sqltypes.Float):
def get_col_spec(self):
@@ -98,25 +103,38 @@ class PGArray(sqltypes.TypeEngine, sqltypes.Concatenable):
impl.__dict__.update(self.__dict__)
impl.item_type = self.item_type.dialect_impl(dialect)
return impl
- def convert_bind_param(self, value, dialect):
- if value is None:
- return value
- def convert_item(item):
- if isinstance(item, (list,tuple)):
- return [convert_item(child) for child in item]
- else:
- return self.item_type.convert_bind_param(item, dialect)
- return [convert_item(item) for item in value]
- def convert_result_value(self, value, dialect):
- if value is None:
- return value
- def convert_item(item):
- if isinstance(item, list):
- return [convert_item(child) for child in item]
- else:
- return self.item_type.convert_result_value(item, dialect)
- # Could specialcase when item_type.convert_result_value is the default identity func
- return [convert_item(item) for item in value]
+
+ def bind_processor(self, dialect):
+ item_proc = self.item_type.bind_processor(dialect)
+ def process(value):
+ if value is None:
+ return value
+ def convert_item(item):
+ if isinstance(item, (list,tuple)):
+ return [convert_item(child) for child in item]
+ else:
+ if item_proc:
+ return item_proc(item)
+ else:
+ return item
+ return [convert_item(item) for item in value]
+ return process
+
+ def result_processor(self, dialect):
+ item_proc = self.item_type.bind_processor(dialect)
+ def process(value):
+ if value is None:
+ return value
+ def convert_item(item):
+ if isinstance(item, list):
+ return [convert_item(child) for child in item]
+ else:
+ if item_proc:
+ return item_proc(item)
+ else:
+ return item
+ return [convert_item(item) for item in value]
+ return process
def get_col_spec(self):
return self.item_type.get_col_spec() + '[]'