~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Brian Aker
  • Date: 2009-11-26 18:48:20 UTC
  • mfrom: (1226.1.3 push)
  • Revision ID: brian@gaz-20091126184820-hltr0upee0ahopsj
Bundle Brian + Monty  (been through staging, just collecting it as want
overall patch as seen by staging).

Show diffs side-by-side

added added

removed removed

Lines of Context:
2212
2212
    session->client->store(table_name);
2213
2213
    session->client->store(operator_name);
2214
2214
 
2215
 
send_result_message:
2216
 
 
2217
2215
    switch (result_code) {
2218
2216
    case HA_ADMIN_NOT_IMPLEMENTED:
2219
2217
      {
2257
2255
      session->client->store(STRING_WITH_LEN("Invalid argument"));
2258
2256
      break;
2259
2257
 
2260
 
    case HA_ADMIN_TRY_ALTER:
2261
 
    {
2262
 
      /*
2263
 
        This is currently used only by InnoDB. ha_innobase::optimize() answers
2264
 
        "try with alter", so here we close the table, do an ALTER Table,
2265
 
        reopen the table and do ha_innobase::analyze() on it.
2266
 
      */
2267
 
      ha_autocommit_or_rollback(session, 0);
2268
 
      session->close_thread_tables();
2269
 
      TableList *save_next_local= table->next_local,
2270
 
                 *save_next_global= table->next_global;
2271
 
      table->next_local= table->next_global= 0;
2272
 
      result_code= mysql_recreate_table(session, table);
2273
 
      /*
2274
 
        mysql_recreate_table() can push OK or ERROR.
2275
 
        Clear 'OK' status. If there is an error, keep it:
2276
 
        we will store the error message in a result set row
2277
 
        and then clear.
2278
 
      */
2279
 
      if (session->main_da.is_ok())
2280
 
        session->main_da.reset_diagnostics_area();
2281
 
      ha_autocommit_or_rollback(session, 0);
2282
 
      session->close_thread_tables();
2283
 
      if (!result_code) // recreation went ok
2284
 
      {
2285
 
        if ((table->table= session->openTableLock(table, lock_type)) &&
2286
 
            ((result_code= table->table->cursor->ha_analyze(session, check_opt)) > 0))
2287
 
          result_code= 0; // analyze went ok
2288
 
      }
2289
 
      if (result_code) // either mysql_recreate_table or analyze failed
2290
 
      {
2291
 
        assert(session->is_error());
2292
 
        if (session->is_error())
2293
 
        {
2294
 
          const char *err_msg= session->main_da.message();
2295
 
          /* Hijack the row already in-progress. */
2296
 
          session->client->store(STRING_WITH_LEN("error"));
2297
 
          session->client->store(err_msg);
2298
 
          (void)session->client->flush();
2299
 
          /* Start off another row for HA_ADMIN_FAILED */
2300
 
          session->client->store(table_name);
2301
 
          session->client->store(operator_name);
2302
 
          session->clear_error();
2303
 
        }
2304
 
      }
2305
 
      result_code= result_code ? HA_ADMIN_FAILED : HA_ADMIN_OK;
2306
 
      table->next_local= save_next_local;
2307
 
      table->next_global= save_next_global;
2308
 
      goto send_result_message;
2309
 
    }
2310
 
    case HA_ADMIN_NEEDS_UPGRADE:
2311
 
    case HA_ADMIN_NEEDS_ALTER:
2312
 
    {
2313
 
      char buf[ERRMSGSIZE];
2314
 
      uint32_t length;
2315
 
 
2316
 
      session->client->store(STRING_WITH_LEN("error"));
2317
 
      length=snprintf(buf, ERRMSGSIZE, ER(ER_TABLE_NEEDS_UPGRADE), table->table_name);
2318
 
      session->client->store(buf, length);
2319
 
      fatal_error=1;
2320
 
      break;
2321
 
    }
2322
 
 
2323
2258
    default:                            // Probably HA_ADMIN_INTERNAL_ERROR
2324
2259
      {
2325
2260
        char buf[ERRMSGSIZE+20];
2369
2304
  return(true);
2370
2305
}
2371
2306
 
2372
 
bool mysql_optimize_table(Session* session, TableList* tables, HA_CHECK_OPT* check_opt)
2373
 
{
2374
 
  return(mysql_admin_table(session, tables, check_opt,
2375
 
                           "optimize", TL_WRITE, 1,0,0,0,
2376
 
                           &Cursor::ha_optimize));
2377
 
}
2378
 
 
2379
2307
/*
2380
2308
  Create a table identical to the specified table
2381
2309