尝试执行sqlite命令时出现Python CGI错误

时间:2014-05-31 06:09:18

标签: python sqlite

我不确定为什么它表示ajax_exmaple表不存在...我检查sqlite3以查看数据库和表及其对应的数据是否全部存在。有什么想法吗?

当我尝试执行此命令时:

query_result = c.execute(query, (sex, age, wpm))

......我明白了:

<class 'sqlite3.OperationalError'>: no such table: ajax_example 
  args = ('no such table: ajax_example',) 
  message = 'no such table: ajax_example'

这是我的完整代码:

#!C:\python27\python.exe
import cgi, cgitb, sqlite3
cgitb.enable()

print "Content-type: text/html"
print ""

conn = sqlite3.connect('../htdocs/ajax_ex.db')
c = conn.cursor()

# Capture URL query
form = cgi.FieldStorage()
age = form.getvalue('age')
sex = form.getvalue('sex')
wpm = form.getvalue('wpm')

# Build SQL
query = "SELECT * FROM ajax_example WHERE ae_sex = ?"
if(isinstance(age, int)):
query += " AND ae_age <= ?"
if(isinstance(wpm, int)):
query += " AND ae_wpm <= ?"

# Execute query
query_result = c.execute(query, (sex, age, wpm))
conn.close()

# Build result string
display_string = '''
<table>
<tr>
    <th>Name</th>
    <th>Age</th>
    <th>Sex</th>
    <th>WPM</th>
</tr>'''

# Insert a new row in the table for each person returned
for row in query_result:
display_string += "<tr>"
display_string += "<td>row['ae_name']</td>"
display_string += "<td>row['ae_age']</td>"
display_string += "<td>row['ae_sex']</td>"
display_string += "<td>row['ae_wpm']</td>"
display_string += "</tr>"

print "Query: ", query, "<br>"
display_string += "</table>"
print display_string

0 个答案:

没有答案