File: vtkSQLiteDatabase.h

package info (click to toggle)
vtk6 6.1.0%2Bdfsg2-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 165,164 kB
  • ctags: 226,428
  • sloc: cpp: 1,354,490; ansic: 730,748; python: 227,134; tcl: 48,285; xml: 8,290; yacc: 4,832; java: 3,827; perl: 3,108; lex: 1,809; sh: 1,437; asm: 471; makefile: 229
file content (168 lines) | stat: -rw-r--r-- 5,205 bytes parent folder | download
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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkSQLiteDatabase.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 2008 Sandia Corporation.
  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
  the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/
// .NAME vtkSQLiteDatabase - maintain a connection to an SQLite database
//
// .SECTION Description
//
// SQLite (http://www.sqlite.org) is a public-domain SQL database
// written in C++.  It's small, fast, and can be easily embedded
// inside other applications.  Its databases are stored in files.
//
// This class provides a VTK interface to SQLite.  You do not need to
// download any external libraries: we include a copy of SQLite 3.3.16
// in VTK/Utilities/vtksqlite.
//
// If you want to open a database that stays in memory and never gets
// written to disk, pass in the URL 'sqlite://:memory:'; otherwise,
// specifiy the file path by passing the URL 'sqlite://<file_path>'.
//
// .SECTION Thanks
// Thanks to Andrew Wilson and Philippe Pebay from Sandia National
// Laboratories for implementing this class.
//
// .SECTION See Also
// vtkSQLiteQuery

#ifndef __vtkSQLiteDatabase_h
#define __vtkSQLiteDatabase_h

#include "vtkIOSQLModule.h" // For export macro
#include "vtkSQLDatabase.h"

class vtkSQLQuery;
class vtkSQLiteQuery;
class vtkStringArray;
struct sqlite3;

class VTKIOSQL_EXPORT vtkSQLiteDatabase : public vtkSQLDatabase
{
  //BTX
  friend class vtkSQLiteQuery;
  //ETX

public:
  vtkTypeMacro(vtkSQLiteDatabase, vtkSQLDatabase);
  void PrintSelf(ostream& os, vtkIndent indent);
  static vtkSQLiteDatabase *New();

  //BTX
  enum {
    USE_EXISTING,
    USE_EXISTING_OR_CREATE,
    CREATE_OR_CLEAR,
    CREATE
  };
  //ETX

  // Description:
  // Open a new connection to the database.  You need to set the
  // filename before calling this function.  Returns true if the
  // database was opened successfully; false otherwise.
  // - USE_EXISTING (default) - Fail if the file does not exist.
  // - USE_EXISTING_OR_CREATE - Create a new file if necessary.
  // - CREATE_OR_CLEAR - Create new or clear existing file.
  // - CREATE - Create new, fail if file exists.
  bool Open(const char* password);
  bool Open(const char* password, int mode);

  // Description:
  // Close the connection to the database.
  void Close();

  // Description:
  // Return whether the database has an open connection
  bool IsOpen();

  // Description:
  // Return an empty query on this database.
  vtkSQLQuery* GetQueryInstance();

  // Description:
  // Get the list of tables from the database
  vtkStringArray* GetTables();

  // Description:
  // Get the list of fields for a particular table
  vtkStringArray* GetRecord(const char *table);

  // Description:
  // Return whether a feature is supported by the database.
  bool IsSupported(int feature);

  // Description:
  // Did the last operation generate an error
  bool HasError();

  // Description:
  // Get the last error text from the database
  const char* GetLastErrorText();

  // Description:
  // String representing database type (e.g. "sqlite").
  vtkGetStringMacro(DatabaseType);

  // Description:
  // String representing the database filename.
  vtkGetStringMacro(DatabaseFileName);
  vtkSetStringMacro(DatabaseFileName);

  // Description:
  // Get the URL of the database.
  virtual vtkStdString GetURL();

  // Description:
  // Return the SQL string with the syntax to create a column inside a
  // "CREATE TABLE" SQL statement.
  // NB: this method implements the SQLite-specific syntax:
  // <column name> <column type> <column attributes>
  virtual vtkStdString GetColumnSpecification( vtkSQLDatabaseSchema* schema,
                                               int tblHandle,
                                               int colHandle );

protected:
  vtkSQLiteDatabase();
  ~vtkSQLiteDatabase();

  // Description:
  // Overridden to determine connection parameters given the URL.
  // This is called by CreateFromURL() to initialize the instance.
  // Look at CreateFromURL() for details about the URL format.
  virtual bool ParseURL(const char* url);

private:
  sqlite3 *SQLiteInstance;

  // We want this to be private, a user of this class
  // should not be setting this for any reason
  vtkSetStringMacro(DatabaseType);

  vtkStringArray *Tables;

  char* DatabaseType;
  char* DatabaseFileName;

  vtkStdString TempURL;

  vtkSQLiteDatabase(const vtkSQLiteDatabase &); // Not implemented.
  void operator=(const vtkSQLiteDatabase &); // Not implemented.
};

#endif // __vtkSQLiteDatabase_h