[Thuban-commits] r2680 - in trunk/thuban: . Thuban Thuban/Model
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon May 15 16:36:51 CEST 2006
Author: dpinte
Date: 2006-05-15 16:36:50 +0200 (Mon, 15 May 2006)
New Revision: 2680
Modified:
trunk/thuban/ChangeLog
trunk/thuban/Thuban/Model/transientdb.py
trunk/thuban/Thuban/version.py
Log:
2006-05-15 Didrik Pinte <dpinte at itae.be>
* Thuban/version.py : Updated imports to support pysqlite2
* Thuban/Model/transientdb.py : Updated imports to support pysqlite2
Patched the querying system to support the param style of pysqlite2
--Cette ligne,
M thuban/Thuban/Model/transientdb.py
M thuban/Thuban/version.py
M thuban/ChangeLog
Modified: trunk/thuban/ChangeLog
===================================================================
--- trunk/thuban/ChangeLog 2006-04-24 18:26:58 UTC (rev 2679)
+++ trunk/thuban/ChangeLog 2006-05-15 14:36:50 UTC (rev 2680)
@@ -1,3 +1,9 @@
+2006-05-15 Didrik Pinte <dpinte at itae.be>
+ * Thuban/version.py : Updated imports to support pysqlite2
+
+ * Thuban/Model/transientdb.py : Updated imports to support pysqlite2
+ Patched the querying system to support the param style of pysqlite2
+
2006-04-24 Didrik Pinte <dpinte at itae.be>
* Extensions/svgexport/__init__.py: The extension now works on win32
architecture. Bug #87 corrected.
Modified: trunk/thuban/Thuban/Model/transientdb.py
===================================================================
--- trunk/thuban/Thuban/Model/transientdb.py 2006-04-24 18:26:58 UTC (rev 2679)
+++ trunk/thuban/Thuban/Model/transientdb.py 2006-05-15 14:36:50 UTC (rev 2680)
@@ -18,7 +18,20 @@
# $Source$
# $Id$
-from sqlite import connect
+# Pysqlite version 1. and 2. behaves quiet differently
+# Pysqlite uses a different paramstyle. The older version
+# support format and pyformat while pysqlite2 supports only qmark
+# and named.
+# The sqlite2 boolean variable is used to manage specific part of the code
+try:
+ # Using SQLITE 2.x
+ sqlite2 = True
+ from pysqlite2 import dbapi2 as sqlite
+except ImportError:
+ # Using SQLITE 1.x
+ sqlite2 = False
+ import sqlite
+
from base import TitledObject
@@ -40,7 +53,7 @@
def __init__(self, filename):
self.filename = filename
- self.conn = connect(filename)
+ self.conn = sqlite.connect(filename)
# Counters to produce unique table and column names
self.num_tables = 0
self.num_cols = 0
@@ -353,7 +366,9 @@
right_template = right.internal_name
params = ()
else:
- right_template = "%s"
+ if sqlite2:
+ right_template = "?"
+ else: right_template = "%s"
params = (right,)
query = "SELECT id FROM %s WHERE %s %s %s ORDER BY id;" \
@@ -408,10 +423,19 @@
# longer than any of the column names
id_key = max([len(col.name) for col in self.columns]) * "x"
- insert_template = "INSERT INTO %s (id, %s) VALUES (%%(%s)s, %s);" \
+ if sqlite2:
+ insert_template = "INSERT INTO %s (id, %s) VALUES (%s, %s);" \
% (self.tablename,
", ".join([col.internal_name
for col in self.columns]),
+ '?',
+ ", ".join(["?" for col in self.columns]))
+
+ else:
+ insert_template = "INSERT INTO %s (id, %s) VALUES (%%(%s)s, %s);" \
+ % (self.tablename,
+ ", ".join([col.internal_name
+ for col in self.columns]),
id_key,
", ".join(["%%(%s)s" % col.name
for col in self.columns]))
@@ -419,7 +443,13 @@
for i in range(table.NumRows()):
row = table.ReadRowAsDict(i)
row[id_key] = i
- cursor.execute(insert_template, row)
+ if sqlite2:
+ params = [i]
+ for col in self.columns:
+ params.append(row[col.name])
+ cursor.execute(insert_template, params)
+ else:
+ cursor.execute(insert_template, row)
self.db.conn.commit()
Modified: trunk/thuban/Thuban/version.py
===================================================================
--- trunk/thuban/Thuban/version.py 2006-04-24 18:26:58 UTC (rev 2679)
+++ trunk/thuban/Thuban/version.py 2006-05-15 14:36:50 UTC (rev 2680)
@@ -111,14 +111,20 @@
versions['python-tuple'] = sys.version_info[:3]
# PySQLite
-from sqlite import version as pysqlite_version
-versions['pysqlite'] = pysqlite_version
-versions['pysqlite-tuple'] = make_tuple(pysqlite_version)
+try:
+ from pysqlite2 import dbapi2 as sqlite
+except ImportError:
+ import sqlite
+versions['pysqlite'] = sqlite.version
+versions['pysqlite-tuple'] = make_tuple(sqlite.version)
# SQLite
-from _sqlite import sqlite_version
-versions['sqlite'] = sqlite_version()
-versions['sqlite-tuple'] = make_tuple(sqlite_version())
+try:
+ from pysqlite2._sqlite import sqlite_version
+except ImportError:
+ from _sqlite import sqlite_version
+versions['sqlite'] = sqlite_version
+versions['sqlite-tuple'] = make_tuple(sqlite_version)
# GDAL
from Thuban.Model.resource import has_gdal_support
More information about the Thuban-commits
mailing list