~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/client.c

  • Committer: Monty Taylor
  • Date: 2008-09-14 18:54:32 UTC
  • mto: This revision was merged to the branch mainline in revision 387.
  • Revision ID: monty@inaugust.com-20080914185432-n0o4tpyaubaljd7d
Removed more mysys stuff.
Removed defaults file processing from libdrizzle.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
  server.
41
41
*/
42
42
 
 
43
#include <stdarg.h>
 
44
 
43
45
#include <drizzled/global.h>
44
46
 
45
47
#include "drizzle.h"
55
57
 
56
58
#define CLI_DRIZZLE_CONNECT drizzle_connect
57
59
 
58
 
#include <mysys/my_sys.h>
59
60
#include <mystrings/m_string.h>
60
61
#include <drizzled/error.h>
61
62
#include "errmsg.h"
525
526
    free_rows(result->data);
526
527
    /* TODO: free result->fields */
527
528
    if (result->row)
528
 
      my_free((uchar*) result->row,MYF(0));
529
 
    my_free((uchar*) result,MYF(0));
530
 
  }
531
 
}
532
 
 
533
 
/****************************************************************************
534
 
  Get options from my.cnf
535
 
****************************************************************************/
536
 
 
537
 
static const char *default_options[]=
538
 
{
539
 
  "port","socket","compress","password","pipe", "timeout", "user",
540
 
  "init-command", "host", "database", "return-found-rows",
541
 
  "ssl-key" ,"ssl-cert" ,"ssl-ca" ,"ssl-capath",
542
 
  "character-sets-dir", "default-character-set", "interactive-timeout",
543
 
  "connect-timeout", "local-infile", "disable-local-infile",
544
 
  "ssl-cipher", "max-allowed-packet", "protocol", "shared-memory-base-name",
545
 
  "multi-results", "multi-statements", "multi-queries", "secure-auth",
546
 
  "report-data-truncation",
547
 
  NullS
548
 
};
549
 
 
550
 
static TYPELIB option_types={array_elements(default_options)-1,
551
 
           "options",default_options, NULL};
552
 
 
553
 
const char *sql_protocol_names_lib[] =
554
 
{ "TCP", "SOCKET", "PIPE", "MEMORY", NullS };
555
 
TYPELIB sql_protocol_typelib = {array_elements(sql_protocol_names_lib)-1,"",
556
 
        sql_protocol_names_lib, NULL};
557
 
 
558
 
static int add_init_command(struct st_drizzle_options *options, const char *cmd)
559
 
{
560
 
  char *tmp;
561
 
 
562
 
  if (!options->init_commands)
563
 
  {
564
 
    options->init_commands= (DYNAMIC_ARRAY*)my_malloc(sizeof(DYNAMIC_ARRAY),
565
 
                  MYF(MY_WME));
566
 
    init_dynamic_array(options->init_commands,sizeof(char*),0,5 CALLER_INFO);
567
 
  }
568
 
 
569
 
  if (!(tmp= my_strdup(cmd,MYF(MY_WME))) ||
570
 
      insert_dynamic(options->init_commands, (uchar*)&tmp))
571
 
  {
572
 
    my_free(tmp, MYF(MY_ALLOW_ZERO_PTR));
573
 
    return 1;
574
 
  }
575
 
 
576
 
  return 0;
577
 
}
578
 
 
579
 
void drizzle_read_default_options(struct st_drizzle_options *options,
580
 
        const char *filename,const char *group)
581
 
