~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_parse.cc

  • Committer: Brian Aker
  • Date: 2008-07-07 21:16:22 UTC
  • Revision ID: brian@tangent.org-20080707211622-tsk0yw2o53umgmnr
Removing bootstrap (we no longer need it... we just work).

Show diffs side-by-side

added added

removed removed

Lines of Context:
270
270
  thd->net.vio= save_vio;
271
271
}
272
272
 
273
 
 
274
 
/**
275
 
  Execute commands from bootstrap_file.
276
 
 
277
 
  Used when creating the initial grant tables.
278
 
*/
279
 
 
280
 
pthread_handler_t handle_bootstrap(void *arg)
281
 
{
282
 
  THD *thd=(THD*) arg;
283
 
  FILE *file=bootstrap_file;
284
 
  char *buff;
285
 
  const char* found_semicolon= NULL;
286
 
 
287
 
  /* The following must be called before DBUG_ENTER */
288
 
  thd->thread_stack= (char*) &thd;
289
 
  if (my_thread_init() || thd->store_globals())
290
 
  {
291
 
    close_connection(thd, ER_OUT_OF_RESOURCES, 1);
292
 
    thd->fatal_error();
293
 
    goto end;
294
 
  }
295
 
  DBUG_ENTER("handle_bootstrap");
296
 
 
297
 
  pthread_detach_this_thread();
298
 
  thd->thread_stack= (char*) &thd;
299
 
 
300
 
  if (thd->variables.max_join_size == HA_POS_ERROR)
301
 
    thd->options |= OPTION_BIG_SELECTS;
302
 
 
303
 
  thd_proc_info(thd, 0);
304
 
  thd->version=refresh_version;
305
 
  thd->security_ctx->priv_user=
306
 
    thd->security_ctx->user= (char*) my_strdup("boot", MYF(MY_WME));
307
 
  thd->security_ctx->priv_host[0]=0;
308
 
  /*
309
 
    Make the "client" handle multiple results. This is necessary
310
 
    to enable stored procedures with SELECTs and Dynamic SQL
311
 
    in init-file.
312
 
  */
313
 
  thd->client_capabilities|= CLIENT_MULTI_RESULTS;
314
 
 
315
 
  buff= (char*) thd->net.buff;
316
 
  thd->init_for_queries();
317
 
  while (fgets(buff, thd->net.max_packet, file))
318
 
  {
319
 
    /* strlen() can't be deleted because fgets() doesn't return length */
320
 
    ulong length= (ulong) strlen(buff);
321
 
    while (buff[length-1] != '\n' && !feof(file))
322
 
    {
323
 
      /*
324
 
        We got only a part of the current string. Will try to increase
325
 
        net buffer then read the rest of the current string.
326
 
      */
327
 
      /* purecov: begin tested */
328
 
      if (net_realloc(&(thd->net), 2 * thd->net.max_packet))
329
 
      {
330
 
        net_end_statement(thd);
331
 
        bootstrap_error= 1;
332
 
        break;
333
 
      }
334
 
      buff= (char*) thd->net.buff;
335
 
      fgets(buff + length, thd->net.max_packet - length, file);
336
 
      length+= (ulong) strlen(buff + length);
337
 
      /* purecov: end */
338
 
    }
339
 
    if (bootstrap_error)
340
 
      break;                                    /* purecov: inspected */
341
 
 
342
 
    while (length && (my_isspace(thd->charset(), buff[length-1]) ||
343
 
                      buff[length-1] == ';'))
344
 
      length--;
345
 
    buff[length]=0;
346
 
 
347
 
    /* Skip lines starting with delimiter */
348
 
    if (strncmp(buff, STRING_WITH_LEN("delimiter")) == 0)
349
 
      continue;
350
 
 
351
 
    thd->query_length=length;
352
 
    thd->query= (char*) thd->memdup_w_gap(buff, length+1, 
353
 
                                          thd->db_length+1);
354
 
    thd->query[length] = '\0';
355
 
    DBUG_PRINT("query",("%-.4096s",thd->query));
356
 
 
357
 
    /*
358
 
      We don't need to obtain LOCK_thread_count here because in bootstrap
359
 
      mode we have only one thread.
360
 
    */
361
 
    thd->query_id=next_query_id();
362
 
    thd->set_time();
363
 
    mysql_parse(thd, thd->query, length, & found_semicolon);
364
 
    close_thread_tables(thd);                   // Free tables
365
 
 
366
 
    bootstrap_error= thd->is_error();
367
 
    net_end_statement(thd);
368
 
 
369
 
    if (bootstrap_error)
370
 
      break;
371
 
 
372
 
    free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
373
 
    free_root(&thd->transaction.mem_root,MYF(MY_KEEP_PREALLOC));
374
 
  }
375
 
 
376
 
end:
377
 
  net_end(&thd->net);
378
 
  thd->cleanup();
379
 
  delete thd;
380
 
 
381
 
  (void) pthread_mutex_lock(&LOCK_thread_count);
382
 
  thread_count--;
383
 
  (void) pthread_mutex_unlock(&LOCK_thread_count);
384
 
  (void) pthread_cond_broadcast(&COND_thread_count);
385
 
  my_thread_end();
386
 
  pthread_exit(0);
387
 
  DBUG_RETURN(0);
388
 
}
389
 
 
390
 
/* This works because items are allocated with sql_alloc() */
391
 
 
392
 
void free_items(Item *item)
393
 
{
394
 
  Item *next;
395
 
  DBUG_ENTER("free_items");
396
 
  for (; item ; item=next)
397
 
  {
398
 
    next=item->next;
399
 
    item->delete_self();
400
 
  }
401
 
  DBUG_VOID_RETURN;
402
 
}
403
 
 
404
 
/* This works because items are allocated with sql_alloc() */
405
 
 
406
 
void cleanup_items(Item *item)
407
 
{
408
 
  DBUG_ENTER("cleanup_items");
409
 
  for (; item ; item=item->next)
410
 
    item->cleanup();
411
 
  DBUG_VOID_RETURN;
412
 
}
413
 
 
414
273
/**
415
274
  Ends the current transaction and (maybe) begin the next.
416
275