/// <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); }
private static bool IsNumberType(int type) { return(HsqlTypes.isNumberType(type)); }
/// <summary> /// Determines whether the given provider-specific data /// type code indicates that a corresponding data element /// represents some kind of number value. /// </summary> /// <param name="type"> /// The provide-specific data type code. /// </param> /// <returns> /// <c>true</c> if the given code denotes an SQL number data type; /// otherwise, <c>false</c>. /// </returns> public static bool IsNumberProviderType(int type) { return(HsqlTypes.isNumberType(type)); }
internal static string ResultMetaDataToString(ResultMetaData rmd) { StringBuilder sb = new StringBuilder(); int columnCount = rmd.colTypes.Length; for (int i = 0; i < columnCount; i++) { if (i > 0) { sb.AppendLine(","); } sb.AppendFormat("{0}: ", i); ColumnMetaData cmd = new ColumnMetaData(); int type = rmd.colTypes[i]; cmd.catalogName = (rmd.catalogNames[i] == null) ? "" : rmd.catalogNames[i]; cmd.schemaName = (rmd.schemaNames[i] == null) ? "" : rmd.schemaNames[i]; cmd.tableName = rmd.tableNames[i] == null ? "" : rmd.tableNames[i]; cmd.columnName = rmd.colNames[i] == null ? "" : rmd.colNames[i]; cmd.columnLabel = rmd.colLabels[i] == null ? "" : rmd.colLabels[i]; cmd.columnType = type; cmd.columnTypeName = HsqlTypes.getTypeString(type); cmd.isWritable = rmd.isWritable[i]; cmd.isReadOnly = !cmd.isWritable; cmd.isAutoIncrement = rmd.isIdentity[i]; cmd.isNullable = rmd.colNullable[i]; cmd.columnClassName = rmd.classNames[i]; if (string.IsNullOrEmpty(cmd.columnClassName)) { cmd.columnClassName = HsqlTypes.getColStClsName(type); } if (HsqlTypes.acceptsPrecisionCreateParam(type)) { if (rmd.colSizes[i] == 0) { cmd.columnDisplaySize = HsqlTypes.getMaxDisplaySize(type); } else { cmd.columnDisplaySize = rmd.colSizes[i]; if (HsqlTypes.acceptsScaleCreateParam(type)) { if (rmd.colScales[i] != 0) { cmd.columnDisplaySize += (1 + rmd.colScales[i]); } } } } else { cmd.columnDisplaySize = HsqlTypes.getMaxDisplaySize(type); } if (HsqlTypes.isNumberType(type) && HsqlTypes.acceptsPrecisionCreateParam(type)) { cmd.precision = rmd.colSizes[i]; if (cmd.precision == 0) { cmd.precision = HsqlTypes.getPrecision(type); } } else { cmd.precision = HsqlTypes.getPrecision(type); } if (HsqlTypes.acceptsScaleCreateParam(type)) { cmd.scale = rmd.colScales[i]; } JavaBoolean iua = HsqlTypes.isUnsignedAttribute(type); cmd.isSigned = ((iua != null) && !iua.booleanValue()); JavaBoolean ics = HsqlTypes.isCaseSensitive(type); cmd.isCaseSensitive = ((ics != null) && ics.booleanValue()); cmd.isSearchable = HsqlTypes.isSearchable(type); sb.Append(cmd.toString()); } return(sb.ToString()); }