B
B
Bruceee2017-07-18 00:02:50
Python
Bruceee, 2017-07-18 00:02:50

Why does the “no such column” error fall?

Why does the committed line execute normally, but the active line throws an error?

def add_row():
  conn = sqlite3.connect('database2.sqlite')
  cursor = conn.cursor()

  # cursor.execute("INSERT INTO table1 (id, text_value, num_value) VALUES (7, 'hello', 12)")
  cursor.execute("INSERT OR IGNORE INTO {table_name} (id, text_value, num_value) VALUES ({col_id}, {col_text}, {col_num})"\
          .format(table_name = 'table1', col_id = 8, col_text = 'fff', col_num = 12))

  conn.commit()
  conn.close()
add_row()

Traceback (most recent call last):
  File "/Users/macmac/python/python and DB/probe2.py", line 45, in <module>
    add_row(6, 'hello2', 12)
  File "/Users/macmac/python/python and DB/probe2.py", line 40, in add_row
    .format(table_name = 'table1', col_id = 8, col_text = 'fff', col_num = 12))
sqlite3.OperationalError: no such column: fff

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Abdulla Mursalov, 2017-07-18
@Bruceee

cursor.execute("INSERT OR IGNORE INTO t1 (col1, col2, col3) VALUES (? ? ?)", (col1, col2, col3))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question