Hi,
I am newbie with wxsqlite3.
I am trying to get data from sqlite3 database. But working with ExecuteQuery is not working perfectly.
Here is my code.
This works perfectly and my code in while loop gets executed.
sprintf(buf,"select * from analog where pt_name = 'New Analog';");
wxSQLite3ResultSet q1 = db->ExecuteQuery(buf);
while (q1.NextRow())
{
// some code ;
}
But when I run following code for variable query, I dont get desired result.
wxString pt_name contains 'New Analog';
sprintf(buf,"select * from analog where pt_name ='%s'",(const char*)ptName.mb_str());
Thanks in advance;
Any other efficient method would be appreciated.
wxsqlite3 and custom query
Re: wxsqlite3 and custom query
Could you please be more specific? Which result do you get? Does the program crash? Or is the result set empty? Or what else?rppatil wrote:But when I run following code for variable query, I dont get desired result.
I don't know what exactly is going wrong. Using C string functions is potentially unsafe. Why don't you use wxString?rppatil wrote: wxString pt_name contains 'New Analog';
sprintf(buf,"select * from analog where pt_name ='%s'",(const char*)ptName.mb_str());
Use prepared statements and bind the value(s) to it.rppatil wrote:Any other efficient method would be appreciated.
Example:
Code: Select all
wxString pt_name;
wxSQLite3Statement stmt = db->PrepareStatement("select * from analog where pt_name = ?;");
// ... assign value to pt_name
stmt.Bind(1, pt_name);
wxSQLite3ResultSet q1 = stmt.ExecuteQuery();
Ulrich