VTK
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
vtkSQLQuery Class Referenceabstract

executes an sql query and retrieves results More...

#include <vtkSQLQuery.h>

Inheritance diagram for vtkSQLQuery:
[legend]
Collaboration diagram for vtkSQLQuery:
[legend]

Public Types

typedef vtkRowQuery Superclass
 
- Public Types inherited from vtkRowQuery
typedef vtkObject Superclass
 
- Public Types inherited from vtkObject
typedef vtkObjectBase Superclass
 

Public Member Functions

virtual int IsA (const char *type)
 
vtkSQLQueryNewInstance () const
 
void PrintSelf (ostream &os, vtkIndent indent)
 
bool IsActive ()
 
virtual bool Execute ()=0
 
virtual bool BindParameter (int index, unsigned char value)
 
virtual bool BindParameter (int index, unsigned short value)
 
virtual bool BindParameter (int index, unsigned int value)
 
virtual bool BindParameter (int index, unsigned long value)
 
virtual bool BindParameter (int index, signed char value)
 
virtual bool BindParameter (int index, short value)
 
virtual bool BindParameter (int index, int value)
 
virtual bool BindParameter (int index, long value)
 
virtual bool BindParameter (int index, vtkTypeUInt64 value)
 
virtual bool BindParameter (int index, vtkTypeInt64 value)
 
virtual bool BindParameter (int index, float value)
 
virtual bool BindParameter (int index, double value)
 
virtual bool BindParameter (int index, const char *stringValue)
 
virtual bool BindParameter (int index, const void *data, size_t length)
 
virtual bool ClearParameterBindings ()
 
char * EscapeString (const char *src, bool addSurroundingQuotes)
 
virtual bool SetQuery (const char *query)
 
virtual const char * GetQuery ()
 
virtual bool BeginTransaction ()
 
virtual bool CommitTransaction ()
 
virtual bool RollbackTransaction ()
 
virtual vtkSQLDatabaseGetDatabase ()
 
virtual bool BindParameter (int index, const char *stringValue, size_t length)
 
virtual bool BindParameter (int index, const vtkStdString &string)
 
virtual bool BindParameter (int index, vtkVariant var)
 
virtual vtkStdString EscapeString (vtkStdString s, bool addSurroundingQuotes=true)
 
- Public Member Functions inherited from vtkRowQuery
vtkRowQueryNewInstance () const
 
virtual int GetNumberOfFields ()=0
 
virtual const char * GetFieldName (int i)=0
 
virtual int GetFieldType (int i)=0
 
int GetFieldIndex (char *name)
 
virtual bool NextRow ()=0
 
bool NextRow (vtkVariantArray *rowArray)
 
virtual vtkVariant DataValue (vtkIdType c)=0
 
virtual bool HasError ()=0
 
virtual const char * GetLastErrorText ()=0
 
virtual void SetCaseSensitiveFieldNames (bool)
 
virtual bool GetCaseSensitiveFieldNames ()
 
virtual void CaseSensitiveFieldNamesOn ()
 
virtual void CaseSensitiveFieldNamesOff ()
 
- Public Member Functions inherited from vtkObject
vtkObjectNewInstance () const
 
virtual void DebugOn ()
 
virtual void DebugOff ()
 
bool GetDebug ()
 
void SetDebug (bool debugFlag)
 
virtual void Modified ()
 
virtual unsigned long GetMTime ()
 
unsigned long AddObserver (unsigned long event, vtkCommand *, float priority=0.0f)
 
unsigned long AddObserver (const char *event, vtkCommand *, float priority=0.0f)
 
vtkCommandGetCommand (unsigned long tag)
 
void RemoveObserver (vtkCommand *)
 
void RemoveObservers (unsigned long event, vtkCommand *)
 
void RemoveObservers (const char *event, vtkCommand *)
 
int HasObserver (unsigned long event, vtkCommand *)
 
int HasObserver (const char *event, vtkCommand *)
 
void RemoveObserver (unsigned long tag)
 
void RemoveObservers (unsigned long event)
 
void RemoveObservers (const char *event)
 
void RemoveAllObservers ()
 
int HasObserver (unsigned long event)
 
int HasObserver (const char *event)
 
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, void(T::*callback)(), float priority=0.0f)
 
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, void(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f)
 
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, bool(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f)
 
int InvokeEvent (unsigned long event, void *callData)
 
int InvokeEvent (const char *event, void *callData)
 
int InvokeEvent (unsigned long event)
 