{
582
 
  int argc;
583
 
  char *argv_buff[1],**argv;
584
 
  const char *groups[3];
585
 
 
586
 
  argc=1; argv=argv_buff; argv_buff[0]= (char*) "client";
587
 
  groups[0]= (char*) "client"; groups[1]= (char*) group; groups[2]=0;
588
 
 
589
 
  load_defaults(filename, groups, &argc, &argv);
590
 
  if (argc != 1)        /* If some default option */
591
 
  {
592
 
    char **option=argv;
593
 
    while (*++option)
594
 
    {
595
 
      if (option[0][0] == '-' && option[0][1] == '-')
596
 
      {
597
 
        char *end=strrchr(*option,'=');
598
 
        char *opt_arg=0;
599
 
        if (end != NULL)
600
 
        {
601
 
          opt_arg=end+1;
602
 
          *end=0;        /* Remove '=' */
603
 
        }
604
 
        /* Change all '_' in variable name to '-' */
605
 
        for (end= *option ; *(end= strrchr(end,'_')) ; )
606
 
          *end= '-';
607
 
        switch (find_type(*option+2,&option_types,2)) {
608
 
        case 1:        /* port */
609
 
          if (opt_arg)
610
 
            options->port=atoi(opt_arg);
611
 
          break;
612
 
        case 2:        /* socket */
613
 
          if (opt_arg)
614
 
          {
615
 
            my_free(options->unix_socket,MYF(MY_ALLOW_ZERO_PTR));
616
 
            options->unix_socket=my_strdup(opt_arg,MYF(MY_WME));
617
 
          }
618
 
          break;
619
 
        case 3:        /* compress */
620
 
          options->compress=1;
621
 
          options->client_flag|= CLIENT_COMPRESS;
622
 
          break;
623
 
        case 4:        /* password */
624
 
          if (opt_arg)
625
 
          {
626
 
            my_free(options->password,MYF(MY_ALLOW_ZERO_PTR));
627
 
            options->password=my_strdup(opt_arg,MYF(MY_WME));
628
 
          }
629
 
          break;
630
 
        case 20:      /* connect_timeout */
631
 
        case 6:        /* timeout */
632
 
          if (opt_arg)
633
 
            options->connect_timeout=atoi(opt_arg);
634
 
          break;
635
 
        case 7:        /* user */
636
 
          if (opt_arg)
637
 
          {
638
 
            my_free(options->user,MYF(MY_ALLOW_ZERO_PTR));
639
 
            options->user=my_strdup(opt_arg,MYF(MY_WME));
640
 
          }
641
 
          break;
642
 
        case 8:        /* init-command */
643
 
          add_init_command(options,opt_arg);
644
 
          break;
645
 
        case 9:        /* host */
646
 
          if (opt_arg)
647
 
          {
648
 
            my_free(options->host,MYF(MY_ALLOW_ZERO_PTR));
649
 
            options->host=my_strdup(opt_arg,MYF(MY_WME));
650
 
          }
651
 
          break;
652
 
        case 10:      /* database */
653
 
          if (opt_arg)
654
 
          {
655
 
            my_free(options->db,MYF(MY_ALLOW_ZERO_PTR));
656
 
            options->db=my_strdup(opt_arg,MYF(MY_WME));
657
 
          }
658
 
          break;
659
 
        case 12:      /* return-found-rows */
660
 
          options->client_flag|=CLIENT_FOUND_ROWS;
661
 
          break;
662
 
        case 13:        /* Ignore SSL options */
663
 
        case 14:
664
 
        case 15:
665
 
        case 16:
666
 
        case 23:
667
 
          break;
668
 
        case 19:        /* Interactive-timeout */
669
 
          options->client_flag|= CLIENT_INTERACTIVE;
670
 
          break;
671
 
        case 21:
672
 
          if (!opt_arg || atoi(opt_arg) != 0)
673
 
            options->client_flag|= CLIENT_LOCAL_FILES;
674
 
          else
675
 
            options->client_flag&= ~CLIENT_LOCAL_FILES;
676
 
          break;
677
 
        case 22:
678
 
          options->client_flag&= ~CLIENT_LOCAL_FILES;
679
 
          break;
680
 
        case 24: /* max-allowed-packet */
681
 
          if (opt_arg)
682
 
            options->max_allowed_packet= atoi(opt_arg);
683
 
          break;
684
 
        case 25: /* protocol */
685
 
          if ((options->protocol= find_type(opt_arg,
686
 
                                            &sql_protocol_typelib,0)) <= 0)
687
 
          {
688
 
            fprintf(stderr, _("Unknown option to protocol: %s\n"), opt_arg);
689
 
            exit(1);
690
 
          }
691
 
          break;
692
 
        case 27: /* multi-results */
693
 
          options->client_flag|= CLIENT_MULTI_RESULTS;
694
 
          break;
695
 
        case 28: /* multi-statements */
696
 
        case 29: /* multi-queries */
697
 
          options->client_flag|= CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS;
698
 
          break;
699
 
        case 30: /* secure-auth */
700
 
          options->secure_auth= true;
701
 
          break;
702
 
        case 31: /* report-data-truncation */
703
 
          options->report_data_truncation= opt_arg ? test(atoi(opt_arg)) : 1;
704
 
          break;
705
 
        default:
706
 
          break;
707
 
        }
708
 
      }
709
 
    }
710
 
  }
711
 
  free_defaults(argv);
712
 
  return;
 
529
      free((uchar*) result->row);
 
530
    free((uchar*) result);
 
531
  }
