Example #1
0
        public IndexCollation(SqlType type, CollationColumn[] columns, string function)
        {
            if (columns.Length == 0)
                throw new ArgumentException("Cannot create an empty collation.", "columns");

            if (columns.Length > 1) {
                if (!(type is SqlCompositeType))
                    throw new ArgumentException("Composite indexes must be represented by composite-type");

                SqlCompositeType ctype = (SqlCompositeType) type;
                if (ctype.PartCount != columns.Length)
                    throw new ArgumentException("Composite type size different to the number of columns given", "columns");
            }

            // Can't contain identical columns
            for (int i = 0; i < columns.Length; ++i) {
                for (int n = 0; n < columns.Length; ++n) {
                    if (i != n && columns[i].ColumnName.Equals(columns[n].ColumnName))
                        throw new ArgumentException("Repeat column '" + columns[i] +"' name");
                }
            }

            this.type = type;
            this.function = function;
            this.columns = (CollationColumn[]) columns.Clone();
        }
Example #2
0
 public IndexCollation(SqlType type, CollationColumn[] columns)
     : this(type, columns, null)
 {
 }
Example #3
0
 public IndexCollation(SqlType type, CollationColumn column)
     : this(type, new CollationColumn[] { column }, null)
 {
 }
Example #4
0
        public IndexCollation Reverse()
        {
            CollationColumn[] reverseColumns = new CollationColumn[columns.Length];
            for (int i = 0; i < columns.Length; i++)
                reverseColumns[i] = new CollationColumn(columns[i].ColumnName, !columns[i].Ascending);

            return new IndexCollation(type, reverseColumns, function);
        }
        private IndexCollation DecodeCollation(SystemTable table)
        {
            string[] columnNames = index.ColumnNames;

            // Each column is encoded as '(+|-)[column name]' representing ascending
            // or descending order of the column.
            int sz = columnNames.Length;
            CollationColumn[] sortColumns = new CollationColumn[sz];
            SqlType[] columnTypes = new SqlType[sz];

            // For each column in the index,
            for (int i = 0; i < sz; ++i) {
                string columnName = columnNames[i];
                bool ascending = index.ColumnOrder[i];

                columnTypes[i] = table.Columns[columnName].Type;

                // Fail if the column is a type we can't index
                if (columnTypes[i].IsBinary)
                    //TODO: check better...
                    return null;

                sortColumns[i] = new CollationColumn(columnName, ascending);
            }

            // No columns, so return null
            if (sz == 0)
                return null;

            if (sz == 1)
                // Create the collation
                return new IndexCollation(columnTypes[0], sortColumns[0]);

            SqlCompositeType compositeType = new SqlCompositeType(columnTypes);
            return new IndexCollation(compositeType, sortColumns);
        }