1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
*
* Copyright (C) 2008-2009 Sun Microsystems, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include <drizzled/session.h>
#include <drizzled/diagnostics_area.h>
namespace drizzled
{
/**
Clear this diagnostics area.
Normally called at the end of a statement.
*/
void Diagnostics_area::reset_diagnostics_area()
{
can_overwrite_status= false;
/** Don't take chances in production */
m_message[0]= '\0';
m_sql_errno= EE_OK;
m_server_status= 0;
m_affected_rows= 0;
m_found_rows= 0;
m_last_insert_id= 0;
m_total_warn_count= 0;
is_sent= false;
/** Tiny reset in debug mode to see garbage right away */
m_status= DA_EMPTY;
}
const char *Diagnostics_area::message() const
{
assert(m_status == DA_ERROR || m_status == DA_OK);
return m_message;
}
drizzled::error_t Diagnostics_area::sql_errno() const
{
assert(m_status == DA_ERROR);
return m_sql_errno;
}
uint32_t Diagnostics_area::server_status() const
{
assert(m_status == DA_OK || m_status == DA_EOF);
return m_server_status;
}
ha_rows Diagnostics_area::affected_rows() const
{ assert(m_status == DA_OK); return m_affected_rows; }
ha_rows Diagnostics_area::found_rows() const
{ assert(m_status == DA_OK); return m_found_rows; }
uint64_t Diagnostics_area::last_insert_id() const
{ assert(m_status == DA_OK); return m_last_insert_id; }
uint32_t Diagnostics_area::total_warn_count() const
{
assert(m_status == DA_OK || m_status == DA_EOF);
return m_total_warn_count;
}
/**
Set OK status -- ends commands that do not return a
result set, e.g. INSERT/UPDATE/DELETE.
*/
void Diagnostics_area::set_ok_status(Session *session,
ha_rows affected_rows_arg,
ha_rows found_rows_arg,
uint64_t last_insert_id_arg,
const char *message_arg)
{
assert(! is_set());
/*
In production, refuse to overwrite an error or a custom response
with an OK packet.
*/
if (is_error() || is_disabled())
return;
/** Only allowed to report success if has not yet reported an error */
m_server_status= session->server_status;
m_total_warn_count= session->total_warn_count;
m_affected_rows= affected_rows_arg;
m_found_rows= found_rows_arg;
m_last_insert_id= last_insert_id_arg;
if (message_arg)
strncpy(m_message, message_arg, sizeof(m_message) - 1);
else
m_message[0]= '\0';
m_status= DA_OK;
}
/**
Set EOF status.
*/
void Diagnostics_area::set_eof_status(Session *session)
{
/** Only allowed to report eof if has not yet reported an error */
assert(! is_set());
/*
In production, refuse to overwrite an error or a custom response
with an EOF packet.
*/
if (is_error() || is_disabled())
return;
m_server_status= session->server_status;
/*
If inside a stored procedure, do not return the total
number of warnings, since they are not available to the client
anyway.
*/
m_total_warn_count= session->total_warn_count;
m_status= DA_EOF;
}
/**
Set ERROR status.
*/
void Diagnostics_area::set_error_status(drizzled::error_t sql_errno_arg,
const char *message_arg)
{
/*
Only allowed to report error if has not yet reported a success
The only exception is when we flush the message to the client,
an error can happen during the flush.
*/
assert(! is_set() || can_overwrite_status);
/*
In production, refuse to overwrite a custom response with an
ERROR packet.
*/
if (is_disabled())
return;
m_sql_errno= sql_errno_arg;
strncpy(m_message, message_arg, sizeof(m_message) - 1);
m_status= DA_ERROR;
}
/**
Mark the diagnostics area as 'DISABLED'.
This is used in rare cases when the COM_ command at hand sends a response
in a custom format. One example is the query cache, another is
COM_STMT_PREPARE.
*/
void Diagnostics_area::disable_status()
{
assert(! is_set());
m_status= DA_DISABLED;
}
} /* namespace drizzled */
|