sqlkata / querybuilder

SQL query builder, written in c#, helps you build complex queries easily, supports SqlServer, MySql, PostgreSql, Oracle, Sqlite and Firebird
https://sqlkata.com
MIT License
3.08k stars 498 forks source link

Sqlite Compiler wraps columns into string literals, preventing the 'No Such Column' exception from occurring (returning the string literal instead of throwing) #655

Open RFBomb opened 1 year ago

RFBomb commented 1 year ago

Take the following database table: Table: Students ID (int) - FirstName (string) - LastName (string)

Use the following query:

var qry = new SqlKata.Query("Students").Select("UnknownCol")

You will receive the string literal 'UnknownCol' back as a result.

The resulting query is as follows: SELECT \"UnknownCol\" FROM \"Students\"

Modifying the above to use brackets instead results in the No Such Column exception being thrown properly.

SELECT [UnknownCol] FROM [Students]

For reference, I am using DBCommand.ExecuteScalar() to retrieve the value from the database

Reference to my downvoted StackOverflow thread. Because apparently I'm the first one ever to have an issue with string literals. https://stackoverflow.com/questions/75040657/sqlite-database-returns-nonexistant-column-name-instead-of-exception-due-to-bad