#include <my_global.h>#include "mysql.h"#include <my_sys.h>#include <mysys_err.h>#include <m_string.h>#include <m_ctype.h>#include "mysql_version.h"#include "mysqld_error.h"#include "errmsg.h"#include <violite.h>#include <sys/stat.h>#include <signal.h>#include <time.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netdb.h>#include <errno.h>#include "client_settings.h"#include <sql_common.h>Include dependency graph for client.c:

Go to the source code of this file.
Defines | |
| #define | CLI_MYSQL_REAL_CONNECT STDCALL mysql_real_connect |
| #define | SOCKET_ERROR -1 |
| #define | CONNECT_TIMEOUT 0 |
| #define | strdup_if_not_null(A) (A) == 0 ? 0 : my_strdup((A),MYF(MY_WME)) |
Functions | |
| static void | mysql_close_free_options (MYSQL *mysql) |
| static void | mysql_close_free (MYSQL *mysql) |
| static int | wait_for_data (my_socket fd, uint timeout) |
| int | my_connect (my_socket fd, const struct sockaddr *name, uint namelen, uint timeout) |
| ulong | cli_safe_read (MYSQL *mysql) |
| void | free_rows (MYSQL_DATA *cur) |
| my_bool | cli_advanced_command (MYSQL *mysql, enum enum_server_command command, const char *header, ulong header_length, const char *arg, ulong arg_length, my_bool skip_check, MYSQL_STMT *stmt __attribute__((unused))) |
| void | free_old_query (MYSQL *mysql) |
| void | set_mysql_error (MYSQL *mysql, int errcode, const char *sqlstate) |
| static void | cli_flush_use_result (MYSQL *mysql) |
| void | end_server (MYSQL *mysql) |
| void STDCALL | mysql_free_result (MYSQL_RES *result) |
| static int | add_init_command (struct st_mysql_options *options, const char *cmd) |
| void | mysql_read_default_options (struct st_mysql_options *options, const char *filename, const char *group) |
| static void | cli_fetch_lengths (ulong *to, MYSQL_ROW column, unsigned int field_count) |
| MYSQL_FIELD * | unpack_fields (MYSQL_DATA *data, MEM_ROOT *alloc, uint fields, my_bool default_value, uint server_capabilities) |
| MYSQL_DATA * | cli_read_rows (MYSQL *mysql, MYSQL_FIELD *mysql_fields, unsigned int fields) |
| static int | read_one_row (MYSQL *mysql, uint fields, MYSQL_ROW row, ulong *lengths) |
| MYSQL *STDCALL | mysql_init (MYSQL *mysql) |
| 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))) |
| const char *STDCALL | mysql_get_ssl_cipher (MYSQL *mysql) |
| static my_bool | cli_read_query_result (MYSQL *mysql) |
| static MYSQL_RES * | cli_use_result (MYSQL *mysql) |
| C_MODE_START int | mysql_init_character_set (MYSQL *mysql) |
| C_MODE_END MYSQL *STDCALL | CLI_MYSQL_REAL_CONNECT (MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, uint port, const char *unix_socket, ulong client_flag) |
| static void | mysql_fix_pointers (MYSQL *mysql, MYSQL *old_mysql) |
| my_bool | mysql_reconnect (MYSQL *mysql) |
| int STDCALL | mysql_select_db (MYSQL *mysql, const char *db) |
| void | mysql_detach_stmt_list (LIST **stmt_list __attribute__((unused))) |
| void STDCALL | mysql_close (MYSQL *mysql) |
| int STDCALL | mysql_send_query (MYSQL *mysql, const char *query, ulong length) |
| int STDCALL | mysql_real_query (MYSQL *mysql, const char *query, ulong length) |
| MYSQL_RES *STDCALL | mysql_store_result (MYSQL *mysql) |
| MYSQL_ROW STDCALL | mysql_fetch_row (MYSQL_RES *res) |
| ulong *STDCALL | mysql_fetch_lengths (MYSQL_RES *res) |
| int STDCALL | mysql_options (MYSQL *mysql, enum mysql_option option, const char *arg) |
| my_ulonglong STDCALL | mysql_num_rows (MYSQL_RES *res) |
| unsigned int STDCALL | mysql_num_fields (MYSQL_RES *res) |
| uint STDCALL | mysql_errno (MYSQL *mysql) |
| const char *STDCALL | mysql_error (MYSQL *mysql) |
| ulong STDCALL | mysql_get_server_version (MYSQL *mysql) |
| int STDCALL | mysql_set_character_set (MYSQL *mysql, const char *cs_name) |
Variables | |
| uint | mysql_port = 0 |
| char * | mysql_unix_port = 0 |
| const char * | unknown_sqlstate = "HY000" |
| const char * | not_error_sqlstate = "00000" |
| CHARSET_INFO * | default_client_charset_info = &my_charset_latin1 |
| static const char * | default_options [] |
| static TYPELIB | option_types |
| const char * | sql_protocol_names_lib [] |
| TYPELIB | sql_protocol_typelib |
| static MYSQL_METHODS | client_methods |
| #define SOCKET_ERROR -1 |
| static int add_init_command | ( | struct st_mysql_options * | options, | |
| const char * | cmd | |||
| ) | [static] |
Definition at line 920 of file client.c.
References CALLER_INFO, init_dynamic_array(), insert_dynamic(), MY_ALLOW_ZERO_PTR, my_free, my_malloc(), my_strdup(), MY_WME, MYF, and options().
00921 { 00922 char *tmp; 00923 00924 if (!options->init_commands) 00925 { 00926 options->init_commands= (DYNAMIC_ARRAY*)my_malloc(sizeof(DYNAMIC_ARRAY), 00927 MYF(MY_WME)); 00928 init_dynamic_array(options->init_commands,sizeof(char*),0,5 CALLER_INFO); 00929 } 00930 00931 if (!(tmp= my_strdup(cmd,MYF(MY_WME))) || 00932 insert_dynamic(options->init_commands, (gptr)&tmp)) 00933 { 00934 my_free(tmp, MYF(MY_ALLOW_ZERO_PTR)); 00935 return 1; 00936 } 00937 00938 return 0; 00939 }
Here is the call graph for this function:

| my_bool cli_advanced_command | ( | MYSQL * | mysql, | |
| enum enum_server_command | command, | |||
| const char * | header, | |||
| ulong | header_length, | |||
| const char * | arg, | |||
| ulong | arg_length, | |||
| my_bool | skip_check, | |||
| MYSQL_STMT *stmt | __attribute__((unused)) | |||
| ) |
Definition at line 653 of file client.c.
References st_mysql::affected_rows, cli_safe_read(), CR_COMMANDS_OUT_OF_SYNC, CR_NET_PACKET_TOO_LARGE, CR_SERVER_GONE_ERROR, DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, end_server(), ER, ER_NET_PACKET_TOO_LARGE, st_mysql::info, init_sigpipe_variables, st_net::last_errno, st_net::last_error, mysql, mysql_reconnect(), MYSQL_STATUS_READY, st_mysql::net, net_clear(), net_write_command(), not_error_sqlstate, packet_error, st_mysql::packet_length, st_net::report_error, reset_sigpipe, SERVER_MORE_RESULTS_EXISTS, st_mysql::server_status, set_mysql_error(), set_sigpipe, socket_errno, st_net::sqlstate, st_mysql::status, strmov(), unknown_sqlstate, and st_net::vio.
00657 { 00658 NET *net= &mysql->net; 00659 my_bool result= 1; 00660 init_sigpipe_variables 00661 DBUG_ENTER("cli_advanced_command"); 00662 00663 /* Don't give sigpipe errors if the client doesn't want them */ 00664 set_sigpipe(mysql); 00665 00666 if (mysql->net.vio == 0) 00667 { /* Do reconnect if possible */ 00668 if (mysql_reconnect(mysql)) 00669 DBUG_RETURN(1); 00670 } 00671 if (mysql->status != MYSQL_STATUS_READY || 00672 mysql->server_status & SERVER_MORE_RESULTS_EXISTS) 00673 { 00674 DBUG_PRINT("error",("state: %d", mysql->status)); 00675 set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); 00676 DBUG_RETURN(1); 00677 } 00678 00679 net->last_error[0]=0; 00680 net->last_errno= 0; 00681 strmov(net->sqlstate, not_error_sqlstate); 00682 mysql->net.report_error=0; 00683 mysql->info=0; 00684 mysql->affected_rows= ~(my_ulonglong) 0; 00685 net_clear(&mysql->net); /* Clear receive buffer */ 00686 00687 if (net_write_command(net,(uchar) command, header, header_length, 00688 arg, arg_length)) 00689 { 00690 DBUG_PRINT("error",("Can't send command to server. Error: %d", 00691 socket_errno)); 00692 if (net->last_errno == ER_NET_PACKET_TOO_LARGE) 00693 { 00694 net->last_errno=CR_NET_PACKET_TOO_LARGE; 00695 strmov(net->last_error,ER(net->last_errno)); 00696 goto end; 00697 } 00698 end_server(mysql); 00699 if (mysql_reconnect(mysql)) 00700 goto end; 00701 if (net_write_command(net,(uchar) command, header, header_length, 00702 arg, arg_length)) 00703 { 00704 net->last_errno=CR_SERVER_GONE_ERROR; 00705 strmov(net->last_error,ER(net->last_errno)); 00706 goto end; 00707 } 00708 } 00709 result=0; 00710 if (!skip_check) 00711 result= ((mysql->packet_length=cli_safe_read(mysql)) == packet_error ? 00712 1 : 0); 00713 end: 00714 reset_sigpipe(mysql); 00715 DBUG_PRINT("exit",("result: %d", result)); 00716 DBUG_RETURN(result); 00717 }
Here is the call graph for this function:

Definition at line 1140 of file client.c.
References start().
01142 { 01143 ulong *prev_length; 01144 byte *start=0; 01145 MYSQL_ROW end; 01146 01147 prev_length=0; /* Keep gcc happy */ 01148 for (end=column + field_count + 1 ; column != end ; column++, to++) 01149 { 01150 if (!*column) 01151 { 01152 *to= 0; /* Null */ 01153 continue; 01154 } 01155 if (start) /* Found end of prev string */ 01156 *prev_length= (ulong) (*column-start-1); 01157 start= *column; 01158 prev_length= to; 01159 } 01160 }
Here is the call graph for this function:

| static void cli_flush_use_result | ( | MYSQL * | mysql | ) | [static] |
Definition at line 755 of file client.c.
References cli_safe_read(), DBUG_ENTER, DBUG_PRINT, mysql, st_mysql::net, packet_error, pos(), protocol_41, st_net::read_pos, st_mysql::server_status, uint2korr, and st_mysql::warning_count.
00756 { 00757 /* Clear the current execution status */ 00758 DBUG_ENTER("cli_flush_use_result"); 00759 DBUG_PRINT("warning",("Not all packets read, clearing them")); 00760 for (;;) 00761 { 00762 ulong pkt_len; 00763 if ((pkt_len=cli_safe_read(mysql)) == packet_error) 00764 break; 00765 if (pkt_len <= 8 && mysql->net.read_pos[0] == 254) 00766 { 00767 if (protocol_41(mysql)) 00768 { 00769 char *pos= (char*) mysql->net.read_pos + 1; 00770 mysql->warning_count=uint2korr(pos); pos+=2; 00771 mysql->server_status=uint2korr(pos); pos+=2; 00772 } 00773 break; /* End of data */ 00774 } 00775 } 00776 DBUG_VOID_RETURN; 00777 }
Here is the call graph for this function:

