• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PQexecParams函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中PQexecParams函数的典型用法代码示例。如果您正苦于以下问题:C++ PQexecParams函数的具体用法?C++ PQexecParams怎么用?C++ PQexecParams使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: v_count_age_owners

uint32_t v_count_age_owners(uint32_t ageInfoId)
{
    PostgresStrings<2> parms;
    parms.set(0, ageInfoId);
    parms.set(1, DS::Vault::e_AgeOwnersFolder);
    PGresult* result = PQexecParams(s_postgres,
                       "SELECT idx FROM vault.find_folder($1, $2);",
                       2, 0, parms.m_values, 0, 0, 0);
    uint32_t owners = 0;
    if (PQresultStatus(result) != PGRES_TUPLES_OK) {
        fprintf(stderr, "%s:%d:\n    Postgres SELECT error: %s\n",
                __FILE__, __LINE__, PQerrorMessage(s_postgres));
        PQclear(result);
        return owners;
    }
    parms.set(0, PQgetvalue(result, 0, 0));
    PQclear(result);
    result = PQexecParams(s_postgres,
             "SELECT COUNT(*) FROM vault.\"NodeRefs\" WHERE \"ParentIdx\"=$1",
              1, 0, parms.m_values, 0, 0, 0);
    if (PQresultStatus(result) == PGRES_TUPLES_OK) {
        owners = strtoul(PQgetvalue(result, 0, 0), 0, 10);
    } else {
        fprintf(stderr, "%s:%d:\n    Postgres SELECT error: %s\n",
                __FILE__, __LINE__, PQerrorMessage(s_postgres));
    }
    PQclear(result);
    return owners;
}
开发者ID:Hoikas,项目名称:dirtsand,代码行数:29,代码来源:AuthVault.cpp


示例2: dm_save_sdl_state

void dm_save_sdl_state(GameHost_Private* host, const DS::String& descriptor,
                       const MOUL::Uoid& object, const SDL::State& state)
{
    check_postgres(host);

    DS::Blob sdlBlob = state.toBlob();
    PostgresStrings<4> parms;
    host->m_buffer.truncate();
    object.write(&host->m_buffer);
    parms.set(0, host->m_serverIdx);
    parms.set(1, descriptor);
    parms.set(2, DS::Base64Encode(host->m_buffer.buffer(), host->m_buffer.size()));
    parms.set(3, DS::Base64Encode(sdlBlob.buffer(), sdlBlob.size()));
    PGresult* result = PQexecParams(host->m_postgres,
                                    "SELECT idx FROM game.\"AgeStates\""
                                    "    WHERE \"ServerIdx\"=$1 AND \"Descriptor\"=$2 AND \"ObjectKey\"=$3",
                                    3, 0, parms.m_values, 0, 0, 0);
    if (PQresultStatus(result) != PGRES_TUPLES_OK) {
        fprintf(stderr, "%s:%d:\n    Postgres SELECT error: %s\n",
                __FILE__, __LINE__, PQerrorMessage(host->m_postgres));
        PQclear(result);
        return;
    }
    if (PQntuples(result) == 0) {
        PQclear(result);
        result = PQexecParams(host->m_postgres,
                              "INSERT INTO game.\"AgeStates\""
                              "    (\"ServerIdx\", \"Descriptor\", \"ObjectKey\", \"SdlBlob\")"
                              "    VALUES ($1, $2, $3, $4)",
                              4, 0, parms.m_values, 0, 0, 0);
        if (PQresultStatus(result) != PGRES_COMMAND_OK) {
            fprintf(stderr, "%s:%d:\n    Postgres INSERT error: %s\n",
                    __FILE__, __LINE__, PQerrorMessage(host->m_postgres));
            PQclear(result);
            return;
        }
        PQclear(result);
    } else {
        DS_DASSERT(PQntuples(result) == 1);
        parms.set(0, DS::String(PQgetvalue(result, 0, 0)));
        parms.set(1, parms.m_strings[3]);   // SDL blob
        PQclear(result);
        result = PQexecParams(host->m_postgres,
                              "UPDATE game.\"AgeStates\""
                              "    SET \"SdlBlob\"=$2 WHERE idx=$1",
                              2, 0, parms.m_values, 0, 0, 0);
        if (PQresultStatus(result) != PGRES_COMMAND_OK) {
            fprintf(stderr, "%s:%d:\n    Postgres UPDATE error: %s\n",
                    __FILE__, __LINE__, PQerrorMessage(host->m_postgres));
            PQclear(result);
            return;
        }
        PQclear(result);
    }
}
开发者ID:daela,项目名称:dirtsand,代码行数:55,代码来源:GameHost.cpp


