示例#1
0
 public void ToDataType()
 {
     Assert.AreEqual(typeof(object), HsqlConvert.ToDataType(HsqlProviderType.Array));
     Assert.AreEqual(typeof(long), HsqlConvert.ToDataType(HsqlProviderType.BigInt));
     Assert.AreEqual(typeof(byte[]), HsqlConvert.ToDataType(HsqlProviderType.Binary));
     Assert.AreEqual(typeof(object), HsqlConvert.ToDataType(HsqlProviderType.Blob));
     Assert.AreEqual(typeof(bool), HsqlConvert.ToDataType(HsqlProviderType.Boolean));
     Assert.AreEqual(typeof(string), HsqlConvert.ToDataType(HsqlProviderType.Char));
     Assert.AreEqual(typeof(object), HsqlConvert.ToDataType(HsqlProviderType.Clob));
     Assert.AreEqual(typeof(object), HsqlConvert.ToDataType(HsqlProviderType.DataLink));
     Assert.AreEqual(typeof(DateTime), HsqlConvert.ToDataType(HsqlProviderType.Date));
     Assert.AreEqual(typeof(decimal), HsqlConvert.ToDataType(HsqlProviderType.Decimal));
     Assert.AreEqual(typeof(object), HsqlConvert.ToDataType(HsqlProviderType.Distinct));
     Assert.AreEqual(typeof(double), HsqlConvert.ToDataType(HsqlProviderType.Double));
     Assert.AreEqual(typeof(double), HsqlConvert.ToDataType(HsqlProviderType.Float));
     Assert.AreEqual(typeof(int), HsqlConvert.ToDataType(HsqlProviderType.Integer));
     Assert.AreEqual(typeof(object), HsqlConvert.ToDataType(HsqlProviderType.JavaObject));
     Assert.AreEqual(typeof(byte[]), HsqlConvert.ToDataType(HsqlProviderType.LongVarBinary));
     Assert.AreEqual(typeof(string), HsqlConvert.ToDataType(HsqlProviderType.LongVarChar));
     Assert.AreEqual(typeof(object), HsqlConvert.ToDataType(HsqlProviderType.Null));
     Assert.AreEqual(typeof(decimal), HsqlConvert.ToDataType(HsqlProviderType.Numeric));
     Assert.AreEqual(typeof(object), HsqlConvert.ToDataType(HsqlProviderType.Object));
     Assert.AreEqual(typeof(float), HsqlConvert.ToDataType(HsqlProviderType.Real));
     Assert.AreEqual(typeof(object), HsqlConvert.ToDataType(HsqlProviderType.Ref));
     Assert.AreEqual(typeof(short), HsqlConvert.ToDataType(HsqlProviderType.SmallInt));
     Assert.AreEqual(typeof(object), HsqlConvert.ToDataType(HsqlProviderType.Struct));
     Assert.AreEqual(typeof(DateTime), HsqlConvert.ToDataType(HsqlProviderType.Time));
     Assert.AreEqual(typeof(DateTime), HsqlConvert.ToDataType(HsqlProviderType.TimeStamp));
     Assert.AreEqual(typeof(sbyte), HsqlConvert.ToDataType(HsqlProviderType.TinyInt));
     Assert.AreEqual(typeof(byte[]), HsqlConvert.ToDataType(HsqlProviderType.VarBinary));
     Assert.AreEqual(typeof(string), HsqlConvert.ToDataType(HsqlProviderType.VarChar));
     Assert.AreEqual(typeof(string), HsqlConvert.ToDataType(HsqlProviderType.Xml));
 }