713
532
}
714
533
 
715
534
 
819
638
 
820
639
  if ((pkt_len= cli_safe_read(drizzle)) == packet_error)
821
640
    return(0);
822
 
  if (!(result=(DRIZZLE_DATA*) my_malloc(sizeof(DRIZZLE_DATA),
823
 
               MYF(MY_WME | MY_ZEROFILL))))
 
641
  if (!(result=(DRIZZLE_DATA*) malloc(sizeof(DRIZZLE_DATA))))
824
642
  {
825
643
    set_drizzle_error(drizzle, CR_OUT_OF_MEMORY, unknown_sqlstate);
826
644
    return(0);
827
645
  }
 
646
  memset(result, 0, sizeof(DRIZZLE_DATA));
828
647
  prev_ptr= &result->data;
829
648
  result->rows=0;
830
649
  result->fields=fields;
959
778
  if (!drizzle_client_init)
960
779
  {
961
780
    drizzle_client_init=true;
962
 
    org_my_init_done=my_init_done;
963
 
 
964
 
    /* Will init threads */
965
 
    if (my_init())
966
 
      return NULL;
967
781
 
968
782
    if (!drizzle_port)
969
783
    {
994
808
    (void) signal(SIGPIPE, SIG_IGN);
995
809
#endif
996
810
  }
997
 
  else
998
 
    /* Init if new thread */
999
 
    if (my_thread_init())
1000
 
      return NULL;
1001
811
 
1002
812
  if (ptr == NULL)
1003
813
  {
1071
881
 
1072
882
  vio_end();
1073
883
 
1074
 
  /* If library called my_init(), free memory allocated by it */
1075
 
  if (!org_my_init_done)
1076
 
  {
1077
 
    my_end(0);
1078
 
  }
1079
 
 
1080
884
  drizzle_client_init= org_my_init_done= 0;
1081
885
}
1082
886
 
1083
887
 
1084
888
/*
1085
 
  Fill in SSL part of DRIZZLE structure and set 'use_ssl' flag.
1086
 
  NB! Errors are not reported until you do drizzle_connect.
1087
 
*/
1088
 
 
1089
 
#define strdup_if_not_null(A) (A) == 0 ? 0 : my_strdup((A),MYF(MY_WME))
1090
 
 
1091
 
/*
1092
889
  Note that the drizzle argument must be initialized with drizzle_init()
1093
890
  before calling drizzle_connect !
1094
891
*/
1118
915
 
1119
916
DRIZZLE *
1120
917
CLI_DRIZZLE_CONNECT(DRIZZLE *drizzle,const char *host, const char *user,
1121
 
                       const char *passwd, const char *db,
1122
 
                       uint32_t port, const char *unix_socket, uint32_t client_flag)
 
918
                    const char *passwd, const char *db,
 
919
                    uint32_t port,
 
920
                    const char * unix_port __attribute__((__unused__)),
 
921
                    uint32_t client_flag)
