Commit 27631f11 authored by Lukas Fleischer's avatar Lukas Fleischer
Browse files

git-interface: Do not use rowcount



Avoid using Cursor.rowcount to obtain the number of rows returned by a
SELECT statement as this is not guaranteed to be supported by every
database engine.

Signed-off-by: Lukas Fleischer's avatarLukas Fleischer <lfleischer@archlinux.org>
parent ecbf32f0
......@@ -40,10 +40,11 @@ cur = conn.execute("SELECT Users.Username, Users.AccountTypeID FROM Users " +
"WHERE SSHPubKeys.PubKey = ? AND Users.Suspended = 0",
(keytype + " " + keytext,))
if cur.rowcount != 1:
row = cur.fetchone()
if not row or cur.fetchone():
exit(1)
user, account_type = cur.fetchone()
user, account_type = row
if not re.match(username_regex, user):
exit(1)
......
......@@ -140,8 +140,9 @@ def save_metadata(metadata, conn, user):
for license in pkginfo['license']:
cur = conn.execute("SELECT ID FROM Licenses WHERE Name = ?",
[license])
if cur.rowcount == 1:
licenseid = cur.fetchone()[0]
row = cur.fetchone()
if row:
licenseid = row[0]
else:
cur = conn.execute("INSERT INTO Licenses (Name) " +
"VALUES (?)", [license])
......@@ -156,8 +157,9 @@ def save_metadata(metadata, conn, user):
for group in pkginfo['groups']:
cur = conn.execute("SELECT ID FROM Groups WHERE Name = ?",
[group])
if cur.rowcount == 1:
groupid = cur.fetchone()[0]
row = cur.fetchone()
if row:
groupid = row[0]
else:
cur = conn.execute("INSERT INTO Groups (Name) VALUES (?)",
[group])
......@@ -329,7 +331,8 @@ if metadata_pkgbase != pkgbase:
# Ensure that packages are neither blacklisted nor overwritten.
pkgbase = metadata['pkgbase']
cur = conn.execute("SELECT ID FROM PackageBases WHERE Name = ?", [pkgbase])
pkgbase_id = cur.fetchone()[0] if cur.rowcount == 1 else 0
row = cur.fetchone()
pkgbase_id = row[0] if row else 0
cur = conn.execute("SELECT Name FROM PackageBlacklist")
blacklist = [row[0] for row in cur.fetchall()]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment