new module for Feature #61

This commit is contained in:
Miroslav Stampar 2010-03-26 20:19:18 +00:00
parent 8bab94de64
commit 2e05e1c54d

47
lib/core/replication.py Normal file
View File

@ -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 "<DataType: %s>" % 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()