From f4fced20c769ccee7f808531221dda481f7bbcca Mon Sep 17 00:00:00 2001 From: Haru Date: Fri, 19 Feb 2016 21:37:39 +0100 Subject: Removed unnecessary typedefs from sql.h - Sql -> struct Sql - SqlStmt -> struct SqlStmt - SqlDataType -> enum SqlDataType This is expected to improve compile time, by removing #include cycles (and forward declaring instead) Signed-off-by: Haru --- src/common/sql.c | 114 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 61 insertions(+), 53 deletions(-) (limited to 'src/common/sql.c') diff --git a/src/common/sql.c b/src/common/sql.c index ed93169ea..1dcf5d374 100644 --- a/src/common/sql.c +++ b/src/common/sql.c @@ -79,11 +79,11 @@ struct SqlStmt { /////////////////////////////////////////////////////////////////////////////// /// Allocates and initializes a new Sql handle. -Sql* Sql_Malloc(void) +struct Sql *Sql_Malloc(void) { - Sql* self; + struct Sql *self; - CREATE(self, Sql, 1); + CREATE(self, struct Sql, 1); mysql_init(&self->handle); StrBuf->Init(&self->buf); self->lengths = NULL; @@ -93,10 +93,10 @@ Sql* Sql_Malloc(void) return self; } -static int Sql_P_Keepalive(Sql* self); +static int Sql_P_Keepalive(struct Sql *self); /// Establishes a connection. -int Sql_Connect(Sql* self, const char* user, const char* passwd, const char* host, uint16 port, const char* db) +int Sql_Connect(struct Sql *self, const char *user, const char *passwd, const char *host, uint16 port, const char *db) { if( self == NULL ) return SQL_ERROR; @@ -119,7 +119,7 @@ int Sql_Connect(Sql* self, const char* user, const char* passwd, const char* hos } /// Retrieves the timeout of the connection. -int Sql_GetTimeout(Sql* self, uint32* out_timeout) +int Sql_GetTimeout(struct Sql *self, uint32 *out_timeout) { if( self && out_timeout && SQL_SUCCESS == SQL->Query(self, "SHOW VARIABLES LIKE 'wait_timeout'") ) { char* data; @@ -136,7 +136,7 @@ int Sql_GetTimeout(Sql* self, uint32* out_timeout) } /// Retrieves the name of the columns of a table into out_buf, with the separator after each name. -int Sql_GetColumnNames(Sql* self, const char* table, char* out_buf, size_t buf_len, char sep) +int Sql_GetColumnNames(struct Sql *self, const char *table, char *out_buf, size_t buf_len, char sep) { char* data; size_t len; @@ -164,7 +164,7 @@ int Sql_GetColumnNames(Sql* self, const char* table, char* out_buf, size_t buf_l } /// Changes the encoding of the connection. -int Sql_SetEncoding(Sql* self, const char* encoding) +int Sql_SetEncoding(struct Sql *self, const char *encoding) { if( self && mysql_set_character_set(&self->handle, encoding) == 0 ) return SQL_SUCCESS; @@ -172,7 +172,7 @@ int Sql_SetEncoding(Sql* self, const char* encoding) } /// Pings the connection. -int Sql_Ping(Sql* self) +int Sql_Ping(struct Sql *self) { if( self && mysql_ping(&self->handle) == 0 ) return SQL_SUCCESS; @@ -184,7 +184,7 @@ int Sql_Ping(Sql* self) /// @private static int Sql_P_KeepaliveTimer(int tid, int64 tick, int id, intptr_t data) { - Sql* self = (Sql*)data; + struct Sql *self = (struct Sql *)data; ShowInfo("Pinging SQL server to keep connection alive...\n"); Sql_Ping(self); return 0; @@ -194,7 +194,7 @@ static int Sql_P_KeepaliveTimer(int tid, int64 tick, int id, intptr_t data) /// /// @return the keepalive timer id, or INVALID_TIMER /// @private -static int Sql_P_Keepalive(Sql* self) +static int Sql_P_Keepalive(struct Sql *self) { uint32 timeout, ping_interval; @@ -214,26 +214,27 @@ static int Sql_P_Keepalive(Sql* self) } /// Escapes a string. -size_t Sql_EscapeString(Sql* self, char *out_to, const char *from) +size_t Sql_EscapeString(struct Sql *self, char *out_to, const char *from) { - if( self ) + if (self != NULL) return (size_t)mysql_real_escape_string(&self->handle, out_to, from, (unsigned long)strlen(from)); else return (size_t)mysql_escape_string(out_to, from, (unsigned long)strlen(from)); } /// Escapes a string. -size_t Sql_EscapeStringLen(Sql* self, char *out_to, const char *from, size_t from_len) +size_t Sql_EscapeStringLen(struct Sql *self, char *out_to, const char *from, size_t from_len) { - if( self ) + if (self != NULL) return (size_t)mysql_real_escape_string(&self->handle, out_to, from, (unsigned long)from_len); else return (size_t)mysql_escape_string(out_to, from, (unsigned long)from_len); } /// Executes a query. -int Sql_Query(Sql *self, const char *query, ...) __attribute__((format(printf, 2, 3))); -int Sql_Query(Sql *self, const char *query, ...) { +int Sql_Query(struct Sql *self, const char *query, ...) __attribute__((format(printf, 2, 3))); +int Sql_Query(struct Sql *self, const char *query, ...) +{ int res; va_list args; @@ -245,7 +246,7 @@ int Sql_Query(Sql *self, const char *query, ...) { } /// Executes a query. -int Sql_QueryV(Sql* self, const char* query, va_list args) +int Sql_QueryV(struct Sql *self, const char *query, va_list args) { if( self == NULL ) return SQL_ERROR; @@ -270,7 +271,7 @@ int Sql_QueryV(Sql* self, const char* query, va_list args) } /// Executes a query. -int Sql_QueryStr(Sql* self, const char* query) +int Sql_QueryStr(struct Sql *self, const char *query) { if( self == NULL ) return SQL_ERROR; @@ -295,33 +296,34 @@ int Sql_QueryStr(Sql* self, const char* query) } /// Returns the number of the AUTO_INCREMENT column of the last INSERT/UPDATE query. -uint64 Sql_LastInsertId(Sql* self) +uint64 Sql_LastInsertId(struct Sql *self) { - if( self ) + if (self != NULL) return (uint64)mysql_insert_id(&self->handle); else return 0; } /// Returns the number of columns in each row of the result. -uint32 Sql_NumColumns(Sql* self) +uint32 Sql_NumColumns(struct Sql *self) { - if( self && self->result ) + if (self != NULL && self->result != NULL) return (uint32)mysql_num_fields(self->result); return 0; } /// Returns the number of rows in the result. -uint64 Sql_NumRows(Sql* self) +uint64 Sql_NumRows(struct Sql *self) { - if( self && self->result ) + if (self != NULL && self->result != NULL) return (uint64)mysql_num_rows(self->result); return 0; } /// Fetches the next row. -int Sql_NextRow(Sql* self) { - if( self && self->result ) { +int Sql_NextRow(struct Sql *self) +{ + if (self != NULL && self->result != NULL) { self->row = mysql_fetch_row(self->result); if( self->row ) { self->lengths = mysql_fetch_lengths(self->result); @@ -335,7 +337,7 @@ int Sql_NextRow(Sql* self) { } /// Gets the data of a column. -int Sql_GetData(Sql* self, size_t col, char** out_buf, size_t* out_len) +int Sql_GetData(struct Sql *self, size_t col, char **out_buf, size_t *out_len) { if( self && self->row ) { if( col < SQL->NumColumns(self) ) { @@ -351,7 +353,8 @@ int Sql_GetData(Sql* self, size_t col, char** out_buf, size_t* out_len) } /// Frees the result of the query. -void Sql_FreeResult(Sql* self) { +void Sql_FreeResult(struct Sql *self) +{ if( self && self->result ) { mysql_free_result(self->result); self->result = NULL; @@ -361,7 +364,7 @@ void Sql_FreeResult(Sql* self) { } /// Shows debug information (last query). -void Sql_ShowDebug_(Sql* self, const char* debug_file, const unsigned long debug_line) +void Sql_ShowDebug_(struct Sql *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); @@ -372,7 +375,7 @@ void Sql_ShowDebug_(Sql* self, const char* debug_file, const unsigned long debug } /// Frees a Sql handle returned by Sql_Malloc. -void Sql_Free(Sql* self) { +void Sql_Free(struct Sql *self) { if( self ) { SQL->FreeResult(self); @@ -515,7 +518,7 @@ static void Sql_P_ShowDebugMysqlFieldInfo(const char* prefix, enum enum_field_ty /// Reports debug information about a truncated column. /// /// @private -static void SqlStmt_P_ShowDebugTruncatedColumn(SqlStmt* self, size_t i) +static void SqlStmt_P_ShowDebugTruncatedColumn(struct SqlStmt *self, size_t i) { MYSQL_RES* meta; MYSQL_FIELD* field; @@ -535,8 +538,9 @@ static void SqlStmt_P_ShowDebugTruncatedColumn(SqlStmt* self, size_t i) } /// Allocates and initializes a new SqlStmt handle. -SqlStmt* SqlStmt_Malloc(Sql* sql) { - SqlStmt* self; +struct SqlStmt *SqlStmt_Malloc(struct Sql *sql) +{ + struct SqlStmt *self; MYSQL_STMT* stmt; if( sql == NULL ) @@ -547,7 +551,7 @@ SqlStmt* SqlStmt_Malloc(Sql* sql) { ShowSQL("DB error - %s\n", mysql_error(&sql->handle)); return NULL; } - CREATE(self, SqlStmt, 1); + CREATE(self, struct SqlStmt, 1); StrBuf->Init(&self->buf); self->stmt = stmt; self->params = NULL; @@ -562,8 +566,9 @@ SqlStmt* SqlStmt_Malloc(Sql* sql) { } /// Prepares the statement. -int SqlStmt_Prepare(SqlStmt *self, const char *query, ...) __attribute__((format(printf, 2, 3))); -int SqlStmt_Prepare(SqlStmt *self, const char *query, ...) { +int SqlStmt_Prepare(struct SqlStmt *self, const char *query, ...) __attribute__((format(printf, 2, 3))); +int SqlStmt_Prepare(struct SqlStmt *self, const char *query, ...) +{ int res; va_list args; @@ -575,7 +580,7 @@ int SqlStmt_Prepare(SqlStmt *self, const char *query, ...) { } /// Prepares the statement. -int SqlStmt_PrepareV(SqlStmt* self, const char* query, va_list args) +int SqlStmt_PrepareV(struct SqlStmt *self, const char *query, va_list args) { if( self == NULL ) return SQL_ERROR; @@ -595,7 +600,7 @@ int SqlStmt_PrepareV(SqlStmt* self, const char* query, va_list args) } /// Prepares the statement. -int SqlStmt_PrepareStr(SqlStmt* self, const char* query) +int SqlStmt_PrepareStr(struct SqlStmt *self, const char *query) { if( self == NULL ) return SQL_ERROR; @@ -615,7 +620,7 @@ int SqlStmt_PrepareStr(SqlStmt* self, const char* query) } /// Returns the number of parameters in the prepared statement. -size_t SqlStmt_NumParams(SqlStmt* self) +size_t SqlStmt_NumParams(struct SqlStmt *self) { if( self ) return (size_t)mysql_stmt_param_count(self->stmt); @@ -624,7 +629,7 @@ size_t SqlStmt_NumParams(SqlStmt* self) } /// Binds a parameter to a buffer. -int SqlStmt_BindParam(SqlStmt* self, size_t idx, enum SqlDataType buffer_type, void* buffer, size_t buffer_len) +int SqlStmt_BindParam(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_type, void *buffer, size_t buffer_len) { if( self == NULL ) return SQL_ERROR; @@ -652,7 +657,7 @@ int SqlStmt_BindParam(SqlStmt* self, size_t idx, enum SqlDataType buffer_type, v } /// Executes the prepared statement. -int SqlStmt_Execute(SqlStmt* self) +int SqlStmt_Execute(struct SqlStmt *self) { if( self == NULL ) return SQL_ERROR; @@ -677,7 +682,7 @@ int SqlStmt_Execute(SqlStmt* self) } /// Returns the number of the AUTO_INCREMENT column of the last INSERT/UPDATE statement. -uint64 SqlStmt_LastInsertId(SqlStmt* self) +uint64 SqlStmt_LastInsertId(struct SqlStmt *self) { if( self ) return (uint64)mysql_stmt_insert_id(self->stmt); @@ -686,7 +691,7 @@ uint64 SqlStmt_LastInsertId(SqlStmt* self) } /// Returns the number of columns in each row of the result. -size_t SqlStmt_NumColumns(SqlStmt* self) +size_t SqlStmt_NumColumns(struct SqlStmt *self) { if( self ) return (size_t)mysql_stmt_field_count(self->stmt); @@ -695,7 +700,8 @@ size_t SqlStmt_NumColumns(SqlStmt* self) } /// Binds the result of a column to a buffer. -int SqlStmt_BindColumn(SqlStmt *self, size_t idx, enum SqlDataType buffer_type, void *buffer, size_t buffer_len, uint32 *out_length, int8 *out_is_null) { +int SqlStmt_BindColumn(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_type, void *buffer, size_t buffer_len, uint32 *out_length, int8 *out_is_null) +{ if (self == NULL) return SQL_ERROR; @@ -736,16 +742,16 @@ int SqlStmt_BindColumn(SqlStmt *self, size_t idx, enum SqlDataType buffer_type, } /// Returns the number of rows in the result. -uint64 SqlStmt_NumRows(SqlStmt* self) +uint64 SqlStmt_NumRows(struct SqlStmt *self) { - if( self ) + if (self != NULL) return (uint64)mysql_stmt_num_rows(self->stmt); else return 0; } /// Fetches the next row. -int SqlStmt_NextRow(SqlStmt* self) +int SqlStmt_NextRow(struct SqlStmt *self) { int err; size_t i; @@ -828,14 +834,14 @@ int SqlStmt_NextRow(SqlStmt* self) } /// Frees the result of the statement execution. -void SqlStmt_FreeResult(SqlStmt* self) +void SqlStmt_FreeResult(struct SqlStmt *self) { if( self ) mysql_stmt_free_result(self->stmt); } /// Shows debug information (with statement). -void SqlStmt_ShowDebug_(SqlStmt* self, const char* debug_file, const unsigned long debug_line) +void SqlStmt_ShowDebug_(struct 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); @@ -846,7 +852,7 @@ void SqlStmt_ShowDebug_(SqlStmt* self, const char* debug_file, const unsigned lo } /// Frees a SqlStmt returned by SqlStmt_Malloc. -void SqlStmt_Free(SqlStmt* self) +void SqlStmt_Free(struct SqlStmt *self) { if( self ) { @@ -919,7 +925,8 @@ void Sql_inter_server_read(const char* cfgName, bool first) { return; } -void Sql_HerculesUpdateCheck(Sql* self) { +void Sql_HerculesUpdateCheck(struct Sql *self) +{ char line[22];// "yyyy-mm-dd--hh-mm" (17) + ".sql" (4) + 1 FILE* ifp;/* index fp */ unsigned int performed = 0; @@ -980,7 +987,8 @@ void Sql_HerculesUpdateCheck(Sql* self) { StrBuf->Destroy(&buf); } -void Sql_HerculesUpdateSkip(Sql* self,const char *filename) { +void Sql_HerculesUpdateSkip(struct Sql *self, const char *filename) +{ char path[41];// "sql-files/upgrades/" (19) + "yyyy-mm-dd--hh-mm" (17) + ".sql" (4) + 1 char timestamp[11];// "1360186680" (10) + 1 FILE* ifp;/* index fp */ -- cgit v1.2.3-70-g09d2 From 127093b5327de343f4ae3f7c8752c465eea911c8 Mon Sep 17 00:00:00 2001 From: Haru Date: Fri, 19 Feb 2016 21:40:53 +0100 Subject: Changed buffer argument of SQL->StmtBindParam() to const Parameters are supposed to be read-only Signed-off-by: Haru --- src/char/char.c | 4 ++-- src/char/int_homun.c | 4 ++-- src/common/sql.c | 19 +++++++++++---- src/common/sql.h | 2 +- src/login/account_sql.c | 62 ++++++++++++++++++++++++------------------------- src/map/log.c | 16 ++++++------- 6 files changed, 58 insertions(+), 49 deletions(-) (limited to 'src/common/sql.c') diff --git a/src/char/char.c b/src/char/char.c index 23f5d1ea0..df59eafc9 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -3298,8 +3298,8 @@ void char_ban(int account_id, int char_id, time_t *unban_time, short year, short if( SQL_SUCCESS != SQL->StmtPrepare(stmt, "UPDATE `%s` SET `unban_time` = ? WHERE `char_id` = ? LIMIT 1", char_db) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_LONG, (void*)×tamp, sizeof(timestamp)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_INT, (void*)&char_id, sizeof(char_id)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_LONG, ×tamp, sizeof(timestamp)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_INT, &char_id, sizeof(char_id)) || SQL_SUCCESS != SQL->StmtExecute(stmt) ) { SqlStmt_ShowDebug(stmt); diff --git a/src/char/int_homun.c b/src/char/int_homun.c index bfb0009e6..90643699c 100644 --- a/src/char/int_homun.c +++ b/src/char/int_homun.c @@ -171,8 +171,8 @@ bool mapif_homunculus_save(const struct s_homunculus *hd) } else { for (i = 0; i < MAX_HOMUNSKILL; ++i) { if (hd->hskill[i].id > 0 && hd->hskill[i].lv != 0) { - SQL->StmtBindParam(stmt, 0, SQLDT_USHORT, (void*)&hd->hskill[i].id, 0); // FIXME: StmtBindParam should take const void - SQL->StmtBindParam(stmt, 1, SQLDT_USHORT, (void*)&hd->hskill[i].lv, 0); // FIXME: StmtBindParam should take const void + SQL->StmtBindParam(stmt, 0, SQLDT_USHORT, &hd->hskill[i].id, 0); + SQL->StmtBindParam(stmt, 1, SQLDT_USHORT, &hd->hskill[i].lv, 0); if (SQL_ERROR == SQL->StmtExecute(stmt)) { SqlStmt_ShowDebug(stmt); flag = false; diff --git a/src/common/sql.c b/src/common/sql.c index 1dcf5d374..65960d8ea 100644 --- a/src/common/sql.c +++ b/src/common/sql.c @@ -629,7 +629,7 @@ size_t SqlStmt_NumParams(struct SqlStmt *self) } /// Binds a parameter to a buffer. -int SqlStmt_BindParam(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_type, void *buffer, size_t buffer_len) +int SqlStmt_BindParam(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_type, const void *buffer, size_t buffer_len) { if( self == NULL ) return SQL_ERROR; @@ -650,10 +650,19 @@ int SqlStmt_BindParam(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_ self->params[i].buffer_type = MYSQL_TYPE_NULL; self->bind_params = true; } - if( idx < self->max_params ) - return Sql_P_BindSqlDataType(self->params+idx, buffer_type, buffer, buffer_len, NULL, NULL); - else - return SQL_SUCCESS;// out of range - ignore + if (idx >= self->max_params) + return SQL_SUCCESS; // out of range - ignore + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-qual" + /* + * MySQL uses the same struct with a non-const buffer for both + * parameters (input) and columns (output). + * As such, we get to close our eyes and pretend we didn't see we're + * dropping a const qualifier here. + */ + return Sql_P_BindSqlDataType(self->params+idx, buffer_type, (void *)buffer, buffer_len, NULL, NULL); +#pragma GCC diagnostic pop } /// Executes the prepared statement. diff --git a/src/common/sql.h b/src/common/sql.h index 3619895b1..07be829fc 100644 --- a/src/common/sql.h +++ b/src/common/sql.h @@ -209,7 +209,7 @@ struct sql_interface { /// All parameters should have bindings. /// /// @return SQL_SUCCESS or SQL_ERROR - int (*StmtBindParam)(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_type, void *buffer, size_t buffer_len); + int (*StmtBindParam)(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_type, const void *buffer, size_t buffer_len); /// Executes the prepared statement. /// Any previous result is freed and all column bindings are removed. diff --git a/src/login/account_sql.c b/src/login/account_sql.c index 6d0e795f6..195a10233 100644 --- a/src/login/account_sql.c +++ b/src/login/account_sql.c @@ -644,22 +644,22 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo if( SQL_SUCCESS != SQL->StmtPrepare(stmt, "INSERT INTO `%s` (`account_id`, `userid`, `user_pass`, `sex`, `email`, `group_id`, `state`, `unban_time`, `expiration_time`, `logincount`, `lastlogin`, `last_ip`, `birthdate`, `character_slots`, `pincode`, `pincode_change`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", db->account_db) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_INT, (void*)&acc->account_id, sizeof(acc->account_id)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, (void*)acc->userid, strlen(acc->userid)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 2, SQLDT_STRING, (void*)acc->pass, strlen(acc->pass)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 3, SQLDT_ENUM, (void*)&acc->sex, sizeof(acc->sex)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 4, SQLDT_STRING, (void*)&acc->email, strlen(acc->email)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 5, SQLDT_INT, (void*)&acc->group_id, sizeof(acc->group_id)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 6, SQLDT_UINT, (void*)&acc->state, sizeof(acc->state)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 7, SQLDT_LONG, (void*)&acc->unban_time, sizeof(acc->unban_time)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 8, SQLDT_INT, (void*)&acc->expiration_time, sizeof(acc->expiration_time)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 9, SQLDT_UINT, (void*)&acc->logincount, sizeof(acc->logincount)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 10, SQLDT_STRING, (void*)&acc->lastlogin, strlen(acc->lastlogin)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 11, SQLDT_STRING, (void*)&acc->last_ip, strlen(acc->last_ip)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 12, SQLDT_STRING, (void*)&acc->birthdate, strlen(acc->birthdate)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 13, SQLDT_UCHAR, (void*)&acc->char_slots, sizeof(acc->char_slots)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 14, SQLDT_STRING, (void*)&acc->pincode, strlen(acc->pincode)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 15, SQLDT_LONG, (void*)&acc->pincode_change, sizeof(acc->pincode_change)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_INT, &acc->account_id, sizeof(acc->account_id)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, acc->userid, strlen(acc->userid)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 2, SQLDT_STRING, acc->pass, strlen(acc->pass)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 3, SQLDT_ENUM, &acc->sex, sizeof(acc->sex)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 4, SQLDT_STRING, &acc->email, strlen(acc->email)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 5, SQLDT_INT, &acc->group_id, sizeof(acc->group_id)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 6, SQLDT_UINT, &acc->state, sizeof(acc->state)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 7, SQLDT_LONG, &acc->unban_time, sizeof(acc->unban_time)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 8, SQLDT_INT, &acc->expiration_time, sizeof(acc->expiration_time)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 9, SQLDT_UINT, &acc->logincount, sizeof(acc->logincount)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 10, SQLDT_STRING, &acc->lastlogin, strlen(acc->lastlogin)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 11, SQLDT_STRING, &acc->last_ip, strlen(acc->last_ip)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 12, SQLDT_STRING, &acc->birthdate, strlen(acc->birthdate)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 13, SQLDT_UCHAR, &acc->char_slots, sizeof(acc->char_slots)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 14, SQLDT_STRING, &acc->pincode, strlen(acc->pincode)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 15, SQLDT_LONG, &acc->pincode_change, sizeof(acc->pincode_change)) || SQL_SUCCESS != SQL->StmtExecute(stmt) ) { SqlStmt_ShowDebug(stmt); @@ -667,21 +667,21 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo } } else {// update account table if( SQL_SUCCESS != SQL->StmtPrepare(stmt, "UPDATE `%s` SET `userid`=?,`user_pass`=?,`sex`=?,`email`=?,`group_id`=?,`state`=?,`unban_time`=?,`expiration_time`=?,`logincount`=?,`lastlogin`=?,`last_ip`=?,`birthdate`=?,`character_slots`=?,`pincode`=?,`pincode_change`=? WHERE `account_id` = '%d'", db->account_db, acc->account_id) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, (void*)acc->userid, strlen(acc->userid)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, (void*)acc->pass, strlen(acc->pass)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 2, SQLDT_ENUM, (void*)&acc->sex, sizeof(acc->sex)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 3, SQLDT_STRING, (void*)acc->email, strlen(acc->email)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 4, SQLDT_INT, (void*)&acc->group_id, sizeof(acc->group_id)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 5, SQLDT_UINT, (void*)&acc->state, sizeof(acc->state)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 6, SQLDT_LONG, (void*)&acc->unban_time, sizeof(acc->unban_time)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 7, SQLDT_LONG, (void*)&acc->expiration_time, sizeof(acc->expiration_time)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 8, SQLDT_UINT, (void*)&acc->logincount, sizeof(acc->logincount)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 9, SQLDT_STRING, (void*)&acc->lastlogin, strlen(acc->lastlogin)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 10, SQLDT_STRING, (void*)&acc->last_ip, strlen(acc->last_ip)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 11, SQLDT_STRING, (void*)&acc->birthdate, strlen(acc->birthdate)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 12, SQLDT_UCHAR, (void*)&acc->char_slots, sizeof(acc->char_slots)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 13, SQLDT_STRING, (void*)&acc->pincode, strlen(acc->pincode)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 14, SQLDT_LONG, (void*)&acc->pincode_change, sizeof(acc->pincode_change)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, acc->userid, strlen(acc->userid)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, acc->pass, strlen(acc->pass)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 2, SQLDT_ENUM, &acc->sex, sizeof(acc->sex)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 3, SQLDT_STRING, acc->email, strlen(acc->email)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 4, SQLDT_INT, &acc->group_id, sizeof(acc->group_id)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 5, SQLDT_UINT, &acc->state, sizeof(acc->state)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 6, SQLDT_LONG, &acc->unban_time, sizeof(acc->unban_time)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 7, SQLDT_LONG, &acc->expiration_time, sizeof(acc->expiration_time)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 8, SQLDT_UINT, &acc->logincount, sizeof(acc->logincount)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 9, SQLDT_STRING, &acc->lastlogin, strlen(acc->lastlogin)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 10, SQLDT_STRING, &acc->last_ip, strlen(acc->last_ip)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 11, SQLDT_STRING, &acc->birthdate, strlen(acc->birthdate)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 12, SQLDT_UCHAR, &acc->char_slots, sizeof(acc->char_slots)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 13, SQLDT_STRING, &acc->pincode, strlen(acc->pincode)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 14, SQLDT_LONG, &acc->pincode_change, sizeof(acc->pincode_change)) || SQL_SUCCESS != SQL->StmtExecute(stmt) ) { SqlStmt_ShowDebug(stmt); diff --git a/src/map/log.c b/src/map/log.c index 245229a15..c19190d90 100644 --- a/src/map/log.c +++ b/src/map/log.c @@ -289,7 +289,7 @@ void log_atcommand_sub_sql(struct map_session_data* sd, const char* message) stmt = SQL->StmtMalloc(logs->mysql_handle); if( SQL_SUCCESS != SQL->StmtPrepare(stmt, LOG_QUERY " INTO `%s` (`atcommand_date`, `account_id`, `char_id`, `char_name`, `map`, `command`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", logs->config.log_gm, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) ) || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, 255)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, message, safestrnlen(message, 255)) || SQL_SUCCESS != SQL->StmtExecute(stmt) ) { SqlStmt_ShowDebug(stmt); @@ -331,11 +331,11 @@ void log_npc_sub_sql(struct map_session_data *sd, const char *message) nullpo_retv(sd); nullpo_retv(message); stmt = SQL->StmtMalloc(logs->mysql_handle); - if( SQL_SUCCESS != SQL->StmtPrepare(stmt, LOG_QUERY " INTO `%s` (`npc_date`, `account_id`, `char_id`, `char_name`, `map`, `mes`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", logs->config.log_npc, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) ) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, 255)) - || SQL_SUCCESS != SQL->StmtExecute(stmt) ) - { + if (SQL_SUCCESS != SQL->StmtPrepare(stmt, LOG_QUERY " INTO `%s` (`npc_date`, `account_id`, `char_id`, `char_name`, `map`, `mes`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", logs->config.log_npc, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) ) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, message, safestrnlen(message, 255)) + || SQL_SUCCESS != SQL->StmtExecute(stmt) + ) { SqlStmt_ShowDebug(stmt); SQL->StmtFree(stmt); return; @@ -388,8 +388,8 @@ void log_chat_sub_sql(e_log_chat_type type, int type_id, int src_charid, int src nullpo_retv(message); stmt = SQL->StmtMalloc(logs->mysql_handle); if( SQL_SUCCESS != SQL->StmtPrepare(stmt, LOG_QUERY " INTO `%s` (`time`, `type`, `type_id`, `src_charid`, `src_accountid`, `src_map`, `src_map_x`, `src_map_y`, `dst_charname`, `message`) VALUES (NOW(), '%c', '%d', '%d', '%d', '%s', '%d', '%d', ?, ?)", logs->config.log_chat, logs->chattype2char(type), type_id, src_charid, src_accid, mapname, x, y) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, (char*)dst_charname, safestrnlen(dst_charname, NAME_LENGTH)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, CHAT_SIZE_MAX)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, dst_charname, safestrnlen(dst_charname, NAME_LENGTH)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, message, safestrnlen(message, CHAT_SIZE_MAX)) || SQL_SUCCESS != SQL->StmtExecute(stmt) ) { SqlStmt_ShowDebug(stmt); -- cgit v1.2.3-70-g09d2