public void RemoveAt (SqliteParameter param)
		{
			RemoveAt (param.ParameterName);
		}
Example #2
0
 private void AddParam(DbCommand cmd, string name, DbType type, object value)
 {
     var p1 = new SqliteParameter(name, type);
     p1.Value = value;
     cmd.Parameters.Add(p1);
 }
		public bool Contains (SqliteParameter param)
		{
			return Contains (param.ParameterName);
		}
		public int IndexOf (SqliteParameter param)
		{
			return IndexOf (param.ParameterName);
		}
		void SetParameter (string parameterName, SqliteParameter parameter)
#endif
		{
			if (this.Contains(parameterName))
				numeric_param_list[(int) named_param_hash[parameterName]] = parameter;
			else if (parameterName.Length > 1 && this.Contains(parameterName.Substring(1)))
				numeric_param_list[(int) named_param_hash[parameterName.Substring(1)]] = parameter;
			else
				throw new IndexOutOfRangeException("The specified name does not exist: " + parameterName);
		}
		public SqliteParameter Add (SqliteParameter param)
		{
			Add ((object)param);
			return param;
		}
Example #7
0
        private static void DoDeriveParameters(SqliteCommand command)
        {
            // See http://www.postgresql.org/docs/9.3/static/catalog-pg-proc.html
            command.Parameters.Clear();
            // Updated after 0.99.3 to support the optional existence of a name qualifying schema and case insensitivity when the schema ror procedure name do not contain a quote.
            // This fixed an incompatibility with SqliteCommand.CheckFunctionReturn(String ReturnType)
            // var serverVersion = command.Connector.ServerVersion;
            Version serverVersion = new Version();

            String query = null;
            string procedureName = null;
            string schemaName = null;
            string[] fullName = command.CommandText.Split('.');
            if (fullName.Length > 1 && fullName[0].Length > 0)
            {
                // proargsmodes is supported for Postgresql 8.1 and above
                if (serverVersion >= new Version(8, 1, 0))
                    query = "select proargnames, proargtypes, proallargtypes, proargmodes from pg_proc p left join pg_namespace n on p.pronamespace = n.oid where proname=:proname and n.nspname=:nspname";
                else
                    query = "select proargnames, proargtypes from pg_proc p left join pg_namespace n on p.pronamespace = n.oid where proname=:proname and n.nspname=:nspname";
                schemaName = (fullName[0].IndexOf("\"") != -1) ? fullName[0] : fullName[0].ToLower();
                procedureName = (fullName[1].IndexOf("\"") != -1) ? fullName[1] : fullName[1].ToLower();
            }
            else
            {
                // proargsmodes is supported for Postgresql 8.1 and above
                if (serverVersion >= new Version(8, 1, 0))
                    query = "select proargnames, proargtypes, proallargtypes, proargmodes from pg_proc where proname = :proname";
                else
                    query = "select proargnames, proargtypes from pg_proc where proname = :proname";
                procedureName = (fullName[0].IndexOf("\"") != -1) ? fullName[0] : fullName[0].ToLower();
            }

            using (SqliteCommand c = new SqliteCommand(query, command.Connection))
            {

                //c.Parameters.Add(new SqliteParameter("proname", NpgsqlDbType.Text));
                c.Parameters.Add(new SqliteParameter("proname", System.Data.DbType.String));
                c.Parameters[0].Value = procedureName.Replace("\"", "").Trim();
                if (fullName.Length > 1 && !String.IsNullOrEmpty(schemaName))
                {
                    //SqliteParameter prm = c.Parameters.Add(new SqliteParameter("nspname", NpgsqlDbType.Text));
                    SqliteParameter prm = c.Parameters.Add(new SqliteParameter("nspname", System.Data.DbType.String));
                    prm.Value = schemaName.Replace("\"", "").Trim();
                }

                string[] names = null;
                uint[] types = null;
                char[] modes = null;

                using (SqliteDataReader rdr = c.ExecuteReader(CommandBehavior.SingleRow | CommandBehavior.SingleResult))
                {
                    if (rdr.Read())
                    {
                        if (!rdr.IsDBNull(0))
                            names = rdr.GetValue(0) as String[];
                        if (serverVersion >= new Version("8.1.0"))
                        {
                            if (!rdr.IsDBNull(2))
                                types = rdr.GetValue(2) as uint[];
                            if (!rdr.IsDBNull(3))
                                modes = rdr.GetValue(3) as char[];
                        }
                        if (types == null)
                        {
                            if (rdr.IsDBNull(1))  // || rdr.GetFieldValue<uint[]>(1).Length == 0)
                                return;  // Parameterless function

                            System.Console.WriteLine("When ? ");

                            //types = rdr.GetFieldValue<uint[]>(1);
                        }
                    }
                    else
                        throw new InvalidOperationException(String.Format("InvalidFunctionName\n\n{0}", command.CommandText));
                }

                command.Parameters.Clear();
                for (var i = 0; i < types.Length; i++)
                {
                    var param = new SqliteParameter();

                    throw new NotImplementedException();
                    /*
                    // TODO: Fix enums, composite types
                    var npgsqlDbType = c.Connector.TypeHandlerRegistry.GetNpgsqlDbTypeFromOid(types[i]);
                    if (npgsqlDbType == NpgsqlDbType.Unknown)
                        throw new InvalidOperationException(String.Format("Invalid parameter type: {0}", types[i]));
                    param.NpgsqlDbType = npgsqlDbType;

                    if (names != null && i < names.Length)
                        param.ParameterName = ":" + names[i];
                    else
                        param.ParameterName = "parameter" + (i + 1);

                    if (modes == null) // All params are IN, or server < 8.1.0 (and only IN is supported)
                        param.Direction = ParameterDirection.Input;
                    else
                    {
                        switch (modes[i])
                        {
                            case 'i':
                                param.Direction = ParameterDirection.Input;
                                break;
                            case 'o':
                                param.Direction = ParameterDirection.Output;
                                break;
                            case 'b':
                                param.Direction = ParameterDirection.InputOutput;
                                break;
                            case 'v':
                                throw new NotImplementedException("Cannot derive function parameter of type VARIADIC");
                            case 't':
                                throw new NotImplementedException("Cannot derive function parameter of type TABLE");
                            default:
                                throw new ArgumentOutOfRangeException("proargmode", modes[i],
                                    "Unknown code in proargmodes while deriving: " + modes[i]);
                        }
                    }

                    command.Parameters.Add(param);
                     */
                }
            }
        }
		void SetParameter (int parameterIndex, SqliteParameter parameter)