示例#2
0
        /// <summary>
        /// Fills a <c>DataTypes</c> metadata collection table
        /// using the given connection and restrictions.
        /// </summary>
        /// <param name="connection">The connection from which to fill the table.</param>
        /// <param name="table">The table to file.</param>
        /// <param name="restrictions">The restrictions.</param>
        public override void FillTable(HsqlConnection connection,
                                       DataTable table, string[] restrictions)
        {
            using (HsqlDataReader reader = Execute(connection, sql))
            {
                object[] values = new object[reader.FieldCount];

                while (reader.Read())
                {
                    reader.GetValues(values);

                    string providerTypeName      = (string)values[0];
                    int    providerDbType        = (int)values[1];
                    int?   columnSize            = (int?)values[2];
                    string literalPrefix         = (string)values[3];
                    string literalSuffix         = (string)values[4];
                    string createParameters      = (string)values[5];
                    short  nullability           = (short)(int)values[6];
                    bool?  isCaseSensitive       = (bool?)values[7];
                    short  searchability         = (short)(int)values[8];
                    bool?  isUnsigned            = (bool?)values[9];
                    bool?  isFixedPrecisionScale = (bool?)values[10];
                    bool?  isAutoIncrementable   = (bool?)values[11];
                    //string localTypeName = (string) values[12];
                    short?minimumScale = (short?)(int?)values[13];
                    short?maximumScale = (short?)(int?)values[14];
                    //int? sqlDataType = (int?) values[15];
                    //int? dateTimeSub = (int?)values[16];
                    //int? numPrecRadix = (int?)values[17];
                    //int? typeSub = (int?)values[18];

                    string createFormat         = ToCreateFormat(providerTypeName, createParameters);
                    string dataType             = Convert.ToString(HsqlConvert.ToDataType(providerDbType));
                    bool   isBestMatch          = IsBestMatchProviderTypeName(providerTypeName);
                    bool   isFixedLength        = IsFixedLength(providerDbType);
                    bool   isLong               = IsLongProviderType(providerDbType);
                    bool   isNullable           = IsNullable(nullability);
                    bool   isSearchable         = IsSearchable(searchability);
                    bool   isSearchableWithLike = IsSearchableWithLike(searchability);
                    bool   isConcurrencyType    = false;
                    bool   isLiteralSupported   = true;

                    AddRow(table,
                           providerTypeName, providerDbType,
                           columnSize,
                           createFormat, createParameters,
                           dataType, isAutoIncrementable, isBestMatch,
                           isCaseSensitive, isFixedLength, isFixedPrecisionScale, isLong,
                           isNullable, isSearchable, isSearchableWithLike, isUnsigned,
                           maximumScale, minimumScale, isConcurrencyType,
                           isLiteralSupported, literalPrefix, literalSuffix);
                }
            }
        }
        /// <summary>
        /// Retrieves a <c>DataTable</c> object representing the column
        /// metadata of the given data reader's current result.
        /// </summary>
        /// <param name="reader">
        /// A reader object for which to retrieve the column metadata.
        /// </param>
        /// <returns>
        /// A <c>DataTable</c> object representing the column metadata of the
        /// given data reader's current result.
        /// </returns>
        /// <exception cref="HsqlDataSourceException">
        /// If a data access error occurs.
        /// </exception>
        public static DataTable CreateSchemaTable(HsqlDataReader reader)
        {
            Result         result         = reader.m_result;
            int            columnCount    = result.getColumnCount();
            ResultMetaData metaData       = result.metaData;
            DataTable      table          = CreateTable(columnCount);
            bool           includeKeyInfo = reader.HasCommandBehavior(CommandBehavior.KeyInfo);
            Dictionary <ColumnIdentifier, KeyInfo> keyInfoMap = (includeKeyInfo)
                ? HsqlResultSetMetaData.GetKeyInfo(reader)
                : null;

            string catalogName = reader.OriginatingConnection.Database;

            for (int i = 0; i < columnCount; i++)
            {
                bool   isAutoIncrement  = metaData.isIdentity[i];
                string columnName       = metaData.colLabels[i];
                int    columnOrdinal    = i;
                int    columnSize       = metaData.colSizes[i];
                int    numericPrecision = metaData.colSizes[i];
                int    numericScale     = metaData.colScales[i];
                bool   isUnique         = false; // isAutoIncrement;
                bool   isKey            = isAutoIncrement;
                string baseServerName   = null;
                string baseCatalogName  = catalogName;//metaData.catalogNames[i];
                string baseColumnName   = metaData.colNames[i];
                string baseSchemaName   = metaData.schemaNames[i];
                string baseTableName    = metaData.tableNames[i];
                int    providerType     = metaData.colTypes[i];
                Type   dataType         = HsqlConvert.ToDataType(providerType);
                int    nullability      = metaData.colNullable[i];
                bool   allowDBNull      = isAutoIncrement || (nullability != 0);
                bool   isAliased        = (columnName != baseColumnName);
                bool   isExpression     = string.IsNullOrEmpty(baseTableName);
                bool   isIdentity       = isAutoIncrement;
                bool   isRowVersion     = false;
                bool   isHidden         = false;
                bool   isLong           = HsqlConvert.ToIsLongProviderType(providerType);
                bool   isReadOnly       = !metaData.isWritable[i];

                if ((columnSize == 0) &&
                    HsqlTypes.isCharacterType(providerType))
                {
                    columnSize = HsqlTypes.getPrecision(providerType);
                }

                if ((numericPrecision == 0) &&
                    HsqlTypes.isNumberType(providerType))
                {
                    numericPrecision = HsqlTypes.getPrecision(providerType);
                }

                if (includeKeyInfo)
                {
                    if (!(string.IsNullOrEmpty(baseTableName) ||
                          string.IsNullOrEmpty(baseColumnName)))
                    {
                        ColumnIdentifier key = new ColumnIdentifier(
                            baseSchemaName, baseTableName, baseColumnName);
                        KeyInfo keyInfo;

                        if (keyInfoMap.TryGetValue(key, out keyInfo))
                        {
                            isKey    = keyInfo.m_isKey;
                            isUnique = keyInfo.m_isUnique;
                        }
                    }
                }

                HsqlResultSetMetaData.AddRow(table, columnName, columnOrdinal,
                                             columnSize, numericPrecision, numericScale, isUnique,
                                             isKey, baseServerName, baseCatalogName, baseColumnName,
                                             baseSchemaName, baseTableName, dataType, allowDBNull,
                                             providerType, isAliased, isExpression, isIdentity,
                                             isAutoIncrement, isRowVersion, isHidden, isLong,
                                             isReadOnly);
            }

            DataColumnCollection columns = table.Columns;
            int count = columns.Count;

            for (int i = 0; i < count; i++)
            {
                columns[i].ReadOnly = true;
            }

            return(table);
        }