79
79
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=
82
static DRIZZLE_PARAMETERS drizzle_internal_parameters=
199
83
{&max_allowed_packet, &net_buffer_length, 0};
201
MYSQL_PARAMETERS *STDCALL mysql_get_parameters(void)
85
DRIZZLE_PARAMETERS *STDCALL drizzle_get_parameters(void)
203
return &mysql_internal_parameters;
87
return &drizzle_internal_parameters;
206
my_bool STDCALL mysql_thread_init()
90
my_bool STDCALL drizzle_thread_init()
208
92
return my_thread_init();
211
void STDCALL mysql_thread_end()
95
void STDCALL drizzle_thread_end()
792
676
/* List all running processes (threads) in server */
795
mysql_list_processes(MYSQL *mysql)
678
DRIZZLE_RES * STDCALL
679
drizzle_list_processes(DRIZZLE *drizzle)
681
DRIZZLE_DATA *fields;
798
682
uint field_count;
801
if (simple_command(mysql,COM_PROCESS_INFO,0,0,0))
685
if (simple_command(drizzle,COM_PROCESS_INFO,0,0,0))
803
free_old_query(mysql);
804
pos=(uchar*) mysql->net.read_pos;
687
free_old_query(drizzle);
688
pos=(uchar*) drizzle->net.read_pos;
805
689
field_count=(uint) net_field_length(&pos);
806
if (!(fields = (*mysql->methods->read_rows)(mysql,(MYSQL_FIELD*) 0,
807
protocol_41(mysql) ? 7 : 5)))
690
if (!(fields = (*drizzle->methods->read_rows)(drizzle,(DRIZZLE_FIELD*) 0,
691
protocol_41(drizzle) ? 7 : 5)))
809
if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc,field_count,0,
810
mysql->server_capabilities)))
693
if (!(drizzle->fields=unpack_fields(fields,&drizzle->field_alloc,field_count,0,
694
drizzle->server_capabilities)))
812
mysql->status=MYSQL_STATUS_GET_RESULT;
813
mysql->field_count=field_count;
814
return(mysql_store_result(mysql));
696
drizzle->status=DRIZZLE_STATUS_GET_RESULT;
697
drizzle->field_count=field_count;
698
return(drizzle_store_result(drizzle));
818
702
#ifdef USE_OLD_FUNCTIONS
820
mysql_create_db(MYSQL *mysql, const char *db)
704
drizzle_create_db(DRIZZLE *drizzle, const char *db)
822
return(simple_command(mysql,COM_CREATE_DB,db, (ulong) strlen(db),0));
706
return(simple_command(drizzle,COM_CREATE_DB,db, (ulong) strlen(db),0));
827
mysql_drop_db(MYSQL *mysql, const char *db)
711
drizzle_drop_db(DRIZZLE *drizzle, const char *db)
829
return(simple_command(mysql,COM_DROP_DB,db,(ulong) strlen(db),0));
713
return(simple_command(drizzle,COM_DROP_DB,db,(ulong) strlen(db),0));
835
mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level)
719
drizzle_shutdown(DRIZZLE *drizzle, enum drizzle_enum_shutdown_level shutdown_level)
838
722
level[0]= (uchar) shutdown_level;
839
return(simple_command(mysql, COM_SHUTDOWN, level, 1, 0));
723
return(simple_command(drizzle, COM_SHUTDOWN, level, 1, 0));
844
mysql_refresh(MYSQL *mysql,uint options)
728
drizzle_refresh(DRIZZLE *drizzle,uint options)
847
731
bits[0]= (uchar) options;
848
return(simple_command(mysql, COM_REFRESH, bits, 1, 0));
732
return(simple_command(drizzle, COM_REFRESH, bits, 1, 0));
853
mysql_kill(MYSQL *mysql, uint32_t pid)
737
drizzle_kill(DRIZZLE *drizzle, uint32_t pid)
856
740
int4store(buff,pid);
857
return(simple_command(mysql,COM_PROCESS_KILL,buff,sizeof(buff),0));
741
return(simple_command(drizzle,COM_PROCESS_KILL,buff,sizeof(buff),0));
862
mysql_set_server_option(MYSQL *mysql, enum enum_mysql_set_option option)
746
drizzle_set_server_option(DRIZZLE *drizzle, enum enum_drizzle_set_option option)
865
749
int2store(buff, (uint) option);
866
return(simple_command(mysql, COM_SET_OPTION, buff, sizeof(buff), 0));
750
return(simple_command(drizzle, COM_SET_OPTION, buff, sizeof(buff), 0));
870
const char *cli_read_statistics(MYSQL *mysql)
754
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])
756
drizzle->net.read_pos[drizzle->packet_length]=0; /* End of stat string */
757
if (!drizzle->net.read_pos[0])
875
set_mysql_error(mysql, CR_WRONG_HOST_INFO, unknown_sqlstate);
876
return mysql->net.last_error;
759
set_drizzle_error(drizzle, CR_WRONG_HOST_INFO, unknown_sqlstate);
760
return drizzle->net.last_error;
878
return (char*) mysql->net.read_pos;
762
return (char*) drizzle->net.read_pos;
882
766
const char * STDCALL
883
mysql_stat(MYSQL *mysql)
767
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));
769
if (simple_command(drizzle,COM_STATISTICS,0,0,0))
770
return(drizzle->net.last_error);
771
return((*drizzle->methods->read_statistics)(drizzle));
892
mysql_ping(MYSQL *mysql)
776
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);
779
res= simple_command(drizzle,COM_PING,0,0,0);
780
if (res == CR_SERVER_LOST && drizzle->reconnect)
781
res= simple_command(drizzle,COM_PING,0,0,0);
902
786
const char * STDCALL
903
mysql_get_server_info(MYSQL *mysql)
787
drizzle_get_server_info(DRIZZLE *drizzle)
905
return((char*) mysql->server_version);
789
return((char*) drizzle->server_version);
909
793
const char * STDCALL
910
mysql_get_host_info(MYSQL *mysql)
794
drizzle_get_host_info(DRIZZLE *drizzle)
912
return(mysql->host_info);
796
return(drizzle->host_info);
917
mysql_get_proto_info(MYSQL *mysql)
801
drizzle_get_proto_info(DRIZZLE *drizzle)
919
return (mysql->protocol_version);
803
return (drizzle->protocol_version);
922
806
const char * STDCALL
923
mysql_get_client_info(void)
807
drizzle_get_client_info(void)
925
809
return (char*) MYSQL_SERVER_VERSION;
928
uint32_t STDCALL mysql_get_client_version(void)
812
uint32_t STDCALL drizzle_get_client_version(void)
930
814
return MYSQL_VERSION_ID;
933
my_bool STDCALL mysql_eof(MYSQL_RES *res)
817
my_bool STDCALL drizzle_eof(DRIZZLE_RES *res)
938
MYSQL_FIELD * STDCALL mysql_fetch_field_direct(MYSQL_RES *res,uint fieldnr)
822
DRIZZLE_FIELD * STDCALL drizzle_fetch_field_direct(DRIZZLE_RES *res,uint fieldnr)
940
824
return &(res)->fields[fieldnr];
943
MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res)
827
DRIZZLE_FIELD * STDCALL drizzle_fetch_fields(DRIZZLE_RES *res)
945
829
return (res)->fields;
948
MYSQL_ROW_OFFSET STDCALL mysql_row_tell(MYSQL_RES *res)
832
DRIZZLE_ROW_OFFSET STDCALL DRIZZLE_ROW_tell(DRIZZLE_RES *res)
950
834
return res->data_cursor;
953
MYSQL_FIELD_OFFSET STDCALL mysql_field_tell(MYSQL_RES *res)
837
DRIZZLE_FIELD_OFFSET STDCALL drizzle_field_tell(DRIZZLE_RES *res)
955
839
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;
844
unsigned int STDCALL drizzle_field_count(DRIZZLE *drizzle)
846
return drizzle->field_count;
849
uint64_t STDCALL drizzle_affected_rows(DRIZZLE *drizzle)
851
return drizzle->affected_rows;
854
uint64_t STDCALL drizzle_insert_id(DRIZZLE *drizzle)
856
return drizzle->insert_id;
859
const char *STDCALL drizzle_sqlstate(DRIZZLE *drizzle)
861
return drizzle ? drizzle->net.sqlstate : cant_connect_sqlstate;
864
uint32_t STDCALL drizzle_warning_count(DRIZZLE *drizzle)
866
return drizzle->warning_count;
869
const char *STDCALL drizzle_info(DRIZZLE *drizzle)
871
return drizzle->info;
874
uint32_t STDCALL drizzle_thread_id(DRIZZLE *drizzle)
876
return (drizzle)->thread_id;
879
const char * STDCALL drizzle_character_set_name(DRIZZLE *drizzle)
881
return drizzle->charset->csname;
884
void STDCALL drizzle_get_character_set_info(DRIZZLE *drizzle, MY_CHARSET_INFO *csinfo)
886
csinfo->number = drizzle->charset->number;
887
csinfo->state = drizzle->charset->state;
888
csinfo->csname = drizzle->charset->csname;
889
csinfo->name = drizzle->charset->name;
890
csinfo->comment = drizzle->charset->comment;
891
csinfo->mbminlen = drizzle->charset->mbminlen;
892
csinfo->mbmaxlen = drizzle->charset->mbmaxlen;
894
if (drizzle->options.charset_dir)
895
csinfo->dir = drizzle->options.charset_dir;
1013
897
csinfo->dir = charsets_dir;
1016
uint STDCALL mysql_thread_safe(void)
900
uint STDCALL drizzle_thread_safe(void)
1022
my_bool STDCALL mysql_embedded(void)
906
my_bool STDCALL drizzle_embedded(void)
1024
908
#ifdef EMBEDDED_LIBRARY