static HsqlResult NewResult() { int columnCount = columns.GetUpperBound(1); HsqlResult result = new HsqlResult(columnCount); object[] row = new object[columnCount]; int i = 0; const int TypeOrdinal = 0; const int ValueOrdinal = 1; result.add(row); foreach (object[] column in columns) { HsqlProviderType dataType = (HsqlProviderType)column[TypeOrdinal]; row[i] = column[ValueOrdinal]; int scale = 0; switch (dataType) { case HsqlProviderType.Decimal: case HsqlProviderType.Numeric: { scale = 4; break; } } int size = HsqlTypes.getPrecision((int)dataType); result.metaData.catalogNames[i] = "mem:test"; result.metaData.classNames[i] = HsqlTypes.getTypeName((int)dataType); result.metaData.colLabels[i] = "COLUMN_" + i; result.metaData.colNames[i] = "C" + i; result.metaData.colNullable[i] = (int)BaseColumnNullability.Nullable; result.metaData.colScales[i] = scale; result.metaData.colSizes[i] = size; result.metaData.colTypes[i] = (int)dataType; result.metaData.isIdentity[i] = false; result.metaData.isLabelQuoted[i] = false; result.metaData.isWritable[i] = false; result.metaData.paramMode[i] = (int)ParameterMode.Unknown; result.metaData.schemaNames[i] = "PUBLIC"; result.metaData.tableNames[i] = "ALL_COL_TYPES"; } return(result); }
private static int ToDefaultPrecision(int type) { return(HsqlTypes.getPrecision(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); }
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()); }