Drizzled Public API Documentation

diagnostics_area.cc
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2008-2009 Sun Microsystems, Inc.
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 #include <config.h>
21 #include <drizzled/session.h>
22 #include <drizzled/diagnostics_area.h>
23 
24 namespace drizzled {
25 
32 {
33  can_overwrite_status= false;
35  m_message[0]= '\0';
36  m_sql_errno= EE_OK;
37  m_server_status= 0;
38  m_affected_rows= 0;
39  m_found_rows= 0;
42  is_sent= false;
44  m_status= DA_EMPTY;
45 }
46 
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 
54 error_t Diagnostics_area::sql_errno() const
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 
69 ha_rows Diagnostics_area::found_rows() const
70 { assert(m_status == DA_OK); return m_found_rows; }
71 
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 
86  ha_rows affected_rows_arg,
87  ha_rows found_rows_arg,
88  uint64_t last_insert_id_arg,
89  const char *message_arg)
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;
100  m_server_status= session->server_status;
101  m_total_warn_count= session->total_warn_count;
102  m_affected_rows= affected_rows_arg;
103  m_found_rows= found_rows_arg;
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 
116 {
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 
141 void Diagnostics_area::set_error_status(error_t sql_errno_arg,
142  const char *message_arg)
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 
171 {
172  assert(! is_set());
173  m_status= DA_DISABLED;
174 }
175 
176 } /* namespace drizzled */
drizzled::error_t m_sql_errno
char m_message[DRIZZLE_ERRMSG_SIZE]
void set_eof_status(Session *session)
void set_ok_status(Session *session, ha_rows affected_rows_arg, ha_rows found_rows_arg, uint64_t last_insert_id_arg, const char *message)
void set_error_status(drizzled::error_t sql_errno_arg, const char *message_arg)