| C_MODE_END MYSQL* STDCALL CLI_MYSQL_REAL_CONNECT | ( | MYSQL * | mysql, | |
| const char * | host, | |||
| const char * | user, | |||
| const char * | passwd, | |||
| const char * | db, | |||
| uint | port, | |||
| const char * | unix_socket, | |||
| ulong | client_flag | |||
| ) |
Definition at line 1753 of file client.c.
References st_dynamic_array::buffer, bzero, st_mysql::charset, cli_safe_read(), cli_use_result(), CLIENT_CAPABILITIES, CLIENT_COMPRESS, CLIENT_CONNECT_WITH_DB, st_mysql_options::client_flag, st_mysql::client_flag, client_methods, CLIENT_MULTI_RESULTS, CLIENT_MULTI_STATEMENTS, CLIENT_PROTOCOL_41, CLIENT_SECURE_CONNECTION, CLIENT_SSL, st_net::compress, st_mysql_options::connect_timeout, st_mysql::connector_fd, CR_CONN_HOST_ERROR, CR_CONN_UNKNOW_PROTOCOL, CR_CONNECTION_ERROR, CR_IPSOCK_ERROR, CR_LOCALHOST_CONNECTION, CR_NAMEDPIPE_CONNECTION, CR_OUT_OF_MEMORY, CR_SECURE_AUTH, CR_SERVER_LOST, CR_SHARED_MEMORY_CONNECTION, CR_SOCKET_CREATE_ERROR, CR_SSL_CONNECTION_ERROR, CR_TCP_CONNECTION, CR_UNKNOWN_HOST, CR_VERSION_ERROR, st_mysql::db, st_mysql_options::db, DBUG_DUMP, DBUG_ENTER, DBUG_PRINT, st_dynamic_array::elements, ER, error, getenv(), GETHOSTBYNAME_BUFF_SIZE, HANDLE, st_mysql::host, st_mysql_options::host, st_mysql::host_info, in_addr_t, INADDR_NONE, st_mysql_options::init_commands, init_sigpipe_variables, int2store, int3store, int4store, st_net::last_errno, st_net::last_error, LINT_INIT, LOCAL_HOST, LOCAL_HOST_NAMEDPIPE, st_mysql_options::max_allowed_packet, st_net::max_packet_size, memcpy, memcpy_fixed, st_mysql::methods, min, MY_ALLOW_ZERO_PTR, st_mysql_options::my_cnf_file, st_mysql_options::my_cnf_group, my_connect(), my_free, my_gethostbyname_r(), my_gethostbyname_r_free(), my_multi_malloc(), my_net_init(), my_net_write(), my_snprintf(), my_socket, my_strdup(), MY_WME, MYF, mysql, mysql_free_result(), mysql_init_character_set(), mysql_port, MYSQL_PROTOCOL_MEMORY, MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_SOCKET, MYSQL_PROTOCOL_TCP, mysql_read_default_options(), mysql_real_query(), mysql_select_db(), mysql_unix_port, NAME_LEN, st_mysql::net, net_flush(), NullS, charset_info_st::number, options(), st_mysql::options, packet_error, st_mysql::passwd, st_mysql_options::password, st_mysql::port, st_mysql_options::port, st_mysql_options::protocol, PROTOCOL_VERSION, st_mysql::protocol_version, st_net::read_pos, st_net::read_timeout, st_mysql_options::read_timeout, read_user_name, st_mysql::reconnect, reconnect(), scramble(), st_mysql::scramble, scramble_323(), SCRAMBLE_LENGTH, SCRAMBLE_LENGTH_323, st_mysql_options::secure_auth, st_mysql::server_capabilities, st_mysql::server_language, st_mysql::server_status, SERVER_STATUS_AUTOCOMMIT, st_mysql::server_version, set_mysql_error(), set_sigpipe, sock, socket_errno, SOCKET_ERROR, st_net::sqlstate, st_mysql_options::ssl_ca, st_mysql_options::ssl_capath, st_mysql_options::ssl_cert, st_mysql_options::ssl_cipher, st_mysql_options::ssl_key, st_mysql_options::ssl_verify_server_cert, strcmp(), strend(), strlen(), strmake(), strmov(), thr_alarm, thr_alarm_init, thr_end_alarm, st_mysql::thread_id, TRUE, uint2korr, uint4korr, st_mysql::unix_socket, st_mysql_options::unix_socket, unknown_sqlstate, st_mysql_options::use_ssl, st_mysql::user, st_mysql_options::user, USERNAME_LENGTH, st_net::vio, VIO_BUFFERED_READ, vio_delete, vio_keepalive, VIO_LOCALHOST, vio_new(), vio_poll_read(), VIO_TYPE_SOCKET, VIO_TYPE_TCPIP, st_net::write_timeout, and st_mysql_options::write_timeout.
01756 { 01757 char buff[NAME_LEN+USERNAME_LENGTH+100]; 01758 char *end,*host_info; 01759 my_socket sock; 01760 in_addr_t ip_addr; 01761 struct sockaddr_in sock_addr; 01762 ulong pkt_length; 01763 NET *net= &mysql->net; 01764 #ifdef MYSQL_SERVER 01765 thr_alarm_t alarmed; 01766 ALARM alarm_buff; 01767 #endif 01768 #ifdef __WIN__ 01769 HANDLE hPipe=INVALID_HANDLE_VALUE; 01770 #endif 01771 #ifdef HAVE_SYS_UN_H 01772 struct sockaddr_un UNIXaddr; 01773 #endif 01774 init_sigpipe_variables 01775 DBUG_ENTER("mysql_real_connect"); 01776 LINT_INIT(host_info); 01777 01778 DBUG_PRINT("enter",("host: %s db: %s user: %s", 01779 host ? host : "(Null)", 01780 db ? db : "(Null)", 01781 user ? user : "(Null)")); 01782 01783 /* Don't give sigpipe errors if the client doesn't want them */ 01784 set_sigpipe(mysql); 01785 mysql->methods= &client_methods; 01786 net->vio = 0; /* If something goes wrong */ 01787 mysql->client_flag=0; /* For handshake */ 01788 01789 /* use default options */ 01790 if (mysql->options.my_cnf_file || mysql->options.my_cnf_group) 01791 { 01792 mysql_read_default_options(&mysql->options, 01793 (mysql->options.my_cnf_file ? 01794 mysql->options.my_cnf_file : "my"), 01795 mysql->options.my_cnf_group); 01796 my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR)); 01797 my_free(mysql->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR)); 01798 mysql->options.my_cnf_file=mysql->options.my_cnf_group=0; 01799 } 01800 01801 /* Some empty-string-tests are done because of ODBC */ 01802 if (!host || !host[0]) 01803 host=mysql->options.host; 01804 if (!user || !user[0]) 01805 { 01806 user=mysql->options.user; 01807 if (!user) 01808 user= ""; 01809 } 01810 if (!passwd) 01811 { 01812 passwd=mysql->options.password; 01813 #if !defined(DONT_USE_MYSQL_PWD) && !defined(MYSQL_SERVER) 01814 if (!passwd) 01815 passwd=getenv("MYSQL_PWD"); /* get it from environment */ 01816 #endif 01817 if (!passwd) 01818 passwd= ""; 01819 } 01820 if (!db || !db[0]) 01821 db=mysql->options.db; 01822 if (!port) 01823 port=mysql->options.port; 01824 if (!unix_socket) 01825 unix_socket=mysql->options.unix_socket; 01826 01827 mysql->server_status=SERVER_STATUS_AUTOCOMMIT; 01828 01829 /* 01830 Part 0: Grab a socket and connect it to the server 01831 */ 01832 #if defined(HAVE_SMEM) 01833 if ((!mysql->options.protocol || 01834 mysql->options.protocol == MYSQL_PROTOCOL_MEMORY) && 01835 (!host || !strcmp(host,LOCAL_HOST))) 01836 { 01837 if ((create_shared_memory(mysql,net, mysql->options.connect_timeout)) == 01838 INVALID_HANDLE_VALUE) 01839 { 01840 DBUG_PRINT("error", 01841 ("host: '%s' socket: '%s' shared memory: %s have_tcpip: %d", 01842 host ? host : "<null>", 01843 unix_socket ? unix_socket : "<null>", 01844 (int) mysql->options.shared_memory_base_name, 01845 (int) have_tcpip)); 01846 if (mysql->options.protocol == MYSQL_PROTOCOL_MEMORY) 01847 goto error; 01848 /* Try also with PIPE or TCP/IP */ 01849 } 01850 else 01851 { 01852 mysql->options.protocol=MYSQL_PROTOCOL_MEMORY; 01853 sock=0; 01854 unix_socket = 0; 01855 host=mysql->options.shared_memory_base_name; 01856 my_snprintf(host_info=buff, sizeof(buff)-1, 01857 ER(CR_SHARED_MEMORY_CONNECTION), host); 01858 } 01859 } 01860 #endif /* HAVE_SMEM */ 01861 #if defined(HAVE_SYS_UN_H) 01862 if (!net->vio && 01863 (!mysql->options.protocol || 01864 mysql->options.protocol == MYSQL_PROTOCOL_SOCKET) && 01865 (unix_socket || mysql_unix_port) && 01866 (!host || !strcmp(host,LOCAL_HOST))) 01867 { 01868 host=LOCAL_HOST; 01869 if (!unix_socket) 01870 unix_socket=mysql_unix_port; 01871 host_info=(char*) ER(CR_LOCALHOST_CONNECTION); 01872 DBUG_PRINT("info",("Using UNIX sock '%s'",unix_socket)); 01873 if ((sock = socket(AF_UNIX,SOCK_STREAM,0)) == SOCKET_ERROR) 01874 { 01875 net->last_errno=CR_SOCKET_CREATE_ERROR; 01876 strmov(net->sqlstate, unknown_sqlstate); 01877 my_snprintf(net->last_error,sizeof(net->last_error)-1, 01878 ER(net->last_errno),socket_errno); 01879 goto error; 01880 } 01881 net->vio= vio_new(sock, VIO_TYPE_SOCKET, 01882 VIO_LOCALHOST | VIO_BUFFERED_READ); 01883 bzero((char*) &UNIXaddr,sizeof(UNIXaddr)); 01884 UNIXaddr.sun_family = AF_UNIX; 01885 strmake(UNIXaddr.sun_path, unix_socket, sizeof(UNIXaddr.sun_path)-1); 01886 if (my_connect(sock,(struct sockaddr *) &UNIXaddr, sizeof(UNIXaddr), 01887 mysql->options.connect_timeout)) 01888 { 01889 DBUG_PRINT("error",("Got error %d on connect to local server", 01890 socket_errno)); 01891 net->last_errno=CR_CONNECTION_ERROR; 01892 strmov(net->sqlstate, unknown_sqlstate); 01893 my_snprintf(net->last_error,sizeof(net->last_error)-1, 01894 ER(net->last_errno),unix_socket,socket_errno); 01895 goto error; 01896 } 01897 mysql->options.protocol=MYSQL_PROTOCOL_SOCKET; 01898 } 01899 #elif defined(__WIN__) 01900 if (!net->vio && 01901 (mysql->options.protocol == MYSQL_PROTOCOL_PIPE || 01902 (host && !strcmp(host,LOCAL_HOST_NAMEDPIPE)) || 01903 (! have_tcpip && (unix_socket || !host && is_NT())))) 01904 { 01905 sock=0; 01906 if ((hPipe=create_named_pipe(net, mysql->options.connect_timeout, 01907 (char**) &host, (char**) &unix_socket)) == 01908 INVALID_HANDLE_VALUE) 01909 { 01910 DBUG_PRINT("error", 01911 ("host: '%s' socket: '%s' have_tcpip: %d", 01912 host ? host : "<null>", 01913 unix_socket ? unix_socket : "<null>", 01914 (int) have_tcpip)); 01915 if (mysql->options.protocol == MYSQL_PROTOCOL_PIPE || 01916 (host && !strcmp(host,LOCAL_HOST_NAMEDPIPE)) || 01917 (unix_socket && !strcmp(unix_socket,MYSQL_NAMEDPIPE))) 01918 goto error; 01919 /* Try also with TCP/IP */ 01920 } 01921 else 01922 { 01923 net->vio=vio_new_win32pipe(hPipe); 01924 my_snprintf(host_info=buff, sizeof(buff)-1, 01925 ER(CR_NAMEDPIPE_CONNECTION), unix_socket); 01926 } 01927 } 01928 #endif 01929 if (!net->vio && 01930 (!mysql->options.protocol || 01931 mysql->options.protocol == MYSQL_PROTOCOL_TCP)) 01932 { 01933 unix_socket=0; /* This is not used */ 01934 if (!port) 01935 port=mysql_port; 01936 if (!host) 01937 host=LOCAL_HOST; 01938 my_snprintf(host_info=buff,sizeof(buff)-1,ER(CR_TCP_CONNECTION),host); 01939 DBUG_PRINT("info",("Server name: '%s'. TCP sock: %d", host,port)); 01940 #ifdef MYSQL_SERVER 01941 thr_alarm_init(&alarmed); 01942 thr_alarm(&alarmed, mysql->options.connect_timeout, &alarm_buff); 01943 #endif 01944 /* _WIN64 ; Assume that the (int) range is enough for socket() */ 01945 sock = (my_socket) socket(AF_INET,SOCK_STREAM,0); 01946 #ifdef MYSQL_SERVER 01947 thr_end_alarm(&alarmed); 01948 #endif 01949 if (sock == SOCKET_ERROR) 01950 { 01951 net->last_errno=CR_IPSOCK_ERROR; 01952 strmov(net->sqlstate, unknown_sqlstate); 01953 my_snprintf(net->last_error,sizeof(net->last_error)-1, 01954 ER(net->last_errno),socket_errno); 01955 goto error; 01956 } 01957 net->vio= vio_new(sock, VIO_TYPE_TCPIP, VIO_BUFFERED_READ); 01958 bzero((char*) &sock_addr,sizeof(sock_addr)); 01959 sock_addr.sin_family = AF_INET; 01960 01961 /* 01962 The server name may be a host name or IP address 01963 */ 01964 01965 if ((int) (ip_addr = inet_addr(host)) != (int) INADDR_NONE) 01966 { 01967 memcpy_fixed(&sock_addr.sin_addr,&ip_addr,sizeof(ip_addr)); 01968 } 01969 else 01970 { 01971 int tmp_errno; 01972 struct hostent tmp_hostent,*hp; 01973 char buff2[GETHOSTBYNAME_BUFF_SIZE]; 01974 hp = my_gethostbyname_r(host,&tmp_hostent,buff2,sizeof(buff2), 01975 &tmp_errno); 01976 if (!hp) 01977 { 01978 my_gethostbyname_r_free(); 01979 net->last_errno=CR_UNKNOWN_HOST; 01980 strmov(net->sqlstate, unknown_sqlstate); 01981 my_snprintf(net->last_error, sizeof(net->last_error)-1, 01982 ER(CR_UNKNOWN_HOST), host, tmp_errno); 01983 goto error; 01984 } 01985 memcpy(&sock_addr.sin_addr, hp->h_addr, 01986 min(sizeof(sock_addr.sin_addr), (size_t) hp->h_length)); 01987 my_gethostbyname_r_free(); 01988 } 01989 sock_addr.sin_port = (ushort) htons((ushort) port); 01990 if (my_connect(sock,(struct sockaddr *) &sock_addr, sizeof(sock_addr), 01991 mysql->options.connect_timeout)) 01992 { 01993 DBUG_PRINT("error",("Got error %d on connect to '%s'",socket_errno, 01994 host)); 01995 net->last_errno= CR_CONN_HOST_ERROR; 01996 strmov(net->sqlstate, unknown_sqlstate); 01997 my_snprintf(net->last_error, sizeof(net->last_error)-1, 01998 ER(CR_CONN_HOST_ERROR), host, socket_errno); 01999 goto error; 02000 } 02001 } 02002 if (!net->vio) 02003 { 02004 DBUG_PRINT("error",("Unknow protocol %d ",mysql->options.protocol)); 02005 set_mysql_error(mysql, CR_CONN_UNKNOW_PROTOCOL, unknown_sqlstate); 02006 goto error; 02007 } 02008 02009 if (my_net_init(net, net->vio)) 02010 { 02011 vio_delete(net->vio); 02012 net->vio = 0; 02013 set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate); 02014 goto error; 02015 } 02016 vio_keepalive(net->vio,TRUE); 02017 /* Override local client variables */ 02018 if (mysql->options.read_timeout) 02019 net->read_timeout= mysql->options.read_timeout; 02020 if (mysql->options.write_timeout) 02021 net->write_timeout= mysql->options.write_timeout; 02022 if (mysql->options.max_allowed_packet) 02023 net->max_packet_size= mysql->options.max_allowed_packet; 02024 02025 /* Get version info */ 02026 mysql->protocol_version= PROTOCOL_VERSION; /* Assume this */ 02027 if (mysql->options.connect_timeout && 02028 vio_poll_read(net->vio, mysql->options.connect_timeout)) 02029 { 02030 set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate); 02031 goto error; 02032 } 02033 02034 /* 02035 Part 1: Connection established, read and parse first packet 02036 */ 02037 02038 if ((pkt_length=cli_safe_read(mysql)) == packet_error) 02039 goto error; 02040 02041 /* Check if version of protocol matches current one */ 02042 02043 mysql->protocol_version= net->read_pos[0]; 02044 DBUG_DUMP("packet",(char*) net->read_pos,10); 02045 DBUG_PRINT("info",("mysql protocol version %d, server=%d", 02046 PROTOCOL_VERSION, mysql->protocol_version)); 02047 if (mysql->protocol_version != PROTOCOL_VERSION) 02048 { 02049 strmov(net->sqlstate, unknown_sqlstate); 02050 net->last_errno= CR_VERSION_ERROR; 02051 my_snprintf(net->last_error, sizeof(net->last_error)-1, 02052 ER(CR_VERSION_ERROR), mysql->protocol_version, 02053 PROTOCOL_VERSION); 02054 goto error; 02055 } 02056 end=strend((char*) net->read_pos+1); 02057 mysql->thread_id=uint4korr(end+1); 02058 end+=5; 02059 /* 02060 Scramble is split into two parts because old clients does not understand 02061 long scrambles; here goes the first part. 02062 */ 02063 strmake(mysql->scramble, end, SCRAMBLE_LENGTH_323); 02064 end+= SCRAMBLE_LENGTH_323+1; 02065 02066 if (pkt_length >= (uint) (end+1 - (char*) net->read_pos)) 02067 mysql->server_capabilities=uint2korr(end); 02068 if (pkt_length >= (uint) (end+18 - (char*) net->read_pos)) 02069 { 02070 /* New protocol with 16 bytes to describe server characteristics */ 02071 mysql->server_language=end[2]; 02072 mysql->server_status=uint2korr(end+3); 02073 } 02074 end+= 18; 02075 if (pkt_length >= (uint) (end + SCRAMBLE_LENGTH - SCRAMBLE_LENGTH_323 + 1 - 02076 (char *) net->read_pos)) 02077 strmake(mysql->scramble+SCRAMBLE_LENGTH_323, end, 02078 SCRAMBLE_LENGTH-SCRAMBLE_LENGTH_323); 02079 else 02080 mysql->server_capabilities&= ~CLIENT_SECURE_CONNECTION; 02081 02082 if (mysql->options.secure_auth && passwd[0] && 02083 !(mysql->server_capabilities & CLIENT_SECURE_CONNECTION)) 02084 { 02085 set_mysql_error(mysql, CR_SECURE_AUTH, unknown_sqlstate); 02086 goto error; 02087 } 02088 02089 if (mysql_init_character_set(mysql)) 02090 goto error; 02091 02092 /* Save connection information */ 02093 if (!my_multi_malloc(MYF(0), 02094 &mysql->host_info, (uint) strlen(host_info)+1, 02095 &mysql->host, (uint) strlen(host)+1, 02096 &mysql->unix_socket,unix_socket ? 02097 (uint) strlen(unix_socket)+1 : (uint) 1, 02098 &mysql->server_version, 02099 (uint) (end - (char*) net->read_pos), 02100 NullS) || 02101 !(mysql->user=my_strdup(user,MYF(0))) || 02102 !(mysql->passwd=my_strdup(passwd,MYF(0)))) 02103 { 02104 set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate); 02105 goto error; 02106 } 02107 strmov(mysql->host_info,host_info); 02108 strmov(mysql->host,host); 02109 if (unix_socket) 02110 strmov(mysql->unix_socket,unix_socket); 02111 else 02112 mysql->unix_socket=0; 02113 strmov(mysql->server_version,(char*) net->read_pos+1); 02114 mysql->port=port; 02115 02116 /* 02117 Part 2: format and send client info to the server for access check 02118 */ 02119 02120 client_flag|=mysql->options.client_flag; 02121 client_flag|=CLIENT_CAPABILITIES; 02122 if (client_flag & CLIENT_MULTI_STATEMENTS) 02123 client_flag|= CLIENT_MULTI_RESULTS; 02124 02125 #ifdef HAVE_OPENSSL 02126 if (mysql->options.ssl_key || mysql->options.ssl_cert || 02127 mysql->options.ssl_ca || mysql->options.ssl_capath || 02128 mysql->options.ssl_cipher) 02129 mysql->options.use_ssl= 1; 02130 if (mysql->options.use_ssl) 02131 client_flag|=CLIENT_SSL; 02132 #endif /* HAVE_OPENSSL */ 02133 if (db) 02134 client_flag|=CLIENT_CONNECT_WITH_DB; 02135 02136 /* Remove options that server doesn't support */ 02137 client_flag= ((client_flag & 02138 ~(CLIENT_COMPRESS | CLIENT_SSL | CLIENT_PROTOCOL_41)) | 02139 (client_flag & mysql->server_capabilities)); 02140 #ifndef HAVE_COMPRESS 02141 client_flag&= ~CLIENT_COMPRESS; 02142 #endif 02143 02144 if (client_flag & CLIENT_PROTOCOL_41) 02145 { 02146 /* 4.1 server and 4.1 client has a 32 byte option flag */ 02147 int4store(buff,client_flag); 02148 int4store(buff+4, net->max_packet_size); 02149 buff[8]= (char) mysql->charset->number; 02150 bzero(buff+9, 32-9); 02151 end= buff+32; 02152 } 02153 else 02154 { 02155 int2store(buff,client_flag); 02156 int3store(buff+2,net->max_packet_size); 02157 end= buff+5; 02158 } 02159 mysql->client_flag=client_flag; 02160 02161 #ifdef HAVE_OPENSSL 02162 if (client_flag & CLIENT_SSL) 02163 { 02164 /* Do the SSL layering. */ 02165 struct st_mysql_options *options= &mysql->options; 02166 struct st_VioSSLFd *ssl_fd; 02167 02168 /* 02169 Send client_flag, max_packet_size - unencrypted otherwise 02170 the server does not know we want to do SSL 02171 */ 02172 if (my_net_write(net,buff,(uint) (end-buff)) || net_flush(net)) 02173 { 02174 set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate); 02175 goto error; 02176 } 02177 02178 /* Create the VioSSLConnectorFd - init SSL and load certs */ 02179 if (!(ssl_fd= new_VioSSLConnectorFd(options->ssl_key, 02180 options->ssl_cert, 02181 options->ssl_ca, 02182 options->ssl_capath, 02183 options->ssl_cipher))) 02184 { 02185 set_mysql_error(mysql, CR_SSL_CONNECTION_ERROR, unknown_sqlstate); 02186 goto error; 02187 } 02188 mysql->connector_fd= (void*)ssl_fd; 02189 02190 /* Connect to the server */ 02191 DBUG_PRINT("info", ("IO layer change in progress...")); 02192 if (sslconnect(ssl_fd, mysql->net.vio, 02193 (long) (mysql->options.connect_timeout))) 02194 { 02195 set_mysql_error(mysql, CR_SSL_CONNECTION_ERROR, unknown_sqlstate); 02196 goto error; 02197 } 02198 DBUG_PRINT("info", ("IO layer change done!")); 02199 02200 /* Verify server cert */ 02201 if (mysql->options.ssl_verify_server_cert && 02202 ssl_verify_server_cert(mysql->net.vio, mysql->host)) 02203 { 02204 set_mysql_error(mysql, CR_SSL_CONNECTION_ERROR, unknown_sqlstate); 02205 goto error; 02206 } 02207 02208 } 02209 #endif /* HAVE_OPENSSL */ 02210 02211 DBUG_PRINT("info",("Server version = '%s' capabilites: %lu status: %u client_flag: %lu", 02212 mysql->server_version,mysql->server_capabilities, 02213 mysql->server_status, client_flag)); 02214 /* This needs to be changed as it's not useful with big packets */ 02215 if (user && user[0]) 02216 strmake(end,user,USERNAME_LENGTH); /* Max user name */ 02217 else 02218 read_user_name((char*) end); 02219 02220 /* We have to handle different version of handshake here */ 02221 #ifdef _CUSTOMCONFIG_ 02222 #include "_cust_libmysql.h" 02223 #endif 02224 DBUG_PRINT("info",("user: %s",end)); 02225 end= strend(end) + 1; 02226 if (passwd[0]) 02227 { 02228 if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION) 02229 { 02230 *end++= SCRAMBLE_LENGTH; 02231 scramble(end, mysql->scramble, passwd); 02232 end+= SCRAMBLE_LENGTH; 02233 } 02234 else 02235 { 02236 scramble_323(end, mysql->scramble, passwd); 02237 end+= SCRAMBLE_LENGTH_323 + 1; 02238 } 02239 } 02240 else 02241 *end++= '\0'; /* empty password */ 02242 02243 /* Add database if needed */ 02244 if (db && (mysql->server_capabilities & CLIENT_CONNECT_WITH_DB)) 02245 { 02246 end= strmake(end, db, NAME_LEN) + 1; 02247 mysql->db= my_strdup(db,MYF(MY_WME)); 02248 db= 0; 02249 } 02250 /* Write authentication package */ 02251 if (my_net_write(net,buff,(ulong) (end-buff)) || net_flush(net)) 02252 { 02253 set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate); 02254 goto error; 02255 } 02256 02257 /* 02258 Part 3: Authorization data's been sent. Now server can reply with 02259 OK-packet, or re-request scrambled password. 02260 */ 02261 02262 if ((pkt_length=cli_safe_read(mysql)) == packet_error) 02263 goto error; 02264 02265 if (pkt_length == 1 && net->read_pos[0] == 254 && 02266 mysql->server_capabilities & CLIENT_SECURE_CONNECTION) 02267 { 02268 /* 02269 By sending this very specific reply server asks us to send scrambled 02270 password in old format. 02271 */ 02272 scramble_323(buff, mysql->scramble, passwd); 02273 if (my_net_write(net, buff, SCRAMBLE_LENGTH_323 + 1) || net_flush(net)) 02274 { 02275 set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate); 02276 goto error; 02277 } 02278 /* Read what server thinks about out new auth message report */ 02279 if (cli_safe_read(mysql) == packet_error) 02280 goto error; 02281 } 02282 02283 if (client_flag & CLIENT_COMPRESS) /* We will use compression */ 02284 net->compress=1; 02285 02286 #ifdef CHECK_LICENSE 02287 if (check_license(mysql)) 02288 goto error; 02289 #endif 02290 02291 if (db && mysql_select_db(mysql,db)) 02292 goto error; 02293 02294 if (mysql->options.init_commands) 02295 { 02296 DYNAMIC_ARRAY *init_commands= mysql->options.init_commands; 02297 char **ptr= (char**)init_commands->buffer; 02298 char **end= ptr + init_commands->elements; 02299 02300 my_bool reconnect=mysql->reconnect; 02301 mysql->reconnect=0; 02302 02303 for (; ptr<end; ptr++) 02304 { 02305 MYSQL_RES *res; 02306 if (mysql_real_query(mysql,*ptr, (ulong) strlen(*ptr))) 02307 goto error; 02308 if (mysql->fields) 02309 { 02310 if (!(res= cli_use_result(mysql))) 02311 goto error; 02312 mysql_free_result(res); 02313 } 02314 } 02315 mysql->reconnect=reconnect; 02316 } 02317 02318 #ifndef TO_BE_DELETED 02319 if (mysql->options.rpl_probe && mysql_rpl_probe(mysql)) 02320 goto error; 02321 #endif 02322 02323 DBUG_PRINT("exit",("Mysql handler: %lx",mysql)); 02324 reset_sigpipe(mysql); 02325 DBUG_RETURN(mysql); 02326 02327 error: 02328 reset_sigpipe(mysql); 02329 DBUG_PRINT("error",("message: %u/%s (%s)", 02330 net->last_errno, net->sqlstate, net->last_error)); 02331 { 02332 /* Free alloced memory */ 02333 end_server(mysql); 02334 mysql_close_free(mysql); 02335 if (!(((ulong) client_flag) & CLIENT_REMEMBER_OPTIONS)) 02336 mysql_close_free_options(mysql); 02337 } 02338 DBUG_RETURN(0); 02339 }
Here is the call graph for this function:

Definition at line 2589 of file client.c.
References st_mysql::affected_rows, cli_read_rows(), cli_safe_read(), CLIENT_TRANSACTIONS, DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, error, st_mysql::field_alloc, st_mysql::field_count, st_mysql::fields, free_old_query(), handle_local_infile(), st_mysql::info, st_mysql::insert_id, st_mysql::last_used_con, mysql, MYSQL_STATUS_GET_RESULT, st_mysql::net, net_field_length(), net_field_length_ll(), NULL_LENGTH, packet_error, pos(), protocol_41, st_net::read_pos, st_mysql::server_capabilities, st_mysql::server_status, SERVER_STATUS_AUTOCOMMIT, SERVER_STATUS_IN_TRANS, st_mysql::status, uint2korr, unpack_fields(), and st_mysql::warning_count.
02590 { 02591 uchar *pos; 02592 ulong field_count; 02593 MYSQL_DATA *fields; 02594 ulong length; 02595 DBUG_ENTER("cli_read_query_result"); 02596 02597 /* 02598 Read from the connection which we actually used, which 02599 could differ from the original connection if we have slaves 02600 */ 02601 mysql = mysql->last_used_con; 02602 02603 if ((length = cli_safe_read(mysql)) == packet_error) 02604 DBUG_RETURN(1); 02605 free_old_query(mysql); /* Free old result */ 02606 #ifdef MYSQL_CLIENT /* Avoid warn of unused labels*/ 02607 get_info: 02608 #endif 02609 pos=(uchar*) mysql->net.read_pos; 02610 if ((field_count= net_field_length(&pos)) == 0) 02611 { 02612 mysql->affected_rows= net_field_length_ll(&pos); 02613 mysql->insert_id= net_field_length_ll(&pos); 02614 DBUG_PRINT("info",("affected_rows: %lu insert_id: %lu", 02615 (ulong) mysql->affected_rows, 02616 (ulong) mysql->insert_id)); 02617 if (protocol_41(mysql)) 02618 { 02619 mysql->server_status=uint2korr(pos); pos+=2; 02620 mysql->warning_count=uint2korr(pos); pos+=2; 02621 } 02622 else if (mysql->server_capabilities & CLIENT_TRANSACTIONS) 02623 { 02624 /* MySQL 4.0 protocol */ 02625 mysql->server_status=uint2korr(pos); pos+=2; 02626 mysql->warning_count= 0; 02627 } 02628 DBUG_PRINT("info",("status: %u warning_count: %u", 02629 mysql->server_status, mysql->warning_count)); 02630 if (pos < mysql->net.read_pos+length && net_field_length(&pos)) 02631 mysql->info=(char*) pos; 02632 DBUG_RETURN(0); 02633 } 02634 #ifdef MYSQL_CLIENT 02635 if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */ 02636 { 02637 int error=handle_local_infile(mysql,(char*) pos); 02638 if ((length= cli_safe_read(mysql)) == packet_error || error) 02639 DBUG_RETURN(1); 02640 goto get_info; /* Get info packet */ 02641 } 02642 #endif 02643 if (!(mysql->server_status & SERVER_STATUS_AUTOCOMMIT)) 02644 mysql->server_status|= SERVER_STATUS_IN_TRANS; 02645 02646 if (!(fields=cli_read_rows(mysql,(MYSQL_FIELD*)0, protocol_41(mysql) ? 7:5))) 02647 DBUG_RETURN(1); 02648 if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc, 02649 (uint) field_count,0, 02650 mysql->server_capabilities))) 02651 DBUG_RETURN(1); 02652 mysql->status= MYSQL_STATUS_GET_RESULT; 02653 mysql->field_count= (uint) field_count; 02654 DBUG_PRINT("exit",("ok")); 02655 DBUG_RETURN(0); 02656 }
Here is the call graph for this function:

| MYSQL_DATA* cli_read_rows | ( | MYSQL * | mysql, | |
| MYSQL_FIELD * | mysql_fields, | |||
| unsigned int | fields | |||
| ) |
Definition at line 1272 of file client.c.
References st_mysql_data::alloc, alloc_root(), cli_safe_read(), CR_MALFORMED_PACKET, CR_OUT_OF_MEMORY, st_mysql_rows::data, st_mysql_data::data, DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, st_mysql_data::fields, free_rows(), init_alloc_root(), st_mysql_field::max_length, memcpy, st_mem_root::min_malloc, my_malloc(), MY_WME, MY_ZEROFILL, MYF, mysql, st_mysql::net, net_field_length(), st_mysql_rows::next, NULL_LENGTH, packet_error, st_net::read_pos, st_mysql_data::rows, st_mysql::server_status, set_mysql_error(), to, uint2korr, unknown_sqlstate, and st_mysql::warning_count.
01274 { 01275 uint field; 01276 ulong pkt_len; 01277 ulong len; 01278 uchar *cp; 01279 char *to, *end_to; 01280 MYSQL_DATA *result; 01281 MYSQL_ROWS **prev_ptr,*cur; 01282 NET *net = &mysql->net; 01283 DBUG_ENTER("cli_read_rows"); 01284 01285 if ((pkt_len= cli_safe_read(mysql)) == packet_error) 01286 DBUG_RETURN(0); 01287 if (!(result=(MYSQL_DATA*) my_malloc(sizeof(MYSQL_DATA), 01288 MYF(MY_WME | MY_ZEROFILL)))) 01289 { 01290 set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate); 01291 DBUG_RETURN(0); 01292 } 01293 init_alloc_root(&result->alloc,8192,0); /* Assume rowlength < 8192 */ 01294 result->alloc.min_malloc=sizeof(MYSQL_ROWS); 01295 prev_ptr= &result->data; 01296 result->rows=0; 01297 result->fields=fields; 01298 01299 /* 01300 The last EOF packet is either a single 254 character or (in MySQL 4.1) 01301 254 followed by 1-7 status bytes. 01302 01303 This doesn't conflict with normal usage of 254 which stands for a 01304 string where the length of the string is 8 bytes. (see net_field_length()) 01305 */ 01306 01307 while (*(cp=net->read_pos) != 254 || pkt_len >= 8) 01308 { 01309 result->rows++; 01310 if (!(cur= (MYSQL_ROWS*) alloc_root(&result->alloc, 01311 sizeof(MYSQL_ROWS))) || 01312 !(cur->data= ((MYSQL_ROW) 01313 alloc_root(&result->alloc, 01314 (fields+1)*sizeof(char *)+pkt_len)))) 01315 { 01316 free_rows(result); 01317 set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate); 01318 DBUG_RETURN(0); 01319 } 01320 *prev_ptr=cur; 01321 prev_ptr= &cur->next; 01322 to= (char*) (cur->data+fields+1); 01323 end_to=to+pkt_len-1; 01324 for (field=0 ; field < fields ; field++) 01325 { 01326 if ((len=(ulong) net_field_length(&cp)) == NULL_LENGTH) 01327 { /* null field */ 01328 cur->data[field] = 0; 01329 } 01330 else 01331 { 01332 cur->data[field] = to; 01333 if (len > (ulong) (end_to - to)) 01334 { 01335 free_rows(result); 01336 set_mysql_error(mysql, CR_MALFORMED_PACKET, unknown_sqlstate); 01337 DBUG_RETURN(0); 01338 } 01339 memcpy(to,(char*) cp,len); to[len]=0; 01340 to+=len+1; 01341 cp+=len; 01342 if (mysql_fields) 01343 { 01344 if (mysql_fields[field].max_length < len) 01345 mysql_fields[field].max_length=len; 01346 } 01347 } 01348 } 01349 cur->data[field]=to; /* End of last field */ 01350 if ((pkt_len=cli_safe_read(mysql)) == packet_error) 01351 { 01352 free_rows(result); 01353 DBUG_RETURN(0); 01354 } 01355 } 01356 *prev_ptr=0; /* last pointer is null */ 01357 if (pkt_len > 1) /* MySQL 4.1 protocol */ 01358 { 01359 mysql->warning_count= uint2korr(cp+1); 01360 mysql->server_status= uint2korr(cp+3); 01361 DBUG_PRINT("info",("status: %u warning_count: %u", 01362 mysql->server_status, mysql->warning_count)); 01363 } 01364 DBUG_PRINT("exit",("Got %d rows",result->rows)); 01365 DBUG_RETURN(result); 01366 }
Here is the call graph for this function:

