/// <summary> /// Fills the table. /// </summary> /// <param name="connection">The connection.</param> /// <param name="table">The table.</param> /// <param name="restrictions">The restrictions.</param> public override void FillTable(HsqlConnection connection, DataTable table, string[] restrictions) { restrictions = GetRestrictions(restrictions, 4); string catalogName = restrictions[0]; string schemaNamePattern = restrictions[1]; string tableNamePattern = restrictions[2]; string constraintNamePattern = restrictions[3]; if (WantsIsNull(schemaNamePattern) || WantsIsNull(tableNamePattern) || WantsIsNull(constraintNamePattern)) { return; } StringBuilder query = new StringBuilder(sql); query //.Append(And("TABLE_CATALOG", "=", catalogName)) .Append(And("TABLE_SCHEMA", "LIKE", schemaNamePattern)) .Append(And("TABLE_NAME", "LIKE", tableNamePattern)) .Append(And("CONSTRAINT_NAME", "LIKE", constraintNamePattern)); using (HsqlDataReader reader = Execute(connection, query.ToString())) { object[] values = new object[reader.FieldCount]; while (reader.Read()) { reader.GetValues(values); string constraintCatalog = (string)values[0]; string constraintSchema = (string)values[1]; string constraintName = (string)values[2]; string constraintType = (string)values[3]; string tableCatalog = (string)values[4]; string tableSchema = (string)values[5]; string tableName = (string)values[6]; string isDeferrable = (string)values[7]; string initiallyDeferred = (string)values[8]; string checkClause = (string)values[9]; AddRow( table, constraintCatalog, constraintSchema, constraintName, constraintType, tableCatalog, tableSchema, tableName, isDeferrable, initiallyDeferred, checkClause ); } } }
public void ReadFromStream() { HsqlDataReader expected = NewTestSubject(); MemoryStream ms = new MemoryStream(HsqlDataReader.ToByteArray(expected)); HsqlDataReader.WriteToStream(ms, expected); ms.Position = 0; HsqlDataReader actual = HsqlDataReader.ReadFromStream(ms); Assert.AreEqual(expected.Depth, actual.Depth, "Depth"); Assert.AreEqual(expected.FieldCount, actual.FieldCount, "FieldCount"); Assert.AreEqual(expected.HasRows, actual.HasRows, "HasRows"); Assert.AreEqual(expected.IsClosed, actual.IsClosed, "IsClosed"); Assert.AreEqual(expected.RecordsAffected, actual.RecordsAffected, "RecordsAffected"); Assert.AreEqual(expected.VisibleFieldCount, actual.VisibleFieldCount, "VisibleFieldCount"); object[] expectedValues = new object[expected.FieldCount]; object[] actualValues = new object[actual.FieldCount]; while (expected.Read()) { Assert.That(actual.Read()); expected.GetValues(expectedValues); actual.GetValues(actualValues); for (int i = 0; i < expectedValues.Length; i++) { Assert.AreEqual(expectedValues[i], actualValues[i]); } } }
/// <summary> /// Fills a <c>Databases</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 fill.</param> /// <param name="restrictions">The restrictions.</param> public override void FillTable(HsqlConnection connection, DataTable table, string[] restrictions) { string databaseNamePattern = GetRestrictions(restrictions, 1)[0]; if (WantsIsNull(databaseNamePattern)) { return; } StringBuilder query = new StringBuilder(sql); query.Append(And("value", "LIKE", databaseNamePattern)); using (HsqlDataReader reader = Execute(connection, query.ToString())) { object[] values = new object[reader.FieldCount]; while (reader.Read()) { reader.GetValues(values); string databaseName = (string)values[0]; AddRow(table, databaseName, null, null); } } }
public void GetSqlString() { HsqlDataReader testSubject = NewTestSubject(); SqlString actual = testSubject.GetSqlString(ColumnOrdinalFor.VarChar); Assert.Fail("TODO"); }
public void GetSqlSingle() { HsqlDataReader testSubject = NewTestSubject(); SqlSingle actual = testSubject.GetSqlSingle(ColumnOrdinalFor.Real); Assert.Fail("TODO"); }
public void GetSqlInt16() { HsqlDataReader testSubject = NewTestSubject(); SqlInt16 actual = testSubject.GetSqlInt16(ColumnOrdinalFor.SmallInt); Assert.Fail("TODO"); }
public void GetSqlBoolean() { HsqlDataReader testSubject = NewTestSubject(); SqlBoolean actual = testSubject.GetSqlBoolean(ColumnOrdinalFor.Boolean); Assert.Fail("TODO"); }
public void GetFloat() { HsqlDataReader testSubject = NewTestSubject(); float actual = testSubject.GetFloat(ColumnOrdinalFor.Real); Assert.Fail("TODO"); }
public void GetSqlDateTime() { HsqlDataReader testSubject = NewTestSubject(); SqlDateTime actual = testSubject.GetSqlDateTime(ColumnOrdinalFor.Timestamp); Assert.Fail("TODO"); }
public void GetSqlBinary() { HsqlDataReader testSubject = NewTestSubject(); SqlBinary actual = testSubject.GetSqlBinary(ColumnOrdinalFor.Binary); Assert.Fail("TODO"); }
public void GetSqlChars() { HsqlDataReader testSubject = NewTestSubject(); SqlChars actual = testSubject.GetSqlChars(ColumnOrdinalFor.Char); Assert.Fail("TODO"); }
public void GetSqlGuid() { HsqlDataReader testSubject = NewTestSubject(); SqlGuid actual = testSubject.GetSqlGuid(ColumnOrdinalFor.Guid); Assert.Fail("TODO"); }
public void GetDouble() { HsqlDataReader testSubject = NewTestSubject(); double actual = testSubject.GetDouble(ColumnOrdinalFor.Double); Assert.Fail("TODO"); }
public void GetDataTypeName() { HsqlDataReader testSubject = NewTestSubject(); string actual = testSubject.GetDataTypeName(ColumnOrdinalFor.Bigint); Assert.Fail("TODO"); }
public void GetSqlInt32() { HsqlDataReader testSubject = NewTestSubject(); SqlInt32 actual = testSubject.GetSqlInt32(ColumnOrdinalFor.Integer); Assert.Fail("TODO"); }
public void GetSqlByte() { HsqlDataReader testSubject = NewTestSubject(); SqlByte actual = testSubject.GetSqlByte(ColumnOrdinalFor.TinyInt); Assert.Fail("TODO"); }
public void Close() { HsqlDataReader testSubject = NewTestSubject(); testSubject.Close(); Assert.Fail("TODO"); }
public void GetSqlInt64() { HsqlDataReader testSubject = NewTestSubject(); SqlInt64 actual = testSubject.GetSqlInt64(ColumnOrdinalFor.Bigint); Assert.Fail("TODO"); }
public void GetSqlXml() { HsqlDataReader testSubject = NewTestSubject(); SqlXml actual = testSubject.GetSqlXml(ColumnOrdinalFor.Xml); Assert.Fail("TODO"); }
public void GetSqlMoney() { HsqlDataReader testSubject = NewTestSubject(); SqlMoney actual = testSubject.GetSqlMoney(ColumnOrdinalFor.Decimal); Assert.Fail("TODO"); }
/// <summary> /// Fills the procedures table. /// </summary> /// <param name="connection">The connection.</param> /// <param name="table">The table.</param> /// <param name="restrictions">The restrictions.</param> public override void FillTable(HsqlConnection connection, DataTable table, string[] restrictions) { restrictions = GetRestrictions(restrictions, 4); string catalogName = restrictions[0]; string specificSchemaPattern = restrictions[1]; string specificNamePattern = restrictions[2]; string typePattern = restrictions[3]; if (WantsIsNull(specificSchemaPattern) || WantsIsNull(specificNamePattern) || WantsIsNull(typePattern)) { return; } StringBuilder query = new StringBuilder(sql); query //.Append(And("SPECIFIC_CATALOG", "=", catalogName)) .Append(And("SPECIFIC_SCHEMA", "LIKE", specificSchemaPattern)) .Append(And("SPECIFIC_NAME", "LIKE", specificNamePattern)) .Append(And("ROUTINE_TYPE", "LIKE", typePattern)) .Append(" ORDER BY 1, 2, 3"); using (HsqlDataReader reader = Execute(connection, query.ToString())) { object[] values = new object[reader.FieldCount]; while (reader.Read()) { reader.GetValues(values); string specificCatalog = (string)values[0]; string specificSchema = (string)values[1]; string specifcName = (string)values[2]; string routineCatalog = (string)values[3]; string routineSchema = (string)values[4]; string routineName = (string)values[5]; string routineType = (string)values[6]; DateTime?created = (DateTime?)values[7]; DateTime?lastAltered = (DateTime?)values[8]; AddRow( table, specificCatalog, specificSchema, specifcName, routineCatalog, routineSchema, routineName, routineType, created, lastAltered); } } }
/// <summary> /// Fills the tables table. /// </summary> /// <param name="connection">The connection.</param> /// <param name="table">The table.</param> /// <param name="restrictions">The restrictions.</param> public override void FillTable(HsqlConnection connection, DataTable table, string[] restrictions) { restrictions = GetRestrictions(restrictions, 4); string catalogName = restrictions[0]; string schemaPattern = restrictions[1]; string tablePattern = restrictions[2]; string typePattern = restrictions[3]; if (schemaPattern != null && schemaPattern.StartsWith("\"") && schemaPattern.EndsWith("\"")) { schemaPattern = schemaPattern.Substring(1, schemaPattern.Length - 2); } StringBuilder query = new StringBuilder(sql); query //.Append(And("TABLE_CAT", "=", catalogName)) .Append(And("TABLE_SCHEM", "LIKE", schemaPattern)) .Append(And("TABLE_NAME", "LIKE", tablePattern)); if (typePattern != null) { string[] types = typePattern.Split(Comma); if (types.Length == 1) { query.Append(And("TABLE_TYPE", "LIKE", types[0])); } else { query.Append(And("TABLE_TYPE", "IN", ToSQLInList(types))); } } using (HsqlDataReader reader = Execute(connection, query.ToString())) { object[] values = new object[reader.FieldCount]; while (reader.Read()) { reader.GetValues(values); string tableCatalog = (string)values[0]; string tableSchema = (string)values[1]; string tableName = (string)values[2]; string tableType = (string)values[3]; AddRow( table, tableCatalog, tableSchema, tableName, tableType); } } }
public void GetSchemaTable() { HsqlDataReader testSubject = NewTestSubject(); DataTable schemaTable = testSubject.GetSchemaTable(); Assert.Fail("TODO"); }
public void GetDecimal() { HsqlDataReader testSubject = NewTestSubject(); decimal actualDecimal = testSubject.GetDecimal(ColumnOrdinalFor.Decimal); decimal actualNumeric = testSubject.GetDecimal(ColumnOrdinalFor.Numeric); Assert.Fail("TODO"); }
/// <summary> /// Returns the collection of currently valid initial schema names, /// given the specified context. /// </summary> /// <param name="context"> /// An <see cref="ITypeDescriptorContext"></see> whose <c>Instance</c> /// property supplies the <c>HsqlConnectionStringBuilder</c> use to /// connect to a data source to retrieve the currently valid initial /// schema names. /// </param> /// <returns> /// A <see cref="TypeConverter.StandardValuesCollection"/> that holds /// collection of currently valid initial schema names. /// </returns> public override TypeConverter.StandardValuesCollection GetStandardValues( ITypeDescriptorContext context) { if (!IsStandardValuesSupported(context)) { return(null); } List <string> values = new List <string>(); try { HsqlConnectionStringBuilder builder = (HsqlConnectionStringBuilder)context.Instance; // TODO: this is sub-optimal, but is currently the best (only?) // solution to the problem of how to avoid creating and/or // leaving open embedded database instances. if (IsEmbeddedProtocol(builder)) { builder = new HsqlConnectionStringBuilder( builder.ConnectionString); builder.AutoShutdown = true; builder.IfExists = true; } using (HsqlConnection connection = new HsqlConnection()) { connection.ConnectionString = builder.ConnectionString; using (HsqlCommand command = new HsqlCommand( connection, SchemaQuery)) { connection.Open(); using (HsqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { values.Add(reader.GetString(0)); } } } } } catch (Exception exception) { #if DEBUG Debug.WriteLine(exception); #endif } return(new TypeConverter.StandardValuesCollection(values)); }
public void FromByteArray() { HsqlDataReader testSubject = NewTestSubject(); byte[] bytes = HsqlDataReader.ToByteArray(testSubject); HsqlDataReader actual = HsqlDataReader.FromByteArray(bytes); Assert.Fail("TODO"); }
public void GetBytes() { HsqlDataReader testSubject = NewTestSubject(); byte[] buffer = new byte[4]; long bytesRead = testSubject.GetBytes(ColumnOrdinalFor.Binary, 0, buffer, 0, 4); Assert.Fail("TODO"); }
public void GetChars() { HsqlDataReader testSubject = NewTestSubject(); char[] buffer = new char[4]; long charsRead = testSubject.GetChars(ColumnOrdinalFor.LongVarChar, 0, buffer, 0, buffer.Length); Assert.Fail("TODO"); }
/// <summary> /// Fills the table. /// </summary> /// <param name="connection">The connection.</param> /// <param name="table">The table.</param> /// <param name="restrictions">The restrictions.</param> public override void FillTable(HsqlConnection connection, DataTable table, string[] restrictions) { restrictions = GetRestrictions(restrictions, 3); string catalogName = restrictions[0]; string schemaNamePattern = restrictions[1]; string sequenceNamePattern = restrictions[2]; if (WantsIsNull(schemaNamePattern) || WantsIsNull(sequenceNamePattern)) { return; } StringBuilder query = new StringBuilder(sql); query //.Append(And("SEQUENCE_CATALOG", "=", catalogName)) .Append(And("SEQUENCE_SCHEMA", "LIKE", schemaNamePattern)) .Append(And("SEQUENCE_NAME", "LIKE", sequenceNamePattern)); using (HsqlDataReader reader = Execute(connection, query.ToString())) { object[] values = new object[reader.FieldCount]; while (reader.Read()) { reader.GetValues(values); string sequenceCatalog = (string)values[0]; string sequenceSchema = (string)values[1]; string sequenceName = (string)values[2]; string dtdIdentifier = (string)values[3]; string maximumValue = (string)values[4]; string minimumValue = (string)values[5]; string increment = (string)values[6]; string cycleOption = (string)values[7]; string startWith = (string)values[8]; AddRow( table, sequenceCatalog, sequenceSchema, sequenceName, dtdIdentifier, maximumValue, minimumValue, increment, cycleOption, startWith ); } } }
public void GetOrdinal() { HsqlDataReader testSubject = NewTestSubject(); for (int i = 0; i < testSubject.FieldCount; i++) { int actual = testSubject.GetOrdinal("COLUMN_" + i); Assert.AreEqual(i, actual); } }
public void NextResult() { HsqlDataReader testSubject = new HsqlDataReader(new int[] { 1, 2, 3, 4 }); Assert.AreEqual(1, testSubject.RecordsAffected); Assert.That(testSubject.NextResult()); Assert.AreEqual(2, testSubject.RecordsAffected); Assert.That(testSubject.NextResult()); Assert.AreEqual(3, testSubject.RecordsAffected); Assert.That(testSubject.NextResult()); Assert.AreEqual(4, testSubject.RecordsAffected); Assert.That(!testSubject.NextResult()); }
/// <summary> /// Computes the key info dictionary for the column metadata of the /// given data reader. /// </summary> /// <remarks> /// Depending upon the column metadata already present in the data /// reader, it may be required to perform further access to the /// originating data source using the reader's /// <c>OriginatingConnection</c>. This in turn implies that the /// <c>OriginatingConnection</c> must be open and must still /// represent the originating session on the originating data source; /// otherwise, the reported key info may be incorrect or the attempt /// access the data source may simply fail. /// </remarks> /// <param name="reader"> /// The reader for which to compute the column metadata key info map. /// </param> /// <returns> /// Map {ColumnIdentifier=>KeyInfo} /// </returns> /// <exception cref="HsqlDataSourceException"> /// If a data access error occurs. /// </exception> internal static Dictionary<ColumnIdentifier, KeyInfo> GetKeyInfo( HsqlDataReader reader) { ResultMetaData metaData = reader.m_result.metaData; Dictionary<TableIdentifier, object> tableSet = new Dictionary<TableIdentifier, object>(); object placeholder = new object(); string[] schemaNames = metaData.schemaNames; string[] tableNames = metaData.tableNames; string[] columnNames = metaData.colNames; int count = columnNames.Length; for (int i = 0; i < count; i++) { string tableName = tableNames[i]; string columnName = columnNames[i]; if (string.IsNullOrEmpty(tableName) || string.IsNullOrEmpty(columnName)) { // not a table column continue; } string schemaName = schemaNames[i]; TableIdentifier tableIdentifier = new TableIdentifier( schemaName, tableName); tableSet[tableIdentifier] = placeholder; } Dictionary<ColumnIdentifier, KeyInfo> columnMap = new Dictionary<ColumnIdentifier, KeyInfo>(); if (tableSet.Count == 0) { return columnMap; } StringBuilder sb = new StringBuilder('('); count = 0; foreach (TableIdentifier tableIdentifier in tableSet.Keys) { if (count > 0) { sb.Append(" OR "); } count++; sb.Append("(bri.table_schem"); string schemaName = tableIdentifier.m_schema; if (string.IsNullOrEmpty(schemaName)) { sb.Append(" IS NULL "); } else { sb.Append(" = ").Append(StringConverter.toQuotedString( schemaName, '\'', /*escape inner quotes*/ true)); } string tableName = tableIdentifier.m_table; sb.Append(" AND bri.table_name = ").Append( StringConverter.toQuotedString(tableName, '\'', /*escape inner quotes*/ true)); sb.Append(')'); } sb.Append(')'); string predicate = sb.ToString(); using (HsqlCommand command = reader.OriginatingConnection.CreateCommand()) { command.CommandText = string.Format(KeyInfoQuery, predicate); command.CommandType = CommandType.Text; using (HsqlDataReader keyInfoReader = command.ExecuteReader()) { while (keyInfoReader.Read()) { bool isKey = keyInfoReader.GetBoolean(3); if (!isKey) { continue; } string schema = keyInfoReader.GetString(0); string table = keyInfoReader.GetString(1); string column = keyInfoReader.GetString(2); ColumnIdentifier key = new ColumnIdentifier(schema, table, column); if (!columnMap.ContainsKey(key)) { KeyInfo keyInfo = new KeyInfo(); keyInfo.m_isKey = true; keyInfo.m_isUnique = false; columnMap.Add(key, keyInfo); } } } } return columnMap; }
/// <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; }