From d439d6d992f76dd547ccd8557e3aa58b11a3ef08 Mon Sep 17 00:00:00 2001 From: epoque11 Date: Mon, 19 Mar 2012 14:43:01 +0000 Subject: - Updated existing registry saving code to perform one single uniform query. (bugreport:2848) git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@15729 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/char/inter.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/char/inter.c b/src/char/inter.c index c72c64108..752fe5163 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -68,7 +68,7 @@ static int wis_dellist[WISDELLIST_MAX], wis_delnum; int inter_accreg_tosql(int account_id, int char_id, struct accreg* reg, int type) { struct global_reg* r; - SqlStmt* stmt; + StringBuf buf; int i; if( account_id <= 0 ) @@ -100,24 +100,31 @@ int inter_accreg_tosql(int account_id, int char_id, struct accreg* reg, int type if( reg->reg_num <= 0 ) return 0; - stmt = SqlStmt_Malloc(sql_handle); - if( SQL_ERROR == SqlStmt_Prepare(stmt, "INSERT INTO `%s` (`type`, `account_id`, `char_id`, `str`, `value`) VALUES ('%d','%d','%d',?,?)", reg_db, type, account_id, char_id) ) - SqlStmt_ShowDebug(stmt); - for( i = 0; i < reg->reg_num; ++i ) - { + StringBuf_Init(&buf); + StringBuf_Printf(&buf, "INSERT INTO `%s` (`type`,`account_id`,`char_id`,`str`,`value`) VALUES ", reg_db); + + for( i = 0; i < reg->reg_num; ++i ) { r = ®->reg[i]; - if( r->str[0] != '\0' && r->value != '\0' ) - { - // str - SqlStmt_BindParam(stmt, 0, SQLDT_STRING, r->str, strnlen(r->str, sizeof(r->str))); - // value - SqlStmt_BindParam(stmt, 1, SQLDT_STRING, r->value, strnlen(r->value, sizeof(r->value))); + if( r->str[0] != '\0' && r->value[0] != '\0' ) { + char str[32]; + char val[256]; + + if( i > 0 ) + StringBuf_AppendStr(&buf, ","); - if( SQL_ERROR == SqlStmt_Execute(stmt) ) - SqlStmt_ShowDebug(stmt); + Sql_EscapeString(sql_handle, str, r->str); + Sql_EscapeString(sql_handle, val, r->value); + + StringBuf_Printf(&buf, "('%d','%d','%d','%s','%s')", type, account_id, char_id, str, val); } } - SqlStmt_Free(stmt); + + if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) { + Sql_ShowDebug(sql_handle); + } + + StringBuf_Destroy(&buf); + return 1; } -- cgit v1.2.3-70-g09d2