public DatabaseConnection(string connectionStr, string connType) { switch (connType.ToLower()) { case "pgsql": _pgsqlConnection = new NpgsqlConnection(connectionStr); _adapter = new NormalQueryReactor(this); _type = 4; break; case "ingress": case "ingres": _ingressConnection = new IngresConnection(connectionStr); _adapter = new NormalQueryReactor(this); _type = 3; break; case "firebird": _firebirdConnection = new FbConnection(connectionStr); _adapter = new NormalQueryReactor(this); _type = 2; break; default: // mySql _mysqlConnection = new MySqlConnection(connectionStr); _adapter = new NormalQueryReactor(this); _type = 1; break; } }
protected System.Data.Common.DbConnection getConnection() { DbConnection con = new IngClient.IngresConnection(conString); con.Open(); configSession(con); return(con); }
/// <summary> /// Returns a new Connection object and a cloned connection string. /// </summary> /// <returns></returns> public object Clone() { IngresConnection newConn = new IngresConnection(); newConn.ConnectionString = ConnectStringConfig.ToConnectionString(this.config); // overlay the connection string with the sanitized version // if the old connection had been openned. newConn._connectionString= this._connectionString; return newConn; }
/// <summary> /// Initializes a new instance of the IngresRoleProviderHandler class. /// </summary> /// <param name="conn">The Ingres connection to use.</param> /// <param name="tran">The Ingres transaction to use.</param> /// <param name="config">The configuration settings to use.</param> /// <param name="provider">The Ingres Role Provider facade to use.</param> internal IngresRoleProviderHandler(IngresConnection conn, IngresTransaction tran, IngresRoleProviderConfiguration config, IngresRoleProvider provider) { if (conn == null || tran == null) { throw new Exception(); } this.tran = tran; this.conn = conn; this.config = config; this.provider = provider; }
/// <summary> /// Wrap the identifier in leading and trailing quote literals. /// </summary> /// <param name="unquotedIdentifier"></param> /// <param name="connection"></param> /// <returns></returns> public string QuoteIdentifier( string unquotedIdentifier, IngresConnection connection) { if (unquotedIdentifier == null) { throw new ArgumentNullException( "Parameter 'unquotedIdentifier' must not be null."); } string quotePrefix = this.QuotePrefix; string quoteSuffix = this.QuoteSuffix; // If the quotes are not set then InvalidOperationException. // Should not happen since they are set by the constructor. if (quotePrefix == null || quoteSuffix == null || quotePrefix.Length == 0 || quoteSuffix.Length == 0) { throw new InvalidOperationException("Quotes are not set."); } System.Text.StringBuilder sb = new System.Text.StringBuilder(unquotedIdentifier.Length + 2); sb.Append(quotePrefix); // starting quote for (int i = 0; i < unquotedIdentifier.Length; i++) { if ((i + quotePrefix.Length) > unquotedIdentifier.Length) { continue; // avoid falling off the edge of the string } string ss = unquotedIdentifier.Substring(i, quotePrefix.Length); if (ss == quotePrefix) // if embedded quote, double up { sb.Append(quotePrefix); sb.Append(quotePrefix); i += quotePrefix.Length - 1; continue; } // not an embedded quote sb.Append(unquotedIdentifier[i]); } // end for loop through unquotedIdentifier sb.Append(quoteSuffix); // closing quote return(sb.ToString()); }
internal IngresTransaction(IngresConnection conn, IsolationLevel level) { switch(level) { case IsolationLevel.ReadUncommitted: case IsolationLevel.ReadCommitted: case IsolationLevel.RepeatableRead: case IsolationLevel.Serializable: break; case IsolationLevel.Unspecified: level = IsolationLevel.ReadCommitted; // default break; default: throw new NotSupportedException( "IngresTransaction(IsolationLevel."+level.ToString()+")"); } _connection = conn; _isolationLevel = level; }
public MySqlClient(DatabaseManager dbManager) { _dbManager = dbManager; switch (DatabaseManager.DatabaseConnectionType.ToLower()) { case "pgsql": _pgSqlConnection = new NpgsqlConnection(dbManager.GetConnectionString()); break; case "ingress": case "ingres": _inGressConnection = new IngresConnection(dbManager.GetConnectionString()); break; case "firebird": _fireBirdConnection = new FbConnection(dbManager.GetConnectionString()); break; default: // mySql _mySqlConnection = new MySqlConnection(dbManager.GetConnectionString()); break; } }
internal IngresTransaction(IngresConnection conn, IsolationLevel level) { switch (level) { case IsolationLevel.ReadUncommitted: case IsolationLevel.ReadCommitted: case IsolationLevel.RepeatableRead: case IsolationLevel.Serializable: break; case IsolationLevel.Unspecified: level = IsolationLevel.ReadCommitted; // default break; default: throw new NotSupportedException( "IngresTransaction(IsolationLevel." + level.ToString() + ")"); } _connection = conn; _isolationLevel = level; }
/// <summary> /// This method takes a role name and determines whether the role exists. /// </summary> /// <remarks> /// This method overrides a method from the <c>System.Web.Security.RoleProvider</c> class to provide an Ingres /// specific implementation. /// </remarks> /// <param name="roleName">Role name to check the existence of.</param> /// <returns>Whether the given role exists.</returns> public override bool RoleExists(string roleName) { bool result = false; IngresTransaction tran = null; try { using (IngresConnection conn = new IngresConnection(this.config.ConnectionString)) { // Open the connection and start a new transaction conn.Open(); tran = conn.BeginTransaction(); // Call the implementation of the method result = this.GetHandler(conn, tran).RoleExists(roleName); // Commit the transaction tran.Commit(); } } catch (Exception ex) { // Attempt to rollback try { if (tran != null && tran.Connection != null) { tran.Rollback(); } } catch { // Add the rollback error. ExceptionHandler.LogRollbackWarning(RoleProviderMethod.RoleExists); } // Handle the exception appropriately ExceptionHandler.HandleException(ex, RoleProviderMethod.RoleExists); } return result; }
/// <summary> /// Remove the leading and trailing quote literals /// from the specified identifier. /// </summary> /// <param name="quotedIdentifier"></param> /// <param name="connection"></param> /// <returns></returns> public string UnquoteIdentifier( string quotedIdentifier, IngresConnection connection) { return UnquoteIdent( quotedIdentifier, connection, this.QuotePrefix, this.QuoteSuffix); }
/// <summary> /// Takes, as input, the name of a new user, a password, and an email address and inserts /// a new user for the application into the data source. The <c>CreateUser</c> method returns a /// <c>MembershipUser</c> object populated with the information for the newly created user. /// The <c>CreateUser</c> method also defines an out parameter that returns a /// <c>MembershipCreateStatus</c> value that indicates whether the user was successfully created, /// or a reason that the user was not successfully created. /// </summary> /// <remarks> /// <para> /// The <c>CreateUser</c> method raises the <c>ValidatingPassword</c> event, if a /// <c>MembershipValidatePasswordEventHandler</c> has been specified, and continues or cancels the /// create-user action based on the results of the event. You can use the /// <c>OnValidatingPassword</c> virtual method to execute the specified /// <c>MembershipValidatePasswordEventHandler</c>. /// </para> /// <para> /// This method overrides a method from the <c>System.Web.Security.MembershipProvider</c> class to provide an /// Ingres specific implementation. /// </para> /// </remarks> /// <param name="username">name of the new user.</param> /// <param name="password">password for the new user.</param> /// <param name="email">email address of the new user.</param> /// <param name="passwordQuestion">password reset question for the new user.</param> /// <param name="passwordAnswer">password reset answer for the new user.</param> /// <param name="isApproved">a boolean indicating whether the user has been approved or not</param> /// <param name="providerUserKey">the identifier/key for the user.</param> /// <param name="status">membership creation status for the user.</param> /// <returns>A MembershipUser object populated with the information for the newly created user.</returns> public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { status = MembershipCreateStatus.ProviderError; MembershipUser result = null; IngresTransaction tran = null; try { using (IngresConnection conn = new IngresConnection(this.config.ConnectionString)) { // Open the connection and start a new transaction conn.Open(); tran = conn.BeginTransaction(); // Call the implementation of the method result = this.GetHandler(conn, tran).CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey, out status); // Commit the transaction tran.Commit(); } } catch (Exception ex) { // Attempt to rollback try { if (tran != null && tran.Connection != null) { tran.Rollback(); } } catch { // Add the rollback error. ExceptionHandler.LogRollbackWarning(MembershipProviderMethod.CreateUser); } // Handle the exception appropriately ExceptionHandler.HandleException(ex, MembershipProviderMethod.CreateUser); } return result; }
/// <summary> /// Takes, as input, a <c>MembershipUser</c> object populated with user information and updates /// the data source with the supplied values. /// </summary> /// <remark> /// This method overrides a method from the <c>System.Web.Security.MembershipProvider</c> /// class to provide an Ingres specific implementation. /// </remark> /// <param name="user">The membership user to update.</param> public override void UpdateUser(MembershipUser user) { IngresTransaction tran = null; try { using (IngresConnection conn = new IngresConnection(this.config.ConnectionString)) { // Open the connection and start a new transaction conn.Open(); tran = conn.BeginTransaction(); // Call the implementation of the method this.GetHandler(conn, tran).UpdateUser(user); // Commit the transaction tran.Commit(); } } catch (Exception ex) { // Attempt to rollback try { if (tran != null && tran.Connection != null) { tran.Rollback(); } } catch { // Add the rollback error. ExceptionHandler.LogRollbackWarning(MembershipProviderMethod.UpdateUser); } // Handle the exception appropriately ExceptionHandler.HandleException(ex, MembershipProviderMethod.UpdateUser); } }
/// <summary> /// Remove the leading and trailing quote literals /// from the specified identifier. /// </summary> /// <param name="quotedIdentifier"></param> /// <param name="connection"></param> /// <param name="quotePrefix"></param> /// <param name="quoteSuffix"></param> /// <returns></returns> internal static string UnquoteIdent( string quotedIdentifier, IngresConnection connection, string quotePrefix, string quoteSuffix) { string ss; // working substring through the identifier if (quotedIdentifier == null) { throw new ArgumentNullException( "Parameter 'quotedIdentifier' must not be null."); } // if the quotes are not set then return original if (quotePrefix == null || quoteSuffix == null || quotePrefix.Length == 0 || quoteSuffix.Length == 0) { return(quotedIdentifier); } int quotesLength = quotePrefix.Length + quoteSuffix.Length; // if identifier could not possibly hold the quotes, return original. if (quotesLength > quotedIdentifier.Length) { return(quotedIdentifier); } // check leading quote is there, else return. ss = quotedIdentifier.Substring(0, quotePrefix.Length); if (ss != quotePrefix) { return(quotedIdentifier); // no leading quote } // check trailing quote is there, else return. ss = quotedIdentifier.Substring( quotedIdentifier.Length - quoteSuffix.Length, quoteSuffix.Length); if (ss != quoteSuffix) { return(quotedIdentifier); // no trailing quote } int identLength = quotedIdentifier.Length - quotesLength; string ident = quotedIdentifier.Substring( quotePrefix.Length, identLength); System.Text.StringBuilder sb = new System.Text.StringBuilder(quotedIdentifier.Length); bool quoteAppended = false; for (int i = 0; i < identLength; i++) { // if not falling off the edge of the string if ((i + quotePrefix.Length) <= ident.Length) { ss = ident.Substring(i, quotePrefix.Length); if (ss == quotePrefix) { if (quoteAppended) // doubled up quote already in? { quoteAppended = false; i += quotePrefix.Length - 1; continue; // drop the second quote } else // start of possible doubled up quote { sb.Append(quotePrefix); // add the first quote quoteAppended = true; i += quotePrefix.Length - 1; continue; } } // end if (ss == quotePrefix) } // end possible embedded quote string quoteAppended = false; // clear slate on doubled up quotes // not an embedded quote sb.Append(ident[i]); } // end for loop through quotedIdentifier return(sb.ToString()); }
} // end constructor DataAdapter /// <summary> /// Create a new DataAdapter object with specified SELECT text string /// and specific Connection object. /// </summary> /// <param name="selectCommandText">SELECT text string.</param> /// <param name="selectConnection">Connection object.</param> public IngresDataAdapter( string selectCommandText, IngresConnection selectConnection) { this.SelectCommand = new IngresCommand(selectCommandText, selectConnection); } // end constructor DataAdapter
public override List<Table> GetTables(string owner) { var tables = new List<Table>(); var conn = new IngresConnection(_connectionString); conn.Open(); try { using (conn) { var tableCommand = conn.CreateCommand(); tableCommand.CommandText = String.Format("SELECT table_name " + "FROM iitables " + "WHERE table_owner = '{0}' " + "AND table_type in ('T', 'V') " + "AND table_name NOT LIKE 'ii%'", owner); var sqlDataReader = tableCommand.ExecuteReader(CommandBehavior.CloseConnection); while (sqlDataReader.Read()) { var tableName = sqlDataReader.GetString(0).TrimEnd(); tables.Add(new Table { Name = tableName, OwnerSchema = owner, DatabaseName = this.DatabaseName }); } } tables.Sort((x, y) => String.CompareOrdinal(x.Name, y.Name)); } finally { conn.Close(); } return tables; }
public override IList<string> GetOwners() { var owners = new List<string>(); var conn = new IngresConnection(_connectionString); conn.Open(); try { using (conn) { var tableCommand = conn.CreateCommand(); tableCommand.CommandText = "SELECT DISTINCT table_owner FROM iitables WHERE table_owner <> '$ingres'"; var sqlDataReader = tableCommand.ExecuteReader(CommandBehavior.CloseConnection); while (sqlDataReader.Read()) { var ownerName = sqlDataReader.GetString(0).TrimEnd(); owners.Add(ownerName); } } } finally { conn.Close(); } return owners; }
private string GetConstraintName(string owner, string tableName, string columnName) { var conn = new IngresConnection(_connectionString); conn.Open(); try { using (conn) { using (var tableDetailsCommand = conn.CreateCommand()) { tableDetailsCommand.CommandText = string.Format("SELECT k.constraint_name " + "FROM iikeys k " + "INNER JOIN iiconstraints c " + "ON k.constraint_name = c.constraint_name " + "WHERE c.constraint_type = 'R' " + "AND k.schema_name = '{0}' " + "AND k.table_name = '{1}' " + "AND k.column_name = '{2}'", owner, tableName, columnName); var result = tableDetailsCommand.ExecuteScalar(); return result == null ? String.Empty : result.ToString(); } } } finally { conn.Close(); } }
private string GetForeignKeyReferenceTableName(string owner, string tableName, string columnName) { var conn = new IngresConnection(_connectionString); conn.Open(); try { using (conn) { using (var tableCommand = conn.CreateCommand()) { tableCommand.CommandText = String.Format("SELECT p.table_name " + "FROM iiref_constraints rc " + "INNER JOIN iikeys p " + "ON p.schema_name = rc.unique_schema_name " + "AND p.constraint_name = rc.unique_constraint_name " + "INNER JOIN iiconstraints c " + "ON c.schema_name = rc.ref_schema_name " + "AND c.constraint_name = rc.ref_constraint_name " + "INNER JOIN iikeys f " + "ON f.schema_name = rc.ref_schema_name " + "AND f.constraint_name = rc.ref_constraint_name " + "AND p.key_position = f.key_position " + "WHERE f.schema_name = '{0}' " + "AND f.table_name = '{1}' " + "AND f.column_name = '{2}'", owner, tableName, columnName); return tableCommand.ExecuteScalar().ToString(); } } } finally { conn.Close(); } }
private bool IsForeignKey(string owner, string tableName, string columnName) { var conn = new IngresConnection(_connectionString); conn.Open(); try { using (conn) { using (var tableDetailsCommand = conn.CreateCommand()) { tableDetailsCommand.CommandText = string.Format("SELECT COUNT(0) " + "FROM iikeys k " + "INNER JOIN iiconstraints c " + "ON k.constraint_name = c.constraint_name " + "WHERE c.constraint_type = 'R' " + "AND k.schema_name = '{0}' " + "AND k.table_name = '{1}' " + "AND k.column_name = '{2}'", owner, tableName, columnName); var obj = tableDetailsCommand.ExecuteScalar(); int result; if (obj != null && Int32.TryParse(obj.ToString(), out result)) return result > 0; } } } finally { conn.Close(); } return false; }
private IList<HasMany> DetermineHasManyRelationships(Table table) { var hasManyRelationships = new List<HasMany>(); var conn = new IngresConnection(_connectionString); conn.Open(); using (conn) { using (var command = conn.CreateCommand()) { command.CommandText = String.Format("SELECT f.table_name " + "FROM iiref_constraints rc " + "INNER JOIN iikeys p " + "ON p.schema_name = rc.unique_schema_name " + "AND p.constraint_name = rc.unique_constraint_name " + "INNER JOIN iiconstraints c " + "ON c.schema_name = rc.ref_schema_name " + "AND c.constraint_name = rc.ref_constraint_name " + "INNER JOIN iikeys f " + "ON f.constraint_name = rc.ref_constraint_name " + "AND p.key_position = f.key_position " + "WHERE p.schema_name = '{0}' " + "AND p.table_name = '{1}'", table.OwnerSchema, table.Name); using (var reader = command.ExecuteReader()) { while (reader.Read()) { hasManyRelationships.Add(new HasMany { Reference = reader.GetString(0).TrimEnd(), }); } } return hasManyRelationships; } } }
/// <summary> /// Remove the leading and trailing quote literals /// from the specified identifier. /// </summary> /// <param name="quotedIdentifier"></param> /// <param name="connection"></param> /// <param name="quotePrefix"></param> /// <param name="quoteSuffix"></param> /// <returns></returns> internal static string UnquoteIdent( string quotedIdentifier, IngresConnection connection, string quotePrefix, string quoteSuffix) { string ss; // working substring through the identifier if (quotedIdentifier == null) throw new ArgumentNullException( "Parameter 'quotedIdentifier' must not be null."); // if the quotes are not set then return original if (quotePrefix == null || quoteSuffix == null || quotePrefix.Length == 0 || quoteSuffix.Length == 0) return quotedIdentifier; int quotesLength = quotePrefix.Length + quoteSuffix.Length; // if identifier could not possibly hold the quotes, return original. if (quotesLength > quotedIdentifier.Length) return quotedIdentifier; // check leading quote is there, else return. ss = quotedIdentifier.Substring(0, quotePrefix.Length); if (ss != quotePrefix) return quotedIdentifier; // no leading quote // check trailing quote is there, else return. ss = quotedIdentifier.Substring( quotedIdentifier.Length-quoteSuffix.Length, quoteSuffix.Length); if (ss != quoteSuffix) return quotedIdentifier; // no trailing quote int identLength = quotedIdentifier.Length - quotesLength; string ident = quotedIdentifier.Substring( quotePrefix.Length, identLength); System.Text.StringBuilder sb = new System.Text.StringBuilder(quotedIdentifier.Length); bool quoteAppended = false; for (int i = 0; i < identLength; i++) { // if not falling off the edge of the string if ((i + quotePrefix.Length) <= ident.Length) { ss = ident.Substring(i, quotePrefix.Length); if (ss == quotePrefix) { if (quoteAppended) // doubled up quote already in? { quoteAppended = false; i += quotePrefix.Length - 1; continue; // drop the second quote } else // start of possible doubled up quote { sb.Append(quotePrefix); // add the first quote quoteAppended = true; i += quotePrefix.Length - 1; continue; } } // end if (ss == quotePrefix) } // end possible embedded quote string quoteAppended = false; // clear slate on doubled up quotes // not an embedded quote sb.Append(ident[i]); } // end for loop through quotedIdentifier return sb.ToString(); }
/// <summary> /// Handles the press of the test connection string button. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The event arguments.</param> private void TestConnectionString(object sender, EventArgs e) { this.btnTest.Enabled = false; IngresConnection conn = new IngresConnection(); if (this.tbConnectionString.Text.Trim() == string.Empty) { MessageBox.Show("A connection string must be entered."); this.btnTest.Enabled = true; return; } try { conn.ConnectionString = this.tbConnectionString.Text; } catch (Exception) { this.tbConnectionResult.Text = "Invalid connection string."; this.btnTest.Enabled = true; return; } try { conn.Open(); this.tbConnectionResult.Text = "Successfully opened a connection!"; MessageBox.Show("A connection to the database was successfully opened!\n\nCopy the generated connection string for use in the web config file.", "Successful Connection"); } catch (Exception ex) { this.tbConnectionResult.Text = ex.Message; } finally { if (conn.State != ConnectionState.Closed) { conn.Close(); } conn = null; this.btnTest.Enabled = true; } }
protected override IList<Column> GetTablesDetails(Table table, string owner) { table.OwnerSchema = owner; var columns = new List<Column>(); var conn = new IngresConnection(_connectionString); conn.Open(); try { using (conn) { using (var tableDetailsCommand = conn.CreateCommand()) { tableDetailsCommand.CommandText = string.Format("SELECT" + " column_name," + " column_datatype," + " column_nulls," + " column_length," + " column_scale " + "FROM iicolumns " + "WHERE table_owner = '{0}' " + "AND table_name = '{1}' " + "ORDER BY column_sequence", owner, table.Name); using (var sqlDataReader = tableDetailsCommand.ExecuteReader(CommandBehavior.Default)) { while (sqlDataReader.Read()) { string columnName = sqlDataReader.GetString(0).TrimEnd(); string dataType = sqlDataReader.GetString(1).TrimEnd(); bool isNullable = sqlDataReader.GetString(2).Equals("Y", StringComparison.CurrentCultureIgnoreCase); int characterMaxLenth = sqlDataReader.GetInt32(3); int numericPrecision = sqlDataReader.GetInt32(3); int numericScale = sqlDataReader.GetInt32(4); var m = new DataTypeMapper(); bool isPrimaryKey = IsPrimaryKey(owner, table.Name, columnName); columns.Add(new Column(table) { Name = columnName, DataType = dataType, IsNullable = isNullable, IsPrimaryKey = isPrimaryKey, IsForeignKey = IsForeignKey(owner, table.Name, columnName), MappedDataType = m.MapFromDBType(DatabaseServerType.Ingres, dataType, characterMaxLenth, numericPrecision, numericScale, isPrimaryKey), DataLength = characterMaxLenth, ConstraintName = GetConstraintName(owner, table.Name, columnName), DataPrecision = numericPrecision, DataScale = numericScale }); table.Columns = columns; } table.PrimaryKey = DeterminePrimaryKeys(table); table.ForeignKeys = DetermineForeignKeyReferences(table); table.HasManyRelationships = DetermineHasManyRelationships(table); } } } } finally { conn.Close(); } return columns; }
// Name: SetConnection - Change the connection string // // Description: // Change the connection string in the Ingres connection obbject. // // Input: // ingresConnection Connection object to update. // connectString Updated connection string. // // Output: // None. // // Returns: // None. // // History: // 02-Oct-2006 ([email protected]) // Created. private void SetConnection(IngresConnection ingresConnection, String connectString) { ingresConnection.ConnectionString = connectString; }
/// <summary> /// Returns a <c>MembershipUserCollection</c> populated with <c>MembershipUser</c> objects for all of the /// users in the data source. /// </summary> /// <remarks> /// <para> /// The results returned by <c>GetAllUsers</c> are constrained by the <c>pageIndex</c> and <c>pageSize</c> /// parameters. The <c>pageSize</c> parameter identifies the maximum number of <c>MembershipUser</c> /// objects to return in the <c>MembershipUserCollection</c>. The <c>pageIndex</c> parameter identifies /// which page of results to return, where 1 identifies the first page. The <c>totalRecords</c> /// parameter is an out parameter that is set to the total number of membership users. For /// example, if 13 users were in the database for the application, and the pageIndex value /// was 2 with a pageSize of 5, the <c>MembershipUserCollection</c> returned would contain the /// sixth through the tenth users returned. <c>totalRecords</c> would be set to 13. /// </para> /// <para> /// This method overrides a method from the <c>System.Web.Security.MembershipProvider</c> class to provide an /// Ingres specific implementation. /// </para> /// </remarks> /// <param name="pageIndex">Which page to return.</param> /// <param name="pageSize">The maximum number of users to return.</param> /// <param name="totalRecords">[out] The total number of users.</param> /// <returns>Returns a MembershipUserCollection populated with MembershipUser objects /// for all of the users in the data source.</returns> public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) { totalRecords = 0; MembershipUserCollection result = new MembershipUserCollection(); IngresTransaction tran = null; try { using (IngresConnection conn = new IngresConnection(this.config.ConnectionString)) { // Open the connection and start a new transaction conn.Open(); tran = conn.BeginTransaction(); // Call the implementation of the method result = this.GetHandler(conn, tran).GetAllUsers(pageIndex, pageSize, out totalRecords); // Commit the transaction tran.Commit(); } } catch (Exception ex) { // Attempt to rollback try { if (tran != null && tran.Connection != null) { tran.Rollback(); } } catch { // Add the rollback error. ExceptionHandler.LogRollbackWarning(MembershipProviderMethod.GetAllUsers); } // Handle the exception appropriately ExceptionHandler.HandleException(ex, MembershipProviderMethod.GetAllUsers); } return result; }
} // ApplyParameterInfo /// <summary> /// Populate the IngresCommand.Parameters collection with data type /// metadata about the parameters of the specified database procedure. /// </summary> /// <param name="command"></param> public static void DeriveParameters(IngresCommand command) { if (command == null) { throw new ArgumentNullException( "DeriveParameters parameter 'command' must not be null."); } IngresConnection conn = command.Connection; if (conn == null || conn.State != ConnectionState.Open) { throw new InvalidOperationException( "The IngresCommand.Connection must be specified and open."); } if (command.CommandText == null || command.CommandText.Length == 0) { throw new InvalidOperationException( "The IngresCommand.CommandText must be specify a procedure name."); } if (command.CommandType != CommandType.StoredProcedure) { throw new InvalidOperationException( "Only CommandType.StoredProcedure is supported."); } ArrayList tokens = Ingres.ProviderInternals.MetaData.ScanSqlStatement( command.CommandText); String[] restriction = new String[3]; if (tokens.Count == 1) // procname { restriction[2] = UnquoteIdent((String)tokens[0], conn, "\"", "\""); } else if (tokens.Count == 3 && // schemaname.procname (String)tokens[1] == ".") { restriction[1] = UnquoteIdent((String)tokens[0], conn, "\"", "\""); restriction[2] = UnquoteIdent((String)tokens[2], conn, "\"", "\""); } else if (tokens.Count == 5 && // catalogname.schemaname.procname (String)tokens[1] == "." && (String)tokens[3] == ".") { restriction[0] = UnquoteIdent((String)tokens[0], conn, "\"", "\""); restriction[1] = UnquoteIdent((String)tokens[2], conn, "\"", "\""); restriction[2] = UnquoteIdent((String)tokens[4], conn, "\"", "\""); } else { throw new InvalidOperationException( "Invalid procedure name."); } DataTable datatable = conn.GetSchema("ProcedureParameters", restriction); command.Parameters.Clear(); foreach (DataRow row in datatable.Rows) { string name = (String)row["COLUMN_NAME"]; IngresType ingresType = (IngresType)row["INGRESTYPE"]; IngresParameter parm = new IngresParameter(name, ingresType); command.Parameters.Add(parm); } // end foreach (DataRow row in datatable) }
/// <summary> /// Remove the leading and trailing quote literals /// from the specified identifier. /// </summary> /// <param name="quotedIdentifier"></param> /// <param name="connection"></param> /// <returns></returns> public string UnquoteIdentifier( string quotedIdentifier, IngresConnection connection) { return(UnquoteIdent( quotedIdentifier, connection, this.QuotePrefix, this.QuoteSuffix)); }
internal IngresTransaction(IngresConnection conn) : this(conn, IsolationLevel.ReadCommitted) { }
/// <summary> /// Takes, as input, a unique user identifier and a Boolean value indicating whether to /// update the <c>LastActivityDate</c> value for the user to show that the user is currently /// online. The <c>GetUser</c> method returns a <c>MembershipUser</c> object populated with current /// values from the data source for the specified user. If the user name is not found in /// the data source, the <c>GetUser</c> method returns null. /// </summary> /// <remark> /// This method overrides a method from the <c>System.Web.Security.MembershipProvider</c> class to provide an /// Ingres specific implementation. /// </remark> /// <param name="providerUserKey">The unique indentifer for the user.</param> /// <param name="userIsOnline">Whether the user is online.</param> /// <returns>The membership user with the specified provider user key.</returns> public override MembershipUser GetUser(object providerUserKey, bool userIsOnline) { MembershipUser result = null; IngresTransaction tran = null; try { using (IngresConnection conn = new IngresConnection(this.config.ConnectionString)) { // Open the connection and start a new transaction conn.Open(); tran = conn.BeginTransaction(); // Call the implementation of the method result = this.GetHandler(conn, tran).GetUser(providerUserKey, userIsOnline); // Commit the transaction tran.Commit(); } } catch (Exception ex) { // Attempt to rollback try { if (tran != null && tran.Connection != null) { tran.Rollback(); } } catch { // Add the rollback error. ExceptionHandler.LogRollbackWarning(MembershipProviderMethod.GetUserByObject); } // Handle the exception appropriately ExceptionHandler.HandleException(ex, MembershipProviderMethod.GetUserByObject); } return result; }
/// <summary> /// Create a new instance of IngresCommand with specified SQL text string, /// IngresConnection, and Transaction objects. /// </summary> /// <param name="cmdText">SQL text string.</param> /// <param name="connection"> /// IngresConnection to be associated with this command.</param> /// <param name="transaction"> /// IngresTransaction to be associated with this command.</param> public IngresCommand(string cmdText, IngresConnection connection, IngresTransaction transaction) { InitializeComponent(); _commandText = cmdText; _connection = connection; _transaction = transaction; }
/// <summary> /// Gets a handler for the Ingres membership provider. /// </summary> /// <param name="conn">The Ingres connection.</param> /// <param name="tran">The Ingres transaction to use.</param> /// <returns>The handler</returns> private IngresMembershipProviderHandler GetHandler(IngresConnection conn, IngresTransaction tran) { IngresMembershipProviderHandler handler = new IngresMembershipProviderHandler(conn, tran, this.config, this); return handler; }
/// <summary> /// Takes an array of user names and an array of role names and removes the specified users /// from the specified roles. /// </summary> /// <remarks> /// <para> /// <c>RemoveUsersFromRoles</c> throws a <c>ProviderException</c> if any of the users or roles do not /// exist, or if any user specified in the call does not belong to the role from which he /// or she is being removed. /// </para> /// <para> /// This method overrides a method from the <c>System.Web.Security.RoleProvider</c> class to provide an Ingres /// specific implementation. /// </para> /// </remarks> /// <param name="usernames">The array of usernames.</param> /// <param name="roleNames">The array of roles.</param> public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames) { IngresTransaction tran = null; try { using (IngresConnection conn = new IngresConnection(this.config.ConnectionString)) { // Open the connection and start a new transaction conn.Open(); tran = conn.BeginTransaction(); // Call the implementation of the method this.GetHandler(conn, tran).RemoveUsersFromRoles(usernames, roleNames); // Commit the transaction tran.Commit(); } } catch (Exception ex) { // Attempt to rollback try { if (tran != null && tran.Connection != null) { tran.Rollback(); } } catch { // Add the rollback error. ExceptionHandler.LogRollbackWarning(RoleProviderMethod.RemoveUsersFromRoles); } // Handle the exception appropriately ExceptionHandler.HandleException(ex, RoleProviderMethod.RemoveUsersFromRoles); } }
/// <summary> /// Takes, as input, the name of a user and deletes that user's information from the data /// source. The <c>DeleteUser</c> method returns true if the user was successfully deleted; /// otherwise, false. An additional Boolean parameter is included to indicate whether /// related information for the user, such as role or profile information is also deleted. /// </summary> /// <remark> /// This method overrides a method from the <c>System.Web.Security.MembershipProvider</c> class to provide an /// Ingres specific implementation. /// </remark> /// <param name="username">The username to delete.</param> /// <param name="deleteAllRelatedData">Whether to delete all related data or not.</param> /// <returns>Returns true if the user was successfully deleted; otherwise, false.</returns> public override bool DeleteUser(string username, bool deleteAllRelatedData) { bool result = false; IngresTransaction tran = null; try { using (IngresConnection conn = new IngresConnection(this.config.ConnectionString)) { // Open the connection and start a new transaction conn.Open(); tran = conn.BeginTransaction(); // Call the implementation of the method result = this.GetHandler(conn, tran).DeleteUser(username, deleteAllRelatedData); // Commit the transaction tran.Commit(); } } catch (Exception ex) { // Attempt to rollback try { if (tran != null && tran.Connection != null) { tran.Rollback(); } } catch { // Add the rollback error. ExceptionHandler.LogRollbackWarning(MembershipProviderMethod.DeleteUser); } // Handle the exception appropriately ExceptionHandler.HandleException(ex, MembershipProviderMethod.DeleteUser); } return result; }
/// <summary> /// Wrap the identifier in leading and trailing quote literals. /// </summary> /// <param name="unquotedIdentifier"></param> /// <param name="connection"></param> /// <returns></returns> public string QuoteIdentifier( string unquotedIdentifier, IngresConnection connection) { if (unquotedIdentifier == null) throw new ArgumentNullException( "Parameter 'unquotedIdentifier' must not be null."); string quotePrefix = this.QuotePrefix; string quoteSuffix = this.QuoteSuffix; // If the quotes are not set then InvalidOperationException. // Should not happen since they are set by the constructor. if (quotePrefix == null || quoteSuffix == null || quotePrefix.Length == 0 || quoteSuffix.Length == 0) throw new InvalidOperationException("Quotes are not set."); System.Text.StringBuilder sb = new System.Text.StringBuilder(unquotedIdentifier.Length + 2); sb.Append(quotePrefix); // starting quote for (int i = 0; i < unquotedIdentifier.Length; i++) { if ((i + quotePrefix.Length) > unquotedIdentifier.Length) continue; // avoid falling off the edge of the string string ss = unquotedIdentifier.Substring(i, quotePrefix.Length); if (ss == quotePrefix) // if embedded quote, double up { sb.Append(quotePrefix); sb.Append(quotePrefix); i += quotePrefix.Length - 1; continue; } // not an embedded quote sb.Append(unquotedIdentifier[i]); } // end for loop through unquotedIdentifier sb.Append(quoteSuffix); // closing quote return sb.ToString(); }
/// <summary> /// Takes, as input, a user name and a password answer and retrieves the password for that /// user from the data source and returns the password as a string. /// </summary> /// <remarks> /// <para> /// GetPassword ensures that the <c>EnablePasswordRetrieval</c> property is set to true before /// performing any action. If the <c>EnablePasswordRetrieval</c> property is false, an /// <c>ProviderException</c> is thrown. /// </para> /// <para> /// The <c>GetPassword</c> method also checks the value of the <c>RequiresQuestionAndAnswer</c> property. /// If the <c>RequiresQuestionAndAnswer</c> property is true, the <c>GetPassword</c> method checks the /// value of the supplied answer parameter against the stored password answer in the data /// source. If they do not match, a <c>MembershipPasswordException</c> is thrown. /// </para> /// <para> /// This method overrides a method from the <c>System.Web.Security.MembershipProvider</c> /// class to provide an Ingres specific implementation. /// </para> /// </remarks> /// <param name="username">The username.</param> /// <param name="answer">The password answer.</param> /// <returns>The password for the given username.</returns> public override string GetPassword(string username, string answer) { string result = string.Empty; IngresTransaction tran = null; try { using (IngresConnection conn = new IngresConnection(this.config.ConnectionString)) { // Open the connection and start a new transaction conn.Open(); tran = conn.BeginTransaction(); // Call the implementation of the method result = this.GetHandler(conn, tran).GetPassword(username, answer); // Commit the transaction tran.Commit(); } } catch (Exception ex) { // Attempt to rollback try { if (tran != null && tran.Connection != null) { tran.Rollback(); } } catch { // Add the rollback error. ExceptionHandler.LogRollbackWarning(MembershipProviderMethod.GetPassword); } // Handle the exception appropriately ExceptionHandler.HandleException(ex, MembershipProviderMethod.GetPassword); } return result; }
/* ** Dispose ** ** History: ** 27-Aug-02 (thoda04) ** Created. */ /// <summary> /// Release resources used by IngresDataReader. /// </summary> /// <param name="disposing"></param> protected override void Dispose(bool disposing) { /*if disposing == true then method called by user code if disposing == false then method called by runtime from inside the finalizer and we should not reference other objects. */ if (disposing) { Close(); _connection = null; _resultset = null; } }
public void SetUpFixture() { // Retrieve the connection details from the App.config file ConnectionStringSettingsCollection connectionSettings = ConfigurationManager.ConnectionStrings; if (connectionSettings.Count == 0) { throw new InvalidOperationException("No connection information specified in application configuration file."); } // Instantiate a connection to the Ingres database using the settings in the App.config // file. ConnectionStringSettings connectionSetting = connectionSettings[0]; string myConnectionString = connectionSetting.ConnectionString; this.Connection = new IngresConnection(); this.Connection.ConnectionString = myConnectionString; // Open the Ingres connection this.Connection.Open(); // Setup the primary key filter (for DBUnit) PrimaryKeyFilter primaryKeyFilter = new PrimaryKeyFilter(); string[] usersInRolesKeys = { "UserId", "RoleId" }; primaryKeyFilter.Add("aspnet_Applications", new PrimaryKey("ApplicationId")); primaryKeyFilter.Add("aspnet_Users", new PrimaryKey("UserId")); primaryKeyFilter.Add("aspnet_Roles", new PrimaryKey("RoleId")); primaryKeyFilter.Add("aspnet_UsersInRoles", new PrimaryKey(usersInRolesKeys)); PKFilter = primaryKeyFilter; DatabaseHandler = new GenericDatabaseHandler(this.Connection); }
private IngresConnection _connection; // = null; /* * The constructors are marked as internal because an application * can't create an IngresDataReader directly. It is created only * by executing one of the reader methods in the IngresCommand. */ internal IngresDataReader( AdvanRslt resultset, IngresConnection connection, CommandBehavior commandBehavior, int recordsAffected, MetaData keyInfoMetaData) { if (resultset == null) // if no result set, build an empty one { resultset = connection.advanConnect.CreateEmptyResultSet(); } _resultset = resultset; _fieldCount = resultset.rsmd.getColumnCount(); _connection = connection; _valueList = new Object[_fieldCount]; _isOpen = true; _commandBehavior = commandBehavior; _recordsAffected = recordsAffected; _keyInfoMetaData = keyInfoMetaData; if (connection != null) connection.ActiveDataReader = this; // only one active DataReader allowed at a time FireInfoMessageEvent(); // call the delegates with any warning messages }