[DB-SIG] SQLite Problem
Mike Bader
mikebader9 at gmail.com
Thu Jun 25 22:54:28 CEST 2009
Hello,
I am relatively new to both SQLite and Python. I am trying to write a script
that calls data from a database and prints it to a website. The problem is,
when I try to do this, as soon as I try to do something with
cursor.execute("SQL cmd"), the webpage stops printing at that spot and does
not continue. When I run it in from the shell, however, the program prints
as it should.
My script is:
import cgi
import sqlite3 as sql
def defineContentType():
print "Content-type:text/html\n"
defineContentType()
print """<html>
<head>
<title>test page</title>
</head>
<body>This is before <br />"""
conn = sql.connect("data_temp")
cur = conn.cursor()
cur.execute('''SELECT type FROM sqlite_master WHERE tbl_name="data"''')
if len(cur.fetchall())>0:
cur.execute('''DROP TABLE data''')
conn.commit()
cur.execute('''CREATE TABLE data (
id INTEGER PRIMARY KEY AUTOINCREMENT,
strfield varchar(8),
numfld1 FLOAT NOT NULL,
numfld2 FLOAT NOT NULL)''')
conn.commit()
cur.execute('''INSERT INTO data (strfield, numfld1, numfld2) VALUES
("%s",%f,%f)''' % ("testing123",40.8052, -73.9654))
conn.commit()
cur.execute('''SELECT * FROM data''')
print cur.fetchall()
conn.close()
print """This is after
</body>
</html>"""
When I call it from a browser, this is what I get:
<html>
<head>
<title>test page</title>
</head>
<body>This is before <br />
But when I run the file from the shell, I get:
Content-type:text/html
<html>
<head>
<title>test page</title>
</head>
<body>This is before <br />
[(1, u'testing123', 40.805199999999999, -73.965400000000002)]
This is after
</body>
</html>
Can anyone please help me understand why the program might stop printing
when retrieved through a browser and run fine when run in the shell? Could
it be related to the version of SQLite I am using (and if so, how do I
check?) Thank you very much.
Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/db-sig/attachments/20090625/05abe200/attachment.htm>
More information about the DB-SIG
mailing list