00001 // 00002 // Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton 00003 // MySQL backend copyright (C) 2006 Pawel Aleksander Fedorynski 00004 // Distributed under the Boost Software License, Version 1.0. 00005 // (See accompanying file LICENSE_1_0.txt or copy at 00006 // http://www.boost.org/LICENSE_1_0.txt) 00007 // 00008 00009 #define SOCI_MYSQL_SOURCE 00010 #include "soci-mysql.h" 00011 #include "common.h" 00012 // 00013 #if defined(SOCI_HEADERS_BURIED) 00014 # include <soci/core/soci-platform.h> 00015 #else 00016 # include <soci-platform.h> 00017 #endif 00018 // 00019 // std 00020 #include <ciso646> 00021 #include <cassert> 00022 #include <cstring> 00023 #include <ctime> 00024 #include <string> 00025 00026 #ifdef _MSC_VER 00027 #pragma warning(disable:4355) 00028 #endif 00029 00030 using namespace soci; 00031 using namespace soci::details; 00032 using namespace soci::details::mysql; 00033 00034 00035 void mysql_standard_into_type_backend::define_by_pos( 00036 int &position, void *data, exchange_type type) 00037 { 00038 data_ = data; 00039 type_ = type; 00040 position_ = position++; 00041 } 00042 00043 void mysql_standard_into_type_backend::pre_fetch() 00044 { 00045 // nothing to do here 00046 } 00047 00048 void mysql_standard_into_type_backend::post_fetch( 00049 bool gotData, bool calledFromFetch, indicator *ind) 00050 { 00051 if (calledFromFetch == true && gotData == false) 00052 { 00053 // this is a normal end-of-rowset condition, 00054 // no need to do anything (fetch() will return false) 00055 return; 00056 } 00057 00058 if (gotData) 00059 { 00060 int pos = position_ - 1; 00061 //mysql_data_seek(statement_.result_, statement_.currentRow_); 00062 mysql_row_seek(statement_.result_, 00063 statement_.resultRowOffsets_[statement_.currentRow_]); 00064 MYSQL_ROW row = mysql_fetch_row(statement_.result_); 00065 if (row[pos] == NULL) 00066 { 00067 if (ind == NULL) 00068 { 00069 throw soci_error( 00070 "Null value fetched and no indicator defined."); 00071 } 00072 *ind = i_null; 00073 return; 00074 } 00075 else 00076 { 00077 if (ind != NULL) 00078 { 00079 *ind = i_ok; 00080 } 00081 } 00082 const char *buf = row[pos] != NULL ? row[pos] : ""; 00083 switch (type_) 00084 { 00085 case x_char: 00086 { 00087 char *dest = static_cast<char*>(data_); 00088 *dest = *buf; 00089 } 00090 break; 00091 case x_stdstring: 00092 { 00093 std::string *dest = static_cast<std::string *>(data_); 00094 unsigned long * lengths = 00095 mysql_fetch_lengths(statement_.result_); 00096 dest->assign(buf, lengths[pos]); 00097 } 00098 break; 00099 case x_short: 00100 { 00101 short *dest = static_cast<short*>(data_); 00102 parse_num(buf, *dest); 00103 } 00104 break; 00105 case x_integer: 00106 { 00107 int *dest = static_cast<int*>(data_); 00108 parse_num(buf, *dest); 00109 } 00110 break; 00111 case x_unsigned_long: 00112 { 00113 unsigned long *dest = static_cast<unsigned long *>(data_); 00114 parse_num(buf, *dest); 00115 } 00116 break; 00117 case x_long_long: 00118 { 00119 long long *dest = static_cast<long long *>(data_); 00120 parse_num(buf, *dest); 00121 } 00122 break; 00123 case x_double: 00124 { 00125 double *dest = static_cast<double*>(data_); 00126 parse_num(buf, *dest); 00127 } 00128 break; 00129 case x_stdtm: 00130 { 00131 // attempt to parse the string and convert to std::tm 00132 std::tm *dest = static_cast<std::tm *>(data_); 00133 parse_std_tm(buf, *dest); 00134 } 00135 break; 00136 default: 00137 throw soci_error("Into element used with non-supported type."); 00138 } 00139 } 00140 } 00141 00142 void mysql_standard_into_type_backend::clean_up() 00143 { 00144 // nothing to do here 00145 }
Generated on Sun Oct 3 2010 17:42:16 for EXTRAS-SOCI by Doxygen 1.7.1