851
by Brian Aker
Class rewrite of Session (aka get all of the junk out) |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 Sun Microsystems
|
|
5 |
*
|
|
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.
|
|
9 |
*
|
|
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.
|
|
14 |
*
|
|
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
|
|
18 |
*/
|
|
19 |
||
20 |
||
21 |
#ifndef DRIZZLED_DIAGNOSTICS_AREA_H
|
|
22 |
#define DRIZZLED_DIAGNOSTICS_AREA_H
|
|
23 |
||
24 |
||
25 |
/**
|
|
26 |
Stores status of the currently executed statement.
|
|
27 |
Cleared at the beginning of the statement, and then
|
|
28 |
can hold either OK, ERROR, or EOF status.
|
|
29 |
Can not be assigned twice per statement.
|
|
30 |
*/
|
|
31 |
||
32 |
class Diagnostics_area |
|
33 |
{
|
|
34 |
public: |
|
35 |
enum enum_diagnostics_status |
|
36 |
{
|
|
37 |
/** The area is cleared at start of a statement. */
|
|
38 |
DA_EMPTY= 0, |
|
39 |
/** Set whenever one calls my_ok(). */
|
|
40 |
DA_OK, |
|
41 |
/** Set whenever one calls my_eof(). */
|
|
42 |
DA_EOF, |
|
43 |
/** Set whenever one calls my_error() or my_message(). */
|
|
44 |
DA_ERROR, |
|
45 |
/** Set in case of a custom response, such as one from COM_STMT_PREPARE. */
|
|
46 |
DA_DISABLED
|
|
47 |
};
|
|
48 |
/** True if status information is sent to the client. */
|
|
49 |
bool is_sent; |
|
50 |
/** Set to make set_error_status after set_{ok,eof}_status possible. */
|
|
51 |
bool can_overwrite_status; |
|
52 |
||
53 |
void set_ok_status(Session *session, ha_rows affected_rows_arg, |
|
54 |
uint64_t last_insert_id_arg, |
|
55 |
const char *message); |
|
56 |
void set_eof_status(Session *session); |
|
57 |
void set_error_status(Session *session, uint32_t sql_errno_arg, const char *message_arg); |
|
58 |
||
59 |
void disable_status(); |
|
60 |
||
61 |
void reset_diagnostics_area(); |
|
62 |
||
63 |
bool is_set() const { return m_status != DA_EMPTY; } |
|
64 |
bool is_error() const { return m_status == DA_ERROR; } |
|
65 |
bool is_eof() const { return m_status == DA_EOF; } |
|
66 |
bool is_ok() const { return m_status == DA_OK; } |
|
67 |
bool is_disabled() const { return m_status == DA_DISABLED; } |
|
68 |
enum_diagnostics_status status() const { return m_status; } |
|
69 |
||
70 |
const char *message() const |
|
71 |
{ assert(m_status == DA_ERROR || m_status == DA_OK); return m_message; } |
|
72 |
||
73 |
uint32_t sql_errno() const |
|
74 |
{ assert(m_status == DA_ERROR); return m_sql_errno; } |
|
75 |
||
76 |
uint32_t server_status() const |
|
77 |
{
|
|
78 |
assert(m_status == DA_OK || m_status == DA_EOF); |
|
79 |
return m_server_status; |
|
80 |
}
|
|
81 |
||
82 |
ha_rows affected_rows() const |
|
83 |
{ assert(m_status == DA_OK); return m_affected_rows; } |
|
84 |
||
85 |
uint64_t last_insert_id() const |
|
86 |
{ assert(m_status == DA_OK); return m_last_insert_id; } |
|
87 |
||
88 |
uint32_t total_warn_count() const |
|
89 |
{
|
|
90 |
assert(m_status == DA_OK || m_status == DA_EOF); |
|
91 |
return m_total_warn_count; |
|
92 |
}
|
|
93 |
||
94 |
Diagnostics_area() { reset_diagnostics_area(); } |
|
95 |
||
96 |
private: |
|
97 |
/** Message buffer. Can be used by OK or ERROR status. */
|
|
98 |
char m_message[DRIZZLE_ERRMSG_SIZE]; |
|
99 |
/**
|
|
100 |
SQL error number. One of ER_ codes from share/errmsg.txt.
|
|
101 |
Set by set_error_status.
|
|
102 |
*/
|
|
103 |
uint32_t m_sql_errno; |
|
104 |
||
105 |
/**
|
|
106 |
Copied from session->server_status when the diagnostics area is assigned.
|
|
107 |
We need this member as some places in the code use the following pattern:
|
|
108 |
session->server_status|= ...
|
|
109 |
my_eof(session);
|
|
110 |
session->server_status&= ~...
|
|
111 |
Assigned by OK, EOF or ERROR.
|
|
112 |
*/
|
|
113 |
uint32_t m_server_status; |
|
114 |
/**
|
|
115 |
The number of rows affected by the last statement. This is
|
|
116 |
semantically close to session->row_count_func, but has a different
|
|
117 |
life cycle. session->row_count_func stores the value returned by
|
|
118 |
function ROW_COUNT() and is cleared only by statements that
|
|
119 |
update its value, such as INSERT, UPDATE, DELETE and few others.
|
|
120 |
This member is cleared at the beginning of the next statement.
|
|
121 |
||
122 |
We could possibly merge the two, but life cycle of session->row_count_func
|
|
123 |
can not be changed.
|
|
124 |
*/
|
|
125 |
ha_rows m_affected_rows; |
|
126 |
/**
|
|
127 |
Similarly to the previous member, this is a replacement of
|
|
128 |
session->first_successful_insert_id_in_prev_stmt, which is used
|
|
129 |
to implement LAST_INSERT_ID().
|
|
130 |
*/
|
|
131 |
uint64_t m_last_insert_id; |
|
132 |
/** The total number of warnings. */
|
|
133 |
uint m_total_warn_count; |
|
134 |
enum_diagnostics_status m_status; |
|
135 |
/**
|
|
136 |
@todo: the following Session members belong here:
|
|
137 |
- warn_list, warn_count,
|
|
138 |
*/
|
|
139 |
};
|
|
140 |
||
141 |
#endif /* DRIZZLED_DIAGNOSTICS_AREA_H */ |