add get_signature function for old signatures that are already in the database for all tables
This commit is contained in:
@@ -63,12 +63,29 @@ class Database:
|
||||
# print(f"Error: Unknown signature type '{table}'. Please use 'ma', 'mb', or 'mc'.")
|
||||
return self.insert_ma(old_signature)
|
||||
|
||||
def get_signature(self, old_signature: str, table: str) -> str | None:
|
||||
"""Get the new signature for the given old signature from the specified table."""
|
||||
cursor = self.connection.cursor()
|
||||
cursor.execute(
|
||||
f"SELECT new_signature FROM {table} WHERE old_signature = ?",
|
||||
(old_signature,),
|
||||
)
|
||||
result = cursor.fetchone()
|
||||
if result:
|
||||
return result[0]
|
||||
else:
|
||||
print(
|
||||
f"Error: The old_signature '{old_signature}' does not exist in the {table} table."
|
||||
)
|
||||
return None
|
||||
|
||||
def insert_ma(self, old_signature: str) -> str|None:
|
||||
"""Insert an old signature into the ma table and return the new signature.
|
||||
New Signatures is generated by using 01 / as prefix, then incrementing the number by 1 for each new entry."""
|
||||
if self.signature_exists(old_signature, "ma"):
|
||||
print(f"Error: The old_signature '{old_signature}' already exists in the ma table.")
|
||||
return None
|
||||
signature = self.get_signature(old_signature, "ma")
|
||||
return signature
|
||||
new_signature = self.create_new_signature("ma")
|
||||
try:
|
||||
cursor = self.connection.cursor()
|
||||
@@ -84,6 +101,12 @@ class Database:
|
||||
"""Insert an old signature into the mb table and return the new signature.
|
||||
New Signatures is generated by using 02 / as prefix, then incrementing the number by 1 for each new entry."""
|
||||
new_signature = self.create_new_signature("mb")
|
||||
if self.signature_exists(old_signature, "mb"):
|
||||
print(
|
||||
f"Error: The old_signature '{old_signature}' already exists in the mb table."
|
||||
)
|
||||
signature = self.get_signature(old_signature, "mb")
|
||||
return signature
|
||||
try:
|
||||
cursor = self.connection.cursor()
|
||||
cursor.execute("INSERT INTO mb (old_signature, new_signature) VALUES (?, ?)", (old_signature, new_signature))
|
||||
@@ -97,6 +120,12 @@ class Database:
|
||||
"""Insert an old signature into the mc table and return the new signature.
|
||||
New Signatures is generated by using 03 / as prefix, then incrementing the number by 1 for each new entry."""
|
||||
new_signature = self.create_new_signature("mc")
|
||||
if self.signature_exists(old_signature, "mc"):
|
||||
print(
|
||||
f"Error: The old_signature '{old_signature}' already exists in the mc table."
|
||||
)
|
||||
signature = self.get_signature(old_signature, "mc")
|
||||
return signature
|
||||
try:
|
||||
cursor = self.connection.cursor()
|
||||
cursor.execute("INSERT INTO mc (old_signature, new_signature) VALUES (?, ?)", (old_signature, new_signature))
|
||||
|
||||
Reference in New Issue
Block a user