Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8486039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:49:27+00:00 2026-06-10T20:49:27+00:00

My table, info, has 4 columns: bp, key, exp and job. I’m trying to

  • 0

My table, “info”, has 4 columns: bp, key, exp and job. I’m trying to create a function that searches for a term within a specified column:

Edit: Different problem, see 2nd code and 2nd error below

def search2(query, field):

    search_string = query    

    if field == "bp":
        cursor.execute("SELECT * FROM info WHERE bp="+search_string)
    elif field == "key":
        cursor.execute("SELECT * FROM info WHERE key="+search_string)
    elif field == "exp":
        cursor.execute("SELECT * FROM info WHERE exp="+search_string)
    elif field == "job":
        cursor.execute("SELECT * FROM info WHERE job="+search_string)

However, this raises an error, with “test” as search string and “bp” as column:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\user\Programs\time_database.py", line 32, in search2
    cursor.execute("SELECT * FROM info WHERE bp="+search_string)
sqlite3.OperationalError: no such column: test

And by the way, “test” wasn’t intended to be a column. I want it to be a search string that matches the specified column…

EDIT

Thanks Martijn Pieters for that, but now another error has surfaced. My code now is:

def search2(query, field):

    search_string = query    

    if field == "bp":
        cursor.execute("SELECT * FROM info WHERE job=?", search_string)
    elif field == "key":
        cursor.execute("SELECT * FROM info WHERE key="+search_string)
    elif field == "exp":
        cursor.execute("SELECT * FROM info WHERE exp="+search_string)
    elif field == "job":
        cursor.execute("SELECT * FROM info WHERE job="+search_string)

And the error I get is:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\gummi\Programs\time_database.py", line 32, in search2
    cursor.execute("SELECT * FROM info WHERE job=?", search_string)
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement         uses 1, and there are 4 supplied.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:49:29+00:00Added an answer on June 10, 2026 at 8:49 pm

    You are not quoting the search string, and the database is interpreting it as a column name instead.

    Use query parameters, these quote your search string automatically:

    cursor.execute("SELECT * FROM info WHERE job=?", search_string)
    

    Next, if the field (column) value is not coming from an untrusted source (such as a web page) you can interpolate it directly into your query:

    cursor.execute("SELECT * FROM info WHERE %s=?" % field, (search_string,))
    

    Now you no longer need all the branching.

    If the field value does come from an untrusted source, the simplest thing is to just test if it is an allowed value:

    def search2(query, field):
        if field not in set(['bp', 'key', 'exp', 'job']):
            raise ValueError('No such column ' + field)    
        cursor.execute("SELECT * FROM info WHERE %s=?" % field, (query,))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a table to only has a foreign key, not
I have a DB that has the label table with info in it. I
I have a simple table that has this structure: <table> <thead> <tr> <td>Some info</td>
I have a table (parts) that has 2 columns in it, 1000 or so
I have a table that has 25 columns, and in total is about 2600px
Table has the following info: date |vendor|sales|percent| -------------------------- 2009-03-03| 10 |13.50| 1.30 | 2009-03-10|
I use this for autoincreamenting one column , create table info (ID INTEGER PRIMARY
I am trying to seek within the primary index of a table on a
I have two tables. Table #1 'color' has columns [red], [blue], [green]; where each
I am trying to create an ANI lookup table from 2 separate tables, one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.