If you want to use sqlite3_exec function then try this

char *zSQL = sqlite3_mprintf("INSERT INTO probes VALUES(%Q)", temp);
sqlite3_exec(db, zSQL, 0, 0, 0);
sqlite3_free(zSQL);

This will format "temp" to hold any special chars which may generate
some errors.

eg:- temp = " Rajesh's Test " will be formated to " Rajesh''s Test "

On 3/11/09, Martin Engelschalk <engelsch...@codeswift.com> wrote:
> Hi,
>
> use sqlite3_prepare and sqlite3_bind.
> See http://www.sqlite.org/capi3ref.html#sqlite3_prepare
> and sqlite3_bind_text under
> http://www.sqlite.org/capi3ref.html#sqlite3_bind_blob
>
>    const char* szTail=0;
>    sqlite3_stmt* pVM;
>
>     int nRet = sqlite3_prepare(mpDB, "insert into table1 values(?)", -1,
> &pVM, &szTail);
>    nRes = sqlite3_bind_text(mpVM, 1, "Hello", -1, SQLITE_TRANSIENT);
>    nRest = sqlite3_step(mpVM);
>
> HTH
> Martin
>
> mrobi...@cs.fiu.edu wrote:
>> Good Morning,
>>
>> I would like to write in C the equivalent code for:
>>
>>    insert into table1 values('Hello');
>>
>> using a variable  char temp[20]= "Hello";
>>
>> instead of the literal Hello
>>
>>
>> I have used multiple variations of the following, but no luck
>>
>>     char temp[20]= "Hello";
>>     sql = "INSERT INTO probes VALUES('%s', :temp)";
>>     rc = sqlite3_exec(db, sql, NULL, NULL, &zErr);
>>
>> Thank you
>>
>> Michael
>>
>> _______________________________________________
>> 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
>


-- 
Regards
Rajesh Nair
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to