bool bind_result_t::next_impl() { if (_handle->debug) std::cerr << "MySQL debug: Accessing next row of handle at " << _handle.get() << std::endl; auto flag = mysql_stmt_fetch(_handle->mysql_stmt); switch (flag) { case 0: case MYSQL_DATA_TRUNCATED: { bool need_to_rebind = false; for (auto& r : _handle->result_param_meta_data) { if (r.len) { if (r.bound_is_null) { *r.text_buffer = nullptr; *r.len = 0; } else { if (r.bound_len > r.bound_text_buffer.size()) { if (_handle->debug) std::cerr << "MySQL debug: Need to reallocate buffer at index " << r.index << " for handle at " << _handle.get() << std::endl; need_to_rebind = true; r.bound_text_buffer.resize(r.bound_len); MYSQL_BIND& param = _handle->result_params[r.index]; param.buffer = r.bound_text_buffer.data(); param.buffer_length = r.bound_text_buffer.size(); if (mysql_stmt_fetch_column(_handle->mysql_stmt, _handle->result_params.data() + r.index, r.index, 0)) throw sqlpp::exception(std::string("MySQL: Fetch column after reallocate failed: ") + mysql_stmt_error(_handle->mysql_stmt)); } *r.text_buffer = r.bound_text_buffer.data(); *r.len = r.bound_len; } } if (r.is_null) *r.is_null = r.bound_is_null; } if (need_to_rebind) bind_impl(); } return true; case 1: throw sqlpp::exception(std::string("MySQL: Could not fetch next result: ") + mysql_stmt_error(_handle->mysql_stmt)); case MYSQL_NO_DATA: return false; default: throw sqlpp::exception("MySQL: Unexpected return value for mysql_stmt_fetch()"); } }
void statement::bind(const string_ref& name, const bind_types_variant& val) { bind_impl(name, val); if (sm_) { bindings_ << "['" << name << "', "; dump_to_ostream vis(bindings_); val.apply_visitor(vis); bindings_ << ']'; } }
auto bind_impl( F&& function , const std::tuple<ARGS...>& args ) { return bind_impl( std::forward<F>( function ) , args , integer_sequence<tml::pack_size<ARGS...>>{} ); }