1

Getting an error when trying to insert a row into SQLite table from Python.

The relevant code;

sql = '''INSERT INTO scr(scr=?, close_date=?, vendor=?, application=?, dev=?, tester=?, release=?)''', (issueId, closeDate, vendor, application, assignedDev, assignedTester, enterpriseRelease)
try:
    cursor.execute(sql)
    db.commit()
except Exception, err:
    print("\nFailed to insert row into table scr:\n" + str(sql))
    print(Exception, err)

and the error returned:

Failed to insert row into table scr:
('INSERT INTO scr(scr=?, close_date=?, vendor=?, application=?, dev=?, tester=?, release=?)', ('236500', '0', 'Database', 'Starbase Deleted', 'john.doe', 'jane.doe', 'None'))
(<type 'exceptions.Exception'>, ValueError('operation parameter must be str or unicode',))

1 Answer 1

2

Your sql statement is not right, try this:

sql = '''INSERT INTO scr(scr, close_date, vendor, application, dev, tester, release) VALUES (?, ?, ?, ?, ?, ?, ?)'''
params = (issueId, closeDate, vendor, application, assignedDev, assignedTester, enterpriseRelease)

try:
    cursor.execute(sql, params)
    db.commit()
except Exception as err:
    print("\nFailed to insert row into table scr:\n" + str(sql))
    print(Exception, err)
Sign up to request clarification or add additional context in comments.

1 Comment

result after making changes: Failed to insert row into table scr: ('INSERT INTO scr(scr, close_date, vendor, application, dev, tester, release)',) (<type 'exceptions.Exception'>, ValueError('operation parameter must be str or unicode',))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.