本文整理汇总了C++中Query::error方法的典型用法代码示例。如果您正苦于以下问题:C++ Query::error方法的具体用法?C++ Query::error怎么用?C++ Query::error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Query
的用法示例。
在下文中一共展示了Query::error方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execute
void MailboxReader::execute() {
while ( q->hasResults() ) {
Row * r = q->nextRow();
UString n = r->getUString( "name" );
uint id = r->getInt( "id" );
Mailbox * m = ::mailboxes->find( id );
if ( !m || m->name() != n ) {
m = Mailbox::obtain( n );
if ( n != m->d->name )
m->d->name = n;
m->setId( id );
::mailboxes->insert( id, m );
}
if ( r->getBoolean( "deleted" ) )
m->setType( Mailbox::Deleted );
else
m->setType( Mailbox::Ordinary );
uint uidvalidity = r->getInt( "uidvalidity" );
if ( m->d->uidvalidity != uidvalidity ) {
m->d->uidvalidity = uidvalidity;
m->abortSessions();
}
if ( !r->isNull( "owner" ) )
m->setOwner( r->getInt( "owner" ) );
m->setUidnextAndNextModSeq( r->getInt( "uidnext" ),
r->getBigint( "nextmodseq" ),
q->transaction() );
m->setFlag( r->getEString( "flag" ) );
}
if ( !q->done() || done )
return;
done = true;
if ( q->transaction() )
q->transaction()->commit();
::readers->remove( this );
::wiped = false;
if ( q->failed() && !EventLoop::global()->inShutdown() ) {
List<Mailbox> * c = Mailbox::root()->children();
if ( c && !c->isEmpty() )
log( "Couldn't update mailbox tree: " + q->error() );
else
log( "Couldn't create mailbox tree: " + q->error(),
Log::Disaster );
}
if ( owner )
owner->execute();
};
示例2: createParmFiles2
void createParmFiles2(string mask, int popid, int popno, int totaltrait, int totalmarker, string db, string name_str)
{
int distinctpop = -1;
try
{
ifstream sqlparmfile("../exe/SQLparms.txt");
string servername, dbname, username, password;
getline(sqlparmfile,servername);
getline(sqlparmfile,dbname);
getline(sqlparmfile,username);
getline(sqlparmfile,password);
Connection conn( dbname.c_str(), servername.c_str(), username.c_str(), password.c_str());
Query query = conn.query();
string pp = "pop"+toStrings(popno);
//SELECT COUNT(DISTINCT pop1 ) as number FROM structure where popstructid = 1;
query << "SELECT COUNT(DISTINCT "<<pp<<" ) as number FROM structure WHERE popstructid = " << popid;
StoreQueryResult ares = query.store();
if(!ares)
{
cerr << query.error() << endl;
return;
}
else
{
for(size_t i = 0; i < ares.num_rows(); i ++)
{
distinctpop = ares[i]["number"] ;
}
}
}
catch(BadQuery er)
{
cerr << "Error: " << er.what() << endl;
return;
}
catch(const BadConversion& er)
{
cerr << "Conversion error: " << er.what() << endl;
return;
}
catch(const Exception& er)
{
cerr << "Error: " << er.what() << endl;
return;
}
ofstream myfile;
myfile.open("parms2.txt");
myfile <<mask<<" "<<popid<<" "<<popno<<" "<<totaltrait<<" "<<totalmarker<<" "<<name_str<<" "<<db<<" "<<distinctpop<< " " << team << endl;
myfile<<"vanilla"<<endl;
myfile.close();
}
示例3: main
int main()
{
Connection con(false);
if ( con.connect("ogame_dev","localhost","root","") )
{
Query query = con.query("SELECT * FROM user");
if ( StoreQueryResult res = query.store() )
{
cout << "Table user:" << endl;
cout << "-------------------------------------------" << endl;
for ( size_t i = 0; i < res.num_rows(); i++ )
{
cout << "| ";
for ( size_t y = 0; y < res.num_fields(); y++)
{
cout << res[i][y] << " | ";
}
cout << endl;
}
cout << "-------------------------------------------" << endl;
}
else
{
cerr << "Error query users table: " << query.error() << endl;
return -1;
}
return 0;
}
else
{
cerr << "Error DB connection: " << con.error() << endl;
return -1;
}
}
示例4: writeStructureFile
int writeStructureFile(int popid, int popnum)
{
int noidis = 0;
int tts=-1;
try
{
ifstream sqlparmfile("../exe/SQLparms.txt");
string servername, dbname, username, password;
getline(sqlparmfile,servername);
getline(sqlparmfile,dbname);
getline(sqlparmfile,username);
getline(sqlparmfile,password);
Connection conn( dbname.c_str(), servername.c_str(), username.c_str(), password.c_str());
Query query = conn.query();
string pp = "pop"+toStrings(popnum);
query << "SELECT "<<pp<<" FROM structure WHERE popstructid = " << popid << " ORDER BY sampleid";
StoreQueryResult ares = query.store();
if(!ares)
{
cerr << query.error() << endl;
return -1;
}
else
{
ofstream myfile;
string fname = "data.test.Z";
myfile.open(fname.c_str());
tts = ares.num_rows();
for(size_t i = 0; i < ares.num_rows(); i ++)
{
myfile << ares[i][pp.c_str()] << "\n";
}
myfile.close();
}
}
catch(BadQuery er)
{
cerr << "Error: " << er.what() << endl;
return -1;
}
catch(const BadConversion& er)
{
cerr << "Conversion error: " << er.what() << endl;
return -1;
}
catch(const Exception& er)
{
cerr << "Error: " << er.what() << endl;
return -1;
}
return tts;
}
示例5: refreshTable
void ConfigureVehicle::refreshTable()
{
//qDebug()<<"refresh the configurevehicle table";
Query q;
if (!q.selectVehicle(model))
{
//qDebug()<<"something happened with selectVehicle";
QString p = "somethign happened with refreshTable selectVehicle: " + q.error();
QMessageBox message(QMessageBox::Critical,"Problem!",p,QMessageBox::Ok,this,Qt::Dialog);
message.exec();
}
}
示例6: gettsid
int gettsid(string mask)
{
try
{
ifstream sqlparmfile("../exe/SQLparms.txt");
string servername, dbname, username, password;
getline(sqlparmfile,servername);
getline(sqlparmfile,dbname);
getline(sqlparmfile,username);
getline(sqlparmfile,password);
Connection conn( dbname.c_str(), servername.c_str(), username.c_str(), password.c_str());
//cout << conn.error() << endl;
Query query = conn.query();
query << "SELECT get_ts_id('" << mask << "') as id";
StoreQueryResult ares = query.store();
if(!ares)
{
cerr << query.error() << endl;
return -1;
}
int id;
for(size_t i = 0; i < ares.num_rows(); i++)
{
id = ares[i]["id"];
return id;
}
}
catch(BadQuery er)
{
cerr<< "Error: " <<er.what() <<endl;
return -1;
}
catch(const BadConversion& er)
{
cerr <<"Conversion error: " << er.what() << endl;
return -1;
}
catch (const Exception& er)
{
cerr << "Error: " <<er.what() << endl;
return -1;
}
}
示例7: execute
void execute()
{
if ( !q ) {
q = new Query( "select not exists (select * from "
"information_schema.table_privileges where "
"privilege_type='DELETE' and table_name="
"'messages' and grantee=$1) and not exists "
"(select u.usename from pg_catalog.pg_class c "
"left join pg_catalog.pg_user u on "
"(u.usesysid=c.relowner) where c.relname="
"'messages' and u.usename=$1) as allowed",
this );
q->bind( 1, Configuration::text( Configuration::DbUser ) );
q->execute();
}
if ( !q->done() )
return;
Row * r = q->nextRow();
if ( q->failed() || !r ||
r->getBoolean( "allowed" ) == false )
{
EString s( "Refusing to start because we have too many "
"privileges on the messages table in secure "
"mode." );
result->setError( s );
l->log( s, Log::Disaster );
if ( q->failed() ) {
l->log( "Query: " + q->description(), Log::Disaster );
l->log( "Error: " + q->error(), Log::Disaster );
}
}
else {
result->setState( Query::Completed );
}
result->notify();
}
示例8: runtime_error
void
MySQLStorage::store (Event* e)
{
try {
this->init();
} catch (const exception& e) {
stringstream errss;
errss << "Couldn't initialise MySQL database: " << e.what();
throw runtime_error (errss.str());
}
try {
// Store the event to the database.
this->dbCheck();
Query query (this->conn.query());
query << "INSERT INTO `log` "
<< "( `time`"
<< ", `ms`"
<< ", `eventId`"
<< ", `dataId`"
<< ", `message`"
#ifdef GOT_DT_ERROR_CODE
<< ", `errorCode`"
#endif
<< ", `datastreamId`"
<< ", `datastreamName`"
<< ", `hostname`"
#ifdef GOT_DT_LOG_LEVEL
<< ", `logLevel`"
#endif
<< ", `pid`"
<< ")"
<< " VALUES "
<< " ( FROM_UNIXTIME(" << e->getTime().tv_sec << ")"
<< " , '" << e->getTime().tv_usec/1000
<< "', '" << e->getId() // SQL safe? (uuid)
<< "', '" << e->getDataId() // SQL safe? (uuid)
<< "', '" << e->getMessage() // Need to escape
#ifdef GOT_DT_ERROR_CODE
<< "', '" << e->getErrorCode() // SQL safe (int)
#endif
<< "', '" << e->getDatastreamId() // SQL safe? (uuid)
<< "', '" << e->getDatastreamName() // SQL safe? (datastreamNames can't contain '; etc)
<< "', '" << e->getHostname() // SQL safe?
#ifdef GOT_DT_LOG_LEVEL
<< "', '" << e->getLogLevel() // SQL safe (int)
#endif
<< "', '" << e->getPid() // SQL safe (int)
<< "');";
//DBG ("INSERT Query string: " << query.str());
if (query.exec() == false) {
stringstream ee;
ee << "Query failed, error: '" << query.error() << "'";
throw runtime_error (ee.str());
}
}
catch (mysqlpp::BadQuery e) { this->handleBadQuery (e); }
catch (mysqlpp::Exception e) { this->handleException (e); }
}
示例9: table
void
MySQLStorage::init (void)
{
vector<pair<string, string> > fields;
fields.push_back (make_pair ("id", "int(10) unsigned NOT NULL auto_increment"));
fields.push_back (make_pair ("eventId", "varchar(255) collate latin1_bin NOT NULL default ''"));
fields.push_back (make_pair ("dataId", "varchar(255) collate latin1_bin NOT NULL default ''"));
fields.push_back (make_pair ("message", "varchar(255) collate latin1_bin NOT NULL default ''"));
fields.push_back (make_pair ("errorCode", "int(10) unsigned NOT NULL default 0"));
fields.push_back (make_pair ("datastreamId", "varchar(255) collate latin1_bin NOT NULL default ''"));
fields.push_back (make_pair ("datastreamName", "varchar(255) collate latin1_bin NOT NULL default ''"));
fields.push_back (make_pair ("hostname", "varchar(255) collate latin1_bin NOT NULL default ''"));
fields.push_back (make_pair ("logLevel", "int(10) unsigned NOT NULL default 0")); // could be enum?
fields.push_back (make_pair ("pid", "int(10) unsigned NOT NULL default 0"));
fields.push_back (make_pair ("time", "DATETIME NOT NULL"));
fields.push_back (make_pair ("ms", "int(10) unsigned NOT NULL default 0"));
string table (MySQLStorage::defaultDbTable);
try {
this->dbCheck();
Query query (this->conn.query());
// Create the database if necessary
query << "CREATE TABLE IF NOT EXISTS `" << table << "` "
<< "(";
bool first (true);
auto iField (fields.begin()), fEnd (fields.end());
while (iField != fEnd) {
if (!first) {
query << ", ";
} else {
first = false;
}
query << "`" << iField->first << "` " << iField->second;
++iField;
}
query << ", PRIMARY KEY (`id`)"
<< ") "
<< "ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_bin; ";
if (query.exec() == false) {
stringstream ee;
ee << "Query failed, error: '" << query.error() << "'";
throw runtime_error (ee.str());
}
// Check that all of the columns exist
iField = fields.begin();
while (iField != fEnd) {
query.reset();
query << "SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'dt'"
<< " AND TABLE_NAME = '" << table << "' AND COLUMN_NAME = '" << iField->first << "';";
UseQueryResult res (query.use());
if (!res) {
stringstream ee;
ee << "Query failed, error: '" << query.error() << "'";
throw runtime_error (ee.str());
}
if (Row row = res.fetch_row()) {
} else {
// Need to add the column
//DBG ("Couldn't find the column '" << iField->first << "'");
query.reset();
query << "ALTER TABLE `" << table << "` ADD `" << iField->first << "` " << iField->second << ";";
//DBG (name << " ALTER query string: " << query.str());
if (query.exec() == false) {
stringstream ee;
ee << "Query failed, error: '" << query.error() << "'";
throw runtime_error (ee.str());
}
}
++iField;
}
}
catch (mysqlpp::BadQuery e) { this->handleBadQuery (e); }
catch (mysqlpp::Exception e) { this->handleException (e); }
}
示例10: writeMarkerFile
int writeMarkerFile(string mask, string filename)
{
int noidis = 0;
try
{
ifstream sqlparmfile("../exe/SQLparms.txt");
string servername, dbname, username, password;
getline(sqlparmfile,servername);
getline(sqlparmfile,dbname);
getline(sqlparmfile,username);
getline(sqlparmfile,password);
Connection conn( dbname.c_str(), servername.c_str(), username.c_str(), password.c_str());
Query query = conn.query();
query << "Select get_ms_id('"<<mask<<"') as id";
StoreQueryResult ares = query.store();
int id;
if(!ares)
{
cerr<<query.error()<<endl;
return -1;
}
for(size_t i = 0; i<ares.num_rows(); i++)
{
id = ares[i]["id"];
//cout << id << endl;
}
query.reset();
//cout << "ID" << id << endl;
query << "SELECT id FROM marker WHERE markersetid= " << id << " ORDER BY idx";
//cout << query.str() << endl;
ares = query.store();
if(!ares)
{
cerr << "Right here. " << endl;
cerr << query.error()<<endl;
return -1;
}
else
{
//run here query once to get size of samples and than store it in a 2d int array
Query q3 = conn.query();
q3 << "SELECT value FROM markerval" << team << ", marker WHERE markerid = marker.id AND markerid = " << ares [0]["id"] << " ORDER BY idx";
StoreQueryResult ares3 = q3.store();
int totalind= ares3.num_rows();
int totalmark = ares.num_rows();
q3.reset();
double towrite[totalind][totalmark];
ofstream myfile;
myfile.open(filename.c_str());
ofstream myfile11;
string fn = "data.vocab";
myfile11.open(fn.c_str());
noidis = ares.num_rows();
for (size_t i = 0; i <ares.num_rows(); i++)
{
myfile11 << ares[i]["id"] << "\n";
Query q2 = conn.query();
q2 << "SELECT value FROM markerval" << team << ", marker WHERE markerid = marker.id AND markerid = " << ares [i]["id"] << " ORDER BY idx";
//cout << q2.str() << endl;
StoreQueryResult ares2 = q2.store();
// noidis = ares2.num_rows();
//cout << noidis << endl;
for(size_t j = 0; j <ares2.num_rows(); j ++)
{
towrite[j][i] = (double)ares2[j]["value"] ;
//myfile << ares2[j]["value"] << "\t";
}
//myfile << endl;
q2.reset();
}
myfile11.close();
for(int ind=0; ind <totalind ; ind++ )
{
for(int mark=0; mark<totalmark; mark++)
{
myfile << towrite[ind][mark] << "\t";
}
myfile << endl;
}
myfile.close();
}
}
catch(BadQuery er)
{
cerr << "Error: " << er.what() << endl;
return -1;
}
//.........这里部分代码省略.........
示例11: writeTraitFile
int writeTraitFile(string mask)
{
int noidis = 0;
int tts=-1;
try
{
ifstream sqlparmfile("../exe/SQLparms.txt");
string servername, dbname, username, password;
getline(sqlparmfile,servername);
getline(sqlparmfile,dbname);
getline(sqlparmfile,username);
getline(sqlparmfile,password);
Connection conn( dbname.c_str(), servername.c_str(), username.c_str(), password.c_str());
Query query = conn.query();
query << "SELECT get_ts_id('" << mask << "') as id";
StoreQueryResult ares = query.store();
int id;
if(!ares)
{
cerr << query.error() << endl;
return -1;
}
for(size_t i=0; i < ares.num_rows(); i ++)
{
id = ares[i]["id"];
}
query.reset();
query << "SELECT id FROM trait WHERE traitsetid = " << id << " ORDER BY idx";
ares = query.store();
if(!ares)
{
cerr << query.error() << endl;
return -1;
}
else
{
tts = ares.num_rows();
int fnum=1;
ofstream myfile1;
string fname1 = "tr_id";
myfile1.open(fname1.c_str());
for(size_t i = 0; i < ares.num_rows(); i ++)
{
ofstream myfile;
string fname = "tr"+toStrings(fnum);
myfile.open(fname.c_str());
Query q2 = conn.query();
myfile1 << ares[i]["id"] << "\n";
query << "SELECT value FROM traitval" << team << ",trait WHERE traitid=trait.id AND traitid = " << ares[i]["id"] << " ORDER BY idx";
StoreQueryResult ares2 = query.store();
noidis = ares2.num_rows();
for(size_t j = 0; j < ares2.num_rows(); j ++)
{
myfile << ares2[j]["value"] << "\n";
}
myfile << endl;
q2.reset();
myfile.close();
fnum++;
}
myfile1.close();
}
}
catch(BadQuery er)
{
cerr << "Error: " << er.what() << endl;
return -1;
}
catch(const BadConversion& er)
{
cerr << "Conversion error: " << er.what() << endl;
return -1;
}
catch(const Exception& er)
{
cerr << "Error: " << er.what() << endl;
return -1;
}
return tts;
}
示例12: insertIntoDB
//.........这里部分代码省略.........
cout<<"file not found: "<<file <<endl;
return;
}
}
string file = "eig_coef";
ifstream myfile(file.c_str());
if(myfile.is_open())
{
for(int i=0; i < totalind; i++)
{
string line;
getline(myfile, line);
vector<string> tokens;
Tokenize(line, tokens,"\t");
cout<<"eigen1 "<<atof(tokens[0].data())<<"\teigen2 "<<atof(tokens[1].data())<<"\teigen3 "<<atof(tokens[2].data())<<endl;
eigen[i][0]=atof(tokens[0].data());
eigen[i][1]=atof(tokens[1].data());
eigen[i][2]=atof(tokens[2].data());
eigen[i][3]=atof(tokens[3].data());
eigen[i][4]=atof(tokens[4].data());
}
}
else
{
cout<<"file not found: "<<file <<endl;
return;
}
//insert
ifstream sqlparmfile("../exe/SQLparms.txt");
string servername, dbname, username, password;
getline(sqlparmfile,servername);
getline(sqlparmfile,dbname);
getline(sqlparmfile,username);
getline(sqlparmfile,password);
Connection conn( dbname.c_str(), servername.c_str(), username.c_str(), password.c_str());
Query query = conn.query();
query << "SELECT createPopStruct(" << msid<< ",'" <<name << "' ) as id";
StoreQueryResult ares = query.store();
int id;
if(!ares)
{
cerr << query.error() << endl;
return;
}
for(size_t i=0; i < ares.num_rows(); i ++)
{
id = ares[i]["id"];
}
//start inserting
query.reset();
for(int i=0; i < totalind; i++)
{
string qstri;
qstri = "INSERT INTO structure (popstructid, sampleid, pop2,pop3,pop4,pop5,pop6,pop7,pop8,pop9,pop10,eig1,eig2,eig3,eig4,eig5) VALUES (";
qstri.append(toStrings(id));
qstri.append(",");
for(int p=0; p<10; p++)
{
qstri.append(toStrings(towrite[i][p]));
qstri.append(",");
}
for(int p=0; p<4; p++)
{
qstri.append(toStrings(eigen[i][p]));
qstri.append(",");
}
qstri.append(toStrings(eigen[i][4]));
qstri.append(")");
cout<<qstri<<endl;
query << qstri;
query.execute();
cout << query.error() << endl;
query.reset();
}
query.reset();
query << "UPDATE popstruct SET loadcmpt = 1 WHERE id = " << id << ";" << endl;
query.execute();
}
catch(BadQuery er)
{
cerr << "Error: " << er.what() << endl;
}
catch(const BadConversion& er)
{
cerr << "Conversion error: " << er.what() << endl;
}
catch(const Exception& er)
{
cerr << "Error: " << er.what() << endl;
}
}