Commit 49ddae44 authored by Timothy M. Shead's avatar Timothy M. Shead
Browse files

ENH: Create vtkRowQuery to act as an abstract interface for all queries that...

ENH: Create vtkRowQuery to act as an abstract interface for all queries that return row-oriented (i.e. tabular) data, and rewrite vtkSQLTableReader as vtkRowQueryToTable to match
parent 11c17f2b
......@@ -95,6 +95,7 @@ vtkPostScriptWriter.cxx
vtkRectilinearGridReader.cxx
vtkRectilinearGridWriter.cxx
vtkRTXMLPolyDataReader.cxx
vtkRowQuery.cxx
vtkSESAMEReader.cxx
vtkShaderCodeLibrary.cxx
vtkSQLDatabase.cxx
......@@ -184,6 +185,7 @@ vtkDataCompressor
vtkEnSightReader
vtkGenericMovieWriter
vtkMoleculeReaderBase
vtkRowQuery
vtkSQLDatabase
vtkSQLQuery
vtkVolumeReader
......@@ -268,7 +270,7 @@ ENDIF(VTK_SIZEOF_LONG_LONG MATCHES "^8$")
IF(VTK_HAS_UINT64_ARRAY)
SET(Kit_SRCS
${Kit_SRCS}
vtkSQLTableReader.cxx
vtkRowQueryToTable.cxx
)
ENDIF(VTK_HAS_UINT64_ARRAY)
......
......@@ -22,7 +22,7 @@
#include "vtkSQLiteDatabase.h"
#include "vtkSQLQuery.h"
#include "vtkSQLTableReader.h"
#include "vtkRowQueryToTable.h"
#include "vtkStdString.h"
#include "vtkTable.h"
#include "vtkVariant.h"
......@@ -129,8 +129,8 @@ int TestSQLiteDatabase(int /*argc*/, char* /*argv*/[])
}
va->Delete();
cerr << endl << "Using vtkSQLTableReader to execute query:" << endl;
vtkSQLTableReader* reader = vtkSQLTableReader::New();
cerr << endl << "Using vtkRowQueryToTable to execute query:" << endl;
vtkRowQueryToTable* reader = vtkRowQueryToTable::New();
reader->SetQuery(query);
reader->Update();
vtkTable* table = reader->GetOutput();
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkRowQuery.cxx
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.
----------------------------------------------------------------------------*/
#include "vtkRowQuery.h"
#include "vtkObjectFactory.h"
#include "vtkVariantArray.h"
vtkCxxRevisionMacro(vtkRowQuery, "1.2");
vtkRowQuery::vtkRowQuery()
{
}
vtkRowQuery::~vtkRowQuery()
{
}
void vtkRowQuery::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
int vtkRowQuery::GetFieldIndex(char* name)
{
int index;
bool found = false;
for (index = 0; index < this->GetNumberOfFields(); index++)
{
if (!strcmp(name, this->GetFieldName(index)))
{
found = true;
break;
}
}
if (found)
{
return index;
}
return -1;
}
bool vtkRowQuery::NextRow(vtkVariantArray* rowArray)
{
if (!this->NextRow())
{
return false;
}
rowArray->Reset();
for (int col = 0; col < this->GetNumberOfFields(); col++)
{
rowArray->InsertNextValue(this->DataValue(col));
}
return true;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkRowQuery.h
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 vtkRowQuery - abstract interface for queries that return
// row-oriented results.
//
// .SECTION Description
// The abstract superclass of query classes that return row-oriented (table)
// results. A subclass will provide database-specific query parameters and
// implement the vtkRowQuery API to return query results:
//
// Execute() - Execute the query. 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.
//
// .SECTION Thanks
// Thanks to Andrew Wilson from Sandia National Laboratories for his work
// on the database classes.
//
// .SECTION See Also
// vtkRowQueryToTable
#ifndef __vtkRowQuery_h
#define __vtkRowQuery_h
#include "vtkObject.h"
class vtkVariant;
class vtkVariantArray;
class VTK_IO_EXPORT vtkRowQuery : public vtkObject
{
public:
vtkTypeRevisionMacro(vtkRowQuery, vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
// 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.
virtual bool IsActive() = 0;
//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;
protected:
vtkRowQuery();
~vtkRowQuery();
private:
vtkRowQuery(const vtkRowQuery &); // Not implemented.
void operator=(const vtkRowQuery &); // Not implemented.
};
#endif // __vtkRowQuery_h
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSQLTableReader.cxx
Module: vtkRowQueryToTable.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
......@@ -16,28 +16,28 @@
Copyright (c) Sandia Corporation
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
----------------------------------------------------------------------------*/
#include "vtkSQLTableReader.h"
#include "vtkRowQueryToTable.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkSQLQuery.h"
#include "vtkRowQuery.h"
#include "vtkStringArray.h"
#include "vtkTable.h"
#include "vtkTypeUInt64Array.h"
#include "vtkVariant.h"
#include "vtkVariantArray.h"
vtkCxxRevisionMacro(vtkSQLTableReader, "1.1");
vtkStandardNewMacro(vtkSQLTableReader);
vtkCxxRevisionMacro(vtkRowQueryToTable, "1.2");
vtkStandardNewMacro(vtkRowQueryToTable);
vtkSQLTableReader::vtkSQLTableReader()
vtkRowQueryToTable::vtkRowQueryToTable()
{
this->SetNumberOfInputPorts(0);
this->Query = NULL;
}
vtkSQLTableReader::~vtkSQLTableReader()
vtkRowQueryToTable::~vtkRowQueryToTable()
{
if (this->Query)
{
......@@ -46,7 +46,7 @@ vtkSQLTableReader::~vtkSQLTableReader()
}
}
void vtkSQLTableReader::PrintSelf(ostream& os, vtkIndent indent)
void vtkRowQueryToTable::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Query: " << (this->Query ? "" : "NULL") << endl;
......@@ -56,9 +56,9 @@ void vtkSQLTableReader::PrintSelf(ostream& os, vtkIndent indent)
}
}
vtkCxxSetObjectMacro(vtkSQLTableReader, Query, vtkSQLQuery);
vtkCxxSetObjectMacro(vtkRowQueryToTable, Query, vtkRowQuery);
unsigned long vtkSQLTableReader::GetMTime()
unsigned long vtkRowQueryToTable::GetMTime()
{
unsigned long mTime = this->Superclass::GetMTime();
if (this->Query != NULL)
......@@ -69,7 +69,7 @@ unsigned long vtkSQLTableReader::GetMTime()
return mTime;
}
int vtkSQLTableReader::RequestData(
int vtkRowQueryToTable::RequestData(
vtkInformation*,
vtkInformationVector** vtkNotUsed(inputVector),
vtkInformationVector* outputVector)
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSQLTableReader.h
Module: vtkRowQueryToTable.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
......@@ -16,12 +16,12 @@
Copyright (c) Sandia Corporation
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
----------------------------------------------------------------------------*/
// .NAME vtkSQLTableReader - executes an sql query and retrieves results into a table
// .NAME vtkRowQueryToTable - executes an sql query and retrieves results into a table
//
// .SECTION Description
// vtkSQLTableReader creates a vtkTable with the results of an arbitrary SQL
// vtkRowQueryToTable creates a vtkTable with the results of an arbitrary SQL
// query. To use this filter, you first need an instance of a vtkSQLDatabase
// subclass. You may use the database class to obtain a vtkSQLQuery instance.
// subclass. You may use the database class to obtain a vtkRowQuery instance.
// Set that query on this filter to extract the query as a table.
//
// .SECTION Thanks
......@@ -29,36 +29,36 @@
// on the database classes.
//
// .SECTION See Also
// vtkSQLDatabase vtkSQLQuery
// vtkSQLDatabase vtkRowQuery
#ifndef __vtkSQLTableReader_h
#define __vtkSQLTableReader_h
#ifndef __vtkRowQueryToTable_h
#define __vtkRowQueryToTable_h
#include "vtkTableAlgorithm.h"
class vtkSQLQuery;
class vtkRowQuery;
class VTK_IO_EXPORT vtkSQLTableReader : public vtkTableAlgorithm
class VTK_IO_EXPORT vtkRowQueryToTable : public vtkTableAlgorithm
{
public:
static vtkSQLTableReader* New();
vtkTypeRevisionMacro(vtkSQLTableReader, vtkTableAlgorithm);
static vtkRowQueryToTable* New();
vtkTypeRevisionMacro(vtkRowQueryToTable, vtkTableAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// The query to execute.
void SetQuery(vtkSQLQuery* query);
vtkGetObjectMacro(Query, vtkSQLQuery);
void SetQuery(vtkRowQuery* query);
vtkGetObjectMacro(Query, vtkRowQuery);
// Description:
// Update the modified time based on the query.
unsigned long GetMTime();
protected:
vtkSQLTableReader();
~vtkSQLTableReader();
vtkRowQueryToTable();
~vtkRowQueryToTable();
vtkSQLQuery* Query;
vtkRowQuery* Query;
int RequestData(
vtkInformation*,
......@@ -66,8 +66,8 @@ protected:
vtkInformationVector*);
private:
vtkSQLTableReader(const vtkSQLTableReader&); // Not implemented
void operator=(const vtkSQLTableReader&); // Not implemented
vtkRowQueryToTable(const vtkRowQueryToTable&); // Not implemented
void operator=(const vtkRowQueryToTable&); // Not implemented
};
#endif
......
......@@ -22,7 +22,7 @@
#include "vtkSQLDatabase.h"
#include "vtkVariantArray.h"
vtkCxxRevisionMacro(vtkSQLQuery, "1.1");
vtkCxxRevisionMacro(vtkSQLQuery, "1.2");
vtkSQLQuery::vtkSQLQuery()
{
......@@ -54,37 +54,3 @@ void vtkSQLQuery::PrintSelf(ostream &os, vtkIndent indent)
}
}
int vtkSQLQuery::GetFieldIndex(char* name)
{
int index;
bool found = false;
for (index = 0; index < this->GetNumberOfFields(); index++)
{
if (!strcmp(name, this->GetFieldName(index)))
{
found = true;
break;
}
}
if (found)
{
return index;
}
return -1;
}
bool vtkSQLQuery::NextRow(vtkVariantArray* rowArray)
{
if (!this->NextRow())
{
return false;
}
rowArray->Reset();
for (int col = 0; col < this->GetNumberOfFields(); col++)
{
rowArray->InsertNextValue(this->DataValue(col));
}
return true;
}
......@@ -53,16 +53,16 @@
#ifndef __vtkSQLQuery_h
#define __vtkSQLQuery_h
#include "vtkObject.h"
#include "vtkRowQuery.h"
class vtkSQLDatabase;
class vtkVariant;
class vtkVariantArray;
class VTK_IO_EXPORT vtkSQLQuery : public vtkObject
class VTK_IO_EXPORT vtkSQLQuery : public vtkRowQuery
{
public:
vtkTypeRevisionMacro(vtkSQLQuery, vtkObject);
vtkTypeRevisionMacro(vtkSQLQuery, vtkRowQuery);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
......@@ -70,34 +70,6 @@ public:
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
......@@ -112,25 +84,6 @@ public:
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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment