python tst_sqlite py foo db id INTEGER 99 None name VARCHAR 80 None jy

 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
## $ python tst_sqlite.py foo.db
## [(0, u'id', u'INTEGER', 99, None, 1), (1, u'name', u'VARCHAR(80)', 0, None, 0)]
## $ jython tst_sqlite.py foo.db
## Traceback (most recent call last):
## File "tst_sqlite.py", line 24, in <module>
## main()
## File "tst_sqlite.py", line 21, in main
## print run_sql(conn)
## File "tst_sqlite.py", line 11, in run_sql
## curs.execute('PRAGMA table_info(users)', {})
## zxJDBC.ProgrammingError: optional second argument must be a list or tuple
##
import sys
def get_sqlite_conn(name):
import sqlite3
return sqlite3.connect('foo.db')
def get_jdbc_conn(name):
from com.ziclix.python.sql import zxJDBC
return zxJDBC.connect('jdbc:sqlite:%s' % name, None, None, 'org.sqlite.JDBC')
def run_sql(conn):
curs = conn.cursor()
curs.execute('PRAGMA table_info(users)', {}) # <--- here the problem place, but SQLAlchemy uses such queries
return curs.fetchall()
def main(args):
name = args[0]
if 'java' in sys.platform:
conn = get_jdbc_conn(name)
else:
conn = get_sqlite_conn(name)
print run_sql(conn)
if __name__ == '__main__':
main(sys.argv[1:])