summaryrefslogtreecommitdiff
path: root/sql/sql_class.h
diff options
context:
space:
mode:
authorunknown <kostja@bodhi.(none)>2007-12-12 18:36:10 +0300
committerunknown <kostja@bodhi.(none)>2007-12-12 18:36:10 +0300
commit2be5708a21b425ee70c2fe3bcd5631ecff3b815f (patch)
treeb28764824a85f53f79f9230601a6470ac02ddebf /sql/sql_class.h
parent8f967bf6ef1a2d0cacb99fb5da16cdd8045e0272 (diff)
parent2a0d2fef51219846e51eae8a56b2de45193edc37 (diff)
downloadmariadb-git-2be5708a21b425ee70c2fe3bcd5631ecff3b815f.tar.gz
Merge bk-internal.mysql.com:/home/bk/mysql-5.1-runtime
into bodhi.(none):/opt/local/work/mysql-5.1-12713-1 mysql-test/r/grant.result: Auto merged mysql-test/t/grant.test: Auto merged sql/opt_range.cc: Auto merged sql/sql_acl.cc: Auto merged sql/sql_base.cc: Auto merged sql/sql_class.h: Auto merged sql/sql_parse.cc: Auto merged sql/sql_select.cc: Auto merged sql/sql_table.cc: Auto merged sql/table.cc: Auto merged
Diffstat (limited to 'sql/sql_class.h')
-rw-r--r--sql/sql_class.h159
1 files changed, 153 insertions, 6 deletions
diff --git a/sql/sql_class.h b/sql/sql_class.h
index bbe6c589c97..0df6fd47dca 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -913,7 +913,6 @@ public:
uint in_sub_stmt;
bool enable_slow_log;
bool last_insert_id_used;
- my_bool no_send_ok;
SAVEPOINT *savepoints;
};
@@ -976,6 +975,123 @@ public:
/**
+ Stores status of the currently executed statement.
+ Cleared at the beginning of the statement, and then
+ can hold either OK, ERROR, or EOF status.
+ Can not be assigned twice per statement.
+*/
+
+class Diagnostics_area
+{
+public:
+ enum enum_diagnostics_status
+ {
+ /** The area is cleared at start of a statement. */
+ DA_EMPTY= 0,
+ /** Set whenever one calls send_ok(). */
+ DA_OK,
+ /** Set whenever one calls send_eof(). */
+ DA_EOF,
+ /** Set whenever one calls my_error() or my_message(). */
+ DA_ERROR,
+ /** Set in case of a custom response, such as one from COM_STMT_PREPARE. */
+ DA_DISABLED
+ };
+ /** True if status information is sent to the client. */
+ bool is_sent;
+ /** Set to make set_error_status after set_{ok,eof}_status possible. */
+ bool can_overwrite_status;
+
+ void set_ok_status(THD *thd, ha_rows affected_rows_arg,
+ ulong last_insert_id_arg,
+ const char *message);
+ void set_eof_status(THD *thd);
+ void set_error_status(THD *thd, uint sql_errno_arg, const char *message_arg);
+
+ void disable_status();
+
+ void reset_diagnostics_area();
+
+ bool is_set() const { return m_status != DA_EMPTY; }
+ bool is_error() const { return m_status == DA_ERROR; }
+ bool is_eof() const { return m_status == DA_EOF; }
+ bool is_ok() const { return m_status == DA_OK; }
+ bool is_disabled() const { return m_status == DA_DISABLED; }
+ enum_diagnostics_status status() const { return m_status; }
+
+ const char *message() const
+ { DBUG_ASSERT(m_status == DA_ERROR || m_status == DA_OK); return m_message; }
+
+ uint sql_errno() const
+ { DBUG_ASSERT(m_status == DA_ERROR); return m_sql_errno; }
+
+ uint server_status() const
+ {
+ DBUG_ASSERT(m_status == DA_OK || m_status == DA_EOF);
+ return m_server_status;
+ }
+
+ ha_rows affected_rows() const
+ { DBUG_ASSERT(m_status == DA_OK); return m_affected_rows; }
+
+ ulong last_insert_id() const
+ { DBUG_ASSERT(m_status == DA_OK); return m_last_insert_id; }
+
+ uint total_warn_count() const
+ {
+ DBUG_ASSERT(m_status == DA_OK || m_status == DA_EOF);
+ return m_total_warn_count;
+ }
+
+ Diagnostics_area() { reset_diagnostics_area(); }
+
+private:
+ /** Message buffer. Can be used by OK or ERROR status. */
+ char m_message[MYSQL_ERRMSG_SIZE];
+ /**
+ SQL error number. One of ER_ codes from share/errmsg.txt.
+ Set by set_error_status.
+ */
+ uint m_sql_errno;
+
+ /**
+ Copied from thd->server_status when the diagnostics area is assigned.
+ We need this member as some places in the code use the following pattern:
+ thd->server_status|= ...
+ send_eof(thd);
+ thd->server_status&= ~...
+ Assigned by OK, EOF or ERROR.
+ */
+ uint m_server_status;
+ /**
+ The number of rows affected by the last statement. This is
+ semantically close to thd->row_count_func, but has a different
+ life cycle. thd->row_count_func stores the value returned by
+ function ROW_COUNT() and is cleared only by statements that
+ update its value, such as INSERT, UPDATE, DELETE and few others.
+ This member is cleared at the beginning of the next statement.
+
+ We could possibly merge the two, but life cycle of thd->row_count_func
+ can not be changed.
+ */
+ ha_rows m_affected_rows;
+ /**
+ Similarly to the previous member, this is a replacement of
+ thd->first_successful_insert_id_in_prev_stmt, which is used
+ to implement LAST_INSERT_ID().
+ */
+ ulong m_last_insert_id;
+ /** The total number of warnings. */
+ uint m_total_warn_count;
+ enum_diagnostics_status m_status;
+ /**
+ @todo: the following THD members belong here:
+ - warn_list, warn_count,
+ */
+};
+
+
+/**
@class THD
For each client connection we create a separate thread with THD serving as
a thread/connection descriptor
@@ -1398,6 +1514,7 @@ public:
List <MYSQL_ERROR> warn_list;
uint warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_END];
uint total_warn_count;
+ Diagnostics_area main_da;
/*
Id of current query. Statement can be reused to execute several queries
query_id is global in context of the whole MySQL server.
@@ -1712,12 +1829,18 @@ public:
CHANGED_TABLE_LIST * changed_table_dup(const char *key, long key_length);
int send_explain_fields(select_result *result);
#ifndef EMBEDDED_LIBRARY
+ /**
+ Clear the current error, if any.
+ We do not clear is_fatal_error or is_fatal_sub_stmt_error since we
+ assume this is never called if the fatal error is set.
+ @todo: To silence an error, one should use Internal_error_handler
+ mechanism. In future this function will be removed.
+ */
inline void clear_error()
{
DBUG_ENTER("clear_error");
- net.last_error[0]= 0;
- net.last_errno= 0;
- net.report_error= 0;
+ if (main_da.is_error())
+ main_da.reset_diagnostics_area();
is_slave_error= 0;
DBUG_VOID_RETURN;
}
@@ -1726,10 +1849,14 @@ public:
void clear_error();
inline bool vio_ok() const { return true; }
#endif
+ /**
+ Mark the current error as fatal. Warning: this does not
+ set any error, it sets a property of the error, so must be
+ followed or prefixed with my_error().
+ */
inline void fatal_error()
{
is_fatal_error= 1;
- net.report_error= 1;
DBUG_PRINT("error",("Fatal error set"));
}
/**
@@ -1745,7 +1872,7 @@ public:
To raise this flag, use my_error().
*/
- inline bool is_error() const { return net.report_error; }
+ inline bool is_error() const { return main_da.is_error(); }
inline CHARSET_INFO *charset() { return variables.character_set_client; }
void update_charset();
@@ -1969,6 +2096,24 @@ private:
};
+/** A short cut for thd->main_da.set_ok_status(). */
+
+inline void
+send_ok(THD *thd, ha_rows affected_rows= 0, ulonglong id= 0,
+ const char *message= NULL)
+{
+ thd->main_da.set_ok_status(thd, affected_rows, id, message);
+}
+
+
+/** A short cut for thd->main_da.set_eof_status(). */
+
+inline void
+send_eof(THD *thd)
+{
+ thd->main_da.set_eof_status(thd);
+}
+
#define tmp_disable_binlog(A) \
{ulonglong tmp_disable_binlog__save_options= (A)->options; \
(A)->options&= ~OPTION_BIN_LOG
@@ -2506,6 +2651,7 @@ public:
void send_error(uint errcode,const char *err);
int do_deletes();
bool send_eof();
+ virtual void abort();
};
@@ -2548,6 +2694,7 @@ public:
void send_error(uint errcode,const char *err);
int do_updates (bool from_send_error);
bool send_eof();
+ virtual void abort();
};
class my_var : public Sql_alloc {