//========================================================================== // OPPMYSQLUTILS.CC - part of // OMNeT++/OMNEST // Discrete System Simulation in C++ // //========================================================================== /*--------------------------------------------------------------* Copyright (C) 1992-2015 Andras Varga Copyright (C) 2011 Zoltan Bojthe This file is distributed WITHOUT ANY WARRANTY. See the file `license' for details on this and other legal matters. *--------------------------------------------------------------*/ #ifndef __OPPMYSQLUTILS_H__ #define __OPPMYSQLUTILS_H__ #include #include using namespace omnetpp; /** * The following options are read from the configuration (omnetpp.ini): * *
 * [General]
 * mysql.mysql-host = 
 * mysql.mysql-user = 
 * mysql.mysql-password = 
 * mysql.mysql-database = 
 * mysql.mysql-port = 
 * mysql.mysql-socket = 
 * mysql.mysql-clientflag = 
 * mysql.mysql-use-pipe =   # Windows named pipes
 * mysql.mysql-options-file = 
 * 
* * Please refer to the MySQL documentation about their meanings. * * If a cfgobj is given (not nullptr or the empty string), then the above * config entries get from cfgobj instead 'mysql'. That is, with cfgobj="homepc", * the configuration is searched for the following entries: * *
 * [General]
 * homepc.mysql-host = 
 * homepc.mysql-user = 
 * homepc.mysql-password = 
 * ...
 * 
*/ void opp_mysql_connectToDB(MYSQL *mysql, cConfiguration *cfg, const char *cfgobj); /** * Fills in a MYSQL_BIND structure with the given data. */ void opp_mysql_bindSTRING(MYSQL_BIND& bind, const char *buf, size_t buflen, unsigned long& len); /** * Fills in a MYSQL_BIND structure with the given data. */ void opp_mysql_bindLONG(MYSQL_BIND& bind, int& d); /** * Fills in a MYSQL_BIND structure with the given data. */ void opp_mysql_bindDOUBLE(MYSQL_BIND& bind, double& d); /** * Assigns the string in s to the given MYSQL_BIND structure. The buf pointer * should point to the bound buffer, and it only needs to be passed to * catch user errors (the function verifies that it's the same as the one inside * the MYSQL_BIND structure.) */ void opp_mysql_assignSTRING(MYSQL_BIND& bind, char *buf, const char *s); /** * Substitutes all occurrences of substring with value in query, and returns * the number of replacements. The mysql arg should hold a valid database * connection -- it is needed because the escaping depends on the character * set in use by the server. * * Example: *
 * std::string query = "SELECT name, age FROM emp WHERE name=\"@empname@\"";
 * opp_mysql_substitute(query, "@empname@", "John Doe", mysql);
 * 
*/ int opp_mysql_substitute(std::string& query, const char *substring, const char *value, MYSQL *mysql); /** * Like the other opp_mysql_substitute(), but this one converts the long to string first. */ int opp_mysql_substitute(std::string& query, const char *substring, long value, MYSQL *mysql); /** * This function escaping the input string str to a legal SQL string that you can use in an SQL statement. * See also mysql_real_escape_string() in MySQL documentation. */ std::string opp_mysql_escape(MYSQL *mysql, const char *str); #endif