取消
显示结果 
搜索替代 
您的意思是: 

Labview Database: Need help reading last index key from MYSQL DB

已解决!
转到解答

Hi all,

I'm new to Labview & MySQL actually learning it on the job. Please forgive me if it's a basic, silly question.

So I need to design a project that will update an existing DB in MySQL. The data is dynamic and must update every time a part goes through a machine.

I have this done and I am connecting to the Db and information is going in. The part I'm stuck on is the autogenerated index key in MYSQL. I need to read back the last key generated in the DB to labview for other parts of the project. 

So how can I generate the last key back, here's what I have so far. Thanks so much in advance. 🙂 

0 项奖励
1 条消息(共 6 条)
3,797 次查看
解答
接受人 Deja_Labvú

Hi,

 

if the new key is defined as latest key+1 you could simply try something like

select MAX(Index_Key) from ...

else you could sort your select descending by creation timestamp and use the first return value.

 

 

ʍolɟɐʇɐp ʞuıɥʇ
2 条消息(共 6 条)
3,752 次查看

That worked for me thanks so much!

0 项奖励
3 条消息(共 6 条)
3,744 次查看
解答
接受人 Deja_Labvú

If you table design includes an auto-index column you could use the SQL-command

SELECT LAST_INSERT_ID();

to get the last auto-index id that you have created.


Greetings, Jens

Kudos are welcome...
4 条消息(共 6 条)
3,740 次查看

This too worked, brilliant!

0 项奖励
5 条消息(共 6 条)
3,735 次查看

Bear in mind that both solutions can yield different results if more than one database user writes to the same table. My solution will give back the auto-index that your connection created (regardless of the table) while crabman's solution will give back the max-index of from one specific table. So if another user inserts data into the same table directly after your insert command you don't get back the index-id of your insert command.

 

Jens

Kudos are welcome...
6 条消息(共 6 条)
3,724 次查看