473,394 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

sqlite3 bug??

I hesitate to ask, but ...

I'm using Ubuntu Feisty:
* Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
* SQLite version 3.3.13

Suppose I run the following program:
import sqlite3

conn = sqlite3.connect('example')
c = conn.cursor()

# Create table
c.execute('''create table stocks
(date text, trans text, symbol text,
qty real, price real)''')

# Insert a row of data
c.execute("""insert into stocks
values ('2006-01-05','BUY','RHAT',100,35.14)""")

and then I go into sqlite:
% sqlite3 example
sqlite3select * from stocks ;

It returns 0 rows. I'm in the right directory. I have experienced this
problem with some other sqlite3 database work I have done with python,
so I'm figuring there is something fishy going on. I've tried doing
similar exercises with Ruby, and they have worked OK.

Anyone else getting these problems?
Jun 17 '07 #1
13 1807
On 6/17/07, mark carter <me@privacy.netwrote:
I hesitate to ask, but ...

I'm using Ubuntu Feisty:
* Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
* SQLite version 3.3.13

Suppose I run the following program:
import sqlite3

conn = sqlite3.connect('example')
c = conn.cursor()

# Create table
c.execute('''create table stocks
(date text, trans text, symbol text,
qty real, price real)''')

# Insert a row of data
c.execute("""insert into stocks
values ('2006-01-05','BUY','RHAT',100,35.14)""")

and then I go into sqlite:
% sqlite3 example
sqlite3select * from stocks ;

It returns 0 rows. I'm in the right directory. I have experienced this
problem with some other sqlite3 database work I have done with python,
so I'm figuring there is something fishy going on. I've tried doing
similar exercises with Ruby, and they have worked OK.

Anyone else getting these problems?
See http://www.python.org/dev/peps/pep-0249/ (emphasis mine):

.commit()

Commit any pending transaction to the database. *Note that
if the database supports an auto-commit feature, this must
be initially off.* An interface method may be provided to
turn it back on.

(This really should be a FAQ...)

-- David
Jun 17 '07 #2
mark carter wrote:
I hesitate to ask, but ...
Don't :-)
I'm using Ubuntu Feisty:
* Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
* SQLite version 3.3.13

Suppose I run the following program:
import sqlite3

conn = sqlite3.connect('example')
c = conn.cursor()

# Create table
c.execute('''create table stocks
(date text, trans text, symbol text,
qty real, price real)''')

# Insert a row of data
c.execute("""insert into stocks
values ('2006-01-05','BUY','RHAT',100,35.14)""")

and then I go into sqlite:
% sqlite3 example
sqlite3select * from stocks ;

It returns 0 rows. I'm in the right directory. I have experienced this
problem with some other sqlite3 database work I have done with python,
so I'm figuring there is something fishy going on. I've tried doing
similar exercises with Ruby, and they have worked OK.

Anyone else getting these problems?
How about conn.commit()?

Peter
Jun 17 '07 #3
On Sun, 2007-06-17 at 12:59 +0100, mark carter wrote:
I hesitate to ask, but ...

I'm using Ubuntu Feisty:
* Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
* SQLite version 3.3.13

Suppose I run the following program:
import sqlite3

conn = sqlite3.connect('example')
c = conn.cursor()

# Create table
c.execute('''create table stocks
(date text, trans text, symbol text,
qty real, price real)''')

# Insert a row of data
c.execute("""insert into stocks
values ('2006-01-05','BUY','RHAT',100,35.14)""")

and then I go into sqlite:
% sqlite3 example
sqlite3select * from stocks ;

It returns 0 rows.
Your program doesn't call conn.commit(). Python's DB-API specifies that
a connection operate in a transaction by default. The transaction is
rolled back at the end of the program if it's not committed.

--
Carsten Haese
http://informixdb.sourceforge.net
Jun 17 '07 #4
David Wahler wrote:
On 6/17/07, mark carter <me@privacy.netwrote:
>Anyone else getting these problems?

See http://www.python.org/dev/peps/pep-0249/ (emphasis mine):

.commit()
OK, I tried that, and I appear to be cooking. The funny thing is, I
could have sworn that I tried that a few days ago, and it didn't work.
Weird. Appears to be working now, though, so I guess I must have been
doing something kooky.

Should I also explicitly close the cursor and connection, or is that
taken care of "automagically"?

