Hello,
I'm fairly new to wxsqlite3 and all I know how to do right now is execute a command:
mydb->ExecuteQuery("select * from dbtable WHERE UserID=DarthVega7")
But how do I actually retrieve the information and put it into a variable? I tried this:
string variable = mydb->ExecuteQuery("select * from dbtable WHERE UserID=DarthVega7");
Thanks,
- DV
wxsqlite3 retrieve database data and put into variable Topic is solved
-
- In need of some credit
- Posts: 7
- Joined: Sat Feb 21, 2015 6:29 pm
Re: wxsqlite3 retrieve database data and put into variable
ExecuteQuery returns a ResultSet object that can be enummerated:
http://wxcode.sourceforge.net/docs/wxsq ... c23512930d
http://wxcode.sourceforge.net/docs/wxsq ... c23512930d
I have a bad habbit of not testing the code I post
-
- In need of some credit
- Posts: 7
- Joined: Sat Feb 21, 2015 6:29 pm
Re: wxsqlite3 retrieve database data and put into variable
DenDev wrote:ExecuteQuery returns a ResultSet object that can be enummerated:
http://wxcode.sourceforge.net/docs/wxsq ... c23512930d
Sorry, I'm such a newb... How do I enumerate the ResultSet object?
Re: wxsqlite3 retrieve database data and put into variable
If your table has a column named "UserName" you could print a list of names using:
Code: Select all
wxSQLite3ResultSet rset = mydb->ExecuteQuery("select UserName from SomeTable");
while (!rset.Eof())
{
cout << rset.GetString("UserName") << endl;
rset.NextRow();
}
I have a bad habbit of not testing the code I post
Re: wxsqlite3 retrieve database data and put into variable
Sorry, the above code will not work as expected. You have to call NextRow before accessing the columns of a retrieved row. In the wxSQLite3 documentation you will find for method wxSQLite3ResultSet::NextRow the descriptionDenDev wrote:If your table has a column named "UserName" you could print a list of names using:Code: Select all
wxSQLite3ResultSet rset = mydb->ExecuteQuery("select UserName from SomeTable"); while (!rset.Eof()) { cout << rset.GetString("UserName") << endl; rset.NextRow(); }
So the code should be similar to the following snippet:Advances the cursor to the next row. On creation of the result set the cursor is positioned BEFORE the first row, i.e. the first call to this method makes the first row available for processing.
Code: Select all
int numid;
wxString name;
wxSQLite3ResultSet query = mydb->ExecuteQuery("select numid, name from sometable;");
while (query.NextRow())
{
numid = query.GetInt(0);
name = query.GetString(1);
// ... do something useful with the retrieved data
}
Regards,
Ulrich
Re: wxsqlite3 retrieve database data and put into variable
Thank you for clarifying thatutelle wrote:Sorry, the above code will not work as expected. You have to call NextRow before accessing the columns of a retrieved row.
I have a bad habbit of not testing the code I post