SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DatabaseManager.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27  */
28 
29 #ifndef CORE_DATABASEMANAGER_DATABASEMANAGER_H
30 #define CORE_DATABASEMANAGER_DATABASEMANAGER_H
31 
32 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
33 # pragma once
34 #endif
35 
36 #include <map>
37 #include <boost/filesystem.hpp>
38 #include <boost/shared_ptr.hpp>
39 #include <boost/any.hpp>
40 #include <boost/noncopyable.hpp>
42 
43 namespace SCIRun
44 {
45  namespace Core
46  {
47  namespace Database
48  {
49 
50 typedef std::vector< std::map< std::string, boost::any > > ResultSet;
51 typedef boost::shared_ptr<ResultSet> ResultSetHandle;
52 
53 typedef boost::shared_ptr< class DatabaseManager > DatabaseManagerHandle;
54 
55 class SCISHARE DatabaseManager : boost::noncopyable
56 {
57 public:
59 
60  ~DatabaseManager();
61 
62 public:
63  /// RUN_SQL_STATEMENT:
64  /// Execute the given SQL statement on the database. If the statement generates
65  /// any results, they will be put in the result set.
66  /// Returns true on success, otherwise false.
67  bool run_sql_statement( const std::string& sql_str, ResultSet& results, std::string& error );
68 
69  /// RUN_SQL_STATEMENT:
70  /// Execute the given SQL statement on the database.
71  /// Returns true on success, otherwise false.
72  bool run_sql_statement( const std::string& sql_str, std::string& error );
73 
74  /// RUN_SQL_SCRIPT:
75  /// Execute multiple SQL statements sequentially.
76  bool run_sql_script( const std::string& sql_str, std::string& error );
77 
78  /// SAVE_DATABASE:
79  /// Save the database to disk
80  bool save_database( const boost::filesystem::path& database_file, std::string& error );
81 
82  /// LOAD_DATABASE:
83  /// Load the database from disk
84  bool load_database( const boost::filesystem::path& database_file, std::string& error );
85 
86  /// GET_LAST_INSERT_ROWID:
87  /// Return the row ID of last successful insert statement.
88  long long get_last_insert_rowid();
89 
90  /// GET_COLUMN_METADATA:
91  /// Get metadata about a specific column of a specific database table.
92  /// Returns true if the table and column exist, otherwise false.
93  bool get_column_metadata( const std::string& table_name, const std::string& column_name,
94  char const** data_type = 0, char const** coll_seq = 0,
95  int* not_null = 0, int* primary_key = 0, int* auto_inc = 0 );
96 
97 private:
98  boost::shared_ptr< class DatabaseManagerPrivate > private_;
99 
100 public:
101  /// ESCAPEQUOTES:
102  /// Escape the quotes(') in the string so it can be used as text in a SQL statement.
103  static std::string EscapeQuotes( const std::string& str );
104 };
105 
106  }
107  }
108 }
109 
110 #endif
111 
#define SCISHARE
Definition: share.h:39
boost::shared_ptr< class DatabaseManager > DatabaseManagerHandle
Definition: DatabaseManager.h:53
Definition: DatabaseManager.h:55
std::vector< std::map< std::string, boost::any > > ResultSet
Definition: DatabaseManager.h:50
boost::shared_ptr< ResultSet > ResultSetHandle
Definition: DatabaseManager.h:51