예제 #1
0
        public static void CreateTable(this IDAC dac, TableSpecification tableSpecification)
        {
            var builder = dac.CreateSQLBuilder();

            builder.CreateTable(tableSpecification);
            dac.ExecuteBatch(builder);
        }
예제 #2
0
        public static DataTable ExecuteQuery(this IDAC dac, string query, params object[] args)
        {
            var builder = dac.CreateSQLBuilder();

            builder.Emit(query, args);
            return(ExecuteQuery(dac, builder.ToString()));
        }
예제 #3
0
        public static IDictionary <string, long> CountRecords(this IDAC dac, IEnumerable <string> tableNames = null)
        {
            var result = new Dictionary <string, long>();

            if (tableNames == null)
            {
                tableNames = dac.GetSchemaCached().Tables.Select(table => table.Name);
            }

            if (!tableNames.Any())
            {
                return(result);
            }

            var sqlBuilder = dac.CreateSQLBuilder();

            foreach (var table in tableNames.WithDescriptions())
            {
                if (table.Index > 0)
                {
                    sqlBuilder.NewLine().Emit("UNION ALL").NewLine();
                }
                sqlBuilder.Emit("SELECT '{0}', COUNT(1) FROM {1}", table.Item, SQLBuilderCommand.TableName(table.Item));
            }

            dac
            .ExecuteQuery(((Object)sqlBuilder).ToString())
            .Rows
            .Cast <DataRow>()
            .ForEach(row => result.Add(row.Get <string>(0), row.Get <long>(1)));
            return(result);
        }
예제 #4
0
        // Improve this
        public static DataTable Select(this IDAC dac, string tableName, IEnumerable <string> columns = null, bool distinct = false, int?limit = null, int?offset = null, IEnumerable <ColumnValue> columnMatches = null, string whereClause = null, string orderByClause = null)
        {
            var sqlBuilder = dac.CreateSQLBuilder();

            sqlBuilder.Select(tableName, columns: columns != null ? columns.Cast <object>() : null, distinct: distinct, limit: limit, offset: offset, columnMatches: columnMatches, whereClause: whereClause, orderByClause: orderByClause, endStatement: true);
            var table = dac.ExecuteQuery(sqlBuilder.ToString());

            table.TableName = tableName;
            return(table);
        }
예제 #5
0
        public static string QuickString(this IDAC dac, string sql, params object[] args)
        {
            var newBuilder = dac.CreateSQLBuilder();

            return(((Object)newBuilder.Emit(sql, args)).ToString());
        }
예제 #6
0
 public virtual ISQLBuilder CreateSQLBuilder()
 {
     return(DecoratedDAC.CreateSQLBuilder());
 }