1123
922
{
1124
923
  char          buff[NAME_LEN+USERNAME_LENGTH+100];
1125
924
  char          *end,*host_info=NULL;
1133
932
  net->vio = 0;        /* If something goes wrong */
1134
933
  drizzle->client_flag=0;      /* For handshake */
1135
934
 
1136
 
  /* use default options */
1137
 
  if (drizzle->options.my_cnf_file || drizzle->options.my_cnf_group)
1138
 
  {
1139
 
    drizzle_read_default_options(&drizzle->options,
1140
 
             (drizzle->options.my_cnf_file ?
1141
 
        drizzle->options.my_cnf_file : "my"),
1142
 
             drizzle->options.my_cnf_group);
1143
 
    my_free(drizzle->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
1144
 
    my_free(drizzle->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
1145
 
    drizzle->options.my_cnf_file=drizzle->options.my_cnf_group=0;
1146
 
  }
1147
 
 
1148
935
  /* Some empty-string-tests are done because of ODBC */
1149
936
  if (!host || !host[0])
1150
937
    host=drizzle->options.host;
1164
951
    db=drizzle->options.db;
1165
952
  if (!port)
1166
953
    port=drizzle->options.port;
1167
 
  if (!unix_socket)
1168
 
    unix_socket=drizzle->options.unix_socket;
1169
954
 
1170
955
  drizzle->server_status=SERVER_STATUS_AUTOCOMMIT;
1171
956
 
1180
965
    int gai_errno;
1181
966
    char port_buf[NI_MAXSERV];
1182
967
 
1183
 
    unix_socket=0;        /* This is not used */
1184
 
 
1185
968
    if (!port)
1186
969
      port= drizzle_port;
1187
970
 
1324
1107
  }
1325
1108
 
1326
1109
  /* Save connection information */
1327
 
  if (!my_multi_malloc(MYF(0),
1328
 
           &drizzle->host_info, (uint) strlen(host_info)+1,
1329
 
           &drizzle->host,      (uint) strlen(host)+1,
1330
 
           &drizzle->unix_socket,unix_socket ?
1331
 
           (uint) strlen(unix_socket)+1 : (uint) 1,
1332
 
           &drizzle->server_version,
1333
 
           (uint) (end - (char*) net->read_pos),
1334
 
           NullS) ||
1335
 
      !(drizzle->user=my_strdup(user,MYF(0))) ||
1336
 
      !(drizzle->passwd=my_strdup(passwd,MYF(0))))
 
1110
  if (!(drizzle->host_info= (char *)malloc(strlen(host_info)+1+strlen(host)+1
 
1111
                                           +(end - (char*) net->read_pos))) ||
 
1112
      !(drizzle->user=strdup(user)) ||
 
1113
      !(drizzle->passwd=strdup(passwd)))
1337
1114
  {
1338
1115
    set_drizzle_error(drizzle, CR_OUT_OF_MEMORY, unknown_sqlstate);
1339
1116
    goto error;
1340
1117
  }
 
1118
  drizzle->host= drizzle->host_info+strlen(host_info)+1;
 
1119
  drizzle->server_version= drizzle->host+strlen(host)+1;
1341
1120
  strcpy(drizzle->host_info,host_info);
1342
1121
  strcpy(drizzle->host,host);
1343
 
  if (unix_socket)
1344
 
    strcpy(drizzle->unix_socket,unix_socket);
1345
 
  else
1346
 
    drizzle->unix_socket=0;
1347
1122
  strcpy(drizzle->server_version,(char*) net->read_pos+1);
1348
1123
  drizzle->port=port;
1349
1124
 
1350
1125
  /*
1351
1126
    Part 2: format and send client info to the server for access check
1352
1127
  */
1353
 
 
 
1128
 
1354
1129
  client_flag|=drizzle->options.client_flag;
1355
1130
  client_flag|=CLIENT_CAPABILITIES;
1356
1131
  if (client_flag & CLIENT_MULTI_STATEMENTS)
1397
1172
  if (db && (drizzle->server_capabilities & CLIENT_CONNECT_WITH_DB))
1398
1173
  {
1399
1174
    end= strncpy(end, db, NAME_LEN) + NAME_LEN + 1;
1400
 
    drizzle->db= my_strdup(db,MYF(MY_WME));
 
1175
    drizzle->db= strdup(db);
1401
1176
    db= 0;
1402
1177
  }
1403
1178
  /* Write authentication package */
1436
1211
    goto error;
1437
1212
  }
1438
1213
 
1439
 
  if (drizzle->options.init_commands)
1440
 
  {
1441
 
    DYNAMIC_ARRAY *init_commands= drizzle->options.init_commands;
1442
 
    char **ptr= (char**)init_commands->buffer;
1443
 
    char **end_command= ptr + init_commands->elements;
1444
 
 
1445
 
    bool reconnect=drizzle->reconnect;
1446
 
    drizzle->reconnect=0;
1447
 
 
1448
 
    for (; ptr < end_command; ptr++)
1449
 
    {
1450
 
      DRIZZLE_RES *res;
1451
 
      if (drizzle_real_query(drizzle,*ptr, (uint32_t) strlen(*ptr)))
1452
 
  goto error;
1453
 
      if (drizzle->fields)
1454
 
      {
1455
 
  if (!(res= cli_use_result(drizzle)))
1456
 
    goto error;
1457
 
  drizzle_free_result(res);
1458
 
      }
1459
 
    }
1460
 
    drizzle->reconnect=reconnect;
1461
 
  }
1462
1214
 
1463
1215
  reset_sigpipe(drizzle);
1464
1216
  return(drizzle);
1494
1246
  tmp_drizzle.options.my_cnf_file= tmp_drizzle.options.my_cnf_group= 0;
1495
1247
 
1496
1248
  if (!drizzle_connect(&tmp_drizzle,drizzle->host,drizzle->user,drizzle->passwd,
1497
 
        drizzle->db, drizzle->port, drizzle->unix_socket,
 
1249
        drizzle->db, drizzle->port, 0,
1498
1250
        drizzle->client_flag | CLIENT_REMEMBER_OPTIONS))
1499
1251
  {
1500
1252
    drizzle->net.last_errno= tmp_drizzle.net.last_errno;
1529
1281
  if ((error=simple_command(drizzle,COM_INIT_DB, (const uchar*) db,
1530
1282
                            (uint32_t) strlen(db),0)))
1531
1283
    return(error);
1532
 
  my_free(drizzle->db,MYF(MY_ALLOW_ZERO_PTR));
1533
 
  drizzle->db=my_strdup(db,MYF(MY_WME));
 
1284
  if (drizzle->db != NULL)
 
1285
    free(drizzle->db);
 
1286
  drizzle->db=strdup(db);
1534
1287
  return(0);
1535
1288
}
1536
1289
 
1542
1295
 
1543
1296
static void drizzle_close_free_options(DRIZZLE *drizzle)
1544
1297
{
1545
 
  my_free(drizzle->options.user,MYF(MY_ALLOW_ZERO_PTR));
1546
 
  my_free(drizzle->options.host,MYF(MY_ALLOW_ZERO_PTR));
1547
 
  my_free(drizzle->options.password,MYF(MY_ALLOW_ZERO_PTR));
1548
 
  my_free(drizzle->options.unix_socket,MYF(MY_ALLOW_ZERO_PTR));
1549
 
  my_free(drizzle->options.db,MYF(MY_ALLOW_ZERO_PTR));
1550
 
  my_free(drizzle->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
1551
 
  my_free(drizzle->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
1552
 
  my_free(drizzle->options.client_ip,MYF(MY_ALLOW_ZERO_PTR));
1553
 
  if (drizzle->options.init_commands)
1554
 
  {
1555
 
    DYNAMIC_ARRAY *init_commands= drizzle->options.init_commands;
1556
 
    char **ptr= (char**)init_commands->buffer;
1557
 
    char **end= ptr + init_commands->elements;
1558
 
    for (; ptr<end; ptr++)
1559
 
      my_free(*ptr,MYF(MY_WME));
1560
 
    delete_dynamic(init_commands);
1561
 
    my_free((char*)init_commands,MYF(MY_WME));
1562
 
  }
 
1298
  if (drizzle->options.user != NULL)
 
1299
    free(drizzle->options.user);
 
1300
  if (drizzle->options.host != NULL)
 
1301
    free(drizzle->options.host);
 
1302
  if (drizzle->options.password != NULL)
 
1303
    free(drizzle->options.password);
 
1304
  if (drizzle->options.db != NULL)
 
1305
    free(drizzle->options.db);
 
1306
  if (drizzle->options.my_cnf_file != NULL)
 
1307
    free(drizzle->options.my_cnf_file);
 
1308
  if (drizzle->options.my_cnf_group != NULL)
 
1309
    free(drizzle->options.my_cnf_group);
 
1310
  if (drizzle->options.client_ip != NULL)
 
1311
    free(drizzle->options.client_ip);
1563
1312
  memset(&drizzle->options, 0, sizeof(drizzle->options));
1564
1313
  return;
1565
1314
}
1567
1316
 
1568
1317
static void drizzle_close_free(DRIZZLE *drizzle)
1569
1318
{
1570
 
  my_free((uchar*) drizzle->host_info,MYF(MY_ALLOW_ZERO_PTR));
1571
 
  my_free(drizzle->user,MYF(MY_ALLOW_ZERO_PTR));
1572
 
  my_free(drizzle->passwd,MYF(MY_ALLOW_ZERO_PTR));
1573
 
  my_free(drizzle->db,MYF(MY_ALLOW_ZERO_PTR));
1574
 
  my_free(drizzle->info_buffer,MYF(MY_ALLOW_ZERO_PTR));
 
1319
  if (drizzle->host_info != NULL)
 
1320
    free((uchar*) drizzle->host_info);
 
1321
  if (drizzle->user != NULL)
 
1322
    free(drizzle->user);
 
1323
  if (drizzle->passwd != NULL)
 
1324
    free(drizzle->passwd);
 
1325
  if (drizzle->db != NULL)
 
1326
    free(drizzle->db);
 
1327
  if (drizzle->info_buffer != NULL)
 
1328
    free(drizzle->info_buffer);
1575
1329
  drizzle->info_buffer= 0;
1576
1330
 
1577
1331
  /* Clear pointers for better safety */
1595
1349
    drizzle_close_free_options(drizzle);
1596
1350
    drizzle_close_free(drizzle);
1597
1351
    if (drizzle->free_me)
1598
 
      my_free((uchar*) drizzle,MYF(0));
 
1352
      free((uchar*) drizzle);
1599
1353
  }
1600
1354
  return;
1601
1355
}
1696
1450
    return(0);
1697
1451
  }
1698
1452
  drizzle->status=DRIZZLE_STATUS_READY;    /* server is ready */
1699
 
  if (!(result=(DRIZZLE_RES*) my_malloc((uint) (sizeof(DRIZZLE_RES)+
 
1453
  if (!(result=(DRIZZLE_RES*) malloc((uint) (sizeof(DRIZZLE_RES)+
1700
1454
                sizeof(uint32_t) *
1701
 
                drizzle->field_count),
1702
 
              MYF(MY_WME | MY_ZEROFILL))))
 
1455
                drizzle->field_count))))
1703
1456
  {
1704
1457
    set_drizzle_error(drizzle, CR_OUT_OF_MEMORY, unknown_sqlstate);
1705
1458
    return(0);
1706
1459
  }
 
1460
  memset(result, 0,(sizeof(DRIZZLE_RES)+ sizeof(uint32_t) *
 
1461
                    drizzle->field_count));
1707
1462
  result->methods= drizzle->methods;
1708
1463
  result->eof= 1;        /* Marker for buffered */
1709
1464
  result->lengths= (uint32_t*) (result+1);
1710
1465
  if (!(result->data=
1711
1466
  (*drizzle->methods->read_rows)(drizzle,drizzle->fields,drizzle->field_count)))
1712
1467
  {
1713
 
    my_free((uchar*) result,MYF(0));
 
1468
    free((uchar*) result);
1714
1469
    return(0);
1715
1470
  }
1716
1471
  drizzle->affected_rows= result->row_count= result->data->rows;
1746
1501
    set_drizzle_error(drizzle, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
1747
1502
    return(0);
1748
1503
  }
1749
 
  if (!(result=(DRIZZLE_RES*) my_malloc(sizeof(*result)+
1750
 
              sizeof(uint32_t)*drizzle->field_count,
1751
 
              MYF(MY_WME | MY_ZEROFILL))))
 
1504
  if (!(result=(DRIZZLE_RES*) malloc(sizeof(*result)+
 
1505
                                     sizeof(uint32_t)*drizzle->field_count)))
1752
1506
    return(0);
 
1507
  memset(result, 0, sizeof(*result)+ sizeof(uint32_t)*drizzle->field_count);
1753
1508
  result->lengths=(uint32_t*) (result+1);
1754
1509
  result->methods= drizzle->methods;
1755
1510
  if (!(result->row=(DRIZZLE_ROW)
1756
 
  my_malloc(sizeof(result->row[0])*(drizzle->field_count+1), MYF(MY_WME))))
 
1511
        malloc(sizeof(result->row[0])*(drizzle->field_count+1))))
