question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid default column type for Timespan on Oracle

See original GitHub issue

Invalid default column type for Timespan property on Oracle

Exception message: ORA-00902: invalid datatype
Stack trace:  at OracleInternal.ServiceObjects.OracleConnectionImpl.VerifyExecution(Int32& cursorId, Boolean bThrowArrayBindRelatedErrors, SqlStatementType sqlStatementType, Int32 arrayBindCount, OracleException& exceptionForArrayBindDML, Boolean& hasMoreRowsInDB, Boolean bFirstIterationDone)
   at OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteNonQuery(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, Int32 longFetchSize, Int64 clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, OracleException& exceptionForArrayBindDML, OracleConnection connection, OracleLogicalTransaction& oracleLogicalTransaction, Boolean isFromEF)
   at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()
   at System.Data.Common.DbCommand.ExecuteNonQueryAsync(CancellationToken cancellationToken)
--- End of stack trace from previous location ---
   at LinqToDB.Data.DataConnection.ExecuteNonQueryAsync(CancellationToken cancellationToken)
   at LinqToDB.Data.DataConnection.ExecuteNonQueryDataAsync(CancellationToken cancellationToken)
   at LinqToDB.Data.DataConnection.ExecuteNonQueryDataAsync(CancellationToken cancellationToken)
   at LinqToDB.Data.DataConnection.QueryRunner.ExecuteNonQueryAsync(CancellationToken cancellationToken)
   at LinqToDB.Linq.QueryRunner.NonQueryQueryAsync(Query query, IDataContext dataContext, Expression expression, Object[] ps, Object[] preambles, CancellationToken cancellationToken)
   at LinqToDB.Linq.QueryRunner.NonQueryQueryAsync(Query query, IDataContext dataContext, Expression expression, Object[] ps, Object[] preambles, CancellationToken cancellationToken)
   at LinqToDB.Linq.QueryRunner.CreateTable`1.QueryAsync(IDataContext dataContext, String tableName, String serverName, String databaseName, String schemaName, String statementHeader, String statementFooter, DefaultNullable defaultNullable, TableOptions tableOptions, CancellationToken token)

Steps to reproduce

[Serializable]
public class TypesTestTable
{
    public bool BoolValue { get; set; }
    public bool? NullableBoolValue { get; set; }
    public char CharValue { get; set; }
    public string StringValue { get; set; }
    public decimal DecimalValue { get; set; }
    public decimal? NullableDecimalValue { get; set; }
    public Guid GuidValue { get; set; }
    public int IntValue { get; set; }
    public int? NullableIntValue { get; set; }
    public DateTime DateTimeValue { get; set; }
    public DateTime? NullableDateTimeValue { get; set; }
    public DateTimeOffset DateTimeOffsetValue { get; set; }
    public DateTimeOffset? NullableDateTimeOffsetValue { get; set; }
    public TimeSpan TimeSpanValue { get; set; }
    public TimeSpan? NullableTimeSpanValue { get; set; }
}

var builder = new LinqToDBConnectionOptionsBuilder();
OracleTools.DontEscapeLowercaseIdentifiers = true;
builder.UseOracle("Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=XEPDB1)));User Id=username;Password=password;");
var options = builder.Build();

var dataConnection = new DataConnection(options);
await dataConnection.CreateTableAsync<TypesTestTable>();

Created SQL clause (LastQuery Property from DataConenction)

CREATE TABLE TypesTestTable
(
	BoolValue                   Char(1)                  NOT NULL,
	NullableBoolValue           Char(1)                      NULL,
	CharValue                   NChar(1)                 NOT NULL,
	StringValue                 VarChar(255)                 NULL,
	DecimalValue                Decimal                  NOT NULL,
	NullableDecimalValue        Decimal                      NULL,
	GuidValue                   Raw(16)                  NOT NULL,
	IntValue                    Int                      NOT NULL,
	NullableIntValue            Int                          NULL,
	DateTimeValue               timestamp                NOT NULL,
	NullableDateTimeValue       timestamp                    NULL,
	DateTimeOffsetValue         timestamp with time zone NOT NULL,
	NullableDateTimeOffsetValue timestamp with time zone     NULL,
	TimeSpanValue               Time                     NOT NULL,
	NullableTimeSpanValue       Time                         NULL
)

If I remove Timespan properties the CreateTable suceeds. It appears that the Time column type doesn’t exist for Oracle.

Environment details

Linq To DB version: 4.1.0 Database (with version): Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production - Version 21.3.0.0.0 ADO.NET Provider (with version): Oracle.ManagedDataAccess.Core 2.19.110 LinqToDB AutoPicked Provider: LinqToDB.DataProvider.Oracle.OracleDataProviderManaged12 Operating system: Windows 10 .NET Version: 6.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MaceWinducommented, Aug 26, 2022

I would agree that we should throw exceptions for such cases. We have plans to revamp type mappings configuration and probably then we change it.

0reactions
Jubastcommented, Aug 26, 2022

I understand. Wouldn’t it be better to throw an exception that there is no default mapping for the type? Getting an error from the database that an invalid datatype was was specified is a weird way to find out that a type is not supported by default.

Thank you for your time to answer my issue 😃 Thank you for the example 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL invalid datatype time - oracle
In Oracle there is no datatype as TIME. You can use TIMESTAMP or DATE. So I think you need to change TIME to...
Read more >
11.2.6 Automatic Initialization and Updating for ...
The default in this case is type dependent. TIMESTAMP has a default of 0 unless defined with the NULL attribute, in which case...
Read more >
4 Datetime Data Types and Time Zone Support
The default date format for the TIMESTAMP WITH TIME ZONE data type is determined by the value of the NLS_TIMESTAMP_TZ_FORMAT initialization parameter.
Read more >
GetTimeSpan
This method returns the TimeSpan value of the specified INTERVAL DAY TO SECOND column. ... The zero-based column index. ... The TimeSpan value...
Read more >
OracleDataAdapter Safe Type Mapping
The Oracle data type INTERVAL DAY TO SECOND can hold up to 9 precision, and the .NET TimeSpan type can hold up to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found