praeclarum / praeclarum/sqlite-net
TableAttribute ExecuteScalar Problem
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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