Changeset 65
- Timestamp:
- 04/09/07 18:06:49
- Files:
-
- trunk/geniusql/adapters.py (modified) (2 diffs)
- trunk/geniusql/dbtypes.py (modified) (5 diffs)
- trunk/geniusql/decompile.py (modified) (6 diffs)
- trunk/geniusql/objects.py (modified) (5 diffs)
- trunk/geniusql/providers/ado.py (modified) (2 diffs)
- trunk/geniusql/providers/msaccess.py (modified) (4 diffs)
- trunk/geniusql/providers/postgres.py (modified) (6 diffs)
- trunk/geniusql/providers/sqlserver.py (modified) (4 diffs)
- trunk/geniusql/select.py (modified) (2 diffs)
- trunk/geniusql/test/test_msaccess.py (modified) (1 diff)
- trunk/geniusql/test/zoo_fixture.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/geniusql/adapters.py
r64 r65 36 36 import pickle 37 37 38 try: 39 set 40 except NameError: 41 from sets import Set as set 38 from geniusql import typerefs 39 42 40 43 41 import sys … … 57 55 del L, sys 58 56 59 import warnings60 61 from geniusql import errors, typerefs62 63 64 # ----------------------------- Adapter Sets ----------------------------- #65 66 67 def getCoerceName(pytype):68 """Return the name of the coercion method for a given Python type."""69 mod = pytype.__module__70 if mod == "__builtin__":71 xform = "%s" % pytype.__name__72 else:73 xform = "%s_%s" % (mod, pytype.__name__)74 xform = xform.replace(".", "_")75 return xform76 77 78 class AdapterSet(object):79 """Determine the best database type for a given column + Python type.80 81 When Geniusql is asked to create database tables, it must choose an82 appropriate column data type for each UnitProperty based on the83 type (and hints) of that property. This class recommends such84 database types by returning a new instance of DatabaseType.85 """86 87 known_types = None88 89 # You should REALLY check into your DB's encoding and override this.90 encoding = 'utf8'91 92 def __copy__(self):93 newset = self.__class__()94 newset.update(self)95 newset.known_types = self.known_types.copy()96 return newset97 copy = __copy__98 99 def canonicalize(self, dbtypename):100 """Return the canonical DatabaseType for the given synonym.101 102 In order to avoid large amounts of code (in each provider module!)103 that merely looks up synonyms, database types MUST be104 canonicalized for all Column and SQLExpression objects.105 """106 for typeset in self.known_types.itervalues():107 for dbtype in typeset:108 if (dbtypename == dbtype.__name__109 or dbtypename in dbtype.synonyms):110 return dbtype111 raise KeyError("No canonical name found for %r." % dbtypename)112 113 def default(self, pytype, dbtype=None):114 """Return a default adapter instance for the given pytype, dbtype."""115 if dbtype is None:116 dbtype = self.database_type(pytype)117 118 ptypes = [pytype, None]119 for base in pytype.__bases__:120 ptypes.append(base)121 122 for p in ptypes:123 if p in dbtype.default_adapters:124 return dbtype.default_adapters[p]125 126 raise TypeError("%s has no default adapter for %s. Looked for: %s" %127 (dbtype, pytype, "\n".join([repr(x) for x in ptypes])))128 129 130 # ------------------------- Database types ------------------------- #131 132 def database_type(self, pytype, hints=None):133 """Return a DatabaseType instance for the given Python type.134 135 hints: if provided, this should be a dict of property attributes136 which can be used to distinguish between similar database types.137 Canonical keys include 'bytes', 'precision', and 'scale'.138 """139 xform = "dbtype_for_" + getCoerceName(pytype)140 try:141 xform = getattr(self, xform)142 except AttributeError:143 raise TypeError("%r is not handled by %s. Tried %r" %144 (pytype, self.__class__, xform))145 if hints is None:146 hints = {}147 return xform(hints)148 149 def dbtype_for_float(self, hints):150 """Return a DatabaseType for floats of the given binary precision."""151 # Note that 'precision' is binary digits, not decimal.152 precision = int(hints.get('precision', maxfloat_digits))153 if precision == 0:154 # Use the maximum precision.155 precision = max([0] + [dbtype.max_precision156 for dbtype in self.known_types['float']])157 for dbtype in self.known_types['float']:158 if precision <= dbtype.max_precision:159 return dbtype(precision=precision)160 return self.decimal_type(precision=precision)161 162 def dbtype_for_str(self, hints):163 # The bytes hint shall not reflect the usual 4-byte base for varchar.164 bytes = int(hints.get('bytes', 255))165 if bytes == 0:166 # Use the maximum bytes.167 bytes = max([0] + [dbtype.max_bytes168 for dbtype in self.known_types['varchar']])169 for dbtype in self.known_types['varchar']:170 if bytes <= dbtype.max_bytes:171 return dbtype(bytes=bytes)172 raise ValueError("%r is greater than the maximum bytes %r."173 % (bytes, dbtype.max_bytes))174 175 def dbtype_for_dict(self, hints):176 return self.dbtype_for_str(hints)177 def dbtype_for_list(self, hints):178 return self.dbtype_for_str(hints)179 def dbtype_for_tuple(self, hints):180 return self.dbtype_for_str(hints)181 def dbtype_for_unicode(self, hints):182 return self.dbtype_for_str(hints)183 184 def dbtype_for_geniusql_logic_Expression(self, hints):185 return self.dbtype_for_str(hints)186 187 def dbtype_for_bool(self, hints):188 return self.known_types['bool'][0]()189 190 def dbtype_for_datetime_datetime(self, hints):191 return self.known_types['datetime'][0]()192 193 def dbtype_for_datetime_date(self, hints):194 return self.known_types['date'][0]()195 196 def dbtype_for_datetime_time(self, hints):197 return self.known_types['time'][0]()198 199 def dbtype_for_datetime_timedelta(self, hints):200 try:201 # If your DB has an INTERVAL datatype, you should provide a202 # native INTERVAL type. You'll also have to update the date203 # arithmetic inside the decompiler and add a timedelta adapter.204 return self.known_types['timedelta'][0]()205 except (KeyError, IndexError):206 # Fallback for DB's which do not have an INTERVAL data type.207 # Use decimal instead of float to avoid rounding errors.208 # Using precision of 12 should allow +/- 31688 years.209 return self.decimal_type(12, 0)210 211 def numeric_max_precision(self):212 return max([0] + [t.max_precision for t in self.known_types['numeric']])213 214 def decimal_type(self, precision, scale):215 if scale > precision:216 scale = precision217 218 for dbtype in self.known_types['numeric']:219 if precision <= dbtype.max_precision:220 return dbtype(precision=precision, scale=scale)221 222 # Use a VARCHAR type (add 1 char for the decimal point and 1 for sign).223 bytes = precision + 1224 if scale:225 bytes += 1226 dbtype = self.dbtype_for_str({'bytes': bytes})227 228 errors.warn("The given precision (%s) is greater than the "229 "maximum numeric precision (%s). Using %s instead."230 % (precision, self.numeric_max_precision(), dbtype))231 return dbtype232 233 if typerefs.decimal:234 if hasattr(typerefs.decimal, "Decimal"):235 def dbtype_for_decimal_Decimal(self, hints):236 precision = int(hints.get('precision', 0))237 if precision == 0:238 precision = self.numeric_max_precision()239 # Assume most people use decimal for money; default scale = 2.240 scale = int(hints.get('scale', 2))241 return self.decimal_type(precision, scale)242 else:243 def dbtype_for_decimal(self, hints):244 precision = int(hints.get('precision', 0))245 if precision == 0:246 precision = self.numeric_max_precision()247 # Assume most people use decimal for money; default scale = 2.248 scale = int(hints.get('scale', 2))249 return self.decimal_type(precision, scale)250 251 if typerefs.fixedpoint:252 def dbtype_for_fixedpoint_FixedPoint(self, hints):253 # Note that fixedpoint has no theoretical precision limit.254 precision = int(hints.get('precision', 0))255 if precision == 0:256 precision = self.numeric_max_precision()257 # Assume most people use fixedpoint for money; default scale = 2.258 scale = int(hints.get('scale', 2))259 return self.decimal_type(precision, scale)260 261 def dbtype_for_long(self, hints):262 if 'bytes' in hints:263 bytes = int(hints['bytes'])264 else:265 bytes = self.numeric_max_precision() / 2266 267 for dbtype in self.known_types['int']:268 if bytes <= dbtype.max_bytes:269 return dbtype(bytes=bytes)270 return self.decimal_type(precision=bytes * 2, scale=0)271 272 def dbtype_for_int(self, hints):273 bytes = int(hints.get('bytes', maxint_bytes))274 for dbtype in self.known_types['int']:275 if bytes <= dbtype.max_bytes:276 return dbtype(bytes=bytes)277 return self.decimal_type(precision=bytes * 2, scale=0)278 57 279 58 trunk/geniusql/dbtypes.py
r64 r65 4 4 import datetime 5 5 6 from geniusql import adapters, typerefs6 from geniusql import adapters, errors, typerefs 7 7 8 8 … … 28 28 synonyms = [] 29 29 30 # Given the wide variety of type systems in commercial databases,31 # it seemed best to just overlay them all with a nominative system.32 implicit_conversions = []33 34 30 def __init__(self, **kwargs): 35 31 for k, v in kwargs.iteritems(): … … 49 45 """Return the type for use in CREATE or ALTER statements.""" 50 46 return self.__class__.__name__ 47 48 def default_adapter(self, pytype): 49 """Return a default adapter instance for the given pytype, dbtype.""" 50 ptypes = [pytype, None] 51 for base in pytype.__bases__: 52 ptypes.append(base) 53 54 for p in ptypes: 55 if p in self.default_adapters: 56 return self.default_adapters[p] 57 58 raise TypeError("%s has no default adapter for %s. Looked for: %s" % 59 (self, pytype, "\n".join([repr(x) for x in ptypes]))) 51 60 52 61 … … 120 129 _initargs = DatabaseType._initargs + ("precision", "max_precision") 121 130 122 # Max binary precision for floating-point columns (= 53 for PostgreSQL 8).123 # Python floats are implemented using C doubles; actual precision depends124 # on platform(but is usually 53 binary digits, see adapters.maxfloat_digits).125 # PostgreSQLDOUBLE is 53 binary-digit precision.131 # Max binary precision for floating-point columns. Python floats are 132 # implemented using C doubles; actual precision depends on platform 133 # (but is usually 53 binary digits, see adapters.maxfloat_digits). 134 # Many commercial DB's DOUBLE is 53 binary-digit precision. 126 135 max_precision = 53 127 136 … … 411 420 default_adapters = {bool: adapters.bool_to_SQL99BOOLEAN()} 412 421 422 423 424 # ----------------------------- Type Sets ----------------------------- # 425 426 427 def getCoerceName(pytype): 428 """Return the name of the coercion method for a given Python type.""" 429 mod = pytype.__module__ 430 if mod == "__builtin__": 431 xform = "%s" % pytype.__name__ 432 else: 433 xform = "%s_%s" % (mod, pytype.__name__) 434 xform = xform.replace(".", "_") 435 return xform 436 437 438 class DatabaseTypeSet(object): 439 """Determine the best database type for a given column + Python type. 440 441 When Geniusql is asked to create database tables, it must choose an 442 appropriate column data type for each UnitProperty based on the 443 type (and hints) of that property. This class recommends such 444 database types by returning a new instance of DatabaseType. 445 """ 446 447 known_types = None 448 449 # You should REALLY check into your DB's encoding and override this. 450 encoding = 'utf8' 451 452 def __copy__(self): 453 newset = self.__class__() 454 newset.update(self) 455 newset.known_types = self.known_types.copy() 456 return newset 457 copy = __copy__ 458 459 def canonicalize(self, dbtypename): 460 """Return the canonical DatabaseType for the given synonym. 461 462 In order to avoid large amounts of code (in each provider module!) 463 that merely looks up synonyms, database types MUST be 464 canonicalized for all Column and SQLExpression objects. 465 """ 466 for typeset in self.known_types.itervalues(): 467 for dbtype in typeset: 468 if (dbtypename == dbtype.__name__ 469 or dbtypename in dbtype.synonyms): 470 return dbtype 471 raise KeyError("No canonical name found for %r." % dbtypename) 472 473 def database_type(self, pytype, hints=None): 474 """Return a DatabaseType instance for the given Python type. 475 476 hints: if provided, this should be a dict of property attributes 477 which can be used to distinguish between similar database types. 478 Canonical keys include 'bytes', 'precision', and 'scale'. 479 """ 480 xform = "dbtype_for_" + getCoerceName(pytype) 481 try: 482 xform = getattr(self, xform) 483 except AttributeError: 484 raise TypeError("%r is not handled by %s. Tried %r" % 485 (pytype, self.__class__, xform)) 486 if hints is None: 487 hints = {} 488 return xform(hints) 489 490 def dbtype_for_float(self, hints): 491 """Return a DatabaseType for floats of the given binary precision.""" 492 # Note that 'precision' is binary digits, not decimal. 493 precision = int(hints.get('precision', adapters.maxfloat_digits)) 494 if precision == 0: 495 # Use the maximum precision. 496 precision = max([0] + [dbtype.max_precision 497 for dbtype in self.known_types['float']]) 498 for dbtype in self.known_types['float']: 499 if precision <= dbtype.max_precision: 500 return dbtype(precision=precision) 501 return self.decimal_type(precision=precision) 502 503 def dbtype_for_str(self, hints): 504 # The bytes hint shall not reflect the usual 4-byte base for varchar. 505 bytes = int(hints.get('bytes', 255)) 506 if bytes == 0: 507 # Use the maximum bytes. 508 bytes = max([0] + [dbtype.max_bytes 509 for dbtype in self.known_types['varchar']]) 510 for dbtype in self.known_types['varchar']: 511 if bytes <= dbtype.max_bytes: 512 return dbtype(bytes=bytes) 513 raise ValueError("%r is greater than the maximum bytes %r." 514 % (bytes, dbtype.max_bytes)) 515 516 def dbtype_for_dict(self, hints): 517 return self.dbtype_for_str(hints) 518 def dbtype_for_list(self, hints): 519 return self.dbtype_for_str(hints) 520 def dbtype_for_tuple(self, hints): 521 return self.dbtype_for_str(hints) 522 def dbtype_for_unicode(self, hints): 523 return self.dbtype_for_str(hints) 524 525 def dbtype_for_geniusql_logic_Expression(self, hints): 526 return self.dbtype_for_str(hints) 527 528 def dbtype_for_bool(self, hints): 529 return self.known_types['bool'][0]() 530 531 def dbtype_for_datetime_datetime(self, hints): 532 return self.known_types['datetime'][0]() 533 534 def dbtype_for_datetime_date(self, hints): 535 return self.known_types['date'][0]() 536 537 def dbtype_for_datetime_time(self, hints): 538 return self.known_types['time'][0]() 539 540 def dbtype_for_datetime_timedelta(self, hints): 541 try: 542 # If your DB has an INTERVAL datatype, you should provide a 543 # native INTERVAL type. You'll also have to update the date 544 # arithmetic inside the decompiler and add a timedelta adapter. 545 return self.known_types['timedelta'][0]() 546 except (KeyError, IndexError): 547 # Fallback for DB's which do not have an INTERVAL data type. 548 # Use decimal instead of float to avoid rounding errors. 549 # Using precision of 12 should allow +/- 31688 years. 550 return self.decimal_type(12, 0) 551 552 def numeric_max_precision(self): 553 return max([0] + [t.max_precision for t in self.known_types['numeric']]) 554 555 def decimal_type(self, precision, scale): 556 if scale > precision: 557 scale = precision 558 559 for dbtype in self.known_types['numeric']: 560 if precision <= dbtype.max_precision: 561 return dbtype(precision=precision, scale=scale) 562 563 # Use a VARCHAR type (add 1 char for the decimal point and 1 for sign). 564 bytes = precision + 1 565 if scale: 566 bytes += 1 567 dbtype = self.dbtype_for_str({'bytes': bytes}) 568 569 errors.warn("The given precision (%s) is greater than the " 570 "maximum numeric precision (%s). Using %s instead." 571 % (precision, self.numeric_max_precision(), dbtype)) 572 return dbtype 573 574 if typerefs.decimal: 575 if hasattr(typerefs.decimal, "Decimal"): 576 def dbtype_for_decimal_Decimal(self, hints): 577 precision = int(hints.get('precision', 0)) 578 if precision == 0: 579 precision = self.numeric_max_precision() 580 # Assume most people use decimal for money; default scale = 2. 581 scale = int(hints.get('scale', 2)) 582 return self.decimal_type(precision, scale) 583 else: 584 def dbtype_for_decimal(self, hints): 585 precision = int(hints.get('precision', 0)) 586 if precision == 0: 587 precision = self.numeric_max_precision() 588 # Assume most people use decimal for money; default scale = 2. 589 scale = int(hints.get('scale', 2)) 590 return self.decimal_type(precision, scale) 591 592 if typerefs.fixedpoint: 593 def dbtype_for_fixedpoint_FixedPoint(self, hints): 594 # Note that fixedpoint has no theoretical precision limit. 595 precision = int(hints.get('precision', 0)) 596 if precision == 0: 597 precision = self.numeric_max_precision() 598 # Assume most people use fixedpoint for money; default scale = 2. 599 scale = int(hints.get('scale', 2)) 600 return self.decimal_type(precision, scale) 601 602 def dbtype_for_long(self, hints): 603 if 'bytes' in hints: 604 bytes = int(hints['bytes']) 605 else: 606 bytes = self.numeric_max_precision() / 2 607 608 for dbtype in self.known_types['int']: 609 if bytes <= dbtype.max_bytes: 610 return dbtype(bytes=bytes) 611 return self.decimal_type(precision=bytes * 2, scale=0) 612 613 def dbtype_for_int(self, hints): 614 bytes = int(hints.get('bytes', adapters.maxint_bytes)) 615 for dbtype in self.known_types['int']: 616 if bytes <= dbtype.max_bytes: 617 return dbtype(bytes=bytes) 618 return self.decimal_type(precision=bytes * 2, scale=0) 619 trunk/geniusql/decompile.py
r64 r65 109 109 bool_false = "FALSE" 110 110 111 def __init__(self, tables, expr, adapterset):111 def __init__(self, tables, expr, typeset): 112 112 self.tables = tables 113 113 self.expr = expr 114 self. adapterset = adapterset114 self.typeset = typeset 115 115 116 116 self.groups = [] … … 120 120 self.false_expr = self.const(False, self.bool_false) 121 121 122 booldbtype = self. adapterset.database_type(bool)123 booladapter = self.adapterset.default(bool, booldbtype)122 booldbtype = self.typeset.database_type(bool) 123 booladapter = booldbtype.default_adapter(bool) 124 124 self.T = self.const(True, booladapter.push(True, booldbtype)) 125 125 self.F = self.const(False, booladapter.push(False, booldbtype)) … … 136 136 name = "expr%s" % self.exprcount 137 137 138 dbtype = self. adapterset.database_type(pytype)138 dbtype = self.typeset.database_type(pytype) 139 139 e = SQLExpression(sql, name, dbtype, pytype) 140 e.adapter = adapter or self.adapterset.default(pytype, dbtype)140 e.adapter = adapter or dbtype.default_adapter(pytype) 141 141 142 142 return e … … 429 429 atoms = [] 430 430 for x in op2.value: 431 adapter = self.adapterset.default(type(x), op1.dbtype)431 adapter = op1.dbtype.default_adapter(type(x)) 432 432 atoms.append(adapter.push(x, op1.dbtype)) 433 433 if atoms: … … 448 448 atoms = [] 449 449 for x in op2.value: 450 adapter = self.adapterset.default(type(x), op1.dbtype)450 adapter = op1.dbtype.default_adapter(type(x)) 451 451 atoms.append(adapter.push(x.lower(), op1.dbtype)) 452 452 return self.get_expr("LOWER(%s) IN (%s)" % … … 531 531 if newpytype != op1.pytype: 532 532 op1.pytype = newpytype 533 op1.dbtype = self. adapterset.database_type(newpytype)534 op1.adapter = self.adapterset.default(newpytype, op1.dbtype)533 op1.dbtype = self.typeset.database_type(newpytype) 534 op1.adapter = op1.dbtype.default_adapter(newpytype) 535 535 if not op1.name.startswith("expr_"): 536 536 op1.name = "expr_%s" % op1.name trunk/geniusql/objects.py
r64 r65 19 19 import geniusql 20 20 from geniusql import errors, typerefs 21 from geniusql import adapters21 from geniusql import dbtypes 22 22 from geniusql import conns 23 23 from geniusql import decompile … … 331 331 tpair = [(self.qname, self)] 332 332 decom = self.schema.db.decompiler(tpair, logic.filter(**inputs), 333 self.schema.db. adapterset)333 self.schema.db.typeset) 334 334 ## decom.verbose = True 335 335 code = decom.code() … … 626 626 col.autoincrement = autoincrement 627 627 628 typer = self.db. adapterset628 typer = self.db.typeset 629 629 if col.dbtype is None: 630 630 col.dbtype = typer.database_type(pytype, hints or {}) 631 col.adapter = typer.default(pytype, col.dbtype)631 col.adapter = col.dbtype.default_adapter(pytype) 632 632 633 633 return col … … 754 754 __metaclass__ = geniusql._AttributeDocstrings 755 755 756 adapterset = adapters.AdapterSet()756 typeset = dbtypes.DatabaseTypeSet() 757 757 decompiler = decompile.SQLDecompiler 758 758 joinwrapper = select.TableWrapper … … 842 842 conn = self.connections.get() 843 843 if isinstance(query, unicode): 844 query = query.encode(self. adapterset.encoding)844 query = query.encode(self.typeset.encoding) 845 845 self.log(query) 846 846 return conn.query(query) trunk/geniusql/providers/ado.py
r64 r65 256 256 atoms = [] 257 257 for x in op2.value: 258 adapter = self.adapterset.default(type(x), op1.dbtype)258 adapter = op1.dbtype.default_adapter(type(x)) 259 259 atoms.append(adapter.push(x, op1.dbtype)) 260 260 if atoms: … … 461 461 conn = self.connections.get() 462 462 ## if isinstance(query, unicode): 463 ## query = query.encode(self. adapterset.encoding)463 ## query = query.encode(self.typeset.encoding) 464 464 465 465 self.log(query) trunk/geniusql/providers/msaccess.py
r64 r65 324 324 325 325 326 class MSAccess AdapterSet(adapters.AdapterSet):326 class MSAccessTypeSet(dbtypes.DatabaseTypeSet): 327 327 328 328 known_types = {'float': [REAL, FLOAT], … … 484 484 485 485 cols = [] 486 typer = self.db. adapterset486 typer = self.db.typeset 487 487 for row in data: 488 488 # I tried passing criteria to OpenSchema, but passing None is … … 532 532 dbtype.bytes = (2 ** 31) - 1 533 533 534 c.adapter = typer.default(pytype, dbtype)534 c.adapter = dbtype.default_adapter(pytype) 535 535 cols.append(c) 536 536 … … 645 645 646 646 decompiler = MSAccessDecompiler 647 adapterset = MSAccessAdapterSet()647 typeset = MSAccessTypeSet() 648 648 connectionmanager = MSAccessConnectionManager 649 649 schemaclass = MSAccessSchema trunk/geniusql/providers/postgres.py
r64 r65 353 353 354 354 355 class Pg AdapterSet(adapters.AdapterSet):355 class PgTypeSet(dbtypes.DatabaseTypeSet): 356 356 357 357 known_types = {'float': [FLOAT4, FLOAT8], … … 385 385 atoms = [] 386 386 for x in op2.value: 387 adapter = self.adapterset.default(type(x), op1.dbtype)387 adapter = op1.dbtype.default_adapter(type(x)) 388 388 atoms.append(adapter.push(x.lower(), op1.dbtype)) 389 389 return self.get_expr("LOWER(%s) IN (%s)" % … … 515 515 data, _ = self.db.fetch(sql, conn=conn) 516 516 cols = [] 517 adapterset = self.db.adapterset517 typeset = self.db.typeset 518 518 for row in data: 519 519 name = row[0] … … 526 526 dbtype, _ = self.db.fetch("SELECT typname, typlen FROM pg_type " 527 527 "WHERE oid = %s" % row[1], conn=conn) 528 dbtypetype = adapterset.canonicalize(dbtype[0][0].upper())528 dbtypetype = typeset.canonicalize(dbtype[0][0].upper()) 529 529 dbtype = dbtypetype() 530 530 … … 532 532 None, key=row[2] in indices, 533 533 name=row[0], qname=self.db.quote(row[0])) 534 c.adapter = adapterset.default(c.pytype, dbtype)534 c.adapter = dbtype.default_adapter(c.pytype) 535 535 536 536 if dbtypetype in (FLOAT4, FLOAT8): … … 660 660 decompiler = PgDecompiler 661 661 schemaclass = PgSchema 662 adapterset = PgAdapterSet()662 typeset = PgTypeSet() 663 663 664 664 def quote(self, name): trunk/geniusql/providers/sqlserver.py
r64 r65 240 240 241 241 242 class SQLServer AdapterSet(adapters.AdapterSet):242 class SQLServerTypeSet(dbtypes.DatabaseTypeSet): 243 243 244 244 known_types = {'float': [REAL, FLOAT], … … 403 403 404 404 cols = [] 405 typer = self.db. adapterset405 typer = self.db.typeset 406 406 for row in data: 407 407 # I tried passing criteria to OpenSchema, but passing None is … … 444 444 dbtype.bytes = b = int(row[13]) 445 445 446 c.adapter = typer.default(pytype, dbtype)446 c.adapter = dbtype.default_adapter(pytype) 447 447 cols.append(c) 448 448 return cols … … 487 487 488 488 decompiler = SQLServerDecompiler 489 adapterset = SQLServerAdapterSet()489 typeset = SQLServerTypeSet() 490 490 connectionmanager = SQLServerConnectionManager 491 491 schemaclass = SQLServerSchema trunk/geniusql/select.py
r64 r65 247 247 """Return an SQL WHERE clause, and an 'imperfect' flag.""" 248 248 tpairs = [(t.alias or t.qname, t.table) for t in self.tables] 249 decom = self.db.decompiler(tpairs, self.restriction, self.db. adapterset)249 decom = self.db.decompiler(tpairs, self.restriction, self.db.typeset) 250 250 code = decom.code() 251 251 return code, decom.imperfect … … 343 343 tpairs = [(t.alias or t.qname, t.table) for t in self.tables] 344 344 decom = self.db.decompiler 345 decom = decom(tpairs, self.attributes, self.db. adapterset)345 decom = decom(tpairs, self.attributes, self.db.typeset) 346 346 ## decom.verbose = True 347 347 trunk/geniusql/test/test_msaccess.py
r64 r65 26 26 ## def test_currency_dbtypes(obj): 27 27 ## db = zoo_fixture.db 28 ## fta = db. adapterset.__class__.__name__28 ## fta = db.typeset.__class__.__name__ 29 29 ## schema = zoo_fixture.schema 30 30 ## trunk/geniusql/test/zoo_fixture.py
r64 r65 1103 1103 if db: 1104 1104 import math 1105 maxprec = db. adapterset.numeric_max_precision1105 maxprec = db.typeset.numeric_max_precision 1106 1106 if maxprec == 0: 1107 1107 # SQLite, for example, must always use TEXT.