示例3: find_public_age_1

static uint32_t find_public_age_1(const DS::String& filename)
{
    PGresult* result;
    {
        PostgresStrings<1> parm;
        parm.set(0, filename);
        result = PQexecParams(s_postgres,
                "SELECT \"AgeUuid\" FROM game.\"PublicAges\""
                "    WHERE \"AgeFilename\"=$1 AND \"SeqNumber\"=0",
                1, 0, parm.m_values, 0, 0, 0);
    }
    if (PQresultStatus(result) != PGRES_TUPLES_OK) {
        fprintf(stderr, "%s:%d:\n    Postgres SELECT error: %s\n",
                __FILE__, __LINE__, PQerrorMessage(s_postgres));
        PQclear(result);
        return 0;
    }
    DS_DASSERT(PQntuples(result) == 1);

    DS::Uuid ageId(PQgetvalue(result, 0, 0));
    PQclear(result);

    {
        PostgresStrings<2> parms;
        parms.set(0, DS::Vault::e_NodeAgeInfo);
        parms.set(1, ageId.toString());
        result = PQexecParams(s_postgres,
                "SELECT idx FROM vault.\"Nodes\""
                "    WHERE \"NodeType\"=$1 AND \"Uuid_1\"=$2",
                2, 0, parms.m_values, 0, 0, 0);
    }
    if (PQresultStatus(result) != PGRES_TUPLES_OK) {
        fprintf(stderr, "%s:%d:\n    Postgres SELECT error: %s\n",
                __FILE__, __LINE__, PQerrorMessage(s_postgres));
        PQclear(result);
        return 0;
    }
    if (PQntuples(result) == 0) {
        // Public age not found
        PQclear(result);
        return 0;
    }
    DS_DASSERT(PQntuples(result) == 1);

    uint32_t ageInfoNode = strtoul(PQgetvalue(result, 0, 0), 0, 10);
    PQclear(result);
    return ageInfoNode;
}
开发者ID:TheEggman,项目名称:dirtsand,代码行数:48,代码来源:AuthVault.cpp


示例4: PQexecParams_stub

CAMLprim value PQexecParams_stub(
  value v_conn, value v_query, value v_params, value v_binary_params)
{
  CAMLparam1(v_conn);
  PGconn *conn = get_conn(v_conn);
  np_callback *np_cb = get_conn_cb(v_conn);
  PGresult *res;
  size_t len = caml_string_length(v_query) + 1;
  char *query = caml_stat_alloc(len);
  size_t nparams = Wosize_val(v_params);
  const char * const *params = copy_params(v_params, nparams);
  int *formats, *lengths;
  copy_binary_params(v_params, v_binary_params, nparams, &formats, &lengths);
  memcpy(query, String_val(v_query), len);
  caml_enter_blocking_section();
    res =
      (nparams == 0)
        ? PQexec(conn, query)
        : PQexecParams(conn, query, nparams, NULL, params, lengths, formats, 0);
    free_binary_params(formats, lengths);
    free_params(params, nparams);
    free(query);
  caml_leave_blocking_section();
  CAMLreturn(alloc_result(res, np_cb));
}
开发者ID:Nevor,项目名称:postgresql-ocaml,代码行数:25,代码来源:postgresql_stubs.c