Definition at line 582 of file client.c.
References CR_NET_PACKET_TOO_LARGE, CR_SERVER_LOST, CR_UNKNOWN_ERROR, DBUG_PRINT, end_server(), ER_NET_PACKET_TOO_LARGE, init_sigpipe_variables, st_net::last_errno, st_net::last_error, min, my_net_read(), mysql, st_mysql::net, packet_error, pos(), protocol_41, st_net::read_pos, reset_sigpipe, SERVER_MORE_RESULTS_EXISTS, st_mysql::server_status, set_mysql_error(), set_sigpipe, st_net::sqlstate, SQLSTATE_LENGTH, strmake(), uint2korr, unknown_sqlstate, st_net::vio, vio_description(), and vio_was_interrupted.
Referenced by cli_advanced_command(), cli_flush_use_result(), CLI_MYSQL_REAL_CONNECT(), cli_read_binary_rows(), cli_read_change_user_result(), cli_read_prepare_result(), cli_read_query_result(), cli_read_rows(), cli_unbuffered_fetch(), dump_remote_log_entries(), and read_one_row().
00583 { 00584 NET *net= &mysql->net; 00585 ulong len=0; 00586 init_sigpipe_variables 00587 00588 /* Don't give sigpipe errors if the client doesn't want them */ 00589 set_sigpipe(mysql); 00590 if (net->vio != 0) 00591 len=my_net_read(net); 00592 reset_sigpipe(mysql); 00593 00594 if (len == packet_error || len == 0) 00595 { 00596 DBUG_PRINT("error",("Wrong connection or packet. fd: %s len: %d", 00597 vio_description(net->vio),len)); 00598 #ifdef MYSQL_SERVER 00599 if (net->vio && vio_was_interrupted(net->vio)) 00600 return (packet_error); 00601 #endif /*MYSQL_SERVER*/ 00602 end_server(mysql); 00603 set_mysql_error(mysql, net->last_errno == ER_NET_PACKET_TOO_LARGE ? 00604 CR_NET_PACKET_TOO_LARGE: CR_SERVER_LOST, unknown_sqlstate); 00605 return (packet_error); 00606 } 00607 if (net->read_pos[0] == 255) 00608 { 00609 if (len > 3) 00610 { 00611 char *pos=(char*) net->read_pos+1; 00612 net->last_errno=uint2korr(pos); 00613 pos+=2; 00614 len-=2; 00615 if (protocol_41(mysql) && pos[0] == '#') 00616 { 00617 strmake(net->sqlstate, pos+1, SQLSTATE_LENGTH); 00618 pos+= SQLSTATE_LENGTH+1; 00619 } 00620 (void) strmake(net->last_error,(char*) pos, 00621 min((uint) len,(uint) sizeof(net->last_error)-1)); 00622 } 00623 else 00624 set_mysql_error(mysql, CR_UNKNOWN_ERROR, unknown_sqlstate); 00625 /* 00626 Cover a protocol design error: error packet does not 00627 contain the server status. Therefore, the client has no way 00628 to find out whether there are more result sets of 00629 a multiple-result-set statement pending. Luckily, in 5.0 an 00630 error always aborts execution of a statement, wherever it is 00631 a multi-statement or a stored procedure, so it should be 00632 safe to unconditionally turn off the flag here. 00633 */ 00634 mysql->server_status&= ~SERVER_MORE_RESULTS_EXISTS; 00635 00636 DBUG_PRINT("error",("Got error: %d/%s (%s)", 00637 net->last_errno, net->sqlstate, net->last_error)); 00638 return(packet_error); 00639 } 00640 return len; 00641 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2762 of file client.c.
References CR_COMMANDS_OUT_OF_SYNC, DBUG_ENTER, DBUG_RETURN, st_mysql::field_alloc, st_mysql::field_count, st_mysql::fields, st_mysql::last_used_con, st_mysql::methods, my_free, my_malloc(), MY_WME, MY_ZEROFILL, MYF, mysql, MYSQL_STATUS_GET_RESULT, MYSQL_STATUS_USE_RESULT, set_mysql_error(), st_mysql::status, st_mysql::unbuffered_fetch_owner, and unknown_sqlstate.
02763 { 02764 MYSQL_RES *result; 02765 DBUG_ENTER("cli_use_result"); 02766 02767 mysql = mysql->last_used_con; 02768 02769 if (!mysql->fields) 02770 DBUG_RETURN(0); 02771 if (mysql->status != MYSQL_STATUS_GET_RESULT) 02772 { 02773 set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); 02774 DBUG_RETURN(0); 02775 } 02776 if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result)+ 02777 sizeof(ulong)*mysql->field_count, 02778 MYF(MY_WME | MY_ZEROFILL)))) 02779 DBUG_RETURN(0); 02780 result->lengths=(ulong*) (result+1); 02781 result->methods= mysql->methods; 02782 if (!(result->row=(MYSQL_ROW) 02783 my_malloc(sizeof(result->row[0])*(mysql->field_count+1), MYF(MY_WME)))) 02784 { /* Ptrs: to one row */ 02785 my_free((gptr) result,MYF(0)); 02786 DBUG_RETURN(0); 02787 } 02788 result->fields= mysql->fields; 02789 result->field_alloc= mysql->field_alloc; 02790 result->field_count= mysql->field_count; 02791 result->current_field=0; 02792 result->handle= mysql; 02793 result->current_row= 0; 02794 mysql->fields=0; /* fields is now in result */ 02795 mysql->status=MYSQL_STATUS_USE_RESULT; 02796 mysql->unbuffered_fetch_owner= &result->unbuffered_fetch_cancelled; 02797 DBUG_RETURN(result); /* Data is read to be fetched */ 02798 }
Here is the call graph for this function:

