heh, you have a table with one column that auto-increments. when you want to INSERT into it, theres no data to insert.

I can make the INSERT statement produce wahtever syntax we want when it wants to insert a totally blank row like that. The problem is, what should the SQL be ?

You might say, INSERT INTO table (id) VALUES(null)

which probably works in SQLite.

But In postgres, you cannot specify the column in an INSERT if you want the auto-increment to take effect; it throws an error.

So what should the SQL be ? I have tried every combination of INSERT INTO table () values () etc., none of them work.

On Dec 18, 2005, at 11:46 PM, limodou wrote:

from sqlalchemy import *
import datetime

sqlite_engine = create_engine('sqlite://filename=:memory:', echo=True)

a = Table('a', sqlite_engine,
    Column('id', Integer, primary_key = True)
)
a.create()

class A(object):
    def __init__(self, id=None):
        self.id = id

A.mapper = mapper(A, a)

a = A()
objectstore.commit()

I got a Exception:


CREATE TABLE a(
        id INTEGER NOT NULL PRIMARY KEY
)


{}
INSERT INTO a () VALUES ()
[]
Traceback (most recent call last):
  File "D:\test\sqlalchemy\t6.py", line 18, in ?
    objectstore.commit()
File "c:\python24\lib\site-packages\SQLAlchemy-0.91alpha-py2.4.egg \sqlalchemy\mapping\objectstore.py",
line 76, in commit
    uow().commit(*obj)
File "c:\python24\lib\site-packages\SQLAlchemy-0.91alpha-py2.4.egg \sqlalchemy\mapping\objectstore.py",
line 256, in commit
    commit_context.execute()
File "c:\python24\lib\site-packages\SQLAlchemy-0.91alpha-py2.4.egg \sqlalchemy\mapping\objectstore.py",
line 365, in execute
    head.execute(self)
File "c:\python24\lib\site-packages\SQLAlchemy-0.91alpha-py2.4.egg \sqlalchemy\mapping\objectstore.py",
line 514, in execute
    self.mapper.save_obj(self.tosave_objects(), trans)
File "c:\python24\lib\site-packages\SQLAlchemy-0.91alpha-py2.4.egg \sqlalchemy\mapping\mapper.py",
line 481, in save_obj
    statement.execute(**params)
File "c:\python24\lib\site-packages\SQLAlchemy-0.91alpha-py2.4.egg \sqlalchemy\sql.py",
line 379, in execute
    return c.execute(*multiparams, **params)
File "c:\python24\lib\site-packages\SQLAlchemy-0.91alpha-py2.4.egg \sqlalchemy\sql.py",
line 277, in execute
    return self.engine.execute_compiled(self, params)
File "c:\python24\lib\site-packages\SQLAlchemy-0.91alpha-py2.4.egg \sqlalchemy\engine.py",
line 380, in execute_compiled
    proxy(str(compiled), parameters)
File "c:\python24\lib\site-packages\SQLAlchemy-0.91alpha-py2.4.egg \sqlalchemy\engine.py",
line 375, in proxy
    self.execute(statement, parameters, connection=connection,
cursor=cursor)
File "c:\python24\lib\site-packages\SQLAlchemy-0.91alpha-py2.4.egg \sqlalchemy\engine.py",
line 428, in execute
    self._execute(cursor, statement, parameters)
File "c:\python24\lib\site-packages\SQLAlchemy-0.91alpha-py2.4.egg \sqlalchemy\engine.py",
line 437, in _execute
    c.execute(statement, parameters)
pysqlite2.dbapi2.OperationalError: near ")": syntax error


Because id is primary_key, so at first I only created a dummy class just like:

class A(object):pass

But it raises the same exception. You can see the INSERT statment is
not correct. And

a.insert().execute(id=1)

can do the work? I don't know if it's a bug. I use above codes just
for some testing work.

--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to