1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008-2009 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "drizzled/session.h"
22
#include "drizzled/diagnostics_area.h"
25
Clear this diagnostics area.
27
Normally called at the end of a statement.
29
void Diagnostics_area::reset_diagnostics_area()
31
can_overwrite_status= false;
32
/** Don't take chances in production */
39
m_total_warn_count= 0;
41
/** Tiny reset in debug mode to see garbage right away */
45
const char *Diagnostics_area::message() const
47
assert(m_status == DA_ERROR || m_status == DA_OK);
52
uint32_t Diagnostics_area::sql_errno() const
54
assert(m_status == DA_ERROR);
58
uint32_t Diagnostics_area::server_status() const
60
assert(m_status == DA_OK || m_status == DA_EOF);
61
return m_server_status;
64
ha_rows Diagnostics_area::affected_rows() const
65
{ assert(m_status == DA_OK); return m_affected_rows; }
67
ha_rows Diagnostics_area::found_rows() const
68
{ assert(m_status == DA_OK); return m_found_rows; }
70
uint64_t Diagnostics_area::last_insert_id() const
71
{ assert(m_status == DA_OK); return m_last_insert_id; }
73
uint32_t Diagnostics_area::total_warn_count() const
75
assert(m_status == DA_OK || m_status == DA_EOF);
76
return m_total_warn_count;
80
Set OK status -- ends commands that do not return a
81
result set, e.g. INSERT/UPDATE/DELETE.
83
void Diagnostics_area::set_ok_status(Session *session,
84
ha_rows affected_rows_arg,
85
ha_rows found_rows_arg,
86
uint64_t last_insert_id_arg,
87
const char *message_arg)
91
In production, refuse to overwrite an error or a custom response
94
if (is_error() || is_disabled())
96
/** Only allowed to report success if has not yet reported an error */
98
m_server_status= session->server_status;
99
m_total_warn_count= session->total_warn_count;
100
m_affected_rows= affected_rows_arg;
101
m_found_rows= found_rows_arg;
102
m_last_insert_id= last_insert_id_arg;
104
strncpy(m_message, message_arg, sizeof(m_message) - 1);
113
void Diagnostics_area::set_eof_status(Session *session)
115
/** Only allowed to report eof if has not yet reported an error */
119
In production, refuse to overwrite an error or a custom response
122
if (is_error() || is_disabled())
125
m_server_status= session->server_status;
127
If inside a stored procedure, do not return the total
128
number of warnings, since they are not available to the client
131
m_total_warn_count= session->total_warn_count;
139
void Diagnostics_area::set_error_status(uint32_t sql_errno_arg,
140
const char *message_arg)
143
Only allowed to report error if has not yet reported a success
144
The only exception is when we flush the message to the client,
145
an error can happen during the flush.
147
assert(! is_set() || can_overwrite_status);
149
In production, refuse to overwrite a custom response with an
155
m_sql_errno= sql_errno_arg;
156
strncpy(m_message, message_arg, sizeof(m_message) - 1);
162
Mark the diagnostics area as 'DISABLED'.
164
This is used in rare cases when the COM_ command at hand sends a response
165
in a custom format. One example is the query cache, another is
168
void Diagnostics_area::disable_status()
171
m_status= DA_DISABLED;