#include <SpecTclDatabase.h> namespace SpecTclDB { class CDatabase { public: static void create(const char* database); CDatabase(const char* database); SaveSet* createSaveSet(const char* name); SaveSet* getSaveSet(const char* name); SaveSet* getSaveSet(int id); std::vector<SaveSet*> getAllSaveSets(); }; } // SpecTclDB namespace.
The SpecTclDB::CDatabase
class provides services for creating new databases
and opening existing databases. Objects
of this type allow you to create new savesets
and perform queries about existing save sets.
static void create(const char* database = );
IF database
does not exist, that file will be created.
The database scheme will be added to that file.
If this is called on a file that already has the
SpecTcl database schema, nothing bad happeens
because all elements of the schema are created
using
CREATE xxx IF NOT EXISTS
If the file already exists and is an Sqlite3 database,
the schema for a SpecTcl database is added to that
database. This may have some valid use case. If
the file exists but is not an
Sqlite3 database file, an exception
derived from
std::exception
is thrown.
CDatabase(const char* database = );
The constructor creates an object that
wraps a specific, existing database.
If the database
does not exist or does not have the correct schema,
a std::invalid_argument
exception is thrown.
If database
is not an Sqlite3
database file, CSqliteException
is thrown. Note that std::exceiption
is a parent class for CSqliteException
SaveSet* createSaveSet(const char* name = );
Creates a new save set in the database encapsulated
by the object. The name of the saveset will be
name
.
On
success, a pointer to a
SpecTclDB::SaveSet
object is returned that encapsulates
the save set.
The return value is dynamically
allocated and, therefore, must be
deleted when your program is done with it.
On failure an
std::invalid_argument
exception is thrown. This is most often because
there already is a save set
named name
.
SaveSet* getSaveSet(const char* name = );
Returns a pointer to a dynamically created
SpecTclDB::SaveSet
object
that encapsulates the save set
name
.
The caller must, at some point,
delete this object to avoid resource leaks.
On failure, usually because
name
, is not the name
of a save set, an
std::invalid_argument
exception is thrown.
SaveSet* getSaveSet(int id = );
Same as above however
id
is the
primary key of the save set we're looking up.
If you know a saveset's id, this is
nominally faster than a lookup by name.
std::vector<SaveSet*> getAllSaveSets();
Returns a vector that contains
the savesets contained by the database.
Each saveset is encapsulated in a
SpecTclDB::SaveSet
object. The vector contains pointers to these
objects which are dynamically
created and must, therefore, be
destroyed at some point by the
caller.