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


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

本文整理汇总了C++中PreparedStatement::execute方法的典型用法代码示例。如果您正苦于以下问题:C++ PreparedStatement::execute方法的具体用法?C++ PreparedStatement::execute怎么用?C++ PreparedStatement::execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PreparedStatement的用法示例。


在下文中一共展示了PreparedStatement::execute方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: storeCall

unsigned int CallManager::storeCall(Connection *sqlCon, bool phone, unsigned int client, unsigned int translator)
{
	if (!sqlCon)
		return 0;
	PreparedStatement *pstmt = sqlCon->prepareStatement(
			"INSERT INTO calls SET phone=(?), client=(?), translator=(?), request_time=NOW()");
	pstmt->setInt(1, phone);
	pstmt->setInt(2, client);
	pstmt->setInt(3, translator);

	try {
		pstmt->execute();
	} catch (SQLException &ex) {
		log(LOG_ERROR, "[%s] MySQL error(%d): %s", __func__, ex.getErrorCode(), ex.what());
		delete pstmt;
		return 0;
	}
	delete pstmt;

	pstmt = sqlCon->prepareStatement("SELECT LAST_INSERT_ID()");

	ResultSet *res;
	try {
		res = pstmt->executeQuery();
	} catch (SQLException &ex) {
		log(LOG_ERROR, "[%s] MySQL error(%d): %s", __func__, ex.getErrorCode(), ex.what());
		delete pstmt;
		return 0;
	}
	delete pstmt;
	res->first();
	unsigned int id = res->getInt(1);
	delete res;
	return id;
}
开发者ID:raschupkin,项目名称:TranslateNet,代码行数:35,代码来源:Call.cpp

示例2: updateFilterBlack

void ConfigConnector::updateFilterBlack(bool enable) {
	Connection conn = _pool->getConnection();

	PreparedStatement stmt = conn->prepareStatement("UPDATE `config_resource` SET `value` = ? WHERE `cid` = '1'");
	stmt->setBoolean(1, enable);
	stmt->execute();

	_pool->returnConnection(conn);
}
开发者ID:koala87,项目名称:ktvserver,代码行数:9,代码来源:ConfigConnector.cpp

示例3: constantQuery

void constantQuery(const std::string &queryName = std::string(), IOManager *ioManager = NULL)
{
    Connection conn(g_goodConnString, ioManager);
    PreparedStatement stmt = conn.prepare("SELECT 1, 'mordor'", queryName);
    Result result = stmt.execute();
    MORDOR_TEST_ASSERT_EQUAL(result.rows(), 1u);
    MORDOR_TEST_ASSERT_EQUAL(result.columns(), 2u);
    MORDOR_TEST_ASSERT_EQUAL(result.get<int>(0, 0), 1);
    MORDOR_TEST_ASSERT_EQUAL(result.get<long long>(0, 0), 1);
    MORDOR_TEST_ASSERT_EQUAL(result.get<const char *>(0, 1), "mordor");
    MORDOR_TEST_ASSERT_EQUAL(result.get<std::string>(0, 1), "mordor");
}
开发者ID:adfin,项目名称:mordor,代码行数:12,代码来源:pq.cpp

示例4: queryForParam

void queryForParam(const std::string &query, ParamType param, size_t expectedCount,
    ExpectedType expected,
    const std::string &queryName = std::string(), IOManager *ioManager = NULL)
{
    Connection conn(g_goodConnString, ioManager);
    fillUsers(conn);
    PreparedStatement stmt = conn.prepare(query, queryName);
    Result result = stmt.execute(param);
    MORDOR_TEST_ASSERT_EQUAL(result.rows(), expectedCount);
    MORDOR_TEST_ASSERT_EQUAL(result.columns(), 1u);
    MORDOR_TEST_ASSERT_EQUAL(result.get<ExpectedType>(0, 0), expected);
}
开发者ID:adfin,项目名称:mordor,代码行数:12,代码来源:pq.cpp

示例5: copyOut

