1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkSQLQuery.h,v $
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*----------------------------------------------------------------------------
Copyright (c) Sandia Corporation
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
----------------------------------------------------------------------------*/
// .NAME vtkSQLQuery - executes an sql query and retrieves results
//
// .SECTION Description
// 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.
//
// .SECTION Thanks
// Thanks to Andrew Wilson from Sandia National Laboratories for his work
// on the database classes.
//
// .SECTION See Also
// vtkSQLDatabase
#ifndef __vtkSQLQuery_h
#define __vtkSQLQuery_h
#include "vtkObject.h"
class vtkSQLDatabase;
class vtkVariant;
class vtkVariantArray;
class VTK_IO_EXPORT vtkSQLQuery : public vtkObject
{
public:
vtkTypeRevisionMacro(vtkSQLQuery, vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// The query string to be executed.
vtkGetStringMacro(Query);
vtkSetStringMacro(Query);
// Description:
// Execute the query. This must be performed
// before any field name or data access functions
// are used.
virtual bool Execute() = 0;
// Description:
// The number of fields in the query result.
virtual int GetNumberOfFields() = 0;
// Description:
// Return the name of the specified query field.
virtual const char* GetFieldName(int i) = 0;
// Description:
// Return the type of the field, using the constants defined in vtkType.h.
virtual int GetFieldType(int i) = 0;
// Description:
// Return the index of the specified query field.
// Uses GetNumberOfFields() and GetFieldName()
// to match field name.
int GetFieldIndex(char* name);
// Description:
// Advance row, return false if past end.
virtual bool NextRow() = 0;
// Description:
// 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.
bool IsActive() { return this->Active; }
// Description:
// Begin, commit, or roll back a transaction. If the underlying
// database does not support transactions these calls will do
// nothing.
virtual bool BeginTransaction() { return true; }
virtual bool CommitTransaction() { return true; }
virtual bool RollbackTransaction() { return true; }
//BTX
// Description:
// Advance row, return false if past end.
// Also, fill array with row values.
bool NextRow(vtkVariantArray* rowArray);
// Description:
// Return data in current row, field c
virtual vtkVariant DataValue(vtkIdType c) = 0;
//ETX
// Description:
// Returns true if an error is set, otherwise false.
virtual bool HasError() = 0;
// Description:
// Get the last error text from the query
virtual const char* GetLastErrorText() = 0;
// Description:
// Return the database associated with the query.
vtkGetObjectMacro(Database, vtkSQLDatabase);
protected:
vtkSQLQuery();
~vtkSQLQuery();
// Description:
// 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().
void SetDatabase(vtkSQLDatabase* db);
char* Query;
vtkSQLDatabase* Database;
bool Active;
private:
vtkSQLQuery(const vtkSQLQuery &); // Not implemented.
void operator=(const vtkSQLQuery &); // Not implemented.
};
#endif // __vtkSQLQuery_h
|