I'm seriously thinking about reporting the commit() thing as a doc bug
in python, as this isn't mentioned at
http://docs.python.org/lib/module-sqlite3.html
and I think it's exactly the kind of thing that should be mentioned in
the examples.
Jun 17 '07 #5
On Jun 17, 7:16 am, mark carter <m...@privacy.netwrote:
David Wahler wrote:
On 6/17/07, mark carter <m...@privacy.netwrote:
Anyone else getting these problems?
Seehttp://www.python.org/dev/peps/pep-0249/(emphasis mine):
.commit()

OK, I tried that, and I appear to be cooking. The funny thing is, I
could have sworn that I tried that a few days ago, and it didn't work.
Weird. Appears to be working now, though, so I guess I must have been
doing something kooky.

Should I also explicitly close the cursor and connection, or is that
taken care of "automagically"?

I'm seriously thinking about reporting the commit() thing as a doc bug
in python, as this isn't mentioned athttp://docs.python.org/lib/module-sqlite3.html
and I think it's exactly the kind of thing that should be mentioned in
the examples.
Please report the whole docs as a bug.

Jun 17 '07 #6
7stud wrote:
On Jun 17, 7:16 am, mark carter <m...@privacy.netwrote:
>David Wahler wrote:
>>On 6/17/07, mark carter <m...@privacy.netwrote:
Anyone else getting these problems?
Seehttp://www.python.org/dev/peps/pep-0249/(emphasis mine):
.commit()
>>
I'm seriously thinking about reporting the commit() thing as a doc bug
in python, as this isn't mentioned at
http://docs.python.org/lib/module-sqlite3.html
and I think it's exactly the kind of thing that should be mentioned in
the examples.

Please report the whole docs as a bug.
http://sourceforge.net/tracker/index...70&atid=105470

That will save a few people tearing their hair out!
Jun 17 '07 #7
On Sun, 2007-06-17 at 07:43 -0700, 7stud wrote:
Please report the whole docs as a bug.
I imagine the author appreciates constructive criticism. This is not
constructive criticism.

In other words: Pointing out specific shortcomings and ways to correct
them, such as what the OP is doing, is helpful. Calling the entire docs
a bug is not helpful.

--
Carsten Haese
http://informixdb.sourceforge.net
Jun 17 '07 #8
Carsten Haese wrote:
On Sun, 2007-06-17 at 07:43 -0700, 7stud wrote:
>Please report the whole docs as a bug.

I imagine the author appreciates constructive criticism. This is not
constructive criticism.

In other words: Pointing out specific shortcomings and ways to correct
them, such as what the OP is doing, is helpful. Calling the entire docs
a bug is not helpful.
You'll be pleased to know that I was specific, and I suggested a change
that I thought would be good.

Actually, I think the docs are quite good! I went hunting around some
Scheme implementations lately. What was immediately apparent to me was
that the docs weren't nearly as good as those for python. Typical
problems centre about what modules I was supposed to load, and how I was
supposed to use them. What might be obvious to an old hand might not be
obvious to someone coming in from fresh. This is where big projects like
Python tend to score - the docs have been through many iterations.
Jun 17 '07 #9
[ Carsten Haese <ca*****@uniqsys.com]
On Sun, 2007-06-17 at 07:43 -0700, 7stud wrote:
Please report the whole docs as a bug.

Calling the entire docs a bug is not helpful.
... unless he also comes up with the "bugfix". ;)

--
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4 (GNU/Linux)

iD8DBQBGdX44n3IEGILecb4RAvIsAJ0dy5Cwi9yB1Od3y6o5SM Boj8fSxwCfUHCV
E0BFKnzSj2n8Nw1ZhNMIGwU=
=n/jF
-----END PGP SIGNATURE-----

Jun 17 '07 #10
On Sun, 2007-06-17 at 19:26 +0100, mark carter wrote:
Carsten Haese wrote:
On Sun, 2007-06-17 at 07:43 -0700, 7stud wrote:
Please report the whole docs as a bug.
I imagine the author appreciates constructive criticism. This is not
constructive criticism.

In other words: Pointing out specific shortcomings and ways to correct
them, such as what the OP is doing, is helpful. Calling the entire docs
a bug is not helpful.

You'll be pleased to know that I was specific, and I suggested a change
that I thought would be good.
I know, and I acknowledged that. Maybe you missed that OP = original
poster = You.

