Re: [sqlite] Error:"Expression cannot be evaluated" withsqlite3_exec()
Hello Igor; I have modified the code to avoid string writting problems now, it is: int ActualizarBBDDAlumnos(char *dni, float nota) { char *errorMsg; char *orden_SQL = sqlite3_mprintf("update ALUMNO set nota=%0.1f where dni=%Q;",nota,dni); sqlite3_exec(db,orden_SQL,0,0,); sqlite3_free(errorMsg); sqlite3_free(orden_SQL); return(0); } after sqlite3_mprintf() function, I obtain the string like this: " update ALUMNO set nota=0.2 where dni='12345678J' " After sqlite3_exec() errorMsg=NULL (0x Bad ptr), and the command is not exectuted in table ALUMNO, the value is not changed. If I type exactly the same order from the sqlite3 command line, it works perfectly. The database and tables where created folloeing the examples in http://www.sqlite.org/sqlite.html ,with CREATE TABLE commands and INSERT INTO TABLE commands. I still don´t understand what is happening, so, as always, thank you very much. Regards, Alberto - Mensaje original De: Igor Tandetnik <[EMAIL PROTECTED]> Para: sqlite-users@sqlite.org Enviado: miércoles, 15 de octubre, 2008 22:18:48 Asunto: Re: [sqlite] Error:"Expression cannot be evaluated" withsqlite3_exec() Alberto Tellaeche <[EMAIL PROTECTED]> wrote: > Tank you very much for the response. > the array is as expected, sprintf is woking fine. Also I get the same > error if I write the SQL command directly in the sqlite3_exec() > function, so this is not the error... Show the CREATE TABLE statement for ALUMNO table. Show the exact text of the statement you run, after sprintf. Igor Tandetnik ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Error:"Expression cannot be evaluated" with sqlite3_exec()
Tank you very much for the response. the array is as expected, sprintf is woking fine. Also I get the same error if I write the SQL command directly in the sqlite3_exec() function, so this is not the error... Thank you again for the interest, Regards alberto - Mensaje original De: Igor Tandetnik <[EMAIL PROTECTED]> Para: sqlite-users@sqlite.org Enviado: miércoles, 15 de octubre, 2008 17:31:59 Asunto: Re: [sqlite] Error:"Expression cannot be evaluated" with sqlite3_exec() Alberto Tellaeche <[EMAIL PROTECTED]> wrote: > work perfectly well, but I am having a very annoying problem with > sqlite3_exec() function. The code just after the example above is: > >memset(orden_SQL,0,200*sizeof(char)); >sprintf(orden_SQL,"update ALUMNO set nota=%0.1f where >dni='%s';",nota,dni); >res=sqlite3_exec(db,orden_SQL,0,0,); >sqlite3_free(errorMsg); Examine orden_SQL after sprintf, check that it's as expected. For example, sprintf is locale sensitive: if your locale, say, uses comma for decimal separator rather than a period, the query would end up with something like "set nota=1,1". But SQLite expects to see a period for decimal separator. Igor Tandetnik ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Error:"Expression cannot be evaluated" with sqlite3_exec()
Hello colleagues; I am new to sqlite, and I have recently started to use it from the command line (sqlite3.exe) and in C programs. In my C example program I open de database at the beginning and close it beforte the end of the program. Examples like: memset(orden_SQL, 0, 200*sizeof(char)); sprintf(orden_SQL,"select nBlancos from CORRECCION_EXAMEN where modelo='%c';",modelo); sqlite3_get_table(db,orden_SQL); for(i=1;i<=Rows;i++) { examen.blancos[i-1]=atoi(Resultado[i]); } work perfectly well, but I am having a very annoying problem with sqlite3_exec() function. The code just after the example above is: memset(orden_SQL,0,200*sizeof(char)); sprintf(orden_SQL,"update ALUMNO set nota=%0.1f where dni='%s';",nota,dni); res=sqlite3_exec(db,orden_SQL,0,0,); sqlite3_free(errorMsg); and it does not work. "res" value is 0 and "errorMsg" is Error:"Expression cannot be evaluated". I have also tried to substitute sqlite3_exec with sqlite3_prepare() + sqlite3_step() with the same result. The command "update ALUMNO set nota=9 where dni='12345678P';" works perfect in the comand line. What problem I am having here? It is very important for me for the project I am developping, so I would appreciate a lot any kind of advise. Best regards, Alberto ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users