wxSQLite3 4.9.11
|
Represents a named collection. More...
#include <wxsqlite3.h>
Public Member Functions | |
wxSQLite3NamedCollection (const wxSQLite3NamedCollection &collection) | |
Copy constructor. | |
wxSQLite3NamedCollection & | operator= (const wxSQLite3NamedCollection &collection) |
Assignment constructor. | |
virtual | ~wxSQLite3NamedCollection () |
Destructor. | |
const wxString & | GetName () const |
Get the name of the collection. | |
bool | IsOk () const |
Gets state of the collection. | |
operator bool () const | |
Gets state of the collection (same as IsOk() method) | |
Protected Member Functions | |
wxSQLite3NamedCollection (const wxString &collectionName, void *collectionData) | |
Constructor (internal use only) | |
wxSQLite3NamedCollection () | |
Default constructor. | |
Protected Attributes | |
wxString | m_name |
Name of the collection. | |
void * | m_data |
Reference to the actual array of values representing the collection. | |
Friends | |
class | wxSQLite3Database |
Represents a named collection.
A named collection is designed to facilitate using an array of integers or strings as the right-hand side of an IN operator. So instead of doing a prepared statement like this:
SELECT * FROM table WHERE x IN (?,?,?,...,?);
And then binding individual integers to each of ? slots, an application can create a named collection object (named "ex1" in the following example), prepare a statement like this:
SELECT * FROM table WHERE x IN ex1;
Then bind an array of integer or string values to the ex1 object to run the statement.
USAGE:
One or more named collection objects can be created as follows:
wxSQLite3IntegerCollection p1, p2, p3; p1 = db.CreateIntegerCollection("ex1"); p2 = db.CreateIntegerCollection("ex2"); p3 = db.CreateIntegerCollection("ex3");
Each call to CreateIntegerCollection generates a new virtual table module and a singleton of that virtual table module in the TEMP database. Both the module and the virtual table instance use the name given by the second parameter. The virtual tables can then be used in prepared statements:
SELECT * FROM t1, t2, t3 WHERE t1.x IN ex1 AND t2.y IN ex2 AND t3.z IN ex3;
Each integer array is initially empty. New arrays can be bound to an integer array as follows:
int a1[] = { 1, 2, 3, 4 }; int a2[] = { 5, 6, 7, 8, 9, 10, 11 }; wxArrayInt a3; // Fill a3 p1.Bind(4, a1); p2.Bind(7, a2); p3.Bind(a3);
A single named collection object can be rebound multiple times. But do not attempt to change the bindings of a named collection while it is in the middle of a query.
The array that holds the integer or string values is automatically allocated by the Bind method.
The named collection object is automatically destroyed when its corresponding virtual table is dropped. Since the virtual tables are created in the TEMP database, they are automatically dropped when the database connection closes so the application does not normally need to take any special action to free the named collection objects.
wxSQLite3NamedCollection::wxSQLite3NamedCollection | ( | const wxSQLite3NamedCollection & | collection | ) |
Copy constructor.
|
virtual |
Destructor.
|
protected |
Constructor (internal use only)
|
inlineprotected |
Default constructor.
Creates completely empty collection instance that must be set by assignment, be careful
|
inline |
Get the name of the collection.
|
inline |
Gets state of the collection.
|
inline |
Gets state of the collection (same as IsOk() method)
wxSQLite3NamedCollection & wxSQLite3NamedCollection::operator= | ( | const wxSQLite3NamedCollection & | collection | ) |
Assignment constructor.
|
friend |
|
protected |
Reference to the actual array of values representing the collection.
|
protected |
Name of the collection.