--
Carsten Haese
http://informixdb.sourceforge.net
Jun 17 '07 #11
On Jun 17, 9:16 am, mark carter <m...@privacy.netwrote:
Should I also explicitly close the cursor and connection, or is that
taken care of "automagically"?
Somebody correct me if I'm wrong, but I'm pretty sure that the Cursor
and Connection objects properly clean themselves up when deallocated
(when their reference count reaches 0), so not explicitly closing them
isn't a terrible thing. In fact, I have code in which references to a
db connection are passed around, so I have to be careful about
explicitly closing the connection, lest it be in use by some other
method somewhere. Maybe people will frown on this, but it's not
uncommon.

Hyuga

Jun 18 '07 #12
On Jun 18, 11:01 am, Hyuga <hyugaricd...@gmail.comwrote:
In fact, I have code in which references to a
db connection are passed around, so I have to be careful about
explicitly closing the connection, lest it be in use by some other
method somewhere.
Hate to reply to myself, but I should clarify that passing around a
handle to an existing DB connection is necessary as a means of
allowing multiple methods that write to the DB to operate atomically
before calling commit(). So again, if you're doing something like
that, you want to be absolutely certain before you close your
connection that it's not in use elsewhere.

Hyuga

Jun 18 '07 #13
Hyuga wrote:
On Jun 17, 9:16 am, mark carter <m...@privacy.netwrote:
>Should I also explicitly close the cursor and connection, or is that
taken care of "automagically"?

Somebody correct me if I'm wrong, but I'm pretty sure that the Cursor
and Connection objects properly clean themselves up when deallocated
(when their reference count reaches 0), so not explicitly closing them
isn't a terrible thing. [...]
That's correct for pysqlite, and probably for all other DB-API modules
too. If you have a client-server database, it's nicer to close the
database connection if you don't need it any longer in order to free up
resources on the server, of course.
In fact, I have code in which references to a db connection are
passed around, so I have to be careful about explicitly closing the
connection, lest it be in use by some other method somewhere. Maybe
people will frown on this, but it's not uncommon.
I don't think I've ever explicitly closed a cursor object when
programming to the DB-API myself.

-- Gerhard
Jun 19 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Harold Shore | last post by:
From the release notes I read that "If you're compiling the Python source yourself, note that the source tree doesn't include the SQLite code, only the wrapper module. You'll need to have the...
2
by: John Machin | last post by:
Apologies in advance if this is a bit bloggy, but I'd like to get comments on whether I've lost the plot (or, more likely, failed to acquire it) before I start reporting bugs etc. From "What's...
66
by: mensanator | last post by:
Probably just me. I've only been using Access and SQL Server for 12 years, so I'm sure my opinions don't count for anything. I was, nevertheless, looking forward to Sqlite3. And now that gmpy...
2
by: Josh | last post by:
Hi, I'm running into a problem when trying to create a view in my sqlite database in python. I think its a bug in the sqlite3 api that comes with python 2.5. This works as expected: conn =...
3
by: cjl | last post by:
P: I am using python 2.5.1 on windows. I have the following code: conn = sqlite3.connect('.\optiondata') c = conn.cursor() try: c.execute('''create table options (ssymbol text, strike real,...
4
by: Simon | last post by:
I installed the source code on unix for python 2.5.1. The install went mainly okay, except for some failures regarding: _ssl, _hashlib, _curses, _curses_panel. No errors regarding sqlite3....
0
by: Josh Ritter | last post by:
A number of our Windows customers have an issue with the sqlite3 module included with Python 2.5.1 We've tracked the problem down to the sqlite3.dll included with the Python 2.5.1 distrubtion. ...
3
by: milan_sanremo | last post by:
I have sqlite installed, but when I try to import sqlite3 I receive: Python 2.5.1 (r251:54863, Nov 3 2007, 02:54:36) on sunos5 Type "help", "copyright", "credits" or "license" for more...
0
by: Ben Lee | last post by:
hi folks -- a quick python and sqlite3 performance question. i find that inserting a million rows of in-memory data into an in-memory database via a single executemany() is about 30% slower...
15
by: Kurda Yon | last post by:
Hi, I try to "build" and "install" pysqlite? After I type "python setup.py build" I get a lot of error messages? The first error is "src/ connection.h:33:21: error: sqlite3.h: No such file or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.