Пример #1
0
 def record_count(self):
     err_originator_desc = 'sqlite record count operation'
     try:
         self.cursor.execute("SELECT COUNT(*) FROM " + self.table_name)
         return self.cursor.fetchone()[0]
     except sqlite3.ProgrammingError as e:
         self.db_connect.close()
         store_log([err_originator_desc, e])
     except Exception as e:
         store_log([err_originator_desc, e])
Пример #2
0
 def open_output_file(self):
     err_originator_desc = 'opening sqlite db'
     try:
         self.db_connect = sqlite3.connect(self.db_path, self.db_timeout)
         self.cursor = self.db_connect.cursor()
         self.cursor.execute("CREATE TABLE IF NOT EXISTS " + self.table_name + " (timestamp INTEGER, buy DOUBLE, sell DOUBLE)")
     except sqlite3.ProgrammingError as e:
         store_log([err_originator_desc, e])
     except Exception as e:
         store_log([err_originator_desc, e])
Пример #3
0
    def __init__(self, _output_path):
        err_originator_desc = 'initializing sqlite_obj'
        self.db_path = _output_path
        self.table_name = 'trade_data'
        self.db_timeout = 15

        # establish initial connection to db
        try:
            self.db_connect = sqlite3.connect(self.db_path, self.db_timeout)
            self.cursor = self.db_connect.cursor()
            self.cursor.execute("CREATE TABLE IF NOT EXISTS " + self.table_name + " (timestamp INTEGER, buy DOUBLE, sell DOUBLE)")
        except sqlite3.ProgrammingError as e:
            store_log([err_originator_desc, e])
        except Exception as e:
            store_log([err_originator_desc, e])
Пример #4
0
 def store_output(self, _timestamp, _bid, _ask):
     err_originator_desc = 'sqlite insert operation'
     try:
         self.cursor.execute("INSERT INTO " + self.table_name + " (timestamp, buy, sell) values(?,?,?)", (_timestamp, _bid, _ask))
         self.db_connect.commit()
     except sqlite3.ProgrammingError as e:
         self.db_connect.close()
         store_log([err_originator_desc, e])
     except IOError as e:
         self.db_connect.close()
         store_log([err_originator_desc, e])
     except Exception as e:
         store_log([err_originator_desc, e])