Merge pull request #270 from niphlod/fix/dal_reference

fix for references, DAL tests pass also on MSSQL now
This commit is contained in:
mdipierro
2013-10-21 19:31:50 -07:00
2 changed files with 13 additions and 3 deletions
+1 -1
View File
@@ -1261,7 +1261,7 @@ class BaseAdapter(ConnectionPool):
return dict([(k[0].name, k[1]) for k in fields \ return dict([(k[0].name, k[1]) for k in fields \
if k[0].name in table._primarykey]) if k[0].name in table._primarykey])
id = self.lastrowid(table) id = self.lastrowid(table)
if not isinstance(id,int): if not isinstance(id, (int, long)):
return id return id
rid = Reference(id) rid = Reference(id)
(rid._table, rid._record) = (table, None) (rid._table, rid._record) = (table, None)
+12 -2
View File
@@ -559,8 +559,13 @@ class TestMigrations(unittest.TestCase):
class TestReference(unittest.TestCase): class TestReference(unittest.TestCase):
def testRun(self): def testRun(self):
db = DAL(DEFAULT_URI, check_reserved=['all']) db = DAL(DEFAULT_URI, check_reserved=['all'])
if DEFAULT_URI.startswith('mssql'):
#multiple cascade gotcha
for key in ['reference','reference FK']:
db._adapter.types[key]=db._adapter.types[key].replace(
'%(on_delete_action)s','NO ACTION')
db.define_table('tt', Field('name'), Field('aa','reference tt')) db.define_table('tt', Field('name'), Field('aa','reference tt'))
db.commit() db.commit()
x = db.tt.insert(name='max') x = db.tt.insert(name='max')
@@ -836,7 +841,7 @@ class TestValidateAndInsert(unittest.TestCase):
db.val_and_insert.drop() db.val_and_insert.drop()
class TestZRName(unittest.TestCase): class TestRName(unittest.TestCase):
""" """
tests for highly experimental rname attribute tests for highly experimental rname attribute
""" """
@@ -946,6 +951,11 @@ class TestZRName(unittest.TestCase):
self.assertEqual(rtn[2].pet.name, 'Gertie') self.assertEqual(rtn[2].pet.name, 'Gertie')
#aliases #aliases
if DEFAULT_URI.startswith('mssql'):
#multiple cascade gotcha
for key in ['reference','reference FK']:
db._adapter.types[key]=db._adapter.types[key].replace(
'%(on_delete_action)s','NO ACTION')
rname = db._adapter.QUOTE_TEMPLATE % 'the cubs' rname = db._adapter.QUOTE_TEMPLATE % 'the cubs'
db.define_table('pet_farm', db.define_table('pet_farm',
Field('name'), Field('name'),