Using sqlite3 DB-API multiple parameter substitution in SELECT statements Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag?“SELECT … WHERE … IN” with unknown number of parametersMultiple variables in a 'with' statement?Substitute multiple whitespace with single whitespace in Pythonsqlite3 square brackets in a select statementSelecting multiple columns in a pandas dataframesqlite3 command line tools don't work in UbuntuPython threading, why can i launch thread only once?sqlite3 select statement fails with "parameters are of unsupported typeWhy can parameter substitution not be used with tables in sqlite3?Parameter substitution for a SQLite with multiple “IN” clausePython and SQLite3 SELECT statement

How much radiation do nuclear physics experiments expose researchers to nowadays?

G-Code for resetting to 100% speed

Why don't the Weasley twins use magic outside of school if the Trace can only find the location of spells cast?

Why is "Captain Marvel" translated as male in Portugal?

Do I really need recursive chmod to restrict access to a folder?

Can a non-EU citizen traveling with me come with me through the EU passport line?

What is the correct way to use the pinch test for dehydration?

Did Kevin spill real chili?

What causes the vertical darker bands in my photo?

Models of set theory where not every set can be linearly ordered

How to bypass password on Windows XP account?

If 'B is more likely given A', then 'A is more likely given B'

How to recreate this effect in Photoshop?

Should I call the interviewer directly, if HR aren't responding?

Why does Python start at index -1 when indexing a list from the end?

Storing hydrofluoric acid before the invention of plastics

How to find all the available tools in macOS terminal?

When -s is used with third person singular. What's its use in this context?

How do I stop a creek from eroding my steep embankment?

When is phishing education going too far?

Do you forfeit tax refunds/credits if you aren't required to and don't file by April 15?

How to draw this diagram using TikZ package?

What is a Meta algorithm?

Can Pao de Queijo, and similar foods, be kosher for Passover?



Using sqlite3 DB-API multiple parameter substitution in SELECT statements



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?“SELECT … WHERE … IN” with unknown number of parametersMultiple variables in a 'with' statement?Substitute multiple whitespace with single whitespace in Pythonsqlite3 square brackets in a select statementSelecting multiple columns in a pandas dataframesqlite3 command line tools don't work in UbuntuPython threading, why can i launch thread only once?sqlite3 select statement fails with "parameters are of unsupported typeWhy can parameter substitution not be used with tables in sqlite3?Parameter substitution for a SQLite with multiple “IN” clausePython and SQLite3 SELECT statement



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















Given:



letters = list("abc")


I'd like to get all rows in characters that contain any of the letters in letters in their c column. I can do this, but only with python's string operations, which isn't suitable given it's vulnerabilities.



Ideally (my example is simplified) this would be using the GLOB clause.



E.g.



>>> cur.execute(**the statement here**)
>>> print(cur.fetchall())
>>> [('a',), ('b',), ('c',)]


Creation of the db:



import sqlite3
import string

def char_generator():
for c in string.ascii_lowercase:
yield (c,)

con = sqlite3.connect(":memory:")
cur = con.cursor()
cur.execute("create table characters(c)")

cur.executemany("insert into characters(c) values (?)", char_generator())









share|improve this question






















  • I don't think it's quite a dupe, but this question might help.

    – glibdud
    Mar 8 at 16:28

















0















Given:



letters = list("abc")


I'd like to get all rows in characters that contain any of the letters in letters in their c column. I can do this, but only with python's string operations, which isn't suitable given it's vulnerabilities.



Ideally (my example is simplified) this would be using the GLOB clause.



E.g.



>>> cur.execute(**the statement here**)
>>> print(cur.fetchall())
>>> [('a',), ('b',), ('c',)]


Creation of the db:



import sqlite3
import string

def char_generator():
for c in string.ascii_lowercase:
yield (c,)

con = sqlite3.connect(":memory:")
cur = con.cursor()
cur.execute("create table characters(c)")

cur.executemany("insert into characters(c) values (?)", char_generator())









share|improve this question






















  • I don't think it's quite a dupe, but this question might help.

    – glibdud
    Mar 8 at 16:28













0












0








0








Given:



letters = list("abc")


I'd like to get all rows in characters that contain any of the letters in letters in their c column. I can do this, but only with python's string operations, which isn't suitable given it's vulnerabilities.



Ideally (my example is simplified) this would be using the GLOB clause.



E.g.



>>> cur.execute(**the statement here**)
>>> print(cur.fetchall())
>>> [('a',), ('b',), ('c',)]


Creation of the db:



import sqlite3
import string

def char_generator():
for c in string.ascii_lowercase:
yield (c,)

con = sqlite3.connect(":memory:")
cur = con.cursor()
cur.execute("create table characters(c)")

cur.executemany("insert into characters(c) values (?)", char_generator())









share|improve this question














Given:



letters = list("abc")


I'd like to get all rows in characters that contain any of the letters in letters in their c column. I can do this, but only with python's string operations, which isn't suitable given it's vulnerabilities.



