Python SQL insert is failing











up vote
1
down vote

favorite












I have 5 character fields in my SQL database, but I am unable to insert rows into the table. I have no problem when I do in Access Database.



Here is the code for my Insert statement and the error I am getting:



f1=hostname; f2=p.Caption; f3=p.Version; f4="1998-10-01";f5="2018-11-01"
print(f1,'--',f2,'--',f3,'--',f4,'--',f5)
sql = "INSERT INTO software VALUES (%s, %s, %s, %s, %s)"
cursor.execute(sql, {f1,f2,f3,f4,f5})


Error Message:




cursor.execute(sql, (f1,f2,f3,f4,f5)) pyodbc.ProgrammingError: ('The
SQL contains 0 parameter markers, but 5 parameters were supplied',
'HY000')











share|improve this question
























  • Have a look at python-course.eu/sql_python.php
    – Paul Rousseau
    Nov 7 at 18:09










  • how many columns your table has ?
    – Tera Byte
    Nov 7 at 18:09










  • one auto generate Identity column, and 5 other columns.
    – user1834682
    Nov 7 at 18:13










  • When I use following code: w = wmi.WMI() for p in w.Win32_Product(): f1=hostname; f2=p.Caption; f3=p.Version; f4="1998-10-01";f5="2018-11-01" sql_command = """INSERT INTO software (computer, software, version, date_installed, date_checked) VALUES (f1, f2, f3, f4, f5);""" cursor.execute(sql_command) conn.commit() I get [SQL Server]Invalid column name 'f1'. (207) (SQLExecDirectW) error
    – user1834682
    Nov 7 at 18:32

















up vote
1
down vote

favorite












I have 5 character fields in my SQL database, but I am unable to insert rows into the table. I have no problem when I do in Access Database.



Here is the code for my Insert statement and the error I am getting:



f1=hostname; f2=p.Caption; f3=p.Version; f4="1998-10-01";f5="2018-11-01"
print(f1,'--',f2,'--',f3,'--',f4,'--',f5)
sql = "INSERT INTO software VALUES (%s, %s, %s, %s, %s)"
cursor.execute(sql, {f1,f2,f3,f4,f5})


Error Message:




cursor.execute(sql, (f1,f2,f3,f4,f5)) pyodbc.ProgrammingError: ('The
SQL contains 0 parameter markers, but 5 parameters were supplied',
'HY000')











share|improve this question
























  • Have a look at python-course.eu/sql_python.php
    – Paul Rousseau
    Nov 7 at 18:09










  • how many columns your table has ?
    – Tera Byte
    Nov 7 at 18:09










  • one auto generate Identity column, and 5 other columns.
    – user1834682
    Nov 7 at 18:13










  • When I use following code: w = wmi.WMI() for p in w.Win32_Product(): f1=hostname; f2=p.Caption; f3=p.Version; f4="1998-10-01";f5="2018-11-01" sql_command = """INSERT INTO software (computer, software, version, date_installed, date_checked) VALUES (f1, f2, f3, f4, f5);""" cursor.execute(sql_command) conn.commit() I get [SQL Server]Invalid column name 'f1'. (207) (SQLExecDirectW) error
    – user1834682
    Nov 7 at 18:32















up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have 5 character fields in my SQL database, but I am unable to insert rows into the table. I have no problem when I do in Access Database.



Here is the code for my Insert statement and the error I am getting:



f1=hostname; f2=p.Caption; f3=p.Version; f4="1998-10-01";f5="2018-11-01"
print(f1,'--',f2,'--',f3,'--',f4,'--',f5)
sql = "INSERT INTO software VALUES (%s, %s, %s, %s, %s)"
cursor.execute(sql, {f1,f2,f3,f4,f5})


Error Message:




cursor.execute(sql, (f1,f2,f3,f4,f5)) pyodbc.ProgrammingError: ('The
SQL contains 0 parameter markers, but 5 parameters were supplied',
'HY000')











share|improve this question















I have 5 character fields in my SQL database, but I am unable to insert rows into the table. I have no problem when I do in Access Database.



Here is the code for my Insert statement and the error I am getting:



f1=hostname; f2=p.Caption; f3=p.Version; f4="1998-10-01";f5="2018-11-01"
print(f1,'--',f2,'--',f3,'--',f4,'--',f5)
sql = "INSERT INTO software VALUES (%s, %s, %s, %s, %s)"
cursor.execute(sql, {f1,f2,f3,f4,f5})


Error Message:




cursor.execute(sql, (f1,f2,f3,f4,f5)) pyodbc.ProgrammingError: ('The
SQL contains 0 parameter markers, but 5 parameters were supplied',
'HY000')








