Hello,
I have been unable to find a solution to my problem, so apologies up front if it is totally FAQ: How do I auto-increment the primary key in a MySQL table?
I am using:
TOS V3.1.3 r26090
Linux/Ubuntu 9.09
Generating Java
I am getting just aquianted with TOS and am trying out the introductory tutorial using some future data of mine. I want to import a tab-seperated file and add to a db. In the db I want to have a primary key, but it seems to dissapear... I suppose I can set the primary key to be auto incremented , but I have no idea where.
This is what I have done and a workaround:
I create the database:
mysql> CREATE TABLE testdb.extab (
-> intid INT NOT NULL AUTO_INCREMENT,
-> accession_num TINYBLOB COMMENT 'IMGT/LIGM-DB accession number(s)',
-> PRIMARY KEY (intid)
-> );
Query OK, 0 rows affected (0.29 sec)
mysql> SHOW COLUMNS FROM testdb.extab;
+---------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+----------+------+-----+---------+----------------+
| intid | int(11) | NO | PRI | NULL | auto_increment |
| accession_num | tinyblob | YES | | NULL | |
+---------------+----------+------+-----+---------+----------------+
In Talend I get the schema. The intid is shown as key (see snapshot 1). As is done in the tutorial, the old table is droped and a new created, so I do the too (snapshot 2). The mapping of the fields is set up, and the intid is left alone (Snapshot 3). Running the job results in an exception:
Starting job testimport at 21:26 29/08/2009.
connecting to socket on port 3890
connected
Exception in component tMysqlOutput_1
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '0' for key 'PRIMARY'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:353)
at com.mysql.jdbc.Util.getInstance(Util.java:336)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1016)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2938)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1601)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1710)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2436)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1402)
disconnected
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1694)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1608)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1593)
at test.testimport_0_1.testimport.tFileInputDelimited_1Process(testimport.java:1302)
at test.testimport_0_1.testimport.runJobInTOS(testimport.java:1587)
at test.testimport_0_1.testimport.main(testimport.java:1497)
Job testimport ended at 21:27 29/08/2009.
Because the 'auto_increment' has dissapeared somehow:
mysql> SHOW COLUMNS FROM testdb.extab;
+---------------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+----------+------+-----+---------+-------+
| intid | int(10) | NO | PRI | NULL | |
| accession_num | tinyblob | YES | | NULL | |
+---------------+----------+------+-----+---------+-------+
2 rows in set (0.86 sec)
When adding 'Numeric.sequence("s1",1,1)' to the Expression of intid (shapshot5) everything works:
Starting job testimport at 21:31 29/08/2009.
connecting to socket on port 4284
connected
disconnected
Job testimport ended at 21:32 29/08/2009.
However, I am not sure how to get this to work when I add more rows to the table...
Any comments and hints are mostly welcome
Ulrik