Changeset 4
- Timestamp:
- 02/12/07 05:59:01
- Files:
-
- trunk/geniusql/__init__.py (modified) (16 diffs)
- trunk/geniusql/providers/firebird.py (modified) (1 diff)
- trunk/geniusql/providers/mysql.py (modified) (3 diffs)
- trunk/geniusql/providers/sqlite.py (modified) (2 diffs)
- trunk/geniusql/test/test.py (modified) (1 diff)
- trunk/geniusql/test/test_firebird.py (modified) (2 diffs)
- trunk/geniusql/test/test_msaccess.py (modified) (5 diffs)
- trunk/geniusql/test/test_mysql.py (modified) (3 diffs)
- trunk/geniusql/test/test_psycopg.py (modified) (3 diffs)
- trunk/geniusql/test/test_sqlite.py (modified) (5 diffs)
- trunk/geniusql/test/test_sqlserver.py (modified) (3 diffs)
- trunk/geniusql/test/zoo_fixture.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/geniusql/__init__.py
r3 r4 50 50 51 51 opts = dict([(str(k), v) for k, v in options.iteritems()]) 52 opts.pop('name', None) 52 53 53 54 return cls(name, **opts) … … 101 102 """Drop the specified index.""" 102 103 t = self.table 103 if t. db is not None:104 if t.created: 104 105 t.db.lock("Creating index. Transactions not allowed.") 105 106 try: … … 114 115 """Drop the specified index.""" 115 116 t = self.table 116 if t. db is not None:117 if t.created: 117 118 t.db.lock("Dropping index. Transactions not allowed.") 118 119 try: … … 142 143 """ 143 144 144 def __init__(self, name, qname, dbtype, default=None, hints=None, key=False): 145 def __init__(self, dbtype, default=None, hints=None, key=False, 146 name=None, qname=None): 147 self.dbtype = dbtype 145 148 self.name = name 146 149 self.qname = qname 147 self.dbtype = dbtype148 150 self.default = default 149 151 if hints is None: 150 152 hints = {} 153 else: 154 hints = hints.copy() 151 155 self.hints = hints 152 156 self.key = key … … 196 200 indexsetclass = IndexSet 197 201 198 def __new__(cls, name, qname, db =None):202 def __new__(cls, name, qname, db, created=False): 199 203 return dict.__new__(cls) 200 204 201 def __init__(self, name, qname, db =None):205 def __init__(self, name, qname, db, created=False): 202 206 dict.__init__(self) 207 203 208 self.name = name 204 209 self.qname = qname 205 210 self.db = db 211 self.created = created 212 206 213 self.indices = self.indexsetclass(self) 207 214 self.references = {} … … 242 249 243 250 def __setitem__(self, key, column): 244 if self.db is None: 251 if column.name is None: 252 column.name = self.db._column_name(self.name, key) 253 column.qname = self.db.quote(column.name) 254 255 if not self.created: 245 256 dict.__setitem__(self, key, column) 246 257 return … … 268 279 del self.indices[key] 269 280 270 if self.db is None:281 if not self.created: 271 282 dict.__delitem__(self, key) 272 283 return … … 292 303 oldcol = self[oldkey] 293 304 294 if self.db is None:305 if not self.created: 295 306 dict.__delitem__(self, oldkey) 296 307 dict.__setitem__(self, newkey, oldcol) … … 298 309 299 310 oldname = oldcol.name 300 newname = self.db. column_name(self.name, newkey)311 newname = self.db._column_name(self.name, newkey) 301 312 302 313 if oldname != newname: … … 313 324 dict.__delitem__(self, oldkey) 314 325 dict.__setitem__(self, newkey, newcol) 326 327 def add_index(self, columnkey): 328 """Add and return a new Index for the given column key. 329 330 The new Index object will possess the same key as the column. 331 In general, the actual SQL name of the new Index will be of 332 the form: "i" + table.name + column.name. 333 """ 334 colname = self[columnkey].name 335 name = self.db.table_name("i" + self.name + colname) 336 i = Index(name, self.db.quote(name), self.name, colname) 337 self.indices[columnkey] = i 338 return i 315 339 316 340 … … 544 568 del self[key] 545 569 546 # Set table. db to self, which should "turn on"570 # Set table.created to True, which should "turn on" 547 571 # any future ALTER TABLE statements. 548 table. db = self572 table.created = True 549 573 550 574 self.lock("Creating storage. Transactions not allowed.") … … 592 616 # Override this to do the actual rename at the DB level. 593 617 raise NotImplementedError 618 newtable.created = True 594 619 595 620 def rename(self, oldkey, newkey): … … 639 664 return key 640 665 641 def column_name(self, tablekey, columnkey):642 " ""Return the SQL column name for the given table and column keys."""666 def _column_name(self, tablename, columnkey): 667 "Return the SQL column name for the given table name and column key." 643 668 # If you want to use a map from your ORM's property names 644 669 # to DB column names, override this method (that's why … … 646 671 return self.sql_name(columnkey) 647 672 648 def make_column(self, tablekey, columnkey, pytype=unicode, default=None, hints=None): 649 """Return a Column object from the given table and column keys.""" 650 name = self.column_name(tablekey, columnkey) 651 if hints is None: 652 hints = {} 653 else: 654 hints = hints.copy() 655 col = Column(name, self.quote(name), None, default, hints) 673 def column(self, pytype=unicode, default=None, hints=None, 674 key=False, autoincrement=False): 675 """Return a Column object from the given arguments.""" 676 col = Column(None, default, hints) 656 677 col.dbtype = self.typeadapter.coerce(col, pytype) 657 678 pytype2 = self.python_type(col.dbtype) 658 679 col.imperfect_type = not self.isrelatedtype(pytype, pytype2) 680 col.key = key 681 col.autoincrement = autoincrement 659 682 return col 660 683 … … 665 688 return self.sql_name(self.Prefix + key) 666 689 667 def make_table(self, name):690 def table(self, name): 668 691 """Create and return a Table object for the given name.""" 669 692 name = self.table_name(name) 670 return self.tableclass(name, self.quote(name)) 671 672 def make_index(self, tablekey, columnkey): 673 name = self.table_name("i" + tablekey + columnkey) 674 return Index(name, self.quote(name), self.table_name(tablekey), 675 self.column_name(tablekey, columnkey)) 693 return self.tableclass(name, self.quote(name), self) 676 694 677 695 # Connecting # … … 935 953 for key, val in inputs.iteritems(): 936 954 col = t[key] 937 val = coerce(val, col.dbtype) 938 parms.append('%s = %s' % (col.qname, val)) 955 if col.autoincrement: 956 # Skip this field, since we're using a sequencer 957 pass 958 else: 959 val = coerce(val, col.dbtype) 960 parms.append('%s = %s' % (col.qname, val)) 939 961 940 962 if parms: trunk/geniusql/providers/firebird.py
r3 r4 656 656 return ("KInterbasDB Version: %r\nServer Version: %r" 657 657 % (kinterbasdb.__version__, svcCon.getServerVersion())) 658 659 658 659 def insert(self, tablekey, **inputs): 660 """Insert a row and return {idcolkey: newid}.""" 661 t = self[tablekey] 662 663 newids = {} 664 fields = [] 665 values = [] 666 for key, col in t.iteritems(): 667 if col.autoincrement: 668 # This advances the generator and returns its new value. 669 data, _ = self.fetch("SELECT GEN_ID(%s, 1) FROM RDB$DATABASE;" 670 % col.sequence_name) 671 val, = data[0] 672 newids[key] = val 673 674 val = self.adaptertosql.coerce(val, col.dbtype) 675 fields.append(col.qname) 676 values.append(val) 677 elif key in inputs: 678 val = self.adaptertosql.coerce(inputs[key], col.dbtype) 679 fields.append(col.qname) 680 values.append(val) 681 682 transconn = self.get_transaction() 683 684 fields = ", ".join(fields) 685 values = ", ".join(values) 686 self.execute('INSERT INTO %s (%s) VALUES (%s);' % 687 (t.qname, fields, values), transconn) 688 689 return newids 690 691 692 fields = ", ".join(fields) 693 values = ", ".join(values) 694 self.db.execute('INSERT INTO %s (%s) VALUES (%s);' % 695 (t.qname, fields, values)) 696 697 trunk/geniusql/providers/mysql.py
r3 r4 161 161 162 162 163 connargs = ["host", "user", "passwd", "db", "port", "unix_socket", 164 "conv", "connect_time", "compress", "named_pipe", 165 "init_command", "read_default_file", "read_default_group", 166 "cursorclass", "client_flag", 167 ] 168 163 169 class MySQLDatabase(geniusql.Database): 164 170 … … 185 191 geniusql.Database.__init__(self, name, **kwargs) 186 192 193 self.connargs = dict([(k, v) for k, v in kwargs.iteritems() 194 if k in connargs]) 195 187 196 self.decompiler = MySQLDecompiler 188 197 … … 229 238 del self[key] 230 239 231 # Set table. db to self, which should "turn on"240 # Set table.created to True, which should "turn on" 232 241 # any future ALTER TABLE statements. 233 table. db = self242 table.created = True 234 243 235 244 fields = [] trunk/geniusql/providers/sqlite.py
r3 r4 386 386 oldname = oldcol.name 387 387 db = self.db 388 newname = db. column_name(self.name, newkey)388 newname = db._column_name(self.name, newkey) 389 389 390 390 if oldname != newname: … … 490 490 if not os.path.isabs(name): 491 491 name = os.path.join(os.getcwd(), name) 492 kwargs['mode'] = int(kwargs.pop('mode', '0755'), 8) 492 493 geniusql.Database.__init__(self, name, **kwargs) 493 494 trunk/geniusql/test/test.py
r3 r4 68 68 69 69 for testmod in self.tests: 70 if testmod.startswith("test_store"): 71 print 72 print "Testing %s storage..." % testmod[10:] 73 mod = __import__(testmod, globals(), locals(), ['']) 74 if hasattr(mod, 'proxied_opts'): 75 mod.proxied_opts['Prefix'] = 'test' 76 elif hasattr(mod, 'opts'): 77 mod.opts['Prefix'] = 'test' 78 mod.run() 79 else: 80 suite = unittest.TestLoader().loadTestsFromName(testmod) 81 tools.TestRunner.run(suite) 70 print 71 print "Testing %s..." % testmod[5:] 72 mod = __import__(testmod, globals(), locals(), ['']) 73 if hasattr(mod, 'opts'): 74 mod.opts['Prefix'] = 'test' 75 mod.run() 82 76 83 77 84 78 def run(): 85 86 79 tools.prefer_parent_path() 87 88 80 testList = [ 89 81 'test_firebird', trunk/geniusql/test/test_firebird.py
r3 r4 24 24 'password': passwd, 25 25 } 26 SM_class = "firebird"26 DB_class = "firebird" 27 27 28 28 del user, passwd … … 32 32 # Isolate schema changes from one test to the next. 33 33 reload(zoo_fixture) 34 zoo_fixture.init() 35 zoo_fixture.run(SM_class, opts) 34 zoo_fixture.run(DB_class, opts['name'], opts) 36 35 37 36 if __name__ == "__main__": trunk/geniusql/test/test_msaccess.py
r3 r4 29 29 return "CURRENCY" 30 30 31 SM_class = "access"31 DB_class = "access" 32 32 opts = {u'Connect': "PROVIDER=MICROSOFT.JET.OLEDB.4.0;" 33 33 "DATA SOURCE=zoo.mdb;", … … 42 42 43 43 def test_currency(obj): 44 sm = zoo_fixture.arena.stores['testSM']45 fta = sm.db.typeadapter.__class__.__name__44 db = zoo_fixture.db 45 fta = db.typeadapter.__class__.__name__ 46 46 47 47 for c, p in [('Exhibit', 'Acreage'), ('Zoo', 'Admission')]: 48 dbtype = sm.db[c][p].dbtype48 dbtype = db[c][p].dbtype 49 49 if fta == "CurrencyAdapter": 50 50 if dbtype != "CURRENCY" and not dbtype.startswith("WCHAR"): … … 62 62 print 63 63 print "Standard MSAccess test." 64 zoo_fixture.ZooTests.test_currency = test_currency 65 zoo_fixture.init() 66 zoo_fixture.run(SM_class, opts) 64 ## zoo_fixture.ZooTests.test_currency = test_currency 65 zoo_fixture.run(DB_class, "zoo.mdb", opts) 67 66 standard_runs.append(True) 68 67 … … 77 76 print 78 77 print "MSAccess test - CURRENCY returned as tuple." 79 zoo_fixture.ZooTests.test_currency = test_currency 80 zoo_fixture.init() 81 zoo_fixture.run(SM_class, opts) 78 ## zoo_fixture.ZooTests.test_currency = test_currency 79 zoo_fixture.run(DB_class, "zoo.mdb", opts) 82 80 altered_runs.append(True) 83 81 … … 92 90 print 93 91 print "MSAccess test - CURRENCY returned as Decimal." 94 zoo_fixture.ZooTests.test_currency = test_currency 95 zoo_fixture.init() 96 zoo_fixture.run(SM_class, opts) 92 ## zoo_fixture.ZooTests.test_currency = test_currency 93 zoo_fixture.run(DB_class, "zoo.mdb", opts) 97 94 altered_runs.append(True) 98 95 trunk/geniusql/test/test_mysql.py
r3 r4 15 15 opts['passwd'] = raw_input("Enter the password for the MySQL '%s' user:" 16 16 % opts['user']) 17 SM_class = "mysql"17 DB_class = "mysql" 18 18 19 19 def run(): … … 24 24 opts['encoding'] = "latin1" 25 25 reload(zoo_fixture) 26 zoo_fixture.init() 27 zoo_fixture.run(SM_class, opts) 26 zoo_fixture.run(DB_class, 'geniusql_test', opts) 28 27 29 28 print … … 31 30 opts['encoding'] = "utf8" 32 31 reload(zoo_fixture) 33 zoo_fixture.init() 34 zoo_fixture.run(SM_class, opts) 32 zoo_fixture.run(DB_class, 'geniusql_test', opts) 35 33 36 34 if __name__ == "__main__": trunk/geniusql/test/test_psycopg.py
r3 r4 22 22 "user=%s password=%s" % (user, passwd)), 23 23 } 24 SM_class = "psycopg"24 DB_class = "psycopg" 25 25 26 26 del user, passwd … … 33 33 opts['encoding'] = "SQL_ASCII" 34 34 reload(zoo_fixture) 35 zoo_fixture.init() 36 zoo_fixture.run(SM_class, opts) 35 zoo_fixture.run(DB_class, 'geniusql_test', opts) 37 36 38 37 print … … 40 39 opts['encoding'] = "UNICODE" 41 40 reload(zoo_fixture) 42 zoo_fixture.init() 43 zoo_fixture.run(SM_class, opts) 41 zoo_fixture.run(DB_class, 'geniusql_test', opts) 44 42 45 43 if __name__ == "__main__": trunk/geniusql/test/test_sqlite.py
r3 r4 21 21 22 22 if _sqlite: 23 SM_class = "sqlite"23 DB_class = "sqlite" 24 24 opts = {"Database": dbpath} 25 25 … … 28 28 # Isolate schema changes from one test to the next. 29 29 reload(zoo_fixture) 30 zoo_fixture.init() 31 zoo_fixture.run(SM_class, opts) 30 zoo_fixture.run(DB_class, opts['Database'], opts) 32 31 33 32 print … … 35 34 opts['Perfect Dates'] = True 36 35 reload(zoo_fixture) 37 zoo_fixture.init() 38 zoo_fixture.run(SM_class, opts) 36 zoo_fixture.run(DB_class, opts['Database'], opts) 39 37 opts['Perfect Dates'] = False 40 38 … … 43 41 opts['Database'] = ':memory:' 44 42 reload(zoo_fixture) 45 zoo_fixture.init() 46 zoo_fixture.run(SM_class, opts) 43 zoo_fixture.run(DB_class, opts['Database'], opts) 47 44 48 45 print … … 51 48 opts['Type Adapter'] = "geniusql.providers.sqlite.TypeAdapterSQLiteTypeless" 52 49 reload(zoo_fixture) 53 zoo_fixture.init() 54 zoo_fixture.run(SM_class, opts) 50 zoo_fixture.run(DB_class, opts['Database'], opts) 55 51 56 52 if __name__ == "__main__": trunk/geniusql/test/test_sqlserver.py
r3 r4 8 8 "The MSAccess test will not be run.") 9 9 else: 10 from geniusq .providers import ado10 from geniusql.providers import ado 11 11 try: 12 12 ado.gen_py() … … 23 23 u'CommandTimeout': 10, 24 24 } 25 SM_class = "sqlserver"25 DB_class = "sqlserver" 26 26 27 27 def run(): … … 29 29 # Isolate schema changes from one test to the next. 30 30 reload(zoo_fixture) 31 zoo_fixture.init() 32 zoo_fixture.run(SM_class, opts) 31 zoo_fixture.run(DB_class, "geniusql_test", opts) 33 32 34 33 if __name__ == "__main__": trunk/geniusql/test/zoo_fixture.py
r3 r4 35 35 36 36 def test_1_create_tables(self): 37 Animal = db.make_table('Animal') 38 39 Animal['ID'] = c = db.make_column('Animal', 'ID', int) 40 c.autoincrement = True 41 c.key = True 42 Animal.indices['ID'] = db.make_index('Animal', 'ID') 43 44 Animal['ZooID'] = db.make_column('Animal', 'ZooID', int) 45 Animal.indices['ZooID'] = db.make_index('Animal', 'ZooID') 46 47 Animal['Species'] = db.make_column('Animal', 'Species', hints={'bytes': 100}) 48 Animal['Legs'] = db.make_column('Animal', 'Legs', int, default=4) 49 Animal['PreviousZoos'] = db.make_column('Animal', 'PreviousZoos', list, hints={'bytes': 8000}) 50 Animal['LastEscape'] = db.make_column('Animal', 'LastEscape', datetime.datetime) 51 Animal['Lifespan'] = db.make_column('Animal', 'Lifespan', float, hints={'precision': 4}) 52 Animal['Age'] = db.make_column('Animal', 'Age', float, default=1, hints={'precision': 4}) 53 Animal['MotherID'] = db.make_column('Animal', 'MotherID', int) 54 Animal['PreferredFoodID'] = db.make_column('Animal', 'PreferredFoodID', int) 55 Animal['AlternateFoodID'] = db.make_column('Animal', 'AlternateFoodID', int) 56 37 Animal = db.table('Animal') 38 Animal['ID'] = db.column(int, autoincrement=True, key=True) 39 Animal['ZooID'] = db.column(int) 40 Animal['Species'] = db.column(hints={'bytes': 100}) 41 Animal['Legs'] = db.column(int, default=4) 42 Animal['PreviousZoos'] = db.column(list, hints={'bytes': 8000}) 43 Animal['LastEscape'] = db.column(datetime.datetime) 44 Animal['Lifespan'] = db.column(float, hints={'precision': 4}) 45 Animal['Age'] = db.column(float, default=1, hints={'precision': 4}) 46 Animal['MotherID'] = db.column(int) 47 Animal['PreferredFoodID'] = db.column(int) 48 Animal['AlternateFoodID'] = db.column(int) 49 Animal.add_index('ID') 50 Animal.add_index('ZooID') 57 51 Animal.references['Animal'] = ('ID', 'Animal', 'MotherID') 58 59 52 db['Animal'] = Animal 60 53 61 ## class Zoo(Unit): 62 ## Name = UnitProperty() 63 ## Founded = UnitProperty(datetime.date) 64 ## Opens = UnitProperty(datetime.time) 65 ## LastEscape = UnitProperty(datetime.datetime) 66 ## 67 ## if typerefs.fixedpoint: 68 ## # Explicitly set precision and scale so test_storemsaccess 69 ## # can test CURRENCY type 70 ## Admission = UnitProperty(typerefs.fixedpoint.FixedPoint, 71 ## hints={'precision': 4, 'scale': 2}) 72 ## else: 73 ## Admission = UnitProperty(float) 74 ## 75 ## Zoo.one_to_many('ID', Animal, 'ZooID') 76 ## 77 ## class AlternateFoodAssociation(UnitAssociation): 78 ## to_many = False 79 ## register = False 80 ## 81 ## def related(self, unit, expr=None): 82 ## food = unit.sandbox.unit(Food, ID=unit.AlternateFoodID) 83 ## return food 84 ## 85 ## class Food(Unit): 86 ## """A food item.""" 87 ## Name = UnitProperty() 88 ## NutritionValue = UnitProperty(int) 89 ## 90 ## Food.one_to_many('ID', Animal, 'PreferredFoodID') 91 ## 92 ## descriptor = AlternateFoodAssociation('AlternateFoodID', Food, 'ID') 93 ## descriptor.nearClass = Animal 94 ## Animal._associations['Alternate Food'] = descriptor 95 ## Animal.AlternateFood = descriptor 96 ## del descriptor 97 ## 54 Zoo = db.table('Zoo') 55 Zoo['ID'] = db.column(int, autoincrement=True, key=True) 56 Zoo['Name'] = db.column() 57 Zoo['Founded'] = db.column(datetime.date) 58 Zoo['Opens'] = db.column(datetime.time) 59 Zoo['LastEscape'] = db.column(datetime.datetime) 60 61 if typerefs.fixedpoint: 62 # Explicitly set precision and scale so test_msaccess 63 # can test CURRENCY type 64 Zoo['Admission'] = db.column(typerefs.fixedpoint.FixedPoint, 65 hints={'precision': 4, 'scale': 2}) 66 else: 67 Zoo['Admission'] = db.column(float) 68 69 Zoo.add_index('ID') 70 Zoo.references['Animal'] = ('ID', 'Animal', 'ZooID') 71 db['Zoo'] = Zoo 72 73 Food = db.table('Food') 74 Food['ID'] = db.column(int, autoincrement=True, key=True) 75 Food['Name'] = db.column() 76 Food['NutritionValue'] = db.column(int) 77 Food.add_index('ID') 78 Food.references['Animal'] = ('ID', 'Animal', 'PreferredFoodID') 79 Animal.references['Alternate Food'] = ('AlternateFoodID', 'Food', 'ID') 80 db['Food'] = Food 81 98 82 ## class Vet(Unit): 99 83 ## """A Veterinarian.""" … … 161 145 162 146 def test_2_populate(self): 163 ## # Notice this also tests that: a Unit which is only 164 ## # dirtied via __init__ is still saved. 165 ## WAP = Zoo(Name = 'Wild Animal Park', 166 ## Founded = datetime.date(2000, 1, 1), 167 ## # 59 can give rounding errors with divmod, which 168 ## # AdapterFromADO needs to correct. 169 ## Opens = datetime.time(8, 15, 59), 170 ## LastEscape = datetime.datetime(2004, 7, 29, 5, 6, 7), 171 ## Admission = "4.95", 172 ## ) 173 ## box.memorize(WAP) 174 ## # The object should get an ID automatically. 175 ## self.assertNotEqual(WAP.ID, None) 176 ## 177 ## SDZ = Zoo(Name = 'San Diego Zoo', 178 ## # This early date should play havoc with a number 179 ## # of implementations. 180 ## Founded = datetime.date(1835, 9, 13), 181 ## Opens = datetime.time(9, 0, 0), 182 ## Admission = "0", 183 ## ) 184 ## box.memorize(SDZ) 185 ## # The object should get an ID automatically. 186 ## self.assertNotEqual(SDZ.ID, None) 187 ## 188 ## Biodome = Zoo(Name = u'Montr\xe9al Biod\xf4me', 189 ## Founded = datetime.date(1992, 6, 19), 190 ## Opens = datetime.time(9, 0, 0), 191 ## Admission = "11.75", 192 ## ) 193 ## box.memorize(Biodome) 194 ## 195 ## seaworld = Zoo(Name = 'Sea_World', Admission = "60") 196 ## box.memorize(seaworld) 197 #### 198 #### mostly_empty = Zoo(Name = 'The Mostly Empty Zoo' + (" " * 255)) 199 #### box.memorize(mostly_empty) 200 ## 147 newids = db.insert('Zoo', Name='Wild Animal Park', 148 Founded=datetime.date(2000, 1, 1), 149 # 59 can give rounding errors with divmod, which 150 # AdapterFromADO needs to correct. 151 Opens=datetime.time(8, 15, 59), 152 LastEscape=datetime.datetime(2004, 7, 29, 5, 6, 7), 153 Admission=4.95, 154 ) 155 wapid=int(newids['ID']) 156 157 db.insert('Zoo', Name = 'San Diego Zoo', 158 # This early date should play havoc with a number 159 # of implementations. 160 Founded = datetime.date(1835, 9, 13), 161 Opens = datetime.time(9, 0, 0), 162 Admission = 0, 163 ) 164 165 db.insert('Zoo', Name = u'Montr\xe9al Biod\xf4me', 166 Founded = datetime.date(1992, 6, 19), 167 Opens = datetime.time(9, 0, 0), 168 Admission = 11.75, 169 ) 170 171 db.insert('Zoo', Name = 'Sea_World', Admission = 60) 172 201 173 # Animals 202 174 newids = db.insert('Animal', Species='Leopard', Lifespan=73.5) 203 self.assertEqual(newids['ID'], 1) 204 205 ## leopard.add(WAP) 206 db.save('Animal', ID=int(newids['ID']), 175 leopardid = int(newids['ID']) 176 self.assertEqual(leopardid, 1) 177 db.save('Animal', ID=leopardid, ZooID=wapid, 207 178 LastEscape=datetime.datetime(2004, 12, 21, 8, 15, 0, 999907)) 208 ## 209 ## lion = Animal(Species='Lion', ZooID=WAP.ID) 210 ## box.memorize(lion) 211 ## 212 ## box.memorize(Animal(Species='Slug', Legs=1, Lifespan=.75, 213 ## # Test our 8000-byte limit 214 ## PreviousZoos=["f" * (8000 - 14)])) 215 ## 216 ## tiger = Animal(Species='Tiger', PreviousZoos=['animal\\universe']) 217 ## box.memorize(tiger) 179 180 db.insert('Animal', Species='Lion', ZooID=wapid) 181 db.insert('Animal', Species='Slug', Legs=1, Lifespan=.75, 182 # Test our 8000-byte limit 183 PreviousZoos=["f" * (8000 - 14)]) 184 185 db.insert('Animal', Species='Tiger', PreviousZoos=['animal\\universe']) 218 186 ## 219 187 ## # Override Legs.default with itself just to make sure it works.