示例5: executeQuery

      boost::shared_ptr<ResultSet> executeQuery(const std::string& sql,int type=0) const
      {
         PGresult *result=0;
         if (type==1)
         {
             result=PQexecParams(conn_,sql.c_str(),0,0,0,0,0,1);
         }
         else
         {
             result=PQexec(conn_,sql.c_str());
         }
         if(!result || PQresultStatus(result) != PGRES_TUPLES_OK)
         {
             std::ostringstream s("Postgis Plugin: PSQL error");
             if (conn_ )
             {
                 std::string msg = PQerrorMessage( conn_ );
                 if ( ! msg.empty() )
                 {
                     s << ":\n" <<  msg.substr( 0, msg.size() - 1 );
                 }
                 
                 s << "\nFull sql was: '" <<  sql << "'\n";
             }
             if (result)
                 PQclear(result);
             throw mapnik::datasource_exception( s.str() );
         }

         return boost::make_shared<ResultSet>(result);
      }
开发者ID:ParveenArora,项目名称:mapnik,代码行数:31,代码来源:connection.hpp


示例6: sequence_last

			virtual long long sequence_last(std::string const &sequence)
			{
				PGresult *res = 0;
				long long rowid = 0;
				try {
					char const * const param_ptr = sequence.c_str();
					res = PQexecParams(	conn_,
								"SELECT currval($1)",
								1, // 1 param
								0, // types
								&param_ptr, // param values
								0, // lengths
								0, // formats
								0 // string format
								);
					if(PQresultStatus(res) != PGRES_TUPLES_OK) {
						throw pqerror(res,"failed to fetch last sequence id");
					}
					char const *val = PQgetvalue(res,0,0);
					if(!val || *val==0)
						throw pqerror("Failed to get value for sequecne id");
					fmt_.str(val);
					fmt_.clear();
					fmt_ >> rowid;
					fmt_.str(std::string());
					fmt_.clear();
				}
				catch(...) {
					if(res) PQclear(res);
					throw;
				}
				PQclear(res);
				return rowid;
			}
开发者ID:aspectron,项目名称:jsx,代码行数:34,代码来源:postgres_backend.cpp


示例7: _DB_mark_config_del

static int _DB_mark_config_del(Database *db, unsigned int id, time_t del_at){
    PGconn   *conn;
    PGresult *res;
    const char *paramValues[2];
    const int   paramLengths[2] = {sizeof(int), sizeof(int)};
    const int   paramFormats[2] = {BINARY_FRMT, BINARY_FRMT};
    uint32_t config_id, time_del_at;
    
    if(_DB_connect(db, &conn)    != 0) return 1;
    if(_DB_begin(db, conn, &res) != 0){ _DB_close_res(db, conn, res); return 1;}
    
    paramValues[0] = chk_time_to_null(del_at, &time_del_at);
    paramValues[1] = order_int(id, &config_id);
            
    res = PQexecParams(conn,
        "UPDATE "CONFIGS_TABNAME" SET deleted_at = "TO_TIMESTAMP("$3")
            " WHERE id = $2::int;",
        2,              /* count of params */
        NULL,           /* let the backend deduce param type */
        paramValues,
        paramLengths,
        paramFormats,
        TEXT_FRMT);             /* text results */
    if(PQresultStatus(res) != PGRES_COMMAND_OK){
        _DB_close_res(db, conn, res);
        return 1;
    }
    PQclear(res);
    
    if(_DB_commit(db, conn, &res) != 0){ _DB_close_res(db, conn, res); return 1;}
    
    PQfinish(conn);
    return 0;
}
开发者ID:korun,项目名称:dcs-system,代码行数:34,代码来源:sync.c


示例8: fillNext

