ni.com is currently experiencing unexpected issues.
Some services may be unavailable at this time.
03-16-2012 11:54 AM
Hey everyone,
I connect to a MySQL database using the Microsoft ADODB ActiveX classes (ADOBD.recordset). This works fine for basic SELECT, INSERT, and UPDATE MySQL commands, and I'm sure others that I haven't tried yet. The table has an auto-increment, unique identifier column named 'id', and I'd like to return the last value that was inserted to the table. However, running SELECT LAST_INSERT_ID() returns a 0.
I've looked into it, and some people mentioned that the ADO can't handle BIGINT, so I've added "Option=16384" to my connection string (FLAG_NO_BIGINT) and still no luck. Others mentioned that the AUTO_IS_NULL database option is causing issues, so I tried that too and it still didn't work.
I also tried the command "SELECT LAST_INSERT_ID() FROM table" and that returned an array of 0s, with length equal to the table length. This is closer, but because items can be removed from the table, I can't use it for my purposes.
Does anyone have any other information on this?
On a related but much less important topic, can ADODB.recordset execute multiple queries or commands with one call? For example, sending multiple INSERT commands.
Solved! Go to Solution.
03-16-2012 12:38 PM
03-16-2012 01:35 PM
Excellent, thank you mikeporter. It's so simple, that must be why I couldn't figure it out. Since I won't be inserting to any index other than the last, this works wonderfully.
Regarding RETURNING, it looks like MySQL 5.1 doesn't support it, but PostgreSQL does (the other database system I use), so that's good to know.
Thanks!