nuodb / nuodb-dotnet

.NET Driver for NuoDB
Other
21 stars 13 forks source link

Bigint Columns return small values as Int32 #19

Closed JamesW-Bede closed 9 years ago

JamesW-Bede commented 9 years ago

Hi there, We are trialling NuoDB and have run across an issue with the types the NuoDb Connector is returning.

Lets say we have a table with a single field ID and that its type is bigint.

When we query the db for a row with ID = 1000000000000 then as expected the Reader returns an object of Int64 (long).

However when we query for a row with ID = 1 the reader returns an Int32 (int).

The following c# exemplifies the issue:

    using System;
    using System.Data;
    public class Program
    {
        public static IDbConnection connectNuoDb()
        {
            var ConnectionString =
                "server=localhost;database=MyDb;user=MyUser;password=MyPass;schema=MySchema";
            var connection = new NuoDb.Data.Client.NuoDbConnection(ConnectionString);
            connection.Open();
            return connection;
        } 

        static void Main()
        {
            using (var connection = connectNuoDb())
            {
                var command = connection.CreateCommand();
                command.CommandText = "CREATE TABLE IF NOT EXISTS MyBigints (`ID` bigint NOT NULL,PRIMARY KEY(ID));";
                command.ExecuteNonQuery();
                command.CommandText = "TRUNCATE TABLE MyBigints;";
                command.ExecuteNonQuery();
                command.CommandText = String.Format("INSERT INTO MyBigints VALUES ({0})", 1000000000000L);
                command.ExecuteNonQuery();
                command.CommandText = String.Format("INSERT INTO MyBigints VALUES ({0})", 1L);
                command.ExecuteNonQuery();
                command.CommandText = "SELECT * FROM MyBigints";
                var result = command.ExecuteReader();
                result.Read();
                Console.WriteLine("Type of first row is: " + result[0].GetType());
                result.Read();
                Console.WriteLine("Type of second row is: " + result[0].GetType());
                Console.ReadKey();
            }
        }
    }
Type of first row is: System.Int64
Type of second row is: System.Int32

In my experience of ADO .net connectors (which I will admit is not much) the type of the object returned from the reader is not determined by the size but rather type of the field in the db..

So for example if I was to switch to the MySql connector I would see:

Type of first row is: System.Int64
Type of second row is: System.Int64

Without this consistency using Micro ORMs like Dapper.Net seems impossible, as they expect all rows to be uniform.

I have reviewed the Connector source however cant see where this issue comes from, I am starting to think this may be down to what NuoDB itself is returning to the driver?

albymassari commented 9 years ago

Hi James, thanks for reporting this issue; the current behavior of the driver is to replicate the type used to transport the data from the server, when the generic getValue API is used. I have filed bug in our internal tracking system to have it fixed.

Thanks, Alberto