1、soci不支持批量orm,只支持简单类型的批量
2、statement在execute时,如果传的参数为true,会根据into和use的大小来调整语句执行次数,用于批量操作中
3、orm对于自定义类型,因为conversion_into_type继承into_type,主要是使用了values这个类,再结合into_type和use_type的特例化
into_type继承into_type,into_type的define方法中会设置语句的行
void define(statement_impl & st, int & /* position */) SOCI_OVERRIDE
{
st.set_row(&r_);
// actual row description is performed
// as part of the statement execute
}
template <>
class into_type<values> : public into_type<row>
{
public:
into_type(values & v)
: into_type<row>(v.get_row()), v_(v)
{}
into_type(values & v, indicator & ind)
: into_type<row>(v.get_row(), ind), v_(v)
{}
void clean_up() SOCI_OVERRIDE
{
v_.clean_up();
}
private:
values & v_;
SOCI_NOT_COPYABLE(into_type)
};
template <>
class use_type<values> : public use_type_base
{
public:
use_type(values & v, std::string const & /*name*/ = std::string())
: v_(v)
{}
// we ignore the possibility to have the whole values as NULL
use_type(values & v, indicator /*ind*/, std::string const & /*name*/ = std::string())
: v_(v)
{}
void bind(details::statement_impl & st, int & /*position*/) SOCI_OVERRIDE
{
v_.uppercase_column_names(st.session_.get_uppercase_column_names());
convert_to_base();
st.bind(v_);
}
std::string get_name() const SOCI_OVERRIDE
{
std::ostringstream oss;
oss << "(";
std::size_t const num_columns = v_.get_number_of_columns();
for (std::size_t n = 0; n < num_columns; ++n)
{
if (n != 0)
oss << ", ";
oss << v_.get_properties(n).get_name();
}
oss << ")";
return oss.str();
}
void dump_value(std::ostream& os) const SOCI_OVERRIDE
{
// TODO: Dump all columns.
os << "<value>";
}
void pre_exec(int /* num */) SOCI_OVERRIDE {}
void post_use(bool /*gotData*/) SOCI_OVERRIDE
{
v_.reset_get_counter();
convert_from_base();
}
void pre_use() SOCI_OVERRIDE {convert_to_base();}
void clean_up() SOCI_OVERRIDE {v_.clean_up();}
std::size_t size() const SOCI_OVERRIDE { return 1; }
// these are used only to re-dispatch to derived class
// (the derived class might be generated automatically by
// user conversions)
virtual void convert_to_base() {}
virtual void convert_from_base() {}
private:
values & v_;
SOCI_NOT_COPYABLE(use_type)
};
因为statement_impl中的rows_不为空,所以在执行execute方法时会进入下面逻辑,describe中会将列信息添加到rows_中,同时将绑定信息添加到intosForRow_中
if (row_ != NULL && alreadyDescribed_ == false)
{
describe();
define_for_row();
}
type_conversion中会根据传递的参数是否是const来确定是不是只读的,在使用use时,如果不是只读的,仍然会调用from_base
4、连接池,将连接池作为一个全局实例来管理 ,在具体的使用中来获取session,用来后直接释放。