mysql1_dart icon indicating copy to clipboard operation
mysql1_dart copied to clipboard

i'm not able to update query with dynamic column name

Open Sreenivassreee opened this issue 5 years ago • 1 comments

var res = await conn.query( "UPDATE levelDetails SET ?=? WHERE userid=?", [Level, percentage, userId]);

Exception has occurred. MySqlException (Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?=? WHERE userid=?' at line 1)

Please help me..

im not able to update query with dynamic column name

Sreenivassreee avatar May 16 '20 09:05 Sreenivassreee

You can try this.

if ( x == 1 ) fieldName = "field1";
 else if ( x == 2 ) fieldName = 'field2';

String cQ = "UPDATE levelDetails SET $fieldName=? WHERE useriid = ?";

await.conn.query(cQ,[Level, percentage, userId]); I Hope it works for You !!

rbtsigma avatar May 20 '20 00:05 rbtsigma