Ejemplo n.º 1
0
        private void BindParameters(CodeContext context, IList args, int num_params_needed)
        {
            if (num_params_needed != args.Count)
            {
                throw PythonSQLite.MakeProgrammingError("Incorrect number of bindings supplied.");
            }

            for (int i = 0; i < args.Count; ++i)
            {
                BindParameter(context, i + 1, maybeAdapt(context, args[i]));
            }
        }
Ejemplo n.º 2
0
        private void BindParameters(CodeContext context, IDictionary args, int num_params_needed)
        {
            for (int i = 1; i <= num_params_needed; ++i)
            {
                string binding_name = Sqlite3.sqlite3_bind_parameter_name(this.st, i);
                if (string.IsNullOrEmpty(binding_name))
                {
                    throw PythonSQLite.MakeProgrammingError("Binding {0} has no name, but you supplied a dictionary (which has only names).".Format(i));
                }

                // remove the leading colon
                binding_name = binding_name.Substring(1);

                if (args.Contains(binding_name))
                {
                    BindParameter(context, i, maybeAdapt(context, args[binding_name]));
                }
                else
                {
                    throw PythonSQLite.MakeProgrammingError("You did not supply a value for binding {0}.".Format(i));
                }
            }
        }
Ejemplo n.º 3
0
        public void BindParameters(CodeContext context, object parameters)
        {
            if (bound)
            {
                this.ClearParameters();
            }

            int num_params_needed = Sqlite3.sqlite3_bind_parameter_count(this.st);

            if (parameters == null)
            {
                if (num_params_needed > 0)
                {
                    throw PythonSQLite.MakeProgrammingError("parameters are required but not specified.");
                }
                else
                {
                    return;
                }
            }

            if (parameters is IDictionary)
            {
                BindParameters(context, (IDictionary)parameters, num_params_needed);
            }
            else if (parameters is IList)
            {
                BindParameters(context, (IList)parameters, num_params_needed);
            }
            else
            {
                throw PythonSQLite.MakeProgrammingError("unknown parameter type");
            }

            bound = true;
        }