static void copyOut(IOManager *ioManager = NULL)
{
    Connection conn(g_goodConnString, ioManager);
    conn.execute("CREATE TEMP TABLE country (code TEXT, name TEXT)");
    PreparedStatement stmt = conn.prepare("INSERT INTO country VALUES($1, $2)",
        "insertcountry");
    Transaction transaction(conn);
    stmt.execute("AF", "AFGHANISTAN");
    stmt.execute("AL", "ALBANIA");
    stmt.execute("DZ", "ALGERIA");
    stmt.execute("ZM", "ZAMBIA");
    stmt.execute("ZW", "ZIMBABWE");

    Stream::ptr stream = conn.copyOut("country").csv().delimiter('|')();
    MemoryStream output;
    transferStream(stream, output);
    MORDOR_ASSERT(output.buffer() ==
        "AF|AFGHANISTAN\n"
        "AL|ALBANIA\n"
        "DZ|ALGERIA\n"
        "ZM|ZAMBIA\n"
        "ZW|ZIMBABWE\n");
}
开发者ID:adfin,项目名称:mordor,代码行数:23,代码来源:pq.cpp

示例6: nuodb_statement_query

int nuodb_statement_query(struct nuodb *db, struct nuodb_statement *st,
                          struct nuodb_resultset **rs, int *column_count) {
    ResultSet *resultSet = 0;
    PreparedStatement *stmt = reinterpret_cast<PreparedStatement *>(st);
    try {
        bool hasResults = stmt->execute();
        if (hasResults) {
            resultSet = stmt->getResultSet();
        } else {
            resultSet = stmt->getGeneratedKeys();
        }
        *column_count = resultSet->getMetaData()->getColumnCount();
        *rs = reinterpret_cast<struct nuodb_resultset *>(resultSet);
        return 0;
    } catch (SQLException &e) {
        if (resultSet) {
            resultSet->close();
        }
        return setError(db, e);
    }
}
开发者ID:tilinna,项目名称:go-nuodb,代码行数:21,代码来源:cnuodb.cpp

示例7: 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

示例8: execute

/**
 *
 * Executes a query and returns the result
 *
 * @param VariantVector arguments The query arguments. The first argument should
 * be the query and any subsequent arguments are the bind parameters
 *
 * @return The results from the query
 */
QueryResult DatabaseConnection::execute(VariantVector arguments)
{
    int i;
    int count;
    QueryResult result;
    ResultSet *sqlResult;
    ResultSetMetaData *sqlMetadata;

    result = connect();
    if (result.error.isError) {

        // There was an error connecting. Return the result.
        return result;
    }

    PreparedStatement *sqlStatement = nullptr;

    try {

        // Prepare query
        sqlStatement = connection->prepareStatement(
            arguments.front().toString());

        if (arguments.size() > 1) {

            // Bind arguments
            int i = 1;
            for (auto it = arguments.begin() + 1; it != arguments.end(); ++it) {

                sqlStatement->setString(i, it->toString());

                i++;
            }
        }

        // Execute query
        sqlStatement->execute();

        // Fetch results
        sqlResult = sqlStatement->getResultSet();
    } catch (SQLException &e) {

        if (sqlStatement != nullptr) {

            // Free memory
            delete sqlStatement;
        }

        result.error.isError = true;
        result.error.code = e.getErrorCode();
        result.error.string = e.getSQLState() + ": " + e.what();

        return result;
    }

    sqlMetadata = sqlResult->getMetaData();

    count = sqlMetadata->getColumnCount();

    for (i = 1; i <= count; i++) {

        // Add to collection
        result.columns.push_back(sqlMetadata->getColumnName(i).asStdString());
    }

    // Read rows
    while (sqlResult->next()) {
        VariantVector row;
        for (i = 1; i <= count; i++) {
            Variant column;

            switch (sqlMetadata->getColumnType(i)) {
            default:
            case ::DataType::UNKNOWN:
            case ::DataType::CHAR:
            case ::DataType::VARCHAR:
            case ::DataType::LONGVARCHAR:
            case ::DataType::BINARY:
            case ::DataType::VARBINARY:
            case ::DataType::LONGVARBINARY:
            case ::DataType::TIMESTAMP:
            case ::DataType::DATE:
            case ::DataType::GEOMETRY:
            case ::DataType::ENUM:
            case ::DataType::SET:
            case ::DataType::BIGINT:
            case ::DataType::REAL:
            case ::DataType::DOUBLE:
            case ::DataType::DECIMAL:
                // @TODO: store binary, timestamp, date, & geometry differently
                // Also numeric types (need to be added to Variant class)
//.........这里部分代码省略.........
开发者ID:curquhart,项目名称:rsql-backend,代码行数:101,代码来源:databaseconnection.cpp


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