~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzleslap.cc

  • Committer: Brian Aker
  • Date: 2010-08-15 23:33:11 UTC
  • mto: (1711.1.17 build)
  • mto: This revision was merged to the branch mainline in revision 1713.
  • Revision ID: brian@tangent.org-20100815233311-2l4hq5lbjuedb4rq
Move primary_keys to being a vector.

Show diffs side-by-side

added added

removed removed

Lines of Context:
120
120
pthread_mutex_t timer_alarm_mutex;
121
121
pthread_cond_t timer_alarm_threshold;
122
122
 
123
 
char **primary_keys;
 
123
std::vector < std::string > primary_keys;
124
124
/* This gets passed to malloc, so lets set it to an arch-dependant size */
125
125
size_t primary_keys_number_of;
126
126
 
797
797
static Statement *build_update_string(void);
798
798
static Statement * build_select_string(bool key);
799
799
static int generate_primary_key_list(drizzle_con_st *con, OptionString *engine_stmt);
800
 
static int drop_primary_key_list(void);
801
800
static int create_schema(drizzle_con_st *con, const char *db, Statement *stmt,
802
801
                         OptionString *engine_stmt, Stats *sptr);
803
802
static int run_scheduler(Stats *sptr, Statement **stmts, uint32_t concur,
1245
1244
 
1246
1245
    /* We are finished with this run */
1247
1246
    if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
1248
 
      drop_primary_key_list();
 
1247
      primary_keys.clear();
1249
1248
  }
1250
1249
 
1251
1250
  if (verbose >= 2)
2196
2195
                         strstr(engine_stmt->getString(), "blackhole")))
2197
2196
  {
2198
2197
    primary_keys_number_of= 1;
2199
 
    primary_keys= (char **)malloc((sizeof(char *) *
2200
 
                                  primary_keys_number_of));
2201
 
    if (primary_keys == NULL)
2202
 
    {
2203
 
      fprintf(stderr, "Memory Allocation error in option processing\n");
2204
 
      exit(1);
2205
 
    }
2206
 
    
2207
 
    memset(primary_keys, 0, (sizeof(char *) * primary_keys_number_of));
2208
2198
    /* Yes, we strdup a const string to simplify the interface */
2209
 
    primary_keys[0]= strdup("796c4422-1d94-102a-9d6d-00e0812d");
2210
 
    if (primary_keys[0] == NULL)
2211
 
    {
2212
 
      fprintf(stderr, "Memory Allocation error in option processing\n");
2213
 
      exit(1);
2214
 
    }
 
2199
    primary_keys.push_back("796c4422-1d94-102a-9d6d-00e0812d");
2215
2200
  }
2216
2201
  else
2217
2202
  {
2236
2221
      /*
2237
2222
        We create the structure and loop and create the items.
2238
2223
      */
2239
 
      primary_keys= (char **)malloc(sizeof(char *) *
2240
 
                                    primary_keys_number_of);
2241
 
      if (primary_keys == NULL)
2242
 
      {
2243
 
        fprintf(stderr, "Memory Allocation error in option processing\n");
2244
 
        exit(1);
2245
 
      }
2246
 
      memset(primary_keys, 0, (size_t)(sizeof(char *) * primary_keys_number_of));
2247
2224
      row= drizzle_row_next(&result);
2248
2225
      for (counter= 0; counter < primary_keys_number_of;
2249
2226
           counter++, row= drizzle_row_next(&result))
2250
2227
      {
2251
 
        primary_keys[counter]= strdup(row[0]);
2252
 
        if (primary_keys[counter] == NULL)
2253
 
        {
2254
 
          fprintf(stderr, "Memory Allocation error in option processing\n");
2255
 
          exit(1);
2256
 
        }
 
2228
        primary_keys.push_back(row[0]);
2257
2229
      }
2258
2230
    }
2259
2231
 
2264
2236
}
2265
2237
 
2266
2238
static int
2267
 
drop_primary_key_list(void)
2268
 
{
2269
 
  uint64_t counter;
2270
 
 
2271
 
  if (primary_keys_number_of)
2272
 
  {
2273
 
    for (counter= 0; counter < primary_keys_number_of; counter++)
2274
 
      free(primary_keys[counter]);
2275
 
 
2276
 
    free(primary_keys);
2277
 
  }
2278
 
 
2279
 
  return 0;
2280
 
}
2281
 
 
2282
 
static int
2283
2239
create_schema(drizzle_con_st *con, const char *db, Statement *stmt,
2284
2240
              OptionString *engine_stmt, Stats *sptr)
2285
2241
{
2628
2584
    {
2629
2585
      int length;
2630
2586
      unsigned int key_val;
2631
 
      char *key;
2632
2587
      char buffer[HUGE_STRING_LENGTH];
2633
2588
 
2634
2589
      /*
2642
2597
      if (primary_keys_number_of)
2643
2598
      {
2644
2599
        key_val= (unsigned int)(random() % primary_keys_number_of);
2645
 
        key= primary_keys[key_val];
 
2600
        const char *key;
 
2601
        key= primary_keys[key_val].c_str();
2646
2602
 
2647
2603
        assert(key);
2648
2604