LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

import the last row written in a database

Hello!
 
I want know what i have to do to import the last row written in a table from a MySQL database.
 
I'm using labview database toolkit.
 
Thank you in advanced.
 
Larson
0 Kudos
Message 1 of 4
(3,637 Views)

Hi Larson,

Just a quickie as I need to get to work. I think  that using SELECT * FROM my_Table; usually returns the data in order that it was written into the table. If that is true you would then you would go to the last row in you array of returned table data.

This would get slower as your table grows Smiley Sad.

Another way of doing it would be to add a field to your table that autoincrements every time you write a record (could be a timestamp too). You would then create a SQL command to get the MAX value of that field then use that value in a select query to return the last row.

David

0 Kudos
Message 2 of 4
(3,630 Views)

Hi David,

I'd thought your first purpose but i think is not a good solution because each five seconds i have to import the wholwe table and this is not efficient I think.

I think that there is some block that allows you to import the last row but i don't know what.

I'll start working with your second purpose, i think it could be a good way. I can use optional clause from select data block to import the max value from time stamp column (i have yet this column in database).

What you want to say create a SQL command, how do you do this?

 

Thank you very much David!

 

Larson

 

0 Kudos
Message 3 of 4
(3,618 Views)

Hi Larson

I total agree that my first suggestion isn't what you want but I wanted to put the idea across that you can retrieve records from table in the order they were written using a simple SQL command.

When dealing with databases I always design my queries using Design View in MS Access. Once you have the query designed you can then convert the query you have just designed in Design View to SQL by changing to SQL View.

So this example SQL statement would return the MAX Timestamp.

SELECT Max(tblTimeStampTest.Timestamp) AS MaxOfTimestamp
FROM tblTimeStampTest;

Say the timestamp was 12/14/2005 8:18:33

SELECT tblTimeStampTest.*
FROM tblTimeStampTest
WHERE (((tblTimeStampTest.Timestamp)=#12/14/2005 8:18:33#));

This will return your last record as long at the timestamps are unique and records are written in timestamp order. You can then use Build Text Express VI or Format into String to build your SQL strings that have variables like the timestamp above.

I have no experience with mySQL but I would assume MS Access could interface to it somehow either through ODBC or MS Access Projects so that can build you SQL commands.

David

0 Kudos
Message 4 of 4
(3,607 Views)