praeclarum / praeclarum/sqlite-net

TableAttribute ExecuteScalar Problem

Open
#1,024 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.5k
Forks
1.4k
PR merge metrics
No merged PRs in 30d

Description

Hi,
when I use the TableAttribute on a class to give the table another name in the database, there is a problem with using the ExecuteScalar function. The function dont pay attention to the TableAttribute attribute, it uses the class/type name.

Example Class

[Table("Cities")]
    class City {

        [PrimaryKey, AutoIncrement]
        public int Id { get; set; }

        [NotNull, Indexed]
        public string Name { get; set; }

    }

Example Code

var conn = new SQLiteConnection(@"c:\myDatabase.sqlite");

var count = conn.ExecuteScalar<City>("SELECT COUNT(*) FROM Cities");

Error

An unhandled exception has occurred while executing the request.
System.NotSupportedException: Don't know how to read NamespaceName.City
   at SQLite.SQLiteCommand.ReadCol(sqlite3_stmt stmt, Int32 index, ColType type, Type clrType)
   at SQLite.SQLiteCommand.ExecuteScalar[T]()

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at SQLiteCommand.ExecuteScalar() and the ReadCol call shown in the stack trace. Reproduce the issue with the City class, its TableAttribute, and the SELECT COUNT(*) query from the report. Done means ExecuteScalar no longer treats the class name as the table name when the attribute specifies Cities.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sqlite
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.