Hi all, I'm running into an exception trying to create a new row in a
table with fromDatabase = True defined (the table is pre-existing).

The class definition looks like this:

class SystemsInfo(SQLObject):
  class sqlmeta:
    fromDatabase = True
    table = 'SystemsInfo'
    idType = str
    idName = 'SystemName'
    lazyUpdate = True

So, my "id" key has been changed to SystemName.  In this particular
table, SystemName is the primary key and is not allowed to be NULL.
All other columns may be NULL.

I just want to create a bare minimum row:

  item = SystemsInfo(SystemName='uniqenname')

However, I get the following error:

  Traceback (most recent call last):
    File "./update_matrix.py", line 113, in ?
      main(sys.argv)
    File "./update_matrix.py", line 104, in main
      s = SystemsInfo(SystemName=row[0])
    File "/usr/lib/python2.4/site-packages/sqlobject/declarative.py", line 98, 
in _wrapper
      return fn(self, *args, **kwargs)
    File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 1210, in 
__init__
      self._create(id, **kw)
    File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 1241, in 
_create
      self._SO_finishCreate(id)
    File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 1268, in 
_SO_finishCreate
      self._init(id)
    File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 929, in 
_init
      assert id is not None
  AssertionError

This actually results in the row I want being added to the database,
but the error above causes my script to halt (unless I add a try/except
block around it).
   
It's an assertion, so perhaps it would go away if I called python with
-O, but... I'd rather make this warning go away completely.  Thinking
that somehow the constructor was angry because I wasn't passing an 'id'
variable, I also tried:

  item = SystemsInfo(id='uniqename').

This results in the following:

  Traceback (most recent call last):
    File "./update_matrix.py", line 112, in ?
      main(sys.argv)
    File "./update_matrix.py", line 104, in main
      item = SystemsInfo(id=row[0])
    File "/usr/lib/python2.4/site-packages/sqlobject/declarative.py", line 98, 
in _wrapper
      return fn(self, *args, **kwargs)
    File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 1210, in 
__init__
      self._create(id, **kw)
    File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 1241, in 
_create
      self._SO_finishCreate(id)
    File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 1265, in 
_SO_finishCreate
      id, names, values)
    File "/usr/lib/python2.4/site-packages/sqlobject/dbconnection.py", line 
396, in queryInsertID
      return self._runWithConnection(self._queryInsertID, soInstance, id, 
names, values)
    File "/usr/lib/python2.4/site-packages/sqlobject/dbconnection.py", line 
255, in _runWithConnection
      val = meth(conn, *args)
    File "/usr/lib/python2.4/site-packages/sqlobject/mssql/mssqlconnection.py", 
line 136, in _queryInsertID
      c.execute(q)
    File "/usr/lib/python2.4/site-packages/pymssql.py", line 126, in execute
      self.executemany(operation, (params,))
    File "/usr/lib/python2.4/site-packages/pymssql.py", line 152, in executemany
      raise DatabaseError, "internal error: %s" % self.__source.errmsg()
  pymssql.DatabaseError: internal error: SQL Server message 264, severity 16, 
state 1, line 1:
  Column name 'SystemName' appears more than once in the result column list.
  DB-Lib error message 20018, severity 5:
  General SQL Server error: Check messages from the SQL Server.

And sure, enough; when I turn on SQL debugging I see that the INSERT
query includes SystemName twice.  In the first version, there is only
one occurence of SystemName, but it is not at the beginning of the
query making me think somehow sqlobject doesn't know I am specifying
the primary key via the function argument.

Maybe I can remove SystemName from the column list somehow and stick to
using it via the id parameter which maybe should map over
transparently?

Any thoughts?

Thanks,
Ray

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to