| void end_server | ( | MYSQL * | mysql | ) |
Definition at line 846 of file client.c.
References DBUG_ENTER, DBUG_PRINT, DBUG_VOID_RETURN, free_old_query(), init_sigpipe_variables, mysql, st_mysql::net, net_end(), reset_sigpipe, set_sigpipe, st_net::vio, vio_delete, and vio_description().
Referenced by cli_advanced_command(), cli_safe_read(), and mysql_close().
00847 { 00848 DBUG_ENTER("end_server"); 00849 if (mysql->net.vio != 0) 00850 { 00851 init_sigpipe_variables 00852 DBUG_PRINT("info",("Net: %s", vio_description(mysql->net.vio))); 00853 set_sigpipe(mysql); 00854 vio_delete(mysql->net.vio); 00855 reset_sigpipe(mysql); 00856 mysql->net.vio= 0; /* Marker */ 00857 } 00858 net_end(&mysql->net); 00859 free_old_query(mysql); 00860 DBUG_VOID_RETURN; 00861 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void free_old_query | ( | MYSQL * | mysql | ) |
Definition at line 719 of file client.c.
References DBUG_ENTER, DBUG_VOID_RETURN, st_mysql::field_alloc, st_mysql::field_count, st_mysql::fields, free_root(), st_mysql::info, init_alloc_root(), MYF, mysql, and st_mysql::warning_count.
Referenced by cli_read_query_result(), end_server(), mysql_close(), mysql_list_fields(), and mysql_list_processes().
00720 { 00721 DBUG_ENTER("free_old_query"); 00722 if (mysql->fields) 00723 free_root(&mysql->field_alloc,MYF(0)); 00724 init_alloc_root(&mysql->field_alloc,8192,0); /* Assume rowlength < 8192 */ 00725 mysql->fields= 0; 00726 mysql->field_count= 0; /* For API */ 00727 mysql->warning_count= 0; 00728 mysql->info= 0; 00729 DBUG_VOID_RETURN; 00730 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void free_rows | ( | MYSQL_DATA * | cur | ) |
Definition at line 643 of file client.c.
References st_mysql_data::alloc, free_root(), my_free, and MYF.
Referenced by cli_read_prepare_result(), cli_read_rows(), mysql_free_result(), and unpack_fields().
00644 { 00645 if (cur) 00646 { 00647 free_root(&cur->alloc,MYF(0)); 00648 my_free((gptr) cur,MYF(0)); 00649 } 00650 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 140 of file client.c.
References errno, flags, and wait_for_data().
Referenced by CLI_MYSQL_REAL_CONNECT(), and mysql_manager_connect().
00142 { 00143 #if defined(__WIN__) || defined(__NETWARE__) 00144 return connect(fd, (struct sockaddr*) name, namelen); 00145 #else 00146 int flags, res, s_err; 00147 00148 /* 00149 If they passed us a timeout of zero, we should behave 00150 exactly like the normal connect() call does. 00151 */ 00152 00153 if (timeout == 0) 00154 return connect(fd, (struct sockaddr*) name, namelen); 00155 00156 flags = fcntl(fd, F_GETFL, 0); /* Set socket to not block */ 00157 #ifdef O_NONBLOCK 00158 fcntl(fd, F_SETFL, flags | O_NONBLOCK); /* and save the flags.. */ 00159 #endif 00160 00161 res= connect(fd, (struct sockaddr*) name, namelen); 00162 s_err= errno; /* Save the error... */ 00163 fcntl(fd, F_SETFL, flags); 00164 if ((res != 0) && (s_err != EINPROGRESS)) 00165 { 00166 errno= s_err; /* Restore it */ 00167 return(-1); 00168 } 00169 if (res == 0) /* Connected quickly! */ 00170 return(0); 00171 return wait_for_data(fd, timeout); 00172 #endif 00173 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void STDCALL mysql_close | ( | MYSQL * | mysql | ) |
Definition at line 2544 of file client.c.
References COM_QUIT, DBUG_ENTER, DBUG_VOID_RETURN, end_server(), st_mysql_methods::free_embedded_thd, st_mysql::free_me, free_old_query(), st_mysql::master, st_mysql::methods, my_free, MYF, mysql, mysql_close(), mysql_close_free(), mysql_close_free_options(), mysql_detach_stmt_list(), MYSQL_STATUS_READY, st_mysql::net, st_mysql::next_slave, NullS, st_mysql::reconnect, st_mysql::rpl_pivot, simple_command, st_mysql::status, st_mysql::stmts, st_mysql::thd, and st_net::vio.
Referenced by check_master_version(), client_connect(), client_disconnect(), close_cons(), db_disconnect(), dbDisconnect(), dump_remote_log_entries(), execute_commands(), handle_sigint(), Instance::is_running(), main(), mysql_close(), mysql_end(), mysql_reconnect(), mysql_set_master(), mysql_sigint(), run_task(), safe_connect(), safe_exit(), sql_real_connect(), test_bug12001(), test_bug12744(), test_bug15752(), test_bug8378(), test_bug9992(), test_multi_statements(), test_opt_reconnect(), test_prepare_grant(), test_prepare_multi_statements(), test_stmt_close(), and thread_query().
02545 { 02546 DBUG_ENTER("mysql_close"); 02547 if (mysql) /* Some simple safety */ 02548 { 02549 /* If connection is still up, send a QUIT message */ 02550 if (mysql->net.vio != 0) 02551 { 02552 free_old_query(mysql); 02553 mysql->status=MYSQL_STATUS_READY; /* Force command */ 02554 mysql->reconnect=0; 02555 simple_command(mysql,COM_QUIT,NullS,0,1); 02556 end_server(mysql); /* Sets mysql->net.vio= 0 */ 02557 } 02558 mysql_close_free_options(mysql); 02559 mysql_close_free(mysql); 02560 mysql_detach_stmt_list(&mysql->stmts); 02561 #ifndef TO_BE_DELETED 02562 /* free/close slave list */ 02563 if (mysql->rpl_pivot) 02564 { 02565 MYSQL* tmp; 02566 for (tmp = mysql->next_slave; tmp != mysql; ) 02567 { 02568 /* trick to avoid following freed pointer */ 02569 MYSQL* tmp1 = tmp->next_slave; 02570 mysql_close(tmp); 02571 tmp = tmp1; 02572 } 02573 mysql->rpl_pivot=0; 02574 } 02575 #endif 02576 if (mysql != mysql->master) 02577 mysql_close(mysql->master); 02578 #ifndef MYSQL_SERVER 02579 if (mysql->thd) 02580 (*mysql->methods->free_embedded_thd)(mysql); 02581 #endif 02582 if (mysql->free_me) 02583 my_free((gptr) mysql,MYF(0)); 02584 } 02585 DBUG_VOID_RETURN; 02586 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void mysql_close_free | ( | MYSQL * | mysql | ) | [static] |
Definition at line 2499 of file client.c.
References st_mysql::db, st_mysql::host_info, st_mysql::info_buffer, MY_ALLOW_ZERO_PTR, my_free, MYF, mysql, st_mysql::passwd, and st_mysql::user.
02500 { 02501 my_free((gptr) mysql->host_info,MYF(MY_ALLOW_ZERO_PTR)); 02502 my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR)); 02503 my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR)); 02504 my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR)); 02505 #if defined(EMBEDDED_LIBRARY) || MYSQL_VERSION_ID >= 50100 02506 my_free(mysql->info_buffer,MYF(MY_ALLOW_ZERO_PTR)); 02507 mysql->info_buffer= 0; 02508 #endif 02509 /* Clear pointers for better safety */ 02510 mysql->host_info= mysql->user= mysql->passwd= mysql->db= 0; 02511 }
| static void mysql_close_free_options | ( | MYSQL * | mysql | ) | [static] |
Definition at line 2463 of file client.c.
References st_dynamic_array::buffer, bzero, st_mysql_options::charset_dir, st_mysql_options::charset_name, st_mysql_options::client_ip, st_mysql_options::db, DBUG_ENTER, DBUG_VOID_RETURN, delete_dynamic(), st_dynamic_array::elements, st_mysql_options::host, st_mysql_options::init_commands, MY_ALLOW_ZERO_PTR, st_mysql_options::my_cnf_file, st_mysql_options::my_cnf_group, my_free, MY_WME, MYF, mysql, st_mysql::options, st_mysql_options::password, st_mysql_options::shared_memory_base_name, st_mysql_options::unix_socket, and st_mysql_options::user.
02464 { 02465 DBUG_ENTER("mysql_close_free_options"); 02466 02467 my_free(mysql->options.user,MYF(MY_ALLOW_ZERO_PTR)); 02468 my_free(mysql->options.host,MYF(MY_ALLOW_ZERO_PTR)); 02469 my_free(mysql->options.password,MYF(MY_ALLOW_ZERO_PTR)); 02470 my_free(mysql->options.unix_socket,MYF(MY_ALLOW_ZERO_PTR)); 02471 my_free(mysql->options.db,MYF(MY_ALLOW_ZERO_PTR)); 02472 my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR)); 02473 my_free(mysql->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR)); 02474 my_free(mysql->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR)); 02475 my_free(mysql->options.charset_name,MYF(MY_ALLOW_ZERO_PTR)); 02476 my_free(mysql->options.client_ip,MYF(MY_ALLOW_ZERO_PTR)); 02477 if (mysql->options.init_commands) 02478 { 02479 DYNAMIC_ARRAY *init_commands= mysql->options.init_commands; 02480 char **ptr= (char**)init_commands->buffer; 02481 char **end= ptr + init_commands->elements; 02482 for (; ptr<end; ptr++) 02483 my_free(*ptr,MYF(MY_WME)); 02484 delete_dynamic(init_commands); 02485 my_free((char*)init_commands,MYF(MY_WME)); 02486 } 02487 #ifdef HAVE_OPENSSL 02488 mysql_ssl_free(mysql); 02489 #endif /* HAVE_OPENSSL */ 02490 #ifdef HAVE_SMEM 02491 if (mysql->options.shared_memory_base_name != def_shared_memory_base_name) 02492 my_free(mysql->options.shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR)); 02493 #endif /* HAVE_SMEM */ 02494 bzero((char*) &mysql->options,sizeof(mysql->options)); 02495 DBUG_VOID_RETURN; 02496 }
Here is the call graph for this function:

