public virtual SqlQueryResult ExecuteSQL(DbEngines dbEngine, string connectionString, string sqlQuery) { ConfigureDependencies(dbEngine); this.DbConnection.ConnectionString = connectionString; this.DbConnection.Open(); var dataReader = GetDataReader(this.DbConnection, sqlQuery); var sqlResult = new SqlQueryResult(); try { while (dataReader.Read()) { var currentRecord = new Dictionary<string, object>(); for (int i = 0; i < dataReader.FieldCount; i++) { var columnName = dataReader.GetName(i); var columnValue = dataReader[columnName]; currentRecord.Add(columnName, columnValue); } sqlResult.AddRecord(currentRecord); } return sqlResult; } finally { dataReader.Close(); this.DbConnection.Close(); } }
public virtual SqlQueryResult ExecuteSQL(DbEngines dbEngine, string connectionString, string sqlQuery) { ConfigureDependencies(dbEngine); this.DbConnection.ConnectionString = connectionString; this.DbConnection.Open(); var dataReader = GetDataReader(this.DbConnection, sqlQuery); var sqlResult = new SqlQueryResult(); try { while (dataReader.Read()) { var currentRecord = new Dictionary <string, object>(); for (int i = 0; i < dataReader.FieldCount; i++) { var columnName = dataReader.GetName(i); var columnValue = dataReader[columnName]; currentRecord.Add(columnName, columnValue); } sqlResult.AddRecord(currentRecord); } return(sqlResult); } finally { dataReader.Close(); this.DbConnection.Close(); } }
/// <summary> /// register dbengine /// </summary> /// <param name="serverType">db server type</param> /// <param name="dbEngine">db engine</param> public static void RegisterDBEngine(ServerType serverType, IDbEngine dbEngine) { if (dbEngine == null) { return; } if (DbEngines.ContainsKey(serverType)) { DbEngines[serverType] = dbEngine; } else { DbEngines.Add(serverType, dbEngine); } }
private void ConfigureDependencies(DbEngines dbEngine) { switch (dbEngine) { case DbEngines.MsSqlServer: this.DbConnection = new SqlConnection(); this.DbCommand = new SqlCommand(); this.DbDataAdapter = new SqlDataAdapter(); break; case DbEngines.Oracle: this.DbConnection = new OracleConnection(); this.DbCommand = new OracleCommand(); this.DbDataAdapter = new OracleDataAdapter(); break; case DbEngines.MySQL: this.DbConnection = new MySqlConnection(); this.DbCommand = new MySqlCommand(); this.DbDataAdapter = new MySqlDataAdapter(); break; case DbEngines.Postgre: this.DbConnection = new NpgsqlConnection(); this.DbCommand = new NpgsqlCommand(); this.DbDataAdapter = new NpgsqlDataAdapter(); break; case DbEngines.Db2: this.DbConnection = new OleDbConnection(); this.DbCommand = new OleDbCommand(); this.DbDataAdapter = new OleDbDataAdapter(); break; case DbEngines.Empty: this.DbConnection = new OdbcConnection(); this.DbCommand = new OdbcCommand(); this.DbDataAdapter = new OdbcDataAdapter(); break; default: throw new ArgumentException(String.Format("[SqlQueryProvider] - This engine ('{0}') is not supportted.", dbEngine.ToString())); } }
private void ConfigureDependencies(DbEngines dbEngine) { switch (dbEngine) { case DbEngines.MsSqlServer: this.DbConnection = new SqlConnection(); this.DbCommand = new SqlCommand(); this.DbDataAdapter = new SqlDataAdapter(); break; case DbEngines.Oracle: this.DbConnection = new OracleConnection(); this.DbCommand = new OracleCommand(); this.DbDataAdapter = new OracleDataAdapter(); break; case DbEngines.MySQL: this.DbConnection = new MySqlConnection(); this.DbCommand = new MySqlCommand(); this.DbDataAdapter = new MySqlDataAdapter(); break; case DbEngines.Postgre: this.DbConnection = new NpgsqlConnection(); this.DbCommand = new NpgsqlCommand(); this.DbDataAdapter = new NpgsqlDataAdapter(); break; case DbEngines.Db2: this.DbConnection = new OleDbConnection(); this.DbCommand = new OleDbCommand(); this.DbDataAdapter = new OleDbDataAdapter(); break; case DbEngines.Empty: this.DbConnection = new OdbcConnection(); this.DbCommand = new OdbcCommand(); this.DbDataAdapter = new OdbcDataAdapter(); break; default: throw new ArgumentException(String.Format("[SqlQueryProvider] - This engine ('{0}') is not supportted.", dbEngine.ToString())); } }
public DbEngine(string engineDescription) { this.EngineAsString = engineDescription; this.Engine = this.GetDbEngineFromString(); }
public DbEngine(string engineDescription) { this.EngineAsString = engineDescription; this.Engine = this.GetDbEngineFromString(); }