Getting info from TextCtrl to an Sqlite Query

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
salvationofpain
Earned a small fee
Earned a small fee
Posts: 10
Joined: Mon Jun 08, 2009 9:42 pm

Getting info from TextCtrl to an Sqlite Query

Post by salvationofpain » Tue Jun 16, 2009 11:42 pm

I'm lost in data types.

Code: Select all

    char *sql;
    sqlite3_stmt *stmt;
    sqlite3 *db;

// sql = ... // Problem is here!

sqlite3_prepare(db, sql, strlen(sql), &stmt, NULL);
I want something like this:

Code: Select all

sql = "Select * from people where name='" + TextCtrl1->GetValue() + "';";
I can't convert using mb_str, strcpy, etc; I can't handle them. Could you please show me the way?

utelle
Moderator
Moderator
Posts: 1018
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Getting info from TextCtrl to an Sqlite Query

Post by utelle » Wed Jun 17, 2009 6:58 am

salvationofpain wrote:I'm lost in data types.

Code: Select all

    char *sql;
    sqlite3_stmt *stmt;
    sqlite3 *db;

// sql = ... // Problem is here!

sqlite3_prepare(db, sql, strlen(sql), &stmt, NULL);
I want something like this:

Code: Select all

sql = "Select * from people where name='" + TextCtrl1->GetValue() + "';";
I can't convert using mb_str, strcpy, etc; I can't handle them. Could you please show me the way?
Consider to use wxSQLite3. wxSQLite3 relieves you from the burden to convert wxString instances to and from SQLite database representation.

In any case you should also consider to use prepared SQL statements to make your application robust against SQL injection.

Regards,

Ulrich

extreme001
I live to help wx-kind
I live to help wx-kind
Posts: 192
Joined: Fri Dec 22, 2006 9:17 am
Location: Germany
Contact:

Post by extreme001 » Wed Jun 17, 2009 11:28 pm

Or use pure char...pure c++ to convert datatypes...

Post Reply