A
A
Andrey Ololoshchenko2015-01-16 15:46:12
Python
Andrey Ololoshchenko, 2015-01-16 15:46:12

Incomprehensible variable passing during sqlite3 execute?

The problem is, I make a query to the database, the table is created, everything is fine.

cu.execute(insert into inc_indexes(number) values ([])', (nums))

and it writes to me
cu.executemany('insert into inc_indexes(number) values ([])', (nums))
sqlite3.OperationalError: no such column:

if you do it as described in the documentation, you get an error in the number of arguments.
nums is a tuple with alphanumeric values, filled in as needed.
However, when passing a variable to a query, sqlite sees not one element consisting of letters, but all letters as elements, so the process does not go on, can you tell me what the sadness might be?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
yttrium, 2015-01-16
@yttrium

there is a guess that it is necessary to transfer either the correct tuple or a list as the second argument.
and guess because the source code with errors. Please provide real source code.

V
Vapaamies, 2015-01-16
@vapaamies

Number is not a keyword in SQLite? The number of fields in brackets must match the number of their values ​​in brackets after values ​​.

A
Andrey Ololoshchenko, 2015-01-16
@veremii

db = sqlite3
    c = db.connect(database="incidents")
    cu = c.cursor()
    print (nums)
    cu.execute('create table if not exists inc_indexes(id INTEGER PRIMARY KEY AUTOINCREMENT, number TEXT)')
    c.commit()
    #Fillup table with short information
    for i in nums:
        cu.execute('insert into inc_indexes(number) values (?)', i )
        c.commit()

Sobsna here is a piece of code. nums - this is a list, the index gives what you need, namely the word consisting of 8 letters, all together.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question