diff options
author | FlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-09-23 19:55:37 +0000 |
---|---|---|
committer | FlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-09-23 19:55:37 +0000 |
commit | 7791397d95512088dca065a4e187bb443b3a6a96 (patch) | |
tree | ca43eab36735561842965d399810941c37288e9b /src/common | |
parent | c85769fcdc89c0f51ca528bc090fe99f30a08518 (diff) | |
download | hercules-7791397d95512088dca065a4e187bb443b3a6a96.tar.gz hercules-7791397d95512088dca065a4e187bb443b3a6a96.tar.bz2 hercules-7791397d95512088dca065a4e187bb443b3a6a96.tar.xz hercules-7791397d95512088dca065a4e187bb443b3a6a96.zip |
* Added flag svn:executable to the configure script.
* Added code for MySQL versions (below 5.0) that don't have MYSQL_DATA_TRUNCATED.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11281 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/sql.c | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/src/common/sql.c b/src/common/sql.c index cc6e81009..6b69c8ce4 100644 --- a/src/common/sql.c +++ b/src/common/sql.c @@ -487,6 +487,30 @@ 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) +{ + MYSQL_RES* meta; + MYSQL_FIELD* field; + MYSQL_BIND* column; + + meta = mysql_stmt_result_metadata(self->stmt); + field = mysql_fetch_field_direct(meta, (unsigned int)i); + ShowSQL("DB error - data of field '%s' was truncated.\n", field->name); + ShowDebug("column - %lu\n", (unsigned long)i); + Sql_P_ShowDebugMysqlFieldInfo("data - ", field->type, field->flags&UNSIGNED_FLAG, self->column_lengths[i].length, ""); + column = &self->columns[i]; + if( column->buffer_type == MYSQL_TYPE_STRING ) + Sql_P_ShowDebugMysqlFieldInfo("buffer - ", column->buffer_type, column->is_unsigned, column->buffer_length, "+1(nul-terminator)"); + else + Sql_P_ShowDebugMysqlFieldInfo("buffer - ", column->buffer_type, column->is_unsigned, column->buffer_length, ""); + mysql_free_result(meta); +} + + + /// Allocates and initializes a new SqlStmt handle. SqlStmt* SqlStmt_Malloc(Sql* sql) { @@ -741,6 +765,8 @@ int SqlStmt_NextRow(SqlStmt* self) // check for errors if( err == MYSQL_NO_DATA ) return SQL_NO_DATA; +#if defined(MYSQL_DATA_TRUNCATED) + // MySQL 5.0/5.1 defines and returns MYSQL_DATA_TRUNCATED [FlavioJS] if( err == MYSQL_DATA_TRUNCATED ) { my_bool truncated; @@ -761,25 +787,14 @@ int SqlStmt_NextRow(SqlStmt* self) column->error = NULL; if( truncated ) {// report truncated column - MYSQL_RES* meta; - MYSQL_FIELD* field; - - meta = mysql_stmt_result_metadata(self->stmt); - field = mysql_fetch_field_direct(meta, (unsigned int)i); - ShowSQL("DB error - data of field '%s' was truncated.\n", field->name); - ShowDebug("column - %lu\n", (unsigned long)i); - Sql_P_ShowDebugMysqlFieldInfo("data - ", field->type, field->flags&UNSIGNED_FLAG, self->column_lengths[i].length, ""); - if( column->buffer_type == MYSQL_TYPE_STRING ) - Sql_P_ShowDebugMysqlFieldInfo("buffer - ", column->buffer_type, column->is_unsigned, column->buffer_length, "+1(nul-terminator)"); - else - Sql_P_ShowDebugMysqlFieldInfo("buffer - ", column->buffer_type, column->is_unsigned, column->buffer_length, ""); - mysql_free_result(meta); + SqlStmt_P_ShowDebugTruncatedColumn(self, i); return SQL_ERROR; } } ShowSQL("DB error - data truncated (unknown source)\n"); return SQL_ERROR; } +#endif if( err ) { ShowSQL("DB error - %s\n", mysql_stmt_error(self->stmt)); @@ -791,6 +806,14 @@ int SqlStmt_NextRow(SqlStmt* self) for( i = 0; i < cols; ++i ) { length = self->column_lengths[i].length; +#if !defined(MYSQL_DATA_TRUNCATED) + // MySQL 4.1/(below?) returns success even if data is truncated, so we test truncation manually [FlavioJS] + if( self->columns[i].buffer_length < length ) + {// report truncated column + SqlStmt_P_ShowDebugTruncatedColumn(self, i); + return SQL_ERROR; + } +#endif if( self->column_lengths[i].out_length ) *self->column_lengths[i].out_length = (uint32)length; column = &self->columns[i]; |