type conversion - Why is it possible to use numeric string values to set integer fields in MySQL, and is this a feature that will always work? -


i noticed phpmyadmin reason seems use numeric string values instead of integer values (i.e. '5' instead of 5) in generated sql queries writing data integer fields in mysql databases, did not know valid sql.

this made me curious, did follow-up experiments myself, , confirm indeed allowed, in ddl queries like:

alter table mytable alter column myintfield set default '5' 

(where, possibly needless say, "myintfield" of "int" type)

and in normal insert , update queries like:

insert mytable (myintfield) values ('5');  update mytable set myintfield = '5' id = 1; 

how/why allowed mysql? databases care types, , strings , integers different types?

also, "feature", same sql injection sanitation procedure used both string values , integer values (instead of integer validation testing input values integer fields , quote-escape-testing input values string fields separately), follow-up question is: can depend on existence , support of feature under conditions in mysql, , in future versions of mysql, i.e. documented somewhere officially?

mysql pretty lax things, default fixing these errors doing can not error out.

mysql have strict mode though not allow behaviour

http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-strict

for more info.

this 'feature' can cause performance issues, comparing sting index'ed int makes index useless (in cases, optimiser can spot , cast input)

strict sql mode

strict mode controls how mysql handles invalid or missing values in data-change statements such insert or update. value can invalid several reasons. example, might have wrong data type column, or might out of range. value missing when new row inserted not contain value non-null column has no explicit default clause in definition. (for null column, null inserted if value missing.) strict mode affects ddl statements such create table.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -