本文整理汇总了C++中StringBuf_Value函数的典型用法代码示例。如果您正苦于以下问题:C++ StringBuf_Value函数的具体用法?C++ StringBuf_Value怎么用?C++ StringBuf_Value使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StringBuf_Value函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: auction_save
void auction_save(struct auction_data *auction)
{
int j;
StringBuf buf;
SqlStmt* stmt;
if( !auction )
return;
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "UPDATE `%s` SET `seller_id` = '%d', `seller_name` = ?, `buyer_id` = '%d', `buyer_name` = ?, `price` = '%d', `buynow` = '%d', `hours` = '%d', `timestamp` = '%lu', `nameid` = '%hu', `item_name` = ?, `type` = '%d', `refine` = '%d', `attribute` = '%d'",
schema_config.auction_db, auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, (unsigned long)auction->timestamp, auction->item.nameid, auction->type, auction->item.refine, auction->item.attribute);
for( j = 0; j < MAX_SLOTS; j++ )
StringBuf_Printf(&buf, ", `card%d` = '%hu'", j, auction->item.card[j]);
StringBuf_Printf(&buf, " WHERE `auction_id` = '%d'", auction->auction_id);
stmt = SqlStmt_Malloc(sql_handle);
if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, auction->seller_name, strnlen(auction->seller_name, NAME_LENGTH))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, auction->buyer_name, strnlen(auction->buyer_name, NAME_LENGTH))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_STRING, auction->item_name, strnlen(auction->item_name, ITEM_NAME_LENGTH))
|| SQL_SUCCESS != SqlStmt_Execute(stmt) )
{
SqlStmt_ShowDebug(stmt);
}
SqlStmt_Free(stmt);
StringBuf_Destroy(&buf);
}
示例2: chmapif_parse_req_saveskillcooldown
//Request to save skill cooldown data
int chmapif_parse_req_saveskillcooldown(int fd){
if( RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2) )
return 0;
else {
int count, aid, cid;
aid = RFIFOL(fd,4);
cid = RFIFOL(fd,8);
count = RFIFOW(fd,12);
if( count > 0 )
{
struct skill_cooldown_data data;
StringBuf buf;
int i;
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "INSERT INTO `%s` (`account_id`, `char_id`, `skill`, `tick`) VALUES ", schema_config.skillcooldown_db);
for( i = 0; i < count; ++i )
{
memcpy(&data,RFIFOP(fd,14+i*sizeof(struct skill_cooldown_data)),sizeof(struct skill_cooldown_data));
if( i > 0 )
StringBuf_AppendStr(&buf, ", ");
StringBuf_Printf(&buf, "('%d','%d','%d','%d')", aid, cid, data.skill_id, data.tick);
}
if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
Sql_ShowDebug(sql_handle);
StringBuf_Destroy(&buf);
}
RFIFOSKIP(fd, RFIFOW(fd, 2));
}
return 1;
}
示例3: itemdb_save_serials
void itemdb_save_serials(void)
{
struct item_data *id;
StringBuf buf;
int count = 0, i;
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "REPLACE INTO `item_serials` (`nameid`, `serial`) VALUES ");
for( i = 0; i < ARRAYLENGTH(itemdb_array); i++ )
{
id = itemdb_array[i];
if( id == NULL || itemdb_isstackable2(id) || id->last_serial == 0 || !id->changed )
continue;
if( count )
StringBuf_AppendStr(&buf, ",");
StringBuf_Printf(&buf, "('%d','%u')", id->nameid, id->last_serial);
id->changed = false;
count++;
}
if( count && SQL_ERROR == Sql_QueryStr(mmysql_handle, StringBuf_Value(&buf)) )
Sql_ShowDebug(mmysql_handle);
StringBuf_Destroy(&buf);
return;
}
示例4: auction_create
unsigned int auction_create(struct auction_data *auction)
{
int j;
StringBuf buf;
SqlStmt* stmt;
if( !auction )
return false;
auction->timestamp = time(NULL) + (auction->hours * 3600);
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "INSERT INTO `%s` (`seller_id`,`seller_name`,`buyer_id`,`buyer_name`,`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`,`unique_id`", auction_db);
for( j = 0; j < MAX_SLOTS; j++ )
StringBuf_Printf(&buf, ",`card%d`", j);
StringBuf_Printf(&buf, ") VALUES ('%d',?,'%d',?,'%d','%d','%d','%lu','%d',?,'%d','%d','%d','%"PRIu64"'",
auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, (unsigned long)auction->timestamp, auction->item.nameid, auction->type, auction->item.refine, auction->item.attribute, auction->item.unique_id);
for( j = 0; j < MAX_SLOTS; j++ )
StringBuf_Printf(&buf, ",'%d'", auction->item.card[j]);
StringBuf_AppendStr(&buf, ")");
//Unique Non Stackable Item ID
updateLastUid(auction->item.unique_id);
dbUpdateUid(sql_handle);
stmt = SqlStmt_Malloc(sql_handle);
if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, auction->seller_name, strnlen(auction->seller_name, NAME_LENGTH))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, auction->buyer_name, strnlen(auction->buyer_name, NAME_LENGTH))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_STRING, auction->item_name, strnlen(auction->item_name, ITEM_NAME_LENGTH))
|| SQL_SUCCESS != SqlStmt_Execute(stmt) )
{
SqlStmt_ShowDebug(stmt);
auction->auction_id = 0;
}
else
{
struct auction_data *auction_;
unsigned int tick = auction->hours * 3600000;
auction->item.amount = 1;
auction->item.identify = 1;
auction->item.expire_time = 0;
auction->auction_id = (unsigned int)SqlStmt_LastInsertId(stmt);
auction->auction_end_timer = add_timer( gettick() + tick , auction_end_timer, auction->auction_id, 0);
ShowInfo("New Auction %u | time left %u ms | By %s.\n", auction->auction_id, tick, auction->seller_name);
CREATE(auction_, struct auction_data, 1);
memcpy(auction_, auction, sizeof(struct auction_data));
idb_put(auction_db_, auction_->auction_id, auction_);
}
SqlStmt_Free(stmt);
StringBuf_Destroy(&buf);
return auction->auction_id;
}
示例5: SqlStmt_ShowDebug_
/// Shows debug information (with statement).
void SqlStmt_ShowDebug_(SqlStmt* self, const char* debug_file, const unsigned long debug_line)
{
if( self == NULL )
ShowDebug("at %s:%lu - self is NULL\n", debug_file, debug_line);
else if( StringBuf_Length(&self->buf) > 0 )
ShowDebug("at %s:%lu - %s\n", debug_file, debug_line, StringBuf_Value(&self->buf));
else
ShowDebug("at %s:%lu\n", debug_file, debug_line);
}
示例6: mail_loadmessage
/// Retrieves a single message from the database.
/// Returns true if the operation succeeds (or false if it fails).
static bool mail_loadmessage(int mail_id, struct mail_message* msg)
{
int j;
StringBuf buf;
StringBuf_Init(&buf);
StringBuf_AppendStr(&buf, "SELECT `id`,`send_name`,`send_id`,`dest_name`,`dest_id`,`title`,`message`,`time`,`status`,"
"`zeny`,`amount`,`nameid`,`refine`,`attribute`,`identify`, `serial`");
for( j = 0; j < MAX_SLOTS; j++ )
StringBuf_Printf(&buf, ",`card%d`", j);
StringBuf_Printf(&buf, " FROM `%s` WHERE `id` = '%d'", mail_db, mail_id);
if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf))
|| SQL_SUCCESS != Sql_NextRow(sql_handle) )
{
Sql_ShowDebug(sql_handle);
Sql_FreeResult(sql_handle);
StringBuf_Destroy(&buf);
return false;
}
else
{
char* data;
Sql_GetData(sql_handle, 0, &data, NULL); msg->id = atoi(data);
Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(msg->send_name, data, NAME_LENGTH);
Sql_GetData(sql_handle, 2, &data, NULL); msg->send_id = atoi(data);
Sql_GetData(sql_handle, 3, &data, NULL); safestrncpy(msg->dest_name, data, NAME_LENGTH);
Sql_GetData(sql_handle, 4, &data, NULL); msg->dest_id = atoi(data);
Sql_GetData(sql_handle, 5, &data, NULL); safestrncpy(msg->title, data, MAIL_TITLE_LENGTH);
Sql_GetData(sql_handle, 6, &data, NULL); safestrncpy(msg->body, data, MAIL_BODY_LENGTH);
Sql_GetData(sql_handle, 7, &data, NULL); msg->timestamp = atoi(data);
Sql_GetData(sql_handle, 8, &data, NULL); msg->status = (mail_status)atoi(data);
Sql_GetData(sql_handle, 9, &data, NULL); msg->zeny = atoi(data);
Sql_GetData(sql_handle,10, &data, NULL); msg->item.amount = (short)atoi(data);
Sql_GetData(sql_handle,11, &data, NULL); msg->item.nameid = atoi(data);
Sql_GetData(sql_handle,12, &data, NULL); msg->item.refine = atoi(data);
Sql_GetData(sql_handle,13, &data, NULL); msg->item.attribute = atoi(data);
Sql_GetData(sql_handle,14, &data, NULL); msg->item.identify = atoi(data);
Sql_GetData(sql_handle,15, &data, NULL); msg->item.serial = (unsigned int)atol(data);
msg->item.expire_time = 0;
msg->item.bound = 0;
msg->item.favorite = 0;
for( j = 0; j < MAX_SLOTS; j++ )
{
Sql_GetData(sql_handle,16 + j, &data, NULL);
msg->item.card[j] = atoi(data);
}
}
StringBuf_Destroy(&buf);
Sql_FreeResult(sql_handle);
return true;
}
示例7: Sql_ShowDebug_
void Sql_ShowDebug_(Sql_t* self, const char* debug_file, const unsigned long debug_line)
{
if( StringBuf_Length(&self->buf) > 0 )
{
ShowDebug("at %s:%lu - %s\n", debug_file, debug_line, StringBuf_Value(&self->buf));
}
else
{
ShowDebug("at %s:%lu\n", debug_file, debug_line);
}
}
示例8: guild_storage_fromsql
/// Load guild_storage data to mem
int guild_storage_fromsql(int guild_id, struct guild_storage* p)
{
StringBuf buf;
struct item* item;
char* data;
int i;
int j;
memset(p, 0, sizeof(struct guild_storage)); //clean up memory
p->storage_amount = 0;
p->guild_id = guild_id;
// storage {`guild_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`}
StringBuf_Init(&buf);
StringBuf_AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`");
for( j = 0; j < MAX_SLOTS; ++j )
StringBuf_Printf(&buf, ",`card%d`", j);
StringBuf_Printf(&buf, " FROM `%s` WHERE `guild_id`='%d' ORDER BY `nameid`", guild_storage_db, guild_id);
if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) )
Sql_ShowDebug(sql_handle);
StringBuf_Destroy(&buf);
for( i = 0; i < MAX_GUILD_STORAGE && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i )
{
item = &p->items[i];
Sql_GetData(sql_handle, 0, &data, NULL);
item->id = atoi(data);
Sql_GetData(sql_handle, 1, &data, NULL);
item->nameid = atoi(data);
Sql_GetData(sql_handle, 2, &data, NULL);
item->amount = atoi(data);
Sql_GetData(sql_handle, 3, &data, NULL);
item->equip = atoi(data);
Sql_GetData(sql_handle, 4, &data, NULL);
item->identify = atoi(data);
Sql_GetData(sql_handle, 5, &data, NULL);
item->refine = atoi(data);
Sql_GetData(sql_handle, 6, &data, NULL);
item->attribute = atoi(data);
item->expire_time = 0;
for( j = 0; j < MAX_SLOTS; ++j )
{
Sql_GetData(sql_handle, 7+j, &data, NULL);
item->card[j] = atoi(data);
}
}
p->storage_amount = i;
Sql_FreeResult(sql_handle);
ShowInfo("guild storage load complete from DB - id: %d (total: %d)\n", guild_id, p->storage_amount);
return 0;
}
示例9: Sql_QueryV
int32 Sql_QueryV(Sql_t* self, const char* query, va_list args)
{
if( self == NULL )
return SQL_ERROR;
Sql_FreeResult(self);
StringBuf_Clear(&self->buf);
StringBuf_Vprintf(&self->buf, query, args);
if( mysql_real_query(&self->handle, StringBuf_Value(&self->buf), (uint32)StringBuf_Length(&self->buf)) )
{
ShowSQL("DB error - %s\n", mysql_error(&self->handle));
ShowSQL("Query: %s\n", StringBuf_Value(&self->buf));
return SQL_ERROR;
}
self->result = mysql_store_result(&self->handle);
if( mysql_errno(&self->handle) != 0 )
{
ShowSQL("DB error - %s\n", mysql_error(&self->handle));
ShowSQL("Query: %s\n", StringBuf_Value(&self->buf));
return SQL_ERROR;
}
return SQL_SUCCESS;
}
示例10: instance_enter_position
/*==========================================
* Warp a user into instance
*------------------------------------------*/
int instance_enter_position(struct map_session_data *sd, const char *name, short x, short y)
{
struct instance_data *im;
struct instance_db *db = instance_searchname_db(name);
struct party_data *p;
int m;
nullpo_retr(-1, sd);
// Character must be in instance party
if(sd->status.party_id == 0)
return 1;
if((p = party_search(sd->status.party_id)) == NULL)
return 1;
// Party must have an instance
if(p->instance_id == 0)
return 2;
if(db == NULL)
return 3;
im = &instance_data[p->instance_id];
if(im->party_id != p->party.party_id)
return 3;
if(im->state != INSTANCE_BUSY)
return 3;
if(im->type != db->id)
return 3;
// Does the instance match?
if((m = instance_mapname2mapid(StringBuf_Value(db->enter.mapname), p->instance_id)) < 0)
return 3;
if(pc_setpos(sd, map_id2index(m), x, y, CLR_OUTSIGHT))
return 3;
// If there was an idle timer, let's stop it
instance_stopidletimer(im);
// Now we start the instance timer
instance_startkeeptimer(im, p->instance_id);
return 0;
}
示例11: ext_storage_fromsql
// DB -> storage data conversion
int ext_storage_fromsql(int account_id, struct extra_storage_data *p)
{
StringBuf buf;
struct item* item;
char* data;
int i;
int j;
memset(p, 0, sizeof(struct extra_storage_data)); //clean up memory
p->storage_amount = 0;
// storage {`account_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`}
StringBuf_Init(&buf);
StringBuf_AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`expire_time`,`unique_id`,`bound`");
for( j = 0; j < MAX_SLOTS; ++j )
StringBuf_Printf(&buf, ",`card%d`", j);
StringBuf_Printf(&buf, " FROM `%s` WHERE `account_id`='%d' ORDER BY `nameid`", rentstorage_db, account_id);
if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) )
Sql_ShowDebug(sql_handle);
StringBuf_Destroy(&buf);
for( i = 0; i < MAX_EXTRA_STORAGE && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i )
{
item = &p->items[i];
Sql_GetData(sql_handle, 0, &data, NULL); item->id = atoi(data);
Sql_GetData(sql_handle, 1, &data, NULL); item->nameid = atoi(data);
Sql_GetData(sql_handle, 2, &data, NULL); item->amount = atoi(data);
Sql_GetData(sql_handle, 3, &data, NULL); item->equip = atoi(data);
Sql_GetData(sql_handle, 4, &data, NULL); item->identify = atoi(data);
Sql_GetData(sql_handle, 5, &data, NULL); item->refine = atoi(data);
Sql_GetData(sql_handle, 6, &data, NULL); item->attribute = atoi(data);
Sql_GetData(sql_handle, 7, &data, NULL); item->expire_time = (unsigned int)atoi(data);
Sql_GetData(sql_handle, 8, &data, NULL); item->unique_id = strtoull(data, NULL, 10);
Sql_GetData(sql_handle, 9, &data, NULL); item->bound = atoi(data);
for( j = 0; j < MAX_SLOTS; ++j )
{
Sql_GetData(sql_handle, 10+j, &data, NULL); item->card[j] = atoi(data);
}
}
p->storage_amount = i;
Sql_FreeResult(sql_handle);
ShowInfo("rentstorage load complete from DB - id: %d (total: %d)\n", account_id, p->storage_amount);
return 1;
}
示例12: SqlStmt_PrepareStr
/// Prepares the statement.
int SqlStmt_PrepareStr(SqlStmt* self, const char* query)
{
if( self == NULL )
return SQL_ERROR;
SqlStmt_FreeResult(self);
StringBuf_Clear(&self->buf);
StringBuf_AppendStr(&self->buf, query);
if( mysql_stmt_prepare(self->stmt, StringBuf_Value(&self->buf), (unsigned long)StringBuf_Length(&self->buf)) )
{
ShowSQL("DB error - %s\n", mysql_stmt_error(self->stmt));
return SQL_ERROR;
}
self->bind_params = false;
return SQL_SUCCESS;
}
示例13: SqlStmt_PrepareV
/// Prepares the statement.
int SqlStmt_PrepareV(SqlStmt* self, const char* query, va_list args)
{
if( self == NULL )
return SQL_ERROR;
SqlStmt_FreeResult(self);
StringBuf_Clear(&self->buf);
StringBuf_Vprintf(&self->buf, query, args);
if( mysql_stmt_prepare(self->stmt, StringBuf_Value(&self->buf), (unsigned long)StringBuf_Length(&self->buf)) )
{
ShowSQL("DB error - %s\n", mysql_stmt_error(self->stmt));
hercules_mysql_error_handler(mysql_stmt_errno(self->stmt));
return SQL_ERROR;
}
self->bind_params = false;
return SQL_SUCCESS;
}
示例14: instance_startidletimer
/*==========================================
* Creates idle timer
* Default before instance destroy is 5 minutes
*------------------------------------------*/
static int instance_startidletimer(struct instance_data *im, short instance_id)
{
struct instance_db *db;
struct party_data *p;
nullpo_retr(1, im);
// No current timer
if(im->idle_timer != INVALID_TIMER)
return 1;
// Add the timer
im->idle_limit = (unsigned int)time(NULL) + INSTANCE_LIMIT / 1000;
im->idle_timer = add_timer(gettick()+INSTANCE_LIMIT, instance_delete_timer, instance_id, 0);
// Notify party of added instance timer
if((p = party_search(im->party_id)) != NULL && (db = instance_searchtype_db(im->type)) != NULL)
clif_instance_status(party_getavailablesd(p), StringBuf_Value(db->name), im->keep_limit, im->idle_limit, 1);
return 0;
}
示例15: Sql_QueryStr
/// Executes a query.
int Sql_QueryStr(Sql* self, const char* query)
{
if( self == NULL )
return SQL_ERROR;
Sql_FreeResult(self);
StringBuf_Clear(&self->buf);
StringBuf_AppendStr(&self->buf, query);
if( mysql_real_query(&self->handle, StringBuf_Value(&self->buf), (unsigned long)StringBuf_Length(&self->buf)) )
{
ShowSQL("DB error - %s\n", mysql_error(&self->handle));
return SQL_ERROR;
}
self->result = mysql_store_result(&self->handle);
if( mysql_errno(&self->handle) != 0 )
{
ShowSQL("DB error - %s\n", mysql_error(&self->handle));
return SQL_ERROR;
}
return SQL_SUCCESS;
}