[wxsqlite] wxSQLite3ResultSet to wxArrayString ? Topic is solved

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
dsk
Experienced Solver
Experienced Solver
Posts: 91
Joined: Sat Jun 25, 2005 12:10 pm
Location: Poland

[wxsqlite] wxSQLite3ResultSet to wxArrayString ?

Post by dsk »

Hello,

I have something like that

Code: Select all

void LoadCategories(wxListBox* itemListBox)
{    
	wxArrayString *temp;
	wxSQLite3ResultSet q1 = db.ExecuteQuery("select name from categories;");
    while (q1.NextRow())
    {
		temp->Insert(q1.GetString(0).mb_str(), 0);	
    }
	itemListBox->InsertItems(temp, 0);
}
This is simple code, but there is error.

What I need.... just I need to insert results from
wxSQLite3ResultSet class to wxArrayString... and then to listbox

Then my questions, how I can convert wxSQLite3ResultSet to wxArrayString and add each wxSQLite3ResultSet result to wxArrayString class ?

Thanks for help

Regards,
Darek
Back to wxWidgets and c++, from long time with php projects
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

Wouldn't this only work when you have one column in your row?

Maybe a more generic extension could be handy;

Code: Select all

  wxSQLite3ResultSet q1 = db.ExecuteQuery("select name,date from categories;");
  wxArrayString res = q1.GetResults("%s %s");
Where GetResults uses a formatting on the number of columns to be returned. In my example I added "date" as column to be returned, wouldn't that be a neat extension ulrich ? This also allows for formatting in case of different types and perhaps different representation.

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
dsk
Experienced Solver
Experienced Solver
Posts: 91
Joined: Sat Jun 25, 2005 12:10 pm
Location: Poland

Post by dsk »

some error:

GetResults' : is not a member of 'wxSQLite3ResultSet' :|
Back to wxWidgets and c++, from long time with php projects
utelle
Moderator
Moderator
Posts: 1126
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: [wxsqlite] wxSQLite3ResultSet to wxArrayString ?

Post by utelle »

dsk wrote:

Code: Select all

void LoadCategories(wxListBox* itemListBox)
{    
    wxArrayString *temp;
    wxSQLite3ResultSet q1 = db.ExecuteQuery("select name from categories;");
    while (q1.NextRow())
    {
        temp->Insert(q1.GetString(0).mb_str(), 0);	
    }
    itemListBox->InsertItems(temp, 0);
}
This is simple code, but there is error.
Definitely. Your variable temp is an uninitialized pointer, that is, the program will crash on the first call to insert.
dsk wrote:What I need.... just I need to insert results from
wxSQLite3ResultSet class to wxArrayString... and then to listbox
First alternative (a minor modification of your code):

Code: Select all

void LoadCategories(wxListBox* itemListBox)
{
    wxArrayString temp;
    wxSQLite3ResultSet q1 = db.ExecuteQuery("select name from categories;");
    while (q1.NextRow())
    {
        // Insert with nIndex as 0 reverses the order of the results
        // Use temp.Add(q1.GetString(0)) to get the same order.
        temp.Insert(q1.GetString(0), 0);
    }
    itemListBox->InsertItems(temp, 0);
}
Second alternative (directly add strings to listbox):

Code: Select all

void LoadCategories(wxListBox* itemListBox)
{
    wxSQLite3ResultSet q1 = db.ExecuteQuery("select name from categories;");
    while (q1.NextRow())
    {
        // If the last parameter of InsertItems is 0, the result order is reversed
        // Increase it by 1 for each loop step to get the same order
        itemListBox->InsertItems(1, &q1.GetString(0), 0);
    }
}
Regards,

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

Post by utelle »

Jorg wrote:Maybe a more generic extension could be handy;

Code: Select all

  wxSQLite3ResultSet q1 = db.ExecuteQuery("select name,date from categories;");
  wxArrayString res = q1.GetResults("%s %s");
Where GetResults uses a formatting on the number of columns to be returned. In my example I added "date" as column to be returned, wouldn't that be a neat extension ulrich ? This also allows for formatting in case of different types and perhaps different representation.
In my opinion this would be sort of misuse of wxSQLite3ResultSet, since it is the purpose of the class to provide access to one row of the result set at a time. If one needs the result set as a whole, one could/should use wxSQLite3Table. This class could be extended by a method to return a complete column as an array.

In respect of the formatting issue I think the GUI controls should handle it.

Regards,

Ulrich
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

To DSK;
some error:

GetResults' : is not a member of 'wxSQLite3ResultSet'
This was my propopsition of an extension ;-) it was not implemented yet.

As for putting it in table, that sounds fine. I will probably not use it much, but a more generic method that can e.g. be used to create CSV by specifying a string format, could be handy..

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
utelle
Moderator
Moderator
Posts: 1126
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Post by utelle »

Jorg wrote:As for putting it in table, that sounds fine. I will probably not use it much,
I wouldn't either. Storing a whole result column in an intermediate array doesn't sound very efficient, although this certainly depends on the further processing of the data.
Jorg wrote:but a more generic method that can e.g. be used to create CSV by specifying a string format, could be handy..
Ok, in this case not a column but a row is handled as a whole. But maybe except for importing or exporting data I can't see a strong demand for such a method. And in case of import/export there arise other questions which can't be handled easily in a fully generic way, i.e.: Should quotes in strings be escaped or not? Which decimal separator should be used for numeric values (important for international applications)? ...

I'm not convinced yet that adding such methods to wxSQLite3 really makes sense.

Regards,

Ulrich
dsk
Experienced Solver
Experienced Solver
Posts: 91
Joined: Sat Jun 25, 2005 12:10 pm
Location: Poland

Re: [wxsqlite] wxSQLite3ResultSet to wxArrayString ?

Post by dsk »

utelle wrote: Second alternative (directly add strings to listbox):

Code: Select all

void LoadCategories(wxListBox* itemListBox)
{
    wxSQLite3ResultSet q1 = db.ExecuteQuery("select name from categories;");
    while (q1.NextRow())
    {
        // If the last parameter of InsertItems is 0, the result order is reversed
        // Increase it by 1 for each loop step to get the same order
        itemListBox->InsertItems(1, &q1.GetString(0), 0);
    }
}
Regards,

Ulrich
Great !
Thanks for help, that I need :)
Jorg wrote:To DSK;
some error:

GetResults' : is not a member of 'wxSQLite3ResultSet'
This was my propopsition of an extension ;-) it was not implemented yet.

As for putting it in table, that sounds fine. I will probably not use it much, but a more generic method that can e.g. be used to create CSV by specifying a string format, could be handy..

- Jorgen
Yes, sorry, I just didn't understand you...

Thanks everyone for help .... :)
Have a nice day
Back to wxWidgets and c++, from long time with php projects
Post Reply