~drizzle-trunk/drizzle/development

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
#ifndef DRIZZLED_DIAGNOSTICS_AREA_H
21
#define DRIZZLED_DIAGNOSTICS_AREA_H
22
23
/**
24
  Stores status of the currently executed statement.
25
  Cleared at the beginning of the statement, and then
26
  can hold either OK, ERROR, or EOF status.
27
  Can not be assigned twice per statement.
28
*/
29
class Diagnostics_area
30
{
31
public:
32
  enum enum_diagnostics_status
33
  {
34
    /** The area is cleared at start of a statement. */
35
    DA_EMPTY= 0,
36
    /** Set whenever one calls my_ok(). */
37
    DA_OK,
38
    /** Set whenever one calls my_eof(). */
39
    DA_EOF,
40
    /** Set whenever one calls my_error() or my_message(). */
41
    DA_ERROR,
42
    /** Set in case of a custom response, such as one from COM_STMT_PREPARE. */
43
    DA_DISABLED
44
  };
45
  /** True if status information is sent to the client. */
46
  bool is_sent;
47
  /** Set to make set_error_status after set_{ok,eof}_status possible. */
48
  bool can_overwrite_status;
49
50
  void set_ok_status(Session *session, ha_rows affected_rows_arg,
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
51
                     ha_rows found_rows_arg, uint64_t last_insert_id_arg,
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
52
                     const char *message);
53
  void set_eof_status(Session *session);
1019.1.1 by Brian Aker
Merge (also removes session from show variables).
54
  void set_error_status(uint32_t sql_errno_arg, const char *message_arg);
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
55
56
  void disable_status();
57
58
  void reset_diagnostics_area();
59
60
  bool is_set() const { return m_status != DA_EMPTY; }
61
  bool is_error() const { return m_status == DA_ERROR; }
62
  bool is_eof() const { return m_status == DA_EOF; }
63
  bool is_ok() const { return m_status == DA_OK; }
64
  bool is_disabled() const { return m_status == DA_DISABLED; }
65
  enum_diagnostics_status status() const { return m_status; }
66
1022.2.29 by Monty Taylor
Fixed some no-inline warnings.
67
  const char *message() const;
68
  uint32_t sql_errno() const;
69
  uint32_t server_status() const;
70
  ha_rows affected_rows() const;
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
71
  ha_rows found_rows() const;
1022.2.29 by Monty Taylor
Fixed some no-inline warnings.
72
  uint64_t last_insert_id() const;
73
  uint32_t total_warn_count() const;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
74
75
  Diagnostics_area() { reset_diagnostics_area(); }
76
77
private:
78
  /** Message buffer. Can be used by OK or ERROR status. */
79
  char m_message[DRIZZLE_ERRMSG_SIZE];
80
  /**
81
    SQL error number. One of ER_ codes from share/errmsg.txt.
82
    Set by set_error_status.
83
  */
84
  uint32_t m_sql_errno;
85
86
  /**
87
    Copied from session->server_status when the diagnostics area is assigned.
88
    We need this member as some places in the code use the following pattern:
89
    session->server_status|= ...
90
    my_eof(session);
91
    session->server_status&= ~...
92
    Assigned by OK, EOF or ERROR.
93
  */
94
  uint32_t m_server_status;
95
  /**
96
    The number of rows affected by the last statement. This is
97
    semantically close to session->row_count_func, but has a different
98
    life cycle. session->row_count_func stores the value returned by
99
    function ROW_COUNT() and is cleared only by statements that
100
    update its value, such as INSERT, UPDATE, DELETE and few others.
101
    This member is cleared at the beginning of the next statement.
102
103
    We could possibly merge the two, but life cycle of session->row_count_func
104
    can not be changed.
105
  */
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
106
  ha_rows m_affected_rows;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
107
  /**
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
108
    This is like m_affected_rows, but contains the number of rows found, not
109
    only affected.
110
  */
111
  ha_rows m_found_rows;
112
  /**
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
113
    Similarly to the previous member, this is a replacement of
114
    session->first_successful_insert_id_in_prev_stmt, which is used
115
    to implement LAST_INSERT_ID().
116
  */
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
117
  uint64_t m_last_insert_id;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
118
  /** The total number of warnings. */
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
119
  uint32_t m_total_warn_count;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
120
  enum_diagnostics_status m_status;
121
  /**
122
    @todo: the following Session members belong here:
123
    - warn_list, warn_count,
124
  */
125
};
126
127
#endif /* DRIZZLED_DIAGNOSTICS_AREA_H */