#endif
		{
			if (this.Count >= parameterIndex+1)
				numeric_param_list[parameterIndex] = parameter;
			else          
				throw new IndexOutOfRangeException("The specified parameter index does not exist: " + parameterIndex.ToString());
		}
Example #9
0
        private void BindParameters3(Sqlite3.Vdbe pStmt)
        {
            if (sql_params == null)
            {
                return;
            }
            if (sql_params.Count == 0)
            {
                return;
            }

            int pcount = Sqlite3.sqlite3_bind_parameter_count(pStmt);

            for (int i = 1; i <= pcount; i++)
            {
                String name = Sqlite3.sqlite3_bind_parameter_name(pStmt, i);

                SqliteParameter param = null;
                if (name != null)
                {
                    param = sql_params[name] as SqliteParameter;
                }
                else
                {
                    param = sql_params[i - 1] as SqliteParameter;
                }

                if (param.Value == null)
                {
                    Sqlite3.sqlite3_bind_null(pStmt, i);
                    continue;
                }

                Type ptype = param.Value.GetType();
                if (ptype.IsEnum)
                {
                    ptype = Enum.GetUnderlyingType(ptype);
                }

                SqliteError err;

                if (ptype.Equals(typeof(String)))
                {
                    String s = (String)param.Value;
                    err = (SqliteError)Sqlite3.sqlite3_bind_text(pStmt, i, s, -1, null);
                }
                else if (ptype.Equals(typeof(DBNull)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_null(pStmt, i);
                }
                else if (ptype.Equals(typeof(Boolean)))
                {
                    bool b = (bool)param.Value;
                    err = (SqliteError)Sqlite3.sqlite3_bind_int(pStmt, i, b ? 1 : 0);
                }
                else if (ptype.Equals(typeof(Byte)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_int(pStmt, i, (Byte)param.Value);
                }
                else if (ptype.Equals(typeof(Char)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_int(pStmt, i, (Char)param.Value);
                }
                else if (ptype.IsEnum)
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_int(pStmt, i, (Int32)param.Value);
                }
                else if (ptype.Equals(typeof(Int16)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_int(pStmt, i, (Int16)param.Value);
                }
                else if (ptype.Equals(typeof(Int32)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_int(pStmt, i, (Int32)param.Value);
                }
                else if (ptype.Equals(typeof(SByte)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_int(pStmt, i, (SByte)param.Value);
                }
                else if (ptype.Equals(typeof(UInt16)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_int(pStmt, i, (UInt16)param.Value);
                }
                else if (ptype.Equals(typeof(DateTime)))
                {
                    DateTime dt = (DateTime)param.Value;
                    err = (SqliteError)Sqlite3.sqlite3_bind_text(pStmt, i, dt.ToString("yyyy-MM-dd  HH:mm:ss"), -1, null);
                }
                else if (ptype.Equals(typeof(Decimal)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_double(pStmt, i, Decimal.ToDouble((Decimal)param.Value));
                }
                else if (ptype.Equals(typeof(Double)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_double(pStmt, i, (Double)param.Value);
                }
                else if (ptype.Equals(typeof(Single)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_double(pStmt, i, (Single)param.Value);
                }
                else if (ptype.Equals(typeof(UInt32)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_int64(pStmt, i, (UInt32)param.Value);
                }
                else if (ptype.Equals(typeof(Int64)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_int64(pStmt, i, (Int64)param.Value);
                }
                else if (ptype.Equals(typeof(Byte[])))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_blob(pStmt, i, (byte[])param.Value, ((byte[])param.Value).Length, null);
                }
                else if (ptype.Equals(typeof(Guid)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_text(pStmt, i, param.Value.ToString(), param.Value.ToString().Length, null);
                }
                else
                {
                    throw new ApplicationException("Unkown Parameter Type");
                }
                if (err != SqliteError.OK)
                {
                    throw new ApplicationException("Sqlite error in bind " + err);
                }
            }
        }
 public void RemoveAt(SqliteParameter param)
 {
     RemoveAt(param.ParameterName);
 }
 public int IndexOf(SqliteParameter param)
 {
     return(IndexOf(param.ParameterName));
 }
 public bool Contains(SqliteParameter param)
 {
     return(Contains(param.ParameterName));
 }
 public SqliteParameter Add(SqliteParameter param)
 {
     Add((object)param);
     return(param);
 }