public void ToProviderSpecificDataType() { Assert.AreEqual(typeof(java.sql.Array), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Array)); Assert.AreEqual(typeof(java.lang.Long), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.BigInt)); Assert.AreEqual(typeof(org.hsqldb.types.Binary), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Binary)); Assert.AreEqual(typeof(System.Data.Hsqldb.Common.Lob.IBlob), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Blob)); Assert.AreEqual(typeof(java.lang.Boolean), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Boolean)); Assert.AreEqual(typeof(string), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Char)); Assert.AreEqual(typeof(System.Data.Hsqldb.Common.Lob.IClob), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Clob)); Assert.AreEqual(typeof(java.net.URL), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.DataLink)); Assert.AreEqual(typeof(java.util.Date), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Date)); Assert.AreEqual(typeof(java.math.BigDecimal), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Decimal)); Assert.AreEqual(typeof(object), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Distinct)); Assert.AreEqual(typeof(java.lang.Double), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Double)); Assert.AreEqual(typeof(java.lang.Double), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Float)); Assert.AreEqual(typeof(java.lang.Integer), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Integer)); Assert.AreEqual(typeof(org.hsqldb.types.JavaObject), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.JavaObject)); Assert.AreEqual(typeof(org.hsqldb.types.Binary), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.LongVarBinary)); Assert.AreEqual(typeof(string), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.LongVarChar)); Assert.AreEqual(typeof(void), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Null)); Assert.AreEqual(typeof(java.math.BigDecimal), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Numeric)); Assert.AreEqual(typeof(System.Data.Hsqldb.Common.Sql.Types.SqlObject), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Object)); Assert.AreEqual(typeof(java.lang.Double), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Real)); Assert.AreEqual(typeof(java.sql.Ref), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Ref)); Assert.AreEqual(typeof(java.lang.Integer), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.SmallInt)); Assert.AreEqual(typeof(java.sql.Struct), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Struct)); Assert.AreEqual(typeof(java.sql.Time), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Time)); Assert.AreEqual(typeof(java.sql.Timestamp), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.TimeStamp)); Assert.AreEqual(typeof(java.lang.Integer), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.TinyInt)); Assert.AreEqual(typeof(org.hsqldb.types.Binary), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.VarBinary)); Assert.AreEqual(typeof(string), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.VarChar)); Assert.AreEqual(typeof(string), HsqlConvert.ToProviderSpecificDataType(org.hsqldb.Types.VARCHAR_IGNORECASE)); Assert.AreEqual(typeof(java.sql.SQLXML), HsqlConvert.ToProviderSpecificDataType(HsqlProviderType.Xml)); }
/// <summary> /// Adds a new <c>DataRow</c> to the given <c>DataTable</c>. /// </summary> /// <remarks> /// It is assumed the given table's column collection is /// compatibly pre-initialized. /// </remarks> /// <param name="dataTable"> /// The <c>DataTable</c> to which to add the row. /// </param> /// <param name="columnName"> /// Specifies the name of the column in the schema table. /// </param> /// <param name="columnOrdinal"> /// Specifies the ordinal of the column. /// </param> /// <param name="columnSize"> /// Specifies the size of the column. /// </param> /// <param name="numericPrecision"> /// Specifies the precision of the column data, if the data is numeric. /// </param> /// <param name="numericScale"> /// Specifies the scale of the column data, if the data is numeric. /// </param> /// <param name="isUnique"> /// Specifies whether a unique constraint applies to this column. /// </param> /// <param name="isKey"> /// Specifies whether this column is a key for the table. /// </param> /// <param name="baseServerName"> /// Specifies the server name of the column. /// </param> /// <param name="baseCatalogName"> /// The name of the catalog associated with the results of the latest /// query. /// </param> /// <param name="baseColumnName"> /// Specifies the name of the column in the schema table. /// </param> /// <param name="baseSchemaName"> /// Specifies the name of the schema in the schema table. /// </param> /// <param name="baseTableName"> /// Specifies the name of the table in the schema table. /// </param> /// <param name="dataType"> /// Specifies the type of data in the column. /// </param> /// <param name="allowDBNull"> /// Specifies whether value DBNull is allowed. /// </param> /// <param name="providerType"> /// Specifies the provider-specific data type of the column. /// </param> /// <param name="isAliased"> /// Specifies whether this column is aliased. /// </param> /// <param name="isExpression"> /// Specifies whether this column is an expression. /// </param> /// <param name="isIdentity"> /// Specifies whether this column is the identity for the schema table. /// </param> /// <param name="isAutoIncrement"> /// Specifies whether the column values in the column are automatically /// incremented. /// </param> /// <param name="isRowVersion"> /// Specifies whether this column contains row version information. /// </param> /// <param name="isHidden"> /// Specifies whether this column is hidden. /// </param> /// <param name="isLong"> /// Specifies whether this column contains long data. /// </param> /// <param name="isReadOnly"> /// Specifies whether this column is read-only. /// </param> public static void AddRow( DataTable dataTable, string columnName, int columnOrdinal, int columnSize, int numericPrecision, int numericScale, bool isUnique, bool isKey, string baseServerName, string baseCatalogName, string baseColumnName, string baseSchemaName, string baseTableName, Type dataType, bool allowDBNull, int providerType, bool isAliased, bool isExpression, bool isIdentity, bool isAutoIncrement, bool isRowVersion, bool isHidden, bool isLong, bool isReadOnly) { DataRow row = dataTable.NewRow(); row[STC.ColumnName] = columnName; row[STC.ColumnOrdinal] = columnOrdinal; row[STC.ColumnSize] = columnSize; row[STC.NumericPrecision] = numericPrecision; row[STC.NumericScale] = numericScale; row[STC.IsUnique] = isUnique; row[STC.IsKey] = isKey; row[STOC.BaseServerName] = baseServerName; row[STOC.BaseCatalogName] = baseCatalogName; row[STC.BaseColumnName] = baseColumnName; row[STC.BaseSchemaName] = baseSchemaName; row[STC.BaseTableName] = baseTableName; row[STC.DataType] = dataType; row[STC.AllowDBNull] = allowDBNull; row[STC.ProviderType] = providerType; row[STC.IsAliased] = isAliased; row[STC.IsExpression] = isExpression; row["IsIdentity"] = isIdentity; row[STOC.IsAutoIncrement] = isAutoIncrement; row[STOC.IsRowVersion] = isRowVersion; row[STOC.IsHidden] = isHidden; row[STC.IsLong] = isLong; row[STOC.IsReadOnly] = isReadOnly; row[STOC.ProviderSpecificDataType] = HsqlConvert.ToProviderSpecificDataType(providerType); row["DataTypeName"] = HsqlConvert.ToSqlDataTypeName(providerType); //row["XmlSchemaCollectionDatabase"] = null; //row["XmlSchemaCollectionOwningSchema"] = null; //row["XmlSchemaCollectionName"] = null; //row["UdtAssemblyQualifiedName"] = null; row[STC.NonVersionedProviderType] = providerType; dataTable.Rows.Add(row); }
public void LiteralValue() { List <LiteralValueTestParameters> testParameters = new List <LiteralValueTestParameters>(); testParameters.Add(new LiteralValueTestParameters( "1234", SqlTokenType.BigIntLiteral, HsqlProviderType.BigInt, HsqlValuePool.getLong(1234L), null, null)); testParameters.Add(new LiteralValueTestParameters( "TRUE", SqlTokenType.BooleanLiteral, HsqlProviderType.Boolean, JavaBoolean.TRUE, null, null)); testParameters.Add(new LiteralValueTestParameters( "2009-2-8", SqlTokenType.DateLiteral, HsqlProviderType.Date, HsqlDateTime.dateValue("2009-2-8"), null, null)); testParameters.Add(new LiteralValueTestParameters( "12345678987654321.12345678987654321", SqlTokenType.DecimalLiteral, HsqlProviderType.Decimal, new JavaDecimal("12345678987654321.12345678987654321"), null, null)); testParameters.Add(new LiteralValueTestParameters( "123.456", SqlTokenType.FloatLiteral, HsqlProviderType.Double, new JavaDouble(123.456D), null, null)); testParameters.Add(new LiteralValueTestParameters( "FOO", SqlTokenType.Null, HsqlProviderType.Null, null, null, null)); testParameters.Add(new LiteralValueTestParameters( "1234567898765432123456712345678987654321234567.1234567898765432123456712345678987654321234567", SqlTokenType.NumberLiteral, HsqlProviderType.Numeric, new JavaDecimal("1234567898765432123456712345678987654321234567.1234567898765432123456712345678987654321234567"), null, null)); testParameters.Add(new LiteralValueTestParameters( "He said 'high five!'", SqlTokenType.StringLiteral, HsqlProviderType.VarChar, "He said 'high five!'", null, null)); testParameters.Add(new LiteralValueTestParameters( "12:01:01", SqlTokenType.TimeLiteral, HsqlProviderType.Time, HsqlDateTime.timeValue("12:01:01"), null, null)); testParameters.Add(new LiteralValueTestParameters( "2009-02-09 12:01:01.123456", SqlTokenType.TimestampLiteral, HsqlProviderType.TimeStamp, HsqlDateTime.timestampValue("2009-02-09 12:01:01.123456"), null, null)); foreach (LiteralValueTestParameters item in testParameters) { Console.WriteLine(item); try { Token token = new Token(item.Chars, item.TokenType); object value = token.LiteralValue; if (item.ErrorMessage != null) { Assert.Fail(item.ErrorMessage); } System.Type expectedType = HsqlConvert.ToProviderSpecificDataType(item.ProviderType); if (expectedType != null && !(typeof(void).Equals(expectedType))) { Assert.IsInstanceOfType(expectedType, value); } Assert.AreEqual(item.Value, value); } catch (AssertionException) { throw; } catch (HsqlDataSourceException hdse) { Assert.AreEqual(item.ErrorCode, -hdse.ErrorCode); } } }
public void GetNextAsLiteralValue() { // Create Constructor Parameters Tokenizer testSubject = new Tokenizer(); List <NextAsLiteralValueTestParameters> testParameters = new List <NextAsLiteralValueTestParameters>(); // Array Literal testParameters.Add(new NextAsLiteralValueTestParameters( "foo", HsqlProviderType.Array, null, org.hsqldb.Trace.UNEXPECTED_TOKEN, "SQL ARRAY literal tokens are not supposed to be supported")); // BigInt Literal testParameters.Add(new NextAsLiteralValueTestParameters( "-1", HsqlProviderType.BigInt, null, org.hsqldb.Trace.UNEXPECTED_TOKEN, "Atomic retrieval of a negative BIGINT literal is not supposed to be supported.")); testParameters.Add(new NextAsLiteralValueTestParameters( "0", HsqlProviderType.BigInt, new java.lang.Long(0), null, null)); testParameters.Add(new NextAsLiteralValueTestParameters( "1", HsqlProviderType.BigInt, new java.lang.Long(1), null, null)); testParameters.Add(new NextAsLiteralValueTestParameters( long.MaxValue.ToString(), HsqlProviderType.BigInt, new java.lang.Long(long.MaxValue), null, null)); testParameters.Add(new NextAsLiteralValueTestParameters( long.MinValue.ToString(), HsqlProviderType.BigInt, null, org.hsqldb.Trace.UNEXPECTED_TOKEN, "Atomic retrieval of a negative BIGINT literal is not supposed to be supported.")); // Binary Literal testParameters.Add(new NextAsLiteralValueTestParameters( "/* a binary literal value */ 'AFD14E7B9F82' ", HsqlProviderType.Binary, new org.hsqldb.types.Binary(HsqlStringConverter.hexToByte("AFD14E7B9F82"), false), null, null)); foreach (NextAsLiteralValueTestParameters parameters in testParameters) { Console.WriteLine(parameters); testSubject.Reset(parameters.Chars); try { object value = testSubject.GetNextAsLiteralValue( parameters.ProviderType); if (parameters.ErrorMessage != null) { Assert.Fail(parameters.ErrorMessage); } System.Type expectedValueType = HsqlConvert.ToProviderSpecificDataType( parameters.ProviderType); Assert.IsAssignableFrom(expectedValueType, parameters.Value); Assert.IsAssignableFrom(expectedValueType, value); Assert.AreEqual(parameters.Value, value); } catch (AssertionException) { throw; } catch (HsqlDataSourceException hdse) { Assert.AreEqual(parameters.ErrorCode, -hdse.ErrorCode); } } //testSubject.Reset("'AFD14E7B9F82'"); //object bytes = testSubject.GetNextAsLiteralValue(HsqlProviderType.Binary); //Assert.IsInstanceOfType(typeof(org.hsqldb.types.Binary), bytes); //testSubject.Reset("'CAFEBABE'"); //try //{ // testSubject.GetNextAsLiteralValue(HsqlProviderType.Blob); // Assert.Fail("SQL BLOB literal tokens are not supposed to be supported at this time"); //} //catch (HsqlDataSourceException) //{ //} //testSubject.Reset("TRUE"); //testSubject.GetNextAsLiteralValue(HsqlProviderType.Boolean); //testSubject.Reset("FALSE"); //testSubject.GetNextAsLiteralValue(HsqlProviderType.Boolean); //testSubject.Reset("NULL"); //testSubject.GetNextAsLiteralValue(HsqlProviderType.Boolean); ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Char); //try //{ // testSubject.GetNextAsLiteralValue(HsqlProviderType.Clob); // Assert.Fail("SQL CLOB literal tokens are not supposed to be supported at this time"); //} //catch (HsqlDataSourceException) //{ //} //try //{ // testSubject.GetNextAsLiteralValue(HsqlProviderType.DataLink); // Assert.Fail("SQL DATALINK literal tokens are not supposed to be supported at this time"); //} //catch (HsqlDataSourceException) //{ //} ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Date); ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Decimal); //try //{ // testSubject.GetNextAsLiteralValue(HsqlProviderType.Distinct); // Assert.Fail("SQL DISTINCT literal tokens are not supposed to be supported"); //} //catch (HsqlDataSourceException) //{ //} ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Double); ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Float); ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Integer); //try //{ // testSubject.GetNextAsLiteralValue(HsqlProviderType.JavaObject); // Assert.Fail("SQL JAVA_OBJECT literal tokens are not supposed to be supported at this time"); //} //catch (HsqlDataSourceException) //{ //} ////testSubject.GetNextAsLiteralValue(HsqlProviderType.LongVarBinary); ////testSubject.GetNextAsLiteralValue(HsqlProviderType.LongVarChar); ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Null); ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Numeric); ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Object); ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Real); //try //{ // testSubject.GetNextAsLiteralValue(HsqlProviderType.Ref); // Assert.Fail("SQL REF literal tokens are not supposed to be supported"); //} //catch (HsqlDataSourceException) //{ //} ////testSubject.GetNextAsLiteralValue(HsqlProviderType.SmallInt); //try //{ // testSubject.GetNextAsLiteralValue(HsqlProviderType.Struct); // Assert.Fail("SQL STRUCT literal tokens are not supposed to be supported"); //} //catch (HsqlDataSourceException) //{ //} ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Time); ////testSubject.GetNextAsLiteralValue(HsqlProviderType.TimeStamp); ////testSubject.GetNextAsLiteralValue(HsqlProviderType.TinyInt); ////testSubject.GetNextAsLiteralValue(HsqlProviderType.VarBinary); ////testSubject.GetNextAsLiteralValue(HsqlProviderType.VarChar); //try //{ // testSubject.GetNextAsLiteralValue(HsqlProviderType.Xml); // Assert.Fail("SQL XML literal tokens are not supposed to be supported at this time"); //} //catch (HsqlDataSourceException) //{ //} }