本文整理汇总了C++中Statement::execute方法的典型用法代码示例。如果您正苦于以下问题:C++ Statement::execute方法的具体用法?C++ Statement::execute怎么用?C++ Statement::execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Statement
的用法示例。
在下文中一共展示了Statement::execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execute
void IfStatement::execute()
{
if (cond->evaluate()) {
cout << "TRUE " << endl;
if (!truecode.empty()) {
list<Statement *>::iterator it = truecode.begin();
while (it != truecode.end()) {
Statement *st = *it;
//printf("StKind: %s\n",st->getSTR().c_str());
st->execute();
it++;
}
//truecode->execute();
}
}
else{
cout << "FALSE" << endl;
if (!falsecode.empty()){
list<Statement *>::iterator it = falsecode.begin();
while (it != falsecode.end()) {
Statement *st = *it;
//printf("StKind: %s\n",st->getSTR().c_str());
st->execute();
it++;
}
//falsecode->execute();
}
}
}
示例2: throw
/*!
* \brief バージョン1にアップデート
*/
void SequenceLogServiceDB::updateVersion1() const throw(Exception)
{
SLOG(CLS_NAME, "updateVersion1");
Statement* stmt = nullptr;
try
{
// バージョン情報テーブル作成
query(
"create table version_info("
" version int not null);");
// バージョン登録
stmt = newStatement();
stmt->prepare("insert into version_info (version) values (1)");
stmt->execute();
delete stmt;
stmt = nullptr;
// アカウントテーブル作成
#if defined(USE_SQLITE)
query(
"create table user("
" id integer primary key autoincrement,"
" name varchar not null unique,"
" password varchar not null,"
" mail_addr varchar,"
" version int not null default 1,"
" admin int not null default 0);");
#else
query(
"create table user("
" id int primary key auto_increment,"
" name varchar(20) not null unique,"
" password varchar(64) not null,"
" mail_addr varchar(256),"
" version tinyint not null default 1,"
" admin tinyint not null default 0);");
#endif
// 初期アカウント登録(パスワード:gols)
stmt = newStatement();
stmt->prepare("insert into user (name, password, admin) values ('slog', 'RrtQzcEv7FQ1QaazVN+ZXHHAS/5F/MVuDUffTotnFKk=', 1)");
stmt->execute();
}
catch (Exception e)
{
SMSG(slog::DEBUG, "%s", e.getMessage());
delete stmt;
throw e;
}
delete stmt;
}
示例3: insertBar
int ODBCWrapper::insertBar(const int stmtId, unsigned int datetime, double *vals, const int size)
{
int rv = 0;
Statement *stmt = stmts[stmtId];
if (!stmt) return MOB_INVALID_STMTID;
//TODO: rewrite to use type-specific parameter binding method
DataPointer *dps = (DataPointer *) malloc(sizeof(DataPointer) * (size + 1));
SQL_TIMESTAMP_STRUCT ts;
time_t tt = (time_t) datetime;
TimestampPointer::timet2timestamp(&tt, &ts);
dps[0] = TimestampPointer(&ts);
for(int i = 0; i < size; i++)
dps[i + 1] = DoublePointer(&vals[i]);
try
{
stmt->bindParameters(dps, size + 1);
rv = stmt->execute();
}
catch (ODBCException *e)
{
handleException(e);
free(dps);
return MOB_NG;
}
free(dps);
return rv;
}
示例4: insert
int64_t Database::insert(const String &table, const Serializable &serializable)
{
Statement dummy = prepare("SELECT * FROM `" + table + "` LIMIT 1");
dummy.step();
String columns;
String values;
int count = 0;
for(int i=0; i<dummy.columnsCount(); ++i)
{
String name = dummy.name(i);
if(name == "rowid" || name == "id")
continue;
if(count)
{
columns+= ',';
values+= ',';
}
columns+= name;
values+= "@" + name;
++count;
}
dummy.finalize();
String request = "INSERT OR REPLACE INTO `" + table + "` (" + columns + ") VALUES (" + values + ")";
Statement statement = prepare(request);
statement << serializable;
statement.execute(); // unbound parameters will be interpreted as null
return insertId();
}
示例5: getVersion
/*!
* \brief データベースバージョン取得
*
* \return データベースバージョン
*/
int32_t SequenceLogServiceDB::getVersion() const
{
SLOG(CLS_NAME, "getVersion");
int32_t version = 0;
Statement* stmt = nullptr;
try
{
const char* sql = "select version from version_info";
stmt = newStatement();
stmt->prepare(sql);
stmt->setIntResult(0, &version);
stmt->bind();
stmt->execute();
stmt->fetch();
}
catch (Exception e)
{
// 初回起動時などテーブルが存在しない場合もあるので、
// 例外が発生しても何もすることはない
SMSG(slog::DEBUG, "%s", e.getMessage());
}
delete stmt;
return version;
}
示例6: SQL
int BillingInstance::SQL(std::string &query, std::vector<std::string> ¶ms)
{
if(_conn == NULL) {
return 0;
}
int retval = 0;
Statement *sth = NULL;
try {
sth = _conn->createStatement(query);
sth->setAutoCommit(true);
for(int i=0; i<params.size(); ++i) {
sth->setString(i+1, params.at(i));
}
std::cerr << "Query execute" << std::endl;
Statement::Status status = sth->execute();
}
catch (SQLException &sqlExcp)
{
std::cerr <<sqlExcp.getErrorCode() << " at " << __FILE__ << "/" << __LINE__ << ": " << sqlExcp.getMessage() << std::endl;
retval = sqlExcp.getErrorCode();
}
if(sth != NULL) {
_conn->terminateStatement(sth);
}
return retval;
}
示例7: main
int main(int argc, char** argv)
{
USE_NETWORK;
using namespace sql;
Statement *state;
ResultSet *result;
Connection *con = DbLib::instance().connect("tcp://127.0.0.1:3306", "root", "");
state = con->createStatement();
state->execute("use net_db");
result = state->executeQuery("select * from g_user");
//printf(" id user_id user_name level profession\n");
printf("%7s%10s%20s%7s%10s\n", "id", "user_id", "user_name", "level", "role_id");
while(result->next())
{
int64_t id = result->getInt64("id");
int user_id = result->getInt("user_id");
string user_name = result->getString("user_name");
int level = result->getInt("level");
int profession = result->getInt("role_id");
printf(" %7d ", id);
printf(" %10d ", user_id);
printf(" %20s ", user_name.c_str());
printf(" %7d ", level);
printf(" %10d \n", profession);
}
delete state;
delete con;
system("pause");
return 0;
}
示例8: rollback
bool AbstractConnection::rollback()
{
bool rval = false;
// save the reason for the rollback
ExceptionRef reason = Exception::get();
// attempt to do the rollback
Statement* s = prepare("ROLLBACK");
rval = (s != NULL) && s->execute() && s->reset();
if(!rval)
{
ExceptionRef e = new Exception(
"Could not rollback transaction.",
"monarch.sql.Connection.TransactionRollbackError");
if(!reason.isNull())
{
e->getDetails()["rollbackReason"] =
Exception::convertToDynamicObject(reason);
}
Exception::push(e);
}
return rval;
}
示例9: runProgram
void runProgram(Program & program, EvalState & state) {
int lineNumber = program.getFirstLineNumber();
while (lineNumber != -1) {
Statement * stmt = program.getParsedStatement(lineNumber);
state.setCurrentLine(program.getNextLineNumber(lineNumber));
stmt->execute(state);
lineNumber = state.getCurrentLine();
}
}
示例10: runProgram
/*
* Function: runProgram
* Usage: runProgram(program, context);
* -------------------------------------------
* Runs the program starting from the first line number.
*/
void runProgram(Program & program, EvaluationContext & context) {
context.setCurrentLine(program.getFirstLineNumber());
int programLine = context.getCurrentLine();
while (programLine != -1) {
Statement *stmt = program.getParsedStatement(programLine);
context.setCurrentLine(program.getNextLineNumber(programLine)); // updates to line + 1
stmt->execute(context); // unless controlled by IF, GOTO, or END
programLine = context.getCurrentLine();
}
}
示例11: testSession
void DataTest::testSession()
{
Session sess(SessionFactory::instance().create("test", "cs"));
sess << "DROP TABLE IF EXISTS Test", now;
int count;
sess << "SELECT COUNT(*) FROM PERSON", into(count), now;
std::string str;
Statement stmt = (sess << "SELECT * FROM Strings", into(str), limit(50));
stmt.execute();
}
示例12: getProcessParams
void DatabaseSubsystem::getProcessParams(Session& session, ProcessPtr process)
{
string paramName, paramValue;
Statement stmt = (session <<
"SELECT param_name, param_value FROM process_param WHERE process_id = ?",
use(process->processID), range(0, 1), into(paramName), into(paramValue));
while (!stmt.done()) {
if (stmt.execute() == 1) {
process->parameters[paramName] = paramValue;
}
}
}
示例13: getResponseLabels
void DatabaseSubsystem::getResponseLabels(Session& session,
ResponsePtr& response)
{
int objectID;
int labelID;
Statement stmt = (session <<
"SELECT object_id, label_id FROM response_label WHERE response_id = ?",
use(response->responseID), range(0, 1), into(objectID), into(labelID));
while (!stmt.done()) {
if (stmt.execute() == 1)
response->labels[objectID] = labelID;
}
}
示例14: main
int main(int argc, char* argv[])
{
//初始化连接,创建参数中maxSize一半的连接
connpool.initPool("tcp://127.0.0.1:3306", "root", "123456", 100);
Connection *con;
Statement *state;
ResultSet *result;
con = connpool.GetConnection();
for(int i = 0; i<2; i++)
{
state = con->createStatement();
state->execute("use mysql");
// 查询
result = state->executeQuery("select host,user from user");
// 输出查询
while (result->next())
{
try{
string user = result->getString("user");
string name = result->getString("host");
cout << user << " : " << name << endl;
}catch(sql::SQLException& e){
std::cout<< e.what() <<std::endl;
}
}
result = state->executeQuery("select cust_id,cust_name from customers");
while (result->next())
{
try{
string user = result->getString("cust_id");
string name = result->getString("cust_name");
cout << user << " : " << name << endl;
}catch(sql::SQLException& e){
std::cout<< e.what() <<std::endl;
}
}
std::cout << i << std::endl;
}
delete result;
delete state;
connpool.ReleaseConnection(con);
return 0;
}
示例15: setup_test_table
/*
* Overload Function: setup_test_table
*/
void setup_test_table(Connection *con, int numOfPocs, int sensorsPerPoc) {
int i, j;
Statement *stmt;
PreparedStatement *pstmt;
try {
stmt = con->createStatement();
stmt->execute("DROP TABLE IF EXISTS ParkingSpot");
stmt->execute("CREATE TABLE ParkingSpot ("
"PocID int NOT NULL,"
"SensorID int NOT NULL,"
"SpotStatus int NOT NULL,"
"StartTime datetime DEFAULT NULL,"
"ExpireTime datetime DEFAULT NULL,"
"PRIMARY KEY (PocID, SensorID),"
"UNIQUE KEY LocationSensor_UNIQUE (PocID, SensorID))");
delete stmt;
pstmt = con->prepareStatement("INSERT INTO ParkingSpot (PocID, SensorID, SpotStatus) VALUES (?, ?, 0)");
for(i = 0; i < numOfPocs; i++)
{
pstmt->setInt(1, i);
for(j = 0; j < sensorsPerPoc; j++)
{
pstmt->setInt(2, j);
pstmt->execute();
}
}
} catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << " (function: " << __FUNCTION__ << ")" << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
delete pstmt;
}