github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/3rd_party/fflib/include/ff/sql/mod_stmt_bind.h (about) 1 /*********************************************** 2 The MIT License (MIT) 3 4 Copyright (c) 2012 Athrun Arthur <athrunarthur@gmail.com> 5 6 Permission is hereby granted, free of charge, to any person obtaining a copy 7 of this software and associated documentation files (the "Software"), to deal 8 in the Software without restriction, including without limitation the rights 9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 copies of the Software, and to permit persons to whom the Software is 11 furnished to do so, subject to the following conditions: 12 13 The above copyright notice and this permission notice shall be included in 14 all copies or substantial portions of the Software. 15 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 THE SOFTWARE. 23 *************************************************/ 24 #pragma once 25 #include "ff/sql/columns.h" 26 #include "ff/sql/common.h" 27 #include "ff/sql/rows.h" 28 #include "ff/util/type_list.h" 29 30 namespace ff { 31 namespace sql { 32 33 template <typename TT, int index> struct traverse_row_for_bind { 34 typedef typename TT::engine_type engine_type; 35 typedef typename engine_type::native_statement_type native_statement_type; 36 37 template <typename VT> 38 static auto run(engine_type *engine, native_statement_type stmt, 39 const VT &val) -> 40 typename std::enable_if<(VT::type_list::len > index), void>::type { 41 typedef typename util::get_type_at_index_in_typelist<typename VT::type_list, 42 index>::type cur_type; 43 engine->bind_to_native_statement(stmt, index + 1, 44 val.template get<cur_type>()); 45 traverse_row_for_bind<TT, index + 1>::run(engine, stmt, val); 46 } 47 48 template <typename VT> 49 static auto run(engine_type *engine, native_statement_type stmt, 50 const VT &val) -> 51 typename std::enable_if<(VT::type_list::len <= index), void>::type {} 52 }; 53 ////////////////////////// 54 template <typename TT, int index, typename TL> 55 struct traverse_row_for_bind_and_put_key_to_last { 56 typedef typename TT::engine_type engine_type; 57 typedef typename engine_type::native_statement_type native_statement_type; 58 59 template <typename VT> 60 static auto run(engine_type *engine, native_statement_type stmt, 61 const VT &val, int &next_index) -> 62 typename std::enable_if<(VT::type_list::len > index), void>::type { 63 typedef 64 typename util::get_type_at_index_in_typelist<typename VT::type_list, 65 index>::type current_type; 66 67 if (std::is_base_of<key<typename current_type::type>, 68 current_type>::value) { 69 traverse_row_for_bind_and_put_key_to_last<TT, index + 1, TL>::run( 70 engine, stmt, val, next_index); 71 engine->bind_to_native_statement(stmt, next_index + 1, 72 val.template get<current_type>()); 73 next_index++; 74 } else { 75 engine->bind_to_native_statement(stmt, next_index + 1, 76 val.template get<current_type>()); 77 next_index++; 78 traverse_row_for_bind_and_put_key_to_last<TT, index + 1, TL>::run( 79 engine, stmt, val, next_index); 80 } 81 } 82 83 template <typename VT> 84 static auto run(engine_type *engine, native_statement_type stmt, 85 const VT &val, int &next_index) -> 86 typename std::enable_if<(VT::type_list::len <= index), void>::type {} 87 }; 88 89 } // namespace sql 90 } // namespace ff