Binds all parameters using the values found in the arguments object. Anonymous parameter values can be directly in the arguments object or in an Array. Named parameter values can be provided in a plain Object argument. Only one plain Object argument may be provided. If an error occurs, an appropriate error is thrown. The return value is a struct indicating how many parameters were successfully bou
| 161 | // The return value is a struct indicating how many parameters were successfully bound |
| 162 | // and whether or not it tried to bind an object. |
| 163 | Result BindArgs(NODE_ARGUMENTS info, int argc, Statement* stmt) { |
| 164 | Napi::Env env = info.Env(); |
| 165 | int count = 0; |
| 166 | bool bound_object = false; |
| 167 | |
| 168 | for (int i = 0; i < argc; ++i) { |
| 169 | Napi::Value arg = info[i]; |
| 170 | |
| 171 | if (arg.IsArray()) { |
| 172 | count += BindArray(env, arg.As<Napi::Array>()); |
| 173 | if (!success) break; |
| 174 | continue; |
| 175 | } |
| 176 | |
| 177 | if (arg.IsObject() && !arg.IsBuffer()) { |
| 178 | Napi::Object obj = arg.As<Napi::Object>(); |
| 179 | if (IsPlainObject(env, obj)) { |
| 180 | if (bound_object) { |
| 181 | Fail(ThrowTypeError, env, "You cannot specify named parameters in two different objects"); |
| 182 | break; |
| 183 | } |
| 184 | bound_object = true; |
| 185 | |
| 186 | count += BindObject(env, obj, stmt); |
| 187 | if (!success) break; |
| 188 | continue; |
| 189 | } else if (env.IsExceptionPending()) { |
| 190 | Fail(NULL, env, NULL); |
| 191 | break; |
| 192 | } else if (stmt->GetBindMap(env).GetSize()) { |
| 193 | Fail(ThrowTypeError, env, "Named parameters can only be passed within plain objects"); |
| 194 | break; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | BindValue(env, arg, NextAnonIndex()); |
| 199 | if (!success) break; |
| 200 | count += 1; |
| 201 | } |
| 202 | |
| 203 | return { count, bound_object }; |
| 204 | } |
| 205 | |
| 206 | sqlite3_stmt* handle; |
| 207 | int param_count; |