~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Brian Aker
  • Date: 2009-09-22 07:35:28 UTC
  • mfrom: (971.6.10 eday-dev)
  • Revision ID: brian@gaz-20090922073528-xgm634aomuflqxl3
MergeĀ Eric

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include <drizzled/item/empty_string.h>
34
34
#include <drizzled/replication_services.h>
35
35
#include <drizzled/table_proto.h>
 
36
#include <drizzled/plugin/client.h>
36
37
 
37
38
#include "drizzled/statement/alter_table.h" /* for mysql_create_like_schema_frm, which will die soon */
38
39
 
2110
2111
  Select_Lex *select= &session->lex->select_lex;
2111
2112
  List<Item> field_list;
2112
2113
  Item *item;
2113
 
  plugin::Protocol *protocol= session->protocol;
2114
2114
  LEX *lex= session->lex;
2115
2115
  int result_code= 0;
2116
2116
  const CHARSET_INFO * const cs= system_charset_info;
2127
2127
  item->maybe_null = 1;
2128
2128
  field_list.push_back(item = new Item_empty_string("Msg_text", 255, cs));
2129
2129
  item->maybe_null = 1;
2130
 
  if (protocol->sendFields(&field_list))
 
2130
  if (session->client->sendFields(&field_list))
2131
2131
    return true;
2132
2132
 
2133
2133
  for (table= tables; table; table= table->next_local)
2204
2204
      /* purecov: begin inspected */
2205
2205
      char buff[FN_REFLEN + DRIZZLE_ERRMSG_SIZE];
2206
2206
      uint32_t length;
2207
 
      protocol->prepareForResend();
2208
 
      protocol->store(table_name);
2209
 
      protocol->store(operator_name);
2210
 
      protocol->store(STRING_WITH_LEN("error"));
 
2207
      session->client->store(table_name);
 
2208
      session->client->store(operator_name);
 
2209
      session->client->store(STRING_WITH_LEN("error"));
2211
2210
      length= snprintf(buff, sizeof(buff), ER(ER_OPEN_AS_READONLY),
2212
2211
                       table_name);
2213
 
      protocol->store(buff, length);
 
2212
      session->client->store(buff, length);
2214
2213
      ha_autocommit_or_rollback(session, 0);
2215
2214
      session->endTransaction(COMMIT);
2216
2215
      session->close_thread_tables();
2217
2216
      lex->reset_query_tables_list(false);
2218
2217
      table->table=0;                           // For query cache
2219
 
      if (protocol->write())
 
2218
      if (session->client->flush())
2220
2219
        goto err;
2221
2220
      continue;
2222
2221
      /* purecov: end */
2242
2241
    if (table->table->s->crashed && operator_func == &handler::ha_check)
2243
2242
    {
2244
2243
      /* purecov: begin inspected */
2245
 
      protocol->prepareForResend();
2246
 
      protocol->store(table_name);
2247
 
      protocol->store(operator_name);
2248
 
      protocol->store(STRING_WITH_LEN("warning"));
2249
 
      protocol->store(STRING_WITH_LEN("Table is marked as crashed"));
2250
 
      if (protocol->write())
 
2244
      session->client->store(table_name);
 
2245
      session->client->store(operator_name);
 
2246
      session->client->store(STRING_WITH_LEN("warning"));
 
2247
      session->client->store(STRING_WITH_LEN("Table is marked as crashed"));
 
2248
      if (session->client->flush())
2251
2249
        goto err;
2252
2250
      /* purecov: end */
2253
2251
    }
2263
2261
      DRIZZLE_ERROR *err;
2264
2262
      while ((err= it++))
2265
2263
      {
2266
 
        protocol->prepareForResend();
2267
 
        protocol->store(table_name);
2268
 
        protocol->store(operator_name);
2269
 
        protocol->store(warning_level_names[err->level].str,
2270
 
                        warning_level_names[err->level].length);
2271
 
        protocol->store(err->msg);
2272
 
        if (protocol->write())
 
2264
        session->client->store(table_name);
 
2265
        session->client->store(operator_name);
 
2266
        session->client->store(warning_level_names[err->level].str,
 
2267
                               warning_level_names[err->level].length);
 
2268
        session->client->store(err->msg);
 
2269
        if (session->client->flush())
2273
2270
          goto err;
2274
2271
      }
2275
2272
      drizzle_reset_errors(session, true);
2276
2273
    }
2277
 
    protocol->prepareForResend();
