Changeset 14
- Timestamp:
- 02/16/07 23:26:39
- Files:
-
- trunk/geniusql/conns.py (modified) (2 diffs)
- trunk/geniusql/objects.py (modified) (1 diff)
- trunk/geniusql/providers/ado.py (modified) (3 diffs)
- trunk/geniusql/providers/postgres.py (modified) (1 diff)
- trunk/geniusql/providers/sqlite.py (modified) (8 diffs)
- trunk/geniusql/test/test_msaccess.py (modified) (3 diffs)
- trunk/geniusql/test/test_psycopg.py (modified) (1 diff)
- trunk/geniusql/test/test_pypgsql.py (modified) (1 diff)
- trunk/geniusql/test/test_sqlite.py (modified) (2 diffs)
- trunk/geniusql/test/test_sqlserver.py (modified) (2 diffs)
- trunk/geniusql/test/zoo_fixture.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/geniusql/conns.py
r13 r14 148 148 class ConnectionManager(object): 149 149 150 poolsize = 10 150 151 implicit_trans = False 151 152 … … 161 162 "REPEATABLE READ", "SERIALIZABLE"] 162 163 163 def __init__(self, db , poolsize=10):164 def __init__(self, db): 164 165 self.transactions = {} 165 166 self.db = db 166 self.poolsize = poolsize167 167 self._set_factory() 168 168 trunk/geniusql/objects.py
r13 r14 729 729 730 730 def __init__(self, **kwargs): 731 self.connections = self.connectionmanager(self) 732 733 children = [] 731 734 for k, v in kwargs.iteritems(): 732 setattr(self, k, v) 733 734 poolsize = kwargs.get('poolsize', 10) 735 self.connections = self.connectionmanager(self, poolsize) 735 if "." in k: 736 # Defer subkeys in case the child is replaced wholesale 737 children.append((k, v)) 738 else: 739 setattr(self, k, v) 740 741 for k, v in children: 742 namespace, name = k.split(".", 1) 743 childobj = getattr(self, namespace) 744 setattr(childobj, name, v) 736 745 737 746 def version(self): trunk/geniusql/providers/ado.py
r13 r14 618 618 adapterfromdb = AdapterFromADO() 619 619 620 def __init__(self, **kwargs):621 geniusql.Database.__init__(self, **kwargs)622 self.connections.Connect = self.Connect623 624 620 def python_type(self, dbtype): 625 621 """Return a Python type which can store values of the given dbtype.""" … … 1076 1072 isolation_levels = ["READ UNCOMMITTED",] 1077 1073 1078 def __init__(self, db , poolsize=0):1074 def __init__(self, db): 1079 1075 self.transactions = {} 1080 1076 self.db = db 1081 self.poolsize = 01082 1077 # MS Access can't use a pool, because there doesn't seem 1083 1078 # to be a commit timeout. See http://support.microsoft.com/kb/200300 … … 1194 1189 # By not providing an Engine Type, it defaults to 5 = Access 2000. 1195 1190 cat = win32com.client.Dispatch(r'ADOX.Catalog') 1196 cat.Create(self.db. Connect)1191 cat.Create(self.db.connections.Connect) 1197 1192 cat.ActiveConnection.Close() 1198 1193 self.clear() trunk/geniusql/providers/postgres.py
r13 r14 330 330 def __init__(self, **kwargs): 331 331 geniusql.Database.__init__(self, **kwargs) 332 self.connections.Connect = self.Connect333 332 334 333 def python_type(self, dbtype): trunk/geniusql/providers/sqlite.py
r13 r14 51 51 # If you are using type adapters that support a "standard" 52 52 # date/datetime format for SQLite, set the following flag to True 53 using_perfect_dates = False53 perfect_dates = False 54 54 55 55 def coerce_bool_to_any(self, value): … … 78 78 79 79 def visit_COMPARE_OP(self, lo, hi): 80 if self.adapter. using_perfect_dates:80 if self.adapter.perfect_dates: 81 81 op2, op1 = self.stack.pop(), self.stack.pop() 82 82 … … 182 182 183 183 def dejavu_now(self): 184 if self.adapter. using_perfect_dates and _cast_support:184 if self.adapter.perfect_dates and _cast_support: 185 185 return "julianday('now')" 186 186 else: … … 191 191 192 192 def dejavu_year(self, x): 193 if self.adapter. using_perfect_dates and _cast_support:193 if self.adapter.perfect_dates and _cast_support: 194 194 return "CAST(strftime('%Y', " + x + ") AS NUMERIC)" 195 195 else: … … 198 198 199 199 def dejavu_month(self, x): 200 if self.adapter. using_perfect_dates and _cast_support:200 if self.adapter.perfect_dates and _cast_support: 201 201 return "CAST(strftime('%m', " + x + ") AS NUMERIC)" 202 202 else: … … 205 205 206 206 def dejavu_day(self, x): 207 if self.adapter. using_perfect_dates and _cast_support:207 if self.adapter.perfect_dates and _cast_support: 208 208 return "CAST(strftime('%d', " + x + ") AS NUMERIC)" 209 209 else: … … 479 479 isolation_levels = ["SERIALIZABLE"] 480 480 481 def __init__(self, db , poolsize=10):481 def __init__(self, db): 482 482 self.transactions = {} 483 483 self.db = db 484 self.poolsize = poolsize485 484 # Can't set up the factory until we have a schema. 486 485 … … 765 764 geniusql.Database.__init__(self, **kwargs) 766 765 767 def _get_upd(self):768 return self.adaptertosql.using_perfect_dates769 def _set_upd(self, value):770 self.adaptertosql.using_perfect_dates = value771 using_perfect_dates = property(_get_upd, _set_upd)772 773 766 def isrelatedtype(self, pytype1, pytype2): 774 if (self. using_perfect_dates and767 if (self.adaptertosql.perfect_dates and 775 768 issubclass(pytype1, (datetime.date, datetime.time, datetime.datetime)) and 776 769 issubclass(pytype2, self.python_type(self.typeadapter.coerce(None, pytype1)))): trunk/geniusql/test/test_msaccess.py
r13 r14 30 30 31 31 DB_class = "access" 32 opts = {' Connect': "PROVIDER=MICROSOFT.JET.OLEDB.4.0;"33 "DATA SOURCE=zoo.mdb;",32 opts = {'connections.Connect': 33 "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=zoo.mdb;", 34 34 } 35 35 … … 55 55 obj.assertEqual(len(standard_runs), 0) 56 56 57 # Isolate schema changes from one test to the next.58 reload(zoo_fixture)59 60 57 # test the standard MS Access setup where Decimal and FixedPoint 61 58 # objects are stored in the database as INTEGERS, LONGS or NUMERIC 59 reload(zoo_fixture) 62 60 print 63 61 print "Standard MSAccess test." … … 66 64 standard_runs.append(True) 67 65 68 # plugin the adapter for testing CURRENCY columns69 ado.MSAccessDatabase.typeadapter = CurrencyAdapter()70 71 reload(zoo_fixture)72 73 66 # test storing and recalling Decimal values to the database using 74 67 # CURRENCY columns - the (current) default behavior of pythoncom 75 68 # is to return CURRENCY values as a tuple 69 reload(zoo_fixture) 76 70 print 77 71 print "MSAccess test - CURRENCY returned as tuple." 78 72 ## zoo_fixture.ZooTests.test_currency = test_currency 73 # plugin the adapter for testing CURRENCY columns 74 opts['typeadapter'] = CurrencyAdapter() 79 75 zoo_fixture.run(DB_class, "zoo.mdb", opts) 76 del opts['typeadapter'] 80 77 altered_runs.append(True) 81 82 # set pythoncom to return CURRENCY values as Decimal objects83 pythoncom.__future_currency__ = True84 85 reload(zoo_fixture)86 78 87 79 # test storing and recalling Decimal values to the database using 88 80 # CURRENCY columns - CURRENCY values are now returned as Decimal 89 # objects 81 # objects. 82 # set pythoncom to return CURRENCY values as Decimal objects 83 pythoncom.__future_currency__ = True 84 reload(zoo_fixture) 90 85 print 91 86 print "MSAccess test - CURRENCY returned as Decimal." trunk/geniusql/test/test_psycopg.py
r13 r14 19 19 passwd = raw_input("Enter the password for the PostgreSQL '%s' user:" % user) 20 20 21 opts = {'Connect': ("host=localhost dbname=geniusql_test " 22 "user=%s password=%s" % (user, passwd)), 21 opts = {'connections.Connect': 22 ("host=localhost dbname=geniusql_test user=%s password=%s" 23 % (user, passwd)), 23 24 } 24 25 DB_class = "psycopg" trunk/geniusql/test/test_pypgsql.py
r13 r14 14 14 passwd = raw_input("Enter the password for the PostgreSQL '%s' user:" % user) 15 15 16 opts = {'Connect': ("host=localhost dbname=geniusql_test " 17 "user=%s password=%s" % (user, passwd)), 16 opts = {'connections.Connect': 17 ("host=localhost dbname=geniusql_test user=%s password=%s" 18 % (user, passwd)), 18 19 } 19 20 DB_class = "postgres" trunk/geniusql/test/test_sqlite.py
r13 r14 22 22 if _sqlite: 23 23 DB_class = "sqlite" 24 opts = { "Database": dbpath}24 opts = {} 25 25 26 26 def run(): … … 28 28 # Isolate schema changes from one test to the next. 29 29 reload(zoo_fixture) 30 zoo_fixture.run(DB_class, opts['Database'], opts)30 zoo_fixture.run(DB_class, dbpath, opts) 31 31 32 32 print 33 33 print "Testing SQLite with 'Perfect Dates'" 34 opts[' Perfect Dates'] = True34 opts['adaptertosql.perfect_dates'] = True 35 35 reload(zoo_fixture) 36 zoo_fixture.run(DB_class, opts['Database'], opts)37 opts[' Perfect Dates'] = False36 zoo_fixture.run(DB_class, dbpath, opts) 37 opts['adaptertosql.perfect_dates'] = False 38 38 39 39 print 40 40 print "Testing SQLite ':memory:' database..." 41 opts['Database'] = ':memory:'42 41 reload(zoo_fixture) 43 zoo_fixture.run(DB_class, opts['Database'], opts)42 zoo_fixture.run(DB_class, ':memory:', opts) 44 43 45 44 print 46 45 print "Testing SQLite 'typeless'..." 47 opts['Database'] = dbpath48 opts[' Type Adapter'] = "geniusql.providers.sqlite.TypeAdapterSQLiteTypeless"46 from geniusql.providers import sqlite 47 opts['typeadapter'] = sqlite.TypeAdapterSQLiteTypeless() 49 48 reload(zoo_fixture) 50 zoo_fixture.run(DB_class, opts['Database'], opts)49 zoo_fixture.run(DB_class, dbpath, opts) 51 50 52 51 if __name__ == "__main__": trunk/geniusql/test/test_sqlserver.py
r13 r14 6 6 def run(): 7 7 warnings.warn("The pythoncom module could not be imported. " 8 "The MSAccesstest will not be run.")8 "The SQL Server test will not be run.") 9 9 else: 10 10 from geniusql.providers import ado … … 16 16 "The SQLServer test will not be run.") 17 17 else: 18 opts = {' Connect': ("Provider=SQLOLEDB.1; Integrated Security=SSPI; "19 "Initial Catalog=geniusql_test; "20 "Data Source=(local)"),18 opts = {'connections.Connect': 19 ("Provider=SQLOLEDB.1; Integrated Security=SSPI; " 20 "Initial Catalog=geniusql_test; Data Source=(local)"), 21 21 # Shorten the transaction deadlock timeout. 22 22 # You may need to adjust this for your system. 23 ' CommandTimeout': 10,23 'connections.CommandTimeout': 1, 24 24 } 25 25 DB_class = "sqlserver" trunk/geniusql/test/zoo_fixture.py
r13 r14 681 681 except AttributeError: 682 682 self.old_implicit = None 683 684 683 685 684 def tearDown(self): … … 690 689 def restore(self): 691 690 self.boxid = 0 692 box = arena.new_sandbox()693 box.start()694 jim = box.unit(Vet,Name = 'Jim McBain')695 jim.City = None696 box.flush_all()691 692 db.connections.start() 693 jim = schema['Vet'].select_one(Name = 'Jim McBain') 694 schema['Vet'].save(ID = jim['ID'], City = None) 695 db.connections.commit() 697 696 698 697 def cleanup_boxes(self): 699 698 try: 700 699 self.boxid = 1 701 self.box1.rollback()700 db.connections.rollback() 702 701 except: pass 703 702 try: 704 703 self.boxid = 2 705 self.box2.rollback()704 db.connections.rollback() 706 705 except: pass 707 708 # Destroy refs so the conns can go back in the pool.709 del self.box1, self.box2710 706 711 707 def attempt(self, testfunc, anomaly_name, level): 708 print ".", 712 709 self.restore() 713 710 714 711 self.boxid = 1 715 self.box1 = arena.new_sandbox() 716 self.box1.start(level) 712 db.connections.start(level) 717 713 718 714 self.boxid = 2 719 self.box2 = arena.new_sandbox() 720 self.box2.start(level) 715 db.connections.start(level) 721 716 722 717 try: … … 754 749 # Write City 1 755 750 self.boxid = 1 756 jim1 = self.box1.unit(Vet, Name = 'Jim McBain') 757 jim1.City = "Addis Ababa" 758 self.box1.repress(jim1) 751 jim1 = schema['Vet'].select_one(Name = 'Jim McBain') 752 schema['Vet'].save(ID = jim1['ID'], City = "Addis Ababa") 759 753 760 754 # Read City 2. 761 755 self.boxid = 2 762 jim2 = s elf.box2.unit(Vet,Name = 'Jim McBain')756 jim2 = schema['Vet'].select_one(Name = 'Jim McBain') 763 757 # If READ UNCOMMITTED or lower, this should fail 764 assert jim2 .Cityis None765 766 for level in geniusql. levels:758 assert jim2['City'] is None 759 760 for level in geniusql.isolation.levels: 767 761 if self.verbose: 768 762 print … … 775 769 # Read City 1 776 770 self.boxid = 1 777 jim1 = s elf.box1.unit(Vet,Name = 'Jim McBain')778 val1 = jim1 .City771 jim1 = schema['Vet'].select_one(Name = 'Jim McBain') 772 val1 = jim1['City'] 779 773 assert val1 is None 780 self.box1.repress(jim1)781 774 782 775 # Write City 2. 783 776 self.boxid = 2 784 jim2 = s elf.box2.unit(Vet,Name = 'Jim McBain')785 jim2.City = "Tehachapi"786 self.box2.flush_all()777 jim2 = schema['Vet'].select_one(Name = 'Jim McBain') 778 schema['Vet'].save(ID=jim2['ID'], City = "Tehachapi") 779 db.connections.commit() 787 780 788 781 # Re-read City 1 789 782 self.boxid = 1 790 jim1 = s elf.box1.unit(Vet,Name = 'Jim McBain')783 jim1 = schema['Vet'].select_one(Name = 'Jim McBain') 791 784 # If READ COMMITTED or lower, this should fail 792 assert jim1 .City== val1793 794 for level in geniusql. levels:785 assert jim1['City'] == val1 786 787 for level in geniusql.isolation.levels: 795 788 if self.verbose: 796 789 print … … 803 796 # Read City 1 804 797 self.boxid = 1 805 pvets = self.box1.recall(Vet, City = 'Poughkeepsie')798 pvets = list(schema['Vet'].select_all(City = 'Poughkeepsie')) 806 799 assert len(pvets) == 0 807 800 808 801 # Write City 2. 809 802 self.boxid = 2 810 jim2 = s elf.box2.unit(Vet,Name = 'Jim McBain')811 jim2.City = "Poughkeepsie"812 self.box2.flush_all()803 jim2 = schema['Vet'].select_one(Name = 'Jim McBain') 804 schema['Vet'].save(ID = jim2['ID'], City = "Poughkeepsie") 805 db.connections.commit() 813 806 814 807 # Re-read City 1 815 808 self.boxid = 1 816 pvets = self.box1.recall(Vet, City = 'Poughkeepsie')809 pvets = list(schema['Vet'].select_all(City = 'Poughkeepsie')) 817 810 # If REPEATABLE READ or lower, this should fail 818 811 assert len(pvets) == 0 819 812 820 for level in geniusql. levels:813 for level in geniusql.isolation.levels: 821 814 if self.verbose: 822 815 print … … 1121 1114 tools.TestRunner.run(zoocase) 1122 1115 print "Ran zoo cases in:", datetime.datetime.now() - startTime 1123 ##1124 ### Run the other cases.1116 1117 # Run the other cases. 1125 1118 ## tools.TestRunner.run(loader(NumericTests)) 1126 1119 ## tools.TestRunner.run(loader(ConcurrencyTests)) 1127 ## s = arena.stores.values()[0] 1128 ## if hasattr(s, "db"): 1129 ## tools.TestRunner.run(loader(IsolationTests)) 1130 ## tools.TestRunner.run(loader(DiscoveryTests)) 1120 tools.TestRunner.run(loader(IsolationTests)) 1121 ## tools.TestRunner.run(loader(DiscoveryTests)) 1131 1122 except: 1132 1123 traceback.print_exc()
