From 9f846dbe3c1588a0d71f452d0afa512a838bbb12 Mon Sep 17 00:00:00 2001 From: niphlod Date: Mon, 21 Oct 2013 12:09:47 -0700 Subject: [PATCH] fix for references, DAL tests pass also on MSSQL now --- gluon/dal.py | 2 +- gluon/tests/test_dal.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/gluon/dal.py b/gluon/dal.py index 6f4b6f19..7c05faa9 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -1261,7 +1261,7 @@ class BaseAdapter(ConnectionPool): return dict([(k[0].name, k[1]) for k in fields \ if k[0].name in table._primarykey]) id = self.lastrowid(table) - if not isinstance(id,int): + if not isinstance(id, (int, long)): return id rid = Reference(id) (rid._table, rid._record) = (table, None) diff --git a/gluon/tests/test_dal.py b/gluon/tests/test_dal.py index bea336e1..d9bbbad0 100644 --- a/gluon/tests/test_dal.py +++ b/gluon/tests/test_dal.py @@ -559,8 +559,13 @@ class TestMigrations(unittest.TestCase): class TestReference(unittest.TestCase): - def testRun(self): + def testRun(self): 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.commit() x = db.tt.insert(name='max') @@ -836,7 +841,7 @@ class TestValidateAndInsert(unittest.TestCase): db.val_and_insert.drop() -class TestZRName(unittest.TestCase): +class TestRName(unittest.TestCase): """ tests for highly experimental rname attribute """ @@ -946,6 +951,11 @@ class TestZRName(unittest.TestCase): self.assertEqual(rtn[2].pet.name, 'Gertie') #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' db.define_table('pet_farm', Field('name'),