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


C++ db_query函数代码示例

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


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

示例1: takeover_cave

static void takeover_cave(db_t *database,
		   int    cave_id,
		   int    attacker_id,
		   const char   *return_start)
{
  /* change owner of cave */
  db_query(database, "UPDATE " DB_TABLE_CAVE " SET playerID = %d"
		     " WHERE caveID = %d", attacker_id, cave_id);

  dstring_t *ds;
  ds = dstring_new("UPDATE Event_movement SET target_caveID = source_caveID, ");
  dstring_append(ds, "end = addtime('%s',timediff('%s',start)), ",return_start,return_start);
  dstring_append(ds, "start='%s', ",return_start);
  dstring_append(ds, "movementID = 5 where caveID = %d and caveID = source_caveID",cave_id);
  debug(DEBUG_SQL, "Torben %s", dstring_str(ds));
  db_query_dstring(database, ds);


  /* delete research from event table*/
  db_query(database, "DELETE FROM Event_science WHERE caveID = %d", cave_id);

  /* copy sciences from new owner to cave */
  science_update_caves(database, attacker_id);
}
开发者ID:agatho,项目名称:uaenhanced,代码行数:24,代码来源:movement_handler.c

示例2: DBConnectionUp

int DBConnectionUp()
{
	mysql_init(&db_read_connection);
	mysql_init(&db_write_connection);
	mysql_init(&payguide::db_checkreqs_connection);
	MYSQL *tmp1=mysql_real_connect(&db_read_connection, payguide::host_saved.c_str(), payguide::user_saved.c_str(), payguide::passwor_saved.c_str(), payguide::db_name_saved.c_str(), 0, NULL, 0);
	MYSQL *tmp2=mysql_real_connect(&db_write_connection, payguide::host_saved.c_str(), payguide::user_saved.c_str(), payguide::passwor_saved.c_str(), payguide::db_name_saved.c_str(), 0, NULL, 0);
	MYSQL *tmp3=mysql_real_connect(&payguide::db_checkreqs_connection, payguide::host_saved.c_str(), payguide::user_saved.c_str(), payguide::passwor_saved.c_str(), payguide::db_name_saved.c_str(), 0, NULL, 0);
	
		if (tmp1==NULL || tmp2==NULL || tmp3==NULL)
		{
			std::cout << "MySQL connection failed. Please, check out login, password, host and database name options." << std::endl;
			return 2;
		}
	
	int r=db_query(&db_write_connection, "set names koi8r");
	r=r+db_query(&db_read_connection, "set names koi8r");
	r=r+db_query(&payguide::db_checkreqs_connection, "set names koi8r");
	if (r!=0) 
		std::cout << "Failed to execute SQL comand: \"set names koi8r\"" << std::endl;

	db_down=0;
	return 0;
}
开发者ID:s-alexander,项目名称:UPGM,代码行数:24,代码来源:db.cpp

示例3: db_reports_get_list

CWERROR db_reports_get_list(CW_DB_CONNECTION *db,
                            CW_REPORT **rlist,
                            CW_UINT32 *count)
{
	static const char query[] = "SELECT rid,sid,uid,datetime(add_dt,'localtime'),code FROM reports ORDER BY add_dt COLLATE NOCASE DESC";
	    
    CW_DB_RESULT       res;
	CW_DB_RESULT_ROW   *row;
	CW_REPORT          *list = NULL;
	CW_UINT32          n, i = 0;
	CWERROR	           err = CW_ER_OK;

	if ((err = db_query(db, &res, query, sizeof(query)-1, NULL, 0)) != CW_ER_OK) {
        DEBUG_ERROR();
        db_result_free(&res);
        return err;
    }

    if ((n = *count = DB_RESULT_ROW_COUNT(res)) == 0) {
        db_result_free(&res);
        return CW_ER_OK;
    }

    if ((list = *rlist = DLL_MALLOC(sizeof(CW_REPORT) * n)) == NULL) {
		DEBUG_ERROR();
		db_result_free(&res);
		return CW_ER_MEMORY;
	}

	row = DB_RESULT_ROW_FIRST(res);
	do {
        list[i].rid = DB_RESULT_AS_INT64(row, 0);
        list[i].pckt.rcpt_sid = (CW_UINT32)DB_RESULT_AS_INT64(row, 1);
        list[i].pckt.rcpt_uid = (CW_UINT32)DB_RESULT_AS_INT64(row, 2);
        if (strcpy_s(list[i].add_dt, DB_RESULT_AS_TEXT(row, 3), sizeof(list[i].add_dt)) == NULL) {
            DEBUG_ERROR();
            DLL_FREE(list);
            db_result_free(&res);
            return CW_ER_INTERNAL;
        }
	    list[i].pckt.code = (CW_UINT32)DB_RESULT_AS_INT64(row, 4);
        ++i;
    } while (((row = DB_RESULT_ROW_NEXT(row)) != NULL) && (--n));

    db_result_free(&res);

    return CW_ER_OK;
}
开发者ID:isaachoward,项目名称:CWCLI,代码行数:48,代码来源:query.c

