Jump to content

dbQuery problem...


Recommended Posts

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 by Arsilex
Link to comment

Try this:

exports.sql:mysqlQuery ( "INSERT INTO `justTABLE` ( `questions` ) VALUES ( ? );", questions )

 

EDIT: Remember, you should use dbExec and not dbQuery.

Edited by DNL291
  • Like 1
Link to comment
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

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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...