0

Dears,

how can I check if pos_cli from database is equal to variable pos_id? for now with code below I get the following error

cur.execute("CREATE TABLE IF NOT EXISTS Magnit_Coor (pos_cli INTEGER PRIMARY KEY, lat INTEGER, long INTEGER);")
cur.execute('SELECT * FROM Magnit_pos')
data = cur.fetchall()
while True:
    for coo in data:
        full_add = coo[6:11]
        pos_id = coo[0]
        print (pos_id)
        yand_add = ", ".join(full_add)
        g = cur.execute('SELECT EXISTS (SELECT * FROM Magnit_Coor WHERE pos_cli = (?))',pos_id)
        g = cur.fetchone()[0]

error below

10001
Traceback (most recent call last):
  File "geoco.py", line 17, in <module>
    g = cur.execute('SELECT EXISTS (SELECT * FROM Magnit_pos WHERE pos_cli = (?))',pos_id)
ValueError: parameters are of unsupported type

The initial code to create Magnit_pos table and pos_cli especially below

cur.execute("DROP TABLE IF EXISTS Magnit_Pos;")
cur.execute(
    "CREATE TABLE Magnit_Pos (pos_cli INTEGER PRIMARY KEY, magnit_name TEXT, codesfa TEXT, codewsot TEXT, pos_sap TEXT, source_dc TEXT, zip TEXT, region TEXT, area TEXT, city TEXT, street TEXT, house TEXT, build TEXT);")

with open('magnit.csv') as csvfile:
    magnit = csv.reader(csvfile, delimiter=';')
    print(magnit)
    for row in magnit:
        print(row[0])
        # to_db = [unicode(row[0], "utf8"), unicode(row[1], "utf8")]
        cur.execute("INSERT INTO Magnit_Pos (pos_cli, magnit_name, codesfa, codewsot, pos_sap, source_dc, zip, region, area, city, street, house, build) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", row)
2
  • 2
    are you expecting people to guess what is inside data variable? Commented Jun 9, 2018 at 19:43
  • just added a few more code and details in the question Commented Jun 9, 2018 at 19:54

1 Answer 1

1

From python's sqlite3 documentation (emphasis mine):

Put ? as a placeholder wherever you want to use a value, and then provide a tuple of values as the second argument to the cursor’s execute() method.

So you should be using:

    g = cur.execute('SELECT EXISTS (SELECT * FROM Magnit_Coor WHERE pos_cli = (?))',(pos_id,))
Sign up to request clarification or add additional context in comments.

Comments

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.