Beispiel #1
0
        public override Type GetFieldType(int ordinal)
        {
            object temp = set.getObject(ConvertOrdnal(ordinal));

            if (temp == null)
            {
                int  typeCode = Meta.getColumnType(ConvertOrdnal(ordinal));
                Type rv       = H2Helper.GetType(typeCode);
                if (rv != null)
                {
                    return(rv);
                }
                string type = Meta.getColumnTypeName(ConvertOrdnal(ordinal));
                throw new NotImplementedException(type);
            }
            Type result = temp.GetType();

            if (result == typeof(java.lang.Integer))
            {
                result = typeof(int);
            }
            else if (result == typeof(java.lang.Long))
            {
                result = typeof(long);
            }
            else if (result == typeof(java.lang.Short))
            {
                result = typeof(short);
            }
            else if (result == typeof(java.lang.String))
            {
                result = typeof(String);
            }
            return(result);
        }
Beispiel #2
0
        public override DataTable GetSchemaTable()
        {
            /*
             * JDBC reference :
             * http://java.sun.com/j2se/1.5.0/docs/api/java/sql/ResultSetMetaData.html
             *
             * ADO.NET reference :
             * http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getschematable.aspx
             */
            var table                    = new DataTable();
            var ColumnName               = table.Columns.Add("ColumnName", typeof(String));
            var ColumnOrdinal            = table.Columns.Add("ColumnOrdinal", typeof(Int32));
            var ColumnSize               = table.Columns.Add("ColumnSize", typeof(Int32));
            var NumericPrecision         = table.Columns.Add("NumericPrecision", typeof(Int32));
            var NumericScale             = table.Columns.Add("NumericScale", typeof(Int32));
            var IsUnique                 = table.Columns.Add("IsUnique", typeof(bool));
            var IsKey                    = table.Columns.Add("IsKey", typeof(bool));
            var BaseServerName           = table.Columns.Add("BaseServerName", typeof(String));
            var BaseCatalogName          = table.Columns.Add("BaseCatalogName", typeof(String));
            var BaseColumnName           = table.Columns.Add("BaseColumnName", typeof(String));
            var BaseSchemaName           = table.Columns.Add("BaseSchemaName", typeof(String));
            var BaseTableName            = table.Columns.Add("BaseTableName", typeof(String));
            var DataType                 = table.Columns.Add("DataType", typeof(Type));
            var AllowDBNull              = table.Columns.Add("AllowDBNull", typeof(bool));
            var ProviderType             = table.Columns.Add("ProviderType");
            var IsAliased                = table.Columns.Add("IsAliased", typeof(bool));
            var IsExpression             = table.Columns.Add("IsExpression", typeof(bool));
            var IsIdentity               = table.Columns.Add("IsIdentity", typeof(bool));
            var IsAutoIncrement          = table.Columns.Add("IsAutoIncrement", typeof(bool));
            var IsRowVersion             = table.Columns.Add("IsRowVersion", typeof(bool));
            var IsHidden                 = table.Columns.Add("IsHidden", typeof(bool));
            var IsLong                   = table.Columns.Add("IsLong", typeof(bool));
            var IsReadOnly               = table.Columns.Add("IsReadOnly", typeof(bool));
            var ProviderSpecificDataType = table.Columns.Add("ProviderSpecificDataType");
            var DataTypeName             = table.Columns.Add("DataTypeName", typeof(String));
            var DbType                   = table.Columns.Add("DbType", typeof(DbType)); // not standard !!!
            //var XmlSchemaCollectionDatabase = table.Columns.Add("XmlSchemaCollectionDatabase");
            //var XmlSchemaCollectionOwningSchema = table.Columns.Add("XmlSchemaCollectionOwningSchema");
            //var XmlSchemaCollectionName = table.Columns.Add("XmlSchemaCollectionName");

            //var dbMeta = connection.connection.getMetaData();
            var tablesPksAndUniques = new Dictionary <String, KeyValuePair <HashSet <String>, HashSet <String> > >();
            var meta = Meta;

            var nCols = meta.getColumnCount();

            table.MinimumCapacity = nCols;
            for (int iCol = 1; iCol <= nCols; iCol++)
            {
                // Beware : iCol starts at 1 (JDBC convention)
                var row       = table.NewRow();
                var name      = meta.getColumnName(iCol);
                var label     = meta.getColumnLabel(iCol);
                var tableName = meta.getTableName(iCol);

                KeyValuePair <HashSet <String>, HashSet <String> > pksAndUniques;
                if (!tablesPksAndUniques.TryGetValue(tableName, out pksAndUniques))
                {
                    pksAndUniques = new KeyValuePair <HashSet <string>, HashSet <string> >(
                        connection.GetPrimaryKeysColumns(tableName),
                        connection.GetUniqueColumns(tableName)
                        );
                }

                row[ColumnName]       = label != null ? label : name;
                row[ColumnOrdinal]    = iCol - 1;
                row[BaseColumnName]   = name;
                row[BaseSchemaName]   = meta.getSchemaName(iCol);
                row[BaseTableName]    = tableName;
                row[ColumnSize]       = meta.getColumnDisplaySize(iCol);
                row[IsReadOnly]       = meta.isReadOnly(iCol);
                row[IsKey]            = pksAndUniques.Key.Contains(name);
                row[IsUnique]         = pksAndUniques.Value.Contains(name);
                row[DataTypeName]     = meta.getColumnTypeName(iCol);             // TODO check this !
                row[NumericPrecision] = meta.getPrecision(iCol);
                row[NumericScale]     = meta.getScale(iCol);
                var jdbcType = meta.getColumnType(iCol);
                var type     = H2Helper.GetType(jdbcType);
                var dbType   = H2Helper.GetDbType(jdbcType);
                row[DataType]    = type;
                row[DbType]      = dbType;
                row[AllowDBNull] = meta.isNullable(iCol);
                table.Rows.Add(row);
            }
            return(table);
            //throw new NotImplementedException();
        }
Beispiel #3
0
        Type DoGetFieldType(int ordinal)
        {
            int typeCode = Meta.getColumnType(ConvertOrdinal(ordinal));

            return(H2Helper.GetType(typeCode));
        }