1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
//
// Copyright (C) 2004-2008 Maciej Sobczak, Stephen Hutton
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
//
#define SOCI_SOURCE
#include "soci/row.h"
#include "soci/type-holder.h"
#include <cstddef>
#include <sstream>
#include <string>
#include "soci-case.h"
using namespace soci;
using namespace details;
row::row()
: uppercaseColumnNames_(false)
, currentPos_(0)
{}
row::~row()
{
clean_up();
}
void row::uppercase_column_names(bool forceToUpper)
{
uppercaseColumnNames_ = forceToUpper;
}
void row::add_properties(column_properties const &cp)
{
columns_.push_back(cp);
std::string columnName;
std::string const & originalName = cp.get_name();
if (uppercaseColumnNames_)
{
columnName = string_toupper(originalName);
// rewrite the column name in the column_properties object
// as well to retain consistent views
columns_[columns_.size() - 1].set_name(columnName);
}
else
{
columnName = originalName;
}
index_[columnName] = columns_.size() - 1;
}
std::size_t row::size() const
{
return holders_.size();
}
void row::clean_up()
{
std::size_t const hsize = holders_.size();
for (std::size_t i = 0; i != hsize; ++i)
{
delete holders_[i];
delete indicators_[i];
}
columns_.clear();
holders_.clear();
indicators_.clear();
index_.clear();
}
indicator row::get_indicator(std::size_t pos) const
{
return *indicators_.at(pos);
}
indicator row::get_indicator(std::string const &name) const
{
return get_indicator(find_column(name));
}
column_properties const & row::get_properties(std::size_t pos) const
{
return columns_.at(pos);
}
column_properties const & row::get_properties(std::string const &name) const
{
return get_properties(find_column(name));
}
std::size_t row::find_column(std::string const &name) const
{
std::map<std::string, std::size_t>::const_iterator it = index_.find(name);
if (it == index_.end())
{
std::ostringstream msg;
msg << "Column '" << name << "' not found";
throw soci_error(msg.str());
}
return it->second;
}
template <>
blob row::move_as<blob>(std::size_t pos) const
{
typedef typename type_conversion<blob>::base_type base_type;
base_type & baseVal = holders_.at(pos)->get<base_type>(value_reference_tag{});
blob ret;
type_conversion<blob>::move_from_base(baseVal, *indicators_.at(pos), ret);
// Re-initialize blob object so it can be used in further queries
baseVal.initialize(ret.get_backend()->get_session_backend().make_blob_backend());
return ret;
}
|