Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.2.3

Bug #17290 MySQL AUTO_INCREMENT problems
Submitted: 2010-04-04 04:35 UTC
From: fludimir Assigned:
Status: Open Package: MDB_QueryTool (version 1.2.2)
PHP Version: 5.2.12 OS: Windows XP SP2
Roadmaps: (Not assigned)    
Subscription  


 [2010-04-04 04:35 UTC] fludimir (Vladimir Lebedinsky)
Description: ------------ Cannot insert data in mysql table with auto_increment primary key. MDB2 version 2.4.1 Test script: --------------- mysql> describe news; +----------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | date | date | YES | | NULL | | | title | varchar(255) | YES | | NULL | | | announce | text | YES | | NULL | | | text | text | YES | | NULL | | +----------+--------------+------+-----+---------+----------------+ 5 rows in set (0.00 sec) class news extends MDB_QueryTool { var $table = 'news'; var $primaryCol = 'id'; } $news = new news($mdb2); $data = array( 'date' => '2010-04-05', 'title' => 'test', 'announce' => 'test', 'text' => 'test' ); $id = $news->save($data); Expected result: ---------------- Valid insertion and return inserted id Actual result: -------------- MDB_QueryTool 1.2.2 (current stable): MDB2 Error: unknown error _doQuery: [Error message: Could not execute statement] [Last executed query: INSERT INTO news (`date`, `title`, `announce`, `text`, `id`) VALUES ('2010-04-05', 'test', 'test', 'test', 'NULL')] [Native code: 1366] [Native message: Incorrect integer value: 'NULL' for column 'id' at row 1] MDB_QueryTool 1.2.0 (tried a lot of earlier versions to find some working): Valid insert and return inserted id, but instead of using MySQL AUTO_INCREMENT feature there was created news_seq sequence table, and insert query builded with col `id` and some value from sequence for this. Don't know how for another RDBMS, but as for MySQL you don't need to specify auto_increment column at all. Valid query is "INSERT INTO news (`date`, `title`, `announce`, `text`) VALUES ('2010-04-05', 'test', 'test', 'test')" . I also tried version from cvs (Query.php,v 1.84 2008/07/14) and took the same result as with 1.2.0 - insertion works, but by using sequences instead of Auto_Increment

Comments