コード例 #1
0
        /// <summary>
        /// Finds the Id for a given rolename.
        /// </summary>
        /// <param name="rolename">The name of the role to find the Id for.</param>
        /// <returns>The Id for the given role.</returns>
        private string GetRoleIdByName(string rolename)
        {
            string id = null;

            string sql = @"
                          SELECT  
                              RoleId 
                          FROM 
                              aspnet_Roles 
                          WHERE 
                              LoweredRoleName = ?
                          AND ApplicationId   = ?
                         ";

            IngresCommand cmd = new IngresCommand(sql, this.conn);

            cmd.Transaction    = this.tran;
            cmd.CommandTimeout = this.config.CommandTimeout;

            cmd.Parameters.Add("LoweredRoleName", DbType.String).Value = rolename.ToLower();
            cmd.Parameters.Add("ApplicationId", DbType.String).Value   = this.ApplicationId.ToLower();

            IngresDataReader datareader = cmd.ExecuteReader();

            if (datareader != null)
            {
                if (datareader.HasRows)
                {
                    datareader.Read();
                    id = datareader.GetString(0);
                }

                datareader.Close();
            }

            return(id);
        }
コード例 #2
0
    static void TestDbProc(string connstring, Type type)
    {
        int    recsaffected;
        string strSeq;
        string strName;

        IngresConnection conn = new IngresConnection(connstring);
        IngresCommand    cmd;

        Console.WriteLine("\nTestDbProc (using " + type.ToString()
                          + ") to database: " + conn.Database);

        conn.Open();

        cmd = new IngresCommand(
            "declare global temporary table session.tab (seq integer," +
            "tabname varchar(32), tabowner varchar(32), numpages integer)" +
            " on commit preserve rows with norecovery", conn);
        recsaffected = cmd.ExecuteNonQuery();
        Console.WriteLine("ExecuteNonQuery(\"declare gtt\") returned " +
                          recsaffected.ToString());

        cmd = new IngresCommand(
            "insert into session.tab (tabname,tabowner,numpages)" +
            " select table_name,table_owner,number_pages from iitables", conn);
        recsaffected = cmd.ExecuteNonQuery();
        Console.WriteLine("ExecuteNonQuery(\"insert into gtt\") returned " +
                          recsaffected.ToString());


        cmd = new IngresCommand(
            "{ call gttproc(gtt1 = session.tab)}", conn);
//        "{ call gttproc(session.tab)}", conn);
        cmd.CommandType = CommandType.Text;
        recsaffected    = cmd.ExecuteNonQuery();
        Console.WriteLine("ExecuteNonQuery(\"execute proc\") returned " +
                          recsaffected.ToString());

        cmd = new IngresCommand(
            "select seq,tabname from session.tab", conn);

        IngresDataReader reader = cmd.ExecuteReader();

        Console.Write(reader.GetName(0) + "\t");
        Console.Write(reader.GetName(1));
        Console.WriteLine();

        while (reader.Read())
        {
            strSeq = reader.IsDBNull(0)?
                     "<none>":reader.GetInt32(0).ToString();
            strName = reader.IsDBNull(1)?
                      "<none>":reader.GetString(1);

            Console.WriteLine(strSeq + "\t" + strName);
        }  // end while loop through result set

        reader.Close();



        conn.Close();
    }
コード例 #3
0
        /// <summary>
        /// Creates an application in the database.
        /// </summary>
        /// <param name="name">The name of the application to create.</param>
        /// <param name="id">The Id of the application to create.</param>
        private void CreateApplication(string name, out string id)
        {
            // Ensure that the proposed rolename is of a valid form and does not already exist
            if (name.IndexOf(',') > 0)
            {
                throw new ArgumentException(Messages.ApplicationNamesCannotContainCommas);
            }

            // Build up the command and connection details
            id = null;

            string sql = @"
                          SELECT
                              ApplicationId 
                          FROM
                              aspnet_Applications 
                          WHERE 
                              LoweredApplicationName = ?
                         ";

            IngresCommand cmd = new IngresCommand(sql, this.conn);

            cmd.Transaction    = this.tran;
            cmd.CommandTimeout = this.config.CommandTimeout;

            cmd.Parameters.Add("LoweredApplicationName", DbType.String).Value = name.ToLower();

            IngresDataReader datareader = cmd.ExecuteReader();

            if (datareader != null)
            {
                if (datareader.HasRows)
                {
                    datareader.Read();
                    id = datareader.GetString(0);

                    datareader.Close();

                    return;
                }

                id = Guid.NewGuid().ToString();
            }

            if (datareader != null)
            {
                datareader.Close();
            }

            sql = @"
                    INSERT INTO aspnet_Applications 
                       (ApplicationId, 
                        ApplicationName, 
                        LoweredApplicationName)
                    VALUES  
                       (?, 
                        ?, 
                        ?)
                    ";

            cmd                = new IngresCommand(sql, this.conn);
            cmd.Transaction    = this.tran;
            cmd.CommandTimeout = this.config.CommandTimeout;

            cmd.Parameters.Add("ApplicationId", DbType.String).Value          = id;
            cmd.Parameters.Add("ApplicationName", DbType.String).Value        = name;
            cmd.Parameters.Add("LoweredApplicationName", DbType.String).Value = name.ToLower();

            cmd.ExecuteNonQuery();

            return;
        }