~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
 *
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 "drizzled/global.h"
21
#include "drizzled/session.h"
22
#include "drizzled/diagnostics_area.h"
23
24
/**
25
  Clear this diagnostics area.
26
27
  Normally called at the end of a statement.
28
*/
29
void Diagnostics_area::reset_diagnostics_area()
30
{
31
  can_overwrite_status= false;
32
  /** Don't take chances in production */
33
  m_message[0]= '\0';
34
  m_sql_errno= 0;
35
  m_server_status= 0;
36
  m_affected_rows= 0;
37
  m_last_insert_id= 0;
38
  m_total_warn_count= 0;
39
  is_sent= false;
40
  /** Tiny reset in debug mode to see garbage right away */
41
  m_status= DA_EMPTY;
42
}
43
44
/**
45
  Set OK status -- ends commands that do not return a
46
  result set, e.g. INSERT/UPDATE/DELETE.
47
*/
48
void Diagnostics_area::set_ok_status(Session *session, ha_rows affected_rows_arg,
49
                                uint64_t last_insert_id_arg,
50
                                const char *message_arg)
51
{
52
  assert(! is_set());
53
  /*
54
    In production, refuse to overwrite an error or a custom response
55
    with an OK packet.
56
  */
57
  if (is_error() || is_disabled())
58
    return;
59
  /** Only allowed to report success if has not yet reported an error */
60
61
  m_server_status= session->server_status;
62
  m_total_warn_count= session->total_warn_count;
63
  m_affected_rows= affected_rows_arg;
64
  m_last_insert_id= last_insert_id_arg;
65
  if (message_arg)
66
    strncpy(m_message, message_arg, sizeof(m_message) - 1);
67
  else
68
    m_message[0]= '\0';
69
  m_status= DA_OK;
70
}
71
72
/**
73
  Set EOF status.
74
*/
75
void Diagnostics_area::set_eof_status(Session *session)
76
{
77
  /** Only allowed to report eof if has not yet reported an error */
78
79
  assert(! is_set());
80
  /*
81
    In production, refuse to overwrite an error or a custom response
82
    with an EOF packet.
83
  */
84
  if (is_error() || is_disabled())
85
    return;
86
87
  m_server_status= session->server_status;
88
  /*
89
    If inside a stored procedure, do not return the total
90
    number of warnings, since they are not available to the client
91
    anyway.
92
  */
93
  m_total_warn_count= session->total_warn_count;
94
95
  m_status= DA_EOF;
96
}
97
98
/**
99
  Set ERROR status.
100
*/
101
void Diagnostics_area::set_error_status(Session *,
102
                                   uint32_t sql_errno_arg,
103
                                   const char *message_arg)
104
{
105
  /*
106
    Only allowed to report error if has not yet reported a success
107
    The only exception is when we flush the message to the client,
108
    an error can happen during the flush.
109
  */
110
  assert(! is_set() || can_overwrite_status);
111
  /*
112
    In production, refuse to overwrite a custom response with an
113
    ERROR packet.
114
  */
115
  if (is_disabled())
116
    return;
117
118
  m_sql_errno= sql_errno_arg;
119
  strncpy(m_message, message_arg, sizeof(m_message) - 1);
120
121
  m_status= DA_ERROR;
122
}
123
124
/**
125
  Mark the diagnostics area as 'DISABLED'.
126
127
  This is used in rare cases when the COM_ command at hand sends a response
128
  in a custom format. One example is the query cache, another is
129
  COM_STMT_PREPARE.
130
*/
131
void Diagnostics_area::disable_status()
132
{
133
  assert(! is_set());
134
  m_status= DA_DISABLED;
135
}