11-28-2012 09:08 AM
Hi
we are using CVI 2012 and the latest sql toolkit. We want to find and update data in a mysql database. But we have the problem that we always get an error message.
Here is our code:
// -----------------------------------------------------------------------
// initialisiert das SQL-Toolkit
DBInit(DB_INIT_MULTITHREADED);
DBInit(DB_INIT_SINGLETHREADED);
//
sprintf(String, "DSN=SYSTEM_DATABASE; Server=127.0.0.1; Database=backup_demo8; UID=root; PWD=admin");
//
hdbc = DBConnect(String);
//
hmap = DBBeginMap(hdbc);
//
rw = DBMapColumnToInt (hmap, "speed", &iSpeed, &iSpeedState);
rw = DBMapColumnToChar(hmap, "datetime", 32, cDateTime, &cDateTimeStat, "");
// Activate the map
hstmt = DBActivateMap(hmap, "plots");
// Find the record we want to update
while((rw = DBFetchNext(hstmt)) == DB_SUCCESS)
{
//
if(StrICmpWithoutSurrWhiteSpace(cDateTime, "05:37") == 0)
break;
}
//
iSpeed = 10;
// Insert the record into the database
rw = DBPutRecord(hstmt);
//
rw = DBDeactivateMap(hmap);
//
rw = DBDisconnect(hdbc);
// -----------------------------------------------------------------------
When we call the DBPutRecord cmd we get the attached error message
Does anyone can help us?
thanks in advance
best regards
Oliver
Solved! Go to Solution.
11-29-2012 02:20 AM
Hi,
I found a solution meanwhile:
The map functions seem to be the problem.In a google research I found some remarks about similar problems.
By using the "normal" Activate SQL functions it is running.
Here is my solution:
// -----------------------------------------------------------------------
// initialisiert das SQL-Toolkit
DBInit(DB_INIT_MULTITHREADED);
DBInit(DB_INIT_SINGLETHREADED);
//
sprintf(String, "DSN=SYSTEM_DATABASE; Server=127.0.0.1; Database=database_l01; UID=root; PWD=admin");
//
hdbc = DBConnect(String);
//
hsql = DBActivateSQL(hdbc, "SELECT * FROM `data_l01`");
//
rw = DBBindColChar(hsql, SQL_TIME, 32, cTime, &cTimeStat, "");
rw = DBBindColInt (hsql, SQL_SPEED, &iSpeed, &iSpeedState);
// Find the record we want to update
while((rw = DBFetchNext(hsql)) == DB_SUCCESS)
{
//
if(StrICmpWithoutSurrWhiteSpace(cTime, "05:34") == 0)
break;
}
//
iSpeed = 15;
// Insert the record into the database
rw = DBPutRecord(hsql);
//
rw = DBDeactivateSQL(hsql);
//
rw = DBDisconnect(hdbc);
// -----------------------------------------------------------------------
Thanks and kudos to me 😄
Oliver