English 中文(简体)
我的选任考试委员会正在搜索一栏而不是一栏中的数据。 我如何检索数据?
原标题:My SELECT function is searching for a column and not the data in the column. How can I make it search the data?

当我把变数输入“名称:植被(a)变数”时,我预计会从b中的配量回来。 这样,用户就能够确定在数据集中是否有人。

在我进行搜查时(从TKinterGUI),我有以下错误:

*line 35, in search
    c.execute("SELECT * FROM addresses WHERE last_name="  + l_name.get())
sqlite3.OperationalError: no such column: Mustang*

(Mustang是搜索词)

这是在Kalk3号文件中提出的表格:

c.execute(""" CREATE TABLE addresses (
    first_name text,
    last_name text,
    address text,
    city text,
    state text,
    postcode integer)""")

职能如下:

def search():
#connect to database from within function
conn = sqlite3.Connection( address_book.db )
#create a cursor from within function
c = conn.cursor()

#Search function in SQL
c.execute("SELECT * FROM addresses WHERE last_name="  +         l_name.get())
records = c.fetchall()
print_records=""
#this loop will print selected items
for record in records:
        print_records += str(record[0])+ " " + str(record[1]) + "	" + str(record[2]) + "
"

#commit changes
conn.commit()
#close connection
conn.close()
#clear text boxes

#query lbl part of the function to display results
query_lbl=Label(root, text=print_records)
query_lbl.grid(row=15,column=0, columnspan=2)

I have tested the variable and it is functioning, I have been able to search by oid with the same code, replacing "last_name" with "oid". I am at a loss. (also quite new to this so please be gentle)

最佳回答

If the content of l_name is "Mustang", then the final SQL will be:

SELECT * FROM addresses WHERE last_name=Mustang

因此,WHERE的条件将比较两栏:last_name Mustang。 您需要的是 引用<>。 www.un.org/Depts/DGACM/index_french.htm

SELECT * FROM addresses WHERE last_name="Mustang"

最好使用 替代持有人<>:>

c.execute("SELECT * FROM addresses WHERE last_name = ?", (l_name.get(),))
问题回答

我需要将tKinter的“植被”功能变成一个变数,作为在持地人之后的论点。

c.execute("SELECT * FROM addresses WHERE last_name=?",(x,))

该职能现在按计划运作,回归数据与用户的投入相匹配。





相关问题
Get webpage contents with Python?

I m using Python 3.1, if that helps. Anyways, I m trying to get the contents of this webpage. I Googled for a little bit and tried different things, but they didn t work. I m guessing that this ...

What is internal representation of string in Python 3.x

In Python 3.x, a string consists of items of Unicode ordinal. (See the quotation from the language reference below.) What is the internal representation of Unicode string? Is it UTF-16? The items ...

What does Python s builtin __build_class__ do?

In Python 3.1, there is a new builtin function I don t know in the builtins module: __build_class__(...) __build_class__(func, name, *bases, metaclass=None, **kwds) -> class Internal ...

what functional tools remain in Python 3k?

I have have read several entries regarding dropping several functional functions from future python, including map and reduce. What is the official policy regarding functional extensions? is lambda ...

Building executables for Python 3 and PyQt

I built a rather simple application in Python 3.1 using PyQt4. Being done, I want the application to be distributed to computers without either of those installed. I almost exclusively care about ...

热门标签