79
77
static void append_wild(char *to,char *end,const char *wild);
81
static my_bool mysql_client_init= 0;
82
static my_bool org_my_init_done= 0;
86
Initialize the MySQL client library
92
Should be called before doing any other calls to the MySQL
93
client library to initialize thread specific variables etc.
94
It's called by mysql_init() to ensure that things will work for
95
old not threaded applications that doesn't call mysql_server_init()
100
1 could not initialize environment (out of memory or thread keys)
103
int STDCALL mysql_server_init(int argc __attribute__((unused)),
104
char **argv __attribute__((unused)),
105
char **groups __attribute__((unused)))
108
if (!mysql_client_init)
111
org_my_init_done=my_init_done;
112
if (my_init()) /* Will init threads */
117
mysql_port = MYSQL_PORT;
119
struct servent *serv_ptr;
123
if builder specifically requested a default port, use that
124
(even if it coincides with our factory default).
125
only if they didn't do we check /etc/services (and, failing
126
on that, fall back to the factory default of 4427).
127
either default can be overridden by the environment variable
128
MYSQL_TCP_PORT, which in turn can be overridden with command
132
#if MYSQL_PORT_DEFAULT == 0
133
if ((serv_ptr = getservbyname("mysql", "tcp")))
134
mysql_port = (uint) ntohs((ushort) serv_ptr->s_port);
136
if ((env = getenv("MYSQL_TCP_PORT")))
137
mysql_port =(uint) atoi(env);
140
if (!mysql_unix_port)
143
mysql_unix_port = (char*) MYSQL_UNIX_ADDR;
144
if ((env = getenv("MYSQL_UNIX_PORT")))
145
mysql_unix_port = env;
148
(void) signal(SIGPIPE, SIG_IGN);
152
result= (int)my_thread_init(); /* Init if new thread */
158
Free all memory and resources used by the client library
161
When calling this there should not be any other threads using
164
To make things simpler when used with windows dll's (which calls this
165
function automaticly), it's safe to call this function multiple times.
169
void STDCALL mysql_server_end()
171
if (!mysql_client_init)
174
finish_client_errs();
177
/* If library called my_init(), free memory allocated by it */
178
if (!org_my_init_done)
188
mysql_client_init= org_my_init_done= 0;
189
#ifdef EMBEDDED_SERVER
192
fclose(stderror_file);
198
static MYSQL_PARAMETERS mysql_internal_parameters=
80
static DRIZZLE_PARAMETERS drizzle_internal_parameters=
199
81
{&max_allowed_packet, &net_buffer_length, 0};
201
MYSQL_PARAMETERS *STDCALL mysql_get_parameters(void)
83
DRIZZLE_PARAMETERS *STDCALL drizzle_get_parameters(void)
203
return &mysql_internal_parameters;
85
return &drizzle_internal_parameters;
206
my_bool STDCALL mysql_thread_init()
88
bool STDCALL drizzle_thread_init()
208
90
return my_thread_init();
211
void STDCALL mysql_thread_end()
93
void STDCALL drizzle_thread_end()
792
677
/* List all running processes (threads) in server */
795
mysql_list_processes(MYSQL *mysql)
679
DRIZZLE_RES * STDCALL
680
drizzle_list_processes(DRIZZLE *drizzle)
682
DRIZZLE_DATA *fields;
798
683
uint field_count;
801
if (simple_command(mysql,COM_PROCESS_INFO,0,0,0))
686
if (simple_command(drizzle,COM_PROCESS_INFO,0,0,0))
803
free_old_query(mysql);
804
pos=(uchar*) mysql->net.read_pos;
688
free_old_query(drizzle);
689
pos=(uchar*) drizzle->net.read_pos;
805
690
field_count=(uint) net_field_length(&pos);
806
if (!(fields = (*mysql->methods->read_rows)(mysql,(MYSQL_FIELD*) 0,
807
protocol_41(mysql) ? 7 : 5)))
691
if (!(fields = (*drizzle->methods->read_rows)(drizzle,(DRIZZLE_FIELD*) 0,
692
protocol_41(drizzle) ? 7 : 5)))
809
if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc,field_count,0,
810
mysql->server_capabilities)))
694
if (!(drizzle->fields=unpack_fields(fields,&drizzle->field_alloc,field_count,0,
695
drizzle->server_capabilities)))
812
mysql->status=MYSQL_STATUS_GET_RESULT;
813
mysql->field_count=field_count;
814
return(mysql_store_result(mysql));
697
drizzle->status=DRIZZLE_STATUS_GET_RESULT;
698
drizzle->field_count=field_count;
699
return(drizzle_store_result(drizzle));
818
703
#ifdef USE_OLD_FUNCTIONS
820
mysql_create_db(MYSQL *mysql, const char *db)
705
drizzle_create_db(DRIZZLE *drizzle, const char *db)
822
return(simple_command(mysql,COM_CREATE_DB,db, (ulong) strlen(db),0));
707
return(simple_command(drizzle,COM_CREATE_DB,db, (ulong) strlen(db),0));
827
mysql_drop_db(MYSQL *mysql, const char *db)
712
drizzle_drop_db(DRIZZLE *drizzle, const char *db)
829
return(simple_command(mysql,COM_DROP_DB,db,(ulong) strlen(db),0));
714
return(simple_command(drizzle,COM_DROP_DB,db,(ulong) strlen(db),0));
835
mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level)
720
drizzle_shutdown(DRIZZLE *drizzle, enum drizzle_enum_shutdown_level shutdown_level)
838
723
level[0]= (uchar) shutdown_level;
839
return(simple_command(mysql, COM_SHUTDOWN, level, 1, 0));
724
return(simple_command(drizzle, COM_SHUTDOWN, level, 1, 0));
844
mysql_refresh(MYSQL *mysql,uint options)
729
drizzle_refresh(DRIZZLE *drizzle,uint options)
847
732
bits[0]= (uchar) options;
848
return(simple_command(mysql, COM_REFRESH, bits, 1, 0));
733
return(simple_command(drizzle, COM_REFRESH, bits, 1, 0));
853
mysql_kill(MYSQL *mysql, uint32_t pid)
738
drizzle_kill(DRIZZLE *drizzle, uint32_t pid)
856
741
int4store(buff,pid);
857
return(simple_command(mysql,COM_PROCESS_KILL,buff,sizeof(buff),0));
742
return(simple_command(drizzle,COM_PROCESS_KILL,buff,sizeof(buff),0));
862
mysql_set_server_option(MYSQL *mysql, enum enum_mysql_set_option option)
747
drizzle_set_server_option(DRIZZLE *drizzle, enum enum_drizzle_set_option option)
865
750
int2store(buff, (uint) option);
866
return(simple_command(mysql, COM_SET_OPTION, buff, sizeof(buff), 0));
751
return(simple_command(drizzle, COM_SET_OPTION, buff, sizeof(buff), 0));
870
const char *cli_read_statistics(MYSQL *mysql)
755
const char *cli_read_statistics(DRIZZLE *drizzle)
872
mysql->net.read_pos[mysql->packet_length]=0; /* End of stat string */
873
if (!mysql->net.read_pos[0])
757
drizzle->net.read_pos[drizzle->packet_length]=0; /* End of stat string */
758
if (!drizzle->net.read_pos[0])
875
set_mysql_error(mysql, CR_WRONG_HOST_INFO, unknown_sqlstate);
876
return mysql->net.last_error;
760
set_drizzle_error(drizzle, CR_WRONG_HOST_INFO, unknown_sqlstate);
761
return drizzle->net.last_error;
878
return (char*) mysql->net.read_pos;
763
return (char*) drizzle->net.read_pos;
882
767
const char * STDCALL
883
mysql_stat(MYSQL *mysql)
768
drizzle_stat(DRIZZLE *drizzle)
885
if (simple_command(mysql,COM_STATISTICS,0,0,0))
886
return(mysql->net.last_error);
887
return((*mysql->methods->read_statistics)(mysql));
770
if (simple_command(drizzle,COM_STATISTICS,0,0,0))
771
return(drizzle->net.last_error);
772
return((*drizzle->methods->read_statistics)(drizzle));
892
mysql_ping(MYSQL *mysql)
777
drizzle_ping(DRIZZLE *drizzle)
895
res= simple_command(mysql,COM_PING,0,0,0);
896
if (res == CR_SERVER_LOST && mysql->reconnect)
897
res= simple_command(mysql,COM_PING,0,0,0);
780
res= simple_command(drizzle,COM_PING,0,0,0);
781
if (res == CR_SERVER_LOST && drizzle->reconnect)
782
res= simple_command(drizzle,COM_PING,0,0,0);
902
787
const char * STDCALL
903
mysql_get_server_info(MYSQL *mysql)
788
drizzle_get_server_info(DRIZZLE *drizzle)
905
return((char*) mysql->server_version);
790
return((char*) drizzle->server_version);
909
794
const char * STDCALL
910
mysql_get_host_info(MYSQL *mysql)
795
drizzle_get_host_info(DRIZZLE *drizzle)
912
return(mysql->host_info);
797
return(drizzle->host_info);
917
mysql_get_proto_info(MYSQL *mysql)
802
drizzle_get_proto_info(DRIZZLE *drizzle)
919
return (mysql->protocol_version);
804
return (drizzle->protocol_version);
922
807
const char * STDCALL
923
mysql_get_client_info(void)
808
drizzle_get_client_info(void)
925
810
return (char*) MYSQL_SERVER_VERSION;
928
uint32_t STDCALL mysql_get_client_version(void)
813
uint32_t STDCALL drizzle_get_client_version(void)
930
815
return MYSQL_VERSION_ID;
933
my_bool STDCALL mysql_eof(MYSQL_RES *res)
818
bool STDCALL drizzle_eof(DRIZZLE_RES *res)
938
MYSQL_FIELD * STDCALL mysql_fetch_field_direct(MYSQL_RES *res,uint fieldnr)
823
DRIZZLE_FIELD * STDCALL drizzle_fetch_field_direct(DRIZZLE_RES *res,uint fieldnr)
940
825
return &(res)->fields[fieldnr];
943
MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res)
828
DRIZZLE_FIELD * STDCALL drizzle_fetch_fields(DRIZZLE_RES *res)
945
830
return (res)->fields;
948
MYSQL_ROW_OFFSET STDCALL mysql_row_tell(MYSQL_RES *res)
833
DRIZZLE_ROW_OFFSET STDCALL DRIZZLE_ROW_tell(DRIZZLE_RES *res)
950
835
return res->data_cursor;
953
MYSQL_FIELD_OFFSET STDCALL mysql_field_tell(MYSQL_RES *res)
838
DRIZZLE_FIELD_OFFSET STDCALL drizzle_field_tell(DRIZZLE_RES *res)
955
840
return (res)->current_field;
960
unsigned int STDCALL mysql_field_count(MYSQL *mysql)
962
return mysql->field_count;
965
uint64_t STDCALL mysql_affected_rows(MYSQL *mysql)
967
return mysql->affected_rows;
970
uint64_t STDCALL mysql_insert_id(MYSQL *mysql)
972
return mysql->insert_id;
975
const char *STDCALL mysql_sqlstate(MYSQL *mysql)
977
return mysql ? mysql->net.sqlstate : cant_connect_sqlstate;
980
uint32_t STDCALL mysql_warning_count(MYSQL *mysql)
982
return mysql->warning_count;
985
const char *STDCALL mysql_info(MYSQL *mysql)
990
uint32_t STDCALL mysql_thread_id(MYSQL *mysql)
992
return (mysql)->thread_id;
995
const char * STDCALL mysql_character_set_name(MYSQL *mysql)
997
return mysql->charset->csname;
1000
void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *csinfo)
1002
csinfo->number = mysql->charset->number;
1003
csinfo->state = mysql->charset->state;
1004
csinfo->csname = mysql->charset->csname;
1005
csinfo->name = mysql->charset->name;
1006
csinfo->comment = mysql->charset->comment;
1007
csinfo->mbminlen = mysql->charset->mbminlen;
1008
csinfo->mbmaxlen = mysql->charset->mbmaxlen;
1010
if (mysql->options.charset_dir)
1011
csinfo->dir = mysql->options.charset_dir;
845
unsigned int STDCALL drizzle_field_count(DRIZZLE *drizzle)
847
return drizzle->field_count;
850
uint64_t STDCALL drizzle_affected_rows(DRIZZLE *drizzle)
852
return drizzle->affected_rows;
855
uint64_t STDCALL drizzle_insert_id(DRIZZLE *drizzle)
857
return drizzle->insert_id;
860
const char *STDCALL drizzle_sqlstate(DRIZZLE *drizzle)
862
return drizzle ? drizzle->net.sqlstate : cant_connect_sqlstate;
865
uint32_t STDCALL drizzle_warning_count(DRIZZLE *drizzle)
867
return drizzle->warning_count;
870
const char *STDCALL drizzle_info(DRIZZLE *drizzle)
872
return drizzle->info;
875
uint32_t STDCALL drizzle_thread_id(DRIZZLE *drizzle)
877
return (drizzle)->thread_id;
880
const char * STDCALL drizzle_character_set_name(DRIZZLE *drizzle)
882
return drizzle->charset->csname;
885
void STDCALL drizzle_get_character_set_info(DRIZZLE *drizzle, MY_CHARSET_INFO *csinfo)
887
csinfo->number = drizzle->charset->number;
888
csinfo->state = drizzle->charset->state;
889
csinfo->csname = drizzle->charset->csname;
890
csinfo->name = drizzle->charset->name;
891
csinfo->comment = drizzle->charset->comment;
892
csinfo->mbminlen = drizzle->charset->mbminlen;
893
csinfo->mbmaxlen = drizzle->charset->mbmaxlen;
895
if (drizzle->options.charset_dir)
896
csinfo->dir = drizzle->options.charset_dir;
1013
898
csinfo->dir = charsets_dir;
1016
uint STDCALL mysql_thread_safe(void)
901
uint STDCALL drizzle_thread_safe(void)
1022
my_bool STDCALL mysql_embedded(void)
907
bool STDCALL drizzle_embedded(void)
1024
909
#ifdef EMBEDDED_LIBRARY