pysqlite problem

B

bapolis

Hello,

I'm getting the following error:

pysqlite2.dbapi2.OperationalError: no such table: tbl1

Here's my code:

from pysqlite2 import dbapi2 as sqlite
con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES)
cur = con.cursor()
cur.execute("select * from tbl1")
data = cursor.fetchall()
for record in date:
record[0], record[1]

my installation versions:

python 2.4.2
pysqlite 2.0.7
sqlite 3.3.4

I checked to make sure I have a table called tbl1. I don't understand
what's going on. Any ideas?
 
B

bapolis

my bad. that was the wrong code, here is my code:

from pysqlite2 import dbapi2 as sqlite
con = sqlite.connect("ex1")
cur = con.cursor()
cur.execute("select * from tbl1")
print cur.fetchall()
 
L

looping

Is it the complete code ?

If so then you have to create the table each time you connect to the
DB.

You use an in-memory DB (":memory:") so all the data of the DB is lost
when you close the connection, including the schema of the DB.
 
L

looping

OK, it's better.

You use relative path to your file 'ex1', are you really sure that you
open the right file and not creating another DB in another path ?

Try to use absolute path (r'c:\temp\ex1').
 
G

Ganesan Rajagopal

bapolis said:
con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES)
^^^^^^^^^^

Did you really intend this? Since you're opening a database in memory, you
will have access to tbl1 only if you create the table after the connect.

Ganesan
 
F

Fredrik Lundh

I'm getting the following error:

pysqlite2.dbapi2.OperationalError: no such table: tbl1

Here's my code:

from pysqlite2 import dbapi2 as sqlite
con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES)
cur = con.cursor()
cur.execute("select * from tbl1")
data = cursor.fetchall()
for record in date:
record[0], record[1]

my installation versions:

python 2.4.2
pysqlite 2.0.7
sqlite 3.3.4

I checked to make sure I have a table called tbl1.
where?

I don't understand what's going on. Any ideas?

last time I checked, connect(":memory:") creates a new blank database
every time it is called.

</F>
 
B

bapolis

I tried using the path "c:\ex1.db" and it worked. I was using "ex1.db"
before.

Thanks everyone for the help. This is a great community and maybe next
time I will ask a harder question :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top