示例4: process_trust_0002

static void process_trust_0002(const char * string, const jsmntok_t * tokens, const int index)
{
   char query[1024];
   char train_id[128], reason[128], type[128], stanox[128];
   
   jsmn_find_extract_token(string, tokens, index, "train_id", train_id, sizeof(train_id));
   jsmn_find_extract_token(string, tokens, index, "canx_reason_code", reason, sizeof(reason));
   jsmn_find_extract_token(string, tokens, index, "canx_type", type, sizeof(type));
   jsmn_find_extract_token(string, tokens, index, "loc_stanox", stanox, sizeof(stanox));

   time_t now = time(NULL);
   sprintf(query, "INSERT INTO trust_cancellation VALUES(%ld, '%s', '%s', '%s', '%s', 0)", now, train_id, reason, type, stanox);
   db_query(query);
   
   return;
}
开发者ID:proffalken,项目名称:openrail,代码行数:16,代码来源:trustdb.c

示例5: db_insert

int db_insert(char *data) {
	int value;
	char *sqlquery;
	
	sqlquery = sqlite3_mprintf(
		"INSERT INTO notifications (timestamp, read, message) "
		"VALUES (%u, 0, '%q')",
		time(NULL),
		data
	);
	
	value = db_query(db, sqlquery);	
	sqlite3_free(sqlquery);
	
	return value;
}
开发者ID:maxux,项目名称:easynotif,代码行数:16,代码来源:notif.c

示例6: get_player_info

/*
 * Retrieve player table information for the given player id.
 */
void get_player_info (db_t *database, int player_id, struct Player *player)
{
  db_result_t *result = db_query(database,
	"SELECT * FROM " DB_TABLE_PLAYER " WHERE playerID = %d", player_id);

  if (!db_result_next_row(result))
    throwf(SQL_EXCEPTION, "get_player_info: player %d not found", player_id);

  player->player_id = player_id;
  player->name = db_result_get_string(result, "name");
  player->tribe = db_result_get_string(result, "tribe");
  player->max_caves = db_result_get_int(result, "takeover_max_caves");
  player->locale = db_result_get_string(result, "language");
  player->locale_id = get_locale_id(player->locale);
  get_science_list(result, player->science);
}
开发者ID:zu-gabe,项目名称:Game,代码行数:19,代码来源:cave.c

示例7: ul_db_query

int ul_db_query(str * table, str * first, str * second, db1_con_t *** _r_h, 
				db_key_t* _k, db_op_t* _op,	db_val_t* _v,
                db_key_t* _c, int _n, int _nc,	db_key_t _o, db1_res_t** _r) {
	ul_db_handle_t * handle;
	db_func_t * f;
	int ret;
	if((handle = get_handle(&mdb.read.dbf, mdb.read.dbh, first, second)) == NULL) {
		LM_ERR("could not retrieve db handle.\n");
		return -1;
	}
	if((ret = db_query(handle, _r_h, &f, table, _k, _op, _v, _c, _n, _nc, _o, _r, db_master_write)) < 0){
		return ret;
	}
	add_dbf(*_r, f);
	return ret;
}
开发者ID:mattvv,项目名称:kamailio,代码行数:16,代码来源:ul_db.c

示例8: snprintf

bool DBPermObj::AddToWhitelist(std::string & dbuser, std::string & pattern)
{
    char * q = new char [ pattern.length() + 1024 ];
    db_struct db;

    snprintf(q, pattern.length() + 1024,
        "SELECT queryid FROM query WHERE "
        "proxyid = %d and db_name = '%s' and query = '%s'",
        proxy_id, db_name.c_str(), pattern.c_str());

    /* read new queryid from the database */
    if (! db_query(&db, q ,pattern.length() + 1024)) {
        /* Failed */
        logevent(STORAGE,"DB config erorr: %s\n",db_error());
        delete [] q;
        db_cleanup(&db);
        return false;
    } 

    /* Download result from server */
    if (db_fetch_row(&db))
    {
        // nothing to do here, query is aready in whitelist
        delete [] q;
        db_cleanup(&db);
        return true;
    }

    // add pattern to the whitelist
    snprintf(q, pattern.length() + 1024,
       "INSERT into query "
       "(proxyid, perm, db_name, query) "
       "VALUES (%d,1,'%s','%s')",
       proxy_id, db_name.c_str(), pattern.c_str());

    /* read new urls from the database */
    if (! db_exec(q)) {
        /* Make query */
        logevent(STORAGE,"DB config erorr: %s\n",db_error());
        delete [] q;
        return false;
    }
    delete [] q;
    q = NULL;

    return true;
}
开发者ID:Avanznow,项目名称:greensql-fw,代码行数:47,代码来源:dbpermobj.cpp

