If you set a field name in table that is a numeric value, because array_merge in DB_forge.php function add_field, this numeric names are transformed into array index, making wrong result.
Code: $fields = array(
'0000' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'0100' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'0200' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'0300' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'0400' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'0500' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'0600' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'0700' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'0800' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'0900' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'1000' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'1100' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'1200' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'1300' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'1400' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'1500' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'1600' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'1700' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'1800' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'1900' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'2000' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'2100' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'2200' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
'2300' => array(
'type' => 'BIT',
'constraint' => '1',
'null' => FALSE,
'default' => 0,
),
);
f( !$this->dbforge->add_field( $fields ) )
return $this->db->error();
Return:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0000 BIT(1) NOT NULL DEFAULT 0, 0100 BIT(1) NOT NULL DEFAULT 0, 0200 BIT(1) NO'
Dump of SQL:
Code: CREATE TABLE IF NOT EXISTS `schedule_time` (
0000 BIT(1) NOT NULL DEFAULT 0,
0100 BIT(1) NOT NULL DEFAULT 0,
0200 BIT(1) NOT NULL DEFAULT 0,
0300 BIT(1) NOT NULL DEFAULT 0,
0400 BIT(1) NOT NULL DEFAULT 0,
0500 BIT(1) NOT NULL DEFAULT 0,
0600 BIT(1) NOT NULL DEFAULT 0,
0700 BIT(1) NOT NULL DEFAULT 0,
0800 BIT(1) NOT NULL DEFAULT 0,
0900 BIT(1) NOT NULL DEFAULT 0,
0 BIT(1) NOT NULL DEFAULT 0,
`1` BIT(1) NOT NULL DEFAULT 0,
`2` BIT(1) NOT NULL DEFAULT 0,
`3` BIT(1) NOT NULL DEFAULT 0,
`4` BIT(1) NOT NULL DEFAULT 0,
`5` BIT(1) NOT NULL DEFAULT 0,
`6` BIT(1) NOT NULL DEFAULT 0,
`7` BIT(1) NOT NULL DEFAULT 0,
`8` BIT(1) NOT NULL DEFAULT 0,
`9` BIT(1) NOT NULL DEFAULT 0,
`10` BIT(1) NOT NULL DEFAULT 0,
`11` BIT(1) NOT NULL DEFAULT 0,
`12` BIT(1) NOT NULL DEFAULT 0,
`13` BIT(1) NOT NULL DEFAULT 0
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_general_ci
Expected SQL:
Code: CREATE TABLE `schedule_time` (
`0000` BIT NOT NULL DEFAULT 0,
`0100` BIT NOT NULL DEFAULT 0,
`0200` BIT NOT NULL DEFAULT 0,
`0300` BIT NOT NULL DEFAULT 0,
`0400` BIT NOT NULL DEFAULT 0,
`0500` BIT NOT NULL DEFAULT 0,
`0600` BIT NOT NULL DEFAULT 0,
`0700` BIT NOT NULL DEFAULT 0,
`0800` BIT NOT NULL DEFAULT 0,
`0900` BIT NOT NULL DEFAULT 0,
`1000` BIT NOT NULL DEFAULT 0,
`1100` BIT NOT NULL DEFAULT 0,
`1200` BIT NOT NULL DEFAULT 0,
`1300` BIT NOT NULL DEFAULT 0,
`1400` BIT NOT NULL DEFAULT 0,
`1500` BIT NOT NULL DEFAULT 0,
`1600` BIT NOT NULL DEFAULT 0,
`1700` BIT NOT NULL DEFAULT 0,
`1800` BIT NOT NULL DEFAULT 0,
`1900` BIT NOT NULL DEFAULT 0,
`2000` BIT NOT NULL DEFAULT 0,
`2100` BIT NOT NULL DEFAULT 0,
`2200` BIT NOT NULL DEFAULT 0,
`2300` BIT NOT NULL DEFAULT 0,
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_general_ci
|