static void fillNext(GtkTreeSelection* selection, GtkListStore* model) {
    uint32_t i;
    gtk_list_store_clear(model);

    static char offset[0x100];
    ssize_t len = snprintf(offset,0x100,"%d",page*pagesize);
    
    const char* values[] = { offset, derpagesize };
    const int lengths[] = { len, sizeof(derpagesize)  };
    const int fmt[] = { 0, 0 };

    PGresult* result = PQexecParams(PQconn,"getpage",1,NULL,values,lengths,fmt,0);
    GtkTreeIter iter = {};
    gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model),&iter);
    for(i=0;i<PQntuples(result);++i) {
        gtk_list_store_append(model,&iter);
        gtk_list_store_set(model,&iter,0,strtof(PQgetvalue(result,i,0),NULL),
                1,PQgetvalue(result,i,1),
                2,PQgetvalue(result,i,2),
                -1);
    }

    PQclear(result);

    ++page;

}
开发者ID:cyisfor,项目名称:songPlayer,代码行数:27,代码来源:ratebytitle.c


示例9: v_fetch_tree

bool v_fetch_tree(uint32_t nodeId, std::vector<DS::Vault::NodeRef>& refs)
{
    PostgresStrings<1> parm;
    parm.set(0, nodeId);
    PGresult* result = PQexecParams(s_postgres,
            "SELECT \"ParentIdx\", \"ChildIdx\", \"OwnerIdx\", \"Seen\""
            "    FROM vault.fetch_tree($1);",
            1, 0, parm.m_values, 0, 0, 0);
    if (PQresultStatus(result) != PGRES_TUPLES_OK) {
        fprintf(stderr, "%s:%d:\n    Postgres SELECT error: %s\n",
                __FILE__, __LINE__, PQerrorMessage(s_postgres));
        PQclear(result);
        return false;
    }

    refs.resize(PQntuples(result));
    for (size_t i=0; i<refs.size(); ++i) {
        refs[i].m_parent = strtoul(PQgetvalue(result, i, 0), 0, 10);
        refs[i].m_child = strtoul(PQgetvalue(result, i, 1), 0, 10);
        refs[i].m_owner = strtoul(PQgetvalue(result, i, 2), 0, 10);
        refs[i].m_seen = strtoul(PQgetvalue(result, i, 3), 0, 10);
    }
    PQclear(result);
    return true;
}
开发者ID:Hoikas,项目名称:dirtsand,代码行数:25,代码来源:AuthVault.cpp


示例10: v_find_public_ages

bool v_find_public_ages(const DS::String& ageFilename, std::vector<Auth_PubAgeRequest::NetAgeInfo>& ages)
{
    PostgresStrings<2> parms;
    parms.set(0, DS::Vault::e_NodeAgeInfo);
    parms.set(1, ageFilename);
    // ageInfoId, Uuid, InstName, UserName, Description, SeqNumber, Language
    PGresult* result = PQexecParams(s_postgres,
                       "SELECT idx, \"Uuid_1\", \"String64_3\", \"String64_4\","
                       "    \"Text_1\",\"Int32_1\", \"Int32_3\" FROM vault.\"Nodes\""
                       "    WHERE \"NodeType\"=$1 AND \"Int32_2\"=1 AND \"String64_2\"=$2"
                       "    ORDER BY \"ModifyTime\" LIMIT 50",
                       2, 0, parms.m_values, 0, 0, 0);
    if (PQresultStatus(result) != PGRES_TUPLES_OK) {
        fprintf(stderr, "%s:%d:\n    Postgres SELECT error: %s\n",
                __FILE__, __LINE__, PQerrorMessage(s_postgres));
        PQclear(result);
        return false;
    }
    for (int i = 0; i < PQntuples(result); ++i) {
        Auth_PubAgeRequest::NetAgeInfo ai;
        ai.m_instance = DS::Uuid(PQgetvalue(result, i, 1));
        ai.m_instancename = PQgetvalue(result, i, 2);
        ai.m_username = PQgetvalue(result, i, 3);
        ai.m_description = PQgetvalue(result, i, 4);
        ai.m_sequence = strtoul(PQgetvalue(result, i, 5), 0, 10);
        ai.m_language = strtoul(PQgetvalue(result, i, 6), 0, 10);
        ai.m_curPopulation = v_count_age_population(PQgetvalue(result, i, 1));
        ai.m_population = v_count_age_owners(strtoul(PQgetvalue(result, i, 0), 0 , 10));
        ages.push_back(ai);
    }
    PQclear(result);
    return true;
}
开发者ID:Hoikas,项目名称:dirtsand,代码行数:33,代码来源:AuthVault.cpp