int InvokeEvent (const char *event)
 
- Public Member Functions inherited from vtkObjectBase
const char * GetClassName () const
 
virtual void Delete ()
 
virtual void FastDelete ()
 
void Print (ostream &os)
 
virtual void Register (vtkObjectBase *o)
 
virtual void UnRegister (vtkObjectBase *o)
 
void SetReferenceCount (int)
 
void PrintRevisions (ostream &)
 
virtual void PrintHeader (ostream &os, vtkIndent indent)
 
virtual void PrintTrailer (ostream &os, vtkIndent indent)
 
int GetReferenceCount ()
 

Static Public Member Functions

static int IsTypeOf (const char *type)
 
static vtkSQLQuerySafeDownCast (vtkObjectBase *o)
 
- Static Public Member Functions inherited from vtkRowQuery
static int IsTypeOf (const char *type)
 
static vtkRowQuerySafeDownCast (vtkObjectBase *o)
 
- Static Public Member Functions inherited from vtkObject
static int IsTypeOf (const char *type)
 
static vtkObjectSafeDownCast (vtkObjectBase *o)
 
static vtkObjectNew ()
 
static void BreakOnError ()
 
static void SetGlobalWarningDisplay (int val)
 
static void GlobalWarningDisplayOn ()
 
static void GlobalWarningDisplayOff ()
 
static int GetGlobalWarningDisplay ()
 
- Static Public Member Functions inherited from vtkObjectBase
static int IsTypeOf (const char *name)
 
static vtkObjectBaseNew ()
 

Protected Member Functions

virtual vtkObjectBaseNewInstanceInternal () const
 
 vtkSQLQuery ()
 
 ~vtkSQLQuery ()
 
void SetDatabase (vtkSQLDatabase *db)
 
- Protected Member Functions inherited from vtkRowQuery
 vtkRowQuery ()
 
 ~vtkRowQuery ()
 
- Protected Member Functions inherited from vtkObject
 vtkObject ()
 
virtual ~vtkObject ()
 
virtual void RegisterInternal (vtkObjectBase *, int check)
 
virtual void UnRegisterInternal (vtkObjectBase *, int check)
 
void InternalGrabFocus (vtkCommand *mouseEvents, vtkCommand *keypressEvents=NULL)
 
void InternalReleaseFocus ()
 
- Protected Member Functions inherited from vtkObjectBase
 vtkObjectBase ()
 
virtual ~vtkObjectBase ()
 
virtual void CollectRevisions (ostream &)
 
virtual void ReportReferences (vtkGarbageCollector *)
 
 vtkObjectBase (const vtkObjectBase &)
 
void operator= (const vtkObjectBase &)
 

Protected Attributes

char * Query
 
vtkSQLDatabaseDatabase
 
bool Active
 
- Protected Attributes inherited from vtkRowQuery
bool CaseSensitiveFieldNames
 
- Protected Attributes inherited from vtkObject
bool Debug
 
vtkTimeStamp MTime
 
vtkSubjectHelper * SubjectHelper
 
- Protected Attributes inherited from vtkObjectBase
vtkAtomicInt32 ReferenceCount
 
vtkWeakPointerBase ** WeakPointers
 

Detailed Description

executes an sql query and retrieves results

The abstract superclass of SQL query classes. Instances of subclasses of vtkSQLQuery are created using the GetQueryInstance() function in vtkSQLDatabase. To implement a query connection for a new database type, subclass both vtkSQLDatabase and vtkSQLQuery, and implement the required functions. For the query class, this involves the following:

Execute() - Execute the query on the database. No results need to be retrieved at this point, unless you are performing caching.

GetNumberOfFields() - After Execute() is performed, returns the number of fields in the query results.

GetFieldName() - The name of the field at an index.

GetFieldType() - The data type of the field at an index.

NextRow() - Advances the query results by one row, and returns whether there are more rows left in the query.

DataValue() - Extract a single data value from the current row.

Begin/Rollback/CommitTransaction() - These methods are optional but recommended if the database supports transactions.

Thanks:
Thanks to Andrew Wilson from Sandia National Laboratories for his work on the database classes.
See also
vtkSQLDatabase
Examples:
vtkSQLQuery (Examples)
Tests:
vtkSQLQuery (Tests)

Definition at line 73 of file vtkSQLQuery.h.

Member Typedef Documentation

Definition at line 76 of file vtkSQLQuery.h.

Constructor & Destructor Documentation

