18 #include "ndb_local_connection.h"
24 #include "sql_class.h"
25 #include "sql_prepare.h"
27 Ndb_local_connection::Ndb_local_connection(THD* thd_arg):
36 m_push_warnings = (thd_arg->get_command() != COM_DAEMON);
41 should_ignore_error(
const uint* ignore_error_list, uint error)
43 DBUG_ENTER(
"should_ignore_error");
44 DBUG_PRINT(
"enter", (
"error: %u", error));
45 const uint* ignore_error = ignore_error_list;
48 DBUG_PRINT(
"info", (
"ignore_error: %u", *ignore_error));
49 if (*ignore_error == error)
53 DBUG_PRINT(
"info", (
"Don't ignore error"));
61 virtual bool should_ignore_error(
Ed_connection& con)
const = 0;
67 const uint* ignore_mysql_errors,
70 DBUG_ENTER(
"Ndb_local_connection::execute_query");
72 if (con.execute_direct(sql_text))
75 const uint last_errno = con.get_last_errno();
77 const char* last_errmsg = con.get_last_error();
79 DBUG_PRINT(
"error", (
"Query '%s' failed, error: '%d: %s'",
81 last_errno, last_errmsg));
84 assert(last_errno != ER_PARSE_ERROR ||
85 last_errno != ER_EMPTY_QUERY);
88 if (ignore_mysql_errors &&
89 should_ignore_error(ignore_mysql_errors, last_errno))
101 suppressor->should_ignore_error(con))
104 m_thd->clear_error();
111 push_warning(m_thd, Sql_condition::WARN_LEVEL_WARN,
112 last_errno, last_errmsg);
117 sql_print_error(
"NDB: Query '%s' failed, error: %d: %s",
119 last_errno, last_errmsg);
126 assert(!m_thd->is_error());
139 const uint* ignore_mysql_errors,
146 THD_TRANS save_thd_transaction_all= m_thd->transaction.all;
147 THD_TRANS save_thd_transaction_stmt= m_thd->transaction.stmt;
150 assert(!m_thd->transaction.stmt.has_modified_non_trans_table());
160 ulong save_thd_thread_id= m_thd->variables.pseudo_thread_id;
161 m_thd->variables.pseudo_thread_id = thread_id;
165 ulonglong save_thd_options= m_thd->variables.option_bits;
166 assert(
sizeof(save_thd_options) ==
sizeof(m_thd->variables.option_bits));
167 m_thd->variables.option_bits&= ~OPTION_BIN_LOG;
169 bool result = execute_query(sql_text,
174 m_thd->variables.option_bits= save_thd_options;
176 m_thd->variables.pseudo_thread_id = save_thd_thread_id;
178 m_thd->transaction.all= save_thd_transaction_all;
179 m_thd->transaction.stmt= save_thd_transaction_stmt;
180 m_thd->status_var= save_thd_status_var;
187 Ndb_local_connection::truncate_table(
const char* db,
size_t db_length,
188 const char*
table,
size_t table_length,
189 bool ignore_no_such_table)
191 DBUG_ENTER(
"Ndb_local_connection::truncate_table");
192 DBUG_PRINT(
"enter", (
"db: '%s', table: '%s'", db, table));
195 String sql_text(db_length + table_length + 100);
196 sql_text.append(STRING_WITH_LEN(
"TRUNCATE TABLE "));
197 sql_text.append(db, db_length);
198 sql_text.append(STRING_WITH_LEN(
"."));
199 sql_text.append(table, table_length);
202 uint ignore_mysql_errors[2] = {0, 0};
203 if (ignore_no_such_table)
204 ignore_mysql_errors[0] = ER_NO_SUCH_TABLE;
206 DBUG_RETURN(execute_query_iso(sql_text.lex_string(),
213 Ndb_local_connection::flush_table(
const char* db,
size_t db_length,
214 const char* table,
size_t table_length)
216 DBUG_ENTER(
"Ndb_local_connection::flush_table");
217 DBUG_PRINT(
"enter", (
"db: '%s', table: '%s'", db, table));
220 String sql_text(db_length + table_length + 100);
221 sql_text.append(STRING_WITH_LEN(
"FLUSH TABLES "));
222 sql_text.append(db, db_length);
223 sql_text.append(STRING_WITH_LEN(
"."));
224 sql_text.append(table, table_length);
226 DBUG_RETURN(execute_query_iso(sql_text.lex_string(),
233 Ndb_local_connection::delete_rows(
const char* db,
size_t db_length,
234 const char* table,
size_t table_length,
235 bool ignore_no_such_table,
238 DBUG_ENTER(
"Ndb_local_connection::truncate_table");
239 DBUG_PRINT(
"enter", (
"db: '%s', table: '%s'", db, table));
242 String sql_text(db_length + table_length + 100);
243 sql_text.append(STRING_WITH_LEN(
"DELETE FROM "));
244 sql_text.append(db, db_length);
245 sql_text.append(STRING_WITH_LEN(
"."));
246 sql_text.append(table, table_length);
247 sql_text.append(
" WHERE ");
250 va_start(args, ignore_no_such_table);
254 bool empty_where =
true;
255 while ((arg= va_arg(args,
char *)))
257 sql_text.append(arg);
264 sql_text.append(
"1=1");
267 uint ignore_mysql_errors[2] = {0, 0};
268 if (ignore_no_such_table)
269 ignore_mysql_errors[0] = ER_NO_SUCH_TABLE;
271 DBUG_RETURN(execute_query_iso(sql_text.lex_string(),
283 const uint last_errno = con.get_last_errno();
285 DBUG_ENTER(
"Create_sys_table_suppressor::should_ignore_error");
286 DBUG_PRINT(
"enter", (
"last_errno: %d, last_errmsg: '%s'",
287 last_errno, last_errmsg));
289 if (last_errno == ER_CANT_CREATE_TABLE)
300 const char* last_space = strrchr(last_errmsg,
' ');
301 DBUG_PRINT(
"info", (
"last_space: '%s'", last_space));
310 if (sscanf(last_space,
" %d)", &error) != 1)
316 DBUG_PRINT(
"info", (
"error: %d", error));
320 case HA_ERR_TABLE_EXIST:
346 case HA_ERR_NO_CONNECTION:
357 DBUG_PRINT(
"info", (
"Don't ignore error"));
364 Ndb_local_connection::create_sys_table(
const char* db,
size_t db_length,
365 const char* table,
size_t table_length,
366 bool create_if_not_exists,
367 const char* create_definitions,
368 const char* create_options)
370 DBUG_ENTER(
"Ndb_local_connection::create_table");
371 DBUG_PRINT(
"enter", (
"db: '%s', table: '%s'", db, table));
375 sql_text.append(STRING_WITH_LEN(
"CREATE TABLE "));
377 if (create_if_not_exists)
378 sql_text.append(STRING_WITH_LEN(
"IF NOT EXISTS "));
379 sql_text.append(db, db_length);
380 sql_text.append(STRING_WITH_LEN(
"."));
381 sql_text.append(table, table_length);
383 sql_text.append(STRING_WITH_LEN(
" ( "));
384 sql_text.append(create_definitions);
385 sql_text.append(STRING_WITH_LEN(
" ) "));
386 sql_text.append(create_options);
389 uint ignore_mysql_errors[2] = {ER_TABLE_EXISTS_ERROR, 0};
398 DBUG_RETURN(execute_query_iso(sql_text.lex_string(),
405 Ndb_local_connection::raw_run_query(
const char*
query,
size_t query_length,
406 const int* suppress_errors)
408 DBUG_ENTER(
"Ndb_local_connection::raw_run_query");
410 LEX_STRING sql_text = { (
char*)query, query_length };
412 DBUG_RETURN(execute_query_iso(sql_text,
413 (
const uint*)suppress_errors,