tags:

views:

26

answers:

1

I notice a very weird problem in my code. I am inserting a value of 128 but in my database it says 127.

I'd like to look at the mysql general/query logs however i dont ever see any log files produce no matter what i do. I tried -l , -l with an absolute path and --general_log_file. No luck. I also used mysqladmin flush-logs. Still nothing

+2  A: 

Are you using a signed TINYINT datatype by any chance?

CREATE TABLE my_table (id TINYINT);
Query OK, 0 rows affected (0.03 sec)

INSERT INTO my_table VALUES (128);
Query OK, 1 row affected, 1 warning (0.00 sec)

SELECT * FROM my_table;
+------+
| id   |
+------+
|  127 |
+------+
1 row in set (0.00 sec)
Daniel Vassallo
!!! yes! that is the problem. Wow. Why (would mysql let me do that)... ouch.Whomever reads the title and excepts the answer will be disappointed. Is there an unsigned 1 byte type or do i need to use SMALLINT?
acidzombie24
@acidzombie24: Yes you can use an unsigned 1 byte: `CREATE TABLE my_table (id TINYINT UNSIGNED);`, or if you want to alter your current table: `ALTER TABLE my_table MODIFY COLUMN id TINYINT UNSIGNED;`
Daniel Vassallo