2278
 
    protocol->store(table_name);
2279
 
    protocol->store(operator_name);
 
2274
    session->client->store(table_name);
 
2275
    session->client->store(operator_name);
2280
2276
 
2281
2277
send_result_message:
2282
2278
 
2286
2282
        char buf[ERRMSGSIZE+20];
2287
2283
        uint32_t length=snprintf(buf, ERRMSGSIZE,
2288
2284
                             ER(ER_CHECK_NOT_IMPLEMENTED), operator_name);
2289
 
        protocol->store(STRING_WITH_LEN("note"));
2290
 
        protocol->store(buf, length);
 
2285
        session->client->store(STRING_WITH_LEN("note"));
 
2286
        session->client->store(buf, length);
2291
2287
      }
2292
2288
      break;
2293
2289
 
2294
2290
    case HA_ADMIN_OK:
2295
 
      protocol->store(STRING_WITH_LEN("status"));
2296
 
      protocol->store(STRING_WITH_LEN("OK"));
 
2291
      session->client->store(STRING_WITH_LEN("status"));
 
2292
      session->client->store(STRING_WITH_LEN("OK"));
2297
2293
      break;
2298
2294
 
2299
2295
    case HA_ADMIN_FAILED:
2300
 
      protocol->store(STRING_WITH_LEN("status"));
2301
 
      protocol->store(STRING_WITH_LEN("Operation failed"));
 
2296
      session->client->store(STRING_WITH_LEN("status"));
 
2297
      session->client->store(STRING_WITH_LEN("Operation failed"));
2302
2298
      break;
2303
2299
 
2304
2300
    case HA_ADMIN_REJECT:
2305
 
      protocol->store(STRING_WITH_LEN("status"));
2306
 
      protocol->store(STRING_WITH_LEN("Operation need committed state"));
 
2301
      session->client->store(STRING_WITH_LEN("status"));
 
2302
      session->client->store(STRING_WITH_LEN("Operation need committed state"));
2307
2303
      open_for_modify= false;
2308
2304
      break;
2309
2305
 
2310
2306
    case HA_ADMIN_ALREADY_DONE:
2311
 
      protocol->store(STRING_WITH_LEN("status"));
2312
 
      protocol->store(STRING_WITH_LEN("Table is already up to date"));
 
2307
      session->client->store(STRING_WITH_LEN("status"));
 
2308
      session->client->store(STRING_WITH_LEN("Table is already up to date"));
2313
2309
      break;
2314
2310
 
2315
2311
    case HA_ADMIN_CORRUPT:
2316
 
      protocol->store(STRING_WITH_LEN("error"));
2317
 
      protocol->store(STRING_WITH_LEN("Corrupt"));
 
2312
      session->client->store(STRING_WITH_LEN("error"));
 
2313
      session->client->store(STRING_WITH_LEN("Corrupt"));
2318
2314
      fatal_error=1;
2319
2315
      break;
2320
2316
 
2321
2317
    case HA_ADMIN_INVALID:
2322
 
      protocol->store(STRING_WITH_LEN("error"));
2323
 
      protocol->store(STRING_WITH_LEN("Invalid argument"));
 
2318
      session->client->store(STRING_WITH_LEN("error"));
 
2319
      session->client->store(STRING_WITH_LEN("Invalid argument"));
2324
2320
      break;
2325
2321
 
2326
2322
    case HA_ADMIN_TRY_ALTER:
2358
2354
        if (session->is_error())
2359
2355
        {
2360
2356
          const char *err_msg= session->main_da.message();
2361
 
          if (!session->protocol->isConnected())
2362
 
          {
2363
 
            errmsg_printf(ERRMSG_LVL_ERROR, "%s", err_msg);
2364
 
          }
2365
 
          else
2366
 
          {
2367
 
            /* Hijack the row already in-progress. */
2368
 
            protocol->store(STRING_WITH_LEN("error"));
2369
 
            protocol->store(err_msg);
2370
 
            (void)protocol->write();
2371
 
            /* Start off another row for HA_ADMIN_FAILED */
2372
 
            protocol->prepareForResend();
2373
 
            protocol->store(table_name);
2374
 
            protocol->store(operator_name);
2375
 
          }
 
2357
          /* Hijack the row already in-progress. */
 
2358
          session->client->store(STRING_WITH_LEN("error"));
 
2359
          session->client->store(err_msg);
 
2360
          (void)session->client->flush();
 
2361
          /* Start off another row for HA_ADMIN_FAILED */
 
2362
          session->client->store(table_name);
 
2363
          session->client->store(operator_name);
2376
2364
          session->clear_error();
2377
2365
        }
