The main MySQL client connection. More...
#include <SqlClient.h>
Public Member Functions | |
virtual bool | connect () |
Create a connection to the database. | |
bool | connected () const |
Check if there is a connection to the database. | |
virtual void | disconnect () |
Closes a connection to the database. | |
const std::string & | getDatabase () const |
Database value accessor. | |
const std::string & | getPassword () const |
Password value accessor. | |
const std::string & | getUser () const |
User value accessor. | |
SqlClient (const SqlClient &client) | |
Create a new SqlClient. | |
SqlClient (const std::string &host, const uint16_t port, const std::string &user, const std::string &password, const std::string &database) | |
Create a new SqlClient. | |
virtual | ~SqlClient () |
Cleans up a SqlClient. | |
Static Public Attributes | |
static const unsigned int | DEFAULT_PORT = 3306 |
Protected Member Functions | |
void | printSqlError () const |
Print the latest SQL error to ROS_ERROR. | |
MYSQL_RES * | query (const std::string &query) const |
Execute a SQL query in the database. | |
Private Attributes | |
bool | connected_ |
MYSQL * | connection_ |
const std::string | database_ |
const std::string | password_ |
const std::string | user_ |
The main MySQL client connection.
The worldlib SQL client can communicate with a MySQL database.
Definition at line 35 of file SqlClient.h.
SqlClient::SqlClient | ( | const SqlClient & | client | ) |
rail::spatial_temporal_learning::worldlib::remote::SqlClient::SqlClient | ( | const std::string & | host, |
const uint16_t | port, | ||
const std::string & | user, | ||
const std::string & | password, | ||
const std::string & | database | ||
) |
Create a new SqlClient.
Creates a new SqlClient with the given connection information. A connection is not made by default.
host | The host of the database. |
port | The host port of the database. |
user | The user of the database. |
password | The password for the user of the database. |
database | The database name. |
SqlClient::~SqlClient | ( | ) | [virtual] |
Cleans up a SqlClient.
Cleans up any connections used by the SqlClient.
Definition at line 40 of file SqlClient.cpp.
bool SqlClient::connect | ( | ) | [virtual] |
Create a connection to the database.
Attempts to create a connection to the database. A flag is returned to indicate the success.
Reimplemented in rail::spatial_temporal_learning::worldlib::remote::SpatialWorldClient.
Definition at line 66 of file SqlClient.cpp.
bool SqlClient::connected | ( | ) | const |
Check if there is a connection to the database.
A boolean check to see if a connection exists to the database.
Definition at line 61 of file SqlClient.cpp.
void SqlClient::disconnect | ( | ) | [virtual] |
Closes a connection to the database.
Attempts to close a connection to the database. No effect is seen if there is no current connection.
Definition at line 83 of file SqlClient.cpp.
const string & SqlClient::getDatabase | ( | ) | const |
Database value accessor.
Get the database value of this SqlClient.
Definition at line 56 of file SqlClient.cpp.
const string & SqlClient::getPassword | ( | ) | const |
Password value accessor.
Get the password value of this SqlClient.
Definition at line 51 of file SqlClient.cpp.
const string & SqlClient::getUser | ( | ) | const |
User value accessor.
Get the user value of this SqlClient.
Definition at line 46 of file SqlClient.cpp.
void SqlClient::printSqlError | ( | ) | const [protected] |
Print the latest SQL error to ROS_ERROR.
Prints the latest SQL error message to the ROS error stream.
Definition at line 118 of file SqlClient.cpp.
MYSQL_RES * SqlClient::query | ( | const std::string & | query | ) | const [protected] |
Execute a SQL query in the database.
Attempt to run a SQL query in the database and return the result. If no connection is made or an error occurred, NULL is returned. It is the job of the caller to cleanup and returned pointer via mysql_free_result.
query | The SQL query to run. |
Definition at line 97 of file SqlClient.cpp.
Connection flag
Definition at line 146 of file SqlClient.h.
The main database connection client.
Definition at line 148 of file SqlClient.h.
const std::string rail::spatial_temporal_learning::worldlib::remote::SqlClient::database_ [private] |
Definition at line 144 of file SqlClient.h.
const unsigned int rail::spatial_temporal_learning::worldlib::remote::SqlClient::DEFAULT_PORT = 3306 [static] |
The default MySQL port.
Reimplemented from rail::spatial_temporal_learning::worldlib::remote::Client.
Definition at line 39 of file SqlClient.h.
const std::string rail::spatial_temporal_learning::worldlib::remote::SqlClient::password_ [private] |
Definition at line 144 of file SqlClient.h.
const std::string rail::spatial_temporal_learning::worldlib::remote::SqlClient::user_ [private] |
Database connection information.
Definition at line 144 of file SqlClient.h.