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 { 00026 00032 void Diagnostics_area::reset_diagnostics_area() 00033 { 00034 can_overwrite_status= false; 00036 m_message[0]= '\0'; 00037 m_sql_errno= EE_OK; 00038 m_server_status= 0; 00039 m_affected_rows= 0; 00040 m_found_rows= 0; 00041 m_last_insert_id= 0; 00042 m_total_warn_count= 0; 00043 is_sent= false; 00045 m_status= DA_EMPTY; 00046 } 00047 00048 const char *Diagnostics_area::message() const 00049 { 00050 assert(m_status == DA_ERROR || m_status == DA_OK); 00051 return m_message; 00052 } 00053 00054 00055 drizzled::error_t Diagnostics_area::sql_errno() const 00056 { 00057 assert(m_status == DA_ERROR); 00058 return m_sql_errno; 00059 } 00060 00061 uint32_t Diagnostics_area::server_status() const 00062 { 00063 assert(m_status == DA_OK || m_status == DA_EOF); 00064 return m_server_status; 00065 } 00066 00067 ha_rows Diagnostics_area::affected_rows() const 00068 { assert(m_status == DA_OK); return m_affected_rows; } 00069 00070 ha_rows Diagnostics_area::found_rows() const 00071 { assert(m_status == DA_OK); return m_found_rows; } 00072 00073 uint64_t Diagnostics_area::last_insert_id() const 00074 { assert(m_status == DA_OK); return m_last_insert_id; } 00075 00076 uint32_t Diagnostics_area::total_warn_count() const 00077 { 00078 assert(m_status == DA_OK || m_status == DA_EOF); 00079 return m_total_warn_count; 00080 } 00081 00086 void Diagnostics_area::set_ok_status(Session *session, 00087 ha_rows affected_rows_arg, 00088 ha_rows found_rows_arg, 00089 uint64_t last_insert_id_arg, 00090 const char *message_arg) 00091 { 00092 assert(! is_set()); 00093 /* 00094 In production, refuse to overwrite an error or a custom response 00095 with an OK packet. 00096 */ 00097 if (is_error() || is_disabled()) 00098 return; 00101 m_server_status= session->server_status; 00102 m_total_warn_count= session->total_warn_count; 00103 m_affected_rows= affected_rows_arg; 00104 m_found_rows= found_rows_arg; 00105 m_last_insert_id= last_insert_id_arg; 00106 if (message_arg) 00107 strncpy(m_message, message_arg, sizeof(m_message) - 1); 00108 else 00109 m_message[0]= '\0'; 00110 m_status= DA_OK; 00111 } 00112 00116 void Diagnostics_area::set_eof_status(Session *session) 00117 { 00120 assert(! is_set()); 00121 /* 00122 In production, refuse to overwrite an error or a custom response 00123 with an EOF packet. 00124 */ 00125 if (is_error() || is_disabled()) 00126 return; 00127 00128 m_server_status= session->server_status; 00129 /* 00130 If inside a stored procedure, do not return the total 00131 number of warnings, since they are not available to the client 00132 anyway. 00133 */ 00134 m_total_warn_count= session->total_warn_count; 00135 00136 m_status= DA_EOF; 00137 } 00138 00142 void Diagnostics_area::set_error_status(drizzled::error_t sql_errno_arg, 00143 const char *message_arg) 00144 { 00145 /* 00146 Only allowed to report error if has not yet reported a success 00147 The only exception is when we flush the message to the client, 00148 an error can happen during the flush. 00149 */ 00150 assert(! is_set() || can_overwrite_status); 00151 /* 00152 In production, refuse to overwrite a custom response with an 00153 ERROR packet. 00154 */ 00155 if (is_disabled()) 00156 return; 00157 00158 m_sql_errno= sql_errno_arg; 00159 strncpy(m_message, message_arg, sizeof(m_message) - 1); 00160 00161 m_status= DA_ERROR; 00162 } 00163 00171 void Diagnostics_area::disable_status() 00172 { 00173 assert(! is_set()); 00174 m_status= DA_DISABLED; 00175 } 00176 00177 } /* namespace drizzled */