当前位置: 首页>>代码示例>>C++>>正文


C++ Statement::execute方法代码示例

本文整理汇总了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();
        }
    }
}
开发者ID:Liz30,项目名称:2016-CompII,代码行数:29,代码来源:ast.cpp

示例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;
}
开发者ID:nandai,项目名称:slog,代码行数:59,代码来源:SequenceLogServiceDB.cpp

示例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;
}
开发者ID:onagano,项目名称:mt4-odbc-bridge,代码行数:29,代码来源:odbcwrapper.cpp

示例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();
}
开发者ID:paullouisageneau,项目名称:Teapotnet,代码行数:35,代码来源:database.cpp

示例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;
}
开发者ID:nandai,项目名称:slog,代码行数:34,代码来源:SequenceLogServiceDB.cpp

示例6: SQL

int BillingInstance::SQL(std::string &query, std::vector<std::string> &params)
{
    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;
}
开发者ID:omever,项目名称:CSharker,代码行数:32,代码来源:billing.cpp

示例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;
}
开发者ID:hcqmaker,项目名称:simple_game,代码行数:35,代码来源:server_dbbase.cpp

示例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;
}
开发者ID:zengyuxing007,项目名称:monarch,代码行数:25,代码来源:AbstractConnection.cpp

示例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();
    }
}
开发者ID:mariolew,项目名称:CS106B,代码行数:9,代码来源:Basic.cpp

示例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();
    }
}
开发者ID:Thunder1989,项目名称:CS106B,代码行数:16,代码来源:Basic.cpp

示例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();
}
开发者ID:carvalhomb,项目名称:tsmells,代码行数:11,代码来源:DataTest.cpp

示例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;
        }
    }
}
开发者ID:Spencerx,项目名称:openBliSSART,代码行数:12,代码来源:DatabaseSubsystem.cpp

示例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;
    }
}
开发者ID:Spencerx,项目名称:openBliSSART,代码行数:13,代码来源:DatabaseSubsystem.cpp

示例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;
}
开发者ID:uglychen,项目名称:chenxun,代码行数:51,代码来源:main.cpp

示例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;
}
开发者ID:FuG,项目名称:FSDB,代码行数:41,代码来源:driver.cpp


注:本文中的Statement::execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。