2378
2366
      }
2387
2375
      char buf[ERRMSGSIZE];
2388
2376
      uint32_t length;
2389
2377
 
2390
 
      protocol->store(STRING_WITH_LEN("error"));
 
2378
      session->client->store(STRING_WITH_LEN("error"));
2391
2379
      length=snprintf(buf, ERRMSGSIZE, ER(ER_TABLE_NEEDS_UPGRADE), table->table_name);
2392
 
      protocol->store(buf, length);
 
2380
      session->client->store(buf, length);
2393
2381
      fatal_error=1;
2394
2382
      break;
2395
2383
    }
2400
2388
        uint32_t length=snprintf(buf, ERRMSGSIZE,
2401
2389
                             _("Unknown - internal error %d during operation"),
2402
2390
                             result_code);
2403
 
        protocol->store(STRING_WITH_LEN("error"));
2404
 
        protocol->store(buf, length);
 
2391
        session->client->store(STRING_WITH_LEN("error"));
 
2392
        session->client->store(buf, length);
2405
2393
        fatal_error=1;
2406
2394
        break;
2407
2395
      }
2427
2415
    session->endTransaction(COMMIT);
2428
2416
    session->close_thread_tables();
2429
2417
    table->table=0;                             // For query cache
2430
 
    if (protocol->write())
 
2418
    if (session->client->flush())
2431
2419
      goto err;
2432
2420
  }
2433
2421
 
2740
2728
  TableList *table;
2741
2729
  List<Item> field_list;
2742
2730
  Item *item;
2743
 
  plugin::Protocol *protocol= session->protocol;
2744
2731
 
2745
2732
  field_list.push_back(item = new Item_empty_string("Table", NAME_LEN*2));
2746
2733
  item->maybe_null= 1;
2747
2734
  field_list.push_back(item= new Item_int("Checksum", (int64_t) 1,
2748
2735
                                          MY_INT64_NUM_DECIMAL_DIGITS));
2749
2736
  item->maybe_null= 1;
2750
 
  if (protocol->sendFields(&field_list))
 
2737
  if (session->client->sendFields(&field_list))
2751
2738
    return true;
2752
2739
 
2753
2740
  /* Open one table after the other to keep lock time as short as possible. */
2761
2748
    t= table->table= session->openTableLock(table, TL_READ);
2762
2749
    session->clear_error();                     // these errors shouldn't get client
2763
2750
 
2764
 
    protocol->prepareForResend();
2765
 
    protocol->store(table_name);
 
2751
    session->client->store(table_name);
2766
2752
 
2767
2753
    if (!t)
2768
2754
    {
2769
2755
      /* Table didn't exist */
2770
 
      protocol->store();
 
2756
      session->client->store();
2771
2757
      session->clear_error();
2772
2758
    }
2773
2759
    else
2774
2760
    {
2775
2761
      if (t->file->ha_table_flags() & HA_HAS_CHECKSUM &&
2776
2762
          !(check_opt->flags & T_EXTEND))
2777
 
        protocol->store((uint64_t)t->file->checksum());
 
2763
        session->client->store((uint64_t)t->file->checksum());
2778
2764
      else if (!(t->file->ha_table_flags() & HA_HAS_CHECKSUM) &&
2779
2765
               (check_opt->flags & T_QUICK))
2780
 
        protocol->store();
 
2766
        session->client->store();
2781
2767
      else
2782
2768
      {
2783
2769
        /* calculating table's checksum */
2787
2773
        t->use_all_columns();
2788
2774
 
2789
2775
        if (t->file->ha_rnd_init(1))
2790
 
          protocol->store();
 
2776
          session->client->store();
2791
2777
        else
2792
2778
        {
2793
2779
          for (;;)
2827
2813
 
2828
2814
            crc+= row_crc;
2829
2815
          }
2830
 
          protocol->store((uint64_t)crc);
 
2816
          session->client->store((uint64_t)crc);
2831
2817
          t->file->ha_rnd_end();
2832
2818
        }
2833
2819
      }
2835
2821
      session->close_thread_tables();
2836
2822
      table->table=0;                           // For query cache
2837
2823
    }
2838
 
    if (protocol->write())
 
2824
    if (session->client->flush())
2839
2825
      goto err;
2840
2826
  }
2841
2827