SA-MP Forums Archive
Query. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Query. (/showthread.php?tid=385940)



Query. - BaubaS - 18.10.2012

Hello, I came here with a small question when sending query to database.

Can I use such queries, as:

Quote:

UPDATE `field` = 'field3+field4' WHERE `something` = 'value'

Or, I need to get field3, field4 values first, then sum field3, field4 values and then use

Quote:

UPDATE `field` = 'sum of field3, field4' WHERE ...

Thanks in advance.


Re: Query. - Vince - 18.10.2012

Why don't you just test it ...


Re: Query. - Roel - 18.10.2012

becuase it will not work.
Using the syntax UPDATE will only send value's to the database, if you wan't to do this in one query, you should create a DECLARE query, but not sure if this is possible with MySQL or with SA-MP.

It will be something that looks like this:
PHP код:
DECLARE
  
var_num1 NUMBER
  
var_num2 NUMBER
BEGIN 
  var_num1 
:= 0
  
var_num2 := 0
 
  DECLARE 
    
var_mult NUMBER
  
BEGIN 
  SELECT 
`NUMBERINTO var_num1 FROM `usersWHERE `ID`=1;
  
SELECT `NUMBER2INTO var_num2 FROM `usersWHERE `ID`=1;
    
var_mult := var_num1 var_num2
    
UPDATE `usersSET `TOTALNUM`=var_mult WHERE `ID`=1;
  
END
 
END
But this will never work, and it seems that DECLARE is not a valid syntax in MySQL so I can't help you with this.


Re: Query. - Vince - 18.10.2012

I wrote that because it should work, actually.


Re: Query. - Roel - 18.10.2012

ok, now I'm lost? lol.


Re: Query. - BaubaS - 18.10.2012

I've tried to do this:

mysql_function_query(Handle, "UPDATE `testx` SET `field`=`field2+field3` WHERE `id` = '1'", false, "", "")

with table:

http://clip2net.com/s/2ppTx

Result:
Quote:

[17:29:33] Passing query UPDATE `testx` SET `field`=`field2+field3` WHERE `id` = '1' |
[17:29:33] CMySQLHandler::ProcessQueryThread() - Error will be triggered to OnQueryError()

So I need to get the values?


Re: Query. - SuperViper - 18.10.2012

pawn Код:
mysql_function_query(Handle, "UPDATE `testx` SET `field` = `field2` + `field3` WHERE `id` = '1'", false, "", "");



Re: Query. - BaubaS - 19.10.2012

Thanks.