- mysql_init(&connection);
- mysql_options(&connection,MYSQL_OPT_CONNECT_TIMEOUT,(char*)&timeout);
- return mysql_real_connect(&connection, host.host.c_str(), host.user.c_str(), host.pass.c_str(), host.name.c_str(), host.port, NULL, 0);
- }
-
- void DoLeadingQuery()
- {
- if (!CheckConnection())
- return;
-
- /* Parse the command string and dispatch it to mysql */
- SQLrequest& req = queue.front();
-
- /* Pointer to the buffer we screw around with substitution in */
- char* query;
-
- /* Pointer to the current end of query, where we append new stuff */
- char* queryend;
-
- /* Total length of the unescaped parameters */
- unsigned long paramlen;
-
- /* Total length of query, used for binary-safety in mysql_real_query */
- unsigned long querylength = 0;
-
- paramlen = 0;
-
- for(ParamL::iterator i = req.query.p.begin(); i != req.query.p.end(); i++)
- {
- paramlen += i->size();
- }
-
- /* To avoid a lot of allocations, allocate enough memory for the biggest the escaped query could possibly be.
- * sizeofquery + (totalparamlength*2) + 1
- *
- * The +1 is for null-terminating the string for mysql_real_escape_string
- */
-
- query = new char[req.query.q.length() + (paramlen*2) + 1];
- queryend = query;
-
- /* Okay, now we have a buffer large enough we need to start copying the query into it and escaping and substituting
- * the parameters into it...
- */
-
- for(unsigned long i = 0; i < req.query.q.length(); i++)
+ connection = mysql_init(connection);
+ mysql_options(connection,MYSQL_OPT_CONNECT_TIMEOUT,(char*)&timeout);
+ std::string host = config->getString("host");
+ std::string user = config->getString("user");
+ std::string pass = config->getString("pass");
+ std::string dbname = config->getString("name");
+ int port = config->getInt("port");
+ bool rv = mysql_real_connect(connection, host.c_str(), user.c_str(), pass.c_str(), dbname.c_str(), port, NULL, 0);
+ if (!rv)
+ return rv;
+ std::string initquery;
+ if (config->readString("initialquery", initquery))