CARMA C++
carma::dbms::MySQLDBConnection Class Reference

an DBConnection implementation for MySQL More...

#include <carma/dbms/MySQLDBConnection.h>

Inheritance diagram for carma::dbms::MySQLDBConnection:
carma::dbms::DBConnection

Public Member Functions

void beginTransaction () const
 begin a transaction More...
 
virtual std::string caseSensitiveSearchModifier () const
 get the modifier necessary for a case-sensitive text search More...
 
virtual void commitTransaction () const
 commit a transaction More...
 
virtual std::string createMonitorDataTable (const MonitorAverageType &averageType, const MonitorAggregateType &aggType, const std::string &tag, const std::string *const location) const
 create a monitor data table More...
 
virtual bool inTransaction () const
 is a transaction being executed? More...
 
void loadDataFromFile (const std::string &filename, const std::string &table, const bool &useTransactions, const int &linesToIgnore=0, const std::string &columnDelimiter="\t") const
 destructor More...
 
void loadDataFromFiles (const file2TableMap &file2Table, const bool &useTransactions, const int &linesToIgnore=0, const std::string &columnDelimiter="\t") const
 load data into tables from disk files. More...
 
virtual unsigned maxColumnsPerTable () const
 the maximum number of columns the RDBMS allows in a table More...
 
virtual unsigned maxTablesPerJoin () const
 the maximum number of tables the RDBMS allows in a join More...
 
virtual void monitorDataTableHasBeenPopulated (const std::string &tableName, const MonitorAverageType &averageType) const
 performs tasks after a monitor data table has been completely populated. More...
 
 MySQLDBConnection (const DBConfigurator *dbconf)
 constructor More...
 
virtual void repairMonitorDataTable (const std::string &tableName) const
 attempt to repair a corrupt monitor data table More...
 
virtual void rollBackTransaction () const
 rollback a transaction More...
 
- Public Member Functions inherited from carma::dbms::DBConnection
void closeConnection ()
 close the ODBC database connection More...
 
carma::dbms::Table databaseInfo (const std::string &database="") const
 get info on the database More...
 
std::string dataSource () const
 is this object using the production database? More...
 
virtual void deleteFromMonitorIndexTable (const std::string &whereClause) const
 delete rows from the MONITOR_INDEX_TABLE More...
 
virtual void dropScratchTable (const std::string &table) const
 drop a table from the scratch database More...
 
virtual void execSQLDropTable (const std::string &tableName) const
 drop a table. More...
 
virtual carma::dbms::Table execSQLSelect (const std::string &statement, const std::string &resultTableName="RESULT TABLE") const
 execute a SELECT query More...
 
virtual carma::dbms::Table execSQLSelect (const std::vector< std::string > &columnNames, const std::string &tableName, const std::string &whereClause="", const std::string &orderByClause="", const std::string &groupByClause="", const std::string &havingClause="", const std::string &resultTableName="RESULT TABLE") const
 execute a SELECT query More...
 
virtual void * getAggregate (const std::string &column, const std::string &table, const std::string &function, carma::dbms::Table::ColumnType &type) const
 get the specified aggregate value of the specified column from the specified table. More...
 
Table getLogMessages (const carma::util::frameType &start, const carma::util::frameType &end=carma::util::Time::computeCurrentFrame(), const std::string *matchString=NULL) const
 get the log messages in the specified frameCount range. More...
 
virtual long getRowCount (const std::string &tableName) const
 get the number of rows in the specified table More...
 
void insertLogMessage (const std::string &message, const carma::util::frameType &frameCount=carma::util::Time::computeCurrentFrame()) const
 add a log message to the Log table More...
 
virtual bool isDBUp ()
 is the RDBMS in question up and accepting connections More...
 
void odbcInfo () const
 print various details about ODBC support More...
 
std::string rdbmsName () const
 get the name of the RDBMS associated with this object More...
 
bool tableExists (const std::string &table, const std::string &database) const
 does the specified table exist in the specified database? More...
 
virtual ~DBConnection ()
 destructor, derived classes may want to override More...
 

Static Public Attributes

static const std::string DBUSER
 
static const std::string ODBC_DATASRC
 
static const std::string RDBMS
 
static const std::string TEST_ODBC_DATASRC
 

Additional Inherited Members

- Public Types inherited from carma::dbms::DBConnection
typedef std::map< std::string,
std::string > 
file2TableMap
 type to map data file names to tables they should be loaded into More...
 
- Static Public Member Functions inherited from carma::dbms::DBConnection
static std::string createInsertStatement (const std::string &tableName, const std::vector< std::string > columns, const std::vector< std::string > values)
 create an SQL insert statement More...
 
static std::string createInsertStatement (const std::string &tableName, const std::vector< std::string > columns, const std::string values)
 create an SQL insert statement "INSERT INTO " + tableName + "(" More...
 
static std::string createJoinClause (const std::string &leftTable, const std::string &rightTable, const std::string &leftColumn, const std::string &rightColumn="", const std::string &rightTableAlias="", const std::string &indexCol="")
 create a (inner) join clause More...
 
static std::string createJoinClause (const std::string &joinTable, const std::string &onClause)
 create a (inner) join clause More...
 
static bool isUp (const DBConfigurator *dbconf=NULL)
 is the database specified by the dbconf object up and accepting connections? More...
 
- Protected Member Functions inherited from carma::dbms::DBConnection
void closeODBCConnection_ ()
 close a database connection using ODBC, henv_ and hdbc_ are freed here More...
 
void closeODBCConnection_ (SQLHENV henv, SQLHDBC hdbc) const
 
 DBConnection (const carma::dbms::DBConfigurator *dbconf)
 create a DBConnection object. More...
 
