~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Eric Day
  • Date: 2009-08-06 07:14:37 UTC
  • mto: This revision was merged to the branch mainline in revision 1131.
  • Revision ID: eday@oddments.org-20090806071437-c3baqgtvsdxp1l1a
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.

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 <algorithm>
38
39
 
2181
2182
  Select_Lex *select= &session->lex->select_lex;
2182
2183
  List<Item> field_list;
2183
2184
  Item *item;
2184
 
  plugin::Protocol *protocol= session->protocol;
2185
2185
  LEX *lex= session->lex;
2186
2186
  int result_code= 0;
2187
2187
  const CHARSET_INFO * const cs= system_charset_info;
2198
2198
  item->maybe_null = 1;
2199
2199
  field_list.push_back(item = new Item_empty_string("Msg_text", 255, cs));
2200
2200
  item->maybe_null = 1;
2201
 
  if (protocol->sendFields(&field_list))
 
2201
  if (session->client->sendFields(&field_list))
2202
2202
    return true;
2203
2203
 
2204
2204
  for (table= tables; table; table= table->next_local)
2275
2275
      /* purecov: begin inspected */
2276
2276
      char buff[FN_REFLEN + DRIZZLE_ERRMSG_SIZE];
2277
2277
      uint32_t length;
2278
 
      protocol->prepareForResend();
2279
 
      protocol->store(table_name);
2280
 
      protocol->store(operator_name);
2281
 
      protocol->store(STRING_WITH_LEN("error"));
 
2278
      session->client->store(table_name);
 
2279
      session->client->store(operator_name);
 
2280
      session->client->store(STRING_WITH_LEN("error"));
2282
2281
      length= snprintf(buff, sizeof(buff), ER(ER_OPEN_AS_READONLY),
2283
2282
                       table_name);
2284
 
      protocol->store(buff, length);
 
2283
      session->client->store(buff, length);
2285
2284
      ha_autocommit_or_rollback(session, 0);
2286
2285
      session->endTransaction(COMMIT);
2287
2286
      session->close_thread_tables();
2288
2287
      lex->reset_query_tables_list(false);
2289
2288
      table->table=0;                           // For query cache
2290
 
      if (protocol->write())
 
2289
      if (session->client->flush())
2291
2290
        goto err;
2292
2291
      continue;
2293
2292
      /* purecov: end */
2313
2312
    if (table->table->s->crashed && operator_func == &handler::ha_check)
2314
2313
    {
2315
2314
      /* purecov: begin inspected */
2316
 
      protocol->prepareForResend();
2317
 
      protocol->store(table_name);
2318
 
      protocol->store(operator_name);
2319
 
      protocol->store(STRING_WITH_LEN("warning"));
2320
 
      protocol->store(STRING_WITH_LEN("Table is marked as crashed"));
2321
 
      if (protocol->write())
 
2315
      session->client->store(table_name);
 
2316
      session->client->store(operator_name);
 
2317
      session->client->store(STRING_WITH_LEN("warning"));
 
2318
      session->client->store(STRING_WITH_LEN("Table is marked as crashed"));
 
2319
      if (session->client->flush())
2322
2320
        goto err;
2323
2321
      /* purecov: end */
2324
2322
    }
2334
2332
      DRIZZLE_ERROR *err;
2335
2333
      while ((err= it++))
2336
2334
      {
2337
 
        protocol->prepareForResend();
2338
 
        protocol->store(table_name);
2339
 
        protocol->store(operator_name);
2340
 
        protocol->store(warning_level_names[err->level].str,
2341
 
                        warning_level_names[err->level].length);
2342
 
        protocol->store(err->msg);
2343
 
        if (protocol->write())
 
2335
        session->client->store(table_name);
 
2336
        session->client->store(operator_name);
 
2337
        session->client->store(warning_level_names[err->level].str,
 
2338
                               warning_level_names[err->level].length);
 
2339
        session->client->store(err->msg);
 
2340
        if (session->client->flush())
2344
2341
          goto err;
2345
2342
      }
2346
2343
      drizzle_reset_errors(session, true);
2347
2344
    }
2348
 
    protocol->prepareForResend();
2349
 
    protocol->store(table_name);
2350
 
    protocol->store(operator_name);
 
2345
    session->client->store(table_name);
 
2346
    session->client->store(operator_name);
2351
2347
 
