Changeset 188
- Timestamp:
- 10/03/07 16:52:11
- Files:
-
- trunk/geniusql/providers/mysql.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/geniusql/providers/mysql.py
r187 r188 378 378 else: 379 379 self.drop_primary() 380 380 381 def insert(self, **kwargs): 382 """Insert a row and return it, including any new identifiers.""" 383 # MySQL interprets "INSERT INTO x (ID) VALUES (0)" to mean 384 # "use the next available number in the sequence" if 385 # x is AUTO_INCREMENT. 386 for key, col in self.iteritems(): 387 if col.autoincrement and kwargs.get(key, None) == 0: 388 raise ValueError("MySQL does not allow manually setting an " 389 "AUTO_INCREMENT column value to 0.") 390 return geniusql.Table.insert(self, **kwargs) 381 391 382 392 … … 444 454 for colkey, col in table.iteritems(): 445 455 fields.append(self.columnclause(col)) 446 447 456 if col.autoincrement: 448 # INSERT INTO t (c) VALUES(0) doesn't work for some reason 449 if col.initial > 1: 457 if col.initial != 1: 450 458 incr_fields.append(col) 459 if col.initial < 1: 460 errors.warn("MySQL interprets manually setting an " 461 "AUTO_INCREMENT column value to 0 as " 462 "'use the next available value in the " 463 "sequence'. By setting %s.initial to %r, " 464 "there is a slight chance you will " 465 "encounter this in the future." % 466 (col.name, col.initial)) 451 467 452 468 if col.key: … … 669 685 def drop(self): 670 686 conn = self.connections._get_conn(master=True) 671 self.execute_ddl('DROP DATABASE %s;' % self.qname, conn) 672 conn.close() 673 687 try: 688 try: 689 self.execute_ddl('DROP DATABASE %s;' % self.qname, conn) 690 except _mysql.OperationalError, x: 691 # OperationalError: (1008, "Can't drop database 692 # 'dejavu_test'; database doesn't exist") 693 if x.args[0] == 1008: 694 raise errors.MappingError(x.args[1]) 695 finally: 696 conn.close() 697
