Re: [PDO-Users]help needed: pysqlite troubles
pythondbo-users-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Wed, 15 Jun 2005 18:29:22 +0300
| Newsgroups | gmane.comp.python.db.pdo.user |
|---|---|
| Message-ID | <[email protected]> |
pythondbo-users-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org wrote:
> Hello!
>
> We're looking into this - it looks like updates to the pysqlite2 may
> have broken compatibility with pdo. We're setting up a test environ on
> our end. More soon!
>
> ~Jon Franz
> NeuroKode Labs, LLC
Jon, thank you for responding!
Thanks to the availability of the source, I seem to got this working.
Don't know if this really makes sense, but for anyone who may fall
over this thread, here's the patch to run pdo.py v. 1.3.1 against
pysqlite 2.0.3 (Windows XP SP2; the diff comes with cygwin):
--- pdo.py 2004-07-28 13:16:16.000000000 +0300
+++ pdo-changed.py 2005-06-15 18:20:28.031250000 +0300
@@ -86,7 +86,7 @@
#Validation: Setup
con_required['MySQLdb'] = ['host','port','user','passwd','db']
con_required['pgdb'] = ['user','password','database']
- con_required['sqlite'] = ['db']
+ con_required['pysqlite2.dbapi2'] = ['db']
con_required['kinterbasdb'] = ['dsn', 'user', 'password']
con_required['mx.ODBC.Windows'] = ['dsn', 'user', 'password']
con_required['mx.ODBC.iODBC'] = ['dsn', 'user', 'password']
@@ -100,7 +100,7 @@
con_defaults['MySQLdb']['host'] = 'localhost'
con_defaults['MySQLdb']['port'] = 3306
con_defaults['pgdb'] = {}
- con_defaults['sqlite'] = {}
+ con_defaults['pysqlite2.dbapi2'] = {}
con_defaults['kinterbasdb'] = {}
con_defaults['mx.ODBC.Windows'] = {}
con_defaults['mx.ODBC.iODBC'] = {}
@@ -117,7 +117,7 @@
con_rename['adodbapi'] = {}
con_rename['pgdb']['passwd'] = "password"
con_rename['pgdb']['db'] = "database"
- con_rename['sqlite'] = {}
+ con_rename['pysqlite2.dbapi2'] = {}
con_rename['kinterbasdb'] = {}
con_rename['kinterbasdb']['passwd'] = "password"
con_rename['mx.ODBC.Windows'] = {}
@@ -169,6 +169,9 @@
for item in self.__connection_vars.keys():
con_str += item + "=" + self.__connection_vars[item] + ";"
self.db = self.PDODB.connect(con_str)
+ elif self.module=="pysqlite2.dbapi2":
+ con_str = self.__connection_vars['db']
+ self.db = self.PDODB.connect(con_str, isolation_level=None)
else:
self.db = self.PDODB.connect(**self.__connection_vars)
self.active=1
Regards!
Yassen
>
> pythondbo-users-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org wrote:
>
>> Hello!
>>
>> PDO seemed to be exactly what I need in order to connect to an sqlite3
>> database from within Python code; however I cannot get this to work.
>>
>> I can use pysqlite (v. 2.0.3) with code like this:
>>
>> ----cut here------------------------------------------------
>> from pysqlite2 import dbapi2 as sqlite
>> connection = sqlite.connect("trial.db", isolation_level=None)
>> cursor = connection.cursor()
>> # -- create a table:
>> cursor.execute('BEGIN')
>> stmt = """CREATE TABLE Family (
>> id int not NULL,
>> name text not NULL,
>> age int not NULL, -- format: YYYYMMDD
>> uid numeric not NULL,
>> comm text NULL
>> );"""
>> cursor.execute(stmt)
>> # -- populate the table:
>> stmt = 'insert into Family values(?,?,?,?,NULL)'
>> for i in range(0,99999):
>> cursor.execute(stmt, (i, 'Name-'+`i`, i+2, '681022'+`i`))
>> # -- that's it!
>> cursor.execute('COMMIT')
>> ----cut here------------------------------------------------
>>
>> The above code works. But when I try to open a db connection using pdo,
>> I inevitably fail:
>>
>> >>> conn = pdo.connect('Module=pysqlite2;DB=trial.db')
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in ?
>> File "D:\devtools\python\python241\lib\site-packages\pdo.py", line
>> 80, in __init__
>> raise pdo_connection_error, self.ErrorMessage
>> pdo.pdo_connection_error: "Unable to load Database Module: Database
>> specific
>> Error:exceptions.AttributeError\n'module' object has no attribute
>> 'paramstyle'"
>>
>> I tried some variations but all seemed to be false. What am I doing
>> wrong?
>>
>> Any help would be more than appreciated -- thanks!
>> Yassen
>>
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click