2352
2348
send_result_message:
2353
2349
 
2357
2353
        char buf[ERRMSGSIZE+20];
2358
2354
        uint32_t length=snprintf(buf, ERRMSGSIZE,
2359
2355
                             ER(ER_CHECK_NOT_IMPLEMENTED), operator_name);
2360
 
        protocol->store(STRING_WITH_LEN("note"));
2361
 
        protocol->store(buf, length);
 
2356
        session->client->store(STRING_WITH_LEN("note"));
 
2357
        session->client->store(buf, length);
2362
2358
      }
2363
2359
      break;
2364
2360
 
2365
2361
    case HA_ADMIN_OK:
2366
 
      protocol->store(STRING_WITH_LEN("status"));
2367
 
      protocol->store(STRING_WITH_LEN("OK"));
 
2362
      session->client->store(STRING_WITH_LEN("status"));
 
2363
      session->client->store(STRING_WITH_LEN("OK"));
2368
2364
      break;
2369
2365
 
2370
2366
    case HA_ADMIN_FAILED:
2371
 
      protocol->store(STRING_WITH_LEN("status"));
2372
 
      protocol->store(STRING_WITH_LEN("Operation failed"));
 
2367
      session->client->store(STRING_WITH_LEN("status"));
 
2368
      session->client->store(STRING_WITH_LEN("Operation failed"));
2373
2369
      break;
2374
2370
 
2375
2371
    case HA_ADMIN_REJECT:
2376
 
      protocol->store(STRING_WITH_LEN("status"));
2377
 
      protocol->store(STRING_WITH_LEN("Operation need committed state"));
 
2372
      session->client->store(STRING_WITH_LEN("status"));
 
2373
      session->client->store(STRING_WITH_LEN("Operation need committed state"));
2378
2374
      open_for_modify= false;
2379
2375
      break;
2380
2376
 
2381
2377
    case HA_ADMIN_ALREADY_DONE:
2382
 
      protocol->store(STRING_WITH_LEN("status"));
2383
 
      protocol->store(STRING_WITH_LEN("Table is already up to date"));
 
2378
      session->client->store(STRING_WITH_LEN("status"));
 
2379
      session->client->store(STRING_WITH_LEN("Table is already up to date"));
2384
2380
      break;
2385
2381
 
2386
2382
    case HA_ADMIN_CORRUPT:
2387
 
      protocol->store(STRING_WITH_LEN("error"));
2388
 
      protocol->store(STRING_WITH_LEN("Corrupt"));
 
2383
      session->client->store(STRING_WITH_LEN("error"));
 
2384
      session->client->store(STRING_WITH_LEN("Corrupt"));
2389
2385
      fatal_error=1;
2390
2386
      break;
2391
2387
 
2392
2388
    case HA_ADMIN_INVALID:
2393
 
      protocol->store(STRING_WITH_LEN("error"));
2394
 
      protocol->store(STRING_WITH_LEN("Invalid argument"));
 
2389
      session->client->store(STRING_WITH_LEN("error"));
 
2390
      session->client->store(STRING_WITH_LEN("Invalid argument"));
2395
2391
      break;
2396
2392
 
2397
2393
    case HA_ADMIN_TRY_ALTER:
2429
2425
        if (session->is_error())
2430
2426
        {
2431
2427
          const char *err_msg= session->main_da.message();
2432
 
          if (!session->protocol->isConnected())
2433
 
          {
2434
 
            errmsg_printf(ERRMSG_LVL_ERROR, "%s", err_msg);
2435
 
          }
2436
 
          else
2437
 
          {
2438
 
            /* Hijack the row already in-progress. */
2439
 
            protocol->store(STRING_WITH_LEN("error"));
2440
 
            protocol->store(err_msg);
2441
 
            (void)protocol->write();
2442
 
            /* Start off another row for HA_ADMIN_FAILED */
2443
 
            protocol->prepareForResend();
2444
 
            protocol->store(table_name);
2445
 
            protocol->store(operator_name);
2446
 
          }
 
2428
          /* Hijack the row already in-progress. */
 
2429
          session->client->store(STRING_WITH_LEN("error"));
 
2430
          session->client->store(err_msg);
 
2431
          (void)session->client->flush();
 
2432
          /* Start off another row for HA_ADMIN_FAILED */
 
2433
          session->client->store(table_name);
 
2434
          session->client->store(operator_name);
2447
2435
          session->clear_error();
2448
2436
        }
