~drizzle-trunk/drizzle/development

934.2.17 by Jay Pipes
Forgot to add diagnostics_area.cc. thx krow. :)
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
934.2.17 by Jay Pipes
Forgot to add diagnostics_area.cc. thx krow. :)
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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
20
#include <config.h>
21
#include <drizzled/session.h>
22
#include <drizzled/diagnostics_area.h>
934.2.17 by Jay Pipes
Forgot to add diagnostics_area.cc. thx krow. :)
23
2318.6.105 by Olaf van der Spek
Use std::list for Diagnostics_area::m_warn_list
24
namespace drizzled {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
25
934.2.17 by Jay Pipes
Forgot to add diagnostics_area.cc. thx krow. :)
26
/**
27
  Clear this diagnostics area.
28
29
  Normally called at the end of a statement.
30
*/
31
void Diagnostics_area::reset_diagnostics_area()
32
{
33
  can_overwrite_status= false;
34
  /** Don't take chances in production */
35
  m_message[0]= '\0';
2126.3.4 by Brian Aker
Additional error cleanup (passing error correctly to the client code).
36
  m_sql_errno= EE_OK;
934.2.17 by Jay Pipes
Forgot to add diagnostics_area.cc. thx krow. :)
37
  m_server_status= 0;
38
  m_affected_rows= 0;
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
39
  m_found_rows= 0;
934.2.17 by Jay Pipes
Forgot to add diagnostics_area.cc. thx krow. :)
40
  m_last_insert_id= 0;
41
  m_total_warn_count= 0;
42
  is_sent= false;
43
  /** Tiny reset in debug mode to see garbage right away */
44
  m_status= DA_EMPTY;
45
}
46
1022.2.29 by Monty Taylor
Fixed some no-inline warnings.
47
const char *Diagnostics_area::message() const
48
{
49
  assert(m_status == DA_ERROR || m_status == DA_OK);
50
  return m_message;
51
}
52
53
2246.4.6 by Olaf van der Spek
Remove some unnecessary drizzled::
54
error_t Diagnostics_area::sql_errno() const
1022.2.29 by Monty Taylor
Fixed some no-inline warnings.
55
{
56
  assert(m_status == DA_ERROR);
57
  return m_sql_errno;
58
}
59
60
uint32_t Diagnostics_area::server_status() const
61
{
62
  assert(m_status == DA_OK || m_status == DA_EOF);
63
  return m_server_status;
64
}
65
66
ha_rows Diagnostics_area::affected_rows() const
67
{ assert(m_status == DA_OK); return m_affected_rows; }
68
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
69
ha_rows Diagnostics_area::found_rows() const
70
{ assert(m_status == DA_OK); return m_found_rows; }
71
1022.2.29 by Monty Taylor
Fixed some no-inline warnings.
72
uint64_t Diagnostics_area::last_insert_id() const
73
{ assert(m_status == DA_OK); return m_last_insert_id; }
74
75
uint32_t Diagnostics_area::total_warn_count() const
76
{
77
  assert(m_status == DA_OK || m_status == DA_EOF);
78
  return m_total_warn_count;
79
}
80
934.2.17 by Jay Pipes
Forgot to add diagnostics_area.cc. thx krow. :)
81
/**
82
  Set OK status -- ends commands that do not return a
83
  result set, e.g. INSERT/UPDATE/DELETE.
84
*/
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
85
void Diagnostics_area::set_ok_status(Session *session,
86
                                     ha_rows affected_rows_arg,
87
                                     ha_rows found_rows_arg,
88
                                     uint64_t last_insert_id_arg,
89
                                     const char *message_arg)
934.2.17 by Jay Pipes
Forgot to add diagnostics_area.cc. thx krow. :)
90
{
91
  assert(! is_set());
92
  /*
93
    In production, refuse to overwrite an error or a custom response
94
    with an OK packet.
95
  */
96
  if (is_error() || is_disabled())
97
    return;
98
  /** Only allowed to report success if has not yet reported an error */
99
100
  m_server_status= session->server_status;
101
  m_total_warn_count= session->total_warn_count;
102
  m_affected_rows= affected_rows_arg;
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
103
  m_found_rows= found_rows_arg;
934.2.17 by Jay Pipes
Forgot to add diagnostics_area.cc. thx krow. :)
104
  m_last_insert_id= last_insert_id_arg;
105
  if (message_arg)
106
    strncpy(m_message, message_arg, sizeof(m_message) - 1);
107
  else
108
    m_message[0]= '\0';
109
  m_status= DA_OK;
110
}
111
112
/**
113
  Set EOF status.
114
*/
115
void Diagnostics_area::set_eof_status(Session *session)
116
{
117
  /** Only allowed to report eof if has not yet reported an error */
118
119
  assert(! is_set());
120
  /*
121
    In production, refuse to overwrite an error or a custom response
122
    with an EOF packet.
123
  */
124
  if (is_error() || is_disabled())
125
    return;
126
127
  m_server_status= session->server_status;
128
  /*
129
    If inside a stored procedure, do not return the total
130
    number of warnings, since they are not available to the client
131
    anyway.
132
  */
133
  m_total_warn_count= session->total_warn_count;
134
135
  m_status= DA_EOF;
136
}
137
138
/**
139
  Set ERROR status.
140
*/
2246.4.6 by Olaf van der Spek
Remove some unnecessary drizzled::
141
void Diagnostics_area::set_error_status(error_t sql_errno_arg,
2126.3.4 by Brian Aker
Additional error cleanup (passing error correctly to the client code).
142
                                        const char *message_arg)
934.2.17 by Jay Pipes
Forgot to add diagnostics_area.cc. thx krow. :)
143
{
144
  /*
145
    Only allowed to report error if has not yet reported a success
146
    The only exception is when we flush the message to the client,
147
    an error can happen during the flush.
148
  */
149
  assert(! is_set() || can_overwrite_status);
150
  /*
151
    In production, refuse to overwrite a custom response with an
152
    ERROR packet.
153
  */
154
  if (is_disabled())
155
    return;
156
157
  m_sql_errno= sql_errno_arg;
158
  strncpy(m_message, message_arg, sizeof(m_message) - 1);
159
160
  m_status= DA_ERROR;
161
}
162
163
/**
164
  Mark the diagnostics area as 'DISABLED'.
165
166
  This is used in rare cases when the COM_ command at hand sends a response
167
  in a custom format. One example is the query cache, another is
168
  COM_STMT_PREPARE.
169
*/
170
void Diagnostics_area::disable_status()
171
{
172
  assert(! is_set());
173
  m_status= DA_DISABLED;
174
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
175
176
} /* namespace drizzled */