~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/diagnostics_area.cc

  • Committer: Brian Aker
  • Date: 2010-02-07 01:33:54 UTC
  • Revision ID: brian@gaz-20100207013354-d2pg1n68u5c09pgo
Remove giant include header to its own file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
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
{
 
26
 
 
27
/**
 
28
  Clear this diagnostics area.
 
29
 
 
30
  Normally called at the end of a statement.
 
31
*/
 
32
void Diagnostics_area::reset_diagnostics_area()
 
33
{
 
34
  can_overwrite_status= false;
 
35
  /** Don't take chances in production */
 
36
  m_message[0]= '\0';
 
37
  m_sql_errno= 0;
 
38
  m_server_status= 0;
 
39
  m_affected_rows= 0;
 
40
  m_found_rows= 0;
 
41
  m_last_insert_id= 0;
 
42
  m_total_warn_count= 0;
 
43
  is_sent= false;
 
44
  /** Tiny reset in debug mode to see garbage right away */
 
45
  m_status= DA_EMPTY;
 
46
}
 
47
 
 
48
const char *Diagnostics_area::message() const
 
49
{
 
50
  assert(m_status == DA_ERROR || m_status == DA_OK);
 
51
  return m_message;
 
52
}
 
53
 
 
54
 
 
55
uint32_t Diagnostics_area::sql_errno() const
 
56
{
 
57
  assert(m_status == DA_ERROR);
 
58
  return m_sql_errno;
 
59
}
 
60
 
 
61
uint32_t Diagnostics_area::server_status() const
 
62
{
 
63
  assert(m_status == DA_OK || m_status == DA_EOF);
 
64
  return m_server_status;
 
65
}
 
66
 
 
67
ha_rows Diagnostics_area::affected_rows() const
 
68
{ assert(m_status == DA_OK); return m_affected_rows; }
 
69
 
 
70
ha_rows Diagnostics_area::found_rows() const
 
71
{ assert(m_status == DA_OK); return m_found_rows; }
 
72
 
 
73
uint64_t Diagnostics_area::last_insert_id() const
 
74
{ assert(m_status == DA_OK); return m_last_insert_id; }
 
75
 
 
76
uint32_t Diagnostics_area::total_warn_count() const
 
77
{
 
78
  assert(m_status == DA_OK || m_status == DA_EOF);
 
79
  return m_total_warn_count;
 
80
}
 
81
 
 
82
/**
 
83
  Set OK status -- ends commands that do not return a
 
84
  result set, e.g. INSERT/UPDATE/DELETE.
 
85
*/
 
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)
 
91
{
 
92
  assert(! is_set());
 
93
  /*
 
94
    In production, refuse to overwrite an error or a custom response
 
95
    with an OK packet.
 
96
  */
 
97
  if (is_error() || is_disabled())
 
98
    return;
 
99
  /** Only allowed to report success if has not yet reported an error */
 
100
 
 
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;
 
106
  if (message_arg)
 
107
    strncpy(m_message, message_arg, sizeof(m_message) - 1);
 
108
  else
 
109
    m_message[0]= '\0';
 
110
  m_status= DA_OK;
 
111
}
 
112
 
 
113
/**
 
114
  Set EOF status.
 
115
*/
 
116
void Diagnostics_area::set_eof_status(Session *session)
 
117
{
 
118
  /** Only allowed to report eof if has not yet reported an error */
 
119
 
 
120
  assert(! is_set());
 
121
  /*
 
122
    In production, refuse to overwrite an error or a custom response
 
123
    with an EOF packet.
 
124
  */
 
125
  if (is_error() || is_disabled())
 
126
    return;
 
127
 
 
128
  m_server_status= session->server_status;
 
129
  /*
 
130
    If inside a stored procedure, do not return the total
 
131
    number of warnings, since they are not available to the client
 
132
    anyway.
 
133
  */
 
134
  m_total_warn_count= session->total_warn_count;
 
135
 
 
136
  m_status= DA_EOF;
 
137
}
 
138
 
 
139
/**
 
140
  Set ERROR status.
 
141
*/
 
142
void Diagnostics_area::set_error_status(uint32_t sql_errno_arg,
 
143
                                   const char *message_arg)
 
144
{
 
145
  /*
 
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.
 
149
  */
 
150
  assert(! is_set() || can_overwrite_status);
 
151
  /*
 
152
    In production, refuse to overwrite a custom response with an
 
153
    ERROR packet.
 
154
  */
 
155
  if (is_disabled())
 
156
    return;
 
157
 
 
158
  m_sql_errno= sql_errno_arg;
 
159
  strncpy(m_message, message_arg, sizeof(m_message) - 1);
 
160
 
 
161
  m_status= DA_ERROR;
 
162
}
 
163
 
 
164
/**
 
165
  Mark the diagnostics area as 'DISABLED'.
 
166
 
 
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
 
169
  COM_STMT_PREPARE.
 
170
*/
 
171
void Diagnostics_area::disable_status()
 
172
{
 
173
  assert(! is_set());
 
174
  m_status= DA_DISABLED;
 
175
}
 
176
 
 
177
} /* namespace drizzled */