Exemple #1
0
        private List <string> GetEnabledDisabledIndexNames(ITableInfo tableInfo, bool isEnabled)
        {
            var indexNamesTemplate = new GetIndexes(tableInfo.DbName, tableInfo.SchemaName, tableInfo.TableName, isEnabled);
            var indexNamesQuery    = indexNamesTemplate.TransformText();

            Console.WriteLine(indexNamesQuery);
            DataTable indexNamesTable;

            try
            {
                indexNamesTable = _queryHelper.ExecuteQueryWithoutParams(tableInfo.DbConnectionString, indexNamesQuery);
            }
            catch (Exception ex)
            {
                throw new IndexServiceException("An error happened while trying to get index names.", ex);
            }

            var columnNames = new List <string>();

            foreach (var rowObject in indexNamesTable.Rows)
            {
                var row = (DataRow)rowObject;
                columnNames.Add((string)row[0]);
            }

            return(columnNames);
        }
        public Dictionary <string, string> GetColumnNamesAndTypes(ITableInfo tableInfo, List <string> columnNames)
        {
            var columnTypesTemplate = new GetColumnTypes(tableInfo.DbName, tableInfo.SchemaName, tableInfo.TableName, columnNames);
            var columnTypesQuery    = columnTypesTemplate.TransformText();

            //Console.WriteLine(columnTypesQuery);
            DataTable columnTypesTable;

            try
            {
                columnTypesTable = _queryHelper.ExecuteQueryWithoutParams(tableInfo.DbConnectionString, columnTypesQuery);
            }
            catch (Exception ex)
            {
                throw new ColumnTypesException("An error happened while trying to get column types.", ex);
            }

            var columnsAndTypes = new Dictionary <string, string>();

            foreach (var rowObject in columnTypesTable.Rows)
            {
                var row = (DataRow)rowObject;
                columnsAndTypes.Add((string)row[GetColumnTypes.columnName],
                                    (string)row[GetColumnTypes.columnType]);
            }

            return(columnsAndTypes);
        }
Exemple #3
0
        public bool IsWhereConditionValid(string connectionString, TableConfig tableConfig)
        {
            if (string.IsNullOrEmpty(tableConfig.Where))
            {
                return(true);
            }

            try
            {
                _sqlHelper.ExecuteQueryWithoutParams(connectionString, $"select top (1)* from {tableConfig.FullTableName} where {tableConfig.Where};");
                return(true);
            }
            catch (SqlException ex)
            {
                Log.Error($"Error while checking the where condition of table {tableConfig.FullTableName}. Connection string: {connectionString}." +
                          $"Message: {ex.Message}.");
                return(false);
            }
        }
 protected override List <string> GetLinkedServerNames(string connectionString)
 {
     return(_queryHelper.ExecuteQueryWithoutParams(connectionString, "select * from sys.servers;").AsEnumerable().Select(r => r.Field <string>(1))
            .Select(x => "[" + x + "]").ToList());;
 }