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

  • Home
  • SEARCH
  • 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 9088473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:54:52+00:00 2026-06-16T21:54:52+00:00

Im trying to form a sanitised query string in Python to use in SQLite3.

  • 0

Im trying to form a sanitised query string in Python to use in SQLite3. It needs to take the ultimate form:

SELECT * FROM Players WHERE PlayerName LIKE '%bob%'

…so I can run a pattern search.

Ideally I want to have a ? in the query so I can then insert the search string when running the query and prevent Bobby Tables type events from occurring (not that I’ll have to worry about that tbh):

search_string = "bob"

query = "SELECT * FROM Players WHERE PlayerName LIKE '%?%'"

cur.execute(query, (search_string))

Running this gives me:

sqlite3.ProgrammingError: Incorrect number of bindings supplied. The
current statement uses 0, and there are 3 supplied.

So I’m pretty sure the issue is both with the use of the single quotes, percents and question marks but am fairly stuck – I can’t form the query so that python sees it needs a binding.

What is the best way round this or is there better practice for forming sanitised queries for pattern search in SQL?

UPDATE: final line was:

cur.execute(query, [('%' + search_string + '%')])
  • 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-16T21:54:53+00:00Added an answer on June 16, 2026 at 9:54 pm

    Use the lone placeholder ? after LIKE and wrap search_string with % during parameter assignment:

    ...
    search_string = 'bob'
    query = 'SELECT * FROM Players WHERE PlayerName LIKE ?'
    cur.execute(query, ('%' + search_string + '%'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to form a query string from multiple checkboxes that will be used
I'm trying to use form's CheckboxSelectMultiple widget but I I'd like to change the
I am trying to intercept form submits from webpages I dont control. My current
I'm trying to form a query that returns a list of entities within a
I'm trying to pass a value from a select input control on an HTML
I am trying to form a regex that functions as mentioned below: String killing
I am trying to form a query using codeigniter's active record, the search is
I'm trying to use a simple PHP mail() function to create user feedback from
I am trying to form ribbon XML with the data from the database and
so I am trying to form a PCRE regex in php, specifically for use

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.