diff options
author | Helmut Grohne <helmut@subdivi.de> | 2014-03-08 17:26:53 +0100 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2014-03-08 17:26:53 +0100 |
commit | f846a2487c3d7c14f07e7f9b3d5aa0d803733ed9 (patch) | |
tree | de3bd44b06068b95881fa3a49e96451ab4b22728 /readyaml.py | |
parent | 5ccb80491346bab81414f74cd8297285083a5d8f (diff) | |
download | debian-dedup-f846a2487c3d7c14f07e7f9b3d5aa0d803733ed9.tar.gz |
get rid of lastrowid usage
On psycopg2 the lastrowid attribute is always 0. The documentation
advises to use inserted_primary_key instead, but in order to use that,
the sqlalchemy expression language must be used.
Diffstat (limited to 'readyaml.py')
-rwxr-xr-x | readyaml.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/readyaml.py b/readyaml.py index 8ba82fa..fac3c40 100755 --- a/readyaml.py +++ b/readyaml.py @@ -9,6 +9,7 @@ from debian.debian_support import version_compare import sqlalchemy import yaml +from dedup import schema from dedup.utils import configure_database_engine def readyaml(conn, stream): @@ -36,10 +37,10 @@ def readyaml(conn, stream): architecture=metadata["architecture"], source=metadata["source"], pid=pid) else: - pid = conn.execute(sqlalchemy.text("INSERT INTO package (name, version, architecture, source) VALUES (:name, :version, :architecture, :source);"), + pid = conn.execute(schema.package.insert().values( name=package, version=metadata["version"], architecture=metadata["architecture"], - source=metadata["source"]).lastrowid + source=metadata["source"])).inserted_primary_key[0] if metadata["depends"]: conn.execute(sqlalchemy.text("INSERT INTO dependency (pid, required) VALUES (:pid, :required);"), [dict(pid=pid, required=dep) @@ -48,9 +49,9 @@ def readyaml(conn, stream): if entry == "commit": return - cur = conn.execute(sqlalchemy.text("INSERT INTO content (pid, filename, size) VALUES (:pid, :filename, :size);"), + cid = conn.execute(schema.content.insert().values( pid=pid, filename=entry["name"], size=entry["size"]) - cid = cur.lastrowid + ).inserted_primary_key[0] if entry["hashes"]: conn.execute(sqlalchemy.text("INSERT INTO hash (cid, fid, hash) VALUES (:cid, :fid, :hash);"), [dict(cid=cid, fid=funcmapping[func], hash=hexhash) |