def _set_params(self, params): self._in_use = True num_params_needed = _lib.sqlite3_bind_parameter_count(self._statement) if isinstance(params, (tuple, list)) or \ not isinstance(params, dict) and \ hasattr(params, '__getitem__'): try: num_params = len(params) except TypeError: num_params = -1 if num_params != num_params_needed: raise ProgrammingError( "Incorrect number of bindings supplied. " "The current statement uses %d, and " "there are %d supplied." % (num_params_needed, num_params)) for i in range(num_params): rc = self.__set_param(i + 1, params[i]) if rc != _lib.SQLITE_OK: raise InterfaceError("Error binding parameter %d - " "probably unsupported type." % i) elif isinstance(params, dict): for i in range(1, num_params_needed + 1): param_name = _lib.sqlite3_bind_parameter_name( self._statement, i) if not param_name: raise ProgrammingError("Binding %d has no name, but you " "supplied a dictionary (which has " "only names)." % i) param_name = _ffi.string(param_name).decode('utf-8')[1:] try: param = params[param_name] except KeyError: raise ProgrammingError("You did not supply a value for " "binding %d." % i) rc = self.__set_param(i, param) if rc != _lib.SQLITE_OK: raise InterfaceError("Error binding parameter :%s - " "probably unsupported type." % param_name) else: raise ValueError("parameters are of unsupported type")
def _set_params(self, params): self._in_use = True num_params_needed = _lib.sqlite3_bind_parameter_count(self._statement) if isinstance(params, (tuple, list)) or \ not isinstance(params, dict) and \ hasattr(params, '__getitem__'): try: num_params = len(params) except TypeError: num_params = -1 if num_params != num_params_needed: raise ProgrammingError("Incorrect number of bindings supplied. " "The current statement uses %d, and " "there are %d supplied." % (num_params_needed, num_params)) for i in range(num_params): rc = self.__set_param(i + 1, params[i]) if rc != _lib.SQLITE_OK: raise InterfaceError("Error binding parameter %d - " "probably unsupported type." % i) elif isinstance(params, dict): for i in range(1, num_params_needed + 1): param_name = _lib.sqlite3_bind_parameter_name(self._statement, i) if not param_name: raise ProgrammingError("Binding %d has no name, but you " "supplied a dictionary (which has " "only names)." % i) param_name = _ffi.string(param_name).decode('utf-8')[1:] try: param = params[param_name] except KeyError: raise ProgrammingError("You did not supply a value for " "binding %d." % i) rc = self.__set_param(i, param) if rc != _lib.SQLITE_OK: raise InterfaceError("Error binding parameter :%s - " "probably unsupported type." % param_name) else: raise ValueError("parameters are of unsupported type")