python sql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 19:35









jarlh

27.9k52137




27.9k52137










asked Nov 7 at 18:04









user1834682

3127




3127












  • Have a look at python-course.eu/sql_python.php
    – Paul Rousseau
    Nov 7 at 18:09










  • how many columns your table has ?
    – Tera Byte
    Nov 7 at 18:09










  • one auto generate Identity column, and 5 other columns.
    – user1834682
    Nov 7 at 18:13










  • When I use following code: w = wmi.WMI() for p in w.Win32_Product(): f1=hostname; f2=p.Caption; f3=p.Version; f4="1998-10-01";f5="2018-11-01" sql_command = """INSERT INTO software (computer, software, version, date_installed, date_checked) VALUES (f1, f2, f3, f4, f5);""" cursor.execute(sql_command) conn.commit() I get [SQL Server]Invalid column name 'f1'. (207) (SQLExecDirectW) error
    – user1834682
    Nov 7 at 18:32




















  • Have a look at python-course.eu/sql_python.php
    – Paul Rousseau
    Nov 7 at 18:09










  • how many columns your table has ?
    – Tera Byte
    Nov 7 at 18:09










  • one auto generate Identity column, and 5 other columns.
    – user1834682
    Nov 7 at 18:13










  • When I use following code: w = wmi.WMI() for p in w.Win32_Product(): f1=hostname; f2=p.Caption; f3=p.Version; f4="1998-10-01";f5="2018-11-01" sql_command = """INSERT INTO software (computer, software, version, date_installed, date_checked) VALUES (f1, f2, f3, f4, f5);""" cursor.execute(sql_command) conn.commit() I get [SQL Server]Invalid column name 'f1'. (207) (SQLExecDirectW) error
    – user1834682
    Nov 7 at 18:32


















Have a look at python-course.eu/sql_python.php
– Paul Rousseau
Nov 7 at 18:09




Have a look at python-course.eu/sql_python.php
– Paul Rousseau
Nov 7 at 18:09












how many columns your table has ?
– Tera Byte
Nov 7 at 18:09




how many columns your table has ?
– Tera Byte
Nov 7 at 18:09












one auto generate Identity column, and 5 other columns.
– user1834682
Nov 7 at 18:13




one auto generate Identity column, and 5 other columns.
– user1834682
Nov 7 at 18:13












When I use following code: w = wmi.WMI() for p in w.Win32_Product(): f1=hostname; f2=p.Caption; f3=p.Version; f4="1998-10-01";f5="2018-11-01" sql_command = """INSERT INTO software (computer, software, version, date_installed, date_checked) VALUES (f1, f2, f3, f4, f5);""" cursor.execute(sql_command) conn.commit() I get [SQL Server]Invalid column name 'f1'. (207) (SQLExecDirectW) error
– user1834682
Nov 7 at 18:32






When I use following code: w = wmi.WMI() for p in w.Win32_Product(): f1=hostname; f2=p.Caption; f3=p.Version; f4="1998-10-01";f5="2018-11-01" sql_command = """INSERT INTO software (computer, software, version, date_installed, date_checked) VALUES (f1, f2, f3, f4, f5);""" cursor.execute(sql_command) conn.commit() I get [SQL Server]Invalid column name 'f1'. (207) (SQLExecDirectW) error
– user1834682
Nov 7 at 18:32














1 Answer
1






active

oldest

votes

















up vote
0
down vote













Assuming you're using pyodbc, the parameter marker is a ?:



sql = "INSERT INTO software VALUES (?, ?, ?, ?, ?)"





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',
    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%2f53195219%2fpython-sql-insert-is-failing%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








    up vote
    0
    down vote













    Assuming you're using pyodbc, the parameter marker is a ?:



    sql = "INSERT INTO software VALUES (?, ?, ?, ?, ?)"





    share|improve this answer

























      up vote
      0
      down vote













      Assuming you're using pyodbc, the parameter marker is a ?:



      sql = "INSERT INTO software VALUES (?, ?, ?, ?, ?)"





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Assuming you're using pyodbc, the parameter marker is a ?:



        sql = "INSERT INTO software VALUES (?, ?, ?, ?, ?)"





        share|improve this answer












        Assuming you're using pyodbc, the parameter marker is a ?:



        sql = "INSERT INTO software VALUES (?, ?, ?, ?, ?)"






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 7 at 18:54









        Mureinik

        175k21125192




        175k21125192






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195219%2fpython-sql-insert-is-failing%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







            這個網誌中的熱門文章

            Academy of Television Arts & Sciences

            L'Équipe

            1995 France bombings