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