Hi,
I'm trying to port my apps to use ORACLE. So, I have a table, e.g.
t_primary_dataset which defined as:
t_primary_dataset = Table('t_primary_dataset', engine,
Column('id', Integer, nullable = False, primary_key = True),
Column('name', String(100), nullable = False)
)
I defined class (in capitals) and a mapper for this table. Then I used
the following code to insert data into this table:
session = create_session()
transaction = session.create_transaction()
try:
tp = T_PRIMARY_DATASET(datasetName)
session.save(tp)
session.flush()
except Exception, ex:
transaction.rollback()
raise DbsDatabaseError(args=ex)
transaction.commit()
The code above works just fine with SQLite, MySQL with the following output:
[2006-06-14 13:46:14,524] [engine]: BEGIN
[2006-06-14 13:46:14,525] [engine]: INSERT INTO t_primary_dataset
(name) VALUES (?)
[2006-06-14 13:46:14,525] [engine]: ['ThisIsATestDatasetf']
[2006-06-14 13:46:14,526] [engine]: COMMIT
[2006-06-14 13:46:14,537] [engine]: COMMIT
But when I used ORACLE, I got the following:
[2006-06-14 13:46:40,421] [engine]: BEGIN
[2006-06-14 13:46:40,422] [engine]: INSERT INTO t_primary_dataset (id,
name) VALUES (:id, :name)
[2006-06-14 13:46:40,423] [engine]: {'id': None, 'name': 'ThisIsATestDatasetf'}
[2006-06-14 13:46:40,430] [engine]: ROLLBACK
[2006-06-14 13:46:40,433] [engine]: ROLLBACK
Traceback (most recent call last):
File "/home/vk/CMS/DBS/work/prototype/DBSSchema/DBSManager.py", line
528, in createPrimaryDataset
session.flush()
File "build/bdist.linux-i686/egg/sqlalchemy/orm/session.py", line
233, in flush
File "build/bdist.linux-i686/egg/sqlalchemy/orm/unitofwork.py", line
252, in flush
File "build/bdist.linux-i686/egg/sqlalchemy/orm/unitofwork.py", line
420, in execute
File "build/bdist.linux-i686/egg/sqlalchemy/orm/unitofwork.py", line
695, in execute
File "build/bdist.linux-i686/egg/sqlalchemy/orm/unitofwork.py", line
645, in _save_objects
File "build/bdist.linux-i686/egg/sqlalchemy/orm/mapper.py", line
661, in save_obj
File "build/bdist.linux-i686/egg/sqlalchemy/engine/base.py", line
240, in execute
File "build/bdist.linux-i686/egg/sqlalchemy/engine/base.py", line
264, in execute_clauseelement
File "build/bdist.linux-i686/egg/sqlalchemy/engine/base.py", line
280, in execute_compiled
File "build/bdist.linux-i686/egg/sqlalchemy/engine/base.py", line
276, in proxy
File "build/bdist.linux-i686/egg/sqlalchemy/engine/base.py", line
315, in _execute_raw
File "build/bdist.linux-i686/egg/sqlalchemy/engine/base.py", line
334, in _execute
sqlalchemy.exceptions.SQLError: (DatabaseError) ORA-01400: cannot
insert NULL into ("MYDB"."T_PRIMARY_DATASET"."ID")
'INSERT INTO t_primary_dataset (id, name) VALUES (:id, :name)' {'id':
None, 'name': 'ThisIsATestDatasetf'}
The difference is that in the case of ORACLE the insert statement use
explicitly id and pass None to id. In the case of SQLite/MySQL id is
created automatically by DB for my insert.
Could someone tell me what's wrong.
Thanks,
Valentin.
--
Thank you,
Valentin
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users