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"
28
Clear this diagnostics area.
30
Normally called at the end of a statement.
32
void Diagnostics_area::reset_diagnostics_area()
34
can_overwrite_status= false;
35
/** Don't take chances in production */
42
m_total_warn_count= 0;
44
/** Tiny reset in debug mode to see garbage right away */
48
const char *Diagnostics_area::message() const
50
assert(m_status == DA_ERROR || m_status == DA_OK);
55
uint32_t Diagnostics_area::sql_errno() const
57
assert(m_status == DA_ERROR);
61
uint32_t Diagnostics_area::server_status() const
63
assert(m_status == DA_OK || m_status == DA_EOF);
64
return m_server_status;
67
ha_rows Diagnostics_area::affected_rows() const
68
{ assert(m_status == DA_OK); return m_affected_rows; }
70
ha_rows Diagnostics_area::found_rows() const
71
{ assert(m_status == DA_OK); return m_found_rows; }
73
uint64_t Diagnostics_area::last_insert_id() const
74
{ assert(m_status == DA_OK); return m_last_insert_id; }
76
uint32_t Diagnostics_area::total_warn_count() const
78
assert(m_status == DA_OK || m_status == DA_EOF);
79
return m_total_warn_count;
83
Set OK status -- ends commands that do not return a
84
result set, e.g. INSERT/UPDATE/DELETE.
86
void Diagnostics_area::set_ok_status(Session *session,
87
ha_rows affected_rows_arg,
88
ha_rows found_rows_arg,
89
uint64_t last_insert_id_arg,
90
const char *message_arg)
94
In production, refuse to overwrite an error or a custom response
97
if (is_error() || is_disabled())
99
/** Only allowed to report success if has not yet reported an error */
101
m_server_status= session->server_status;
102
m_total_warn_count= session->total_warn_count;
103
m_affected_rows= affected_rows_arg;
104
m_found_rows= found_rows_arg;
105
m_last_insert_id= last_insert_id_arg;
107
strncpy(m_message, message_arg, sizeof(m_message) - 1);
116
void Diagnostics_area::set_eof_status(Session *session)
118
/** Only allowed to report eof if has not yet reported an error */
122
In production, refuse to overwrite an error or a custom response
125
if (is_error() || is_disabled())
128
m_server_status= session->server_status;
130
If inside a stored procedure, do not return the total
131
number of warnings, since they are not available to the client
134
m_total_warn_count= session->total_warn_count;
142
void Diagnostics_area::set_error_status(uint32_t sql_errno_arg,
143
const char *message_arg)
146
Only allowed to report error if has not yet reported a success
147
The only exception is when we flush the message to the client,
148
an error can happen during the flush.
150
assert(! is_set() || can_overwrite_status);
152
In production, refuse to overwrite a custom response with an
158
m_sql_errno= sql_errno_arg;
159
strncpy(m_message, message_arg, sizeof(m_message) - 1);
165
Mark the diagnostics area as 'DISABLED'.
167
This is used in rare cases when the COM_ command at hand sends a response
168
in a custom format. One example is the query cache, another is
171
void Diagnostics_area::disable_status()
174
m_status= DA_DISABLED;
177
} /* namespace drizzled */