OrientDB-NET.binary icon indicating copy to clipboard operation
OrientDB-NET.binary copied to clipboard

default(DateTime) causes ArgumentOutOfRangeException

Open bnoffer opened this issue 10 years ago • 5 comments

When working with DateTime and setting values to its default value using default(DateTime) this results in a ArgumentOutOfRangeException. Here is the stack trace:

at System.DateTime.AddTicks(Int64 value)
at Orient.Client.Protocol.Serializers.RecordCSVSerializer.ParseValue(Int32 i, String recordString, ODocument document, String fieldName) in ..\OrientDB-NET.binary\src\Orient\Orient.Client\Protocol\Serializers\RecordCSVSerializer.cs:Line 523.
at Orient.Client.Protocol.Serializers.RecordCSVSerializer.ParseFieldName(Int32 i, String recordString, ODocument document) in ..\OrientDB-NET.binary\src\Orient\Orient.Client\Protocol\Serializers\RecordCSVSerializer.cs:Line 300.
at Orient.Client.Protocol.Serializers.RecordCSVSerializer.Deserialize(String recordString, ODocument document) in ..\OrientDB-NET.binary\src\Orient\Orient.Client\Protocol\Serializers\RecordCSVSerializer.cs:Line 62.
at Orient.Client.Protocol.Serializers.RecordCSVSerializer.Deserialize(Byte[] rawRecord, ODocument document) in ..\OrientDB-NET.binary\src\Orient\Orient.Client\Protocol\Serializers\RecordCSVSerializer.cs:Line 77.
at Orient.Client.Protocol.Operations.Command.Command.ParseDocument(BinaryReader reader) in ..\OrientDB-NET.binary\src\Orient\Orient.Client\Protocol\Operations\Command\Command.cs:Line 217.
at Orient.Client.Protocol.Operations.Command.Command.Response(Response response) in ..\OrientDB-NET.binary\src\Orient\Orient.Client\Protocol\Operations\Command\Command.cs:Line 143.
at Orient.Client.Protocol.Connection.ExecuteOperation(IOperation operation) in ..\OrientDB-NET.binary\src\Orient\Orient.Client\Protocol\Connection.cs:Line 129.
at Orient.Client.OSqlInsert.Run() in ..\OrientDB-NET.binary\src\Orient\Orient.Client\API\Query\OSqlInsert.cs:Line 113.

From what I could see it is caused by the conversion to UNIX timestamp. I currently do not have the time to investigate, but at the point where the DateTime field is converted to UNIX Timestamp there should be a check if the field value matches default(DateTime).

Revision used: master 5102043

Quick update: Insert operations succeeded despite those exceptions being thrown.

bnoffer avatar Dec 13 '14 15:12 bnoffer

Can you post your test case ?

GoorMoon avatar Dec 13 '14 16:12 GoorMoon

Here is basically what happened:

Database db = new Database("myPool");
....
DateTime dateOfBirth = default(DateTime);
....
ODocument doc = new ODocument();
doc.SetField<DateTime>("DateOfBirth", dateOfBirth);
...
ODocument result = db.Insert(doc);

To get past the issue I changed the code as follows:

Database db = new Database("myPool");
....
DateTime dateOfBirth = default(DateTime);
....
ODocument doc = new ODocument();
If ((dateOfBirth == null) || (dateOfBrith == default(DateTime)))
   dateOfBirth = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
doc.SetField<DateTime>("DateOfBirth", dateOfBirth);
...
ODocument result = db.Insert(doc);

bnoffer avatar Dec 13 '14 16:12 bnoffer

I used the following code to test on two of my device(win,mac(mono)), the document is successfully created. I can not use your code to test because there is no Database class, and insert a document throws an error with finding class name.

using (var database = Settings.GetDatabase())
{
    DateTime dateOfBirth = default(DateTime);
    database
        .Create
        .Vertex<OVertex>()
        .Set("date", dateOfBirth)
        .Run();
}

and

using (var database = Settings.GetDatabase())
{
    DateTime dateOfBirth = default(DateTime);
    var doc = new OVertex();
    doc.SetField("Date", dateOfBirth);
    var doc1 = database.Create.Document<OVertex>(doc).Run();
}

peteryongzhong avatar Dec 28 '14 11:12 peteryongzhong

I was using the document model, not the graph model. That might be the difference. Although I did not check this for quite some time. I'll revisit this.

bnoffer avatar Jan 20 '15 14:01 bnoffer

OrientDB has issue with date's < 1582-10-14 Because of using standard Java datetime classes this different handled by .NET. I still looking how to tackle such problem :(

GoorMoon avatar Jan 20 '15 16:01 GoorMoon