SOCI Logo Get SOCI at SourceForge.net. Fast, secure and Free Open Source software downloads

standard-into-type.cpp

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton, Rafal Bobrowski
00003 // Distributed under the Boost Software License, Version 1.0.
00004 // (See accompanying file LICENSE_1_0.txt or copy at
00005 // http://www.boost.org/LICENSE_1_0.txt)
00006 //
00007 
00008 #define SOCI_FIREBIRD_SOURCE
00009 #include "soci-firebird.h"
00010 #include "common.h"
00011 //
00012 #if defined(SOCI_HEADERS_BURIED)
00013 #       include <soci/core/soci.h>
00014 #else
00015 #       include <soci.h>
00016 #endif
00017 //
00018 
00019 using namespace soci;
00020 using namespace soci::details;
00021 using namespace soci::details::firebird;
00022 
00023 void firebird_standard_into_type_backend::define_by_pos(
00024     int & position, void * data, exchange_type type)
00025 {
00026     position_ = position-1;
00027     data_ = data;
00028     type_ = type;
00029 
00030     ++position;
00031 
00032     statement_.intoType_ = eStandard;
00033     statement_.intos_.push_back(static_cast<void*>(this));
00034 
00035     XSQLVAR *var = statement_.sqldap_->sqlvar+position_;
00036 
00037     buf_ = allocBuffer(var);
00038     var->sqldata = buf_;
00039     var->sqlind = &indISCHolder_;
00040 }
00041 
00042 void firebird_standard_into_type_backend::pre_fetch()
00043 {
00044     // nothing to do
00045 }
00046 
00047 void firebird_standard_into_type_backend::post_fetch(
00048     bool gotData, bool calledFromFetch, indicator * ind)
00049 {
00050     if (calledFromFetch && (gotData == false))
00051     {
00052         // this is a normal end-of-rowset condition,
00053         // no need to set anything (fetch() will return false)
00054         return;
00055     }
00056 
00057     if (gotData)
00058     {
00059         if (i_null == statement_.inds_[position_][0] && NULL == ind)
00060         {
00061             throw soci_error("Null value fetched and no indicator defined.");
00062         }
00063         else if (NULL != ind)
00064         {
00065             *ind = statement_.inds_[position_][0];
00066         }
00067     }
00068 }
00069 
00070 
00071 void firebird_standard_into_type_backend::exchangeData()
00072 {
00073     XSQLVAR *var = statement_.sqldap_->sqlvar+position_;
00074 
00075     switch (type_)
00076     {
00077             // simple cases
00078         case x_char:
00079             *reinterpret_cast<char*>(data_) = getTextParam(var)[0];
00080             break;
00081         case x_short:
00082             {
00083                 short t = from_isc<short>(var);
00084                 *reinterpret_cast<short*>(data_) = t;
00085             }
00086             break;
00087         case x_unsigned_long:
00088             {
00089                 unsigned long t = from_isc<unsigned long>(var);
00090                 *reinterpret_cast<unsigned long*>(data_) = t;
00091             }
00092             break;
00093         case x_integer:
00094             {
00095                 long long t = from_isc<long long>(var);
00096                 *reinterpret_cast<long long *>(data_) = t;
00097             }
00098             break;
00099         case x_double:
00100             {
00101                 double t = from_isc<double>(var);
00102                 *reinterpret_cast<double*>(data_) = t;
00103             }
00104             break;
00105 
00106         case x_stdstring:
00107             *(reinterpret_cast<std::string*>(data_)) = getTextParam(var);
00108             break;
00109         case x_stdtm:
00110             tmDecode(var->sqltype,
00111                      buf_, static_cast<std::tm*>(data_));
00112             break;
00113 
00114             // cases that require special handling
00115         case x_blob:
00116             {
00117                 blob *tmp = reinterpret_cast<blob*>(data_);
00118 
00119                 firebird_blob_backend *blob =
00120                     dynamic_cast<firebird_blob_backend*>(tmp->get_backend());
00121 
00122                 if (0 == blob)
00123                 {
00124                     throw soci_error("Can't get Firebid BLOB BackEnd");
00125                 }
00126 
00127                 blob->assign(*reinterpret_cast<ISC_QUAD*>(buf_));
00128             }
00129             break;
00130         default:
00131             throw soci_error("Into element used with non-supported type.");
00132     } // switch
00133 }
00134 
00135 void firebird_standard_into_type_backend::clean_up()
00136 {
00137     if (buf_ != NULL)
00138     {
00139         delete [] buf_;
00140         buf_ = NULL;
00141     }
00142 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
SourceForge Logo

Generated on Sun Oct 3 2010 17:42:16 for EXTRAS-SOCI by Doxygen 1.7.1