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

blob.cpp

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2004-2007 Maciej Sobczak, Stephen Hutton
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 #include "soci-oracle.h"
00009 #include "error.h"
00010 //
00011 #if defined(SOCI_HEADERS_BURIED)
00012 #       include <soci/core/statement.h>
00013 #else
00014 #       include <statement.h>
00015 #endif
00016 //
00017 #include <cstring>
00018 #include <sstream>
00019 #include <cstdio>
00020 #include <ctime>
00021 #include <cctype>
00022 
00023 #ifdef _MSC_VER
00024 #pragma warning(disable:4355)
00025 #endif
00026 
00027 using namespace soci;
00028 using namespace soci::details;
00029 using namespace soci::details::oracle;
00030 
00031 oracle_blob_backend::oracle_blob_backend(oracle_session_backend &session)
00032     : session_(session)
00033 {
00034     sword res = OCIDescriptorAlloc(session.envhp_,
00035         reinterpret_cast<dvoid**>(&lobp_), OCI_DTYPE_LOB, 0, 0);
00036     if (res != OCI_SUCCESS)
00037     {
00038         throw soci_error("Cannot allocate the LOB locator");
00039     }
00040 }
00041 
00042 oracle_blob_backend::~oracle_blob_backend()
00043 {
00044     OCIDescriptorFree(lobp_, OCI_DTYPE_LOB);
00045 }
00046 
00047 std::size_t oracle_blob_backend::get_len()
00048 {
00049     ub4 len;
00050 
00051     sword res = OCILobGetLength(session_.svchp_, session_.errhp_,
00052         lobp_, &len);
00053 
00054     if (res != OCI_SUCCESS)
00055     {
00056         throw_oracle_soci_error(res, session_.errhp_);
00057     }
00058 
00059     return static_cast<std::size_t>(len);
00060 }
00061 
00062 std::size_t oracle_blob_backend::read(
00063     std::size_t offset, char *buf, std::size_t toRead)
00064 {
00065     ub4 amt = static_cast<ub4>(toRead);
00066 
00067     sword res = OCILobRead(session_.svchp_, session_.errhp_, lobp_, &amt,
00068         static_cast<ub4>(offset), reinterpret_cast<dvoid*>(buf),
00069         amt, 0, 0, 0, 0);
00070     if (res != OCI_SUCCESS)
00071     {
00072         throw_oracle_soci_error(res, session_.errhp_);
00073     }
00074 
00075     return static_cast<std::size_t>(amt);
00076 }
00077 
00078 std::size_t oracle_blob_backend::write(
00079     std::size_t offset, char const *buf, std::size_t toWrite)
00080 {
00081     ub4 amt = static_cast<ub4>(toWrite);
00082 
00083     sword res = OCILobWrite(session_.svchp_, session_.errhp_, lobp_, &amt,
00084         static_cast<ub4>(offset),
00085         reinterpret_cast<dvoid*>(const_cast<char*>(buf)),
00086         amt, OCI_ONE_PIECE, 0, 0, 0, 0);
00087     if (res != OCI_SUCCESS)
00088     {
00089         throw_oracle_soci_error(res, session_.errhp_);
00090     }
00091 
00092     return static_cast<std::size_t>(amt);
00093 }
00094 
00095 std::size_t oracle_blob_backend::append(char const *buf, std::size_t toWrite)
00096 {
00097     ub4 amt = static_cast<ub4>(toWrite);
00098 
00099     sword res = OCILobWriteAppend(session_.svchp_, session_.errhp_, lobp_,
00100         &amt, reinterpret_cast<dvoid*>(const_cast<char*>(buf)),
00101         amt, OCI_ONE_PIECE, 0, 0, 0, 0);
00102     if (res != OCI_SUCCESS)
00103     {
00104         throw_oracle_soci_error(res, session_.errhp_);
00105     }
00106 
00107     return static_cast<std::size_t>(amt);
00108 }
00109 
00110 void oracle_blob_backend::trim(std::size_t newLen)
00111 {
00112     sword res = OCILobTrim(session_.svchp_, session_.errhp_, lobp_,
00113         static_cast<ub4>(newLen));
00114     if (res != OCI_SUCCESS)
00115     {
00116         throw_oracle_soci_error(res, session_.errhp_);
00117     }
00118 }
 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