示例11: PQexecParams

static char *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const char *name, unsigned int *len)
{
	pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
	char *id = NULL;

	if (name == NULL) {
		if (H->pgoid == InvalidOid) {
			return NULL;
		}
		*len = spprintf(&id, 0, ZEND_LONG_FMT, (zend_long) H->pgoid);
	} else {
		PGresult *res;
		ExecStatusType status;
		const char *q[1];
		q[0] = name;
		res = PQexecParams(H->server, "SELECT CURRVAL($1)", 1, NULL, q, NULL, NULL, 0);
		status = PQresultStatus(res);

		if (res && (status == PGRES_TUPLES_OK)) {
			id = estrdup((char *)PQgetvalue(res, 0, 0));
			*len = PQgetlength(res, 0, 0);
		} else {
			pdo_pgsql_error(dbh, status, pdo_pgsql_sqlstate(res));
		}

		if (res) {
			PQclear(res);
		}
	}
	return id;
}
开发者ID:mdesign83,项目名称:php-src,代码行数:31,代码来源:pgsql_driver.c


示例12: clearSession

void clearSession()
{
	const char *conninfo;
    PGconn     *conn;
    PGresult   *res;
    conninfo = "dbname=echuraev";
	
    conn = PQconnectdb(conninfo);

    if (PQstatus(conn) != CONNECTION_OK)
    {
		printf ("Connection to database failed: %s\n", PQerrorMessage(conn));
		exit_nicely(conn);
    }
    res = PQexecParams(conn, "DELETE FROM sessions", 0, NULL, NULL, NULL, NULL, 0);
    if (PQresultStatus(res) != PGRES_COMMAND_OK)
    {
		printf ("Cannot remove old sessions: %s\n", PQerrorMessage(conn));
		PQclear(res);
        exit_nicely(conn);
    }
	
    PQclear(res);
	PQfinish(conn);
}
开发者ID:echuraev,项目名称:Distributed-Computer-Systems,代码行数:25,代码来源:im_svc.c


示例13: pgsql_exec

/**
 *  Execute a database command that has no result.
 *
 *  Error messages from this function are sent to the message
 *  handler (see msngr_init_log() and msngr_init_mail()).
 *
 *  @param  dbconn  - pointer to the database connection
 *  @param  command - command string
 *  @param  nparams - number of $1, $2, ... parameters in the command
 *  @param  params  - parameters to substitute in the command
 *
 *  @return database status:
 *    - DB_NO_ERROR
 *    - DB_ERROR
 *
 *  @see DBStatus
 */
DBStatus pgsql_exec(
    DBConn      *dbconn,
    const char  *command,
    int          nparams,
    const char **params)
{
    PGconn   *pgconn = (PGconn *)dbconn->dbh;
    PGresult *pgres;
    DBStatus  status;

    if (nparams > 0) {
        pgres = PQexecParams(
            pgconn, command, nparams, NULL, params, NULL, NULL, 0);
    }
    else {
        pgres = PQexec(pgconn, command);
    }

    if (!pgres || PQresultStatus(pgres) != PGRES_COMMAND_OK) {

        PGSQL_ERROR(dbconn, pgconn, pgres,
            "FAILED: %s\n", command);

        status = DB_ERROR;
    }
    else {
        status = DB_NO_ERROR;
    }

    if (pgres) {
        PQclear(pgres);
    }

    return(status);
}
开发者ID:ARM-DOE,项目名称:adi-macosx,代码行数:52,代码来源:dbconn_pgsql.c


