bitbake: prserv: store_value() improvements

Add a test_checksum_value() to test whether
a (version, pkgarch, checksum, value) entry already
exists in the database.

This is used to protect the store_value() function from
an error when trying to store a duplicate entry in the database.

Also check whether the current database is open in read-only mode.

(Bitbake rev: b7f6c085a7cf8ac83695242a0299e2d5f7abc69a)

Signed-off-by: Michael Opdenacker <michael.opdenacker@bootlin.com>
Cc: Joshua Watt <JPEWhacker@gmail.com>
Cc: Tim Orling <ticotimo@gmail.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Michael Opdenacker
2024-05-11 16:31:33 +05:30
committed by Richard Purdie
parent 0d6dd343de
commit 3be2201de5

View File

@@ -78,6 +78,18 @@ class PRTable(object):
else:
return False
def test_checksum_value(self, version, pkgarch, checksum, value):
"""Returns whether the specified value is found in the database for the specified package, architecture and checksum"""
with closing(self.conn.cursor()) as cursor:
data=cursor.execute("SELECT value FROM %s WHERE version=? AND pkgarch=? and checksum=? and value=?;" % self.table,
(version, pkgarch, checksum, value))
row=data.fetchone()
if row is not None:
return True
else:
return False
def test_value(self, version, pkgarch, value):
"""Returns whether the specified value is found in the database for the specified package and architecture"""
@@ -143,15 +155,13 @@ class PRTable(object):
return base + ".0"
def store_value(self, version, pkgarch, checksum, value):
"""Store new value in the database"""
"""Store value in the database"""
with closing(self.conn.cursor()) as cursor:
try:
if not self.read_only and not self.test_checksum_value(version, pkgarch, checksum, value):
with closing(self.conn.cursor()) as cursor:
cursor.execute("INSERT INTO %s VALUES (?, ?, ?, ?);" % (self.table),
(version, pkgarch, checksum, value))
except sqlite3.IntegrityError as exc:
logger.error(str(exc))
self.conn.commit()
self.conn.commit()
def _get_value(self, version, pkgarch, checksum, history):