Jump to content

dbExec Problem


Overkillz

Recommended Posts

Posted (edited)

Hey there dear community, today I started to work on a system which will be sync with my forum, leaving out it. Im trying to update a value on a colum, however, I couldn't do it due to I cannot understand at all dbExec Function

 

local tableAccount = {"plCash","plPoints","plMapsplayed","plMapswon","plWinratio","plHunters","plToptimes","plToptimes1","plPvps","plPvpswon","plPvpsratio"}

function updatePlayerDatas(account)
	for i=1,#tableAccount do
		local randomValues = math.random(1,328842)
		dbExec (dbConnectTable.connection, "UPDATE core_members SET "..tableAccount[i].."="..randomValues.." WHERE `name` = "..account .."" ) 
	end
end

Table: core_members

Column: tableAccount Array

Debugscript 3 drops me: You have an error on your SQL syntax ...

Thanks for reading.

Regards.

Edited by Overkillz
Posted (edited)

I think (not sure) that it's better to run 1 query instead of multiple queries in a row

dbExec (dbConnectTable.connection, "UPDATE core_members SET ?? = ??, ?? = ??, ?? = ??, ?? = ??, ?? = ??, ?? = ??, ?? = ??, ?? = ??, ?? = ??, ?? = ??, ?? = ?? WHERE `name` = ??", tableAccount[1], 0, tableAccount[2], 0, tableAccount[3], 0, tableAccount[4], 0, tableAccount[5], 0, tableAccount[6], 0, tableAccount[7], 0, tableAccount[8], 0, tableAccount[9], 0, tableAccount[10], 0, tableAccount[11], 0)

Don't concat, use ?? and write the parameters in the end. It does seem a lot tho might be a better way and I haven't tested it

 

Note that I've used 0 as value for everything this has to be changed

Edited by ViRuZGamiing

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted

Im a bit dump. I have solved the problem following ur example.

I didn't realize that ??=?? expression is remplaced by the arguments.

However, I was using a for, so, the code can be shorter by this

	local tableNamecall = "core_members"
	local name = "name"
	for i=1,#tableAccount do
		local randomValues = math.random(1000,328842)
		dbExec( dbConnectTable.connection, "UPDATE ?? SET ??=? WHERE ??=?", tableNamecall, tableAccount[i], randomValues, name, account )
	end

Regards.

#You can close the topic

Posted (edited)

Your code is shorter indeed but the difference is, Analogue example:

You're in a store and want 10 things, you:

For each question do

   Look for a worker and ask where you Can find 1 thing.

 

While you could ask all 10 items in 1 time. It's a performance difference

Edited by ViRuZGamiing

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

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