vtkSQLQuery::vtkSQLQuery ( )
protected
vtkSQLQuery::~vtkSQLQuery ( )
protected

Member Function Documentation

static int vtkSQLQuery::IsTypeOf ( const char *  type)
static
virtual int vtkSQLQuery::IsA ( const char *  name)
virtual

Return 1 if this class is the same type of (or a subclass of) the named class. Returns 0 otherwise. This method works in combination with vtkTypeMacro found in vtkSetGet.h.

Reimplemented from vtkRowQuery.

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, vtkPostgreSQLQuery, and vtkMySQLQuery.

static vtkSQLQuery* vtkSQLQuery::SafeDownCast ( vtkObjectBase o)
static
virtual vtkObjectBase* vtkSQLQuery::NewInstanceInternal ( ) const
protectedvirtual

Reimplemented from vtkRowQuery.

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, vtkPostgreSQLQuery, and vtkMySQLQuery.

vtkSQLQuery* vtkSQLQuery::NewInstance ( ) const
void vtkSQLQuery::PrintSelf ( ostream &  os,
vtkIndent  indent 
)
virtual

Methods invoked by print to print information about the object including superclasses. Typically not called by the user (use Print() instead) but used in the hierarchical print process to combine the output of several classes.

Reimplemented from vtkRowQuery.

virtual bool vtkSQLQuery::SetQuery ( const char *  query)
virtual

The query string to be executed. Since some databases will process the query string as soon as it's set, this method returns a boolean to indicate success or failure.

Reimplemented in vtkODBCQuery, vtkSQLiteQuery, and vtkMySQLQuery.

virtual const char* vtkSQLQuery::GetQuery ( )
virtual

The query string to be executed. Since some databases will process the query string as soon as it's set, this method returns a boolean to indicate success or failure.

Reimplemented in vtkODBCQuery.

bool vtkSQLQuery::IsActive ( )
inlinevirtual

Return true if the query is active (i.e. execution was successful and results are ready to be fetched). Returns false on error or inactive query.

Implements vtkRowQuery.

Definition at line 90 of file vtkSQLQuery.h.

virtual bool vtkSQLQuery::Execute ( )
pure virtual

Execute the query. This must be performed before any field name or data access functions are used.

Implements vtkRowQuery.

Implemented in vtkSQLiteQuery, vtkMySQLQuery, vtkODBCQuery, and vtkPostgreSQLQuery.

virtual bool vtkSQLQuery::BeginTransaction ( )
inlinevirtual

Begin, commit, or roll back a transaction. If the underlying database does not support transactions these calls will do nothing.

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, vtkPostgreSQLQuery, and vtkMySQLQuery.

Definition at line 99 of file vtkSQLQuery.h.

virtual bool vtkSQLQuery::CommitTransaction ( )
inlinevirtual

Begin, commit, or roll back a transaction. If the underlying database does not support transactions these calls will do nothing.

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, vtkPostgreSQLQuery, and vtkMySQLQuery.

Definition at line 100 of file vtkSQLQuery.h.

virtual bool vtkSQLQuery::RollbackTransaction ( )
inlinevirtual

Begin, commit, or roll back a transaction. If the underlying database does not support transactions these calls will do nothing.

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, vtkPostgreSQLQuery, and vtkMySQLQuery.

Definition at line 101 of file vtkSQLQuery.h.

virtual vtkSQLDatabase* vtkSQLQuery::GetDatabase ( )
virtual

Return the database associated with the query.

virtual bool vtkSQLQuery::BindParameter ( int  index,
unsigned char  value 
)
virtual

Bind a parameter to a placeholder in a query. A full discussion of this feature is beyond the scope of this header file, but in short, here's how it works: Instead of saying "SELECT foo FROM mytable WHERE myfield = 12345" you can say "SELECT foo FROM mytable WHERE myfield = ?". The ? character is a placeholder for a parameter that must then be bound. Call BindParameter(0, 12345) to bind the integer value 12345 to that field. Placeholders are indexed starting at 0. You are responsible for making sure that the types match when you call BindParameter. You don't have to get it precisely correct: in general, the SQL driver is smart enough to do things like cast a short to a long or a float to a double. Bound parameters were introduced in ANSI SQL 92. Please see that standard for more information. Most of these methods are excluded from wrapping because the Java wrapper treats all integer types from char up through 64-bit long as 'int'. This is incorrect behavior but what else am I going to do? Finally, the default implementation for BindParameter(int, vtkVariant) dispatches to one of the more type-specific versions. It should be OK to use in database drivers without modification.

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, and vtkMySQLQuery.

