#include <connection.h>
Public Methods | |
Connection () | |
Create object without connecting it to the MySQL server. | |
Connection (bool te) | |
Connection (const char *db, const char *host="", const char *user="", const char *passwd="", bool te=true) | |
For connecting to database without any special options. | |
Connection (const char *db, const char *host, const char *user, const char *passwd, uint port, my_bool compress=0, unsigned int connect_timeout=60, bool te=true, cchar *socket_name=0, unsigned int client_flag=0) | |
Connect to database, allowing you to specify all connection parameters. | |
bool | connect (cchar *db="", cchar *host="", cchar *user="", cchar *passwd="") |
Open connection to MySQL database. | |
bool | real_connect (cchar *db="", cchar *host="", cchar *user="", cchar *passwd="", uint port=0, my_bool compress=0, unsigned int connect_timeout=60, cchar *socket_name=0, unsigned int client_flag=0) |
Connect to database after object is created. | |
void | close () |
Close connection to MySQL server. | |
std::string | info () |
Calls MySQL C API function mysql_info() and returns result as a C++ string. | |
bool | connected () const |
return true if connection was established successfully | |
bool | success () const |
Return true if the last query was successful. | |
bool | lock () |
Lock the object. | |
void | unlock () |
Unlock the object. | |
void | purge () |
Alias for close(). | |
Query | query () |
Return a new query object. | |
operator bool () | |
Alias for success(). | |
const char * | error () |
Return error message for last MySQL error associated with this connection. | |
int | errnum () |
Return last MySQL error number associated with this connection. | |
int | refresh (unsigned int refresh_options) |
Wraps MySQL C API function mysql_refresh() . | |
int | ping () |
"Pings" the MySQL database | |
int | kill (unsigned long pid) |
Kill a MySQL server thread. | |
std::string | client_info () |
Get MySQL client library version. | |
std::string | host_info () |
Get information about the network connection. | |
int | proto_info () |
Returns version number of MySQL protocol this connection is using. | |
std::string | server_info () |
Get the MySQL server's version number. | |
std::string | stat () |
Returns information about MySQL server status. | |
Result | store (const std::string &str) |
Execute a query that can return a result set. | |
ResUse | use (const std::string &str) |
Execute a query that can return a result set. | |
ResNSel | execute (const std::string &str) |
Execute a query. | |
bool | exec (const std::string &str) |
Execute a query. | |
Result | store (const std::string &str, bool te) |
Same as store(str) except that it allows you to turn off exceptions for this query. | |
ResUse | use (const std::string &str, bool te) |
Same as use(str) except that it allows you to turn off exceptions for this query. | |
ResNSel | execute (const std::string &str, bool te) |
Same as execute(str) except that it allows you to turn off exceptions for this query. | |
bool | create_db (std::string db) |
Create a database. | |
bool | drop_db (std::string db) |
Drop a database. | |
bool | select_db (std::string db) |
Change to a different database. | |
bool | select_db (const char *db) |
Change to a different database. | |
bool | reload () |
Ask MySQL server to reload the grant tables. | |
bool | shutdown () |
Ask MySQL server to shut down. | |
std::string | infoo () |
Alias for info(). | |
st_mysql_options | get_options () const |
Return the connection options object. | |
int | read_options (enum mysql_option option, const char *arg) |
Sets the given MySQL connection option. | |
my_ulonglong | affected_rows () |
Return the number of rows affected by the last query. | |
my_ulonglong | insert_id () |
Get ID generated for an AUTO_INCREMENT column in the previous INSERT query. | |
template<class Sequence> void | storein_sequence (Sequence &con, const std::string &s) |
Execute a query, storing the result set in an STL sequence container. | |
template<class Set> void | storein_set (Set &con, const std::string &s) |
Execute a query, storing the result set in an STL associative container. | |
template<class T> void | storein (std::vector< T > &con, const std::string &s) |
Specialization of storein_sequence() for std::vector . | |
template<class T> void | storein (std::deque< T > &con, const std::string &s) |
Specialization of storein_sequence() for std::deque . | |
template<class T> void | storein (std::list< T > &con, const std::string &s) |
Specialization of storein_sequence() for std::list . | |
template<class T> void | storein (std::set< T > &con, const std::string &s) |
Specialization of storein_set() for std::set . | |
template<class T> void | storein (std::multiset< T > &con, const std::string &s) |
Specialization of storein_set() for std::multiset . |
|
Create object without connecting it to the MySQL server. Use real_connect() method to establish the connection. |
|
Same as default ctor except that it allows you to choose whether exceptions are enabled.
|
|
For connecting to database without any special options.
This constructor takes the minimum parameters needed for most programs' use of MySQL. There is a more complicated constructor that lets you specify everything that the C API function
|
|
Connect to database, allowing you to specify all connection parameters.
This constructor allows you to most fully specify the options used when connecting to the MySQL database. It is the thinnest layer in MySQL++ over the MySQL C API function
|
|
Return the number of rows affected by the last query.
Simply wraps |
|
Get MySQL client library version.
Simply wraps |
|
Close connection to MySQL server. Closes the connection to the MySQL server. |
|
Open connection to MySQL database. Open connection to the MySQL server, using defaults for all but the most common parameters. It's better to use one of the connect-on-create constructors if you can. See this for parameter documentation. |
|
return true if connection was established successfully
|
|
Create a database.
|
|
Drop a database.
|
|
Return last MySQL error number associated with this connection.
Simply wraps |
|
Return error message for last MySQL error associated with this connection.
Simply wraps |
|
Execute a query.
Same as execute(), except that it only returns a flag indicating whether the query succeeded or not. It is basically a thin wrapper around the C API function
|
|
Same as execute(str) except that it allows you to turn off exceptions for this query.
|
|
Execute a query. Use this function if you don't expect the server to return a result set. For instance, a DELETE query. The returned ResNSel object contains status information from the server, such as whether the query succeeded, and if so how many rows were affected.
|
|
Get information about the network connection. String contains info about type of connection and the server hostname.
Simply wraps |
|
Alias for info(). This probably shouldn't exist. It will be removed in the next major version of the library unless a good justification is found. |
|
Get ID generated for an AUTO_INCREMENT column in the previous INSERT query.
|
|
Kill a MySQL server thread.
mysql_kill() in the C API. |
|
Lock the object. Apparently supposed to prevent multiple simultaneous connections since only connection-related functions change the lock status but it's never actually checked! See Wishlist for plan to fix this. |
|
Alias for success(). Alias for success() member function. Allows you to have code constructs like this:
Connection conn; .... use conn if (conn) { ... last SQL query was successful } else { ... error occurred in SQL query } |
|
"Pings" the MySQL database If server doesn't respond, this function tries to reconnect.
mysql_ping() in the C API. |
|
Returns version number of MySQL protocol this connection is using.
Simply wraps |
|
Return a new query object. The returned query object is tied to this MySQL connection, so when you call a method like execute() on that object, the query is sent to the server this object is connected to. |
|
Sets the given MySQL connection option. Not sure why this is named as it is; set_option() would be a better name. It may change in the next major version of the library.
Simply wraps |
|
Connect to database after object is created. It's better to use one of the connect-on-create constructors if you can.
Despite the name, this function is not a direct wrapper for the MySQL C API function See this for parameter documentation. |
|
Wraps MySQL C API function
The corresponding C API function is undocumented. All I know is that it's used by |
|
Ask MySQL server to reload the grant tables. User must have the "reload" privilege.
Simply wraps |
|
Get the MySQL server's version number.
Simply wraps |
|
Ask MySQL server to shut down. User must have the "shutdown" privilege.
Simply wraps |
|
Returns information about MySQL server status.
String is similar to that returned by the |
|
Same as store(str) except that it allows you to turn off exceptions for this query.
|
|
Execute a query that can return a result set. This function returns the entire result set immediately. This is useful if you actually need all of the records at once, but if not, consider using use() instead, which returns the results one at a time. As a result of this difference, use() doesn't need to allocate as much memory as store().
You must use store(), storein() or use() for
The name of this method comes from the MySQL C API function it is implemented in terms of,
|
|
Execute a query, storing the result set in an STL sequence container. This function works much like store() from the caller's perspective, because it returns the entire result set at once. It's actually implemented in terms of use(), however, so that memory for the result set doesn't need to be allocated twice.
|
|
Execute a query, storing the result set in an STL associative container.
std::set . Other than that detail, that method's comments apply equally well to this one. |
|
Unlock the object. See lock() documentation for caveats. |
|
Same as use(str) except that it allows you to turn off exceptions for this query.
|
|
Execute a query that can return a result set. Unlike store(), this function does not return the result set directly. Instead, it returns an object that can walk through the result records one by one. This is superior to store() when there are a large number of results; store() would have to allocate a large block of memory to hold all those records, which could cause problems. A potential downside of this method is that MySQL database resources are tied up until the result set is completely consumed. Do your best to walk through the result set as expeditiously as possible.
The name of this method comes from the MySQL C API function that initiates the retrieval process,
|