示例9: do_migrate

int do_migrate(int migrate_limit)
{
	C c; R r;
	int id = 0;
	int count = 0;
	DbmailMessage *m;
	
	qprintf ("Mirgrate legacy 2.2.x messageblks to mimeparts...\n");
	if (!yes_to_all) {
		qprintf ("\tmigration skipped. Use -y option to perform mirgration.\n");
		return 0;
	}
	qprintf ("Preparing to migrate %d physmessages.\n", migrate_limit);

	c = db_con_get();
	TRY
		r = db_query(c, "SELECT DISTINCT(physmessage_id) FROM %smessageblks LIMIT %d", DBPFX, migrate_limit);
		qprintf ("Migrating %d physmessages...\n", migrate_limit);
		while (db_result_next(r))
		{
			count++;
			id = db_result_get_u64(r,0);
			m = dbmail_message_new();
			m = dbmail_message_retrieve(m, id, DBMAIL_MESSAGE_FILTER_FULL);
			if(!dm_message_store(m))
			{
				if(verbose) qprintf ("%d ",id);
				db_update("DELETE FROM %smessageblks WHERE physmessage_id = %d", DBPFX, id);
			}
			else
			{
				if(!verbose) qprintf ("migrating physmessage_id: %d\n",id);
				qprintf ("failed\n");
				return -1;
			}
			dbmail_message_free(m);
		}
	CATCH(SQLException)
		LOG_SQLERROR;
		return -1;
	FINALLY
		db_con_close(c);
	END_TRY;
	
	qprintf ("Migration complete. Migrated %d physmessages.\n", count);
	return 0;
}
开发者ID:skrapsrwt,项目名称:dbmail-memcache,代码行数:47,代码来源:maintenance.c

示例10: db_getserver

/* serv should be db_escape'd before call */
int db_getserver(char *serv)
{
#ifdef HASHLISTSUPPORT
	strtolwr(serv);
	return hash_find(hashservs, serv, KEYOTHER);
#else
	MYSQL_RES *resptr;
	int res = 0;

	db_query("SELECT servid FROM " TBL_SERV " WHERE server=\'%s\'", serv);
	resptr = mysql_store_result(myptr);
	if (mysql_num_rows(resptr))
		res = atoi(*mysql_fetch_row(resptr));
	mysql_free_result(resptr);
	return res;
#endif
}
开发者ID:GeekShed,项目名称:gs-thales,代码行数:18,代码来源:db.c

示例11: get_monster_info

/*
 * Retrieve monster table information for the given monster id.
 */
void get_monster_info (db_t *database, int monster_id, struct Monster *monster)
{
  db_result_t *result = db_query(database,
	"SELECT * FROM Monster WHERE monsterID = %d", monster_id);

  if (!db_result_next_row(result))
    throwf(SQL_EXCEPTION, "get_monster_info: monster %d not found", monster_id);

  monster->monster_id = monster_id;
  monster->name = db_result_get_string(result, "name");
  monster->attack = db_result_get_int(result, "angriff");
  monster->defense = db_result_get_int(result, "verteidigung");
  monster->mental = db_result_get_int(result, "mental");
  monster->strength = db_result_get_int(result, "koerperkraft");
  monster->exp_value = db_result_get_int(result, "erfahrung");
  monster->attributes = db_result_get_string(result, "eigenschaft");
}
开发者ID:zu-gabe,项目名称:Game,代码行数:20,代码来源:cave.c

示例12: db_query_silent

t_max_err db_query_silent(t_database *db, t_db_result **dbresult, const char *s, ...)
{
	char		sql[DATABASE_SQL_MAXLEN+2];
	va_list		ap;
	long		logging = false;
	t_max_err	err;

	va_start(ap, s);
	vsnprintf(sql, DATABASE_SQL_MAXLEN, s, ap);
	sql[DATABASE_SQL_MAXLEN] = '\0';

	logging = object_attr_getlong(db, _sym_log);
	object_attr_setlong(db, _sym_log, 0);
	err = db_query(db, dbresult, sql, NULL);
	object_attr_setlong(db, _sym_log, logging);
	return err;
}
开发者ID:Alfpercar,项目名称:MaxMSPExternals,代码行数:17,代码来源:ext_database.c

