def __init__(self, dbName, tablePrefix='', timeout=1000): SqliteDb.__init__(self) tablePrefix = tablePrefix.strip() if tablePrefix and not tablePrefix.endswith( '_'): # Avoid having _ for empty prefix tablePrefix += '_' #NOTE (Jose Miguel, 2014/01/02 # Reusing connections is a bit dangerous, since it have lead to # unexpected and hard to trace errors due to using an out-of-date # reused connection. That's why we are changing now the default to False # and only setting to True when the tablePrefix is non-empty, which is the # case for classes that are different tables in the same db and it logical # to reuse the connection. if tablePrefix: self._reuseConnections = True else: self._reuseConnections = False #True self.CHECK_TABLES = "SELECT name FROM sqlite_master WHERE type='table' AND name='%sObjects';" % tablePrefix self.SELECT = "SELECT * FROM %sObjects WHERE " % tablePrefix self.FROM = "FROM %sObjects" % tablePrefix self.DELETE = "DELETE FROM %sObjects WHERE " % tablePrefix self.INSERT_CLASS = "INSERT INTO %sClasses (label_property, column_name, class_name) VALUES (?, ?, ?)" % tablePrefix self.SELECT_CLASS = "SELECT * FROM %sClasses;" % tablePrefix self.tablePrefix = tablePrefix self._createConnection(dbName, timeout) self.INSERT_OBJECT = None self.UPDATE_OBJECT = None self._columnsMapping = {} self.INSERT_PROPERTY = "INSERT INTO Properties (key, value) VALUES (?, ?)" self.DELETE_PROPERTY = "DELETE FROM Properties WHERE key=?" self.UPDATE_PROPERTY = "UPDATE Properties SET value=? WHERE key=?" self.SELECT_PROPERTY = "SELECT value FROM Properties WHERE key=?" self.SELECT_PROPERTY_KEYS = "SELECT key FROM Properties"
def __init__(self, dbName, tablePrefix='', timeout=1000): SqliteDb.__init__(self) tablePrefix = tablePrefix.strip() if tablePrefix and not tablePrefix.endswith('_'): # Avoid having _ for empty prefix tablePrefix += '_' #NOTE (Jose Miguel, 2014/01/02 # Reusing connections is a bit dangerous, since it have lead to # unexpected and hard to trace errors due to using an out-of-date # reused connection. That's why we are changing now the default to False # and only setting to True when the tablePrefix is non-empty, which is the # case for classes that are different tables in the same db and it logical # to reuse the connection. if tablePrefix: self._reuseConnections = True else: self._reuseConnections = False#True self.CHECK_TABLES = "SELECT name FROM sqlite_master WHERE type='table' AND name='%sObjects';" % tablePrefix self.SELECT = "SELECT * FROM %sObjects WHERE " % tablePrefix self.FROM = "FROM %sObjects" % tablePrefix self.DELETE = "DELETE FROM %sObjects WHERE " % tablePrefix self.INSERT_CLASS = "INSERT INTO %sClasses (label_property, column_name, class_name) VALUES (?, ?, ?)" % tablePrefix self.SELECT_CLASS = "SELECT * FROM %sClasses;" % tablePrefix self.tablePrefix = tablePrefix self._createConnection(dbName, timeout) self.INSERT_OBJECT = None self.UPDATE_OBJECT = None self._columnsMapping = {} self.INSERT_PROPERTY = "INSERT INTO Properties (key, value) VALUES (?, ?)" self.DELETE_PROPERTY = "DELETE FROM Properties WHERE key=?" self.UPDATE_PROPERTY = "UPDATE Properties SET value=? WHERE key=?" self.SELECT_PROPERTY = "SELECT value FROM Properties WHERE key=?" self.SELECT_PROPERTY_KEYS = "SELECT key FROM Properties"
def __init__(self, dbName, timeout=1000): SqliteDb.__init__(self) self._createConnection(dbName, timeout) self._initialize()