]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Modified objectstore to look for primary key param values by column name not key...
authorRobert Leftwich <rtl@pobox.com>
Fri, 17 Feb 2006 12:35:52 +0000 (12:35 +0000)
committerRobert Leftwich <rtl@pobox.com>
Fri, 17 Feb 2006 12:35:52 +0000 (12:35 +0000)
lib/sqlalchemy/engine.py
test/objectstore.py

index aa8e89ca4de128d6479fb25a13d44988104998c2..8afafe6647ac1337425e8c7c18a2ba5dfeeed7b2 100644 (file)
@@ -455,16 +455,16 @@ class SQLEngine(schema.SchemaEngine):
                 for c in compiled.statement.table.c:
                     if isinstance(c.default, schema.PassiveDefault):
                         self.context.lastrow_has_defaults = True
-                    if not param.has_key(c.key) or param[c.key] is None:
+                    if not param.has_key(c.name) or param[c.name] is None:
                         newid = drunner.get_column_default(c)
                         if newid is not None:
                             param[c.key] = newid
                             if c.primary_key:
-                                last_inserted_ids.append(param[c.key])
+                                last_inserted_ids.append(param[c.name])
                         elif c.primary_key:
                             need_lastrowid = True
                     elif c.primary_key:
-                        last_inserted_ids.append(param[c.key])
+                        last_inserted_ids.append(param[c.name])
                 if need_lastrowid:
                     self.context.last_inserted_ids = None
                 else:
index f411913f71ac7968e92fe5d3d5cdb31a7d0ce0d3..2d0167498d3adbdbd8c6f3596281b8bf0146381e 100644 (file)
@@ -118,6 +118,7 @@ class PKTest(AssertMixin):
         db.echo = False
         global table
         global table2
+        global table3
         table = Table(
             'multi', db, 
             Column('multi_id', Integer, Sequence("multi_id_seq", optional=True), primary_key=True),
@@ -131,13 +132,21 @@ class PKTest(AssertMixin):
             Column('pk_col_2', String(30), primary_key=True),
             Column('data', String(30), )
             )
+        table3 = Table('multi3', db,
+            Column('pri_code', String(30), key='primary', primary_key=True),
+            Column('sec_code', String(30), key='secondary', primary_key=True),
+            Column('date_assigned', Date, key='assigned', primary_key=True),
+            Column('data', String(30), )
+            )
         table.create()
         table2.create()
+        table3.create()
         db.echo = testbase.echo
     def tearDownAll(self):
         db.echo = False
         table.drop()
         table2.drop()
+        table3.drop()
         db.echo = testbase.echo
     def setUp(self):
         objectstore.clear()
@@ -163,6 +172,18 @@ class PKTest(AssertMixin):
         e.pk_col_2 = 'pk1_related'
         e.data = 'im the data'
         objectstore.commit()
+    def testmulti_column_primary_key(self):
+        import datetime
+        class Entity(object):
+            pass
+        Entity.mapper = mapper(Entity, table3)
+        e = Entity()
+        e.primary = 'pk1'
+        e.secondary = 'pk2'
+        e.assigned = datetime.date.today()
+        e.data = 'some more data'
+        objectstore.commit()
+        
 class DefaultTest(AssertMixin):
     def setUpAll(self):
         #db.echo = 'debug'