0

I am Using python3.

self.cur.execute("""INSERT or IGNORE INTO {0}(Konu, KonuAnlatımı, SoruSayısı, ToplamDogru, ToplamYanlıs) VALUES
 ('{1}', '{2}', '{3}','{4}', '{5}') UPDATE {0} SET (KonuAnlatımı = '{2}'),
 SoruSayısı = '{6}',
 TaplamDogru = '{7}',
 ToplamYanlıs = '{8}'
 WHERE Konu = {1}""".format(ders, konu, Çalışıldı, soru, dogru, yanlis,
 str(int(soru) + int(self.cur.execute(
 "Select SoruSayısı From "+ders+" WHERE Konu = '"+konu+"'").fetchone()[0])),
 str(int(dogru) + int(self.cur.execute(
 "Select ToplamDogru From "+ders+" WHERE Konu = '"+konu+"'").fetchone()[0])),
 str(int(dogru) + int(self.cur.execute(
 "Select ToplamYanlıs From "+ders+" WHERE Konu = '"+konu+"'").fetchone()[0]))))

I get an errow which is :

"Select ToplamYanlıs From "+ders+" WHERE Konu = '"+konu+"'").fetchone()[0]))))

sqlite3.Warning: You can only execute one statement at a time.

if I delete ';' I get this:

"Select ToplamYanlıs From "+ders+" WHERE Konu = '"+konu+"'").fetchone()[0]))))

sqlite3.OperationalError: near "UPDATE": syntax error

So what is happening? And I haven't find the title name. sorry...

asked Jul 2, 2014 at 15:19
1
  • you should also fix your code to prevent SQL injection. Commented Jul 2, 2014 at 17:50

2 Answers 2

1

I would suggest breaking it down to smaller parts first, for debugging, and build it up again when each part is working as expected.

I have taken the liberty to replace non-ASCII characters with visually similar ASCII versions for this example.

SoruSayisi = self.cur.execute(
 "SELECT SoruSayisi From {} WHERE Konu = ?".format(ders), konu
).fetchone()[0]
TaplamDogru = self.cur.execute(
 "SELECT ToplamDogru From {} WHERE Konu = ?".format(konu), konu
).fetchone()[0]
ToplamYanlis = self.cur.execute(
 "SELECT ToplamYanlis FROM {} WHERE Konu = ?".format(konu), konu
) .fetchone()[0]
self.cur.execute("""\
INSERT or IGNORE INTO {0}
(Konu, KonuAnlatımı, SoruSayisi, ToplamDogru, ToplamYanlis)
VALUES (?, ?, ?, ?, ?)""".format(ders),
 konu,
 Calisildi,
 soru,
 dogru,
 yanlis)
self.cur.execute("""
UPDATE {0}
SET KonuAnlatımı = ?,
 SoruSayisi = ?,
 TaplamDogru = ?,
 ToplamYanlis = ?
WHERE Konu = {1}""".format(ders),
 Calisildi,
 str(int(soru) + int(SoruSayisi)),
 str(int(dogru) + int(TaplamDogru)),
 str(int(dogru) + int(ToplamYanlis)))

Since I cannot test this, I may have made mistakes. It's just an approach to finding out what is going on.

answered Dec 10, 2016 at 4:36
Sign up to request clarification or add additional context in comments.

Comments

0
  1. Don't use Python {num} formatting, it won't quote correctly for SQL. Use the ? placeholder instead:

    c.executemany('INSERT INTO stocks VALUES (?,?)', (12, 'whiskey'))

  2. Do the sub selects separately, verify the values, then use them in the larger SQL statement -- it's clearer and simpler.

https://docs.python.org/3/library/sqlite3.html

answered Jul 2, 2014 at 15:38

1 Comment

Oh, you can't use ? parameters for SQL, only for the values inserted. For now, hard code the table name, using ? for each value. If that works, then use good old Python string formatting to insert the table name like the original code.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.