Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] MySQL last insert id

Hi,
I try to use the tMysqlLastInsertId componant but I don't understand how to use it.
Description of the job I've made:
- Read a spreadsheet file
- Insert data into database
- Log id of inserted data
You can see a screenshot of my job in attachment.
The problem is that the autogenerated "Last_insert_id" column contains always the value "0" instead of the value of autoincrement.
Does anyone know how can I get the value of autoincrement ?
Thx in advance for your help.

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Hello
How can I get the id for each row ?
It is possible ?

Yes, we can get all the new inserted id. There is a global variable can be used to get the first new inserted id:
tMysqlOutput_1_NB_LINE: the total number of new inserted rows.
For more information, please see my screenshots.
Best regards
shong

View solution in original post

18 Replies
Anonymous
Not applicable
Author

Hi,
first you seem to have an error on your tMySQLOutput component (see red cross).
Despite this, in the db table, make sure your id is set to autoincrement.
Anonymous
Not applicable
Author

Long-time lurker, first-time poster...
I'm having the same issue with virtually the same setup, though I don't have any compile problems in my job. In my tMySqlLastInsertId_1 component, I have tMySqlConnection_1 in my "Link with" field and I'm using a built-in schema. Any advice on this would be extremely helpful.
Anonymous
Not applicable
Author

Hello milou
Please see my screenshot.
Best regards
shong
Anonymous
Not applicable
Author

Hello shong,
I try to reproduce your example.
See my screenshot.
I've just replace the tRowGenerator componant by a tFileInputExcel.
When I run the job, I see 2 problems:
- I have value 0 instead of null for last_insert_id column in console.
- If you look at the statistics, 20 rows have been inserted into database.
But only one row is displayed in console for last_insert_id...
Do you know why ?
Thx for your help.
Anonymous
Not applicable
Author

Hello
Can you show us your table structure? Is there a column defined as auto_increment in your talbe?
Best regards
shong
Anonymous
Not applicable
Author

Hi shong,
I've uploaded 2 screenshots:
- structure of my table (view from phpmyadmin)
- configuration of tMysqlOutput component (which insert value in my database)
You can see that my table has an autoincrement column as primary key.
Anonymous
Not applicable
Author

Hello milou
I have run my job again with a table created on phpmyadmin and it works fine.
Please send me your job via email.
Best regards
shong
Anonymous
Not applicable
Author

Hi shong,
I sent you my job by email this morning.
Anonymous
Not applicable
Author

Hi shong,
I update my job and found what it doesn't work:
I must check option "use an existing connection" in the tMysqlOutput component
and select the good tMysqlConnection in drop down list.
So it works !
I get a not null last inserted id when I execute the job.
But if the job insert more than one row in my table, I only get the inserted id for the last row.
How can I get the id for each row ?
It is possible ?