~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/libdrizzle.c

  • Committer: Brian Aker
  • Date: 2008-07-31 19:57:34 UTC
  • mfrom: (236.1.27 codestyle)
  • Revision ID: brian@tangent.org-20080731195734-c7cu4gx70xgjr68o
Merge from Monty.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <drizzled/global.h>
21
21
#include <mysys/my_sys.h>
22
22
#include "my_time.h"
23
 
#include <mysys_err.h>
 
23
#include <mysys/mysys_err.h>
24
24
#include <mystrings/m_string.h>
25
25
#include <mystrings/m_ctype.h>
26
26
#include "drizzle.h"
27
 
#include "drizzled_error.h"
28
27
#include "errmsg.h"
29
 
#include <violite.h>
 
28
#include <vio/violite.h>
30
29
#include <sys/stat.h>
31
30
#include <signal.h>
32
31
#include <time.h>
51
50
#ifdef HAVE_SYS_UN_H
52
51
#include <sys/un.h>
53
52
#endif
54
 
#include <my_pthread.h>        /* because of signal()  */
 
53
#include <mysys/my_pthread.h>        /* because of signal()  */
55
54
#ifndef INADDR_NONE
56
55
#define INADDR_NONE  -1
57
56
#endif
81
80
static DRIZZLE_PARAMETERS drizzle_internal_parameters=
82
81
{&max_allowed_packet, &net_buffer_length, 0};
83
82
 
84
 
DRIZZLE_PARAMETERS *STDCALL drizzle_get_parameters(void)
 
83
const DRIZZLE_PARAMETERS *STDCALL drizzle_get_parameters(void)
85
84
{
86
85
  return &drizzle_internal_parameters;
87
86
}
136
135
 
137
136
 
138
137
/**************************************************************************
139
 
  Connect to sql server
140
 
  If host == 0 then use localhost
141
 
**************************************************************************/
142
 
 
143
 
#ifdef USE_OLD_FUNCTIONS
144
 
DRIZZLE * STDCALL
145
 
drizzle_connect(DRIZZLE *drizzle,const char *host,
146
 
        const char *user, const char *passwd)
147
 
{
148
 
  DRIZZLE *res;
149
 
  drizzle=drizzle_init(drizzle);      /* Make it thread safe */
150
 
  {
151
 
    if (!(res=drizzle_connect(drizzle,host,user,passwd,NullS,0,NullS,0)))
152
 
    {
153
 
      if (drizzle->free_me && drizzle)
154
 
        free((uchar*) drizzle);
155
 
    }
156
 
    drizzle->reconnect= 1;
157
 
    return(res);
158
 
  }
159
 
}
160
 
#endif
161
 
 
162
 
 
163
 
/**************************************************************************
164
138
  Change user and database
165
139
**************************************************************************/
166
140
 
167
 
int cli_read_change_user_result(DRIZZLE *drizzle, char *buff, const char *passwd)
 
