Skip to content
Advertisement

SQL Statment fails to run with Syntax errors using Flutter/Dart and PostgreSql 12, even though exact same query runs to the same db from python

Hi Flutter/Dart/PostgreSQL noob here;

I have an SQL statement which is running fine from a python/Flask application, I am using some variables within it which are added in at runtime to the statement before it is sent to the db.This is the python version;

As I said this works fine apologises if I have not added all the variables, that is a copy and paste issue.

I have changed the SQL code to reflect Dart’s need to have slight changes so the code now looks like this;

the variable miles =2 as testing and keeping it stable and is a local variable for now.

I am getting the error :[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: ERROR 42601 syntax error at or near “{“. I am printing the created SQL statement and it is odd as it seems to stop half way through the process; I get this:

I cant see the issue, please point me in the right direction.

I am running PostgreSQL 12, Flutter version 2.0.2 at C:flutter • Framework revision 8962f6dc68 (4 days ago), 2021-03-11 13:22:20 -0800 • Engine revision 5d8bf811b3 • Dart version 2.12.1

Side note just before posting: I have taken the this statement out and done the usual ‘select * from db’ and query particular columns for data and this all worked fine. Sorry another side note: I know the database is a right mess, it will be rebuilt and changed before use it is literally a dumping server while I figure out what I fully need for my app.

Advertisement

Answer

I believe issue is that you are using “{}” as parameter placeholders in your query (see this part “case when LOCALTIME(0) BETWEEN {} AND {} then” as example). You should either inline them with values (like you are doing with $miles for example) or better pass them as variables @varName and then pass their values along with query, like this:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement