/// <summary>
 /// Nullifies the reference, if any, to the internally cached column
 /// label map, making it elligible for garbage collection.
 /// </summary>
 internal void DisposeColumnMap()
 {
     m_columnMap = null;
 }
        /// <summary>
        /// Gets the column ordinal, given the name of the column.
        /// </summary>
        /// <remarks>
        /// This method employs a search that is case-insensitive, proceeds
        /// from left to right and uses the following matching precedence:
        /// <list type="">
        /// <item>column label (SQL 'AS' ALIAS)</item>
        /// <item>'simple column name' (in base table or view)</item>
        /// <item>'simple-table-name.simple-column-name' (non-delimited form only)</item>
        /// <item>'schema.simple-table-name.simple-column-name' (non-delimited form only)</item>
        /// </list>
        /// </remarks>
        /// <param name="name">
        /// The character sequence for which to search
        /// </param>
        /// <returns>
        /// The zero-based ordinal of the first encountered column
        /// satisfying the search.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// When a <c>null</c> name is specified.
        /// </exception>        
        /// <exception cref="IndexOutOfRangeException">
        /// When the search concludes without finding a match.
        /// </exception>
        public override int GetOrdinal(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            int columnIndex;

            // faster lookup for subsequent access
            if (m_columnMap != null)
            {
                columnIndex = m_columnMap.get(name, -1);

                if (columnIndex >= 0)
                {
                    return columnIndex;
                }
            }

            string[] colLabels = m_metaData.colLabels;

            columnIndex = -1;
            StringComparison comparisonType
                = StringComparison.InvariantCultureIgnoreCase;

            // column labels first, to preference column aliases
            for (int i = 0; i < m_fieldCount; i++)
            {
                if (name.Equals(colLabels[i], comparisonType))
                {
                    columnIndex = i;

                    break;
                }
            }

            string[] colNames = m_metaData.colNames;

            // then base column names, to preference simple
            // quoted column idents that *may* contain "."
            if (columnIndex < 0)
            {
                for (int i = 0; i < m_fieldCount; i++)
                {
                    if (name.Equals(colNames[i], comparisonType))
                    {
                        columnIndex = i;

                        break;
                    }
                }
            }

            string[] tabNames = m_metaData.tableNames;

            // then table-qualified column names (again, quoted
            // table idents *may* contain "."
            if (columnIndex < 0)
            {
                for (int i = 0; i < m_fieldCount; i++)
                {
                    string tabName = tabNames[i];

                    if (string.IsNullOrEmpty(tabName))
                    {
                        continue;
                    }

                    string colName = colNames[i];

                    if (string.IsNullOrEmpty(colName))
                    {
                        continue;
                    }

                    if (name.Equals(tabName + "." + colName, comparisonType))
                    {
                        columnIndex = i;

                        break;
                    }
                }
            }

            string[] schemNames = m_metaData.schemaNames;

            // As a last resort, "fully" qualified column names
            // (we don't yet support catalog qualification)
            if (columnIndex < 0)
            {
                for (int i = 0; i < m_fieldCount; i++)
                {
                    string schemName = schemNames[i];

                    if (string.IsNullOrEmpty(schemName))
                    {
                        continue;
                    }

                    string tabName = tabNames[i];

                    if (string.IsNullOrEmpty(tabName))
                    {
                        continue;
                    }

                    string colName = colNames[i];

                    if (string.IsNullOrEmpty(colName))
                    {
                        continue;
                    }

                    string match = new StringBuilder(schemName)
                        .Append('.')
                        .Append(tabName)
                        .Append('.')
                        .Append(colName)
                        .ToString();

                    if (name.Equals(match, comparisonType))
                    {
                        columnIndex = i;

                        break;
                    }
                }
            }

            if (columnIndex < 0)
            {
                org.hsqldb.HsqlException ex
                    = org.hsqldb.Trace.error(
                        org.hsqldb.Trace.COLUMN_NOT_FOUND,
                        name);

                throw new IndexOutOfRangeException(ex.getMessage(), ex);
            }

            if (m_columnMap == null)
            {
                m_columnMap = new org.hsqldb.lib.IntValueHashMap();
            }

            m_columnMap.put(name, columnIndex);

            return columnIndex;
        }
        /// <summary>
        /// Initializes the <see cref="Tokenizer"/> class.
        /// </summary>
        static Tokenizer()
        {
            m_ValueTokens = new org.hsqldb.lib.IntValueHashMap();

            m_ValueTokens.put(Token.ValueFor.NULL,
                (int)SqlTokenType.Null);
            m_ValueTokens.put(Token.ValueFor.TRUE,
                (int)SqlTokenType.BooleanLiteral);
            m_ValueTokens.put(Token.ValueFor.FALSE,
                (int)SqlTokenType.BooleanLiteral);

            m_EnglishCulture = CultureInfo.GetCultureInfo("en");

            m_LongMaxValuePlusOne
                = JavaBigDecimal.valueOf(long.MaxValue)
                    .add(JavaBigDecimal.valueOf(1));
        }
 /// <summary>
 /// Nullifies the reference, if any, to the internally cached column
 /// label map, making it elligible for garbage collection.
 /// </summary>
 internal void DisposeColumnMap()
 {
     m_columnMap = null;
 }