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>
37
38
#include "drizzled/statement/alter_table.h" /* for mysql_create_like_schema_frm, which will die soon */
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))
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),
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())
2222
2221
/* purecov: end */
2242
2241
if (table->table->s->crashed && operator_func == &handler::ha_check)
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())
2252
2250
/* purecov: end */
2263
2261
DRIZZLE_ERROR *err;
2264
2262
while ((err= it++))
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())
2275
2272
drizzle_reset_errors(session, true);
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);
2281
2277
send_result_message:
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);
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"));
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"));
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;
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"));
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"));
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"));
2326
2322
case HA_ADMIN_TRY_ALTER:
2358
2354
if (session->is_error())
2360
2356
const char *err_msg= session->main_da.message();
2361
if (!session->protocol->isConnected())
2363
errmsg_printf(ERRMSG_LVL_ERROR, "%s", err_msg);
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);
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();
2387
2375
char buf[ERRMSGSIZE];
2388
2376
uint32_t length;
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);
2400
2388
uint32_t length=snprintf(buf, ERRMSGSIZE,
2401
2389
_("Unknown - internal error %d during operation"),
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);
2740
2728
TableList *table;
2741
2729
List<Item> field_list;
2743
plugin::Protocol *protocol= session->protocol;
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))
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
2764
protocol->prepareForResend();
2765
protocol->store(table_name);
2751
session->client->store(table_name);
2769
2755
/* Table didn't exist */
2756
session->client->store();
2771
2757
session->clear_error();
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))
2766
session->client->store();
2783
2769
/* calculating table's checksum */