Bug 2191 - SqliteDataReader throws on GetDecimal()
Summary: SqliteDataReader throws on GetDecimal()
Alias: None
Product: Class Libraries
Classification: Mono
Component: Mono.Data.Sqlite ()
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2011-11-24 09:51 UTC by Federico Di Gregorio
Modified: 2011-12-12 21:00 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Patch to fix the reported bug (1.21 KB, patch)
2011-12-12 17:04 UTC, Federico Di Gregorio

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Federico Di Gregorio 2011-11-24 09:51:58 UTC
A "NUMERIC" column should be able to store a decimal value by converting it internally to integer, float or text (as per SQLite documentation) but trying to retrieve a negative value from it using GetDecimal() fails, as shown by the following code (tested with branch 2-10 from git):

using System;
using Mono.Data.Sqlite;

namespace SqliteTest
    class MainClass
        public static void Main (string[] args)
            if (System.IO.File.Exists("tests.db"))
            SqliteConnection conn = new SqliteConnection("data source=tests.db;version=3");

            SqliteCommand cmd = conn.CreateCommand();
            cmd.CommandText = "CREATE TABLE test (n NUMERIC)";
            cmd.CommandText = "INSERT INTO test VALUES (-10.0)";

            cmd.CommandText = "SELECT * FROM test";
            SqliteDataReader data = cmd.ExecuteReader();
            while (data.Read()) {
                decimal m = data.GetDecimal(0);
                Console.WriteLine("DATA: {0}", m);
Comment 1 Federico Di Gregorio 2011-12-12 17:04:25 UTC
Created attachment 1035 [details]
Patch to fix the reported bug

The attached patch make the test provided with the bug report pass and fixes the problem.
Comment 2 Miguel de Icaza [MSFT] 2011-12-12 21:00:11 UTC
Applied to mono-2-10 and master