141
int cli_read_change_user_result(DRIZZLE *drizzle)
168
142
{
169
 
  (void)buff;
170
 
  (void)passwd;
171
143
  ulong pkt_length;
172
144
 
173
145
  pkt_length= cli_safe_read(drizzle);
229
201
  /* Write authentication package */
230
202
  (void)simple_command(drizzle,COM_CHANGE_USER, (uchar*) buff, (ulong) (end-buff), 1);
231
203
 
232
 
  rc= (*drizzle->methods->read_change_user_result)(drizzle, buff, passwd);
 
204
  rc= (*drizzle->methods->read_change_user_result)(drizzle);
233
205
 
234
206
  if (rc == 0)
235
207
  {
254
226
  return(rc);
255
227
}
256
228
 
257
 
#if defined(HAVE_GETPWUID) && defined(NO_GETPWUID_DECL)
258
 
struct passwd *getpwuid(uid_t);
259
 
char* getlogin(void);
260
 
#endif
261
 
 
262
 
void read_user_name(char *name)
263
 
{
264
 
  if (geteuid() == 0)
265
 
    (void) strmov(name,"root");    /* allow use of surun */
266
 
  else
267
 
  {
268
 
#ifdef HAVE_GETPWUID
269
 
    struct passwd *skr;
270
 
    const char *str;
271
 
    if ((str=getlogin()) == NULL)
272
 
    {
273
 
      if ((skr=getpwuid(geteuid())) != NULL)
274
 
  str=skr->pw_name;
275
 
      else if (!(str=getenv("USER")) && !(str=getenv("LOGNAME")) &&
276
 
         !(str=getenv("LOGIN")))
277
 
  str="UNKNOWN_USER";
278
 
    }
279
 
    (void) strmake(name,str,USERNAME_LENGTH);
280
 
#elif HAVE_CUSERID
281
 
    (void) cuserid(name);
282
 
#else
283
 
    strmov(name,"UNKNOWN_USER");
284
 
#endif
285
 
  }
286
 
  return;
287
 
}
288
229
 
289
230
bool handle_local_infile(DRIZZLE *drizzle, const char *net_filename)
290
231
{
701
642
}
702
643
 
703
644
 
704
 
#ifdef USE_OLD_FUNCTIONS
705
 
int  STDCALL
706
 
drizzle_create_db(DRIZZLE *drizzle, const char *db)
707
 
{
708
 
  return(simple_command(drizzle,COM_CREATE_DB,db, (ulong) strlen(db),0));
709
 
}
710
 
 
711
 
 
712
 
int  STDCALL
713
 
drizzle_drop_db(DRIZZLE *drizzle, const char *db)
714
 
{
715
 
  return(simple_command(drizzle,COM_DROP_DB,db,(ulong) strlen(db),0));
716
 
}
717
 
#endif
718
 
 
719
 
 
720
645
int STDCALL
721
646
drizzle_shutdown(DRIZZLE *drizzle, enum drizzle_enum_shutdown_level shutdown_level)
722
647
{
786
711
 
787
712
 
788
713
const char * STDCALL
789
 
drizzle_get_server_info(DRIZZLE *drizzle)
 
714
drizzle_get_server_info(const DRIZZLE *drizzle)
790
715
{
791
716
  return((char*) drizzle->server_version);
792
717
}
793
718
 
794
719
 
795
720
const char * STDCALL
796
 
drizzle_get_host_info(DRIZZLE *drizzle)
 
721
drizzle_get_host_info(const DRIZZLE *drizzle)
797
722
{
798
723
  return(drizzle->host_info);
799
724
}
800
725
 
801
726
 
802
727
uint STDCALL
803
 
drizzle_get_proto_info(DRIZZLE *drizzle)
 
728
drizzle_get_proto_info(const DRIZZLE *drizzle)
804
729
{
805
730
  return (drizzle->protocol_version);
806
731
}
816
741
  return MYSQL_VERSION_ID;
817
742
}
818
743
 
819
 
bool STDCALL drizzle_eof(DRIZZLE_RES *res)
 
744
bool STDCALL drizzle_eof(const DRIZZLE_RES *res)
820
745
{
821
746
  return res->eof;
822
747
}
823
748
 
824
 
DRIZZLE_FIELD * STDCALL drizzle_fetch_field_direct(DRIZZLE_RES *res,uint fieldnr)
 
749
const DRIZZLE_FIELD * STDCALL drizzle_fetch_field_direct(const DRIZZLE_RES *res, unsigned int fieldnr)
825
750
{
826
751
  return &(res)->fields[fieldnr];
827
752
}
828
753
 
829
 
DRIZZLE_FIELD * STDCALL drizzle_fetch_fields(DRIZZLE_RES *res)
 
754
const DRIZZLE_FIELD * STDCALL drizzle_fetch_fields(const DRIZZLE_RES *res)
830
755
{
831
 
  return (res)->fields;
 
756
  return res->fields;
832
757
}
833
758
 
834
 
DRIZZLE_ROW_OFFSET STDCALL DRIZZLE_ROW_tell(DRIZZLE_RES *res)
 
759
DRIZZLE_ROW_OFFSET STDCALL drizzle_row_tell(const DRIZZLE_RES *res)
835
760
{
836
761
  return res->data_cursor;
837
762
}
838
763
 
839
 
DRIZZLE_FIELD_OFFSET STDCALL drizzle_field_tell(DRIZZLE_RES *res)
 
764
DRIZZLE_FIELD_OFFSET STDCALL drizzle_field_tell(const DRIZZLE_RES *res)
840
765
{
841
 
  return (res)->current_field;
 
766
  return res->current_field;
842
767
}
843
768
 
844
769
/* DRIZZLE */
845
770
 
846
 
unsigned int STDCALL drizzle_field_count(DRIZZLE *drizzle)
 
771
unsigned int STDCALL drizzle_field_count(const DRIZZLE *drizzle)
847
772
{
848
773
  return drizzle->field_count;
849
774
}
850
775
 
851
 
uint64_t STDCALL drizzle_affected_rows(DRIZZLE *drizzle)
 
776
uint64_t STDCALL drizzle_affected_rows(const DRIZZLE *drizzle)
852
777
{
853
778
  return drizzle->affected_rows;
854
779
}
855
780
 
856
 
uint64_t STDCALL drizzle_insert_id(DRIZZLE *drizzle)
 
781
uint64_t STDCALL drizzle_insert_id(const DRIZZLE *drizzle)
857
782
{
858
783
  return drizzle->insert_id;
859
784
}
860
785
 
861
 
const char *STDCALL drizzle_sqlstate(DRIZZLE *drizzle)
 
786
const char *STDCALL drizzle_sqlstate(const DRIZZLE *drizzle)
862
787
{
863
788
  return drizzle ? drizzle->net.sqlstate : cant_connect_sqlstate;
864
789
}
865
790
 
866
 
uint32_t STDCALL drizzle_warning_count(DRIZZLE *drizzle)
 
791
uint32_t STDCALL drizzle_warning_count(const DRIZZLE *drizzle)
867
792
{
868
793
  return drizzle->warning_count;
869
794
}
870
795
 
871
 
const char *STDCALL drizzle_info(DRIZZLE *drizzle)
 
796
const char *STDCALL drizzle_info(const DRIZZLE *drizzle)
872
797
{
873
798
  return drizzle->info;
874
799
}
875
800
 
876
 
uint32_t STDCALL drizzle_thread_id(DRIZZLE *drizzle)
 
801
uint32_t STDCALL drizzle_thread_id(const DRIZZLE *drizzle)
877
802
{
878
 
  return (drizzle)->thread_id;
 
803
  return drizzle->thread_id;
879
804
}
880
805
 
881
 
const char * STDCALL drizzle_character_set_name(DRIZZLE *drizzle)
 
806
const char * STDCALL drizzle_character_set_name(const DRIZZLE *drizzle)
882
807
{
883
808
  return drizzle->charset->csname;
884
809
}
885
810
 
886
 
void STDCALL drizzle_get_character_set_info(DRIZZLE *drizzle, MY_CHARSET_INFO *csinfo)
 
811
void STDCALL drizzle_get_character_set_info(const DRIZZLE *drizzle, MY_CHARSET_INFO *csinfo)
887
812
{
888
813
  csinfo->number   = drizzle->charset->number;
889
814
  csinfo->state    = drizzle->charset->state;
975
900
uint32_t STDCALL
976
901
drizzle_escape_string(char *to,const char *from, uint32_t length)
977
902
{
978
 
  return escape_string_for_mysql(default_charset_info, to, 0, from, length);
 
903
  return escape_string_for_drizzle(default_charset_info, to, 0, from, length);
979
904
}
980
905
 
981
906
uint32_t STDCALL
983
908
       uint32_t length)
984
909
{
985
910
  if (drizzle->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
986
 
    return escape_quotes_for_mysql(drizzle->charset, to, 0, from, length);
987
 
  return escape_string_for_mysql(drizzle->charset, to, 0, from, length);
 
911
    return escape_quotes_for_drizzle(drizzle->charset, to, 0, from, length);
 
912
  return escape_string_for_drizzle(drizzle->charset, to, 0, from, length);
988
913
}
989
914
 
990
915
void STDCALL
991
 
myodbc_remove_escape(DRIZZLE *drizzle,char *name)
 
916
myodbc_remove_escape(const DRIZZLE *drizzle, char *name)
992
917
{
993
918
  char *to;
994
919
#ifdef USE_MB
995
 
  bool use_mb_flag=use_mb(drizzle->charset);
 
920
  bool use_mb_flag= use_mb(drizzle->charset);
996
921
  char *end=NULL;
997
922
  if (use_mb_flag)
998
923
    for (end=name; *end ; end++) ;
1005
930
    if (use_mb_flag && (l = my_ismbchar( drizzle->charset, name , end ) ) )
1006
931
    {
1007
932
      while (l--)
1008
 
  *to++ = *name++;
 
933
        *to++ = *name++;
1009
934
      name--;
1010
935
      continue;
1011
936
    }
1022
947
  if (packet_error == cli_safe_read(drizzle))
1023
948
    return 1;
1024
949
 
1025
 
  *row= ((drizzle->net.read_pos[0] == 254) ? NULL :
 
950
  *row= ((drizzle->net.read_pos[0] == DRIZZLE_PROTOCOL_NO_MORE_DATA) ? NULL :
1026
951
   (char*) (drizzle->net.read_pos+1));
1027
952
  return 0;
1028
953
}
1071
996
  to be read using drizzle_next_result()
1072
997
*/
1073
998
 
1074
 
bool STDCALL drizzle_more_results(DRIZZLE *drizzle)
 
999
bool STDCALL drizzle_more_results(const DRIZZLE *drizzle)
1075
1000
{
1076
 
  bool res;
1077
 
 
1078
 
  res= ((drizzle->server_status & SERVER_MORE_RESULTS_EXISTS) ? 1: 0);
1079
 
  return(res);
 
1001
  return (drizzle->server_status & SERVER_MORE_RESULTS_EXISTS) ? true:false;
1080
1002
}
1081
1003
 
1082
1004