void directSQLExec_ (const SQLHSTMT hstmt, const std::string &statement) const
 execute a single SQL statement More...
 
void directSQLExec_ (const std::string &statement) const
 execute a single SQL statement directly More...
 
void directSQLInsert_ (const std::string &statement) const
 perform a single sql insert statement directly (ie, no prepared statements More...
 
void freeSQLStatement_ (const SQLHSTMT &hstmt) const
 free an ODBC statment handle More...
 
carma::dbms::Table odbcResultSetToTable_ (const SQLHSTMT &hstmt) const
 convert an ODBC result set to a carma::dbms::Table object More...
 
void openODBCConnection_ (SQLHENV *henv, SQLHDBC *hdbc)
 open a database connection using ODBC, henv_ and hdbc_ are initialized here More...
 
void openODBCConnection_ ()
 
std::string readPassword_ () const
 read the database user's password so that it can be sent to the ODBC driver as part of the connect string IMPORTANT! Passwords are considered sensitive information and so the files in which they reside should be readable only by the unix account which owns them More...
 
- Protected Attributes inherited from carma::dbms::DBConnection
std::vector< SQLHSTMT > activeStatements
 
std::string dataSource_
 
std::string dbname_
 
std::string dbuser_
 
SQLHDBC hdbc_
 connection and environment handles for ODBC interface More...
 
SQLHENV henv_
 
bool inTxn_
 
log4cpp::Category & logger_
 
std::string odbcConnectString_
 
std::string odbcini_
 odbc config file More...
 
std::string passwordFile_
 
unsigned port_
 
std::string rdbmsName_
 
std::string socket_
 

Detailed Description

an DBConnection implementation for MySQL

Definition at line 27 of file MySQLDBConnection.h.

Constructor & Destructor Documentation

carma::dbms::MySQLDBConnection::MySQLDBConnection ( const DBConfigurator dbconf)

constructor

Member Function Documentation

void carma::dbms::MySQLDBConnection::beginTransaction ( ) const
virtual

begin a transaction

Exceptions
DBConnectionException

Reimplemented from carma::dbms::DBConnection.

virtual std::string carma::dbms::MySQLDBConnection::caseSensitiveSearchModifier ( ) const
virtual

get the modifier necessary for a case-sensitive text search

Returns
the modifier necessary for a case-sensitive text search

Reimplemented from carma::dbms::DBConnection.

Definition at line 125 of file MySQLDBConnection.h.

virtual void carma::dbms::MySQLDBConnection::commitTransaction ( ) const
virtual

commit a transaction

Exceptions
DBConnectionException

Reimplemented from carma::dbms::DBConnection.

virtual std::string carma::dbms::MySQLDBConnection::createMonitorDataTable ( const MonitorAverageType averageType,
const MonitorAggregateType aggType,
const std::string &  tag,
const std::string *const  location 
) const
virtual

create a monitor data table

Parameters
averageTypethe average type of the table
dataTypethe data type of the table
tagthe tag to be appended to the table name
locationlocation (directory) at which to create the table, if NULL, use the default location determined by the RDBMS
Returns
the name of the created table
Exceptions
DBConnecitonException

Implements carma::dbms::DBConnection.

virtual bool carma::dbms::MySQLDBConnection::inTransaction ( ) const
virtual

is a transaction being executed?

Returns
true if a transaction is being executed
Exceptions
DBConnectionException

Reimplemented from carma::dbms::DBConnection.

void carma::dbms::MySQLDBConnection::loadDataFromFile ( const std::string &  filename,
const std::string &  table,
const bool &  useTransactions,
const int &  linesToIgnore = 0,
const std::string &  columnDelimiter = "\t" 
) const
virtual

destructor

Implements carma::dbms::DBConnection.

void carma::dbms::MySQLDBConnection::loadDataFromFiles ( const file2TableMap file2Table,
const bool &  useTransactions,
const int &  linesToIgnore = 0,
const std::string &  columnDelimiter = "\t" 
) const
virtual

load data into tables from disk files.

Because this is not an ODBC supported operation, derived classes must implement this method using their own native RDBMS interfaces

Parameters
file2Tablethe file to table map
useTransactionsshould transactions be used (implementing classes decide how to use this parameter
linesToIgnorenumber of lines to ignore (e.g. header files) at the beginning of the file

Implements carma::dbms::DBConnection.

virtual unsigned carma::dbms::MySQLDBConnection::maxColumnsPerTable ( ) const
virtual

the maximum number of columns the RDBMS allows in a table

Returns
the maximum number of columns permitted in a table

Implements carma::dbms::DBConnection.

virtual unsigned carma::dbms::MySQLDBConnection::maxTablesPerJoin ( ) const
virtual

the maximum number of tables the RDBMS allows in a join

Returns
the maximum number of tables which can be joined in a SELECT statement

Implements carma::dbms::DBConnection.

virtual void carma::dbms::MySQLDBConnection::monitorDataTableHasBeenPopulated ( const std::string &  tableName,
const MonitorAverageType averageType 
) const
virtual

performs tasks after a monitor data table has been completely populated.

the input table is altered by adding an index on tagID and then a call to the base method of the same name is made,

Parameters
tableNamename of the table that has been populated
averageTypethe average type of the table
Exceptions
DBConnectionException

Reimplemented from carma::dbms::DBConnection.

virtual void carma::dbms::MySQLDBConnection::repairMonitorDataTable ( const std::string &  tableName) const
virtual

attempt to repair a corrupt monitor data table

Parameters
tableNamethe table name to repair

Implements carma::dbms::DBConnection.

virtual void carma::dbms::MySQLDBConnection::rollBackTransaction ( ) const
virtual

rollback a transaction

Exceptions
DBConnectionException

Reimplemented from carma::dbms::DBConnection.


The documentation for this class was generated from the following file: