LSSTApplications
10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
|
Class for implementation of database storage. More...
#include <DbStorageImpl.h>
Public Member Functions | |
virtual | ~DbStorageImpl (void) |
template<> | |
void | setColumn (std::string const &columnName, std::string const &value) |
template<> | |
void | setColumn (std::string const &columnName, dafBase::DateTime const &value) |
template<> | |
void | outParam (std::string const &columnName, std::string *location, bool isExpr) |
template<> | |
void | outParam (std::string const &columnName, dafBase::DateTime *location, bool isExpr) |
template<> | |
std::string const & | getColumnByPos (int pos) |
template<> | |
dafBase::DateTime const & | getColumnByPos (int pos) |
Public Member Functions inherited from lsst::daf::base::Citizen | |
Citizen (const std::type_info &) | |
Citizen (Citizen const &) | |
~Citizen () | |
Citizen & | operator= (Citizen const &) |
std::string | repr () const |
Return a string representation of a Citizen. More... | |
void | markPersistent (void) |
Mark a Citizen as persistent and not destroyed until process end. More... | |
memId | getId () const |
Return the Citizen's ID. More... | |
Private Types | |
typedef std::tr1::unordered_map < std::string, BoundVar > | BoundVarMap |
Private Member Functions | |
DbStorageImpl (void) | |
virtual void | setPolicy (pexPolicy::Policy::Ptr policy) |
virtual void | setPersistLocation (LogicalLocation const &location) |
virtual void | setRetrieveLocation (LogicalLocation const &location) |
virtual void | startTransaction (void) |
virtual void | endTransaction (void) |
virtual void | startSession (std::string const &location) |
virtual void | createTableFromTemplate (std::string const &tableName, std::string const &templateName, bool mayAlreadyExist) |
virtual void | dropTable (std::string const &tableName) |
virtual void | truncateTable (std::string const &tableName) |
virtual void | executeSql (std::string const &sqlStatement) |
virtual void | setTableForInsert (std::string const &tableName) |
template<typename T > | |
void | setColumn (std::string const &columnName, T const &value) |
virtual void | setColumnToNull (std::string const &columnName) |
virtual void | insertRow (void) |
virtual void | setTableForQuery (std::string const &tableName, bool isExpr) |
virtual void | setTableListForQuery (std::vector< std::string > const &tableNameList) |
virtual void | outColumn (std::string const &columnName, bool isExpr) |
template<typename T > | |
void | outParam (std::string const &columnName, T *location, bool isExpr) |
template<typename T > | |
void | condParam (std::string const ¶mName, T const &value) |
virtual void | orderBy (std::string const &expression) |
virtual void | groupBy (std::string const &expression) |
virtual void | setQueryWhere (std::string const &whereClause) |
virtual void | query (void) |
virtual bool | next (void) |
template<typename T > | |
T const & | getColumnByPos (int pos) |
bool | columnIsNull (int pos) |
virtual void | finishQuery (void) |
void | executeQuery (std::string const &query) |
std::string | quote (std::string const &name) |
void | stError (std::string const &text) |
void | error (std::string const &text, bool mysqlCaused=true) |
void * | allocateMemory (size_t size) |
Private Attributes | |
bool | _readonly |
Remember if we are supposed to be read-only. More... | |
std::string | _location |
Database location string saved for use by raw MySQL interface. More... | |
MYSQL * | _db |
MySQL database connection pointer. More... | |
std::string | _insertTable |
Name of table into which to insert. More... | |
std::vector< std::string > | _queryTables |
Names of tables to select from. More... | |
BoundVarMap | _inputVars |
Input variable bindings. More... | |
BoundVarMap | _outputVars |
Output variable bindings. More... | |
std::vector < boost::shared_array< char > > | _bindingMemory |
Memory for bound variables. More... | |
std::vector< std::string > | _outColumns |
std::string | _whereClause |
std::string | _groupBy |
std::string | _orderBy |
MYSQL_STMT * | _statement |
Prepared query statement. More... | |
MYSQL_FIELD * | _resultFields |
Query result field metadata. More... | |
int | _numResultFields |
Number of result fields. More... | |
boost::shared_array< unsigned long > | _fieldLengths |
Space for lengths of result fields. More... | |
boost::shared_array< my_bool > | _fieldNulls |
Space for null flags of result fields. More... | |
Friends | |
class | DbStorage |
Additional Inherited Members | |
Public Types inherited from lsst::daf::base::Citizen | |
enum | { magicSentinel = 0xdeadbeef } |
typedef unsigned long | memId |
Type of the block's ID. More... | |
typedef memId(* | memNewCallback )(const memId cid) |
A function used to register a callback. More... | |
typedef memId(* | memCallback )(const Citizen *ptr) |
Static Public Member Functions inherited from lsst::daf::base::Citizen | |
static bool | hasBeenCorrupted () |
Check all allocated blocks for corruption. More... | |
static memId | getNextMemId () |
Return the memId of the next object to be allocated. More... | |
static int | init () |
Called once when the memory system is being initialised. More... | |
static int | census (int, memId startingMemId=0) |
How many active Citizens are there? More... | |
static void | census (std::ostream &stream, memId startingMemId=0) |
Print a list of all active Citizens to stream, sorted by ID. More... | |
static const std::vector < const Citizen * > * | census () |
Return a (newly allocated) std::vector of active Citizens sorted by ID. More... | |
static memId | setNewCallbackId (memId id) |
Call the NewCallback when block is allocated. More... | |
static memId | setDeleteCallbackId (memId id) |
Call the current DeleteCallback when block is deleted. More... | |
static memNewCallback | setNewCallback (memNewCallback func) |
Set the NewCallback function. More... | |
static memCallback | setDeleteCallback (memCallback func) |
Set the DeleteCallback function. More... | |
static memCallback | setCorruptionCallback (memCallback func) |
Set the CorruptionCallback function. More... | |
Class for implementation of database storage.
Use via DbStorage class only.
Definition at line 79 of file DbStorageImpl.h.
|
private |
Definition at line 149 of file DbStorageImpl.h.
|
virtual |
Destructor. End session if present.
Definition at line 168 of file DbStorageImpl.cc.
|
private |
Default constructor.
Definition at line 161 of file DbStorageImpl.cc.
|
private |
Definition at line 283 of file DbStorageImpl.cc.
|
private |
Determine if the value of a column is NULL.
[in] | pos | Position of the column (starts at 0) |
Definition at line 979 of file DbStorageImpl.cc.
|
private |
Bind a value to a WHERE condition parameter.
[in] | paramName | Name of the parameter (prefixed by ":" in the WHERE clause) |
[in] | value | Value to be bound to the parameter. |
Definition at line 627 of file DbStorageImpl.cc.
|
privatevirtual |
Create a new table from an existing template table.
[in] | tableName | Name of the new table |
[in] | templateName | Name of the existing template table |
[in] | mayAlreadyExist | False (default) if the table must not be present |
Definition at line 298 of file DbStorageImpl.cc.
|
privatevirtual |
Drop a table.
[in] | tableName | Name of the table to drop |
Definition at line 310 of file DbStorageImpl.cc.
|
privatevirtual |
End a transaction.
Definition at line 237 of file DbStorageImpl.cc.
|
private |
Definition at line 274 of file DbStorageImpl.cc.
|
private |
Execute a query string.
Definition at line 250 of file DbStorageImpl.cc.
|
privatevirtual |
Execute an arbitrary SQL statement. Use primarily to perform server-side computations or complex DDL.
[in] | sqlStatement | SQL statement to be executed. Must not end in ";". |
Definition at line 325 of file DbStorageImpl.cc.
|
privatevirtual |
Indicate that query processing is finished.
Definition at line 990 of file DbStorageImpl.cc.
|
private |
Get the value of a column of the query result row by position.
[in] | pos | Position of the column (starts at 0) |
Definition at line 890 of file DbStorageImpl.cc.
std::string const& lsst::daf::persistence::DbStorageImpl::getColumnByPos | ( | int | pos | ) |
Definition at line 914 of file DbStorageImpl.cc.
dafBase::DateTime const& lsst::daf::persistence::DbStorageImpl::getColumnByPos | ( | int | pos | ) |
Definition at line 943 of file DbStorageImpl.cc.
|
privatevirtual |
Request that the query output be grouped by an expression.
[in] | expression | Text of the SQL expression |
Definition at line 645 of file DbStorageImpl.cc.
|
privatevirtual |
Insert the row. Row values must have been set with setColumn() calls.
Definition at line 435 of file DbStorageImpl.cc.
|
privatevirtual |
Move to the next (first) row of the query result.
Definition at line 845 of file DbStorageImpl.cc.
|
privatevirtual |
Request that the query output be sorted by an expression. Multiple expressions may be specified, in order.
[in] | expression | Text of the SQL expression |
Definition at line 635 of file DbStorageImpl.cc.
|
privatevirtual |
Request a column in the query output.
[in] | columnName | Name of the column |
[in] | isExpr | True if the name is actually an expression |
The order of outColumn() calls is the order of appearance in the output row. Use either outColumn() or outParam() but not both.
Definition at line 548 of file DbStorageImpl.cc.
|
private |
Request a column in the query output and bind a destination location.
[in] | columnName | Name of the column |
[in] | location | Pointer to the destination |
[in] | isExpr | True if the name is actually an expression |
The order of outParam() calls is the order of appearance in the output row. Use either outColumn() or outParam() but not both.
Definition at line 563 of file DbStorageImpl.cc.
void lsst::daf::persistence::DbStorageImpl::outParam | ( | std::string const & | columnName, |
std::string * | location, | ||
bool | isExpr | ||
) |
Definition at line 581 of file DbStorageImpl.cc.
void lsst::daf::persistence::DbStorageImpl::outParam | ( | std::string const & | columnName, |
dafBase::DateTime * | location, | ||
bool | isExpr | ||
) |
Definition at line 601 of file DbStorageImpl.cc.
|
privatevirtual |
Execute the query.
Definition at line 663 of file DbStorageImpl.cc.
|
private |
Quote a name in ANSI-standard fashion.
Definition at line 263 of file DbStorageImpl.cc.
|
private |
Set the value to insert in a given column.
[in] | columnName | Name of the column |
[in] | value | Value to set in the column |
Definition at line 349 of file DbStorageImpl.cc.
void lsst::daf::persistence::DbStorageImpl::setColumn | ( | std::string const & | columnName, |
std::string const & | value | ||
) |
Definition at line 369 of file DbStorageImpl.cc.
void lsst::daf::persistence::DbStorageImpl::setColumn | ( | std::string const & | columnName, |
dafBase::DateTime const & | value | ||
) |
Definition at line 389 of file DbStorageImpl.cc.
|
privatevirtual |
Set a given column to NULL.
[in] | columnName | Name of the column |
Definition at line 421 of file DbStorageImpl.cc.
|
privatevirtual |
Set the database location to persist to.
[in] | location | Database connection string to insert into |
Definition at line 214 of file DbStorageImpl.cc.
|
privatevirtual |
Allow a Policy to be used to configure the DbStorage.
[in] | policy |
Definition at line 178 of file DbStorageImpl.cc.
|
privatevirtual |
Set the condition for the WHERE clause of the query.
[in] | whereClause | SQL text of the WHERE clause |
May include join conditions.
Definition at line 657 of file DbStorageImpl.cc.
|
privatevirtual |
Set the database location to retrieve from.
[in] | location | Database connection string to query |
Definition at line 222 of file DbStorageImpl.cc.
|
privatevirtual |
Set the table to insert rows into.
[in] | tableName | Name of the table |
Definition at line 336 of file DbStorageImpl.cc.
|
privatevirtual |
Set the table to query (single-table queries only).
[in] | tableName | Name of the table |
[in] | isExpr | True if the name is actually a table expression |
Definition at line 508 of file DbStorageImpl.cc.
|
privatevirtual |
Set a list of tables to query (multiple-table queries).
[in] | tableNameList | Vector of names of tables |
Definition at line 525 of file DbStorageImpl.cc.
|
privatevirtual |
Start a database session.
[in] | location | Physical database location |
[in] | am | Access mode for the database (ReadOnly or Update) |
Definition at line 189 of file DbStorageImpl.cc.
|
privatevirtual |
Start a transaction.
Definition at line 229 of file DbStorageImpl.cc.
|
private |
Definition at line 270 of file DbStorageImpl.cc.
|
privatevirtual |
Truncate a table.
[in] | tableName | Name of the table to truncate |
Definition at line 317 of file DbStorageImpl.cc.
|
friend |
Definition at line 85 of file DbStorageImpl.h.
|
private |
Memory for bound variables.
Definition at line 154 of file DbStorageImpl.h.
|
private |
MySQL database connection pointer.
Definition at line 141 of file DbStorageImpl.h.
|
private |
Space for lengths of result fields.
Definition at line 169 of file DbStorageImpl.h.
|
private |
Space for null flags of result fields.
Definition at line 171 of file DbStorageImpl.h.
|
private |
Definition at line 160 of file DbStorageImpl.h.
|
private |
Input variable bindings.
Definition at line 150 of file DbStorageImpl.h.
|
private |
Name of table into which to insert.
Definition at line 144 of file DbStorageImpl.h.
|
private |
Database location string saved for use by raw MySQL interface.
Definition at line 139 of file DbStorageImpl.h.
|
private |
Number of result fields.
Definition at line 167 of file DbStorageImpl.h.
|
private |
Definition at line 161 of file DbStorageImpl.h.
|
private |
Definition at line 158 of file DbStorageImpl.h.
|
private |
Output variable bindings.
Definition at line 152 of file DbStorageImpl.h.
|
private |
Names of tables to select from.
Definition at line 146 of file DbStorageImpl.h.
|
private |
Remember if we are supposed to be read-only.
Definition at line 137 of file DbStorageImpl.h.
|
private |
Query result field metadata.
Definition at line 165 of file DbStorageImpl.h.
|
private |
Prepared query statement.
Definition at line 163 of file DbStorageImpl.h.
|
private |
Definition at line 159 of file DbStorageImpl.h.