Drizzled Public API Documentation

diagnostics_area.cc
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #include <config.h>
00021 #include <drizzled/session.h>
00022 #include <drizzled/diagnostics_area.h>
00023 
00024 namespace drizzled {
00025 
00031 void Diagnostics_area::reset_diagnostics_area()
00032 {
00033   can_overwrite_status= false;
00035   m_message[0]= '\0';
00036   m_sql_errno= EE_OK;
00037   m_server_status= 0;
00038   m_affected_rows= 0;
00039   m_found_rows= 0;
00040   m_last_insert_id= 0;
00041   m_total_warn_count= 0;
00042   is_sent= false;
00044   m_status= DA_EMPTY;
00045 }
00046 
00047 const char *Diagnostics_area::message() const
00048 {
00049   assert(m_status == DA_ERROR || m_status == DA_OK);
00050   return m_message;
00051 }
00052 
00053 
00054 error_t Diagnostics_area::sql_errno() const
00055 {
00056   assert(m_status == DA_ERROR);
00057   return m_sql_errno;
00058 }
00059 
00060 uint32_t Diagnostics_area::server_status() const
00061 {
00062   assert(m_status == DA_OK || m_status == DA_EOF);
00063   return m_server_status;
00064 }
00065 
00066 ha_rows Diagnostics_area::affected_rows() const
00067 { assert(m_status == DA_OK); return m_affected_rows; }
00068 
00069 ha_rows Diagnostics_area::found_rows() const
00070 { assert(m_status == DA_OK); return m_found_rows; }
00071 
00072 uint64_t Diagnostics_area::last_insert_id() const
00073 { assert(m_status == DA_OK); return m_last_insert_id; }
00074 
00075 uint32_t Diagnostics_area::total_warn_count() const
00076 {
00077   assert(m_status == DA_OK || m_status == DA_EOF);
00078   return m_total_warn_count;
00079 }
00080 
00085 void Diagnostics_area::set_ok_status(Session *session,
00086                                      ha_rows affected_rows_arg,
00087                                      ha_rows found_rows_arg,
00088                                      uint64_t last_insert_id_arg,
00089                                      const char *message_arg)
00090 {
00091   assert(! is_set());
00092   /*
00093     In production, refuse to overwrite an error or a custom response
00094     with an OK packet.
00095   */
00096   if (is_error() || is_disabled())
00097     return;
00100   m_server_status= session->server_status;
00101   m_total_warn_count= session->total_warn_count;
00102   m_affected_rows= affected_rows_arg;
00103   m_found_rows= found_rows_arg;
00104   m_last_insert_id= last_insert_id_arg;
00105   if (message_arg)
00106     strncpy(m_message, message_arg, sizeof(m_message) - 1);
00107   else
00108     m_message[0]= '\0';
00109   m_status= DA_OK;
00110 }
00111 
00115 void Diagnostics_area::set_eof_status(Session *session)
00116 {
00119   assert(! is_set());
00120   /*
00121     In production, refuse to overwrite an error or a custom response
00122     with an EOF packet.
00123   */
00124   if (is_error() || is_disabled())
00125     return;
00126 
00127   m_server_status= session->server_status;
00128   /*
00129     If inside a stored procedure, do not return the total
00130     number of warnings, since they are not available to the client
00131     anyway.
00132   */
00133   m_total_warn_count= session->total_warn_count;
00134 
00135   m_status= DA_EOF;
00136 }
00137 
00141 void Diagnostics_area::set_error_status(error_t sql_errno_arg,
00142                                         const char *message_arg)
00143 {
00144   /*
00145     Only allowed to report error if has not yet reported a success
00146     The only exception is when we flush the message to the client,
00147     an error can happen during the flush.
00148   */
00149   assert(! is_set() || can_overwrite_status);
00150   /*
00151     In production, refuse to overwrite a custom response with an
00152     ERROR packet.
00153   */
00154   if (is_disabled())
00155     return;
00156 
00157   m_sql_errno= sql_errno_arg;
00158   strncpy(m_message, message_arg, sizeof(m_message) - 1);
00159 
00160   m_status= DA_ERROR;
00161 }
00162 
00170 void Diagnostics_area::disable_status()
00171 {
00172   assert(! is_set());
00173   m_status= DA_DISABLED;
00174 }
00175 
00176 } /* namespace drizzled */