示例13: assert

long CDataObject::GetData(CDatabase* p_db)
{
	/*
		Fills the data array and returns the number of points inserted
	*/

	assert(m_br >= ePreflopIndex && m_br < eRoundIndices);
	assert(m_nacted >= 0);

	std::string query_str = CDatabaseInterface::ConstructSelectQueryString(m_br, m_nacted, m_ndealt, m_action);

	//p_db->CheckDB(br_ndx, times_acted);
	CDatabaseQuery db_query(p_db);
	db_query.Select(query_str.c_str());

	// Get the actual values
	for(int p = 0; p < db_query.get_numrows(); p++)
	{
		// save address for ann
		m_data[p] = m_points.row(p).data();
		// save hand_id
		m_hand_ids[p] = atoi(PQgetvalue(db_query.get_pgresult(), p, 0));
		// FIX ME - profit should be a part of the select query
		bool profit_ok = CDatabaseInterface::GetProfit(m_hand_ids[p], m_profits(p), p_db);

		// prefix every row with 1's for teh intercept
		m_points(p, 0) = 1.0;
		for(int column = 1; column < db_query.get_numcolumns(); column++)
		{
			double tmp = atof(PQgetvalue(db_query.get_pgresult(), p, column));
			m_points(p, column) = tmp;
		}

		#if defined DEBUG_ALIGN
			if(row < 10)
			{
				double progress_percent = ((m_npoints > 0) ? ((100.0 * (row+1))/m_npoints) : 0.0);
				gLog.WriteLogNoHeading(eSeverityInfo, eCatANN, "Data Point : %d/%d [%.2lf %%] - %s\n", 
														row+1, m_npoints, progress_percent, PrintPtStr(m_points.row(row).data(), m_ndims).c_str());
			}
		#endif
	}

	return db_query.get_numrows();
}
开发者ID:strikles,项目名称:poker,代码行数:45,代码来源:CData.cpp

示例14: get_relation_info

/*
 * Retrieve relation table information for the given tribe and tribe_target.
 */
int get_relation_info (db_t *database, const char *tribe,
		       const char *tribe_target, struct Relation *relation)
{
  db_result_t *result = NULL;

  if (tribe && tribe_target)
  {
    debug(DEBUG_BATTLE, "get relation for tribes %s %s", tribe, tribe_target);
    result = db_query(database,
	"SELECT * FROM " DB_TABLE_RELATION
	" WHERE tribe = '%s' AND tribe_target = '%s'", tribe, tribe_target);
  }

  if (!result || !db_result_next_row(result))
  {
    debug(DEBUG_BATTLE, "filling dummy relation");
    relation->relation_id = 0;
    relation->tribe = tribe;
    relation->tribe_target = tribe_target;
    relation->relationType = RELATION_TYPE_NONE;

    /* FIXME these values should be read from relation types */
    relation->attackerMultiplicator = 0.5;
    relation->defenderMultiplicator = 1.0;
    relation->attackerReceivesFame = 0;
    relation->defenderReceivesFame = 0;

    return 0;	/* no relation entry */
  }

  relation->relation_id = db_result_get_int(result, "relationID");
  relation->tribe = tribe;
  relation->tribe_target = tribe_target;
  relation->relationType = db_result_get_int(result, "relationType");
  relation->defenderMultiplicator =
    db_result_get_double(result, "defenderMultiplicator");
  relation->attackerMultiplicator =
    db_result_get_double(result, "attackerMultiplicator");
  relation->defenderReceivesFame =
    db_result_get_int(result, "defenderReceivesFame");
  relation->attackerReceivesFame =
    db_result_get_int(result, "attackerReceivesFame");

  return 1;
}
开发者ID:zu-gabe,项目名称:Game,代码行数:48,代码来源:cave.c

示例15: while

void *reset(void *dummy) {
	while(1) {
		// waiting user input
		getchar();
		split();

		// reset black color
		bkgd(COLOR_PAIR(2));
		refresh();

		newmessage = 0;
		
		// mark all as read
		db_query(db, "UPDATE notifications SET read = 1");
	}
	
	return dummy;
}
开发者ID:maxux,项目名称:easynotif,代码行数:18,代码来源:notif.c


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