Пример #1
0
        /// <summary>
        /// Parse the specified CREATE INDEX statement and returned the
        /// index representation as a DbIndex instance.
        /// </summary>
        /// <param name="sql">The CREATE INDEX sql statement</param>
        /// <returns>The DbIndex representation of the table.</returns>
        private static DbIndex ParseDbIndex(ref string sql)
        {
            DbIndex index = new DbIndex();
            Match   m     = _indexHeader.Match(sql);

            if (m.Success)
            {
                if (m.Groups[1].Success)
                {
                    index.IsUnique = true;
                }

                int start = m.Index + m.Length;
                index.IndexName = ParsePotentiallyDelimitedToken(sql, ref start);
                if (index.IndexName == null)
                {
                    throw DbUpgradeException.SchemaIsNotSupported();
                }

                // Search for occurence of "ON"
                int offset = sql.IndexOf("ON", start);
                if (offset == -1)
                {
                    throw DbUpgradeException.SchemaIsNotSupported();
                }
                start = offset + 2;

                index.TableName = ParsePotentiallyDelimitedToken(sql, ref start);
                if (index.TableName == null)
                {
                    throw DbUpgradeException.SchemaIsNotSupported();
                }

                sql = sql.Substring(start);
                if (!ScanToken(ref sql, "("))
                {
                    throw DbUpgradeException.SchemaIsNotSupported();
                }

                string cols = null;
                for (int i = 0; i < sql.Length; i++)
                {
                    if (sql[i] == ')')
                    {
                        cols = sql.Substring(0, i);
                        if (i < sql.Length - 1)
                        {
                            sql = sql.Substring(i + 1);
                        }
                        else
                        {
                            sql = string.Empty;
                        }
                        break;
                    }
                } // for
                if (cols == null)
                {
                    throw DbUpgradeException.SchemaIsNotSupported();
                }

                string[] parts = cols.Split(',');
                Dictionary <string, DbSortOrder> icols =
                    new Dictionary <string, DbSortOrder>();
                foreach (string p in parts)
                {
                    string      cn     = p.Trim();
                    string[]    cparts = cn.Split(' ', '\t');
                    DbSortOrder order  = DbSortOrder.Ascending;
                    if (cparts.Length == 2)
                    {
                        if (cparts[1].ToUpper() == "DESC")
                        {
                            order = DbSortOrder.Descending;
                        }
                        else
                        {
                            throw DbUpgradeException.SchemaIsNotSupported();
                        }
                    }

                    icols.Add(cparts[0].Trim().Trim('[', ']', '\'', '`', '\"'), order);
                }
                if (icols.Count == 0)
                {
                    throw DbUpgradeException.SchemaIsNotSupported();
                }
                index.IndexColumns = icols;

                return(index);
            }
            else
            {
                throw DbUpgradeException.SchemaIsNotSupported();
            }
        }
Пример #2
0
        private static string GetSortOrder(DbSortOrder sortOrder)
        {
            switch (sortOrder)
            {
                case DbSortOrder.Descending:
                    return "DESC";

                default:
                    return "ASC";
            }
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DbSortDescriptor"/> class.
 /// </summary>
 /// <param name="columnName">
 /// The column name.
 /// </param>
 /// <param name="sortOrder">
 /// The sort order.
 /// </param>
 public DbSortDescriptor(string columnName, DbSortOrder sortOrder)
 {
     ColumnName = columnName;
     SortOrder = sortOrder;
 }