/// <summary> /// Checks exception for Sql related exceptions and attempts to transform it to RhetosException /// </summary> public static RhetosException InterpretSqlException(Exception exception) { if (DatabaseLanguageIsMsSql.Value) { return(MsSqlUtility.InterpretSqlException(exception)); } else if (DatabaseLanguageIsOracle.Value) { return(OracleSqlUtility.InterpretSqlException(exception)); } else { return(null); } }
public static string GetSchemaName(string fullObjectName) { if (_databaseLanguageIsMsSql) { return(MsSqlUtility.GetSchemaName(fullObjectName)); } else if (_databaseLanguageIsOracle) { return(OracleSqlUtility.GetSchemaName(fullObjectName)); } else { throw new FrameworkException(UnsupportedLanguageError); } }
/// <summary> /// Throws an exception if 'name' is not a valid SQL database object name. /// Function returns given argument so it can be used as fluent interface. /// In some cases the function may change the identifier (limit identifier length to 30 on Oracle database, e.g.). /// </summary> public static string Identifier(string name) { string error = CsUtility.GetIdentifierError(name); if (error != null) { throw new FrameworkException("Invalid database object name: " + error); } if (DatabaseLanguageIsOracle.Value) { name = OracleSqlUtility.LimitIdentifierLength(name); } return(name); }
private void SafeExecuteCommand(Action <OracleCommand> action) { using (var connection = new OracleConnection(_connectionString)) { OracleTransaction transaction = null; OracleCommand com; try { connection.Open(); OracleSqlUtility.SetSqlUserInfo(connection, _userInfo); transaction = connection.BeginTransaction(); com = connection.CreateCommand(); com.CommandTimeout = SqlUtility.SqlCommandTimeout; com.Transaction = transaction; } catch (OracleException ex) { if (transaction != null) { transaction.Rollback(); } var csb = new OracleConnectionStringBuilder(_connectionString); string msg = string.Format(CultureInfo.InvariantCulture, "Could not connect to data source '{0}', userID '{1}'.", csb.DataSource, csb.UserID); _logger.Error(msg); _logger.Error(ex.ToString()); throw new FrameworkException(msg, ex); } try { var setNationalLanguage = OracleSqlUtility.SetNationalLanguageQuery(); if (!string.IsNullOrEmpty(setNationalLanguage)) { _logger.Trace("Setting national language: {0}", SqlUtility.NationalLanguage); com.CommandText = setNationalLanguage; com.ExecuteNonQuery(); } action(com); transaction.Commit(); } catch (OracleException ex) { if (com != null && !string.IsNullOrWhiteSpace(com.CommandText)) { _logger.Error("Unable to execute SQL query:\r\n" + com.CommandText); } string msg = "OracleException has occurred:\r\n" + ReportSqlErrors(ex); if (ex.Number == 911) { msg += "\r\nCheck that you are not using ';' at the end of the command's SQL query."; } _logger.Error(msg); _logger.Error(ex.ToString()); throw new FrameworkException(msg, ex); } finally { TryRollback(transaction); } } }