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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSQLQuery.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 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/
#include "vtkSQLQuery.h"
#include "vtkObjectFactory.h"
#include "vtkSQLDatabase.h"
#include "vtkVariantArray.h"
#include "vtksys/SystemTools.hxx"
vtkSQLQuery::vtkSQLQuery()
{
this->Query = 0;
this->Database = 0;
this->Active = false;
}
vtkSQLQuery::~vtkSQLQuery()
{
this->SetQuery(0);
if (this->Database)
{
this->Database->Delete();
this->Database = NULL;
}
}
vtkCxxSetObjectMacro(vtkSQLQuery, Database, vtkSQLDatabase);
void vtkSQLQuery::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Query: " << (this->Query ? this->Query : "NULL") << endl;
os << indent << "Database: " << (this->Database ? "" : "NULL") << endl;
if (this->Database)
{
this->Database->PrintSelf(os, indent.GetNextIndent());
}
}
vtkStdString vtkSQLQuery::EscapeString( vtkStdString s, bool addSurroundingQuotes )
{
vtkStdString d;
if ( addSurroundingQuotes )
{
d += '\'';
}
for ( vtkStdString::iterator it = s.begin(); it != s.end(); ++ it )
{
if ( *it == '\'' )
d += '\''; // Single quotes are escaped by repeating them
d += *it;
}
if ( addSurroundingQuotes )
{
d += '\'';
}
return d;
}
char* vtkSQLQuery::EscapeString( const char* src, bool addSurroundingQuotes )
{
vtkStdString sstr( src );
vtkStdString dstr = this->EscapeString( sstr, addSurroundingQuotes );
return vtksys::SystemTools::DuplicateString( dstr.c_str() );
}
bool vtkSQLQuery::BindParameter(int vtkNotUsed(index), unsigned char vtkNotUsed(value))
{
vtkErrorMacro(<<"This database driver does not support bound parameters.");
return false;
}
bool vtkSQLQuery::BindParameter(int vtkNotUsed(index), signed char vtkNotUsed(value))
{
vtkErrorMacro(<<"This database driver does not support bound parameters.");
return false;
}
bool vtkSQLQuery::BindParameter(int vtkNotUsed(index), unsigned short vtkNotUsed(value))
{
vtkErrorMacro(<<"This database driver does not support bound parameters.");
return false;
}
bool vtkSQLQuery::BindParameter(int vtkNotUsed(index), short vtkNotUsed(value))
{
vtkErrorMacro(<<"This database driver does not support bound parameters.");
return false;
}
bool vtkSQLQuery::BindParameter(int vtkNotUsed(index), unsigned int vtkNotUsed(value))
{
vtkErrorMacro(<<"This database driver does not support bound parameters.");
return false;
}
bool vtkSQLQuery::BindParameter(int vtkNotUsed(index), int vtkNotUsed(value))
{
vtkErrorMacro(<<"This database driver does not support bound parameters.");
return false;
}
bool vtkSQLQuery::BindParameter(int vtkNotUsed(index), unsigned long vtkNotUsed(value))
{
vtkErrorMacro(<<"This database driver does not support bound parameters.");
return false;
}
bool vtkSQLQuery::BindParameter(int vtkNotUsed(index), long vtkNotUsed(value))
{
vtkErrorMacro(<<"This database driver does not support bound parameters.");
return false;
}
bool vtkSQLQuery::BindParameter(int vtkNotUsed(index), vtkTypeUInt64 vtkNotUsed(value))
{
vtkErrorMacro(<<"This database driver does not support bound parameters.");
return false;
}
bool vtkSQLQuery::BindParameter(int vtkNotUsed(index), vtkTypeInt64 vtkNotUsed(value))
{
vtkErrorMacro(<<"This database driver does not support bound parameters.");
return false;
}
bool vtkSQLQuery::BindParameter(int vtkNotUsed(index), float vtkNotUsed(value))
{
vtkErrorMacro(<<"This database driver does not support bound parameters.");
return false;
}
bool vtkSQLQuery::BindParameter(int vtkNotUsed(index), double vtkNotUsed(value))
{
vtkErrorMacro(<<"This database driver does not support bound parameters.");
return false;
}
bool vtkSQLQuery::BindParameter(int vtkNotUsed(index), const char *vtkNotUsed(value))
{
vtkErrorMacro(<<"This database driver does not support bound parameters.");
return false;
}
bool vtkSQLQuery::BindParameter(int vtkNotUsed(index), const char *vtkNotUsed(value), size_t vtkNotUsed(length))
{
vtkErrorMacro(<<"This database driver does not support bound parameters.");
return false;
}
bool vtkSQLQuery::BindParameter(int vtkNotUsed(index), const vtkStdString &vtkNotUsed(value))
{
vtkErrorMacro(<<"This database driver does not support bound parameters.");
return false;
}
bool vtkSQLQuery::BindParameter(int vtkNotUsed(index), const void *vtkNotUsed(value), size_t vtkNotUsed(length))
{
vtkErrorMacro(<<"This database driver does not support bound parameters.");
return false;
}
bool vtkSQLQuery::ClearParameterBindings()
{
vtkErrorMacro(<<"This database driver does not support bound parameters.");
return false;
}
bool vtkSQLQuery::BindParameter(int index, vtkVariant data)
{
if (!data.IsValid())
{
return true; // binding nulls is a no-op
}
#define VTK_VARIANT_BIND_PARAMETER(Type,Function) \
case Type: return this->BindParameter(index, data.Function())
switch (data.GetType())
{
VTK_VARIANT_BIND_PARAMETER(VTK_STRING,ToString);
VTK_VARIANT_BIND_PARAMETER(VTK_FLOAT,ToFloat);
VTK_VARIANT_BIND_PARAMETER(VTK_DOUBLE,ToDouble);
VTK_VARIANT_BIND_PARAMETER(VTK_CHAR,ToChar);
VTK_VARIANT_BIND_PARAMETER(VTK_UNSIGNED_CHAR,ToUnsignedChar);
VTK_VARIANT_BIND_PARAMETER(VTK_SIGNED_CHAR,ToSignedChar);
VTK_VARIANT_BIND_PARAMETER(VTK_SHORT,ToShort);
VTK_VARIANT_BIND_PARAMETER(VTK_UNSIGNED_SHORT,ToUnsignedShort);
VTK_VARIANT_BIND_PARAMETER(VTK_INT,ToInt);
VTK_VARIANT_BIND_PARAMETER(VTK_UNSIGNED_INT,ToUnsignedInt);
VTK_VARIANT_BIND_PARAMETER(VTK_LONG,ToLong);
VTK_VARIANT_BIND_PARAMETER(VTK_UNSIGNED_LONG,ToUnsignedLong);
VTK_VARIANT_BIND_PARAMETER(VTK_LONG_LONG,ToLongLong);
VTK_VARIANT_BIND_PARAMETER(VTK_UNSIGNED_LONG_LONG,ToUnsignedLongLong);
case VTK_OBJECT:
vtkErrorMacro(<<"Variants of type VTK_OBJECT cannot be inserted into a database.");
return false;
default:
vtkErrorMacro(<<"Variants of type "
<< data.GetType() << " are not currently supported by BindParameter.");
return false;
}
}
// ----------------------------------------------------------------------
bool vtkSQLQuery::SetQuery(const char *queryString)
{
// This is just vtkSetStringMacro from vtkSetGet.h
vtkDebugMacro(<< this->GetClassName()
<< " (" << this << "): setting Query to "
<< (queryString?queryString:"(null)") );
if ( this->Query == NULL && queryString == NULL)
{
return true;
}
if ( this->Query && queryString && (!strcmp(this->Query,queryString)))
{
return true; // query string isn't changing
}
delete [] this->Query;
if (queryString)
{
size_t n = strlen(queryString) + 1;
char *cp1 = new char[n];
const char *cp2 = (queryString);
this->Query = cp1;
do { *cp1++ = *cp2++; } while ( --n ); \
}
else
{
this->Query = NULL;
}
this->Modified();
return true;
}
// As above, this is a copy of vtkGetStringMacro from vtkGetSet.h.
const char* vtkSQLQuery::GetQuery()
{
vtkDebugMacro(<< this->GetClassName()
<< " (" << this << "): returning Query of "
<< (this->Query?this->Query:"(null)"));
return this->Query;
}
|