示例14: PQexec

static char *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const char *name, size_t *len)
{
	pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
	char *id = NULL;
	PGresult *res;
	ExecStatusType status;

	if (name == NULL) {
		res = PQexec(H->server, "SELECT LASTVAL()");
	} else {
		const char *q[1];
		q[0] = name;

		res = PQexecParams(H->server, "SELECT CURRVAL($1)", 1, NULL, q, NULL, NULL, 0);
	}
	status = PQresultStatus(res);

	if (res && (status == PGRES_TUPLES_OK)) {
		id = estrdup((char *)PQgetvalue(res, 0, 0));
		*len = PQgetlength(res, 0, 0);
	} else {
		pdo_pgsql_error(dbh, status, pdo_pgsql_sqlstate(res));
	}

	if (res) {
		PQclear(res);
	}

	return id;
}
开发者ID:IMSoP,项目名称:php-src,代码行数:30,代码来源:pgsql_driver.c


示例15: libpqGetFile

/*
 * Receive a single file as a malloc'd buffer.
 */
char *
libpqGetFile(const char *filename, size_t *filesize)
{
	PGresult   *res;
	char	   *result;
	int			len;
	const char *paramValues[1];

	paramValues[0] = filename;
	res = PQexecParams(conn, "SELECT pg_read_binary_file($1)",
					   1, NULL, paramValues, NULL, NULL, 1);

	if (PQresultStatus(res) != PGRES_TUPLES_OK)
		pg_fatal("could not fetch remote file \"%s\": %s",
				 filename, PQresultErrorMessage(res));

	/* sanity check the result set */
	if (PQntuples(res) != 1 || PQgetisnull(res, 0, 0))
		pg_fatal("unexpected result set while fetching remote file \"%s\"\n",
				 filename);

	/* Read result to local variables */
	len = PQgetlength(res, 0, 0);
	result = pg_malloc(len + 1);
	memcpy(result, PQgetvalue(res, 0, 0), len);
	result[len] = '\0';

	PQclear(res);

	pg_log(PG_DEBUG, "fetched file \"%s\", length %d\n", filename, len);

	if (filesize)
		*filesize = len;
	return result;
}
开发者ID:winlibs,项目名称:postgresql,代码行数:38,代码来源:libpq_fetch.c


示例16: v_has_node

bool v_has_node(uint32_t parentId, uint32_t childId)
{
    if (parentId == 0)
        return false;
    if (parentId == childId)
        return true;

    PostgresStrings<2> parms;
    parms.set(0, parentId);
    parms.set(1, childId);

    check_postgres();
    PGresult* result = PQexecParams(s_postgres,
                                    "SELECT vault.has_node($1, $2)",
                                    2, 0, parms.m_values, 0, 0, 0);
    if (PQresultStatus(result) != PGRES_TUPLES_OK) {
        fprintf(stderr, "%s:%d:\n    Postgres SELECT error: %s\n",
                __FILE__, __LINE__, PQerrorMessage(s_postgres));
        PQclear(result);
        return false;
    }
    DS_DASSERT(PQntuples(result) == 1);
    bool retval = (*PQgetvalue(result, 0, 0) == 't');
    PQclear(result);
    return retval != 0;
}
开发者ID:Hoikas,项目名称:dirtsand,代码行数:26,代码来源:AuthVault.cpp


示例17: v_send_node