2449
2437
      }
2458
2446
      char buf[ERRMSGSIZE];
2459
2447
      uint32_t length;
2460
2448
 
2461
 
      protocol->store(STRING_WITH_LEN("error"));
 
2449
      session->client->store(STRING_WITH_LEN("error"));
2462
2450
      length=snprintf(buf, ERRMSGSIZE, ER(ER_TABLE_NEEDS_UPGRADE), table->table_name);
2463
 
      protocol->store(buf, length);
 
2451
      session->client->store(buf, length);
2464
2452
      fatal_error=1;
2465
2453
      break;
2466
2454
    }
2471
2459
        uint32_t length=snprintf(buf, ERRMSGSIZE,
2472
2460
                             _("Unknown - internal error %d during operation"),
2473
2461
                             result_code);
2474
 
        protocol->store(STRING_WITH_LEN("error"));
2475
 
        protocol->store(buf, length);
 
2462
        session->client->store(STRING_WITH_LEN("error"));
 
2463
        session->client->store(buf, length);
2476
2464
        fatal_error=1;
2477
2465
        break;
2478
2466
      }
2498
2486
    session->endTransaction(COMMIT);
2499
2487
    session->close_thread_tables();
2500
2488
    table->table=0;                             // For query cache
2501
 
    if (protocol->write())
 
2489
    if (session->client->flush())
2502
2490
      goto err;
2503
2491
  }
2504
2492
 
4276
4264
  TableList *table;
4277
4265
  List<Item> field_list;
4278
4266
  Item *item;
4279
 
  plugin::Protocol *protocol= session->protocol;
4280
4267
 
4281
4268
  field_list.push_back(item = new Item_empty_string("Table", NAME_LEN*2));
4282
4269
  item->maybe_null= 1;
4283
4270
  field_list.push_back(item= new Item_int("Checksum", (int64_t) 1,
4284
4271
                                          MY_INT64_NUM_DECIMAL_DIGITS));
4285
4272
  item->maybe_null= 1;
4286
 
  if (protocol->sendFields(&field_list))
 
4273
  if (session->client->sendFields(&field_list))
4287
4274
    return true;
4288
4275
 
4289
4276
  /* Open one table after the other to keep lock time as short as possible. */
4297
4284
    t= table->table= session->open_ltable(table, TL_READ);
4298
4285
    session->clear_error();                     // these errors shouldn't get client
4299
4286
 
4300
 
    protocol->prepareForResend();
4301
 
    protocol->store(table_name);
 
4287
    session->client->store(table_name);
4302
4288
 
4303
4289
    if (!t)
4304
4290
    {
4305
4291
      /* Table didn't exist */
4306
 
      protocol->store();
 
4292
      session->client->store();
4307
4293
      session->clear_error();
4308
4294
    }
4309
4295
    else
4310
4296
    {
4311
4297
      if (t->file->ha_table_flags() & HA_HAS_CHECKSUM &&
4312
4298
          !(check_opt->flags & T_EXTEND))
4313
 
        protocol->store((uint64_t)t->file->checksum());
 
4299
        session->client->store((uint64_t)t->file->checksum());
4314
4300
      else if (!(t->file->ha_table_flags() & HA_HAS_CHECKSUM) &&
4315
4301
               (check_opt->flags & T_QUICK))
4316
 
        protocol->store();
 
4302
        session->client->store();
4317
4303
      else
4318
4304
      {
4319
4305
        /* calculating table's checksum */
4323
4309
        t->use_all_columns();
4324
4310
 
4325
4311
        if (t->file->ha_rnd_init(1))
4326
 
          protocol->store();
 
4312
          session->client->store();
4327
4313
        else
4328
4314
        {
4329
4315
          for (;;)
4363
4349
 
4364
4350
            crc+= row_crc;
4365
4351
          }
4366
 
          protocol->store((uint64_t)crc);
 
4352
          session->client->store((uint64_t)crc);
4367
4353
          t->file->ha_rnd_end();
4368
4354
        }
4369
4355
      }
4371
4357
      session->close_thread_tables();
4372
4358
      table->table=0;                           // For query cache
4373
4359
    }
4374
 
    if (protocol->write())
 
4360
    if (session->client->flush())
4375
4361
      goto err;
4376
4362
  }
4377
4363