Reputation: 31
Im trying to get eeror about invalid data for a query but it seems mysql accept strings as tiney in queries and set 0 instead of returning any error.
So how can I restrict it to just accept integers.
Thanks in advance.
Upvotes: 0
Views: 221
Reputation: 42632
This is SQL Mode-dependent.
In strict mode you must receive either 'Data truncated' (inserted value starts from numeric chars) or 'Incorrect integer value' (first symbol is not numeric) error message, and none data must be inserted.
If strict mode is disabled then warning is generated instead of error, and the value is converted to numeric (all symbols starting from first non-numeric one are truncated, then the value is converted to number, if it is empty string then zero is assigned).
Data type checking (and convertion if needed) is performed firstly, even before BEFORE INSERT trigger.
Upvotes: 1