Author: phd
Date: Tue Feb 5 13:23:32 2013
New Revision: 4581
Log:
Changed the way to get if the table has identity in MS SQL
Added:
SQLObject/trunk/sqlobject/tests/test_identity.py
Modified:
SQLObject/trunk/docs/Authors.txt
SQLObject/trunk/docs/News.txt
SQLObject/trunk/sqlobject/mssql/mssqlconnection.py
Modified: SQLObject/trunk/docs/Authors.txt
==============================================================================
--- SQLObject/trunk/docs/Authors.txt Sun Feb 3 04:23:15 2013 (r4580)
+++ SQLObject/trunk/docs/Authors.txt Tue Feb 5 13:23:32 2013 (r4581)
@@ -26,6 +26,7 @@
* Daniel Fetchinson <fetchinson at googlemail.com>
* Neil Muller <drnlmuller+sqlobject at gmail.com>
* Petr Jakes <petr.jakes at tpc.cz>
+* Andrew Ziem <ahz001 at gmail.com>
* Oleg Broytman <ph...@ph...>
.. image:: http://sflogo.sourceforge.net/sflogo.php?group_id=74338&type=10
Modified: SQLObject/trunk/docs/News.txt
==============================================================================
--- SQLObject/trunk/docs/News.txt Sun Feb 3 04:23:15 2013 (r4580)
+++ SQLObject/trunk/docs/News.txt Tue Feb 5 13:23:32 2013 (r4581)
@@ -18,7 +18,9 @@
* Optimization in PostgresConnection: use INSERT...RETURNING id
to get the autoincremented id in one query instead of two
- (SELECT id + INSERT).
+ (INSERT + SELECT id).
+
+* Changed the way to get if the table has identity in MS SQL.
SQLObject 1.3.2
===============
Modified: SQLObject/trunk/sqlobject/mssql/mssqlconnection.py
==============================================================================
--- SQLObject/trunk/sqlobject/mssql/mssqlconnection.py Sun Feb 3 04:23:15 2013 (r4580)
+++ SQLObject/trunk/sqlobject/mssql/mssqlconnection.py Tue Feb 5 13:23:32 2013 (r4581)
@@ -100,13 +100,10 @@
return con
HAS_IDENTITY = """
- SELECT col.name, col.status, obj.name
- FROM syscolumns col
- JOIN sysobjects obj
- ON obj.id = col.id
- WHERE obj.name = '%s'
- and col.autoval is not null
-
+ select 1
+ from INFORMATION_SCHEMA.COLUMNS
+ where TABLE_NAME = '%s'
+ and COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity') = 1
"""
def _hasIdentity(self, conn, table):
query = self.HAS_IDENTITY % table
Added: SQLObject/trunk/sqlobject/tests/test_identity.py
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ SQLObject/trunk/sqlobject/tests/test_identity.py Tue Feb 5 13:23:32 2013 (r4581)
@@ -0,0 +1,28 @@
+from sqlobject import *
+from sqlobject.tests.dbtest import *
+
+########################################
+## Identity (MS SQL)
+########################################
+
+class TestIdentity(SQLObject):
+ n = IntCol()
+
+def test_identity():
+ if getConnection().dbName != "mssql":
+ return
+
+ # create table
+ setupClass(TestIdentity)
+
+ # insert without giving identity
+ i1 = TestIdentity(n=100)
+ # verify result
+ i1get = TestIdentity.get(1)
+ assert(i1get.n == 100)
+
+ # insert while giving identity
+ i1 = TestIdentity(id=2, n=200)
+ # verify result
+ i2get = TestIdentity.get(2)
+ assert(i2get.n == 200)
|