------------------------------------------------------------------------------
| 330 | |
| 331 | //------------------------------------------------------------------------------ |
| 332 | vtkVariant vtkSQLiteQuery::DataValue(vtkIdType column) |
| 333 | { |
| 334 | if (!this->IsActive()) |
| 335 | { |
| 336 | vtkWarningMacro(<< "DataValue() called on inactive query"); |
| 337 | return vtkVariant(); |
| 338 | } |
| 339 | else if (column < 0 || column >= this->GetNumberOfFields()) |
| 340 | { |
| 341 | vtkWarningMacro(<< "DataValue() called with out-of-range column index " << column); |
| 342 | return vtkVariant(); |
| 343 | } |
| 344 | else |
| 345 | { |
| 346 | switch (sqlite3_column_type(this->Private->Statement, column)) |
| 347 | { |
| 348 | case SQLITE_INTEGER: |
| 349 | return vtkVariant(sqlite3_column_int(this->Private->Statement, column)); |
| 350 | |
| 351 | case SQLITE_FLOAT: |
| 352 | return vtkVariant(sqlite3_column_double(this->Private->Statement, column)); |
| 353 | |
| 354 | case SQLITE_TEXT: |
| 355 | { |
| 356 | std::ostringstream str; |
| 357 | str << sqlite3_column_text(this->Private->Statement, column); |
| 358 | return vtkVariant(vtkStdString(str.str())); |
| 359 | } |
| 360 | |
| 361 | case SQLITE_BLOB: |
| 362 | { |
| 363 | // This is a hack ... by passing the BLOB to vtkStdString with an explicit |
| 364 | // byte count, we ensure that the string will store all of the BLOB's bytes, |
| 365 | // even if there are nullptr values. |
| 366 | |
| 367 | return vtkVariant(vtkStdString( |
| 368 | static_cast<const char*>(sqlite3_column_blob(this->Private->Statement, column)), |
| 369 | sqlite3_column_bytes(this->Private->Statement, column))); |
| 370 | } |
| 371 | |
| 372 | case SQLITE_NULL: |
| 373 | default: |
| 374 | return vtkVariant(); |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | //------------------------------------------------------------------------------ |
| 380 | const char* vtkSQLiteQuery::GetLastErrorText() |