mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Fixed compiler warnings detected by option -Wshadow and -Wunused:
- Removed not used variables and functions - Added #ifdef around code that is not used - Renamed variables and functions to avoid conflicts - Removed some not used arguments Fixed some class/struct warnings in ndb Added define IS_LONGDATA() to simplify code in libmysql.c I did run gcov on the changes and added 'purecov' comments on almost all lines that was not just variable name changes BUILD/SETUP.sh: Added printing of unused functions and variables. Made it easy to test compiling with -Wshadow BUILD/compile-pentium-gcov: Added warnings Mark binary with -gcov client/mysql.cc: Fixed warnings found with gcc -Wshadow client/mysql_upgrade.c: Fixed warnings found with gcc -Wshadow client/mysqlbinlog.cc: Fixed warnings found with gcc -Wshadow client/mysqldump.c: Fixed warnings found with gcc -Wshadow client/mysqltest.c: Fixed warnings found with gcc -Wshadow client/sql_string.cc: Fixed warnings found with gcc -Wshadow Merged with sql/sql_string.cc client/sql_string.h: Fixed warnings found with gcc -Wshadow Merged with sql/sql_string.h cmd-line-utils/readline/display.c: Fixed compiler warning cmd-line-utils/readline/histexpand.c: Fixed warnings found with gcc -Wshadow cmd-line-utils/readline/input.c: Fixed warnings found with gcc -Wshadow cmd-line-utils/readline/text.c: Fixed warnings found with gcc -Wshadow cmd-line-utils/readline/vi_mode.c: Fixed warnings found with gcc -Wshadow dbug/dbug_analyze.c: Fixed warnings found with gcc -Wshadow extra/my_print_defaults.c: Prefixed defaults_extra_file and defaults_group_suffix with 'my' to avoid conflicts with similar named local variables extra/yassl/include/buffer.hpp: Fixed compiler warnings extra/yassl/include/crypto_wrapper.hpp: Fixed compiler warnings extra/yassl/include/yassl_imp.hpp: Fixed compiler warnings extra/yassl/include/yassl_int.hpp: Fixed compiler warnings extra/yassl/src/crypto_wrapper.cpp: Fixed compiler warnings extra/yassl/taocrypt/benchmark/benchmark.cpp: Fixed warnings found with gcc -Wshadow extra/yassl/taocrypt/include/algebra.hpp: Fixed compiler warnings extra/yassl/taocrypt/include/des.hpp: Fixed compiler warnings extra/yassl/taocrypt/include/hash.hpp: Fixed compiler warnings extra/yassl/taocrypt/include/hmac.hpp: Fixed compiler warnings extra/yassl/taocrypt/include/modarith.hpp: Fixed compiler warnings extra/yassl/taocrypt/include/modes.hpp: Fixed compiler warnings extra/yassl/taocrypt/include/rsa.hpp: Fixed compiler warnings extra/yassl/taocrypt/mySTL/list.hpp: Fixed compiler warnings extra/yassl/taocrypt/src/aes.cpp: Fixed compiler warnings extra/yassl/taocrypt/src/algebra.cpp: Fixed compiler warnings extra/yassl/taocrypt/src/asn.cpp: Fixed compiler warnings extra/yassl/taocrypt/test/test.cpp: Fixed compiler warnings extra/yassl/testsuite/testsuite.cpp: Fixed compiler warnings include/m_ctype.h: Fixed warnings found with gcc -Wshadow include/my_pthread.h: Fixed warnings found with gcc -Wshadow include/my_sys.h: Fixed warnings found with gcc -Wshadow include/my_time.h: Fixed warnings found with gcc -Wshadow include/mysql.h: Fixed warnings found with gcc -Wshadow Added define IS_LONGDATA() to simplify code in libmysql.c libmysql/libmysql.c: Fixed warnings found with gcc -Wshadow (Mostly replaced bind -> my_bind and time -> my_time) libmysqld/lib_sql.cc: Removed not used variables and labels myisam/ft_boolean_search.c: Fixed warnings found with gcc -Wshadow myisam/mi_open.c: Fixed warnings found with gcc -Wshadow myisam/mi_search.c: Fixed warnings found with gcc -Wshadow myisam/mi_unique.c: Fixed compiler warning myisam/myisampack.c: Fixed warnings found with gcc -Wshadow myisam/rt_index.c: Remove not used variables myisam/sort.c: Fixed warnings found with gcc -Wshadow mysql-test/r/mysqlcheck.result: Remove databases and tables possible left by previous test mysql-test/r/mysqltest.result: New test results mysql-test/t/mysql.test: Coverage tests mysql-test/t/mysqlbinlog.test: Coverage tests mysql-test/t/mysqlcheck.test: Remove databases and tables possible left by previous test mysql-test/t/mysqltest.test: Coverage tests mysys/default.c: Prefixed defaults_file, defaults_group_suffix and defaults_extra_file with 'my' to avoid conflicts with local variables in some functions mysys/mf_iocache2.c: Fixed warnings found with gcc -Wshadow mysys/mf_keycache.c: Fixed warnings found with gcc -Wshadow mysys/my_bitmap.c: Fixed warnings found with gcc -Wshadow mysys/sha1.c: Fixed warnings found with gcc -Wshadow ndb/include/kernel/signaldata/ArbitSignalData.hpp: Fixed compiler warning ndb/include/kernel/signaldata/DictTabInfo.hpp: Fixed compiler warnings ndb/include/ndbapi/NdbReceiver.hpp: Fixed warnings found with gcc -Wshadow ndb/include/transporter/TransporterDefinitions.hpp: Fixed compiler warning ndb/include/util/InputStream.hpp: Fixed compiler warning ndb/include/util/OutputStream.hpp: Fixed compiler warning ndb/include/util/SimpleProperties.hpp: Fixed compiler warning ndb/include/util/SocketAuthenticator.hpp: Fixed compiler warning ndb/include/util/SocketServer.hpp: Fixed compiler warning ndb/src/common/mgmcommon/ConfigRetriever.cpp: Fixed warnings found with gcc -Wshadow ndb/src/common/portlib/NdbTick.c: Fixed warnings found with gcc -Wshadow ndb/src/common/transporter/SHM_Transporter.cpp: Fixed warnings found with gcc -Wshadow ndb/src/common/transporter/TCP_Transporter.cpp: Fixed warnings found with gcc -Wshadow ndb/src/common/transporter/TCP_Transporter.hpp: Fixed compiler warning ndb/src/common/transporter/Transporter.cpp: Removed not used variable ndb/src/common/transporter/TransporterRegistry.cpp: Removed not used variable ndb/src/common/util/Bitmask.cpp: Moved function to avoid warnings of not used function ndb/src/common/util/ConfigValues.cpp: Fixed warnings found with gcc -Wshadow ndb/src/common/util/File.cpp: Fixed warnings found with gcc -Wshadow ndb/src/common/util/Properties.cpp: Fixed warnings found with gcc -Wshadow ndb/src/common/util/SocketClient.cpp: Fixed wrong return value ndb/src/common/util/random.c: Fixed warnings found with gcc -Wshadow ndb/src/common/util/socket_io.cpp: Fixed warnings found with gcc -Wshadow ndb/src/cw/cpcd/APIService.cpp: Removed not used variable ndb/src/cw/cpcd/main.cpp: Removed not used variables ndb/src/kernel/blocks/cmvmi/Cmvmi.cpp: Fixed compiler warnings ndb/src/kernel/blocks/dbdict/Dbdict.cpp: Removed not used variables ndb/src/kernel/blocks/dbdict/Dbdict.hpp: Fixed compiler warnings ndb/src/kernel/blocks/dbdih/Dbdih.hpp: Fixed compiler warnings ndb/src/kernel/blocks/dblqh/Dblqh.hpp: Fixed compiler warnings ndb/src/kernel/blocks/dblqh/DblqhMain.cpp: Removed not used variables ndb/src/kernel/blocks/dbtc/Dbtc.hpp: Fixed compiler warnings ndb/src/kernel/blocks/dbtup/Dbtup.hpp: Fixed compiler warnings ndb/src/kernel/blocks/dbtup/DbtupScan.cpp: Removed not used variable ndb/src/kernel/blocks/dbtux/DbtuxNode.cpp: Removed not used variables ndb/src/kernel/blocks/dbtux/DbtuxScan.cpp: Removed not used variables ndb/src/kernel/blocks/dbtux/DbtuxTree.cpp: Removed not used variables ndb/src/kernel/blocks/ndbcntr/Ndbcntr.hpp: Fixed compiler warnings ndb/src/kernel/blocks/ndbcntr/NdbcntrMain.cpp: Removed not used variables ndb/src/kernel/blocks/ndbfs/AsyncFile.hpp: Fixed compiler warnings ndb/src/kernel/blocks/qmgr/Qmgr.hpp: Fixed compiler warnings ndb/src/kernel/blocks/qmgr/QmgrMain.cpp: Removed not used variables ndb/src/kernel/blocks/suma/Suma.cpp: Removed not used variables ndb/src/kernel/blocks/suma/Suma.hpp: Fixed compiler warnings ndb/src/kernel/vm/MetaData.hpp: Fixed compiler warnings ndb/src/mgmapi/LocalConfig.cpp: Fixed warnings found with gcc -Wshadow ndb/src/mgmapi/mgmapi.cpp: Fixed warnings found with gcc -Wshadow ndb/src/mgmclient/CommandInterpreter.cpp: Removed not used variables ndb/src/mgmsrv/ConfigInfo.cpp: Fixed warnings found with gcc -Wshadow Removed not used variables ndb/src/mgmsrv/ConfigInfo.hpp: Fixed warnings found with gcc -Wshadow ndb/src/mgmsrv/InitConfigFileParser.cpp: Prefixed defaults_file, defaults_group_suffix and defaults_extra_file with 'my' to avoid conflicts with local variables in some functions ndb/src/mgmsrv/MgmtSrvr.cpp: Removed not used variables and functions ndb/src/mgmsrv/MgmtSrvr.hpp: Fixed compiler warnings ndb/src/mgmsrv/Services.cpp: Removed not used variables and functions ndb/src/mgmsrv/main.cpp: Removed not used variable ndb/src/ndbapi/ClusterMgr.hpp: Fixed compiler warnings ndb/src/ndbapi/Ndb.cpp: Removed not used variables ndb/src/ndbapi/NdbBlob.cpp: Removed not used variables ndb/src/ndbapi/NdbDictionaryImpl.cpp: Removed not used variables ndb/src/ndbapi/NdbIndexOperation.cpp: Removed not used variables ndb/src/ndbapi/NdbOperationDefine.cpp: Removed not used variables ndb/src/ndbapi/NdbOperationExec.cpp: Removed not used variables ndb/src/ndbapi/NdbOperationSearch.cpp: Removed not used variables ndb/src/ndbapi/NdbScanFilter.cpp: Fixed compiler warning ndb/src/ndbapi/NdbScanOperation.cpp: Removed not used variables ndb/src/ndbapi/SignalSender.cpp: Removed not used variables ndb/src/ndbapi/ndb_cluster_connection.cpp: Removed not used variable ndb/tools/delete_all.cpp: Removed not used variable ndb/tools/desc.cpp: Removed not used variable ndb/tools/drop_index.cpp: Removed not used variable ndb/tools/drop_tab.cpp: Removed not used variable ndb/tools/listTables.cpp: Removed not used variable ndb/tools/ndb_config.cpp: Fixed warnings found with gcc -Wshadow Added missing puts(desc) ndb/tools/restore/Restore.hpp: Changed delimiter to define instead of static variable, as the static variable caused a LOT of compiler warnings Fixed compiler warning ndb/tools/restore/consumer.hpp: Fixed compiler warning ndb/tools/restore/restore_main.cpp: Fixed compiler warnings ndb/tools/select_all.cpp: Removed not used variables ndb/tools/select_count.cpp: Removed not used variable server-tools/instance-manager/commands.h: Fixed compiler warnings server-tools/instance-manager/guardian.cc: Fixed compiler warnings server-tools/instance-manager/instance_options.cc: Removed not used variables server-tools/instance-manager/mysql_connection.cc: Fixed compiler warnings server-tools/instance-manager/options.cc: Fixed compiler warnings server-tools/instance-manager/options.h: Fixed compiler warnings server-tools/instance-manager/parse.cc: Removed not used variable server-tools/instance-manager/user_map.cc: Fixed compiler warnings server-tools/instance-manager/user_map.h: Fixed compiler warnings sql/field.cc: Fixed compiler warnings sql/field.h: Fixed compiler warnings sql/filesort.cc: Fixed compiler warnings sql/ha_archive.cc: Removed table and share arguments from get_share() / free_share() to get rid of compiler warnings sql/ha_archive.h: Removed table and share arguments from get_share() / free_share() to get rid of compiler warnings sql/ha_federated.cc: Fixed compiler warnings sql/ha_heap.cc: Fixed compiler warnings sql/ha_myisam.cc: Fixed compiler warnings sql/ha_myisammrg.cc: Fixed compiler warnings sql/ha_ndbcluster.cc: Fixed compiler warnings sql/handler.cc: Fixed compiler warnings sql/item.cc: Fixed compiler warnings sql/item.h: Fixed compiler warnings new_item() -> clone_item(), to avoid a lot of warnings with variable 'new_item' el() -> element_index() sql/item_cmpfunc.cc: Fixed compiler warnings sql/item_cmpfunc.h: Fixed compiler warnings sql/item_func.cc: Fixed compiler warnings sql/item_geofunc.cc: Fixed compiler warnings sql/item_row.h: Fixed compiler warnings sql/item_strfunc.cc: Fixed compiler warnings sql/item_subselect.cc: Fixed compiler warnings sql/item_subselect.h: Fixed compiler warnings sql/item_sum.cc: Fixed compiler warnings sql/item_timefunc.cc: Fixed compiler warnings sql/log.cc: Fixed compiler warnings More comments Added #ifdef HAVE_REPLICATION sql/log_event.cc: Fixed compiler warnings sql/log_event.h: Fixed compiler warnings sql/mysql_priv.h: query_id -> global_query_id, to avoid a lot of clashes with function and class variables start_time -> server_start_time sql/mysqld.cc: Fixed compiler warnings: - Removed not used variables - Added #ifndef EMBEDDED_LIBRARY - Fixed shadow warnings sql/net_serv.cc: Fixed compiler warnings sql/opt_range.cc: range -> last_range to avoid shadow warnings Removed not used function print_rowid() sql/opt_range.h: range -> last_range to avoid shadow warnings sql/password.c: Fixed compiler warnings sql/protocol.cc: Fixed compiler warnings sql/repl_failsafe.cc: Fixed compiler warnings sql/set_var.cc: Fixed compiler warnings sql/set_var.h: type() -> show_type() Fixed compiler warnings sql/slave.cc: Fixed compiler warnings sql/sp_head.cc: Fixed compiler warnings sql/sp_head.h: Fixed compiler warnings sql/spatial.cc: Fixed compiler warnings sql/spatial.h: length() -> geom_length() to avoid compiler warnings wkb_end -> wkb_last to avoid compiler warnings with local variables named 'wkb_end' sql/sql_cache.h: Fixed compiler warnings sql/sql_class.cc: Fixed compiler warnings sql/sql_class.h: log -> log_xid() to avoid compiler warnings Fixed shadow compiler warnings sql/sql_derived.cc: Removed not used variable sql/sql_insert.cc: Fixed compiler warnings sql/sql_lex.cc: Fixed compiler warnings sql/sql_lex.h: res -> saved_error to make the meaning of the variable clear and avoid shadow warnings sql/sql_load.cc: Fixed compiler warnings sql/sql_parse.cc: Fixed compiler warnings sql/sql_prepare.cc: Fixed compiler warnings sql/sql_select.cc: Fixed compiler warnings sql/sql_show.cc: Fixed compiler warnings sql/sql_string.cc: Fixed compiler warnings sql/sql_string.h: Fixed compiler warnings sql/sql_table.cc: Fixed compiler warnings sql/sql_trigger.cc: Fixed compiler warnings sql/sql_trigger.h: table -> trigger_table to avoid warnings from local variables sql/sql_union.cc: Fixed compiler warnings (mainly res -> saved_error) sql-common/client.c: Removed not used variable sql-common/my_time.c: Removed not used variable time -> my_time sql/sql_update.cc: Removed not used variable sql/sql_view.cc: Removed not used variable sql/sql_yacc.yy: Removed not used variable sql/table.cc: Removed not used variable sql/tztime.cc: Removed not used variable sql/unireg.cc: Removed not used variable strings/ctype-bin.c: mblen -> mb_len to avoid compiler warnings with local variable mblen strings/ctype-cp932.c: Fixed compiler warnings strings/ctype-eucjpms.c: Fixed compiler warnings strings/ctype-mb.c: mblen -> mb_len to avoid compiler warnings with local variable mblen strings/ctype-simple.c: mblen -> mb_len to avoid compiler warnings with local variable mblen exp -> exponent strings/ctype-sjis.c: Fixed compiler warnings strings/ctype-uca.c: mblen -> mb_len to avoid compiler warnings with local variable mblen strings/ctype-ujis.c: Fixed compiler warnings strings/ctype-utf8.c: Fixed compiler warnings strings/decimal.c: Fixed compiler warnings strings/my_vsnprintf.c: Added comment strings/strtod.c: Fixed compiler warnings tests/mysql_client_test.c: Fixed compiler warnings (Biggest part of patch is to not get a conflict with global function 'bind')
This commit is contained in:
@ -1730,7 +1730,7 @@ static int stmt_read_row_no_result_set(MYSQL_STMT *stmt, unsigned char **row);
|
||||
STMT_ATTR_UPDATE_MAX_LENGTH attribute is set.
|
||||
*/
|
||||
static void stmt_update_metadata(MYSQL_STMT *stmt, MYSQL_ROWS *data);
|
||||
static my_bool setup_one_fetch_function(MYSQL_BIND *bind, MYSQL_FIELD *field);
|
||||
static my_bool setup_one_fetch_function(MYSQL_BIND *, MYSQL_FIELD *field);
|
||||
|
||||
/* Auxilary function used to reset statement handle. */
|
||||
|
||||
@ -2166,7 +2166,7 @@ static void update_stmt_fields(MYSQL_STMT *stmt)
|
||||
MYSQL_FIELD *field= stmt->mysql->fields;
|
||||
MYSQL_FIELD *field_end= field + stmt->field_count;
|
||||
MYSQL_FIELD *stmt_field= stmt->fields;
|
||||
MYSQL_BIND *bind= stmt->bind_result_done ? stmt->bind : 0;
|
||||
MYSQL_BIND *my_bind= stmt->bind_result_done ? stmt->bind : 0;
|
||||
|
||||
DBUG_ASSERT(stmt->field_count == stmt->mysql->field_count);
|
||||
|
||||
@ -2177,10 +2177,10 @@ static void update_stmt_fields(MYSQL_STMT *stmt)
|
||||
stmt_field->type = field->type;
|
||||
stmt_field->flags = field->flags;
|
||||
stmt_field->decimals = field->decimals;
|
||||
if (bind)
|
||||
if (my_bind)
|
||||
{
|
||||
/* Ignore return value: it should be 0 if bind_result succeeded. */
|
||||
(void) setup_one_fetch_function(bind++, stmt_field);
|
||||
(void) setup_one_fetch_function(my_bind++, stmt_field);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3002,7 +3002,7 @@ static my_bool int_is_null_false= 0;
|
||||
mysql_stmt_bind_param()
|
||||
stmt statement handle
|
||||
The statement must be prepared with mysql_stmt_prepare().
|
||||
bind Array of mysql_stmt_param_count() bind parameters.
|
||||
my_bind Array of mysql_stmt_param_count() bind parameters.
|
||||
This function doesn't check that size of this argument
|
||||
is >= mysql_stmt_field_count(): it's user's responsibility.
|
||||
|
||||
@ -3077,65 +3077,66 @@ static my_bool int_is_null_false= 0;
|
||||
to point to the buffer of given type. Finally, additional actions
|
||||
may be taken for some types or use cases:
|
||||
|
||||
Binding integer types.
|
||||
For integer types you might also need to set MYSQL_BIND::is_unsigned
|
||||
member. Set it to TRUE when binding unsigned char, unsigned short,
|
||||
unsigned int, unsigned long, unsigned long long.
|
||||
Binding integer types.
|
||||
For integer types you might also need to set MYSQL_BIND::is_unsigned
|
||||
member. Set it to TRUE when binding unsigned char, unsigned short,
|
||||
unsigned int, unsigned long, unsigned long long.
|
||||
|
||||
Binding floating point types.
|
||||
For floating point types you just need to set
|
||||
MYSQL_BIND::buffer_type and MYSQL_BIND::buffer. The rest of the
|
||||
members should be zero-initialized.
|
||||
Binding floating point types.
|
||||
For floating point types you just need to set
|
||||
MYSQL_BIND::buffer_type and MYSQL_BIND::buffer. The rest of the
|
||||
members should be zero-initialized.
|
||||
|
||||
Binding NULLs.
|
||||
You might have a column always NULL, never NULL, or sometimes NULL.
|
||||
For an always NULL column set MYSQL_BIND::buffer_type to
|
||||
MYSQL_TYPE_NULL. The rest of the members just need to be
|
||||
zero-initialized. For never NULL columns set MYSQL_BIND::is_null to
|
||||
0, or this has already been done if you zero-initialized the entire
|
||||
structure. If you set MYSQL_TYPE::is_null to point to an
|
||||
application buffer of type 'my_bool', then this buffer will be
|
||||
checked on each execution: this way you can set the buffer to TRUE,
|
||||
or any non-0 value for NULLs, and to FALSE or 0 for not NULL data.
|
||||
Binding NULLs.
|
||||
You might have a column always NULL, never NULL, or sometimes
|
||||
NULL. For an always NULL column set MYSQL_BIND::buffer_type to
|
||||
MYSQL_TYPE_NULL. The rest of the members just need to be
|
||||
zero-initialized. For never NULL columns set
|
||||
MYSQL_BIND::is_null to 0, or this has already been done if you
|
||||
zero-initialized the entire structure. If you set
|
||||
MYSQL_TYPE::is_null to point to an application buffer of type
|
||||
'my_bool', then this buffer will be checked on each execution:
|
||||
this way you can set the buffer to TRUE, or any non-0 value for
|
||||
NULLs, and to FALSE or 0 for not NULL data.
|
||||
|
||||
Binding text strings and sequences of bytes.
|
||||
For strings, in addition to MYSQL_BIND::buffer_type and
|
||||
MYSQL_BIND::buffer you need to set MYSQL_BIND::length or
|
||||
MYSQL_BIND::buffer_length.
|
||||
If 'length' is set, 'buffer_length' is ignored. 'buffer_length'
|
||||
member should be used when size of string doesn't change between
|
||||
executions. If you want to vary buffer length for each value, set
|
||||
'length' to point to an application buffer of type 'unsigned long'
|
||||
and set this long to length of the string before each
|
||||
mysql_stmt_execute().
|
||||
Binding text strings and sequences of bytes.
|
||||
For strings, in addition to MYSQL_BIND::buffer_type and
|
||||
MYSQL_BIND::buffer you need to set MYSQL_BIND::length or
|
||||
MYSQL_BIND::buffer_length. If 'length' is set, 'buffer_length'
|
||||
is ignored. 'buffer_length' member should be used when size of
|
||||
string doesn't change between executions. If you want to vary
|
||||
buffer length for each value, set 'length' to point to an
|
||||
application buffer of type 'unsigned long' and set this long to
|
||||
length of the string before each mysql_stmt_execute().
|
||||
|
||||
Binding dates and times.
|
||||
For binding dates and times prepared statements API provides clients
|
||||
with MYSQL_TIME structure. A pointer to instance of this structure
|
||||
should be assigned to MYSQL_BIND::buffer whenever MYSQL_TYPE_TIME,
|
||||
MYSQL_TYPE_DATE, MYSQL_TYPE_DATETIME typecodes are used. When
|
||||
typecode is MYSQL_TYPE_TIME, only members 'hour', 'minute', 'second'
|
||||
and 'neg' (is time offset negative) are used. These members only
|
||||
will be sent to the server.
|
||||
MYSQL_TYPE_DATE implies use of 'year', 'month', 'day', 'neg'.
|
||||
MYSQL_TYPE_DATETIME utilizes both parts of MYSQL_TIME structure.
|
||||
You don't have to set MYSQL_TIME::time_type member: it's not used
|
||||
when sending data to the server, typecode information is enough.
|
||||
'second_part' member can hold microsecond precision of time value,
|
||||
but now it's only supported on protocol level: you can't store
|
||||
microsecond in a column, or use in temporal calculations. However,
|
||||
if you send a time value with microsecond part for 'SELECT ?',
|
||||
statement, you'll get it back unchanged from the server.
|
||||
Binding dates and times.
|
||||
For binding dates and times prepared statements API provides
|
||||
clients with MYSQL_TIME structure. A pointer to instance of this
|
||||
structure should be assigned to MYSQL_BIND::buffer whenever
|
||||
MYSQL_TYPE_TIME, MYSQL_TYPE_DATE, MYSQL_TYPE_DATETIME typecodes
|
||||
are used. When typecode is MYSQL_TYPE_TIME, only members
|
||||
'hour', 'minute', 'second' and 'neg' (is time offset negative)
|
||||
are used. These members only will be sent to the server.
|
||||
MYSQL_TYPE_DATE implies use of 'year', 'month', 'day', 'neg'.
|
||||
MYSQL_TYPE_DATETIME utilizes both parts of MYSQL_TIME structure.
|
||||
You don't have to set MYSQL_TIME::time_type member: it's not
|
||||
used when sending data to the server, typecode information is
|
||||
enough. 'second_part' member can hold microsecond precision of
|
||||
time value, but now it's only supported on protocol level: you
|
||||
can't store microsecond in a column, or use in temporal
|
||||
calculations. However, if you send a time value with microsecond
|
||||
part for 'SELECT ?', statement, you'll get it back unchanged
|
||||
from the server.
|
||||
|
||||
Data conversion.
|
||||
If conversion from host language type to data representation,
|
||||
corresponding to SQL type, is required it's done on the server.
|
||||
Data truncation is possible when conversion is lossy. For example,
|
||||
if you supply MYSQL_TYPE_DATETIME value out of valid SQL type
|
||||
TIMESTAMP range, the same conversion will be applied as if this
|
||||
value would have been sent as string in the old protocol.
|
||||
TODO: document how the server will behave in case of truncation/data
|
||||
loss.
|
||||
Data conversion.
|
||||
If conversion from host language type to data representation,
|
||||
corresponding to SQL type, is required it's done on the server.
|
||||
Data truncation is possible when conversion is lossy. For
|
||||
example, if you supply MYSQL_TYPE_DATETIME value out of valid
|
||||
SQL type TIMESTAMP range, the same conversion will be applied as
|
||||
if this value would have been sent as string in the old
|
||||
protocol. TODO: document how the server will behave in case of
|
||||
truncation/data loss.
|
||||
|
||||
After variables were bound, you can repeatedly set/change their
|
||||
values and mysql_stmt_execute() the statement.
|
||||
@ -3163,7 +3164,7 @@ static my_bool int_is_null_false= 0;
|
||||
1 error, can be retrieved with mysql_stmt_error.
|
||||
*/
|
||||
|
||||
my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind)
|
||||
my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *my_bind)
|
||||
{
|
||||
uint count=0;
|
||||
MYSQL_BIND *param, *end;
|
||||
@ -3180,7 +3181,7 @@ my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind)
|
||||
}
|
||||
|
||||
/* Allocated on prepare */
|
||||
memcpy((char*) stmt->params, (char*) bind,
|
||||
memcpy((char*) stmt->params, (char*) my_bind,
|
||||
sizeof(MYSQL_BIND) * stmt->param_count);
|
||||
|
||||
for (param= stmt->params, end= param+stmt->param_count;
|
||||
@ -3343,8 +3344,7 @@ mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number,
|
||||
}
|
||||
|
||||
param= stmt->params+param_number;
|
||||
if (param->buffer_type < MYSQL_TYPE_TINY_BLOB ||
|
||||
param->buffer_type > MYSQL_TYPE_STRING)
|
||||
if (!IS_LONGDATA(param->buffer_type))
|
||||
{
|
||||
/* Long data handling should be used only for string/binary types */
|
||||
strmov(stmt->sqlstate, unknown_sqlstate);
|
||||
@ -3508,7 +3508,7 @@ static void fetch_string_with_conversion(MYSQL_BIND *param, char *value,
|
||||
This function should support all target buffer types: the rest
|
||||
of conversion functions can delegate conversion to it.
|
||||
*/
|
||||
switch(param->buffer_type) {
|
||||
switch (param->buffer_type) {
|
||||
case MYSQL_TYPE_NULL: /* do nothing */
|
||||
break;
|
||||
case MYSQL_TYPE_TINY:
|
||||
@ -3850,32 +3850,32 @@ static void fetch_float_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field,
|
||||
|
||||
static void fetch_datetime_with_conversion(MYSQL_BIND *param,
|
||||
MYSQL_FIELD *field,
|
||||
MYSQL_TIME *time)
|
||||
MYSQL_TIME *my_time)
|
||||
{
|
||||
switch (param->buffer_type) {
|
||||
case MYSQL_TYPE_NULL: /* do nothing */
|
||||
break;
|
||||
case MYSQL_TYPE_DATE:
|
||||
*(MYSQL_TIME *)(param->buffer)= *time;
|
||||
*param->error= time->time_type != MYSQL_TIMESTAMP_DATE;
|
||||
*(MYSQL_TIME *)(param->buffer)= *my_time;
|
||||
*param->error= my_time->time_type != MYSQL_TIMESTAMP_DATE;
|
||||
break;
|
||||
case MYSQL_TYPE_TIME:
|
||||
*(MYSQL_TIME *)(param->buffer)= *time;
|
||||
*param->error= time->time_type != MYSQL_TIMESTAMP_TIME;
|
||||
*(MYSQL_TIME *)(param->buffer)= *my_time;
|
||||
*param->error= my_time->time_type != MYSQL_TIMESTAMP_TIME;
|
||||
break;
|
||||
case MYSQL_TYPE_DATETIME:
|
||||
case MYSQL_TYPE_TIMESTAMP:
|
||||
*(MYSQL_TIME *)(param->buffer)= *time;
|
||||
*(MYSQL_TIME *)(param->buffer)= *my_time;
|
||||
/* No error: time and date are compatible with datetime */
|
||||
break;
|
||||
case MYSQL_TYPE_YEAR:
|
||||
shortstore(param->buffer, time->year);
|
||||
shortstore(param->buffer, my_time->year);
|
||||
*param->error= 1;
|
||||
break;
|
||||
case MYSQL_TYPE_FLOAT:
|
||||
case MYSQL_TYPE_DOUBLE:
|
||||
{
|
||||
ulonglong value= TIME_to_ulonglong(time);
|
||||
ulonglong value= TIME_to_ulonglong(my_time);
|
||||
fetch_float_with_conversion(param, field,
|
||||
ulonglong2double(value), DBL_DIG);
|
||||
break;
|
||||
@ -3886,7 +3886,7 @@ static void fetch_datetime_with_conversion(MYSQL_BIND *param,
|
||||
case MYSQL_TYPE_LONG:
|
||||
case MYSQL_TYPE_LONGLONG:
|
||||
{
|
||||
longlong value= (longlong) TIME_to_ulonglong(time);
|
||||
longlong value= (longlong) TIME_to_ulonglong(my_time);
|
||||
fetch_long_with_conversion(param, field, value, TRUE);
|
||||
break;
|
||||
}
|
||||
@ -3897,7 +3897,7 @@ static void fetch_datetime_with_conversion(MYSQL_BIND *param,
|
||||
fetch_string_with_conversion:
|
||||
*/
|
||||
char buff[MAX_DATE_STRING_REP_LENGTH];
|
||||
uint length= my_TIME_to_str(time, buff);
|
||||
uint length= my_TIME_to_str(my_time, buff);
|
||||
/* Resort to string conversion */
|
||||
fetch_string_with_conversion(param, (char *)buff, length);
|
||||
break;
|
||||
@ -4263,6 +4263,8 @@ static my_bool is_binary_compatible(enum enum_field_types type1,
|
||||
|
||||
static my_bool setup_one_fetch_function(MYSQL_BIND *param, MYSQL_FIELD *field)
|
||||
{
|
||||
DBUG_ENTER("setup_one_fetch_function");
|
||||
|
||||
/* Setup data copy functions for the different supported types */
|
||||
switch (param->buffer_type) {
|
||||
case MYSQL_TYPE_NULL: /* for dummy binds */
|
||||
@ -4327,7 +4329,9 @@ static my_bool setup_one_fetch_function(MYSQL_BIND *param, MYSQL_FIELD *field)
|
||||
param->fetch_result= fetch_result_str;
|
||||
break;
|
||||
default:
|
||||
return TRUE;
|
||||
DBUG_PRINT("error", ("Unknown param->buffer_type: %u",
|
||||
(uint) param->buffer_type));
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
if (! is_binary_compatible(param->buffer_type, field->type))
|
||||
param->fetch_result= fetch_result_with_conversion;
|
||||
@ -4396,9 +4400,10 @@ static my_bool setup_one_fetch_function(MYSQL_BIND *param, MYSQL_FIELD *field)
|
||||
param->skip_result= skip_result_string;
|
||||
break;
|
||||
default:
|
||||
return TRUE;
|
||||
DBUG_PRINT("error", ("Unknown field->type: %u", (uint) field->type));
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
return FALSE;
|
||||
DBUG_RETURN(FALSE);
|
||||
}
|
||||
|
||||
|
||||
@ -4406,7 +4411,7 @@ static my_bool setup_one_fetch_function(MYSQL_BIND *param, MYSQL_FIELD *field)
|
||||
Setup the bind buffers for resultset processing
|
||||
*/
|
||||
|
||||
my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
|
||||
my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *my_bind)
|
||||
{
|
||||
MYSQL_BIND *param, *end;
|
||||
MYSQL_FIELD *field;
|
||||
@ -4430,8 +4435,9 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
|
||||
is called from mysql_stmt_store_result.
|
||||
*/
|
||||
|
||||
if (stmt->bind != bind)
|
||||
memcpy((char*) stmt->bind, (char*) bind, sizeof(MYSQL_BIND) * bind_count);
|
||||
if (stmt->bind != my_bind)
|
||||
memcpy((char*) stmt->bind, (char*) my_bind,
|
||||
sizeof(MYSQL_BIND) * bind_count);
|
||||
|
||||
for (param= stmt->bind, end= param + bind_count, field= stmt->fields ;
|
||||
param < end ;
|
||||
@ -4478,7 +4484,7 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
|
||||
|
||||
static int stmt_fetch_row(MYSQL_STMT *stmt, uchar *row)
|
||||
{
|
||||
MYSQL_BIND *bind, *end;
|
||||
MYSQL_BIND *my_bind, *end;
|
||||
MYSQL_FIELD *field;
|
||||
uchar *null_ptr, bit;
|
||||
int truncation_count= 0;
|
||||
@ -4500,11 +4506,12 @@ static int stmt_fetch_row(MYSQL_STMT *stmt, uchar *row)
|
||||
bit= 4; /* first 2 bits are reserved */
|
||||
|
||||
/* Copy complete row to application buffers */
|
||||
for (bind= stmt->bind, end= bind + stmt->field_count, field= stmt->fields ;
|
||||
bind < end ;
|
||||
bind++, field++)
|
||||
for (my_bind= stmt->bind, end= my_bind + stmt->field_count,
|
||||
field= stmt->fields ;
|
||||
my_bind < end ;
|
||||
my_bind++, field++)
|
||||
{
|
||||
*bind->error= 0;
|
||||
*my_bind->error= 0;
|
||||
if (*null_ptr & bit)
|
||||
{
|
||||
/*
|
||||
@ -4514,15 +4521,15 @@ static int stmt_fetch_row(MYSQL_STMT *stmt, uchar *row)
|
||||
mysql_stmt_fetch_column, and in this case nullness of column will be
|
||||
lost. See mysql_stmt_fetch_column for details.
|
||||
*/
|
||||
bind->row_ptr= NULL;
|
||||
*bind->is_null= 1;
|
||||
my_bind->row_ptr= NULL;
|
||||
*my_bind->is_null= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
*bind->is_null= 0;
|
||||
bind->row_ptr= row;
|
||||
(*bind->fetch_result)(bind, field, &row);
|
||||
truncation_count+= *bind->error;
|
||||
*my_bind->is_null= 0;
|
||||
my_bind->row_ptr= row;
|
||||
(*my_bind->fetch_result)(my_bind, field, &row);
|
||||
truncation_count+= *my_bind->error;
|
||||
}
|
||||
if (!((bit<<=1) & 255))
|
||||
{
|
||||
@ -4579,7 +4586,7 @@ int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt)
|
||||
SYNOPSIS
|
||||
mysql_stmt_fetch_column()
|
||||
stmt Prepared statement handler
|
||||
bind Where data should be placed. Should be filled in as
|
||||
my_bind Where data should be placed. Should be filled in as
|
||||
when calling mysql_stmt_bind_result()
|
||||
column Column to fetch (first column is 0)
|
||||
ulong offset Offset in result data (to fetch blob in pieces)
|
||||
@ -4589,7 +4596,7 @@ int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt)
|
||||
1 error
|
||||
*/
|
||||
|
||||
int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind,
|
||||
int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *my_bind,
|
||||
uint column, ulong offset)
|
||||
{
|
||||
MYSQL_BIND *param= stmt->bind+column;
|
||||
@ -4606,26 +4613,26 @@ int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind,
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
|
||||
if (!bind->error)
|
||||
bind->error= &bind->error_value;
|
||||
*bind->error= 0;
|
||||
if (!my_bind->error)
|
||||
my_bind->error= &my_bind->error_value;
|
||||
*my_bind->error= 0;
|
||||
if (param->row_ptr)
|
||||
{
|
||||
MYSQL_FIELD *field= stmt->fields+column;
|
||||
uchar *row= param->row_ptr;
|
||||
bind->offset= offset;
|
||||
if (bind->is_null)
|
||||
*bind->is_null= 0;
|
||||
if (bind->length) /* Set the length if non char/binary types */
|
||||
*bind->length= *param->length;
|
||||
my_bind->offset= offset;
|
||||
if (my_bind->is_null)
|
||||
*my_bind->is_null= 0;
|
||||
if (my_bind->length) /* Set the length if non char/binary types */
|
||||
*my_bind->length= *param->length;
|
||||
else
|
||||
bind->length= ¶m->length_value; /* Needed for fetch_result() */
|
||||
fetch_result_with_conversion(bind, field, &row);
|
||||
my_bind->length= ¶m->length_value; /* Needed for fetch_result() */
|
||||
fetch_result_with_conversion(my_bind, field, &row);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bind->is_null)
|
||||
*bind->is_null= 1;
|
||||
if (my_bind->is_null)
|
||||
*my_bind->is_null= 1;
|
||||
}
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
@ -4697,7 +4704,7 @@ err:
|
||||
|
||||
static void stmt_update_metadata(MYSQL_STMT *stmt, MYSQL_ROWS *data)
|
||||
{
|
||||
MYSQL_BIND *bind, *end;
|
||||
MYSQL_BIND *my_bind, *end;
|
||||
MYSQL_FIELD *field;
|
||||
uchar *null_ptr, bit;
|
||||
uchar *row= (uchar*) data->data;
|
||||
@ -4710,12 +4717,12 @@ static void stmt_update_metadata(MYSQL_STMT *stmt, MYSQL_ROWS *data)
|
||||
bit= 4; /* first 2 bits are reserved */
|
||||
|
||||
/* Go through all fields and calculate metadata */
|
||||
for (bind= stmt->bind, end= bind + stmt->field_count, field= stmt->fields ;
|
||||
bind < end ;
|
||||
bind++, field++)
|
||||
for (my_bind= stmt->bind, end= my_bind + stmt->field_count, field= stmt->fields ;
|
||||
my_bind < end ;
|
||||
my_bind++, field++)
|
||||
{
|
||||
if (!(*null_ptr & bit))
|
||||
(*bind->skip_result)(bind, field, &row);
|
||||
(*my_bind->skip_result)(my_bind, field, &row);
|
||||
DBUG_ASSERT(row <= row_end);
|
||||
if (!((bit<<=1) & 255))
|
||||
{
|
||||
@ -4779,16 +4786,17 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt)
|
||||
We must initalize the bind structure to be able to calculate
|
||||
max_length
|
||||
*/
|
||||
MYSQL_BIND *bind, *end;
|
||||
MYSQL_BIND *my_bind, *end;
|
||||
MYSQL_FIELD *field;
|
||||
bzero((char*) stmt->bind, sizeof(*stmt->bind)* stmt->field_count);
|
||||
|
||||
for (bind= stmt->bind, end= bind + stmt->field_count, field= stmt->fields;
|
||||
bind < end ;
|
||||
bind++, field++)
|
||||
for (my_bind= stmt->bind, end= my_bind + stmt->field_count,
|
||||
field= stmt->fields;
|
||||
my_bind < end ;
|
||||
my_bind++, field++)
|
||||
{
|
||||
bind->buffer_type= MYSQL_TYPE_NULL;
|
||||
bind->buffer_length=1;
|
||||
my_bind->buffer_type= MYSQL_TYPE_NULL;
|
||||
my_bind->buffer_length=1;
|
||||
}
|
||||
|
||||
if (mysql_stmt_bind_result(stmt, stmt->bind))
|
||||
|
Reference in New Issue
Block a user