[sqlite] sqlite3_mprintf and Prepare

2008-03-26 Thread Mahalakshmi.m

Igor Tandetnik Wrote:
>The first case is slower, since it has to make an extra sqlite3_mprintf 
>call (that achieves precisely nothing).

Thanks a lot Igor.Its am clear now.



___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] sqlite3_mprintf and Prepare

2008-03-26 Thread Igor Tandetnik
"Mahalakshmi.m"
<[EMAIL PROTECTED]> wrote
in message
news:[EMAIL PROTECTED]
> I want to know why we have to use sqlite3_mprintf before
> sqlite3_prepare()

We don't; wherever did you get this idea from?

> Case 1:
> Query = sqlite3_mprintf ("DELETE FROM MUSIC WHERE URL = ?;");
> sqlite3_prepare(db, Query ,-1,,0);
> sqlite3_free(Query);
>
> case 2:
> We can also use directly - sqlite3_prepare(db, "DELETE FROM MUSIC
> WHERE URL = ?;",-1,,0);
>
> Will there be any performance difference between case 1 and
> case2.

The first case is slower, since it has to make an extra sqlite3_mprintf 
call (that achieves precisely nothing).

> Sometimes I am using sprintf instead of sqlite3_mprintf.will both
> have the same functionality.

sprintf requires you to provide an output buffer (but not its length, 
risking a buffer overrun). sqlite3_mprintf allocates its buffer (of an 
appropriate size) on the heap (which you have to free afterwards). Also, 
sqlite3_mprintf supports an extra format specifier - %m if I remember 
correctly - which takes a string and turns it into correctly escaped SQL 
string literal. This helps protect against SQL injection attacks (but 
using a parameterized prepared statement is still better).

> sprintf(buff,"DELETE FROM MUSIC WHERE URL = ?;");
> sqlite3_prepare(db, buff,-1,,0);

You don't need sprintf here either.

Igor Tandetnik 



___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] sqlite3_mprintf and Prepare

2008-03-26 Thread Mahalakshmi.m
Hi,

I want to know why we have to use sqlite3_mprintf before sqlite3_prepare()

Case 1:
Query = sqlite3_mprintf ("DELETE FROM MUSIC WHERE URL = ?;");
sqlite3_prepare(db, Query ,-1,,0);
sqlite3_free(Query);

case 2:
We can also use directly - sqlite3_prepare(db, "DELETE FROM MUSIC WHERE URL
= ?;",-1,,0);

Will there be any performance difference between case 1 and case2.Kindly
help me to solve.Right now I am directly passing the Sqlite staments inside
sqlite3_prepare().Do I need to use sqlite3_mprintf or not needed.

Sometimes I am using sprintf instead of sqlite3_mprintf.will both have the
same functionality.After calling sqlite3_mprintf()we are freeing using
sqlite3_free but not sprintf().

sprintf(buff,"DELETE FROM MUSIC WHERE URL = ?;");
sqlite3_prepare(db, buff,-1,,0);


Thanks & Regards,
Mahalakshmi


___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users