~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzleslap.cc

  • Committer: Brian Aker
  • Date: 2009-02-02 23:10:18 UTC
  • mfrom: (779.3.40 devel)
  • Revision ID: brian@tangent.org-20090202231018-zlp0hka6kgwy1vfy
Merge from Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
99
99
static char *shared_memory_base_name=0;
100
100
#endif
101
101
 
 
102
extern "C"
 
103
bool get_one_option(int optid, const struct my_option *, char *argument);
 
104
 
102
105
/* Global Thread counter */
103
106
uint thread_counter;
104
107
pthread_mutex_t counter_mutex;
115
118
static char **defaults_argv;
116
119
 
117
120
char **primary_keys;
118
 
uint64_t primary_keys_number_of;
 
121
/* This gets passed to malloc, so lets set it to an arch-dependant size */
 
122
size_t primary_keys_number_of;
119
123
 
120
124
static char *host= NULL, *opt_password= NULL, *user= NULL,
121
125
  *user_supplied_query= NULL,
289
293
                         option_string *engine_stmt, stats *sptr);
290
294
static int run_scheduler(stats *sptr, statement **stmts, uint concur,
291
295
                         uint64_t limit);
292
 
pthread_handler_t run_task(void *p);
293
 
pthread_handler_t timer_thread(void *p);
 
296
extern "C" pthread_handler_t run_task(void *p);
 
297
extern "C" pthread_handler_t timer_thread(void *p);
294
298
void statement_cleanup(statement *stmt);
295
299
void option_cleanup(option_string *stmt);
296
300
void concurrency_loop(DRIZZLE *drizzle, uint current, option_string *eptr);
730
734
  my_print_help(my_long_options);
731
735
}
732
736
 
733
 
static bool
734
 
get_one_option(int optid, const struct my_option *, char *argument)
 
737
bool get_one_option(int optid, const struct my_option *, char *argument)
735
738
{
736
739
  char *endchar= NULL;
737
740
  uint64_t temp_drizzle_port= 0;
792
795
  case 'V':
793
796
    print_version();
794
797
    exit(0);
795
 
    break;
796
798
  case '?':
797
799
  case 'I':          /* Info */
798
800
    usage();
1284
1286
  struct stat sbuf;
1285
1287
  option_string *sql_type;
1286
1288
  unsigned int sql_type_count= 0;
 
1289
  ssize_t bytes_read= 0;
1287
1290
 
1288
1291
 
1289
1292
  if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
1554
1557
        fprintf(stderr,"%s: Could not open create file\n", my_progname);
1555
1558
        exit(1);
1556
1559
      }
1557
 
      tmp_string= (char *)malloc(sbuf.st_size + 1);
 
1560
      if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
 
1561
      {
 
1562
        fprintf(stderr, "Request for more memory than architecture supports\n");
 
1563
        exit(1);
 
1564
      }
 
1565
      tmp_string= (char *)malloc((size_t)(sbuf.st_size + 1));
1558
1566
      if (tmp_string == NULL)
1559
1567
      {
1560
1568
        fprintf(stderr, "Memory Allocation error in option processing\n");
1561
1569
        exit(1);
1562
1570
      }
1563
 
      memset(tmp_string, 0, sbuf.st_size + 1);
1564
 
      my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
 
1571
      memset(tmp_string, 0, (size_t)(sbuf.st_size + 1));
 
1572
      bytes_read= read(data_file, (unsigned char*) tmp_string,
 
1573
                       (size_t)sbuf.st_size);
1565
1574
      tmp_string[sbuf.st_size]= '\0';
1566
 
      my_close(data_file,MYF(0));
 
1575
      close(data_file);
 
1576
      if (bytes_read != sbuf.st_size)
 
1577
      {
 
1578
        fprintf(stderr, "Problem reading file: read less bytes than requested\n");
 
1579
      }
1567
1580
      parse_delimiter(tmp_string, &create_statements, delimiter[0]);
1568
1581
      free(tmp_string);
1569
1582
    }
1601
1614
        fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1602
1615
        exit(1);
1603
1616
      }
1604
 
      tmp_string= (char *)malloc(sbuf.st_size + 1);
 
1617
      if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
 
1618
      {
 
1619
        fprintf(stderr, "Request for more memory than architecture supports\n");
 
1620
        exit(1);
 
1621
      }
 
1622
      tmp_string= (char *)malloc((size_t)(sbuf.st_size + 1));
1605
1623
      if (tmp_string == NULL)
1606
1624
      {
1607
1625
        fprintf(stderr, "Memory Allocation error in option processing\n");
1608
1626
        exit(1);
1609
1627
      }
1610
 
      memset(tmp_string, 0, sbuf.st_size + 1);
1611
 
      my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
 
1628
      memset(tmp_string, 0, (size_t)(sbuf.st_size + 1));
 