virtual bool vtkSQLQuery::BindParameter ( int  index,
unsigned short  value 
)
virtual

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, and vtkMySQLQuery.

virtual bool vtkSQLQuery::BindParameter ( int  index,
unsigned int  value 
)
virtual

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, and vtkMySQLQuery.

virtual bool vtkSQLQuery::BindParameter ( int  index,
unsigned long  value 
)
virtual

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, and vtkMySQLQuery.

virtual bool vtkSQLQuery::BindParameter ( int  index,
signed char  value 
)
virtual

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, and vtkMySQLQuery.

virtual bool vtkSQLQuery::BindParameter ( int  index,
short  value 
)
virtual

Reimplemented in vtkSQLiteQuery.

virtual bool vtkSQLQuery::BindParameter ( int  index,
int  value 
)
virtual

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, and vtkMySQLQuery.

virtual bool vtkSQLQuery::BindParameter ( int  index,
long  value 
)
virtual

Reimplemented in vtkSQLiteQuery.

virtual bool vtkSQLQuery::BindParameter ( int  index,
vtkTypeUInt64  value 
)
virtual

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, and vtkMySQLQuery.

virtual bool vtkSQLQuery::BindParameter ( int  index,
vtkTypeInt64  value 
)
virtual

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, and vtkMySQLQuery.

virtual bool vtkSQLQuery::BindParameter ( int  index,
float  value 
)
virtual

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, and vtkMySQLQuery.

virtual bool vtkSQLQuery::BindParameter ( int  index,
double  value 
)
virtual

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, and vtkMySQLQuery.

virtual bool vtkSQLQuery::BindParameter ( int  index,
const char *  stringValue 
)
virtual

Bind a string value – string must be null-terminated

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, and vtkMySQLQuery.

virtual bool vtkSQLQuery::BindParameter ( int  index,
const char *  stringValue,
size_t  length 
)
virtual

Bind a string value by specifying an array and a size

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, and vtkMySQLQuery.

virtual bool vtkSQLQuery::BindParameter ( int  index,
const vtkStdString string 
)
virtual

Bind a string value by specifying an array and a size

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, and vtkMySQLQuery.

virtual bool vtkSQLQuery::BindParameter ( int  index,
vtkVariant  var 
)
virtual

Bind a string value by specifying an array and a size

Reimplemented in vtkSQLiteQuery.

virtual bool vtkSQLQuery::BindParameter ( int  index,
const void *  data,
size_t  length 
)
virtual

Bind a blob value. Not all databases support blobs as a data type. Check vtkSQLDatabase::IsSupported(VTK_SQL_FEATURE_BLOB) to make sure.

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, and vtkMySQLQuery.

virtual bool vtkSQLQuery::ClearParameterBindings ( )
virtual

Reset all parameter bindings to NULL.

Reimplemented in vtkSQLiteQuery, vtkODBCQuery, and vtkMySQLQuery.

virtual vtkStdString vtkSQLQuery::EscapeString ( vtkStdString  s,
bool  addSurroundingQuotes = true 
)
virtual

Escape a string for inclusion into an SQL query. If addSurroundingQuotes is true, then quotation marks appropriate to the backend database will be added to enclose the escaped string. This argument defaults to true. A default, simple-minded implementation is provided for database backends that do not provde a way to escape strings for use inside queries.

Reimplemented in vtkMySQLQuery, and vtkPostgreSQLQuery.

char* vtkSQLQuery::EscapeString ( const char *  src,
bool  addSurroundingQuotes 
)

Escape a string for inclusion into an SQL query. This method exists to provide a wrappable version of the method that takes and returns vtkStdString objects. You are responsible for calling delete [] on the character array returned by this method. This method simply calls the vtkStdString variant and thus need not be re-implemented by subclasses.

void vtkSQLQuery::SetDatabase ( vtkSQLDatabase db)
protected

Set the database associated with the query. This is only to be called by the corresponding database class on creation of the query in GetQueryInstance().

Member Data Documentation

char* vtkSQLQuery::Query
protected

Definition at line 193 of file vtkSQLQuery.h.

vtkSQLDatabase* vtkSQLQuery::Database
protected

Definition at line 194 of file vtkSQLQuery.h.

bool vtkSQLQuery::Active
protected

Definition at line 195 of file vtkSQLQuery.h.


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