Slyde wrote:In setting up the wxGrid, I want to get a count of the number of entries in a Table and then build the number of Grid rows shown accordingly. I'm used to working with PHP and MariaDB and the solution to this with wx* is elusive.
Partially, SQLite is to "blame". When issuing a SELECT query, the number of rows returned is not known in advance. That is, if you need to know the number of rows beforehand, you have to issue a "SELECT COUNT(*)" with the same selection criteria as your actual query statement.
Slyde wrote:I have:
Code: Select all
wxSQLite3ResultSet res = db->ExecuteScalar("SELECT COUNT(*) FROM recipe_names");
to get a count of rows I'll need. But that's throwing an error:
Code: Select all
error: conversion from ‘int’ to non-scalar type ‘wxSQLite3ResultSet’ requested|
This is not surprising, because method
ExecuteScalar returns an int value - which can't be converted to a result set object. Just do
Code: Select all
int numRows = db->ExecuteScalar("SELECT COUNT(*) FROM recipe_names");
to get the number of rows in table
recipe_names.
Slyde wrote:I thought by using ExecuteScalar that I'd "easily" get an INT return value.
I'm sure you will agree that is indeed easy, after you have inspected and tested the code above.
Slyde wrote:I'm sure I'm just using it the wrong way, but I can't find anything on how it's supposed to be used. And it'd be nice if I cld actually get it back in INT form so I cld plug it in to:
Code: Select all
Grid_View_Recipes->AppendRows( COUNT(*)_Int_Here );
I hope things are now a bit clearer.
The samples coming with wxSQLite3 show many of its features in action. So maybe you should spend some time on inspecting the code of the "minimal" sample. Yes, the minimal sample is NOT a GUI application, but this is just to not distract from the essentials. A slightly more elaborate GUI sample is the "treeview" sample.
Regards,
Ulrich