wxSQLite3  5.0.1
Loading...
Searching...
No Matches
wxSQLite3::NamedCollection Class Reference

Represents a named collection. More...

#include <wxsqlite3.h>

Inheritance diagram for wxSQLite3::NamedCollection:
wxSQLite3::IntegerCollection wxSQLite3::StringCollection

Public Member Functions

 NamedCollection (const NamedCollection &collection)
 Copy constructor.
NamedCollectionoperator= (const NamedCollection &collection)
 Assignment constructor.
virtual ~NamedCollection ()
 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

 NamedCollection (const wxString &collectionName, void *collectionData)
 Constructor (internal use only).
 NamedCollection ()
 Default constructor.

Protected Attributes

wxString m_name
 Name of the collection.
void * m_data
 Reference to the actual array of values representing the collection.

Detailed Description

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:

 IntegerCollection 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.

Constructor & Destructor Documentation

◆ NamedCollection() [1/3]

wxSQLite3::NamedCollection::NamedCollection ( const NamedCollection & collection)

Copy constructor.

◆ ~NamedCollection()

virtual wxSQLite3::NamedCollection::~NamedCollection ( )
virtual

Destructor.

◆ NamedCollection() [2/3]

wxSQLite3::NamedCollection::NamedCollection ( const wxString & collectionName,
void * collectionData )
protected

Constructor (internal use only).

◆ NamedCollection() [3/3]

wxSQLite3::NamedCollection::NamedCollection ( )
inlineprotected

Default constructor.

Creates completely empty collection instance that must be set by assignment, be careful

Member Function Documentation

◆ GetName()

const wxString & wxSQLite3::NamedCollection::GetName ( ) const
inline

Get the name of the collection.

Returns
the name of the collection

◆ IsOk()

bool wxSQLite3::NamedCollection::IsOk ( ) const
inline

Gets state of the collection.

Returns
state of the collection

◆ operator bool()

wxSQLite3::NamedCollection::operator bool ( ) const
inline

Gets state of the collection (same as IsOk() method).

Returns
state of the collection

◆ operator=()

NamedCollection & wxSQLite3::NamedCollection::operator= ( const NamedCollection & collection)

Assignment constructor.

Member Data Documentation

◆ m_data

void* wxSQLite3::NamedCollection::m_data
protected

Reference to the actual array of values representing the collection.

◆ m_name

wxString wxSQLite3::NamedCollection::m_name
protected

Name of the collection.


The documentation for this class was generated from the following file: