private async Task <List <SqlColumnInfo> > GetTableSchema(SqlQueryExecutor queryExecutor, string tablePath) { var databaseName = tablePath.Split('.').First(); var tableName = tablePath.Split('.').Last().Replace("[", "").Replace("]", ""); var query = "SELECT COLUMN_NAME, IS_NULLABLE, DATA_TYPE " + $"FROM {databaseName}.INFORMATION_SCHEMA.COLUMNS " + $"WHERE TABLE_NAME = '{tableName}'"; var columns = queryExecutor.ExecuteReaderAsync(query); var columnInformation = new List <SqlColumnInfo>(); await foreach (var column in columns) { var columnName = (string)column["COLUMN_NAME"]; var isNullable = column["IS_NULLABLE"].Equals("YES"); var dataType = (string)column["DATA_TYPE"]; columnInformation.Add(new SqlColumnInfo(columnName, isNullable, dataType)); } return(columnInformation); }
public MssqlRdDataStorage( string id, string serverAddress, string databaseName, string sqlUserName, string sqlUserPassword, IIdGeneratorManager idGeneratorManager) { Id = id; this.databaseName = databaseName; this.idGeneratorManager = idGeneratorManager; var sqlConnectionString = new SqlConnectionStringBuilder { DataSource = serverAddress, InitialCatalog = databaseName, UserID = sqlUserName, Password = sqlUserPassword }.ConnectionString; queryBuilder = new QueryBuilder(fieldName => fieldName.Replace('.', GenericDataContainerTraversal.PathDelimiter)); sqlQueryExecutor = new SqlQueryExecutor(sqlConnectionString); }
public SqlTableSetup( string dataType, string server, string tableName, string username, string passwordEnvironmentVariable, string idColumnName) { DataType = dataType; Server = server; TableName = tableName; Username = username; PasswordEnvironmentVariable = passwordEnvironmentVariable; IdColumnName = idColumnName; ConnectionString = new SqlConnectionStringBuilder { DataSource = server, UserID = username, Password = Secrets.Get(passwordEnvironmentVariable) }.ConnectionString; QueryExecutor = new SqlQueryExecutor(ConnectionString); ReservationContainerBuilder = new ReservationContainerBuilder(QueryExecutor, TableName); }
public ReservationContainerBuilder(SqlQueryExecutor queryExecutor, string tableName) { columnInfos = Task.Run(async() => await GetTableSchema(queryExecutor, tableName)).Result; }