dongzhou1865 2014-06-30 11:12
浏览 81
已采纳

MySQL默认值无法按预期工作

Hi friends from SO!

This code used to be working, but it seems like it stop working when I cloned the database. There's a table called maps, which has some default values, like maximum. As far as I understand, if my INSERT code has no value, then, the dafault value will be used.

This is what I'm doing:

These values might be there, as they might not be there.

$scan->maximo_exploracion   = addslashes($_GET['scan_maximo_exploracion']);
$scan->proceso_analisis = addslashes($_GET['scan_proceso_analisis']);
$scan->email_user           = addslashes($_GET['scan_email_user']);
$scan->email_owner          = addslashes($_GET['scan_email_owner']);

Then:

db_ask($db_resonance_slave, "
INSERT INTO mapas
SET
usuario_id              = '$user->id',
maximo_exploracion      = '$scan->maximo_exploracion',
proceso_analisis        = '$scan->proceso_analisis',
email_user              = '$scan->email_user',
email_owner             = '$scan->email_owner',
max_proc                = '5',
proceso_exploracion     = 'esperando',
direccion               = '$scan->address',
dominio                 = '$scan->dominio',
dominio_id              = '$dominio->id',
server_address          = '$scan->server_address',
server_zone             = '$scan->zone_name',
server_zone_code        = '$scan->zone_code',
server_response_speed   = '$scan->server_response_speed'
");

Now, a few days ago, with the same code, if $scan->maximo_exploracion didn't have any information, the record would be inserted with the default value which is 100.

At this moment, it's appearing blank. Which, of course, is causing problems.

Any ideas?

Thanks! Chris;


The Table:

CREATE TABLE `mapas` (
`id` INT(12) NOT NULL AUTO_INCREMENT,
`usuario_id` VARCHAR(256) NOT NULL,
`maximo_exploracion` VARCHAR(256) NOT NULL DEFAULT '100',
`max_proc` VARCHAR(256) NOT NULL,
`open_proc` VARCHAR(256) NOT NULL,
`hora_lanzado` VARCHAR(256) NOT NULL,
`direccion` VARCHAR(256) NOT NULL,
`dominio` VARCHAR(256) NOT NULL,
`dominio_id` VARCHAR(256) NOT NULL,
`idioma` VARCHAR(256) NOT NULL,
`server_address` VARCHAR(256) NOT NULL,
`server_zone` VARCHAR(256) NOT NULL,
`server_zone_code` VARCHAR(256) NOT NULL,
`server_response_speed` VARCHAR(256) NOT NULL,
`proceso_exploracion` VARCHAR(256) NOT NULL DEFAULT 'esperando',
`proceso_analisis` VARCHAR(256) NOT NULL DEFAULT 'esperando',
`email_owner` VARCHAR(256) NOT NULL DEFAULT 'False',
`email_user` VARCHAR(256) NOT NULL DEFAULT 'True',
`eliminado` INT(12) NOT NULL DEFAULT '0',
`creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)

COMMENT='Almacena mapas, los mapas son ordenes de exploración y análisis para un dominio específico.' COLLATE='latin1_swedish_ci' ENGINE=InnoDB;

  • 写回答

2条回答 默认 最新

  • douren5490 2014-06-30 13:51
    关注

    Perhaps: http://www.noelherrick.com/blog/mysql-quirk-not-null-defaults

    It indicates using an extended insert (where you specify multiple rows in an insert statement), that you can bypass this default value; a warning is provided instead of errros. Yet single insert statements throw an error.

    This can be avoided presently by

    Set sql_mode = "strict_all_tables"; 
    

    Then use the the default keyword, which will insert that column’s default value.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答