Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default(DateTime) causes ArgumentOutOfRangeException #4

Open
bnoffer opened this issue Dec 13, 2014 · 5 comments
Open

default(DateTime) causes ArgumentOutOfRangeException #4

bnoffer opened this issue Dec 13, 2014 · 5 comments
Assignees
Labels

Comments

@bnoffer
Copy link

bnoffer commented Dec 13, 2014

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.

@GoorMoon GoorMoon added the bug label Dec 13, 2014
@GoorMoon GoorMoon self-assigned this Dec 13, 2014
@GoorMoon
Copy link
Contributor

Can you post your test case ?

@bnoffer
Copy link
Author

bnoffer commented Dec 13, 2014

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);

@peteryongzhong
Copy link
Contributor

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();
}

@bnoffer
Copy link
Author

bnoffer commented Jan 20, 2015

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.

@GoorMoon
Copy link
Contributor

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 :(

schwarzeszeux pushed a commit to schwarzeszeux/OrientDB-NET.binary that referenced this issue Mar 23, 2016
…edge-in-transaction

Feature remove edge in transaction
GrayDelacluyse added a commit that referenced this issue Oct 28, 2016
* Fix typo preceeded

* Fix typo somtimes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants