SOLVED!!!!! Thanks to all and expecially to Dennis I've found MY MISTAKE!!! :-) My head is safe ;-)
The error was in my_custom_function. Inside this function I need to query the same table to retrieve some values needed to calculate the float value. Inside my_custom_function I use the prepare ,step, finalize functions, but I forgot to use sqlite3_finalize before to exit, so the table was locked, or better, was locked the same RECORD i need to update, because the where statement is the same. In this conditions the update fail, but the strange thing is that I don't receive any error. The result of update statement is SQLITE_OK (this is very strange, it's normal or it's a sqlite bug ??). Follow I attach my code "CORRECT". Dennis, please can You check the correctness ? float expander::upd_ai_val(int Address, int Port) { int rc; char sql[2048],ssss[512]; char *zErrMsg = 0; char *zSql; pkt rcvd_frm; long int value; time_t rawtime; float valore; char val[25]; time(&rawtime); printf("Address=%d - Port=%d\n",Address,Port); inp_ana_inp_req(Address, Port, &rcvd_frm); value = (rcvd_frm.arg[1]*256 + rcvd_frm.arg[2]); valore = my_custom_function(Address, Port, value); //valore=value; if (debug > 1) {printf("Arg[1]=%x - Arg[2]=%x - Valore letto=%ld\n", rcvd_frm.arg[1],rcvd_frm.arg[2],value);} zSql = sqlite3_mprintf ("UPDATE inputai SET Value=%.2f, Timestamp=%d WHERE Address=%d and PortNumber=%d;",valore , Port,Address, Port); if (debug > 1) {printf ("upd_ai_val:%s\n",sql);} printf("upd_ai_val:%s\n",zSql); rc = sqlite3_exec(db,zSql, NULL, NULL, &zErrMsg ); if( rc!=SQLITE_OK ) { fprintf(stderr, "SQL error: %s\n", zErrMsg); sqlite3_free (zErrMsg); return(-1); } return(valore); } float expander:: my_custom_function(int Address, int PortNumber, int Valore) { char sql [2048]; int i; float RangeMin, RangeMax, Offset; sqlite3_stmt *stmt; /* Init Variables */ RangeMin=0; RangeMax=0; Offset=0; //char sA[3]; //sprintf(sA,"%s",Address); //printf("calcola_valore: Address=%d/%s - Porta=%d/%s\n",Address, sA, PortNumber, itos (PortNumber)); strcpy(sql,"SELECT RangeMin, RangeMax, Offset FROM inputai WHERE Address="); strcat(sql,itos(Address)); strcat(sql," and PortNumber="); strcat(sql,itos(PortNumber)); printf("CV_SQL=%s\n", sql); if (sqlite3_prepare(db, sql, -1, &stmt, 0) != SQLITE_OK) { // printf("CV_Errore prepare\n"); return(-1); } if (sqlite3_step (stmt)==SQLITE_ROW) { for (i=0; i< sqlite3_column_count (stmt); i++) { /* Column are in the SELECT order */ if (strcasecmp(sqlite3_column_name(stmt,i),"RangeMin") == 0) RangeMin = atof((char *)sqlite3_column_text(stmt,i)); else if (strcasecmp(sqlite3_column_name(stmt,i)," RangeMax") == 0) RangeMax = atof((char *) sqlite3_column_text(stmt,i)); else if (strcasecmp(sqlite3_column_name(stmt,i),"Offset") == 0) Offset = atof((char *)sqlite3_column_text(stmt,i)); } } // The follow row is that one I forgot :-) sqlite3_finalize (stmt); return(Valore * (RangeMax - RangeMin)/1023 + RangeMin + Offset); } _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users