~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
 *
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 Sun Microsystems, Inc.
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
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
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
20
#pragma once
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
21
2239.1.3 by Olaf van der Spek
Refactor includes
22
#include <drizzled/base.h>
23
#include <drizzled/error_t.h>
2241.3.10 by Olaf van der Spek
Move warn_list from Session to diagnostics_area
24
#include <drizzled/sql_error.h>
25
#include <drizzled/sql_list.h>
2239.1.3 by Olaf van der Spek
Refactor includes
26
27
namespace drizzled {
28
29
class Session;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
30
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
31
/**
32
  Stores status of the currently executed statement.
33
  Cleared at the beginning of the statement, and then
34
  can hold either OK, ERROR, or EOF status.
35
  Can not be assigned twice per statement.
36
*/
37
class Diagnostics_area
38
{
39
public:
40
  enum enum_diagnostics_status
41
  {
42
    /** The area is cleared at start of a statement. */
43
    DA_EMPTY= 0,
44
    /** Set whenever one calls my_ok(). */
45
    DA_OK,
46
    /** Set whenever one calls my_eof(). */
47
    DA_EOF,
48
    /** Set whenever one calls my_error() or my_message(). */
49
    DA_ERROR,
50
    /** Set in case of a custom response, such as one from COM_STMT_PREPARE. */
51
    DA_DISABLED
52
  };
53
  /** True if status information is sent to the client. */
54
  bool is_sent;
55
  /** Set to make set_error_status after set_{ok,eof}_status possible. */
56
  bool can_overwrite_status;
57
58
  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.
59
                     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)
60
                     const char *message);
61
  void set_eof_status(Session *session);
2126.3.4 by Brian Aker
Additional error cleanup (passing error correctly to the client code).
62
  void set_error_status(drizzled::error_t sql_errno_arg, const char *message_arg);
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
63
64
  void disable_status();
65
66
  void reset_diagnostics_area();
67
68
  bool is_set() const { return m_status != DA_EMPTY; }
69
  bool is_error() const { return m_status == DA_ERROR; }
70
  bool is_eof() const { return m_status == DA_EOF; }
71
  bool is_ok() const { return m_status == DA_OK; }
72
  bool is_disabled() const { return m_status == DA_DISABLED; }
73
  enum_diagnostics_status status() const { return m_status; }
74
1022.2.29 by Monty Taylor
Fixed some no-inline warnings.
75
  const char *message() const;
2126.3.4 by Brian Aker
Additional error cleanup (passing error correctly to the client code).
76
  drizzled::error_t sql_errno() const;
1022.2.29 by Monty Taylor
Fixed some no-inline warnings.
77
  uint32_t server_status() const;
78
  ha_rows affected_rows() const;
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
79
  ha_rows found_rows() const;
1022.2.29 by Monty Taylor
Fixed some no-inline warnings.
80
  uint64_t last_insert_id() const;
81
  uint32_t total_warn_count() const;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
82
2241.3.10 by Olaf van der Spek
Move warn_list from Session to diagnostics_area
83
  List<DRIZZLE_ERROR> m_warn_list;
84
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
85
  Diagnostics_area() { reset_diagnostics_area(); }
86
87
private:
88
  /** Message buffer. Can be used by OK or ERROR status. */
89
  char m_message[DRIZZLE_ERRMSG_SIZE];
90
  /**
91
    SQL error number. One of ER_ codes from share/errmsg.txt.
92
    Set by set_error_status.
93
  */
2126.3.4 by Brian Aker
Additional error cleanup (passing error correctly to the client code).
94
  drizzled::error_t m_sql_errno;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
95
96
  /**
97
    Copied from session->server_status when the diagnostics area is assigned.
98
    We need this member as some places in the code use the following pattern:
99
    session->server_status|= ...
100
    my_eof(session);
101
    session->server_status&= ~...
102
    Assigned by OK, EOF or ERROR.
103
  */
104
  uint32_t m_server_status;
2126.3.4 by Brian Aker
Additional error cleanup (passing error correctly to the client code).
105
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
106
  /**
107
    The number of rows affected by the last statement. This is
108
    semantically close to session->row_count_func, but has a different
109
    life cycle. session->row_count_func stores the value returned by
110
    function ROW_COUNT() and is cleared only by statements that
111
    update its value, such as INSERT, UPDATE, DELETE and few others.
112
    This member is cleared at the beginning of the next statement.
113
114
    We could possibly merge the two, but life cycle of session->row_count_func
115
    can not be changed.
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
  ha_rows m_affected_rows;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
118
  /**
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
119
    This is like m_affected_rows, but contains the number of rows found, not
120
    only affected.
121
  */
122
  ha_rows m_found_rows;
123
  /**
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
124
    Similarly to the previous member, this is a replacement of
125
    session->first_successful_insert_id_in_prev_stmt, which is used
126
    to implement LAST_INSERT_ID().
127
  */
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.
128
  uint64_t m_last_insert_id;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
129
  /** 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.
130
  uint32_t m_total_warn_count;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
131
  enum_diagnostics_status m_status;
132
  /**
133
    @todo: the following Session members belong here:
2241.3.10 by Olaf van der Spek
Move warn_list from Session to diagnostics_area
134
    - warn_count,
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
135
  */
136
};
137
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
138
} /* namespace drizzled */
139