Arsilex Posted May 2, 2017 Share Posted May 2, 2017 (edited) Well i have a problem with the dbQuery i'm trying to insert into my database this string: Quote "How are you?" But as i have ? on my string dbQuery detect is as a argument for the dbQuery argument but as i dont give a argument automaticly parsing it into Quote " How are you' " As i read on the wiki if i use ?? the ? wont be a argument anymore so with a simple str:gsub("?" "??") i'm chaning it but i still getting ' instead of every ? character.. I already tried using ? into a string something like this "How are you '?'" but still nothing in every case i'm getting ' as ? is this a current dbQuery bug or i'm just doing something bad? This is the function i'm using to insert function mysqlQuery(str) if sourceResource == getResourceFromName( "runcode" ) then return false end checkConnection() str = dbPrepareString(connection, str:gsub( "?", '"??"' ) ) local qh = dbQuery( connection, str ) writeToLog(getResourceName(sourceResource), str) return qh end And the way i'm using it: local query = exports.sql:mysqlQuery( "INSERT INTO justTABLE (questions) VALUES('"..questions.."')" ) questions is a JSON string with questions. Edited May 2, 2017 by Arsilex Link to comment
DNL291 Posted May 3, 2017 Share Posted May 3, 2017 (edited) Try this: exports.sql:mysqlQuery ( "INSERT INTO `justTABLE` ( `questions` ) VALUES ( ? );", questions ) EDIT: Remember, you should use dbExec and not dbQuery. Edited May 3, 2017 by DNL291 1 Link to comment
Arsilex Posted May 3, 2017 Author Share Posted May 3, 2017 7 hours ago, DNL291 said: Try this: exports.sql:mysqlQuery ( "INSERT INTO `justTABLE` ( `questions` ) VALUES ( ? );", questions ) EDIT: Remember, you should use dbExec and not dbQuery. Isn't dbExec only used for UPDATE, DELETE and some other which doesnt give any return as i know INSER INTO return rows affected last ID and others or i'm wrong? Link to comment
DNL291 Posted May 3, 2017 Share Posted May 3, 2017 INSERT INTO statement is for dbExec as well. By the way, replace your function 'mysqlQuery' with this function: function mysqlQuery( ... ) if sourceResource == getResourceFromName( "runcode" ) then return false end checkConnection() local qh = dbPoll( dbQuery( db, ... ), - 1 ) writeToLog(getResourceName(sourceResource), table.concat( { ... }, ", " )) return qh end Link to comment
Arsilex Posted May 4, 2017 Author Share Posted May 4, 2017 8 hours ago, DNL291 said: INSERT INTO statement is for dbExec as well. By the way, replace your function 'mysqlQuery' with this function: function mysqlQuery( ... ) if sourceResource == getResourceFromName( "runcode" ) then return false end checkConnection() local qh = dbPoll( dbQuery( db, ... ), - 1 ) writeToLog(getResourceName(sourceResource), table.concat( { ... }, ", " )) return qh end Works fine with: VALUES ( ? );", questions Thanks, @DNL291 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now