• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

mysql query updates all columns

vexler222

Active Member
Joined
Apr 22, 2012
Messages
714
Solutions
15
Reaction score
46
Hi, can someone tell me why this

Code:
db.query(string.format("UPDATE exclusive_hunts SET `hunt_id` = %d, `guid_player` = %d, `time` = %s, `to_time` = %s", item.actionid, guid, os.time(), (os.time() + tempo)))

Updating all columns in table?
Table look that:

1655629061408.png

After when im go to teleport with aid 64151

1655629013263.png

Why it not update only column with hunt_id = 64151?
And after this i can go to all teleport, from this script to aid 64150/64151/64152/64153
 
Solution
Because you use "SET hunt_id" statement instead "WHERE hunt_id":
SQL:
SET `hunt_id` = %d
instead:
SQL:
WHERE `hunt_id` = %d

Probably you want change all columns with id "hunt_id", so use "WHERE" statement for variable "hunt_id":
Code:
db.query(string.format("UPDATE exclusive_hunts SET `guid_player` = %d, `time` = %s, `to_time` = %s WHERE `hunt_id` = %d", guid, os.time(), (os.time() + tempo), item.actionid))

More info:
SQL update

If column "hunt_id" is unique, you may use additional "LIMIT 0,1" statement (end search, when you find unique value - your query will be a bit more optimized)
Code:
db.query(string.format("UPDATE exclusive_hunts SET `guid_player` = %d, `time` = %s, `to_time` = %s WHERE  `hunt_id` = %d LIMIT 0,1", guid...
Because you use "SET hunt_id" statement instead "WHERE hunt_id":
SQL:
SET `hunt_id` = %d
instead:
SQL:
WHERE `hunt_id` = %d

Probably you want change all columns with id "hunt_id", so use "WHERE" statement for variable "hunt_id":
Code:
db.query(string.format("UPDATE exclusive_hunts SET `guid_player` = %d, `time` = %s, `to_time` = %s WHERE `hunt_id` = %d", guid, os.time(), (os.time() + tempo), item.actionid))

More info:
SQL update

If column "hunt_id" is unique, you may use additional "LIMIT 0,1" statement (end search, when you find unique value - your query will be a bit more optimized)
Code:
db.query(string.format("UPDATE exclusive_hunts SET `guid_player` = %d, `time` = %s, `to_time` = %s WHERE  `hunt_id` = %d LIMIT 0,1", guid, os.time(), (os.time() + tempo), item.actionid))

More info:
MYSQL limit
 
Solution
Because you use "SET hunt_id" statement instead "WHERE hunt_id":
SQL:
SET `hunt_id` = %d
instead:
SQL:
WHERE `hunt_id` = %d

Probably you want change all columns with id "hunt_id", so use "WHERE" statement for variable "hunt_id":
Code:
db.query(string.format("UPDATE exclusive_hunts SET `guid_player` = %d, `time` = %s, `to_time` = %s WHERE `hunt_id` = %d", guid, os.time(), (os.time() + tempo), item.actionid))

More info:
SQL update

If column "hunt_id" is unique, you may use additional "LIMIT 0,1" statement (end search, when you find unique value - your query will be a bit more optimized)
Code:
db.query(string.format("UPDATE exclusive_hunts SET `guid_player` = %d, `time` = %s, `to_time` = %s WHERE  `hunt_id` = %d LIMIT 0,1", guid, os.time(), (os.time() + tempo), item.actionid))

More info:
MYSQL limit

Thanks, mysql is for me so crazy, where lua language i start understand little, then mysql is so hard for me
 
Back
Top