LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Database query (SQL, MySQL)

Hello,

i need to periodically request data from a database (SQL). Do i need the CVI
Enterprise Connectivity Toolkit to connect to the database and to request
the required data or is there another "simple" way to do it?

Thanks for any hint

Norbert Rieper


0 Kudos
Message 1 of 5
(5,131 Views)
Hi,
    Check for ODBC(google and msdn will help you)
    You can direcly use ODBC in Labwindows by Odbc32.dll and SqlAkw32.dll windows library.
    (add c:\Program Files\National Instruments\CVI71\sdk\lib\Odbc32.Lib
     and c:\Program Files\National Instruments\CVI71\sdk\lib\SqlAkw32.Lib to your project).
    Long time ago, i experimet with this
    My experiment example Get data from server with DNS name "PQ" and database name "UI2" to file "PQ.CSV"
    DNS item is created with utility "ODBC source" (located in windows control panel)
   
    I hope this help.
   
P.S. RowFetch is file with original example which i first port to CVI
Download All
0 Kudos
Message 2 of 5
(5,125 Views)
Hi there,

because i'm short of time in my project i decided to order the sql-toolkit
from ni.
Its pretty easy to use....
What i'm trying to do now is to determine the number of rows of a table and
then read a certain row. But i always get 1 as number of rows, but with a
viewer i can see that there are three rows in that table and within the
viewer (FlySpeed QueryTool) i'm also able to readout the correct number of
rows with the query

SELECT COUNT(*) FROM test_table

with the cvi toolkit i try it this way:

hstmt = DBActivateSQL (db_connectionHandle, "SELECT COUNT(*) FROM
test_table");
if (hstmt <= 0) {
errorMsg = DBErrorMessage();
return 0;
}
rows = DBNumberOfRecords(hstmt);

resCode = DBDeactivateSQL (hstmt);
if (hstmt <= 0) {
errorMsg = DBErrorMessage();
}
return rows;
}

What am i doing wrong ?

Thanks for any help

Norbert


0 Kudos
Message 3 of 5
(4,999 Views)
Hi,

if i use SELECT * FROM test_table
i get the right number of rows from rows = DBNumberOfRecords(hstmt);
but why does COUNT(*) not work ?

What i really have to do is to check if there is a new data record in the
table and if so, i have to read it out. I did not find something like
TRIGGER, is there any way to let the database tell me if there is a new
record inserted in the tabel, without polling the table all the time?




"Norbert Rieper" <nrieper@isitec.de> schrieb im Newsbeitrag
news:48590ba4$1@PYROS.natinst.com...
> Hi there,
>
> because i'm short of time in my project i decided to order the sql-toolkit
> from ni.
> Its pretty easy to use....
> What i'm trying to do now is to determine the number of rows of a table
> and then read a certain row. But i always get 1 as number of rows, but
> with a viewer i can see that there are three rows in that table and within
> the viewer (FlySpeed QueryTool) i'm also able to readout the correct
> number of rows with the query
>
> SELECT COUNT(*) FROM test_table
>
> with the cvi toolkit i try it this way:
>
> hstmt = DBActivateSQL (db_connectionHandle, "SELECT COUNT(*) FROM
> test_table");
> if (hstmt <= 0) {
> errorMsg = DBErrorMessage();
> return 0;
> }
> rows = DBNumberOfRecords(hstmt);
>
> resCode = DBDeactivateSQL (hstmt);
> if (hstmt <= 0) {
> errorMsg = DBErrorMessage();
> }
> return rows;
> }
>
> What am i doing wrong ?
>
> Thanks for any help
>
> Norbert
>


0 Kudos
Message 4 of 5
(4,995 Views)
Hi Norbert,
 
The reason you are getting only one "record" when you do DBNumberOfRecords on a "SELECT COUNT(*) ..." statement is that that Select statement only returns one row, the row contains a single value which has the number of records.
 
You can either use "SELECT * FROM ..." and then call DBNumberOfRecords as you seem to be doing, or you can examine the value that "SELECT COUNT(*)" returns.
 
Kevin
NI


Message Edited by Kevin B. on 06-25-2008 06:48 PM
Kevin B.
0 Kudos
Message 5 of 5
(4,945 Views)