[DB-SIG] Which db mapping tool?

Federico Di Gregorio fog@initd.org
16 Jul 2002 12:09:10 +0200


--=-tGE1iS59/icyt4pV9X0o
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: quoted-printable

Il mar, 2002-07-16 alle 11:36, Gerhard H=E4ring ha scritto:

> > as i already said on the webware ML,
>=20
> I don't have any message from you in my local archive. Maybe it was
> before I subscribed.

doh. sorry in that case.

> > psycopg (and other adapters too, i think) supports .lastrowid(),
> > exactly what you need.
>=20
> A grep on the psycopg 1.0.9 doesn't hit a string "lastrowid". And
> neither does a search on "last_" help. All I get is the last _OID_,
> which isn't exactly the same, and as I described doesn't quite work with
> MiddleKit (apart from other problems with OIDs). AFAIK (I asked on
> #postgresql) it's even not possible, and you'll have to do it in two
> steps anyway, either: nextval from sequence, then insert row, or insert
> row, then get curval from sequence.
>=20
> Am I missing something here?

psycopg 1.0.9 has lastoid(), 1.1 series lastrowid()

don't know if this is what you need but you *can* use the oid returned
by lastrowid() to access a newly inserted row. and if you want to use a
"serial" type, yes, you need a two step process to get the value but i
don't see any problem with:

    curs.execute("INSERT INTO ...")
    curs.execute("SELECT id FROM ... WHERE oid =3D %d", [curs.lastrowid()])

if you use psycopg 1.1 you can even do:

    curs.execute("INSERT INTO ... ; SELECT curval(...)")=20
    curs.fetchone()

--=20
Federico Di Gregorio
Debian GNU/Linux Developer & Italian Press Contact        fog@debian.org
INIT.D Developer                                           fog@initd.org
              La felicit=E0 =E8 una tazza di cioccolata calda. Sempre. -- I=
o

--=-tGE1iS59/icyt4pV9X0o
Content-Type: application/pgp-signature; name=signature.asc

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQA9M/DGvcCgrgZGjesRAm/fAKCkVmOF9HMdRckU8atl1iyXXhvyywCaAtoD
QMAN4w+6lwQlFHIZZejumr8=
=G2tv
-----END PGP SIGNATURE-----

--=-tGE1iS59/icyt4pV9X0o--