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

standard-use-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_use_type_backend::bind_by_pos(
00024     int & position, void * data, exchange_type type, bool /* readOnly */)
00025 {
00026     if (statement_.boundByName_)
00027     {
00028         throw soci_error(
00029          "Binding for use elements must be either by position or by name.");
00030     }
00031 
00032     position_ = position-1;
00033     data_ = data;
00034     type_ = type;
00035 
00036     ++position;
00037 
00038     statement_.useType_ = eStandard;
00039     statement_.uses_.push_back(static_cast<void*>(this));
00040 
00041     XSQLVAR *var = statement_.sqlda2p_->sqlvar+position_;
00042 
00043     buf_ = allocBuffer(var);
00044     var->sqldata = buf_;
00045     var->sqlind = &indISCHolder_;
00046 
00047     statement_.boundByPos_ = true;
00048 }
00049 
00050 void firebird_standard_use_type_backend::bind_by_name(
00051     std::string const & name, void * data,
00052     exchange_type type, bool /* readOnly */)
00053 {
00054     if (statement_.boundByPos_)
00055     {
00056         throw soci_error(
00057          "Binding for use elements must be either by position or by name.");
00058     }
00059 
00060     std::map <std::string, int> :: iterator idx =
00061         statement_.names_.find(name);
00062 
00063     if (idx == statement_.names_.end())
00064     {
00065         throw soci_error("Missing use element for bind by name (" + name + ")");
00066     }
00067 
00068     position_ = idx->second;
00069     data_ = data;
00070     type_ = type;
00071 
00072     statement_.useType_ = eStandard;
00073     statement_.uses_.push_back(static_cast<void*>(this));
00074 
00075     XSQLVAR *var = statement_.sqlda2p_->sqlvar+position_;
00076 
00077     buf_ = allocBuffer(var);
00078     var->sqldata = buf_;
00079     var->sqlind = &indISCHolder_;
00080 
00081     statement_.boundByName_ = true;
00082 }
00083 
00084 void firebird_standard_use_type_backend::pre_use(indicator const * ind)
00085 {
00086     if (ind)
00087     {
00088         switch (*ind)
00089         {
00090             case i_null:
00091                 indISCHolder_ = -1;
00092                 break;
00093             case i_ok:
00094                 indISCHolder_ =  0;
00095                 break;
00096             default:
00097                 throw soci_error("Unsupported indicator value.");
00098         }
00099     }
00100 }
00101 
00102 void firebird_standard_use_type_backend::exchangeData()
00103 {
00104     XSQLVAR *var = statement_.sqlda2p_->sqlvar+position_;
00105 
00106     switch (type_)
00107     {
00108         case x_char:
00109             setTextParam(static_cast<char*>(data_), 1, buf_, var);
00110             break;
00111         case x_short:
00112             to_isc<short>(data_, var);
00113             break;
00114         case x_integer:
00115             to_isc<int>(data_, var);
00116             break;
00117         case x_unsigned_long:
00118             to_isc<unsigned long>(data_, var);
00119             break;
00120         case x_long_long:
00121             to_isc<long long>(data_, var);
00122             break;
00123         case x_double:
00124             to_isc<double>(data_, var);
00125             break;
00126 
00127         case x_stdstring:
00128             {
00129                 std::string *tmp = static_cast<std::string*>(data_);
00130                 setTextParam(tmp->c_str(), tmp->size(), buf_, var);
00131             }
00132             break;
00133         case x_stdtm:
00134             tmEncode(var->sqltype,
00135                      static_cast<std::tm*>(data_), buf_);
00136             break;
00137 
00138             // cases that require special handling
00139         case x_blob:
00140             {
00141                 blob *tmp = static_cast<blob*>(data_);
00142 
00143                 firebird_blob_backend* blob =
00144                     dynamic_cast<firebird_blob_backend*>(tmp->get_backend());
00145 
00146                 if (NULL == blob)
00147                 {
00148                     throw soci_error("Can't get Firebid BLOB BackEnd");
00149                 }
00150 
00151                 blob->save();
00152                 memcpy(buf_, &blob->bid_, var->sqllen);
00153             }
00154             break;
00155         default:
00156             throw soci_error("Use element used with non-supported type.");
00157     } // switch
00158 }
00159 
00160 void firebird_standard_use_type_backend::post_use(
00161     bool /* gotData */, indicator * /* ind */)
00162 {
00163     // TODO: Is it possible to have the bound element being overwritten
00164     // by the database?
00165     // If not, then nothing to do here, please remove this comment.
00166     // If yes, then use the value of the readOnly parameter:
00167     // - true:  the given object should not be modified and the backend
00168     //          should detect if the modification was performed on the
00169     //          isolated buffer and throw an exception if the buffer was modified
00170     //          (this indicates logic error, because the user used const object
00171     //          and executed a query that attempted to modified it)
00172     // - false: the modification should be propagated to the given object.
00173     // ...
00174 }
00175 
00176 void firebird_standard_use_type_backend::clean_up()
00177 {
00178     if (buf_ != NULL)
00179     {
00180         delete [] buf_;
00181         buf_ = NULL;
00182     }
00183 }
 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