DS::Vault::NodeRef v_send_node(uint32_t nodeId, uint32_t playerId, uint32_t senderId)
{
    DS::Vault::NodeRef ref;
    ref.m_child = ref.m_owner = ref.m_parent = 0;
    PostgresStrings<2> parms;
    parms.set(0, playerId);
    parms.set(1, DS::Vault::e_InboxFolder);
    PGresult* result = PQexecParams(s_postgres,
            "SELECT idx FROM vault.find_folder($1, $2);",
            2, 0, parms.m_values, 0, 0, 0);
    if (PQresultStatus(result) != PGRES_TUPLES_OK) {
        fprintf(stderr, "%s:%d:\n    Postgres SELECT error: %s\n",
                __FILE__, __LINE__, PQerrorMessage(s_postgres));
        PQclear(result);
        return ref;
    }
    DS_DASSERT(PQntuples(result) == 1);
    uint32_t inbox = strtoul(PQgetvalue(result, 0, 0), 0, 10);
    PQclear(result);

    if (v_ref_node(inbox, nodeId, senderId)) {
        ref.m_child = nodeId;
        ref.m_owner = senderId;
        ref.m_parent = inbox;
    }
    return ref;
}
开发者ID:Hoikas,项目名称:dirtsand,代码行数:27,代码来源:AuthVault.cpp


示例18: cmdev_list_game

void cmdev_list_game(const struct lh_kv_elem *params, const struct lh_kv_elem *cookies, struct lh_response* resp) {
    //check auth
    cm::Session session;
    int err = cm::find_session(cookies, session);
    if (err) {
        return cm_send_error(resp, CMERR_AUTH);
	}
	
	//check param
	const char *appid = lh_kv_string(params, "appid", &err);
    if (err) {
        return cm_send_error(resp, CMERR_PARAM);
	}
	
	//check db
    PGconn *cmatchdb = cm::get_context()->cmatchdb;
    if (PQstatus(cmatchdb) != CONNECTION_OK) {
        return cm_send_error(resp, CMERR_DB);
    }
	
    //qurey db
	const int VAR_NUMS = 1;
	const char *vars[VAR_NUMS] = {
		appid,
    };
    PGresult *res = PQexecParams(cmatchdb,
                       "SELECT id, name FROM game WHERE app_id=$1;",
                       VAR_NUMS, NULL, vars, NULL, NULL, 0);
    Autofree af_res_cl(res, (Freefunc)PQclear);
	
    if (PQresultStatus(res) != PGRES_TUPLES_OK) {
        return cm_send_error(resp, CMERR_DB);
    }
    
    int rownums = PQntuples(res);
    if (rownums == 0) {
        return cm_send_ok(resp);
    }
    
    std::stringstream ssout;
    ssout << "{\"error\":0,\"games\":{";
    
    bool first = true;
    for (int i = 0; i < rownums; ++i) {
        const char* sid = PQgetvalue(res, i, 0);
        const char* sname = PQgetvalue(res, i, 1);
        if (sid && sname) {
            if (first)
                first = false;
            else
                ssout << ",";
            ssout << "\"" << sid << "\"" << ":\"" << sname << "\"";
        }
    }
    ssout << "}}";
    
    //send to client
	lh_append_body(resp, ssout.str().c_str());
}
开发者ID:henyouqian,项目名称:cmatch2,代码行数:59,代码来源:cm_dev_match.cpp


示例19: defined

