79
78
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=
81
static DRIZZLE_PARAMETERS drizzle_internal_parameters=
199
82
{&max_allowed_packet, &net_buffer_length, 0};
201
MYSQL_PARAMETERS *STDCALL mysql_get_parameters(void)
84
DRIZZLE_PARAMETERS *STDCALL drizzle_get_parameters(void)
203
return &mysql_internal_parameters;
86
return &drizzle_internal_parameters;
206
my_bool STDCALL mysql_thread_init()
89
bool STDCALL drizzle_thread_init()
208
91
return my_thread_init();
211
void STDCALL mysql_thread_end()
94
void STDCALL drizzle_thread_end()
792
678
/* List all running processes (threads) in server */
795
mysql_list_processes(MYSQL *mysql)
680
DRIZZLE_RES * STDCALL
681
drizzle_list_processes(DRIZZLE *drizzle)
683
DRIZZLE_DATA *fields;
798
684
uint field_count;
801
if (simple_command(mysql,COM_PROCESS_INFO,0,0,0))
687
if (simple_command(drizzle,COM_PROCESS_INFO,0,0,0))
803
free_old_query(mysql);
804
pos=(uchar*) mysql->net.read_pos;
689
free_old_query(drizzle);
690
pos=(uchar*) drizzle->net.read_pos;
805
691
field_count=(uint) net_field_length(&pos);
806
if (!(fields = (*mysql->methods->read_rows)(mysql,(MYSQL_FIELD*) 0,
807
protocol_41(mysql) ? 7 : 5)))
692
if (!(fields = (*drizzle->methods->read_rows)(drizzle,(DRIZZLE_FIELD*) 0,
693
protocol_41(drizzle) ? 7 : 5)))
809
if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc,field_count,0,
810
mysql->server_capabilities)))
695
if (!(drizzle->fields=unpack_fields(fields,&drizzle->field_alloc,field_count,0,
696
drizzle->server_capabilities)))
812
mysql->status=MYSQL_STATUS_GET_RESULT;
813
mysql->field_count=field_count;
814
return(mysql_store_result(mysql));
698
drizzle->status=DRIZZLE_STATUS_GET_RESULT;
699
drizzle->field_count=field_count;
700
return(drizzle_store_result(drizzle));
818
704
#ifdef USE_OLD_FUNCTIONS
820
mysql_create_db(MYSQL *mysql, const char *db)
706
drizzle_create_db(DRIZZLE *drizzle, const char *db)
822
return(simple_command(mysql,COM_CREATE_DB,db, (ulong) strlen(db),0));
708
return(simple_command(drizzle,COM_CREATE_DB,db, (ulong) strlen(db),0));
827
mysql_drop_db(MYSQL *mysql, const char *db)
713
drizzle_drop_db(DRIZZLE *drizzle, const char *db)
829
return(simple_command(mysql,COM_DROP_DB,db,(ulong) strlen(db),0));
715
return(simple_command(drizzle,COM_DROP_DB,db,(ulong) strlen(db),0));
835
mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level)
721
drizzle_shutdown(DRIZZLE *drizzle, enum drizzle_enum_shutdown_level shutdown_level)
838
724
level[0]= (uchar) shutdown_level;
839
return(simple_command(mysql, COM_SHUTDOWN, level, 1, 0));
725
return(simple_command(drizzle, COM_SHUTDOWN, level, 1, 0));
844
mysql_refresh(MYSQL *mysql,uint options)
730
drizzle_refresh(DRIZZLE *drizzle,uint options)
847
733
bits[0]= (uchar) options;
848
return(simple_command(mysql, COM_REFRESH, bits, 1, 0));
734
return(simple_command(drizzle, COM_REFRESH, bits, 1, 0));
853
mysql_kill(MYSQL *mysql, uint32_t pid)
739
drizzle_kill(DRIZZLE *drizzle, uint32_t pid)
856
742
int4store(buff,pid);
857
return(simple_command(mysql,COM_PROCESS_KILL,buff,sizeof(buff),0));
743
return(simple_command(drizzle,COM_PROCESS_KILL,buff,sizeof(buff),0));
862
mysql_set_server_option(MYSQL *mysql, enum enum_mysql_set_option option)
748
drizzle_set_server_option(DRIZZLE *drizzle, enum enum_drizzle_set_option option)
865
751
int2store(buff, (uint) option);
866
return(simple_command(mysql, COM_SET_OPTION, buff, sizeof(buff), 0));
752
return(simple_command(drizzle, COM_SET_OPTION, buff, sizeof(buff), 0));
870
const char *cli_read_statistics(MYSQL *mysql)
756
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])
758
drizzle->net.read_pos[drizzle->packet_length]=0; /* End of stat string */
759
if (!drizzle->net.read_pos[0])
875
set_mysql_error(mysql, CR_WRONG_HOST_INFO, unknown_sqlstate);
876
return mysql->net.last_error;
761
set_drizzle_error(drizzle, CR_WRONG_HOST_INFO, unknown_sqlstate);
762
return drizzle->net.last_error;
878
return (char*) mysql->net.read_pos;
764
return (char*) drizzle->net.read_pos;
882
768
const char * STDCALL
883
mysql_stat(MYSQL *mysql)
769
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));
771
if (simple_command(drizzle,COM_STATISTICS,0,0,0))
772
return(drizzle->net.last_error);
773
return((*drizzle->methods->read_statistics)(drizzle));
892
mysql_ping(MYSQL *mysql)
778
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);
781
res= simple_command(drizzle,COM_PING,0,0,0);
782
if (res == CR_SERVER_LOST && drizzle->reconnect)
783
res= simple_command(drizzle,COM_PING,0,0,0);
902
788
const char * STDCALL
903
mysql_get_server_info(MYSQL *mysql)
789
drizzle_get_server_info(DRIZZLE *drizzle)
905
return((char*) mysql->server_version);
791
return((char*) drizzle->server_version);
909
795
const char * STDCALL
910
mysql_get_host_info(MYSQL *mysql)
796
drizzle_get_host_info(DRIZZLE *drizzle)
912
return(mysql->host_info);
798
return(drizzle->host_info);
917
mysql_get_proto_info(MYSQL *mysql)
803
drizzle_get_proto_info(DRIZZLE *drizzle)
919
return (mysql->protocol_version);
805
return (drizzle->protocol_version);
922
808
const char * STDCALL
923
mysql_get_client_info(void)
809
drizzle_get_client_info(void)
925
811
return (char*) MYSQL_SERVER_VERSION;
928
uint32_t STDCALL mysql_get_client_version(void)
814
uint32_t STDCALL drizzle_get_client_version(void)
930
816
return MYSQL_VERSION_ID;
933
my_bool STDCALL mysql_eof(MYSQL_RES *res)
819
bool STDCALL drizzle_eof(DRIZZLE_RES *res)
938
MYSQL_FIELD * STDCALL mysql_fetch_field_direct(MYSQL_RES *res,uint fieldnr)
824
DRIZZLE_FIELD * STDCALL drizzle_fetch_field_direct(DRIZZLE_RES *res,uint fieldnr)
940
826
return &(res)->fields[fieldnr];
943
MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res)
829
DRIZZLE_FIELD * STDCALL drizzle_fetch_fields(DRIZZLE_RES *res)
945
831
return (res)->fields;
948
MYSQL_ROW_OFFSET STDCALL mysql_row_tell(MYSQL_RES *res)
834
DRIZZLE_ROW_OFFSET STDCALL DRIZZLE_ROW_tell(DRIZZLE_RES *res)
950
836
return res->data_cursor;
953
MYSQL_FIELD_OFFSET STDCALL mysql_field_tell(MYSQL_RES *res)
839
DRIZZLE_FIELD_OFFSET STDCALL drizzle_field_tell(DRIZZLE_RES *res)
955
841
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;
846
unsigned int STDCALL drizzle_field_count(DRIZZLE *drizzle)
848
return drizzle->field_count;
851
uint64_t STDCALL drizzle_affected_rows(DRIZZLE *drizzle)
853
return drizzle->affected_rows;
856
uint64_t STDCALL drizzle_insert_id(DRIZZLE *drizzle)
858
return drizzle->insert_id;
861
const char *STDCALL drizzle_sqlstate(DRIZZLE *drizzle)
863
return drizzle ? drizzle->net.sqlstate : cant_connect_sqlstate;
866
uint32_t STDCALL drizzle_warning_count(DRIZZLE *drizzle)
868
return drizzle->warning_count;
871
const char *STDCALL drizzle_info(DRIZZLE *drizzle)
873
return drizzle->info;
876
uint32_t STDCALL drizzle_thread_id(DRIZZLE *drizzle)
878
return (drizzle)->thread_id;
881
const char * STDCALL drizzle_character_set_name(DRIZZLE *drizzle)
883
return drizzle->charset->csname;
886
void STDCALL drizzle_get_character_set_info(DRIZZLE *drizzle, MY_CHARSET_INFO *csinfo)
888
csinfo->number = drizzle->charset->number;
889
csinfo->state = drizzle->charset->state;
890
csinfo->csname = drizzle->charset->csname;
891
csinfo->name = drizzle->charset->name;
892
csinfo->comment = drizzle->charset->comment;
893
csinfo->mbminlen = drizzle->charset->mbminlen;
894
csinfo->mbmaxlen = drizzle->charset->mbmaxlen;
896
if (drizzle->options.charset_dir)
897
csinfo->dir = drizzle->options.charset_dir;
1013
899
csinfo->dir = charsets_dir;
1016
uint STDCALL mysql_thread_safe(void)
902
uint STDCALL drizzle_thread_safe(void)
1022
my_bool STDCALL mysql_embedded(void)
908
bool STDCALL drizzle_embedded(void)
1024
910
#ifdef EMBEDDED_LIBRARY