OpenASIP  2.0
Public Member Functions | Private Attributes | List of all members
SQLite Class Reference

#include <SQLite.hh>

Inheritance diagram for SQLite:
Inheritance graph
Collaboration diagram for SQLite:
Collaboration graph

Public Member Functions

 SQLite ()
 
virtual ~SQLite ()
 
virtual RelationalDBConnectionconnect (const std::string &database, const std::string &login="", const std::string &password="", bool readOnly=false)
 
virtual void close (const RelationalDBConnection &connection)
 
- Public Member Functions inherited from RelationalDB
virtual ~RelationalDB ()
 

Private Attributes

SQLiteConnectionactiveConnection_
 Only one simultaneous active connection per SQLite instance allowed currently. More...
 

Detailed Description

Implementation of RelationalDB interface for SQLite library.

Definition at line 45 of file SQLite.hh.

Constructor & Destructor Documentation

◆ SQLite()

SQLite::SQLite ( )

Constructor.

Definition at line 44 of file SQLite.cc.

44  : activeConnection_(NULL) {
45 }

◆ ~SQLite()

SQLite::~SQLite ( )
virtual

Destructor.

Definition at line 50 of file SQLite.cc.

50  {
52 }

References activeConnection_, and close().

Here is the call graph for this function:

Member Function Documentation

◆ close()

void SQLite::close ( const RelationalDBConnection connection)
virtual

Closes a database connection.

Close should be idempotent, that is, it can be called arbitrary amount of times to a connection without an error.

Parameters
connectionThe database connection to close.
Exceptions
RelationalDBExceptionThrown if closing the connection failed.

Implements RelationalDB.

Definition at line 100 of file SQLite.cc.

100  {
101  if (activeConnection_ == NULL) {
102  return;
103  }
104 
105  delete activeConnection_;
106  activeConnection_ = NULL;
107 }

References activeConnection_.

Referenced by connect(), HDB::HDBManager::createNew(), DSDBManager::createNew(), DSDBManager::~DSDBManager(), HDB::HDBManager::~HDBManager(), and ~SQLite().

◆ connect()

RelationalDBConnection & SQLite::connect ( const std::string &  database,
const std::string &  login = "",
const std::string &  password = "",
bool  readOnly = false 
)
virtual

Connects to a database.

Possible old connection is closed. SQLite implementation doesn't support multiple active connections currently. If database file is not found, creation of new database file with the given name is attempted.

Parameters
databaseThe filename of the SQLite database.
loginLogin name to use for the database connection.
passwordPassword to use for the database connection.
readOnlyShould the database be opened in read-only mode only?
Returns
Connection "handle" which is used to query the DB, etc.
Exceptions
RelationalDBExceptionThrown if connection failed.

Implements RelationalDB.

Definition at line 69 of file SQLite.cc.

70  {
71  if (activeConnection_ != NULL) {
73  activeConnection_ = NULL;
74  }
75 
76  sqlite3* connection = NULL;
77  int value = sqlite3_open(database.c_str(), &connection);
78 
79  if (value != SQLITE_OK) {
80  string error = sqlite3_errmsg(connection);
81  error += " - file:\"" + database +"\"";
83  __FILE__, __LINE__, "SQLite::connect()", error);
84  }
85 
86  activeConnection_ = new SQLiteConnection(connection);
87  return *activeConnection_;
88 }

References activeConnection_, and close().

Referenced by HDB::HDBManager::createNew(), DSDBManager::createNew(), DSDBManager::DSDBManager(), and HDB::HDBManager::HDBManager().

Here is the call graph for this function:

Member Data Documentation

◆ activeConnection_

SQLiteConnection* SQLite::activeConnection_
private

Only one simultaneous active connection per SQLite instance allowed currently.

Definition at line 59 of file SQLite.hh.

Referenced by close(), connect(), and ~SQLite().


The documentation for this class was generated from the following files:
RelationalDBException
Definition: Exception.hh:692
SQLite::close
virtual void close(const RelationalDBConnection &connection)
Definition: SQLite.cc:100
SQLite::activeConnection_
SQLiteConnection * activeConnection_
Only one simultaneous active connection per SQLite instance allowed currently.
Definition: SQLite.hh:59
SQLiteConnection
Definition: SQLiteConnection.hh:47