Ideally (my example is simplified) this would be using the GLOB clause.



E.g.



>>> cur.execute(**the statement here**)
>>> print(cur.fetchall())
>>> [('a',), ('b',), ('c',)]


Creation of the db:



import sqlite3
import string

def char_generator():
for c in string.ascii_lowercase:
yield (c,)

con = sqlite3.connect(":memory:")
cur = con.cursor()
cur.execute("create table characters(c)")

cur.executemany("insert into characters(c) values (?)", char_generator())






python sqlite3






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 16:14









DaveDave

1158




1158












  • I don't think it's quite a dupe, but this question might help.

    – glibdud
    Mar 8 at 16:28

















  • I don't think it's quite a dupe, but this question might help.

    – glibdud
    Mar 8 at 16:28
















I don't think it's quite a dupe, but this question might help.

– glibdud
Mar 8 at 16:28





I don't think it's quite a dupe, but this question might help.

– glibdud
Mar 8 at 16:28












1 Answer
1






active

oldest

votes


















1














Maybe this sample can help you.



import sqlite3
import string

def char_generator():
for c in string.ascii_lowercase:
yield (c,)


con = sqlite3.connect(":memory:")

def initdb():
cur = con.cursor()
cur.execute("create table characters(c)")

cur.executemany("insert into characters(c) values (?)", char_generator())

def search(value):
values = [c for c in value]
cur = con.cursor()
cur.execute('SELECT * FROM characters WHERE c IN (0)'.format(','.join(['?' for c in values])), values)
return cur.fetchall()


if __name__ == '__main__':
initdb()
print(search("abcde"))


This code uses parameters. So you do not need to worry about SQL Injection.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55067006%2fusing-sqlite3-db-api-multiple-parameter-substitution-in-select-statements%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Maybe this sample can help you.



    import sqlite3
    import string

    def char_generator():
    for c in string.ascii_lowercase:
    yield (c,)


    con = sqlite3.connect(":memory:")

    def initdb():
    cur = con.cursor()
    cur.execute("create table characters(c)")

    cur.executemany("insert into characters(c) values (?)", char_generator())

    def search(value):
    values = [c for c in value]
    cur = con.cursor()
    cur.execute('SELECT * FROM characters WHERE c IN (0)'.format(','.join(['?' for c in values])), values)
    return cur.fetchall()


    if __name__ == '__main__':
    initdb()
    print(search("abcde"))


    This code uses parameters. So you do not need to worry about SQL Injection.






    share|improve this answer



























      1














      Maybe this sample can help you.



      import sqlite3
      import string

      def char_generator():
      for c in string.ascii_lowercase:
      yield (c,)


      con = sqlite3.connect(":memory:")

      def initdb():
      cur = con.cursor()
      cur.execute("create table characters(c)")

      cur.executemany("insert into characters(c) values (?)", char_generator())

      def search(value):
      values = [c for c in value]
      cur = con.cursor()
      cur.execute('SELECT * FROM characters WHERE c IN (0)'.format(','.join(['?' for c in values])), values)
      return cur.fetchall()


      if __name__ == '__main__':
      initdb()
      print(search("abcde"))


      This code uses parameters. So you do not need to worry about SQL Injection.






      share|improve this answer

























        1












        1








        1







        Maybe this sample can help you.



        import sqlite3
        import string

        def char_generator():
        for c in string.ascii_lowercase:
        yield (c,)


        con = sqlite3.connect(":memory:")

        def initdb():
        cur = con.cursor()
        cur.execute("create table characters(c)")

        cur.executemany("insert into characters(c) values (?)", char_generator())

        def search(value):
        values = [c for c in value]
        cur = con.cursor()
        cur.execute('SELECT * FROM characters WHERE c IN (0)'.format(','.join(['?' for c in values])), values)
        return cur.fetchall()


        if __name__ == '__main__':
        initdb()
        print(search("abcde"))


        This code uses parameters. So you do not need to worry about SQL Injection.






        share|improve this answer













        Maybe this sample can help you.



        import sqlite3
        import string

        def char_generator():
        for c in string.ascii_lowercase:
        yield (c,)


        con = sqlite3.connect(":memory:")

        def initdb():
        cur = con.cursor()
        cur.execute("create table characters(c)")

        cur.executemany("insert into characters(c) values (?)", char_generator())

        def search(value):
        values = [c for c in value]
        cur = con.cursor()
        cur.execute('SELECT * FROM characters WHERE c IN (0)'.format(','.join(['?' for c in values])), values)
        return cur.fetchall()


        if __name__ == '__main__':
        initdb()
        print(search("abcde"))


        This code uses parameters. So you do not need to worry about SQL Injection.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 17:03









        andercruzbrandercruzbr

        33619




        33619





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55067006%2fusing-sqlite3-db-api-multiple-parameter-substitution-in-select-statements%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved