private void ClearParameters() { if (Sqlite3.sqlite3_clear_bindings(this.st) != Sqlite3.SQLITE_OK) { throw PythonSQLite.GetSqliteError(this.db, null); } }
private void BindParameter(CodeContext context, int index, object arg) { int rc; if (arg == null) { rc = Sqlite3.sqlite3_bind_null(st, index); } else if (arg is int) { rc = Sqlite3.sqlite3_bind_int(st, index, (int)arg); } else if (arg is bool) { rc = Sqlite3.sqlite3_bind_int(st, index, (bool)arg ? 1 : 0); } else if (arg is long) { rc = Sqlite3.sqlite3_bind_int64(st, index, (long)arg); } else if (arg is System.Numerics.BigInteger) { rc = Sqlite3.sqlite3_bind_int64(st, index, (long)((System.Numerics.BigInteger)arg)); } else if (arg is float) { rc = Sqlite3.sqlite3_bind_double(st, index, (float)arg); } else if (arg is double) { rc = Sqlite3.sqlite3_bind_double(st, index, (double)arg); } else if (arg is string) { rc = Sqlite3.sqlite3_bind_text(st, index, (string)arg, -1, Sqlite3.SQLITE_TRANSIENT); } else if (arg is byte[]) { rc = Sqlite3.sqlite3_bind_blob(this.st, index, (byte[])arg, -1, Sqlite3.SQLITE_TRANSIENT); } else if (arg is PythonBuffer) { //TODO: see if there is a better way to do this PythonBuffer buffer = (PythonBuffer)arg; string s = buffer[new Slice(0, null)].ToString(); byte[] bytes = PythonSQLite.Latin1.GetBytes(s); rc = Sqlite3.sqlite3_bind_blob(this.st, index, bytes, -1, Sqlite3.SQLITE_TRANSIENT); } else { throw PythonSQLite.MakeInterfaceError("Unable to bind parameter {0} - unsupported type {1}".Format(index, arg.GetType())); } if (rc != Sqlite3.SQLITE_OK) { throw PythonSQLite.MakeInterfaceError("Unable to bind parameter {0}: {1}".Format(index, Sqlite3.sqlite3_errmsg(db))); } }
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])); } }
private void BindParameter(CodeContext context, int index, object arg) { int rc; if (arg == null) { rc = Sqlite3.sqlite3_bind_null(st, index); } else if (arg is int) { rc = Sqlite3.sqlite3_bind_int(st, index, (int)arg); } else if (arg is bool) { rc = Sqlite3.sqlite3_bind_int(st, index, (bool)arg ? 1 : 0); } else if (arg is long) { rc = Sqlite3.sqlite3_bind_int64(st, index, (long)arg); } else if (arg is System.Numerics.BigInteger) { rc = Sqlite3.sqlite3_bind_int64(st, index, (long)((System.Numerics.BigInteger)arg)); } else if (arg is float) { rc = Sqlite3.sqlite3_bind_double(st, index, (float)arg); } else if (arg is double) { rc = Sqlite3.sqlite3_bind_double(st, index, (double)arg); } else if (arg is string) { rc = Sqlite3.sqlite3_bind_text(st, index, (string)arg, -1, Sqlite3.SQLITE_TRANSIENT); } else if (arg is byte[]) { rc = Sqlite3.sqlite3_bind_blob(this.st, index, (byte[])arg, -1, Sqlite3.SQLITE_TRANSIENT); } else { throw PythonSQLite.MakeInterfaceError("Unable to bind parameter {0} - unsupported type {1}".Format(index, arg.GetType())); } if (rc != Sqlite3.SQLITE_OK) { throw PythonSQLite.MakeInterfaceError("Unable to bind parameter {0}: {1}".Format(index, Sqlite3.sqlite3_errmsg(db))); } }
public Statement(PythonSQLite.Connection connection, string operation) { this.uniqueid = Guid.NewGuid(); this.db = connection.db; this.sql = operation; this.st = null; string tail = null; if(Sqlite3.sqlite3_prepare(this.db, this.sql, -1, ref this.st, ref tail) != Sqlite3.SQLITE_OK /*TODO: || too much sql */) { Sqlite3.sqlite3_finalize(st); this.st = null; throw PythonSQLite.GetSqliteError(this.db, null); } this.Tail = tail; }
public Statement(PythonSQLite.Connection connection, string operation) { this.uniqueid = Guid.NewGuid(); this.db = connection.db; this.sql = operation; this.st = null; string tail = null; if (Sqlite3.sqlite3_prepare(this.db, this.sql, -1, ref this.st, ref tail) != Sqlite3.SQLITE_OK /*TODO: || too much sql */) { Sqlite3.sqlite3_finalize(st); this.st = null; throw PythonSQLite.GetSqliteError(this.db, null); } this.Tail = tail; }
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)); } } }
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; }
public object callproc(string procname) { throw PythonSQLite.MakeNotSupportedError(); }