SQLite WARNING: Type mapping failed

The log of our product started showing SQLite warnings. We ignored them to focus on the release. Now it was time to repro and fix the warnings.

After reading the verbose log we found the issue. Unknown datatypes are allowed when creating SQLite database, but log a warning when the check database routine would call GetSchema.

WARNING: Type mapping failed, returning default type Object for name “LARGEINT”.
WARNING: Type mapping failed, returning default name “” for type Object.

See the repro code below. System.Data.SQLite can be downloaded from here.

static void Main(string[] args) {
    // Trace to see SQLite warning
    Trace.Listeners.Add(new ConsoleTraceListener());
    // Use in-memory database
    var connectionString = "Data Source=:memory:;Version=3;";
    using(var connection = new SQLiteConnection(connectionString)) {
        connection.Open();
        // Create table with unknown datatype column
        using (var createTableOne = connection.CreateCommand()) {
            createTableOne.CommandText = 
                "CREATE TABLE One (Id LARGEINT NOT NULL);";
            createTableOne.ExecuteNonQuery();
        }
        // Table is created, no exceptions, only warning on GetSchema
        var schema = connection.GetSchema("Columns", null);
        var result = schema.Select("TABLE_NAME = 'One'");
        if (result.Length > 0) Console.WriteLine("One exists");
        else Console.WriteLine("One not exists");
    }
    Console.ReadLine();
}

We edited the create database scripts to use known SQLite types and the issue was resolved.

About erictummers

My work as a recruited developer changes almost every month. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Development and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s