koron / nvgd

Filterable (grep, head and tail) HTTP file server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

strict type check when import excel

koron opened this issue · comments

target: MySQL

数字型のカラムへ文字列の値を入れた場合にエラーにしたい。

暗黙の型変換はこの辺を参照: https://qiita.com/shioharu_/items/a6397384ea1397a1fcf0

id = a だと暗黙の型変換はないが id = 'a' だと型変換されてしまう。

SET sql_mode='TRADITIONAL' すれば入らなくなった。

mysql> SET sql_mode='TRADITIONAL';
Query OK, 0 rows affected (0.00 sec)

mysql> insert into countrylanguage values('ABWZ', 'Japanese', 'F', 'foobar');
ERROR 1406 (22001): Data too long for column 'CountryCode' at row 1

mysql> insert into countrylanguage values('ABW', 'Japanese', 'F', 'foobar');
ERROR 1366 (HY000): Incorrect decimal value: 'foobar' for column 'Percentage' at row 1

https://qiita.com/park-jh/items/32b21d7b8d24b0ab3dba

MySQLのDB接続文字列に ?sql_mode=TRADITIONAL と付ければ良さげ。

設定例:

protocols:

  db:
    mysql:
      driver: mysql
      multiple_database: true
      name: "mysql:abcd1234@tcp(127.0.0.1:3306)/mysql?sql_mode=TRADITIONAL"

設定による回避手段がありそうなので wontfix で close

invalid に変更