1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
import sys, StringIO, string, types
import sqlalchemy.sql as sql
import sqlalchemy.engine as engine
import sqlalchemy.schema as schema
import sqlalchemy.ansisql as ansisql
from sqlalchemy.ansisql import *
from pysqlite2 import dbapi2 as sqlite
colspecs = {
schema.INT : "INTEGER",
schema.CHAR : "CHAR(%(length)s)",
schema.VARCHAR : "VARCHAR(%(length)s)",
schema.TEXT : "TEXT",
schema.FLOAT : "NUMERIC(%(precision)s, %(length)s)",
schema.DECIMAL : "NUMERIC(%(precision)s, %(length)s)",
schema.TIMESTAMP : "TIMESTAMP",
schema.DATETIME : "TIMESTAMP",
schema.CLOB : "TEXT",
schema.BLOB : "BLOB",
schema.BOOLEAN : "BOOLEAN",
}
def engine(filename, **params):
return SQLiteSQLEngine(filename, **params)
class SQLiteSQLEngine(ansisql.ANSISQLEngine):
def __init__(self, filename, **params):
self.filename = filename
ansisql.ANSISQLEngine.__init__(self, **params)
def connect_args(self):
return ([self.filename], {})
def dbapi(self):
return sqlite
def columnimpl(self, column):
return SQLiteColumnImpl(column)
class SQLiteColumnImpl(sql.ColumnSelectable):
def _get_specification(self):
coltype = self.column.type
if type(coltype) == types.ClassType:
key = coltype
else:
key = coltype.__class__
return self.name + " " + colspecs[key] % {'precision': getattr(coltype, 'precision', None), 'length' : getattr(coltype, 'length', None)}
|