再一次,我的指针噩梦更多了。我之前的线程让我在我的数据库连接器实现中发现另一个问题,导致双链表错误和崩溃。这是违规代码:
void dbase::insert() {
dbaselogger.log( "insert() called.", 0 );
mysqlpp::Connection conn( false );
if ( conn.connect( dbname, dbhost, dbuser, dbpass ) ) {
std::stringstream iss;
iss<< "INSERT INTO `" << dbname << "`.`gd_servers` VALUES( ";
for( int i = 0; i < 13; i++ ) {
iss<< mysqlpp::quote_only << inval[i] << ", ";
}
iss<< mysqlpp::quote_only << "0" << ", NOW() );";
std::string is = iss.str();
dbaselogger.log( is, 1 );
mysqlpp::Query query = conn.query( is );
mysqlpp::SimpleResult res = query.execute();
if( res ) {
dbaselogger.log( "Data inserted successfully.", 1 );
}
else {
dbaselogger.log( "Failed to add server to database.", 2 );
}
}
else {
dbaselogger.log( "Failed to connect to database. Please ensure mysql is running, and that your credentials are correct.", 3 );
}
dbaselogger.log("insert() completed.", 0 );
}
我经常遇到损坏的双链表错误。我很神秘。