PGresult *OGRPG_PQexec(PGconn *conn, const char *query, int bMultipleCommandAllowed,
                       int bErrorAsDebug)
{
    PGresult* hResult;
#if defined(PG_PRE74)
    /* PQexecParams introduced in PG >= 7.4 */
    hResult = PQexec(conn, query);
#else
    if (bMultipleCommandAllowed)
        hResult = PQexec(conn, query);
    else
        hResult = PQexecParams(conn, query, 0, NULL, NULL, NULL, NULL, 0);
#endif

#ifdef DEBUG
    const char* pszRetCode = "UNKNOWN";
    char szNTuples[32];
    szNTuples[0] = '\0';
    if (hResult)
    {
        switch(PQresultStatus(hResult))
        {
        case PGRES_TUPLES_OK:
            pszRetCode = "PGRES_TUPLES_OK";
            snprintf(szNTuples, sizeof(szNTuples), ", ntuples = %d", PQntuples(hResult));
            break;
        case PGRES_COMMAND_OK:
            pszRetCode = "PGRES_COMMAND_OK";
            break;
        case PGRES_NONFATAL_ERROR:
            pszRetCode = "PGRES_NONFATAL_ERROR";
            break;
        case PGRES_FATAL_ERROR:
            pszRetCode = "PGRES_FATAL_ERROR";
            break;
        default:
            break;
        }
    }
    if (bMultipleCommandAllowed)
        CPLDebug("PG", "PQexec(%s) = %s%s", query, pszRetCode, szNTuples);
    else
        CPLDebug("PG", "PQexecParams(%s) = %s%s", query, pszRetCode, szNTuples);
#endif

    /* -------------------------------------------------------------------- */
    /*      Generate an error report if an error occurred.                  */
    /* -------------------------------------------------------------------- */
    if ( !hResult || (PQresultStatus(hResult) == PGRES_NONFATAL_ERROR ||
                      PQresultStatus(hResult) == PGRES_FATAL_ERROR ) )
    {
        if( bErrorAsDebug )
            CPLDebug("PG", "%s", PQerrorMessage( conn ) );
        else
            CPLError( CE_Failure, CPLE_AppDefined, "%s", PQerrorMessage( conn ) );
    }

    return hResult;
}
开发者ID:drons,项目名称:gdal,代码行数:59,代码来源:ogrpgutility.cpp


示例20: cmdev_add_match

void cmdev_add_match(const struct lh_kv_elem *params, const struct lh_kv_elem *cookies, struct lh_response* resp) {
    //check auth
    cm::Session session;
    int err = cm::find_session(cookies, session);
    if (err) {
        return cm_send_error(resp, CMERR_AUTH);
	}
    
    //parse param
	const char *appid = lh_kv_string(params, "appid", &err);
	const char *gameid = lh_kv_string(params, "gameid", &err);
	const char *begin = lh_kv_string(params, "begin", &err);
	const char *end = lh_kv_string(params, "end", &err);
	const char *matchname = lh_kv_string(params, "matchname", NULL);
	if (matchname && matchname[0] == 0) {
		matchname = NULL;
	}
    if (err) {
        return cm_send_error(resp, CMERR_PARAM);
	}

	//check db
    PGconn *cmatchdb = cm::get_context()->cmatchdb;
    if (PQstatus(cmatchdb) != CONNECTION_OK) {
        return cm_send_error(resp, CMERR_DB);
    }
	
    //insert into db
	const int VAR_NUMS = 6;
    const char *vars[VAR_NUMS] = {
		matchname,
		gameid,
		appid,
		session.userid.c_str(),
		begin,
		end,
    };
	PGresult *res = PQexecParams(cmatchdb,
								 "INSERT INTO match (name, game_id, app_id, developer_id, begin_time, end_time) "
								 "SELECT $1, $2, $3, $4, $5::TIMESTAMP, $6::TIMESTAMP "
									"WHERE $4=(SELECT developer_id FROM game WHERE id=$2) "
										"AND $3=(SELECT app_id FROM game WHERE id=$2) "
										"AND $5::TIMESTAMP<$6::TIMESTAMP "
								 "RETURNING id;",
								 VAR_NUMS, NULL, vars, NULL, NULL, 0);
    Autofree af_res_insert(res, (Freefunc)PQclear);
    if (PQresultStatus(res) != PGRES_TUPLES_OK){
        return cm_send_error(resp, CMERR_DB);
    }

    //get match id
    const char* matchid = PQgetvalue(res, 0, 0);
    if (matchid == NULL) {
        return cm_send_error(resp, CMERR_DB);
    }
    
    //send to client
	lh_appendf_body(resp, "{\"error\":0, \"matchid\":%s}", matchid);
}
开发者ID:henyouqian,项目名称:cmatch2,代码行数:59,代码来源:cm_dev_match.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PQexecPrepared函数代码示例发布时间:2022-05-30
下一篇:
C++ PQexec函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap