Fri, 30 Aug 2002 17:13:15 +0200
If I understood the question here correctly - I am looking for answer to it
I am using PostgreSQL however, but I have tables with fields whose default
values are taken from sequence. Since I need to know the primary key
value for record directly after insertion, I am fetching next value from
seperately, and only then inserting the row into table with primary key
Is there a way to easily fetch the field values for inserted row after
Senior system analyst
TietoEnator Financial Solutions
41 Lacplesa Str.
Riga, LV-1011, Latvia
Tel: +371 7286660
Fax: +371 7243000
> -----Original Message-----
> From: firstname.lastname@example.org
> [mailto:email@example.com]On Behalf Of firstname.lastname@example.org
> Sent: piektdiena, 2002. gada 30. august? 17:17
> To: email@example.com
> Subject: [DB-SIG]
> Hallo everybody,
> I'm developing yet another web-based interface to an Oracle database
> using Python and DCOracle2. I would like to write as little
> implementation-dependent code as possible. In this attempt, I miss
> something in the API.
> my question is about automatically generated primary keys.
> when I let the database generate the primary keys (the
> technique involved
> is implementation-dependent), how on earth do I retrieve the
> keys of my
> newly inserted record?
> in practice:
> >>> import DCOracle2
> >>> db = DCOracle2.connect('user/password@service')
> >>> crsr = db.cursor()
> >>> crsr.execute("insert into persone (nome, cognome,
> datanascita) values ('Ave', 'Ninchi', '14-Dic-1915')")
> here the method returns a value, but I assume that this is only to be
> used by the ones how developed the DCOracle2 package.
> how do I retrieve the primary key of the 'Ave Ninchi' record?
> the cursor.execute method can be used to prepare a SELECT and thus,
> it makes sense to ask the cursor to fetchxxx what was prepared by the
> executexxx. this is what I tried, with no luck:
> dco2.ProgrammingError: No results available from last execute
> maybe this possibility is offered somewhere else, but I don't
> find it in
> the documentation of the API. if it is not there, what about
> the API by requiring the execute('INSERT ...') to prepare the
> cursor as
> if the user had asked to execute('SELECT <primary keys> ...')?
> the other option, as far as I can understand, is not to use any
> automatically generated primary keys and do all the work from inside
> Python. Whenever I try to insert any object into a table, I should
> check if the primary keys are defined, if that is not the
> case, generate
> them in my Python program and only then put the object into
> the database.
> I don't like this solution (in practice, it forces me to accesses
> the database *only* from the Python program) I wonder if there was a
> discussion on this regard and if the API2 reflects the results of the
> thanks for your time,
> Mario Frasca
> DB-SIG maillist - DB-SIG@python.org