OrientDB-NET.binary
OrientDB-NET.binary copied to clipboard
default(DateTime) causes ArgumentOutOfRangeException
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.
Can you post your test case ?
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);
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();
}
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.
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 :(