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')
python sql
add a comment |
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')
python sql
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
add a comment |
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')
python sql
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
python sql
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
add a comment |
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
add a comment |
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 (?, ?, ?, ?, ?)"
add a comment |
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 (?, ?, ?, ?, ?)"
add a comment |
up vote
0
down vote
Assuming you're using pyodbc, the parameter marker is a ?:
sql = "INSERT INTO software VALUES (?, ?, ?, ?, ?)"
add a comment |
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 (?, ?, ?, ?, ?)"
Assuming you're using pyodbc, the parameter marker is a ?:
sql = "INSERT INTO software VALUES (?, ?, ?, ?, ?)"
answered Nov 7 at 18:54
Mureinik
175k21125192
175k21125192
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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