summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@archlinux.org>2016-08-04 21:00:50 +0200
committerLukas Fleischer <lfleischer@archlinux.org>2016-08-05 12:05:22 +0200
commit27631f1157226bd9ca4d0dbfb6a59c7656e7e361 (patch)
tree3c393a62029829a61c1ed92ca4b6814b08da9a86
parentecbf32f0cc4673c56380a97a0097187924d47624 (diff)
downloadaurweb-27631f1157226bd9ca4d0dbfb6a59c7656e7e361.tar.xz
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 <lfleischer@archlinux.org>
-rwxr-xr-xgit-interface/git-auth.py5
-rwxr-xr-xgit-interface/git-update.py13
2 files changed, 11 insertions, 7 deletions
diff --git a/git-interface/git-auth.py b/git-interface/git-auth.py
index ebdc75c..45fd577 100755
--- a/git-interface/git-auth.py
+++ b/git-interface/git-auth.py
@@ -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)
diff --git a/git-interface/git-update.py b/git-interface/git-update.py
index 9a127a9..d6c9f10 100755
--- a/git-interface/git-update.py
+++ b/git-interface/git-update.py
@@ -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()]