mirror of
https://github.com/MariaDB/server.git
synced 2025-06-13 13:01:51 +03:00
Cleanup after split of libmysql.c to client.c and libmysql.c. A 4.1 master/slave will now use the 4.1 protocol
Fixed wrong value for SQLSTATE_LENGTH Added CLIENT_REMEMBER_OPTIONS to mysql_real_connect() Changed mysql_port and mysql_unix_port to mysqld_xxxx client/mysql.cc: Removed valgrind & compiler warnings client/sql_string.h: Fix to remove valgrind warnings include/mysql.h: Added read_timeout and write_timeout to mysql options struct. This is to be used for slave when connection to master. code cleanup include/mysql_com.h: Fixed wrong value for SQLSTATE_LENGTH Added CLIENT_REMEMBER_OPTIONS include/sql_common.h: Cleanup after split of libmysql.c to client.c and libmysql.c include/sql_state.h: Removed default states libmysql/client_settings.h: Cleanup after split of libmysql.c to client.c and libmysql.c libmysql/libmysql.c: Cleanup after split of libmysql.c to client.c and libmysql.c mysql-test/r/type_blob.result: Update results after someone updated error messages without running tests mysys/charset.c: More debug information mysys/errors.c: Fixed wrong error message sql-common/client.c: Cleanup after split of libmysql.c to client.c and libmysql.c sql/Makefile.am: Added sql_client.cc sql/client_settings.h: Cleanup after split of libmysql.c to client.c and libmysql.c sql/log.cc: Changed mysql_port and mysql_unix_port to mysqld_xxxx sql/mysql_priv.h: Changed mysql_port and mysql_unix_port to mysqld_xxxx sql/mysqld.cc: Changed mysql_port and mysql_unix_port to mysqld_xxxx sql/protocol.cc: Fix for SQLSTATE_LENGTH Moved function to sql_client.c sql/repl_failsafe.cc: Cleanup after split of libmysql.c to client.c and libmysql.c sql/set_var.cc: Changed mysql_port and mysql_unix_port to mysqld_xxxx sql/slave.cc: Cleanup after split of libmysql.c to client.c and libmysql.c
This commit is contained in:
@ -59,24 +59,11 @@
|
||||
|
||||
#include <sql_common.h>
|
||||
|
||||
uint mysql_port=0;
|
||||
my_string mysql_unix_port=0;
|
||||
ulong net_buffer_length=8192;
|
||||
ulong max_allowed_packet= 1024L*1024L*1024L;
|
||||
ulong net_read_timeout= NET_READ_TIMEOUT;
|
||||
ulong net_write_timeout= NET_WRITE_TIMEOUT;
|
||||
|
||||
#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG \
|
||||
| CLIENT_LOCAL_FILES | CLIENT_TRANSACTIONS \
|
||||
| CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION)
|
||||
|
||||
|
||||
#ifdef __WIN__
|
||||
#define CONNECT_TIMEOUT 20
|
||||
#else
|
||||
#define CONNECT_TIMEOUT 0
|
||||
#endif
|
||||
|
||||
#if defined(MSDOS) || defined(__WIN__)
|
||||
/* socket_errno is defined in my_global.h for all platforms */
|
||||
#define perror(A)
|
||||
@ -85,10 +72,6 @@ ulong net_write_timeout= NET_WRITE_TIMEOUT;
|
||||
#define SOCKET_ERROR -1
|
||||
#endif /* __WIN__ */
|
||||
|
||||
const char *sql_protocol_names_lib[] =
|
||||
{ "TCP", "SOCKET", "PIPE", "MEMORY", NullS };
|
||||
TYPELIB sql_protocol_typelib = {array_elements(sql_protocol_names_lib)-1,"",
|
||||
sql_protocol_names_lib};
|
||||
/*
|
||||
If allowed through some configuration, then this needs to
|
||||
be changed
|
||||
@ -101,7 +84,67 @@ sig_handler pipe_sig_handler(int sig);
|
||||
static ulong mysql_sub_escape_string(CHARSET_INFO *charset_info, char *to,
|
||||
const char *from, ulong length);
|
||||
my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list);
|
||||
static my_bool org_my_init_done=0;
|
||||
|
||||
/*
|
||||
Initialize the MySQL library
|
||||
|
||||
SYNOPSIS
|
||||
mysql_once_init()
|
||||
|
||||
NOTES
|
||||
Can't be static on NetWare
|
||||
This function is called by mysql_init() and indirectly called
|
||||
by mysql_real_query(), so one should never have to call this from an
|
||||
outside program.
|
||||
*/
|
||||
|
||||
static my_bool mysql_client_init= 0;
|
||||
static my_bool org_my_init_done= 0;
|
||||
|
||||
void mysql_once_init(void)
|
||||
{
|
||||
if (!mysql_client_init)
|
||||
{
|
||||
mysql_client_init=1;
|
||||
org_my_init_done=my_init_done;
|
||||
my_init(); /* Will init threads */
|
||||
init_client_errs();
|
||||
if (!mysql_port)
|
||||
{
|
||||
mysql_port = MYSQL_PORT;
|
||||
#ifndef MSDOS
|
||||
{
|
||||
struct servent *serv_ptr;
|
||||
char *env;
|
||||
if ((serv_ptr = getservbyname("mysql", "tcp")))
|
||||
mysql_port = (uint) ntohs((ushort) serv_ptr->s_port);
|
||||
if ((env = getenv("MYSQL_TCP_PORT")))
|
||||
mysql_port =(uint) atoi(env);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (!mysql_unix_port)
|
||||
{
|
||||
char *env;
|
||||
#ifdef __WIN__
|
||||
mysql_unix_port = (char*) MYSQL_NAMEDPIPE;
|
||||
#else
|
||||
mysql_unix_port = (char*) MYSQL_UNIX_ADDR;
|
||||
#endif
|
||||
if ((env = getenv("MYSQL_UNIX_PORT")))
|
||||
mysql_unix_port = env;
|
||||
}
|
||||
mysql_debug(NullS);
|
||||
#if defined(SIGPIPE) && !defined(THREAD) && !defined(__WIN__)
|
||||
(void) signal(SIGPIPE,SIG_IGN);
|
||||
#endif
|
||||
}
|
||||
#ifdef THREAD
|
||||
else
|
||||
my_thread_init(); /* Init if new thread */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int STDCALL mysql_server_init(int argc __attribute__((unused)),
|
||||
char **argv __attribute__((unused)),
|
||||
@ -529,30 +572,6 @@ STDCALL mysql_rpl_query_type(const char* q, int len)
|
||||
return MYSQL_RPL_MASTER; /* By default, send to master */
|
||||
}
|
||||
|
||||
/*
|
||||
Fill in SSL part of MYSQL structure and set 'use_ssl' flag.
|
||||
NB! Errors are not reported until you do mysql_real_connect.
|
||||
*/
|
||||
|
||||
#define strdup_if_not_null(A) (A) == 0 ? 0 : my_strdup((A),MYF(MY_WME))
|
||||
|
||||
my_bool STDCALL
|
||||
mysql_ssl_set(MYSQL *mysql __attribute__((unused)) ,
|
||||
const char *key __attribute__((unused)),
|
||||
const char *cert __attribute__((unused)),
|
||||
const char *ca __attribute__((unused)),
|
||||
const char *capath __attribute__((unused)),
|
||||
const char *cipher __attribute__((unused)))
|
||||
{
|
||||
#ifdef HAVE_OPENSSL
|
||||
mysql->options.ssl_key= strdup_if_not_null(key);
|
||||
mysql->options.ssl_cert= strdup_if_not_null(cert);
|
||||
mysql->options.ssl_ca= strdup_if_not_null(ca);
|
||||
mysql->options.ssl_capath= strdup_if_not_null(capath);
|
||||
mysql->options.ssl_cipher= strdup_if_not_null(cipher);
|
||||
#endif /* HAVE_OPENSSL */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Connect to sql server
|
||||
@ -578,6 +597,7 @@ mysql_connect(MYSQL *mysql,const char *host,
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
Change user and database
|
||||
**************************************************************************/
|
||||
@ -836,56 +856,6 @@ STDCALL mysql_add_slave(MYSQL* mysql, const char* host,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Alloc struct for use with unbuffered reads. Data is fetched by domand
|
||||
when calling to mysql_fetch_row.
|
||||
mysql_data_seek is a noop.
|
||||
|
||||
No other queries may be specified with the same MYSQL handle.
|
||||
There shouldn't be much processing per row because mysql server shouldn't
|
||||
have to wait for the client (and will not wait more than 30 sec/packet).
|
||||
**************************************************************************/
|
||||
|
||||
MYSQL_RES * STDCALL
|
||||
mysql_use_result(MYSQL *mysql)
|
||||
{
|
||||
MYSQL_RES *result;
|
||||
DBUG_ENTER("mysql_use_result");
|
||||
|
||||
mysql = mysql->last_used_con;
|
||||
|
||||
if (!mysql->fields)
|
||||
DBUG_RETURN(0);
|
||||
if (mysql->status != MYSQL_STATUS_GET_RESULT)
|
||||
{
|
||||
strmov(mysql->net.sqlstate, unknown_sqlstate);
|
||||
strmov(mysql->net.last_error,
|
||||
ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC));
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result)+
|
||||
sizeof(ulong)*mysql->field_count,
|
||||
MYF(MY_WME | MY_ZEROFILL))))
|
||||
DBUG_RETURN(0);
|
||||
result->lengths=(ulong*) (result+1);
|
||||
if (!(result->row=(MYSQL_ROW)
|
||||
my_malloc(sizeof(result->row[0])*(mysql->field_count+1), MYF(MY_WME))))
|
||||
{ /* Ptrs: to one row */
|
||||
my_free((gptr) result,MYF(0));
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
result->fields= mysql->fields;
|
||||
result->field_alloc= mysql->field_alloc;
|
||||
result->field_count= mysql->field_count;
|
||||
result->current_field=0;
|
||||
result->handle= mysql;
|
||||
result->current_row= 0;
|
||||
mysql->fields=0; /* fields is now in result */
|
||||
mysql->status=MYSQL_STATUS_USE_RESULT;
|
||||
DBUG_RETURN(result); /* Data is read to be fetched */
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
Return next field of the query results
|
||||
@ -899,6 +869,13 @@ mysql_fetch_field(MYSQL_RES *result)
|
||||
return &result->fields[result->current_field++];
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
Get column lengths of the current row
|
||||
If one uses mysql_use_result, res->lengths contains the length information,
|
||||
else the lengths are calculated from the offset between pointers.
|
||||
**************************************************************************/
|
||||
|
||||
ulong * STDCALL
|
||||
mysql_fetch_lengths(MYSQL_RES *res)
|
||||
{
|
||||
@ -911,6 +888,23 @@ mysql_fetch_lengths(MYSQL_RES *res)
|
||||
return res->lengths;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
Move to a specific row and column
|
||||
**************************************************************************/
|
||||
|
||||
void STDCALL
|
||||
mysql_data_seek(MYSQL_RES *result, my_ulonglong row)
|
||||
{
|
||||
MYSQL_ROWS *tmp=0;
|
||||
DBUG_PRINT("info",("mysql_data_seek(%ld)",(long) row));
|
||||
if (result->data)
|
||||
for (tmp=result->data->data; row-- && tmp ; tmp = tmp->next) ;
|
||||
result->current_row=0;
|
||||
result->data_cursor = tmp;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
put the row or field cursor one a position one got from mysql_row_tell()
|
||||
This doesn't restore any data. The next mysql_fetch_row or
|
||||
@ -935,6 +929,7 @@ mysql_field_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET field_offset)
|
||||
return return_value;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
List all databases
|
||||
*****************************************************************************/
|
||||
@ -2444,7 +2439,7 @@ static void send_data_long(MYSQL_BIND *param, longlong value)
|
||||
}
|
||||
default:
|
||||
{
|
||||
char tmp[12];
|
||||
char tmp[22]; /* Enough for longlong */
|
||||
uint length= (uint)(longlong10_to_str(value,(char *)tmp,10)-tmp);
|
||||
ulong copy_length= min((ulong)length-param->offset, param->buffer_length);
|
||||
memcpy(buffer, (char *)tmp+param->offset, copy_length);
|
||||
@ -2492,7 +2487,7 @@ static void send_data_double(MYSQL_BIND *param, double value)
|
||||
}
|
||||
default:
|
||||
{
|
||||
char tmp[12];
|
||||
char tmp[128];
|
||||
uint length= my_sprintf(tmp,(tmp,"%g",value));
|
||||
ulong copy_length= min((ulong)length-param->offset, param->buffer_length);
|
||||
memcpy(buffer, (char *)tmp+param->offset, copy_length);
|
||||
|
Reference in New Issue
Block a user