/// <summary> /// Determines whether the given provider-specific data type code /// indicates that the corresponding data element represents an /// SQL character value. /// </summary> /// <param name="type"> /// A provider-specific data type code. /// </param> /// <returns> /// <c>true</c> if the given code denotes an SQL character data type; /// otherwise, <c>false</c>. /// </returns> public static bool IsProviderCharacterType(int type) { return(HsqlTypes.isCharacterType(type)); }
/// <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 IsCharacterType(int type) { return(HsqlTypes.isCharacterType(type)); }