1629
      bytes_read= read(data_file, (unsigned char*) tmp_string,
 
1630
                       (size_t)sbuf.st_size);
1612
1631
      tmp_string[sbuf.st_size]= '\0';
1613
 
      my_close(data_file,MYF(0));
 
1632
      close(data_file);
 
1633
      if (bytes_read != sbuf.st_size)
 
1634
      {
 
1635
        fprintf(stderr, "Problem reading file: read less bytes than requested\n");
 
1636
      }
1614
1637
      if (user_supplied_query)
1615
1638
        actual_queries= parse_delimiter(tmp_string, &query_statements[0],
1616
1639
                                        delimiter[0]);
1638
1661
      fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1639
1662
      exit(1);
1640
1663
    }
1641
 
    tmp_string= (char *)malloc(sbuf.st_size + 1);
 
1664
    if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
 
1665
    {
 
1666
      fprintf(stderr, "Request for more memory than architecture supports\n");
 
1667
      exit(1);
 
1668
    }
 
1669
    tmp_string= (char *)malloc((size_t)(sbuf.st_size + 1));
1642
1670
    if (tmp_string == NULL)
1643
1671
    {
1644
1672
      fprintf(stderr, "Memory Allocation error in option processing\n");
1645
1673
      exit(1);
1646
1674
    }
1647
 
    memset(tmp_string, 0, sbuf.st_size + 1);
1648
 
    my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
 
1675
    memset(tmp_string, 0, (size_t)(sbuf.st_size + 1));
 
1676
    bytes_read= read(data_file, (unsigned char*) tmp_string,
 
1677
                     (size_t)sbuf.st_size);
1649
1678
    tmp_string[sbuf.st_size]= '\0';
1650
 
    my_close(data_file,MYF(0));
 
1679
    close(data_file);
 
1680
    if (bytes_read != sbuf.st_size)
 
1681
    {
 
1682
      fprintf(stderr, "Problem reading file: read less bytes than requested\n");
 
1683
    }
1651
1684
    if (user_supplied_pre_statements)
1652
1685
      (void)parse_delimiter(tmp_string, &pre_statements,
1653
1686
                            delimiter[0]);
1675
1708
      fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1676
1709
      exit(1);
1677
1710
    }
1678
 
    tmp_string= (char *)malloc(sbuf.st_size + 1);
 
1711
 
 
1712
    if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
 
1713
    {
 
1714
      fprintf(stderr, "Request for more memory than architecture supports\n");
 
1715
      exit(1);
 
1716
    }
 
1717
    tmp_string= (char *)malloc((size_t)(sbuf.st_size + 1));
1679
1718
    if (tmp_string == NULL)
1680
1719
    {
1681
1720
      fprintf(stderr, "Memory Allocation error in option processing\n");
1682
1721
      exit(1);
1683
1722
    }
1684
 
    memset(tmp_string, 0, sbuf.st_size+1);
1685
 
    my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
 
1723
    memset(tmp_string, 0, (size_t)(sbuf.st_size+1));
 
1724
 
 
1725
    bytes_read= read(data_file, (unsigned char*) tmp_string,
 
1726
                     (size_t)(sbuf.st_size));
1686
1727
    tmp_string[sbuf.st_size]= '\0';
1687
 
    my_close(data_file,MYF(0));
 
1728
    close(data_file);
 
1729
    if (bytes_read != sbuf.st_size)
 
1730
    {
 
1731
      fprintf(stderr, "Problem reading file: read less bytes than requested\n");
 
1732
    }
1688
1733
    if (user_supplied_post_statements)
1689
1734
      (void)parse_delimiter(tmp_string, &post_statements,
1690
1735
                            delimiter[0]);
1765
1810
    }
1766
1811
 
1767
1812
    result= drizzle_store_result(drizzle);
1768
 
    primary_keys_number_of= drizzle_num_rows(result);
 
1813
    uint64_t num_rows_ret= drizzle_num_rows(result);
 
1814
    if (num_rows_ret > SIZE_MAX)
 
1815
    {
 
1816
      fprintf(stderr, "More primary keys than than architecture supports\n");
 
1817
      exit(1);
 
1818
    }
 
1819
    primary_keys_number_of= (size_t)num_rows_ret;
1769
1820
 
1770
1821
    /* So why check this? Blackhole :) */
1771
1822
    if (primary_keys_number_of)
1780
1831
        fprintf(stderr, "Memory Allocation error in option processing\n");
1781
1832
        exit(1);
1782
1833
      }
1783
 
      memset(primary_keys, 0, sizeof(char *) * primary_keys_number_of);
 
1834
      memset(primary_keys, 0, (size_t)(sizeof(char *) * primary_keys_number_of));
1784
1835
      row= drizzle_fetch_row(result);
1785
1836
      for (counter= 0; counter < primary_keys_number_of;
1786
1837
           counter++, row= drizzle_fetch_row(result))