| void mysql_detach_stmt_list | ( | LIST **stmt_list | __attribute__((unused)) | ) |
Definition at line 2528 of file client.c.
References st_list::data, and st_list::next.
02529 { 02530 #ifdef MYSQL_CLIENT 02531 /* Reset connection handle in all prepared statements. */ 02532 LIST *element= *stmt_list; 02533 for (; element; element= element->next) 02534 { 02535 MYSQL_STMT *stmt= (MYSQL_STMT *) element->data; 02536 stmt->mysql= 0; 02537 /* No need to call list_delete for statement here */ 02538 } 02539 *stmt_list= 0; 02540 #endif /* MYSQL_CLIENT */ 02541 }
Definition at line 2973 of file client.c.
References st_net::last_errno, mysql, and st_mysql::net.
Referenced by check_if_ignore_table(), com_use(), connect_n_handle_errors(), create_table(), DB_error(), db_error(), db_error_with_table(), DBerror(), do_connect(), do_save_master_pos(), do_sync_with_master2(), dump_table(), execute_commands(), get_table_structure(), list_table_status(), main(), my_process_result_set(), mysql_query_with_error_report(), mysql_real_query_for_lazy(), print_error(), put_error(), run_query(), run_query_normal(), run_task(), sql_connect(), sql_real_connect(), test_bug15752(), test_bug7990(), test_bug9992(), test_multi_statements(), test_prepare_grant(), util_query(), and var_query_set().
02974 { 02975 return mysql->net.last_errno; 02976 }
Here is the caller graph for this function:

| const char* STDCALL mysql_error | ( | MYSQL * | mysql | ) |
Definition at line 2979 of file client.c.
References st_net::last_error, mysql, and st_mysql::net.
Referenced by append_warnings(), build_completion_hash(), change_user(), check_if_ignore_table(), check_master_version(), com_status(), connect_n_handle_errors(), create_schema(), DB_error(), db_error(), db_error_with_table(), DBerror(), do_connect(), do_rpl_probe(), do_save_master_pos(), do_sync_with_master2(), do_wait_for_slave_to_stop(), drop_db(), drop_schema(), dump_all_databases(), dump_remote_log_entries(), dump_table(), execute_commands(), fix_object_name(), get_pidfile(), get_table_structure(), Instance::is_running(), list_dbs(), list_fields(), list_table_status(), list_tables(), main(), mysql_query_with_error_report(), mysql_store_result_for_lazy(), primary_key_fields(), print_error(), process_all_databases(), put_error(), run_query(), run_query_normal(), run_task(), safe_connect(), safe_query(), sql_connect(), test_bug10760(), test_bug15752(), test_bug9478(), test_bug9992(), test_manual_sample(), test_multi_statements(), test_parse_error_and_bad_length(), test_prepare_multi_statements(), thread_query(), util_query(), and var_query_set().
02980 { 02981 return mysql->net.last_error; 02982 }
Here is the caller graph for this function:

Definition at line 2861 of file client.c.
References st_mysql_res::current_row, st_mysql_res::data, st_mysql_methods::fetch_lengths, st_mysql_res::field_count, st_mysql_res::lengths, and st_mysql_res::methods.
Referenced by append_result(), dump_table(), get_actual_table_name(), get_table_structure(), get_view_structure(), print_tab_data(), print_table_data(), print_table_data_html(), print_table_data_xml(), print_xml_row(), and var_query_set().
02862 { 02863 MYSQL_ROW column; 02864 02865 if (!(column=res->current_row)) 02866 return 0; /* Something is wrong */ 02867 if (res->data) 02868 (*res->methods->fetch_lengths)(res->lengths, column, res->field_count); 02869 return res->lengths; 02870 }
Here is the caller graph for this function:

Definition at line 2806 of file client.c.
References CR_COMMANDS_OUT_OF_SYNC, CR_FETCH_CANCELED, st_mysql_res::current_row, st_mysql_rows::data, st_mysql_res::data, st_mysql_res::data_cursor, DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, st_mysql_res::eof, st_mysql_res::field_count, st_mysql_res::handle, st_mysql_res::lengths, mysql, MYSQL_STATUS_READY, MYSQL_STATUS_USE_RESULT, st_mysql_rows::next, read_one_row(), st_mysql_res::row, st_mysql_res::row_count, set_mysql_error(), st_mysql::status, st_mysql_res::unbuffered_fetch_cancelled, st_mysql::unbuffered_fetch_owner, and unknown_sqlstate.
Referenced by append_result(), build_completion_hash(), check_have_innodb(), check_if_ignore_table(), check_master_version(), com_server_help(), com_status(), do_save_master_pos(), do_show_master_status(), do_sync_with_master2(), do_wait_for_slave_to_stop(), dump_all_databases(), dump_all_tablespaces(), dump_events_for_db(), dump_routines_for_db(), dump_table(), dump_triggers_for_table(), execute_commands(), get_actual_table_name(), get_current_db(), get_pidfile(), get_slaves_from_master(), get_table_structure(), get_view_structure(), getTableName(), init_dumping(), init_username(), list_dbs(), list_fields(), list_table_status(), list_tables(), main(), my_process_result_set(), mysql_rpl_probe(), primary_key_fields(), print_result(), print_tab_data(), print_table_data(), print_table_data_html(), print_table_data_vertically(), print_table_data_xml(), print_warnings(), process_all_databases(), process_all_tables_in_db(), run_task(), store_values(), test_bug1644(), test_bug4172(), test_bug6049(), test_bug6058(), test_frm_bug(), test_tran_bdb(), test_tran_innodb(), var_query_set(), and verify_col_data().
02807 { 02808 DBUG_ENTER("mysql_fetch_row"); 02809 if (!res->data) 02810 { /* Unbufferred fetch */ 02811 if (!res->eof) 02812 { 02813 MYSQL *mysql= res->handle; 02814 if (mysql->status != MYSQL_STATUS_USE_RESULT) 02815 { 02816 set_mysql_error(mysql, 02817 res->unbuffered_fetch_cancelled ? 02818 CR_FETCH_CANCELED : CR_COMMANDS_OUT_OF_SYNC, 02819 unknown_sqlstate); 02820 } 02821 else if (!(read_one_row(mysql, res->field_count, res->row, res->lengths))) 02822 { 02823 res->row_count++; 02824 DBUG_RETURN(res->current_row=res->row); 02825 } 02826 DBUG_PRINT("info",("end of data")); 02827 res->eof=1; 02828 mysql->status=MYSQL_STATUS_READY; 02829 /* 02830 Reset only if owner points to us: there is a chance that somebody 02831 started new query after mysql_stmt_close(): 02832 */ 02833 if (mysql->unbuffered_fetch_owner == &res->unbuffered_fetch_cancelled) 02834 mysql->unbuffered_fetch_owner= 0; 02835 /* Don't clear handle in mysql_free_result */ 02836 res->handle=0; 02837 } 02838 DBUG_RETURN((MYSQL_ROW) NULL); 02839 } 02840 { 02841 MYSQL_ROW tmp; 02842 if (!res->data_cursor) 02843 { 02844 DBUG_PRINT("info",("end of data")); 02845 DBUG_RETURN(res->current_row=(MYSQL_ROW) NULL); 02846 } 02847 tmp = res->data_cursor->data; 02848 res->data_cursor = res->data_cursor->next; 02849 DBUG_RETURN(res->current_row=tmp); 02850 } 02851 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2345 of file client.c.
References st_mysql::last_used_con, st_mysql::last_used_slave, st_mysql::master, mysql, and st_mysql::next_slave.
02346 { 02347 MYSQL *tmp, *tmp_prev; 02348 if (mysql->master == old_mysql) 02349 mysql->master= mysql; 02350 if (mysql->last_used_con == old_mysql) 02351 mysql->last_used_con= mysql; 02352 if (mysql->last_used_slave == old_mysql) 02353 mysql->last_used_slave= mysql; 02354 for (tmp_prev = mysql, tmp = mysql->next_slave; 02355 tmp != old_mysql;tmp = tmp->next_slave) 02356 { 02357 tmp_prev= tmp; 02358 } 02359 tmp_prev->next_slave= mysql; 02360 }
| void STDCALL mysql_free_result | ( | MYSQL_RES * | result | ) |
Definition at line 865 of file client.c.
References st_mysql_res::data, DBUG_ENTER, DBUG_PRINT, DBUG_VOID_RETURN, st_mysql_res::field_alloc, st_mysql_res::fields, st_mysql_methods::flush_use_result, free_root(), free_rows(), st_mysql_res::handle, st_mysql::methods, my_free, MYF, mysql, MYSQL_STATUS_READY, MYSQL_STATUS_USE_RESULT, st_mysql_res::row, st_mysql::status, TRUE, st_mysql_res::unbuffered_fetch_cancelled, and st_mysql::unbuffered_fetch_owner.
Referenced by append_warnings(), build_completion_hash(), check_have_innodb(), check_if_ignore_table(), check_master_version(), CLI_MYSQL_REAL_CONNECT(), client_store_result(), client_use_result(), com_go(), com_server_help(), com_status(), do_save_master_pos(), do_show_master_status(), do_sync_with_master2(), do_wait_for_slave_to_stop(), dump_events_for_db(), dump_result(), dump_routines_for_db(), dump_table(), dump_triggers_for_table(), execute_commands(), get_actual_table_name(), get_current_db(), get_pidfile(), get_slaves_from_master(), get_table_structure(), get_view_structure(), getTableName(), list_dbs(), list_fields(), list_table_status(), list_tables(), main(), my_process_result(), my_process_stmt_result(), mysql_rpl_probe(), primary_key_fields(), print_result(), print_warnings(), process_all_tables_in_db(), run_query_normal(), run_query_stmt(), run_task(), stmt_fetch_init(), test_bug12001(), test_bug15752(), test_bug1644(), test_bug19671(), test_bug2247(), test_bug4172(), test_bug6049(), test_bug6058(), test_bug6096(), test_bug6761(), test_bug9735(), test_bug9992(), test_cuted_rows(), test_debug_example(), test_double_compare(), test_errors(), test_explain_bug(), test_field_flags(), test_field_misc(), test_field_names(), test_frm_bug(), test_func_fields(), test_insert(), test_list_fields(), test_long_data(), test_long_data_bin(), test_long_data_str(), test_long_data_str1(), test_mem_overun(), test_multi_statements(), test_open_direct(), test_prepare_field_result(), test_prepare_noparam(), test_prepare_resultset(), test_select_direct(), test_set_option(), test_simple_delete(), test_simple_update(), test_stmt_close(), test_tran_bdb(), test_tran_innodb(), test_ts(), test_update(), test_view_sp_list_fields(), test_warnings(), var_query_set(), and verify_col_data().
00866 { 00867 DBUG_ENTER("mysql_free_result"); 00868 DBUG_PRINT("enter",("mysql_res: %lx",result)); 00869 if (result) 00870 { 00871 MYSQL *mysql= result->handle; 00872 if (mysql) 00873 { 00874 if (mysql->unbuffered_fetch_owner == &result->unbuffered_fetch_cancelled) 00875 mysql->unbuffered_fetch_owner= 0; 00876 if (mysql->status == MYSQL_STATUS_USE_RESULT) 00877 { 00878 (*mysql->methods->flush_use_result)(mysql); 00879 mysql->status=MYSQL_STATUS_READY; 00880 if (mysql->unbuffered_fetch_owner) 00881 *mysql->unbuffered_fetch_owner= TRUE; 00882 } 00883 } 00884 free_rows(result->data); 00885 if (result->fields) 00886 free_root(&result->field_alloc,MYF(0)); 00887 if (result->row) 00888 my_free((gptr) result->row,MYF(0)); 00889 my_free((gptr) result,MYF(0)); 00890 } 00891 DBUG_VOID_RETURN; 00892 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 3003 of file client.c.
References mysql, pos(), st_mysql::server_version, strtoul(), and version().
Referenced by client_connect(), com_help(), dbConnect(), dump_all_tables_in_db(), dump_selected_tables(), init_dumping(), mysql_set_character_set(), test_explain_bug(), test_field_misc(), test_prepare_field_result(), and use_db().
03004 { 03005 uint major, minor, version; 03006 char *pos= mysql->server_version, *end_pos; 03007 major= (uint) strtoul(pos, &end_pos, 10); pos=end_pos+1; 03008 minor= (uint) strtoul(pos, &end_pos, 10); pos=end_pos+1; 03009 version= (uint) strtoul(pos, &end_pos, 10); 03010 return (ulong) major*10000L+(ulong) (minor*100+version); 03011 }
Here is the call graph for this function:

Here is the caller graph for this function:

| const char* STDCALL mysql_get_ssl_cipher | ( | MYSQL * | mysql | ) |
Definition at line 1562 of file client.c.
References DBUG_ENTER, DBUG_RETURN, mysql, st_mysql::net, SSL_get_cipher_name, and st_net::vio.
Referenced by com_status().
01563 { 01564 DBUG_ENTER("mysql_get_ssl_cipher"); 01565 #ifdef HAVE_OPENSSL 01566 if (mysql->net.vio && mysql->net.vio->ssl_arg) 01567 DBUG_RETURN(SSL_get_cipher_name((SSL*)mysql->net.vio->ssl_arg)); 01568 #endif /* HAVE_OPENSSL */ 01569 DBUG_RETURN(NULL); 01570 }
Here is the caller graph for this function:

Definition at line 1429 of file client.c.
References bzero, CLIENT_LOCAL_FILES, CONNECT_TIMEOUT, default_client_charset_info, st_mysql::free_me, my_malloc(), MY_WME, MY_ZEROFILL, MYF, mysql, MYSQL_OPT_GUESS_CONNECTION, mysql_server_init, not_error_sqlstate, strmov(), and TRUE.
Referenced by client_connect(), db_connect(), dbConnect(), do_connect(), handle_sigint(), Instance::is_running(), main(), mysql_reconnect(), mysql_sigint(), run_task(), safe_connect(), spawn_init(), sql_real_connect(), test_bug12001(), test_bug15752(), test_bug8378(), test_bug9992(), test_multi_statements(), test_opt_reconnect(), test_prepare_grant(), test_prepare_multi_statements(), test_stmt_close(), thread_query(), and util_query().
01430 { 01431 if (mysql_server_init(0, NULL, NULL)) 01432 return 0; 01433 if (!mysql) 01434 { 01435 if (!(mysql=(MYSQL*) my_malloc(sizeof(*mysql),MYF(MY_WME | MY_ZEROFILL)))) 01436 return 0; 01437 mysql->free_me=1; 01438 } 01439 else 01440 bzero((char*) (mysql), sizeof(*(mysql))); 01441 mysql->options.connect_timeout= CONNECT_TIMEOUT; 01442 mysql->last_used_con= mysql->next_slave= mysql->master = mysql; 01443 mysql->charset=default_client_charset_info; 01444 strmov(mysql->net.sqlstate, not_error_sqlstate); 01445 /* 01446 By default, we are a replication pivot. The caller must reset it 01447 after we return if this is not the case. 01448 */ 01449 #ifndef TO_BE_DELETED 01450 mysql->rpl_pivot = 1; 01451 #endif 01452 01453 /* 01454 Only enable LOAD DATA INFILE by default if configured with 01455 --enable-local-infile 01456 */ 01457 01458 #if defined(ENABLED_LOCAL_INFILE) && !defined(MYSQL_SERVER) 01459 mysql->options.client_flag|= CLIENT_LOCAL_FILES; 01460 #endif 01461 01462 #ifdef HAVE_SMEM 01463 mysql->options.shared_memory_base_name= (char*) def_shared_memory_base_name; 01464 #endif 01465 01466 mysql->options.methods_to_use= MYSQL_OPT_GUESS_CONNECTION; 01467 mysql->options.report_data_truncation= TRUE; /* default */ 01468 01469 /* 01470 By default we don't reconnect because it could silently corrupt data (after 01471 reconnection you potentially lose table locks, user variables, session 01472 variables (transactions but they are specifically dealt with in 01473 mysql_reconnect()). 01474 This is a change: < 5.0.3 mysql->reconnect was set to 1 by default. 01475 How this change impacts existing apps: 01476 - existing apps which relyed on the default will see a behaviour change; 01477 they will have to set reconnect=1 after mysql_real_connect(). 01478 - existing apps which explicitely asked for reconnection (the only way they 01479 could do it was by setting mysql.reconnect to 1 after mysql_real_connect()) 01480 will not see a behaviour change. 01481 - existing apps which explicitely asked for no reconnection 01482 (mysql.reconnect=0) will not see a behaviour change. 01483 */ 01484 mysql->reconnect= 0; 01485 01486 return mysql; 01487 }
Here is the call graph for this function:

Here is the caller graph for this function:

| C_MODE_START int mysql_init_character_set | ( | MYSQL * | mysql | ) |
Definition at line 1680 of file client.c.
References st_mysql::charset, st_mysql_options::charset_dir, st_mysql_options::charset_name, charsets_dir, CR_CANT_READ_CHARSET, default_collation_name, ER, ER_UNKNOWN_ERROR, FN_REFLEN, get_charset_by_csname(), get_charset_by_name(), get_charsets_dir(), st_net::last_errno, st_net::last_error, my_charset_same(), MY_CS_PRIMARY, my_printf_error(), my_snprintf(), my_strdup(), MY_WME, MYF, mysql, MYSQL_DEFAULT_CHARSET_NAME, MYSQL_DEFAULT_COLLATION_NAME, st_mysql::net, st_mysql::options, st_net::sqlstate, strmov(), and unknown_sqlstate.
01681 { 01682 NET *net= &mysql->net; 01683 const char *default_collation_name; 01684 01685 /* Set character set */ 01686 if (!mysql->options.charset_name) 01687 { 01688 default_collation_name= MYSQL_DEFAULT_COLLATION_NAME; 01689 if (!(mysql->options.charset_name= 01690 my_strdup(MYSQL_DEFAULT_CHARSET_NAME,MYF(MY_WME)))) 01691 return 1; 01692 } 01693 else 01694 default_collation_name= NULL; 01695 01696 { 01697 const char *save= charsets_dir; 01698 if (mysql->options.charset_dir) 01699 charsets_dir=mysql->options.charset_dir; 01700 mysql->charset=get_charset_by_csname(mysql->options.charset_name, 01701 MY_CS_PRIMARY, MYF(MY_WME)); 01702 if (mysql->charset && default_collation_name) 01703 { 01704 CHARSET_INFO *collation; 01705 if ((collation= 01706 get_charset_by_name(default_collation_name, MYF(MY_WME)))) 01707 { 01708 if (!my_charset_same(mysql->charset, collation)) 01709 { 01710 my_printf_error(ER_UNKNOWN_ERROR, 01711 "COLLATION %s is not valid for CHARACTER SET %s", 01712 MYF(0), 01713 default_collation_name, mysql->options.charset_name); 01714 mysql->charset= NULL; 01715 } 01716 else 01717 { 01718 mysql->charset= collation; 01719 } 01720 } 01721 else 01722 mysql->charset= NULL; 01723 } 01724 charsets_dir= save; 01725 } 01726 01727 if (!mysql->charset) 01728 { 01729 net->last_errno=CR_CANT_READ_CHARSET; 01730 strmov(net->sqlstate, unknown_sqlstate); 01731 if (mysql->options.charset_dir) 01732 my_snprintf(net->last_error, sizeof(net->last_error)-1, 01733 ER(net->last_errno), 01734 mysql->options.charset_name, 01735 mysql->options.charset_dir); 01736 else 01737 { 01738 char cs_dir_name[FN_REFLEN]; 01739 get_charsets_dir(cs_dir_name); 01740 my_snprintf(net->last_error, sizeof(net->last_error)-1, 01741 ER(net->last_errno), 01742 mysql->options.charset_name, 01743 cs_dir_name); 01744 } 01745 return 1; 01746 } 01747 return 0; 01748 }
Here is the call graph for this function:

| unsigned int STDCALL mysql_num_fields | ( | MYSQL_RES * | res | ) |
Definition at line 2968 of file client.c.
References st_mysql_res::field_count.
Referenced by append_result(), build_completion_hash(), com_server_help(), dump_table(), dump_triggers_for_table(), get_master(), get_slaves_from_master(), list_tables(), main(), my_print_dashes(), my_print_result_metadata(), my_process_result_set(), my_process_stmt_result(), print_res_row(), print_row(), print_tab_data(), print_table_data(), print_table_data_html(), print_table_data_vertically(), print_table_data_xml(), run_query_normal(), run_query_stmt(), stmt_fetch_init(), test_bug6096(), test_bug6761(), test_explain_bug(), test_field_flags(), test_field_misc(), test_mem_overun(), test_ts(), test_view_sp_list_fields(), var_query_set(), and verify_field_count().
02969 { 02970 return res->field_count; 02971 }
Here is the caller graph for this function:

| my_ulonglong STDCALL mysql_num_rows | ( | MYSQL_RES * | res | ) |
Definition at line 2963 of file client.c.
References st_mysql_res::row_count.
Referenced by build_completion_hash(), com_go(), com_server_help(), dump_events_for_db(), dump_routines_for_db(), dump_triggers_for_table(), execute_commands(), get_actual_table_name(), get_table_structure(), list_dbs(), list_fields(), main(), print_table_data(), and print_warnings().
02964 { 02965 return res->row_count; 02966 }
Here is the caller graph for this function:

| int STDCALL mysql_options | ( | MYSQL * | mysql, | |
| enum mysql_option | option, | |||
| const char * | arg | |||
| ) |
Definition at line 2874 of file client.c.
References add_init_command(), st_mysql_options::charset_dir, st_mysql_options::charset_name, CLIENT_COMPRESS, st_mysql_options::client_flag, st_mysql_options::client_ip, CLIENT_LOCAL_FILES, st_mysql_options::compress, st_mysql_options::connect_timeout, DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, st_mysql_options::methods_to_use, MY_ALLOW_ZERO_PTR, st_mysql_options::my_cnf_file, st_mysql_options::my_cnf_group, my_free, my_strdup(), MY_WME, MYF, mysql, MYSQL_INIT_COMMAND, MYSQL_OPT_COMPRESS, MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_GUESS_CONNECTION, MYSQL_OPT_LOCAL_INFILE, MYSQL_OPT_NAMED_PIPE, MYSQL_OPT_PROTOCOL, MYSQL_OPT_READ_TIMEOUT, MYSQL_OPT_RECONNECT, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_OPT_USE_EMBEDDED_CONNECTION, MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_WRITE_TIMEOUT, MYSQL_PROTOCOL_PIPE, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_SECURE_AUTH, MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_SET_CLIENT_IP, MYSQL_SHARED_MEMORY_BASE_NAME, st_mysql::options, st_mysql_options::protocol, st_mysql_options::read_timeout, st_mysql::reconnect, st_mysql_options::report_data_truncation, st_mysql_options::secure_auth, st_mysql_options::shared_memory_base_name, st_mysql_options::ssl_verify_server_cert, test, and st_mysql_options::write_timeout.
Referenced by connect_n_handle_errors(), db_connect(), dbConnect(), do_connect(), main(), safe_connect(), sql_real_connect(), test_bug8378(), test_opt_reconnect(), and test_truncation_option().
02875 { 02876 DBUG_ENTER("mysql_option"); 02877 DBUG_PRINT("enter",("option: %d",(int) option)); 02878 switch (option) { 02879 case MYSQL_OPT_CONNECT_TIMEOUT: 02880 mysql->options.connect_timeout= *(uint*) arg; 02881 break; 02882 case MYSQL_OPT_READ_TIMEOUT: 02883 mysql->options.read_timeout= *(uint*) arg; 02884 break; 02885 case MYSQL_OPT_WRITE_TIMEOUT: 02886 mysql->options.write_timeout= *(uint*) arg; 02887 break; 02888 case MYSQL_OPT_COMPRESS: 02889 mysql->options.compress= 1; /* Remember for connect */ 02890 mysql->options.client_flag|= CLIENT_COMPRESS; 02891 break; 02892 case MYSQL_OPT_NAMED_PIPE: /* This option is depricated */ 02893 mysql->options.protocol=MYSQL_PROTOCOL_PIPE; /* Force named pipe */ 02894 break; 02895 case MYSQL_OPT_LOCAL_INFILE: /* Allow LOAD DATA LOCAL ?*/ 02896 if (!arg || test(*(uint*) arg)) 02897 mysql->options.client_flag|= CLIENT_LOCAL_FILES; 02898 else 02899 mysql->options.client_flag&= ~CLIENT_LOCAL_FILES; 02900 break; 02901 case MYSQL_INIT_COMMAND: 02902 add_init_command(&mysql->options,arg); 02903 break; 02904 case MYSQL_READ_DEFAULT_FILE: 02905 my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR)); 02906 mysql->options.my_cnf_file=my_strdup(arg,MYF(MY_WME)); 02907 break; 02908 case MYSQL_READ_DEFAULT_GROUP: 02909 my_free(mysql->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR)); 02910 mysql->options.my_cnf_group=my_strdup(arg,MYF(MY_WME)); 02911 break; 02912 case MYSQL_SET_CHARSET_DIR: 02913 my_free(mysql->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR)); 02914 mysql->options.charset_dir=my_strdup(arg,MYF(MY_WME)); 02915 break; 02916 case MYSQL_SET_CHARSET_NAME: 02917 my_free(mysql->options.charset_name,MYF(MY_ALLOW_ZERO_PTR)); 02918 mysql->options.charset_name=my_strdup(arg,MYF(MY_WME)); 02919 break; 02920 case MYSQL_OPT_PROTOCOL: 02921 mysql->options.protocol= *(uint*) arg; 02922 break; 02923 case MYSQL_SHARED_MEMORY_BASE_NAME: 02924 #ifdef HAVE_SMEM 02925 if (mysql->options.shared_memory_base_name != def_shared_memory_base_name) 02926 my_free(mysql->options.shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR)); 02927 mysql->options.shared_memory_base_name=my_strdup(arg,MYF(MY_WME)); 02928 #endif 02929 break; 02930 case MYSQL_OPT_USE_REMOTE_CONNECTION: 02931 case MYSQL_OPT_USE_EMBEDDED_CONNECTION: 02932 case MYSQL_OPT_GUESS_CONNECTION: 02933 mysql->options.methods_to_use= option; 02934 break; 02935 case MYSQL_SET_CLIENT_IP: 02936 mysql->options.client_ip= my_strdup(arg, MYF(MY_WME)); 02937 break; 02938 case MYSQL_SECURE_AUTH: 02939 mysql->options.secure_auth= *(my_bool *) arg; 02940 break; 02941 case MYSQL_REPORT_DATA_TRUNCATION: 02942 mysql->options.report_data_truncation= test(*(my_bool *) arg); 02943 break; 02944 case MYSQL_OPT_RECONNECT: 02945 mysql->reconnect= *(my_bool *) arg; 02946 break; 02947 case MYSQL_OPT_SSL_VERIFY_SERVER_CERT: 02948 mysql->options.ssl_verify_server_cert= *(my_bool *) arg; 02949 break; 02950 default: 02951 DBUG_RETURN(1); 02952 } 02953 DBUG_RETURN(0); 02954 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void mysql_read_default_options | ( | struct st_mysql_options * | options, | |
| const char * | filename, | |||
| const char * | group | |||
| ) |
Definition at line 941 of file client.c.
References add_init_command(), atoi(), CLIENT_COMPRESS, CLIENT_FOUND_ROWS, CLIENT_INTERACTIVE, CLIENT_LOCAL_FILES, CLIENT_MULTI_RESULTS, CLIENT_MULTI_STATEMENTS, DBUG_ENTER, DBUG_PRINT, DBUG_VOID_RETURN, exit, find_type(), free_defaults(), load_defaults(), MY_ALLOW_ZERO_PTR, my_free, my_strdup(), MY_WME, MYF, mysql_debug(), MYSQL_PROTOCOL_PIPE, option_types, options(), sql_protocol_typelib, strcend(), test, and TRUE.
00943 { 00944 int argc; 00945 char *argv_buff[1],**argv; 00946 const char *groups[3]; 00947 DBUG_ENTER("mysql_read_default_options"); 00948 DBUG_PRINT("enter",("file: %s group: %s",filename,group ? group :"NULL")); 00949 00950 argc=1; argv=argv_buff; argv_buff[0]= (char*) "client"; 00951 groups[0]= (char*) "client"; groups[1]= (char*) group; groups[2]=0; 00952 00953 load_defaults(filename, groups, &argc, &argv); 00954 if (argc != 1) /* If some default option */ 00955 { 00956 char **option=argv; 00957 while (*++option) 00958 { 00959 /* DBUG_PRINT("info",("option: %s",option[0])); */ 00960 if (option[0][0] == '-' && option[0][1] == '-') 00961 { 00962 char *end=strcend(*option,'='); 00963 char *opt_arg=0; 00964 if (*end) 00965 { 00966 opt_arg=end+1; 00967 *end=0; /* Remove '=' */ 00968 } 00969 /* Change all '_' in variable name to '-' */ 00970 for (end= *option ; *(end= strcend(end,'_')) ; ) 00971 *end= '-'; 00972 switch (find_type(*option+2,&option_types,2)) { 00973 case 1: /* port */ 00974 if (opt_arg) 00975 options->port=atoi(opt_arg); 00976 break; 00977 case 2: /* socket */ 00978 if (opt_arg) 00979 { 00980 my_free(options->unix_socket,MYF(MY_ALLOW_ZERO_PTR)); 00981 options->unix_socket=my_strdup(opt_arg,MYF(MY_WME)); 00982 } 00983 break; 00984 case 3: /* compress */ 00985 options->compress=1; 00986 options->client_flag|= CLIENT_COMPRESS; 00987 break; 00988 case 4: /* password */ 00989 if (opt_arg) 00990 { 00991 my_free(options->password,MYF(MY_ALLOW_ZERO_PTR)); 00992 options->password=my_strdup(opt_arg,MYF(MY_WME)); 00993 } 00994 break; 00995 case 5: 00996 options->protocol = MYSQL_PROTOCOL_PIPE; 00997 case 20: /* connect_timeout */ 00998 case 6: /* timeout */ 00999 if (opt_arg) 01000 options->connect_timeout=atoi(opt_arg); 01001 break; 01002 case 7: /* user */ 01003 if (opt_arg) 01004 { 01005 my_free(options->user,MYF(MY_ALLOW_ZERO_PTR)); 01006 options->user=my_strdup(opt_arg,MYF(MY_WME)); 01007 } 01008 break; 01009 case 8: /* init-command */ 01010 add_init_command(options,opt_arg); 01011 break; 01012 case 9: /* host */ 01013 if (opt_arg) 01014 { 01015 my_free(options->host,MYF(MY_ALLOW_ZERO_PTR)); 01016 options->host=my_strdup(opt_arg,MYF(MY_WME)); 01017 } 01018 break; 01019 case 10: /* database */ 01020 if (opt_arg) 01021 { 01022 my_free(options->db,MYF(MY_ALLOW_ZERO_PTR)); 01023 options->db=my_strdup(opt_arg,MYF(MY_WME)); 01024 } 01025 break; 01026 case 11: /* debug */ 01027 #ifdef MYSQL_CLIENT 01028 mysql_debug(opt_arg ? opt_arg : "d:t:o,/tmp/client.trace"); 01029 break; 01030 #endif 01031 case 12: /* return-found-rows */ 01032 options->client_flag|=CLIENT_FOUND_ROWS; 01033 break; 01034 #ifdef HAVE_OPENSSL 01035 case 13: /* ssl_key */ 01036 my_free(options->ssl_key, MYF(MY_ALLOW_ZERO_PTR)); 01037 options->ssl_key = my_strdup(opt_arg, MYF(MY_WME)); 01038 break; 01039 case 14: /* ssl_cert */ 01040 my_free(options->ssl_cert, MYF(MY_ALLOW_ZERO_PTR)); 01041 options->ssl_cert = my_strdup(opt_arg, MYF(MY_WME)); 01042 break; 01043 case 15: /* ssl_ca */ 01044 my_free(options->ssl_ca, MYF(MY_ALLOW_ZERO_PTR)); 01045 options->ssl_ca = my_strdup(opt_arg, MYF(MY_WME)); 01046 break; 01047 case 16: /* ssl_capath */ 01048 my_free(options->ssl_capath, MYF(MY_ALLOW_ZERO_PTR)); 01049 options->ssl_capath = my_strdup(opt_arg, MYF(MY_WME)); 01050 break; 01051 #else 01052 case 13: /* Ignore SSL options */ 01053 case 14: 01054 case 15: 01055 case 16: 01056 break; 01057 #endif /* HAVE_OPENSSL */ 01058 case 17: /* charset-lib */ 01059 my_free(options->charset_dir,MYF(MY_ALLOW_ZERO_PTR)); 01060 options->charset_dir = my_strdup(opt_arg, MYF(MY_WME)); 01061 break; 01062 case 18: 01063 my_free(options->charset_name,MYF(MY_ALLOW_ZERO_PTR)); 01064 options->charset_name = my_strdup(opt_arg, MYF(MY_WME)); 01065 break; 01066 case 19: /* Interactive-timeout */ 01067 options->client_flag|= CLIENT_INTERACTIVE; 01068 break; 01069 case 21: 01070 if (!opt_arg || atoi(opt_arg) != 0) 01071 options->client_flag|= CLIENT_LOCAL_FILES; 01072 else 01073 options->client_flag&= ~CLIENT_LOCAL_FILES; 01074 break; 01075 case 22: 01076 options->client_flag&= ~CLIENT_LOCAL_FILES; 01077 break; 01078 case 23: /* replication probe */ 01079 #ifndef TO_BE_DELETED 01080 options->rpl_probe= 1; 01081 #endif 01082 break; 01083 case 24: /* enable-reads-from-master */ 01084 options->no_master_reads= 0; 01085 break; 01086 case 25: /* repl-parse-query */ 01087 #ifndef TO_BE_DELETED 01088 options->rpl_parse= 1; 01089 #endif 01090 break; 01091 case 27: 01092 if (opt_arg) 01093 options->max_allowed_packet= atoi(opt_arg); 01094 break; 01095 case 28: /* protocol */ 01096 if ((options->protocol= find_type(opt_arg, 01097 &sql_protocol_typelib,0)) <= 0) 01098 { 01099 fprintf(stderr, "Unknown option to protocol: %s\n", opt_arg); 01100 exit(1); 01101 } 01102 break; 01103 case 29: /* shared_memory_base_name */ 01104 #ifdef HAVE_SMEM 01105 if (options->shared_memory_base_name != def_shared_memory_base_name) 01106 my_free(options->shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR)); 01107 options->shared_memory_base_name=my_strdup(opt_arg,MYF(MY_WME)); 01108 #endif 01109 break; 01110 case 30: 01111 options->client_flag|= CLIENT_MULTI_RESULTS; 01112 break; 01113 case 31: 01114 case 32: 01115 options->client_flag|= CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS; 01116 break; 01117 case 33: /* secure-auth */ 01118 options->secure_auth= TRUE; 01119 break; 01120 case 34: /* report-data-truncation */ 01121 options->report_data_truncation= opt_arg ? test(atoi(opt_arg)) : 1; 01122 break; 01123 default: 01124 DBUG_PRINT("warning",("unknown option: %s",option[0])); 01125 } 01126 } 01127 } 01128 } 01129 free_defaults(argv); 01130 DBUG_VOID_RETURN; 01131 }
Here is the call graph for this function:

Definition at line 2691 of file client.c.
References DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, st_mysql::methods, mysql, mysql_send_query(), and st_mysql_methods::read_query_result.
Referenced by append_warnings(), CLI_MYSQL_REAL_CONNECT(), dump_all_tables_in_db(), dump_all_views_in_db(), dump_selected_tables(), dump_table(), handle_request_for_tables(), handle_sigint(), lock_table(), mysql_autocommit(), mysql_commit(), mysql_query(), mysql_real_query_for_lazy(), mysql_rollback(), mysql_set_character_set(), mysql_sigint(), run_query(), test_bug11901(), test_bug11909(), test_bug15752(), test_bug17667(), test_bug1946(), test_bug3035(), test_bug3796(), test_bug4172(), test_bug4231(), test_bug5126(), test_bug5194(), test_bug6046(), test_bug6049(), test_bug6058(), test_bug6096(), test_bug6761(), test_bug8330(), test_bug8378(), test_bug8722(), test_conversion(), test_datetime_ranges(), test_mem_overun(), test_parse_error_and_bad_length(), test_ps_i18n(), test_rewind(), test_truncation(), and var_query_set().
02692 { 02693 DBUG_ENTER("mysql_real_query"); 02694 DBUG_PRINT("enter",("handle: %lx",mysql)); 02695 DBUG_PRINT("query",("Query = '%-.4096s'",query)); 02696 02697 if (mysql_send_query(mysql,query,length)) 02698 DBUG_RETURN(1); 02699 DBUG_RETURN((int) (*mysql->methods->read_query_result)(mysql)); 02700 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2364 of file client.c.
References bzero, st_mysql::charset, st_mysql::client_flag, CLIENT_REMEMBER_OPTIONS, CR_SERVER_GONE_ERROR, charset_info_st::csname, st_list::data, st_mysql::db, DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, st_mysql::free_me, st_mysql::host, st_mysql::host_info, st_net::last_errno, st_net::last_error, list_add(), mysql, mysql_close(), mysql_init(), mysql_real_connect(), mysql_set_character_set(), MYSQL_STMT_INIT_DONE, st_mysql::net, st_list::next, st_mysql::options, st_mysql::passwd, st_mysql::port, st_mysql::reconnect, st_mysql::rpl_pivot, st_mysql::server_status, SERVER_STATUS_IN_TRANS, set_mysql_error(), st_net::sqlstate, st_mysql::stmts, strmov(), st_mysql::unix_socket, unknown_sqlstate, and st_mysql::user.
Referenced by cli_advanced_command().
02365 { 02366 MYSQL tmp_mysql; 02367 DBUG_ENTER("mysql_reconnect"); 02368 02369 if (!mysql->reconnect || 02370 (mysql->server_status & SERVER_STATUS_IN_TRANS) || !mysql->host_info) 02371 { 02372 /* Allow reconnect next time */ 02373 mysql->server_status&= ~SERVER_STATUS_IN_TRANS; 02374 set_mysql_error(mysql, CR_SERVER_GONE_ERROR, unknown_sqlstate); 02375 DBUG_RETURN(1); 02376 } 02377 mysql_init(&tmp_mysql); 02378 tmp_mysql.options= mysql->options; 02379 tmp_mysql.rpl_pivot= mysql->rpl_pivot; 02380 02381 if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd, 02382 mysql->db, mysql->port, mysql->unix_socket, 02383 mysql->client_flag | CLIENT_REMEMBER_OPTIONS)) 02384 { 02385 mysql->net.last_errno= tmp_mysql.net.last_errno; 02386 strmov(mysql->net.last_error, tmp_mysql.net.last_error); 02387 strmov(mysql->net.sqlstate, tmp_mysql.net.sqlstate); 02388 DBUG_RETURN(1); 02389 } 02390 if (mysql_set_character_set(&tmp_mysql, mysql->charset->csname)) 02391 { 02392 DBUG_PRINT("error", ("mysql_set_character_set() failed")); 02393 bzero((char*) &tmp_mysql.options,sizeof(tmp_mysql.options)); 02394 mysql_close(&tmp_mysql); 02395 mysql->net.last_errno= tmp_mysql.net.last_errno; 02396 strmov(mysql->net.last_error, tmp_mysql.net.last_error); 02397 strmov(mysql->net.sqlstate, tmp_mysql.net.sqlstate); 02398 DBUG_RETURN(1); 02399 } 02400 02401 DBUG_PRINT("info", ("reconnect succeded")); 02402 tmp_mysql.reconnect= 1; 02403 tmp_mysql.free_me= mysql->free_me; 02404 02405 /* 02406 For each stmt in mysql->stmts, move it to tmp_mysql if it is 02407 in state MYSQL_STMT_INIT_DONE, otherwise close it. 02408 */ 02409 { 02410 LIST *element= mysql->stmts; 02411 for (; element; element= element->next) 02412 { 02413 MYSQL_STMT *stmt= (MYSQL_STMT *) element->data; 02414 if (stmt->state != MYSQL_STMT_INIT_DONE) 02415 { 02416 stmt->mysql= 0; 02417 } 02418 else 02419 { 02420 tmp_mysql.stmts= list_add(tmp_mysql.stmts, &stmt->list); 02421 } 02422 /* No need to call list_delete for statement here */ 02423 } 02424 mysql->stmts= NULL; 02425 } 02426 02427 /* Don't free options as these are now used in tmp_mysql */ 02428 bzero((char*) &mysql->options,sizeof(mysql->options)); 02429 mysql->free_me=0; 02430 mysql_close(mysql); 02431 *mysql=tmp_mysql; 02432 mysql_fix_pointers(mysql, &tmp_mysql); /* adjust connection pointers */ 02433 net_clear(&mysql->net); 02434 mysql->affected_rows= ~(my_ulonglong) 0; 02435 DBUG_RETURN(0); 02436 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int STDCALL mysql_select_db | ( | MYSQL * | mysql, | |
| const char * | db | |||
| ) |
Definition at line 2444 of file client.c.
References COM_INIT_DB, st_mysql::db, DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, error, MY_ALLOW_ZERO_PTR, my_free, my_strdup(), MY_WME, MYF, mysql, simple_command, and strlen().
Referenced by CLI_MYSQL_REAL_CONNECT(), com_use(), create_schema(), db_connect(), dump_all_views_in_db(), init_dumping(), list_dbs(), list_fields(), list_tables(), main(), test_bug6081(), and use_db().
02445 { 02446 int error; 02447 DBUG_ENTER("mysql_select_db"); 02448 DBUG_PRINT("enter",("db: '%s'",db)); 02449 02450 if ((error=simple_command(mysql,COM_INIT_DB,db,(ulong) strlen(db),0))) 02451 DBUG_RETURN(error); 02452 my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR)); 02453 mysql->db=my_strdup(db,MYF(MY_WME)); 02454 DBUG_RETURN(0); 02455 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2666 of file client.c.
References COM_QUERY, DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, st_mysql::last_used_con, mysql, mysql_master_send_query, MYSQL_RPL_ADMIN, MYSQL_RPL_MASTER, mysql_rpl_query_type, MYSQL_RPL_SLAVE, mysql_slave_send_query, st_mysql::options, st_mysql_options::rpl_parse, st_mysql::rpl_pivot, and simple_command.
Referenced by mysql_real_query(), and run_query_normal().
02667 { 02668 DBUG_ENTER("mysql_send_query"); 02669 DBUG_PRINT("enter",("rpl_parse: %d rpl_pivot: %d", 02670 mysql->options.rpl_parse, mysql->rpl_pivot)); 02671 #ifndef TO_BE_DELETED 02672 if (mysql->options.rpl_parse && mysql->rpl_pivot) 02673 { 02674 switch (mysql_rpl_query_type(query, length)) { 02675 case MYSQL_RPL_MASTER: 02676 DBUG_RETURN(mysql_master_send_query(mysql, query, length)); 02677 case MYSQL_RPL_SLAVE: 02678 DBUG_RETURN(mysql_slave_send_query(mysql, query, length)); 02679 case MYSQL_RPL_ADMIN: 02680 break; /* fall through */ 02681 } 02682 } 02683 mysql->last_used_con = mysql; 02684 #endif 02685 02686 DBUG_RETURN(simple_command(mysql, COM_QUERY, query, length, 1)); 02687 }
Here is the caller graph for this function:

| int STDCALL mysql_set_character_set | ( | MYSQL * | mysql, | |
| const char * | cs_name | |||
| ) |
Definition at line 3020 of file client.c.
References st_mysql::charset, st_mysql_options::charset_dir, charsets_dir, CR_CANT_READ_CHARSET, ER, FN_REFLEN, get_charset_by_csname(), get_charsets_dir(), st_net::last_errno, st_net::last_error, MY_CS_NAME_SIZE, MY_CS_PRIMARY, my_snprintf(), MYF, mysql, mysql_get_server_version(), mysql_real_query(), st_mysql::net, st_mysql::options, st_net::sqlstate, strlen(), strmov(), and unknown_sqlstate.
Referenced by mysql_reconnect(), and test_client_character_set().
03021 { 03022 struct charset_info_st *cs; 03023 const char *save_csdir= charsets_dir; 03024 03025 if (mysql->options.charset_dir) 03026 charsets_dir= mysql->options.charset_dir; 03027 03028 if (strlen(cs_name) < MY_CS_NAME_SIZE && 03029 (cs= get_charset_by_csname(cs_name, MY_CS_PRIMARY, MYF(0)))) 03030 { 03031 char buff[MY_CS_NAME_SIZE + 10]; 03032 charsets_dir= save_csdir; 03033 /* Skip execution of "SET NAMES" for pre-4.1 servers */ 03034 if (mysql_get_server_version(mysql) < 40100) 03035 return 0; 03036 sprintf(buff, "SET NAMES %s", cs_name); 03037 if (!mysql_real_query(mysql, buff, strlen(buff))) 03038 { 03039 mysql->charset= cs; 03040 } 03041 } 03042 else 03043 { 03044 char cs_dir_name[FN_REFLEN]; 03045 get_charsets_dir(cs_dir_name); 03046 mysql->net.last_errno= CR_CANT_READ_CHARSET; 03047 strmov(mysql->net.sqlstate, unknown_sqlstate); 03048 my_snprintf(mysql->net.last_error, sizeof(mysql->net.last_error) - 1, 03049 ER(mysql->net.last_errno), cs_name, cs_dir_name); 03050 03051 } 03052 charsets_dir= save_csdir; 03053 return mysql->net.last_errno; 03054 }
Here is the call graph for this function:

Here is the caller graph for this function:

| 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)) | |||
| ) |
Definition at line 1498 of file client.c.
References cert, cipher, DBUG_ENTER, DBUG_RETURN, FALSE, key, mysql, st_mysql::options, st_mysql_options::ssl_ca, st_mysql_options::ssl_capath, st_mysql_options::ssl_cert, st_mysql_options::ssl_cipher, st_mysql_options::ssl_key, st_mysql_options::ssl_verify_server_cert, and strdup_if_not_null.
01504 { 01505 DBUG_ENTER("mysql_ssl_set"); 01506 #ifdef HAVE_OPENSSL 01507 mysql->options.ssl_key= strdup_if_not_null(key); 01508 mysql->options.ssl_cert= strdup_if_not_null(cert); 01509 mysql->options.ssl_ca= strdup_if_not_null(ca); 01510 mysql->options.ssl_capath= strdup_if_not_null(capath); 01511 mysql->options.ssl_cipher= strdup_if_not_null(cipher); 01512 mysql->options.ssl_verify_server_cert= FALSE; /* Off by default */ 01513 #endif /* HAVE_OPENSSL */ 01514 DBUG_RETURN(0); 01515 }
Definition at line 2708 of file client.c.
References st_mysql::affected_rows, CR_COMMANDS_OUT_OF_SYNC, CR_OUT_OF_MEMORY, st_mysql_data::data, st_mysql_res::data, st_mysql_res::data_cursor, DBUG_ENTER, DBUG_RETURN, st_mysql_res::eof, st_mysql::field_alloc, st_mysql_res::field_alloc, st_mysql_res::field_count, st_mysql::field_count, st_mysql_res::fields, st_mysql::fields, st_mysql::last_used_con, st_mysql_res::lengths, st_mysql::methods, st_mysql_res::methods, my_free, my_malloc(), MY_WME, MY_ZEROFILL, MYF, mysql, MYSQL_STATUS_GET_RESULT, MYSQL_STATUS_READY, st_mysql_methods::read_rows, st_mysql_res::row_count, st_mysql_data::rows, set_mysql_error(), st_mysql::status, st_mysql::unbuffered_fetch_owner, and unknown_sqlstate.
Referenced by append_warnings(), build_completion_hash(), check_master_version(), client_store_result(), do_save_master_pos(), do_sync_with_master2(), do_wait_for_slave_to_stop(), dump_all_databases(), dump_result(), dump_table(), execute_commands(), get_actual_table_name(), get_pidfile(), get_slaves_from_master(), get_table_structure(), get_view_structure(), init_dumping(), list_dbs(), list_fields(), list_table_status(), list_tables(), main(), my_process_result(), mysql_list_dbs(), mysql_list_processes(), mysql_list_tables(), mysql_query_with_error_report(), mysql_rpl_probe(), mysql_store_result_for_lazy(), primary_key_fields(), process_all_databases(), process_all_tables_in_db(), run_query_normal(), run_task(), test_bug11718(), test_bug15752(), test_bug1644(), test_bug2247(), test_bug4172(), test_bug6049(), test_bug6058(), test_bug6096(), test_bug9735(), test_bug9992(), test_cuted_rows(), test_double_compare(), test_errors(), test_field_misc(), test_frm_bug(), test_func_fields(), test_insert(), test_long_data(), test_long_data_bin(), test_long_data_str(), test_long_data_str1(), test_multi_statements(), test_open_direct(), test_prepare_noparam(), test_select_direct(), test_set_option(), test_simple_delete(), test_simple_update(), test_stmt_close(), test_tran_bdb(), test_tran_innodb(), test_update(), test_warnings(), and var_query_set().
02709 { 02710 MYSQL_RES *result; 02711 DBUG_ENTER("mysql_store_result"); 02712 /* read from the actually used connection */ 02713 mysql = mysql->last_used_con; 02714 if (!mysql->fields) 02715 DBUG_RETURN(0); 02716 if (mysql->status != MYSQL_STATUS_GET_RESULT) 02717 { 02718 set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); 02719 DBUG_RETURN(0); 02720 } 02721 mysql->status=MYSQL_STATUS_READY; /* server is ready */ 02722 if (!(result=(MYSQL_RES*) my_malloc((uint) (sizeof(MYSQL_RES)+ 02723 sizeof(ulong) * 02724 mysql->field_count), 02725 MYF(MY_WME | MY_ZEROFILL)))) 02726 { 02727 set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate); 02728 DBUG_RETURN(0); 02729 } 02730 result->methods= mysql->methods; 02731 result->eof=1; /* Marker for buffered */ 02732 result->lengths=(ulong*) (result+1); 02733 if (!(result->data= 02734 (*mysql->methods->read_rows)(mysql,mysql->fields,mysql->field_count))) 02735 { 02736 my_free((gptr) result,MYF(0)); 02737 DBUG_RETURN(0); 02738 } 02739 mysql->affected_rows= result->row_count= result->data->rows; 02740 result->data_cursor= result->data->data; 02741 result->fields= mysql->fields; 02742 result->field_alloc= mysql->field_alloc; 02743 result->field_count= mysql->field_count; 02744 /* The rest of result members is bzeroed in malloc */ 02745 mysql->fields=0; /* fields is now in result */ 02746 /* just in case this was mistakenly called after mysql_stmt_execute() */ 02747 mysql->unbuffered_fetch_owner= 0; 02748 DBUG_RETURN(result); /* Data fetched */ 02749 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1375 of file client.c.
References cli_safe_read(), CR_UNKNOWN_ERROR, mysql, st_mysql::net, net_field_length(), NULL_LENGTH, packet_error, pos(), st_net::read_pos, st_mysql::server_status, set_mysql_error(), uint2korr, unknown_sqlstate, and st_mysql::warning_count.
01376 { 01377 uint field; 01378 ulong pkt_len,len; 01379 uchar *pos, *prev_pos, *end_pos; 01380 NET *net= &mysql->net; 01381 01382 if ((pkt_len=cli_safe_read(mysql)) == packet_error) 01383 return -1; 01384 if (pkt_len <= 8 && net->read_pos[0] == 254) 01385 { 01386 if (pkt_len > 1) /* MySQL 4.1 protocol */ 01387 { 01388 mysql->warning_count= uint2korr(net->read_pos+1); 01389 mysql->server_status= uint2korr(net->read_pos+3); 01390 } 01391 return 1; /* End of data */ 01392 } 01393 prev_pos= 0; /* allowed to write at packet[-1] */ 01394 pos=net->read_pos; 01395 end_pos=pos+pkt_len; 01396 for (field=0 ; field < fields ; field++) 01397 { 01398 if ((len=(ulong) net_field_length(&pos)) == NULL_LENGTH) 01399 { /* null field */ 01400 row[field] = 0; 01401 *lengths++=0; 01402 } 01403 else 01404 { 01405 if (len > (ulong) (end_pos - pos)) 01406 { 01407 set_mysql_error(mysql, CR_UNKNOWN_ERROR, unknown_sqlstate); 01408 return -1; 01409 } 01410 row[field] = (char*) pos; 01411 pos+=len; 01412 *lengths++=len; 01413 } 01414 if (prev_pos) 01415 *prev_pos=0; /* Terminate prev field */ 01416 prev_pos=pos; 01417 } 01418 row[field]=(char*) prev_pos+1; /* End of last field */ 01419 *prev_pos=0; /* Terminate last field */ 01420 return 0; 01421 }
Here is the call graph for this function:

| void set_mysql_error | ( | MYSQL * | mysql, | |
| int | errcode, | |||
| const char * | sqlstate | |||
| ) |
Definition at line 736 of file client.c.
References DBUG_ASSERT, DBUG_ENTER, DBUG_PRINT, DBUG_VOID_RETURN, ER, st_net::last_errno, st_net::last_error, mysql, st_mysql::net, st_net::sqlstate, and strmov().
Referenced by cli_advanced_command(), CLI_MYSQL_REAL_CONNECT(), cli_read_rows(), cli_safe_read(), cli_use_result(), mysql_fetch_row(), mysql_reconnect(), mysql_stmt_init(), mysql_store_result(), and read_one_row().
00737 { 00738 NET *net; 00739 DBUG_ENTER("set_mysql_error"); 00740 DBUG_PRINT("enter", ("error :%d '%s'", errcode, ER(errcode))); 00741 DBUG_ASSERT(mysql != 0); 00742 00743 net= &mysql->net; 00744 net->last_errno= errcode; 00745 strmov(net->last_error, ER(errcode)); 00746 strmov(net->sqlstate, sqlstate); 00747 00748 DBUG_VOID_RETURN; 00749 }
Here is the call graph for this function:

Here is the caller graph for this function:

| MYSQL_FIELD* unpack_fields | ( | MYSQL_DATA * | data, | |
| MEM_ROOT * | alloc, | |||
| uint | fields, | |||
| my_bool | default_value, | |||
| uint | server_capabilities | |||
| ) |
Definition at line 1167 of file client.c.
References alloc_root(), bzero, cli_fetch_lengths(), CLIENT_LONG_FLAG, CLIENT_PROTOCOL_41, st_mysql_rows::data, data, DBUG_ENTER, DBUG_RETURN, free_rows(), INTERNAL_NUM_FIELD, lengths, st_mysql_rows::next, NUM_FLAG, pos(), strdup_root(), uint2korr, uint3korr, and uint4korr.
Referenced by cli_list_fields(), cli_read_prepare_result(), cli_read_query_result(), and mysql_list_processes().
01169 { 01170 MYSQL_ROWS *row; 01171 MYSQL_FIELD *field,*result; 01172 ulong lengths[9]; /* Max of fields */ 01173 DBUG_ENTER("unpack_fields"); 01174 01175 field= result= (MYSQL_FIELD*) alloc_root(alloc, 01176 (uint) sizeof(*field)*fields); 01177 if (!result) 01178 { 01179 free_rows(data); /* Free old data */ 01180 DBUG_RETURN(0); 01181 } 01182 bzero((char*) field, (uint) sizeof(MYSQL_FIELD)*fields); 01183 if (server_capabilities & CLIENT_PROTOCOL_41) 01184 { 01185 /* server is 4.1, and returns the new field result format */ 01186 for (row=data->data; row ; row = row->next,field++) 01187 { 01188 uchar *pos; 01189 cli_fetch_lengths(&lengths[0], row->data, default_value ? 8 : 7); 01190 field->catalog = strdup_root(alloc,(char*) row->data[0]); 01191 field->db = strdup_root(alloc,(char*) row->data[1]); 01192 field->table = strdup_root(alloc,(char*) row->data[2]); 01193 field->org_table= strdup_root(alloc,(char*) row->data[3]); 01194 field->name = strdup_root(alloc,(char*) row->data[4]); 01195 field->org_name = strdup_root(alloc,(char*) row->data[5]); 01196 01197 field->catalog_length= lengths[0]; 01198 field->db_length= lengths[1]; 01199 field->table_length= lengths[2]; 01200 field->org_table_length= lengths[3]; 01201 field->name_length= lengths[4]; 01202 field->org_name_length= lengths[5]; 01203 01204 /* Unpack fixed length parts */ 01205 pos= (uchar*) row->data[6]; 01206 field->charsetnr= uint2korr(pos); 01207 field->length= (uint) uint4korr(pos+2); 01208 field->type= (enum enum_field_types) pos[6]; 01209 field->flags= uint2korr(pos+7); 01210 field->decimals= (uint) pos[9]; 01211 01212 if (INTERNAL_NUM_FIELD(field)) 01213 field->flags|= NUM_FLAG; 01214 if (default_value && row->data[7]) 01215 { 01216 field->def=strdup_root(alloc,(char*) row->data[7]); 01217 field->def_length= lengths[7]; 01218 } 01219 else 01220 field->def=0; 01221 field->max_length= 0; 01222 } 01223 } 01224 #ifndef DELETE_SUPPORT_OF_4_0_PROTOCOL 01225 else 01226 { 01227 /* old protocol, for backward compatibility */ 01228 for (row=data->data; row ; row = row->next,field++) 01229 { 01230 cli_fetch_lengths(&lengths[0], row->data, default_value ? 6 : 5); 01231 field->org_table= field->table= strdup_root(alloc,(char*) row->data[0]); 01232 field->name= strdup_root(alloc,(char*) row->data[1]); 01233 field->length= (uint) uint3korr(row->data[2]); 01234 field->type= (enum enum_field_types) (uchar) row->data[3][0]; 01235 01236 field->catalog=(char*) ""; 01237 field->db= (char*) ""; 01238 field->catalog_length= 0; 01239 field->db_length= 0; 01240 field->org_table_length= field->table_length= lengths[0]; 01241 field->name_length= lengths[1]; 01242 01243 if (server_capabilities & CLIENT_LONG_FLAG) 01244 { 01245 field->flags= uint2korr(row->data[4]); 01246 field->decimals=(uint) (uchar) row->data[4][2]; 01247 } 01248 else 01249 { 01250 field->flags= (uint) (uchar) row->data[4][0]; 01251 field->decimals=(uint) (uchar) row->data[4][1]; 01252 } 01253 if (INTERNAL_NUM_FIELD(field)) 01254 field->flags|= NUM_FLAG; 01255 if (default_value && row->data[5]) 01256 { 01257 field->def=strdup_root(alloc,(char*) row->data[5]); 01258 field->def_length= lengths[5]; 01259 } 01260 else 01261 field->def=0; 01262 field->max_length= 0; 01263 } 01264 } 01265 #endif /* DELETE_SUPPORT_OF_4_0_PROTOCOL */ 01266 free_rows(data); /* Free old data */ 01267 DBUG_RETURN(result); 01268 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 185 of file client.c.
References errno, NULL, SOCKOPT_OPTLEN_TYPE, start_time, and THREAD.
00186 { 00187 #ifdef HAVE_POLL 00188 struct pollfd ufds; 00189 int res; 00190 00191 ufds.fd= fd; 00192 ufds.events= POLLIN | POLLPRI; 00193 if (!(res= poll(&ufds, 1, (int) timeout*1000))) 00194 { 00195 errno= EINTR; 00196 return -1; 00197 } 00198 if (res < 0 || !(ufds.revents & (POLLIN | POLLPRI))) 00199 return -1; 00200 return 0; 00201 #else 00202 SOCKOPT_OPTLEN_TYPE s_err_size = sizeof(uint); 00203 fd_set sfds; 00204 struct timeval tv; 00205 time_t start_time, now_time; 00206 int res, s_err; 00207 00208 if (fd >= FD_SETSIZE) /* Check if wrong error */ 00209 return 0; /* Can't use timeout */ 00210 00211 /* 00212 Our connection is "in progress." We can use the select() call to wait 00213 up to a specified period of time for the connection to suceed. 00214 If select() returns 0 (after waiting howevermany seconds), our socket 00215 never became writable (host is probably unreachable.) Otherwise, if 00216 select() returns 1, then one of two conditions exist: 00217 00218 1. An error occured. We use getsockopt() to check for this. 00219 2. The connection was set up sucessfully: getsockopt() will 00220 return 0 as an error. 00221 00222 Thanks goes to Andrew Gierth <andrew@erlenstar.demon.co.uk> 00223 who posted this method of timing out a connect() in 00224 comp.unix.programmer on August 15th, 1997. 00225 */ 00226 00227 FD_ZERO(&sfds); 00228 FD_SET(fd, &sfds); 00229 /* 00230 select could be interrupted by a signal, and if it is, 00231 the timeout should be adjusted and the select restarted 00232 to work around OSes that don't restart select and 00233 implementations of select that don't adjust tv upon 00234 failure to reflect the time remaining 00235 */ 00236 start_time = time(NULL); 00237 for (;;) 00238 { 00239 tv.tv_sec = (long) timeout; 00240 tv.tv_usec = 0; 00241 #if defined(HPUX10) && defined(THREAD) 00242 if ((res = select(fd+1, NULL, (int*) &sfds, NULL, &tv)) > 0) 00243 break; 00244 #else 00245 if ((res = select(fd+1, NULL, &sfds, NULL, &tv)) > 0) 00246 break; 00247 #endif 00248 if (res == 0) /* timeout */ 00249 return -1; 00250 now_time=time(NULL); 00251 timeout-= (uint) (now_time - start_time); 00252 if (errno != EINTR || (int) timeout <= 0) 00253 return -1; 00254 } 00255 00256 /* 00257 select() returned something more interesting than zero, let's 00258 see if we have any errors. If the next two statements pass, 00259 we've got an open socket! 00260 */ 00261 00262 s_err=0; 00263 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (char*) &s_err, &s_err_size) != 0) 00264 return(-1); 00265 00266 if (s_err) 00267 { /* getsockopt could succeed */ 00268 errno = s_err; 00269 return(-1); /* but return an error... */ 00270 } 00271 return (0); /* ok */ 00272 #endif /* HAVE_POLL */ 00273 }
MYSQL_METHODS client_methods [static] |
Initial value:
{
cli_read_query_result,
cli_advanced_command,
cli_read_rows,
cli_use_result,
cli_fetch_lengths,
cli_flush_use_result
,cli_list_fields,
cli_read_prepare_result,
cli_stmt_execute,
cli_read_binary_rows,
cli_unbuffered_fetch,
NULL,
cli_read_statistics,
cli_read_query_result,
cli_read_change_user_result,
cli_read_binary_rows
}
const char* default_options[] [static] |
Initial value:
{
"port","socket","compress","password","pipe", "timeout", "user",
"init-command", "host", "database", "debug", "return-found-rows",
"ssl-key" ,"ssl-cert" ,"ssl-ca" ,"ssl-capath",
"character-sets-dir", "default-character-set", "interactive-timeout",
"connect-timeout", "local-infile", "disable-local-infile",
"replication-probe", "enable-reads-from-master", "repl-parse-query",
"ssl-cipher", "max-allowed-packet", "protocol", "shared-memory-base-name",
"multi-results", "multi-statements", "multi-queries", "secure-auth",
"report-data-truncation",
NullS
}
| uint mysql_port = 0 |
| char* mysql_unix_port = 0 |
| const char* not_error_sqlstate = "00000" |
Definition at line 115 of file client.c.
Referenced by cli_advanced_command(), mysql_init(), mysql_next_result(), mysql_stmt_init(), net_clear_error(), and stmt_clear_error().
TYPELIB option_types [static] |
Initial value:
{array_elements(default_options)-1,
"options",default_options, NULL}
| const char* sql_protocol_names_lib[] |
Initial value:
Definition at line 917 of file client.c.
Referenced by get_one_option(), and mysql_read_default_options().
| const char* unknown_sqlstate = "HY000" |
Definition at line 114 of file client.c.
Referenced by cli_advanced_command(), CLI_MYSQL_REAL_CONNECT(), cli_read_binary_rows(), cli_read_change_user_result(), cli_read_rows(), cli_read_statistics(), cli_safe_read(), cli_stmt_execute(), cli_use_result(), handle_local_infile(), mysql_fetch_row(), mysql_init_character_set(), mysql_next_result(), mysql_reconnect(), mysql_set_character_set(), mysql_stmt_attr_set(), mysql_stmt_bind_param(), mysql_stmt_bind_result(), mysql_stmt_execute(), mysql_stmt_fetch_column(), mysql_stmt_init(), mysql_stmt_prepare(), mysql_stmt_reset(), mysql_stmt_result_metadata(), mysql_stmt_send_long_data(), mysql_stmt_store_result(), mysql_store_result(), read_one_row(), stmt_read_row_no_result_set(), stmt_read_row_unbuffered(), and store_param().
1.4.7

