Forums

"(": syntax error for sqlite3 request in pythonanywhere, but executed on localhost

Hi! pythonanywhere console return "(": syntax error for sqlite3 request, screenshot: http://take.ms/QEtS3

sqlite3.OperationalError: near "(": syntax error

but the request is executed successfully in database and on localhost, screenshot: http://take.ms/mfTJN

code:

cur.executescript('update last_reminders set (user_id, chat_id, last_reminder_text, reminder_message_id, reminder_sent_at) = ("{uid}", "{ch_id}", "{m_text}", "{mes_id}", "{s_at}") where (user_id = "{uid}") and (chat_id = "{ch_id}"); insert into last_reminders (user_id, chat_id, last_reminder_text, reminder_message_id, reminder_sent_at) select "{uid}", "{ch_id}", "{m_text}", "{mes_id}", "{s_at}" where (Select Changes() = 0)'.format(uid=reminder[0], ch_id=reminder[1], m_text=reminder[2], mes_id=reminder[3], s_at=int(datetime.today().timestamp())))

print result from screenshot:

update last_reminders set (user_id, chat_id, last_reminder_text, reminder_message_id, reminder_sent_at) = ("116794415", "116794415", "test", "667", "1515583062") where (user_id =
 "116794415") and (chat_id = "116794415"); insert into last_reminders (user_id, chat_id, last_reminder_text, reminder_message_id, reminder_sent_at) select "116794415", "116794415", "test", "667", "1515583062" where (Select Changes() = 0)

could the versions of sqlite be different?

both of them are sqlite3, but on localhost 3.19.3 2017-06-27 16:48:08 and on pythonanywhere 3.8.2 2013-12-06 14:53:30

That might explain it then? Perhaps you're using some new piece of syntax that's not compatible with the older version? The sqlite docs will have more info.

You'll have to rewrite your queries I'm afraid, there's no real way to upgrade sqlite on pythonanywhere.

In any case -- we recommend against sqlite for production use. Because of the distributed nature of our filesystem, it doesn't perform well, and it won't be reliable with multiple workers. MySQL or Postgres are recommended.

thank you! the problem was in

...set (user_id, chat_id, last_reminder_text, reminder_message_id, reminder_sent_at) = ("{uid}", "{ch_id}", "{m_text}", "{mes_id}", "{s_at}")..

I just replaced it with

user_id = "{uid}", chat_id = "{ch_id}", last_reminder_text = "{m_text}", reminder_message_id = "{mes_id}", reminder_sent_at = "{s_at}"

Excellent, glad you worked it out!