views:

60

answers:

4

Hey guys,

I am using pawn script for something, and everything works great except for one of my queries. For some reason, it will not work, and I am hoping it is simple enough someone can spot my mistake as I have been banging my head on it for days.

http://ampaste.net/m6a887d30

The two highlighted lines are the queries that are not working. The other one works fine, but the values for 'class1kills' and 'class2kills' remain at 0. Here is a screenshot from phpmyadmin incase I did something silly.

http://brutalservers.net/sql.png

+1  A: 

Is MySQL case sensitive when it comes to comparing strings? Otherwise check encodings etc. That is all I can think of.

uriDium
Default collation `latin1_swedish_ci` is not case sensitive.
Marcus Adams
It's case-sensitive on binary strings or if you use =. `LIKE` is insensitive.
Duncan
+2  A: 

Try inserting a row into global, and then updating it.

Note that without a WHERE clause on your UPDATE statement, all rows will be updated.

Marcus Adams
+2  A: 

Your SQL-code, copied from where you pasted it:

UPDATE global SET class1kills = class1kills + 1

In addition to what the user Marcus said, even if there is a row in the table, but it's value is NULL, then adding to the value will not work. You will have to set it to an integer value first, such as 0.

E.g.:

mysql> create table mytable(a int);
mysql> insert into mytable(a) values (0),(NULL);
mysql> select * from mytable;

+------+
| a    |
+------+
|    0 |
| NULL |
+------+

mysql> update mytable set a = a+1;

mysql> select * from mytable;

+------+
| a    |
+------+
|    1 |
| NULL |
+------+

The NULL value was not updated!

By the way, are you sure you want to update the complete table?

thomastiger
I think this might be the key, here is the query I am using to create the table from the code.Format(query, 1024, "CREATE TABLE IF NOT EXISTS global (`class1kills` INT(20) unsigned NOT NULL DEFAULT '0', `class2kills` INT(20) unsigned NOT NULL DEFAULT '0')");Isn't that setting it to 0, not NULL? And yeah, if you look at my screenshot it is basically just a way of keeping track of total kills for one class versus total kills for another class.So is the table created correctly from that query?
Brett Powell
A: 

Sorry guys, turns out it is a bug with the scripting language. For some reason two queries right after each other causes the second one not to be called properly.

Thank you all for all of the help!

Brett Powell