Beispiel #1
0
            statement &statement::bind(size_t index, const sql_value &value)
            {
                if (!is_valid()) {
                    throw binding_error("statment invalid");
                }

                if (!value.apply_visitor<data_mapper::from_value, bool>(data_mapper::from_value(stmt_, index))) {
                    throw binding_error(sess_->last_error());
                }

                bound_++;

                return *this;
            }
Beispiel #2
0
            statement &statement::bind(const string &name, const sql_value &value)
            {
                if (!is_valid()) {
                    throw binding_error("statment invalid");
                }

                int index = sqlite3_bind_parameter_index(stmt_.get(), name.c_str());

                if (index <= 0) {
                    throw binding_error("No such named parameter '" + name + "'");
                }

                bind(index, value);

                return *this;
            }
Beispiel #3
0
        bind_mapping &bind_mapping::bind(const std::string &name, const sql_value &value)
        {
            if (mappings_.count(name) == 0) {
                throw binding_error("No parameter named '" + name + "' found");
            }

            auto indexes = mappings_[name];

            for (auto &index : indexes) {
                bind_value(index, value);
            }
            return *this;
        }
Beispiel #4
0
 bindable &bindable::bind_value(size_t index, const sql_value &value)
 {
     switch (value.type()) {
         case variant::NULLTYPE:
             bind(index, sql_null);
             break;
         case variant::CHAR:
         case variant::WCHAR:
         case variant::BOOL:
         case variant::NUMBER:
             if (value.size() <= sizeof(int)) {
                 bind(index, value.to_int());
             } else {
                 bind(index, value.to_llong());
             }
             break;
         case variant::UNUMBER:
             bind(index, value.to_llong());
             break;
         case variant::REAL:
             if (value.size() <= sizeof(float)) {
                 bind(index, value.to_float());
             } else {
                 bind(index, value.to_double());
             }
             break;
         case variant::STRING:
             bind(index, value.to_string());
             break;
         case variant::WSTRING:
             bind(index, value.to_wstring());
             break;
         case variant::BINARY:
             bind(index, value.to_binary());
             break;
         case variant::COMPLEX:
             if (value.is_time()) {
                 bind(index, value.to_time());
             } else {
                 throw binding_error("unknown custom type in binding");
             }
             break;
     }
     return *this;
 }
Beispiel #5
0
 sqlite3_statement &sqlite3_statement::bind(size_t index, const void *data, size_t size, void (*pFree)(void *))
 {
     if (sqlite3_bind_blob(stmt_, index, data, size, pFree) != SQLITE_OK)
         throw binding_error(db_->last_error());
     return *this;
 }
Beispiel #6
0
 sqlite3_statement &sqlite3_statement::bind(size_t index, const sql_null_t &value)
 {
     if (sqlite3_bind_null(stmt_, index) != SQLITE_OK)
         throw binding_error(db_->last_error());
     return *this;
 }
Beispiel #7
0
 sqlite3_statement &sqlite3_statement::bind(size_t index, const sql_blob &value)
 {
     if (sqlite3_bind_blob(stmt_, index, value.ptr(), value.size(), value.destructor()) != SQLITE_OK)
         throw binding_error(db_->last_error());
     return *this;
 }
Beispiel #8
0
 sqlite3_statement &sqlite3_statement::bind(size_t index, const std::string &value, int len)
 {
     if (sqlite3_bind_text(stmt_, index, value.c_str(), len, SQLITE_TRANSIENT) != SQLITE_OK)
         throw binding_error(db_->last_error());
     return *this;
 }
Beispiel #9
0
 sqlite3_statement &sqlite3_statement::bind(size_t index, double value)
 {
     if (sqlite3_bind_double(stmt_, index, value) != SQLITE_OK)
         throw binding_error(db_->last_error());
     return *this;
 }