cocluto v1.0.22 - fixes a bug that causes quman to fail when using mysql backend
- added the method ISqlDatabaseBackend.get_last_insert_id because the actual sql function is different in sqlite (last_insert_rowid) and mysql (last_insert_id), the query is different for both backends work related to [https://bugzilla.ipr.univ-rennes.fr/show_bug.cgi?id=3093]
This commit is contained in:
parent
6974f51221
commit
eef27f1dd2
|
|
@ -79,6 +79,13 @@ class ISqlDatabaseBackend(object):
|
|||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_last_insert_id(self) -> int:
|
||||
"""
|
||||
:return: the id of the last inserted row
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
@abc.abstractmethod
|
||||
def table_exists(self, table_name: str) -> bool:
|
||||
"""returns true if the given table exists in the database
|
||||
|
|
@ -139,6 +146,12 @@ class RemoteMysqlDb(ISqlDatabaseBackend):
|
|||
rows = self._conn.store_result()
|
||||
return rows
|
||||
|
||||
def get_last_insert_id(self) -> int:
|
||||
"""
|
||||
:return: the id of the last inserted row
|
||||
"""
|
||||
return int(self.query("SELECT last_insert_id();")[0][0])
|
||||
|
||||
def table_exists(self, table_name: str) -> bool:
|
||||
rows = self.query(f"SHOW TABLES LIKE '{table_name}';")
|
||||
assert len(rows) <= 1, f'Unexpected case: more than one ({len(rows)}) tables match the table name {table_name}.'
|
||||
|
|
@ -190,6 +203,12 @@ class SshAccessedMysqlDb(ISqlDatabaseBackend):
|
|||
rows = completed_process.stdout.decode('utf-8').split('\n')
|
||||
return rows
|
||||
|
||||
def get_last_insert_id(self) -> int:
|
||||
"""
|
||||
:return: the id of the last inserted row
|
||||
"""
|
||||
return int(self.query("SELECT last_insert_id();")[0][0])
|
||||
|
||||
def table_exists(self, table_name: str) -> bool:
|
||||
rows = self.query(f"SHOW TABLES LIKE '{table_name}';")
|
||||
logging.debug('len(rows) = %d', len(rows))
|
||||
|
|
@ -274,6 +293,12 @@ class SqliteDb(ISqlDatabaseBackend):
|
|||
self._con.commit()
|
||||
return rows
|
||||
|
||||
def get_last_insert_id(self) -> int:
|
||||
"""
|
||||
:return: the id of the last inserted row
|
||||
"""
|
||||
return int(self.query("SELECT last_insert_rowid();")[0][0])
|
||||
|
||||
def table_exists(self, table_name: str) -> bool:
|
||||
rows = self.query(f"SELECT name FROM sqlite_master WHERE type='table' AND name='{table_name}';")
|
||||
assert len(rows) <= 1, f'Unexpected case: more than one ({len(rows)}) tables match the table name {table_name}.'
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ class QueueManager:
|
|||
sql_query = f"INSERT INTO log (timestamp, user_id, host_fqdn, queue_machines, action, disable_id, reason) VALUES ('{timestamp}', '{userid}', '{host_fqdn}', '{','.join(queue_machines)}', '{action}', '{disable_id}', '{reason}');"
|
||||
self.db_backend.query(sql_query)
|
||||
# get the log id of the disable action that was just inserted
|
||||
log_id = self.db_backend.query("SELECT last_insert_rowid();")[0][0]
|
||||
log_id = self.db_backend.get_last_insert_id()
|
||||
return log_id
|
||||
|
||||
def get_disable_requests(self, queue_machine: QueueMachineId) -> Dict[int, DisableRequest]:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
__version__ = '1.0.21'
|
||||
__version__ = '1.0.22'
|
||||
|
||||
|
||||
class Version(object):
|
||||
|
|
|
|||
Loading…
Reference in New Issue