~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzleslap.cc

  • Committer: Brian Aker
  • Date: 2008-12-09 17:33:02 UTC
  • mfrom: (656.1.54 devel)
  • Revision ID: brian@tangent.org-20081209173302-aptngvc7efxnatnt
Merge from Monty.

Show diffs side-by-side

added added

removed removed

Lines of Context:
437
437
  conclusions conclusion;
438
438
  uint64_t client_limit;
439
439
 
440
 
  head_sptr= (stats *)my_malloc(sizeof(stats) * iterations,
441
 
                                MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
440
  head_sptr= (stats *)malloc(sizeof(stats) * iterations);
 
441
  if (head_sptr == NULL)
 
442
  {
 
443
    fprintf(stderr,"Error allocating memory in concurrency_loop\n");
 
444
    exit(1);
 
445
  }
 
446
  memset(head_sptr, 0, sizeof(stats) * iterations);
442
447
 
443
448
  memset(&conclusion, 0, sizeof(conclusions));
444
449
 
713
718
static void usage(void)
714
719
{
715
720
  print_version();
716
 
  puts("Copyright (C) 2005 DRIZZLE AB");
 
721
  puts("Copyright (C) 2008 Sun Microsystems");
717
722
  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\
718
723
       \nand you are welcome to modify and redistribute it under the GPL \
719
724
       license\n");
735
740
    if (argument)
736
741
    {
737
742
      char *start= argument;
738
 
      free(opt_password);
739
 
      opt_password= my_strdup(argument,MYF(MY_FAE));
 
743
      if (opt_password)
 
744
        free(opt_password);
 
745
      opt_password = strdup(argument);
 
746
      if (opt_password == NULL)
 
747
      {
 
748
        fprintf(stderr, "Memory allocation error while copying password. "
 
749
                        "Aborting.\n");
 
750
        exit(ENOMEM);
 
751
      }
740
752
      while (*argument) *argument++= 'x';    /* Destroy argument */
741
753
      if (*start)
742
754
        start[1]= 0;        /* Cut length of argument */
897
909
    }
898
910
 
899
911
  table_string.append(")");
900
 
  ptr= (statement *)my_malloc(sizeof(statement),
901
 
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
902
 
  ptr->string = (char *)my_malloc(table_string.length()+1,
903
 
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
912
  ptr= (statement *)malloc(sizeof(statement));
 
913
  if (ptr == NULL)
 
914
  {
 
915
    fprintf(stderr, "Memory Allocation error in creating table\n");
 
916
    exit(1);
 
917
  }
 
918
  memset(ptr, 0, sizeof(statement));
 
919
  ptr->string = (char *)malloc(table_string.length()+1);
 
920
  if (ptr->string == NULL)
 
921
  {
 
922
    fprintf(stderr, "Memory Allocation error in creating table\n");
 
923
    exit(1);
 
924
  }
 
925
  memset(ptr->string, 0, table_string.length()+1);
904
926
  ptr->length= table_string.length()+1;
905
927
  ptr->type= CREATE_TABLE_TYPE;
906
928
  strcpy(ptr->string, table_string.c_str());
963
985
    update_string.append(" WHERE id = ");
964
986
 
965
987
 
966
 
  ptr= (statement *)my_malloc(sizeof(statement),
967
 
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
988
  ptr= (statement *)malloc(sizeof(statement));
 
989
  if (ptr == NULL)
 
990
  {
 
991
    fprintf(stderr, "Memory Allocation error in creating update\n");
 
992
    exit(1);
 
993
  }
 
994
  memset(ptr, 0, sizeof(statement));
968
995
 
969
 
  ptr->string= (char *)my_malloc(update_string.length() + 1,
970
 
                                 MYF(MY_ZEROFILL|MY_FAE|MY_WME));
971
996
  ptr->length= update_string.length()+1;
 
997
  ptr->string= (char *)malloc(ptr->length);
 
998
  if (ptr->string == NULL)
 
999
  {
 
1000
    fprintf(stderr, "Memory Allocation error in creating update\n");
 
1001
    exit(1);
 
1002
  }
 
1003
  memset(ptr->string, 0, ptr->length);
972
1004
  if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
973
1005
    ptr->type= UPDATE_TYPE_REQUIRES_PREFIX ;
974
1006
  else
975
1007
    ptr->type= UPDATE_TYPE;
976
 
  strcpy(ptr->string, update_string.c_str());
 
1008
  strncpy(ptr->string, update_string.c_str(), ptr->length);
977
1009
  return(ptr);
978
1010
}
979
1011
 
1060
1092
 
1061
1093
    if (num_blob_cols_size > HUGE_STRING_LENGTH)
1062
1094
    {
1063
 
      blob_ptr= (char *)my_malloc(sizeof(char)*num_blob_cols_size,
1064
 
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1095
      blob_ptr= (char *)malloc(sizeof(char)*num_blob_cols_size);
1065
1096
      if (!blob_ptr)
1066
1097
      {
1067
1098
        fprintf(stderr, "Memory Allocation error in creating select\n");
1068
1099
        exit(1);
1069
1100
      }
 
1101
      memset(blob_ptr, 0, sizeof(char)*num_blob_cols_size);
1070
1102
    }
1071
1103
    else
1072
1104
    {
1098
1130
 
1099
1131
  insert_string.append(")", 1);
1100
1132
 
1101
 
  if (!(ptr= (statement *)my_malloc(sizeof(statement), MYF(MY_ZEROFILL|MY_FAE|MY_WME))))
1102
 
  {
1103
 
    fprintf(stderr, "Memory Allocation error in creating select\n");
1104
 
    exit(1);
1105
 
  }
1106
 
  if (!(ptr->string= (char *)my_malloc(insert_string.length() + 1, MYF(MY_ZEROFILL|MY_FAE|MY_WME))))
1107
 
  {
1108
 
    fprintf(stderr, "Memory Allocation error in creating select\n");
1109
 
    exit(1);
1110
 
  }
 
1133
  if (!(ptr= (statement *)malloc(sizeof(statement))))
 
1134
  {
 
1135
    fprintf(stderr, "Memory Allocation error in creating select\n");
 
1136
    exit(1);
 
1137
  }
 
1138
  memset(ptr, 0, sizeof(statement));
1111
1139
  ptr->length= insert_string.length()+1;
 
1140
  if (!(ptr->string= (char *)malloc(ptr->length)))
 
1141
  {
 
1142
    fprintf(stderr, "Memory Allocation error in creating select\n");
 
1143
    exit(1);
 
1144
  }
 
1145
  memset(ptr->string, 0, ptr->length);
1112
1146
  ptr->type= INSERT_TYPE;
1113
1147
  strcpy(ptr->string, insert_string.c_str());
1114
1148
  return(ptr);
1186
1220
      (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1187
1221
    query_string.append(" WHERE id = ");
1188
1222
 
1189
 
  ptr= (statement *)my_malloc(sizeof(statement),
1190
 
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1191
 
  ptr->string= (char *)my_malloc(query_string.length() + 1,
1192
 
                                 MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1223
  ptr= (statement *)malloc(sizeof(statement));
 
1224
  if (ptr == NULL)
 
1225
  {
 
1226
    fprintf(stderr, "Memory Allocation error in creating select\n");
 
1227
    exit(1);
 
1228
  }
 
1229
  memset(ptr, 0, sizeof(statement));
1193
1230
  ptr->length= query_string.length()+1;
 
1231
  ptr->string= (char *)malloc(ptr->length);
 
1232
  if (ptr->string == NULL)
 
1233
  {
 
1234
    fprintf(stderr, "Memory Allocation error in creating select\n");
 
1235
    exit(1);
 
1236
  }
 
1237
  memset(ptr->string, 0, ptr->length);
1194
1238
  if ((key) &&
1195
1239
      (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1196
1240
    ptr->type= SELECT_TYPE_REQUIRES_PREFIX;
1352
1396
    query_statements_count=
1353
1397
      parse_option(opt_auto_generate_sql_type, &query_options, ',');
1354
1398
 
1355
 
    query_statements= (statement **)my_malloc(sizeof(statement *) * query_statements_count,
1356
 
                                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1399
    query_statements= (statement **)malloc(sizeof(statement *) * query_statements_count);
 
1400
    if (query_statements == NULL)
 
1401
    {
 
1402
      fprintf(stderr, "Memory Allocation error in Building Query Statements\n");
 
1403
      exit(1);
 
1404
    }
 
1405
    memset(query_statements, 0, sizeof(statement *) * query_statements_count);
1357
1406
 
1358
1407
    sql_type= query_options;
1359
1408
    do
1473
1522
        fprintf(stderr,"%s: Could not open create file\n", my_progname);
1474
1523
        exit(1);
1475
1524
      }
1476
 
      tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1477
 
                                    MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1525
      tmp_string= (char *)malloc(sbuf.st_size + 1);
 
1526
      if (tmp_string == NULL)
 
1527
      {
 
1528
        fprintf(stderr, "Memory Allocation error in option processing\n");
 
1529
        exit(1);
 
1530
      }
 
1531
      memset(tmp_string, 0, sbuf.st_size + 1);
1478
1532
      my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
1479
1533
      tmp_string[sbuf.st_size]= '\0';
1480
1534
      my_close(data_file,MYF(0));
1492
1546
      query_statements_count=
1493
1547
        parse_option("default", &query_options, ',');
1494
1548
 
1495
 
      query_statements= (statement **)my_malloc(sizeof(statement *),
1496
 
                                                MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1549
      query_statements= (statement **)malloc(sizeof(statement *) * query_statements_count);
 
1550
      if (query_statements == NULL)
 
1551
      {
 
1552
        fprintf(stderr, "Memory Allocation error in option processing\n");
 
1553
        exit(1);
 
1554
      }
 
1555
      memset(query_statements, 0, sizeof(statement *) * query_statements_count); 
1497
1556
    }
1498
1557
 
1499
1558
    if (user_supplied_query && !stat(user_supplied_query, &sbuf))
1510
1569
        fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1511
1570
        exit(1);
1512
1571
      }
1513
 
      tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1514
 
                                    MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1572
      tmp_string= (char *)malloc(sbuf.st_size + 1);
 
1573
      if (tmp_string == NULL)
 
1574
      {
 
1575
        fprintf(stderr, "Memory Allocation error in option processing\n");
 
1576
        exit(1);
 
1577
      }
 
1578
      memset(tmp_string, 0, sbuf.st_size + 1);
1515
1579
      my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
1516
1580
      tmp_string[sbuf.st_size]= '\0';
1517
1581
      my_close(data_file,MYF(0));
1542
1606
      fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1543
1607
      exit(1);
1544
1608
    }
1545
 
    tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1546
 
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1609
    tmp_string= (char *)malloc(sbuf.st_size + 1);
 
1610
    if (tmp_string == NULL)
 
1611
    {
 
1612
      fprintf(stderr, "Memory Allocation error in option processing\n");
 
1613
      exit(1);
 
1614
    }
 
1615
    memset(tmp_string, 0, sbuf.st_size + 1);
1547
1616
    my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
1548
1617
    tmp_string[sbuf.st_size]= '\0';
1549
1618
    my_close(data_file,MYF(0));
1574
1643
      fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1575
1644
      exit(1);
1576
1645
    }
1577
 
    tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1578
 
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1646
    tmp_string= (char *)malloc(sbuf.st_size + 1);
 
1647
    if (tmp_string == NULL)
 
1648
    {
 
1649
      fprintf(stderr, "Memory Allocation error in option processing\n");
 
1650
      exit(1);
 
1651
    }
 
1652
    memset(tmp_string, 0, sbuf.st_size+1);
1579
1653
    my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
1580
1654
    tmp_string[sbuf.st_size]= '\0';
1581
1655
    my_close(data_file,MYF(0));
1632
1706
                         strstr(engine_stmt->string, "blackhole")))
1633
1707
  {
1634
1708
    primary_keys_number_of= 1;
1635
 
    primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
1636
 
                                            primary_keys_number_of),
1637
 
                                     MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1709
    primary_keys= (char **)malloc((sizeof(char *) *
 
1710
                                  primary_keys_number_of));
 
1711
    if (primary_keys == NULL)
 
1712
    {
 
1713
      fprintf(stderr, "Memory Allocation error in option processing\n");
 
1714
      exit(1);
 
1715
    }
 
1716
    
 
1717
    memset(primary_keys, 0, (sizeof(char *) * primary_keys_number_of));
1638
1718
    /* Yes, we strdup a const string to simplify the interface */
1639
 
    primary_keys[0]= my_strdup("796c4422-1d94-102a-9d6d-00e0812d", MYF(0));
 
1719
    primary_keys[0]= strdup("796c4422-1d94-102a-9d6d-00e0812d");
 
1720
    if (primary_keys[0] == NULL)
 
1721
    {
 
1722
      fprintf(stderr, "Memory Allocation error in option processing\n");
 
1723
      exit(1);
 
1724
    }
1640
1725
  }
1641
1726
  else
1642
1727
  {
1656
1741
      /*
1657
1742
        We create the structure and loop and create the items.
1658
1743
      */
1659
 
      primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
1660
 
                                              primary_keys_number_of),
1661
 
                                       MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1744
      primary_keys= (char **)malloc(sizeof(char *) *
 
1745
                                    primary_keys_number_of);
 
1746
      if (primary_keys == NULL)
 
1747
      {
 
1748
        fprintf(stderr, "Memory Allocation error in option processing\n");
 
1749
        exit(1);
 
1750
      }
 
1751
      memset(primary_keys, 0, sizeof(char *) * primary_keys_number_of);
1662
1752
      row= drizzle_fetch_row(result);
1663
1753
      for (counter= 0; counter < primary_keys_number_of;
1664
1754
           counter++, row= drizzle_fetch_row(result))
1665
 
        primary_keys[counter]= my_strdup(row[0], MYF(0));
 
1755
      {
 
1756
        primary_keys[counter]= strdup(row[0]);
 
1757
        if (primary_keys[counter] == NULL)
 
1758
        {
 
1759
          fprintf(stderr, "Memory Allocation error in option processing\n");
 
1760
          exit(1);
 
1761
        }
 
1762
      }
1666
1763
    }
1667
1764
 
1668
1765
    drizzle_free_result(result);
1889
1986
    while (options_loop--)
1890
1987
      for (x= 0; x < concur; x++)
1891
1988
      {
1892
 
        con= (thread_context *)my_malloc(sizeof(thread_context), MYF(0));
 
1989
        con= (thread_context *)malloc(sizeof(thread_context));
 
1990
        if (con == NULL)
 
1991
        {
 
1992
          fprintf(stderr, "Memory Allocation error in scheduler\n");
 
1993
          exit(1);
 
1994
        }
1893
1995
        con->stmt= stmts[y];
1894
1996
        con->limit= limit;
1895
1997
 
2144
2246
 
2145
2247
  end_ptr= (char *)origin + length;
2146
2248
 
2147
 
  tmp= *sptr= (option_string *)my_malloc(sizeof(option_string),
2148
 
                                         MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
2249
  tmp= *sptr= (option_string *)malloc(sizeof(option_string));
 
2250
  if (tmp == NULL)
 
2251
  {
 
2252
    fprintf(stderr,"Error allocating memory while parsing options\n");
 
2253
    exit(1);
 
2254
  }
 
2255
  memset(tmp, 0, sizeof(option_string));
2149
2256
 
2150
2257
  for (begin_ptr= (char *)origin;
2151
2258
       begin_ptr != end_ptr;
2178
2285
 
2179
2286
      /* Move past the : and the first string */
2180
2287
      tmp->option_length= strlen(buffer_ptr);
2181
 
      tmp->option= my_strndup(buffer_ptr, (uint)tmp->option_length,
2182
 
                              MYF(MY_FAE));
 
2288
      tmp->option= (char *)malloc(tmp->option_length + 1);
 
2289
      if (tmp->option == NULL)
 
2290
      {
 
2291
        fprintf(stderr,"Error allocating memory while parsing options\n");
 
2292
        exit(1);
 
2293
      }
 
2294
      memcpy(tmp->option, buffer_ptr, tmp->option_length);
 
2295
      tmp->option[tmp->option_length]= 0; 
2183
2296
    }
2184
2297
 
2185
 
    tmp->string= my_strndup(buffer, strlen(buffer), MYF(MY_FAE));
2186
2298
    tmp->length= strlen(buffer);
 
2299
    tmp->string= strdup(buffer);
 
2300
    if (tmp->string == NULL)
 
2301
    {
 
2302
      fprintf(stderr,"Error allocating memory while parsing options\n");
 
2303
      exit(1);
 
2304
    }
2187
2305
 
2188
2306
    if (isspace(*begin_ptr))
2189
2307
      begin_ptr++;
2191
2309
    count++;
2192
2310
 
2193
2311
    if (begin_ptr != end_ptr)
2194
 
      tmp->next= (option_string *)my_malloc(sizeof(option_string),
2195
 
                                            MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
2312
    {
 
2313
      tmp->next= (option_string *)malloc(sizeof(option_string));
 
2314
      if (tmp->next == NULL)
 
2315
      {
 
2316
        fprintf(stderr,"Error allocating memory while parsing options\n");
 
2317
        exit(1);
 
2318
      }
 
2319
      memset(tmp->next, 0, sizeof(option_string));
 
2320
    }
 
2321
    
2196
2322
  }
2197
2323
 
2198
2324
  return count;
2213
2339
  uint length= strlen(script);
2214
2340
  uint count= 0; /* We know that there is always one */
2215
2341
 
2216
 
  for (tmp= *sptr= (statement *)my_malloc(sizeof(statement),
2217
 
                                          MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
2342
  for (tmp= *sptr= (statement *)malloc(sizeof(statement));
2218
2343
       (retstr= strchr(ptr, delm));
2219
 
       tmp->next=  (statement *)my_malloc(sizeof(statement),
2220
 
                                          MYF(MY_ZEROFILL|MY_FAE|MY_WME)),
2221
 
         tmp= tmp->next)
 
2344
       tmp->next=  (statement *)malloc(sizeof(statement)),
 
2345
       tmp= tmp->next)
2222
2346
  {
 
2347
    memset(tmp, 0, sizeof(statement));
2223
2348
    count++;
2224
 
    tmp->string= my_strndup(ptr, (uint)(retstr - ptr), MYF(MY_FAE));
2225
2349
    tmp->length= (size_t)(retstr - ptr);
 
2350
    tmp->string= (char *)malloc(tmp->length + 1);
 
2351
    if (tmp->string == NULL)
 
2352
    {
 
2353
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
 
2354
      exit(1);
 
2355
    }
 
2356
    memcpy(tmp->string, ptr, tmp->length);
 
2357
    tmp->string[tmp->length]= 0;
2226
2358
    ptr+= retstr - ptr + 1;
2227
2359
    if (isspace(*ptr))
2228
2360
      ptr++;
2230
2362
 
2231
2363
  if (ptr != script+length)
2232
2364
  {
2233
 
    tmp->string= my_strndup(ptr, (uint)((script + length) - ptr),
2234
 
                            MYF(MY_FAE));
2235
2365
    tmp->length= (size_t)((script + length) - ptr);
 
2366
    tmp->string= (char *)malloc(tmp->length + 1);
 
2367
    if (tmp->string == NULL)
 
2368
    {
 
2369
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
 
2370
      exit(1);
 
2371
    }
 
2372
    memcpy(tmp->string, ptr, tmp->length);
 
2373
    tmp->string[tmp->length]= 0;
2236
2374
    count++;
2237
2375
  }
2238
2376
 
2248
2386
uint
2249
2387
parse_comma(const char *string, uint **range)
2250
2388
{
2251
 
  uint count= 1,x; /* We know that there is always one */
 
2389
  unsigned int count= 1,x; /* We know that there is always one */
2252
2390
  char *retstr;
2253
2391
  char *ptr= (char *)string;
2254
 
  uint *nptr;
 
2392
  unsigned int *nptr;
2255
2393
 
2256
2394
  for (;*ptr; ptr++)
2257
2395
    if (*ptr == ',') count++;
2258
2396
 
2259
2397
  /* One extra spot for the NULL */
2260
 
  nptr= *range= (uint *)my_malloc(sizeof(uint) * (count + 1),
2261
 
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
2398
  nptr= *range= (uint *)malloc(sizeof(unsigned int) * (count + 1));
 
2399
  memset(nptr, 0, sizeof(unsigned int) * (count + 1));
2262
2400
 
2263
2401
  ptr= (char *)string;
2264
2402
  x= 0;