예제 #1
0
void
SOCICursorBackend::exec(const Values &params)
{
    try {
        if (!executed_ && in_params_.size())
            bound_first_ = true;
        if (!bound_first_) {
            if (executed_) {
                delete stmt_;
                stmt_ = new soci::statement(*conn_);
                stmt_->alloc();
                stmt_->prepare(sql_);
                in_params_.clear();
                in_flags_.clear();
            }
            TypeCodes types(params.size());
            for (size_t i = 0; i < params.size(); ++i)
                types[i] = params[i].get_type();
            bind_params(types);
        }
        executed_ = true;
        for (size_t i = 0; i < params.size(); ++i) {
            const Value &param = params[i];
            if (param.is_null()) {
                in_flags_[i] = soci::i_null;
                continue;
            }
            in_flags_[i] = soci::i_ok;
            switch (param_types_[i]) {
                case Value::INTEGER: {
                    int &x = *(int *)&(in_params_[i][0]);
                    x = param.as_integer();
                    break;
                }
                case Value::LONGINT: {
                    LongInt &x = *(LongInt *)&(in_params_[i][0]);
                    x = param.as_longint();
                    break;
                }
                case Value::FLOAT: {
                    double &x = *(double *)&(in_params_[i][0]);
                    x = param.as_float();
                    break;
                }
                case Value::DATETIME: {
                    std::tm &x = *(std::tm *)&(in_params_[i][0]);
                    memset(&x, 0, sizeof(x));
                    const DateTime &d = param.as_date_time();
                    x.tm_year = dt_year(d) - 1900;
                    x.tm_mon = dt_month(d) - 1;
                    x.tm_mday = dt_day(d);
                    x.tm_hour = dt_hour(d);
                    x.tm_min = dt_minute(d);
                    x.tm_sec = dt_second(d);
                    break;
                }
                default: {
                    in_params_[i] = NARROW(param.as_string());
                }
            }
        }
        stmt_->execute(!is_select_);
    }
    catch (const soci::soci_error &e) {
        throw DBError(WIDEN(e.what()));
    }
}
예제 #2
0
파일: moment.c 프로젝트: gitpan/Time-Moment
int
moment_year(const moment_t *mt) {
    return dt_year(moment_local_dt(mt));
}