1757
1512
  {          /* Ptrs: to one row */
1758
 
    my_free((uchar*) result,MYF(0));
 
1513
    free((uchar*) result);
1759
1514
    return(0);
1760
1515
  }
1761
1516
  result->fields=  drizzle->fields;
1862
1617
    else
1863
1618
      drizzle->options.client_flag&= ~CLIENT_LOCAL_FILES;
1864
1619
    break;
1865
 
  case DRIZZLE_INIT_COMMAND:
1866
 
    add_init_command(&drizzle->options,arg);
1867
 
    break;
1868
1620
  case DRIZZLE_READ_DEFAULT_FILE:
1869
 
    my_free(drizzle->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
1870
 
    drizzle->options.my_cnf_file=my_strdup(arg,MYF(MY_WME));
 
1621
    if (drizzle->options.my_cnf_file != NULL)
 
1622
      free(drizzle->options.my_cnf_file);
 
1623
    drizzle->options.my_cnf_file=strdup(arg);
1871
1624
    break;
1872
1625
  case DRIZZLE_READ_DEFAULT_GROUP:
1873
 
    my_free(drizzle->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
1874
 
    drizzle->options.my_cnf_group=my_strdup(arg,MYF(MY_WME));
 
1626
    if (drizzle->options.my_cnf_group != NULL)
 
1627
      free(drizzle->options.my_cnf_group);
 
1628
    drizzle->options.my_cnf_group=strdup(arg);
1875
1629
    break;
1876
1630
  case DRIZZLE_OPT_PROTOCOL:
1877
1631
    drizzle->options.protocol= *(const uint*) arg;
1881
1635
    drizzle->options.methods_to_use= option;
1882
1636
    break;
1883
1637
  case DRIZZLE_SET_CLIENT_IP:
1884
 
    drizzle->options.client_ip= my_strdup(arg, MYF(MY_WME));
 
1638
    drizzle->options.client_ip= strdup(arg);
1885
1639
    break;
1886
1640
  case DRIZZLE_SECURE_AUTH:
1887
1641
    drizzle->options.secure_auth= *(const bool *) arg;