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


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

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


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

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

示例2: fetch

int ODBCWrapper::fetch(int stmtId)
{
    Statement *stmt = stmts[stmtId];
    if (!stmt) return MOB_INVALID_STMTID;
    int rc = stmt->fetch();
    return (rc);
}
开发者ID:onagano,项目名称:mt4-odbc-bridge,代码行数:7,代码来源:odbcwrapper.cpp

示例3: execute

bool DatabaseClient::execute(SqlExecutableRef& se, Connection* c)
{
   bool rval = false;

   if(se.isNull())
   {
      // typical usage will involve generating an SQL executable and then
      // passing it to this method ... the generation might result in a
      // NULL SQL executable which would be passed here and caught for
      // convenience ... if that's the case a relevant exception is already
      // set -- for the degenerate/unusual case nothing is set yet so we set
      // something here
      if(!Exception::isSet())
      {
         ExceptionRef e = new Exception(
            "Could not execute SQL. SqlExecutable is NULL.",
            DBC_EXCEPTION ".NullSqlExecutable");
         Exception::set(e);
      }
   }
   else
   {
      // FIXME: this is for mysql only, see FIXME below
      if(se->returnRowsFound)
      {
         size_t i = se->sql.find("SELECT ");
         if(i != string::npos)
         {
            se->sql.insert(i + 7, "SQL_CALC_FOUND_ROWS ");
         }
      }

      if(mDebugLogging)
      {
         MO_CAT_DEBUG_DATA(MO_SQL_CAT,
            "SqlExecutable:\n"
            "sql: %s\n"
            "write: %s\n"
            "params: %s\n"
            "columnSchemas: %s\n"
            "whereFilter: %s\n",
            se->sql.c_str(),
            se->write ? "true" : "false",
            JsonWriter::writeToString(se->params, false, false).c_str(),
            JsonWriter::writeToString(se->columnSchemas, false, false).c_str(),
            JsonWriter::writeToString(se->whereFilter, false, false).c_str());
      }

      // get a connection from the pool if one wasn't passed in
      Connection* conn = (c == NULL) ?
         (se->write ? getWriteConnection() : getReadConnection()) : c;
      if(conn != NULL)
      {
         // prepare statement, set parameters, and execute
         Statement* s = conn->prepare(se->sql.c_str());
         rval = (s != NULL) && setParams(s, se->params) && s->execute();

         // if we wrote to the database, get affected rows and last insert ID
         if(rval && se->write)
         {
            s->getRowsChanged(se->rowsAffected);
            se->lastInsertRowId = s->getLastInsertRowId();
         }
         // else we read, so get row results
         else if(rval && !se->result.isNull())
         {
            // get results as an array
            if(se->result->getType() == Array)
            {
               // FIXME: we intentionally do not check rval in this while()
               // loop right now because there are some issues where if
               // if we don't retrieve the entire result set (fetch each row)
               // then we run into problems -- this needs to be double checked
               // so we can handle this case better

               // iterate over rows
               int index = 0;
               Row* r;
               while((r = s->fetch()) != NULL)
               {
                  // pull out data
                  DynamicObject& row = se->result[index++];
                  rval = getRowData(se->columnSchemas, r, row);
               }

               // save number of rows retrieved
               se->rowsRetrieved = se->result->length();
            }
            // get results as a single map
            else
            {
               Row* r = s->fetch();
               if(r == NULL)
               {
                  // the value doesn't exist
                  se->rowsRetrieved = 0;
               }
               else
               {
                  // row found, pull out data
//.........这里部分代码省略.........
开发者ID:bsletten,项目名称:monarch,代码行数:101,代码来源:DatabaseClient.cpp


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