From 2e05e1c54de196d6c3958f8122b7f474f3a54f2a Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Fri, 26 Mar 2010 20:19:18 +0000 Subject: [PATCH] new module for Feature #61 --- lib/core/replication.py | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 lib/core/replication.py diff --git a/lib/core/replication.py b/lib/core/replication.py new file mode 100644 index 000000000..a33a5e425 --- /dev/null +++ b/lib/core/replication.py @@ -0,0 +1,47 @@ +import sqlite3 + + +class Replication: + def __init__(self, dbpath): + self.dbpath = dbpath + self.connection = sqlite3.connect(dbpath) + self.connection.isolation_level = None + self.cursor = self.connection.cursor() + + class DataType: + def __init__(self, name): + self.name = name + + def __str__(self): + return self.name + + def __repr__(self): + return "" % self + + class Table: + def __init__(self, parent, name, columns, typeless=False): + self.parent = parent + self.name = name + self.columns = columns + if not typeless: + self.parent.cursor.execute('CREATE TABLE %s (%s)' % (name, ','.join('%s %s' % (colname, coltype) for colname, coltype in columns))) + else: + self.parent.cursor.execute('CREATE TABLE %s (%s)' % (name, ','.join(colname for colname in columns))) + + def insert(self, rows): + self.parent.cursor.executemany('INSERT INTO %s VALUES (?,?,?,?,?)' % self.name, rows) + + + NULL = DataType('NULL') + INTEGER = DataType('INTEGER') + REAL = DataType('REAL') + TEXT = DataType('TEXT') + BLOB = DataType('BLOB') + + def createTable(self, name, columns): + return Table(self, name, columns) + + def __del__(self): + self.cursor.close() + self.connection.close() + \ No newline at end of file