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.11k stars 500 forks source link

SqliteCompiler - Issue when using Unique Identifier #635

Open kapilbhavsar opened 1 year ago

kapilbhavsar commented 1 year ago

The query generated by SqliteCompiler for a table with UUID, the parameters are treated as string. But the sqlite db stores UUID as blob so the strings needs to be passed as X'3E9FDFCAFF7B3B4AB2065C63BC4609C4' instead of '3E9FDFCAFF7B3B4AB2065C63BC4609C4'. SqliteCompiler doesn't appends X and the query returns with no result.

This further creates problems when using Include or IncludeMany. If the primary and foreign keys are UniqueIdentifier the Include function does not works.

https://stackoverflow.com/questions/7815587/using-guid-in-sqlite-select-where-guid-is-stored-in-the-sqlite-db-as-binaries

kapilbhavsar commented 1 year ago

I was using postgresql and one more thing I noticed with Include .. In the handleIncludes method of QueryFactory class, you are converting all the local keys to string var localIds = dynamicResult.Where(x => x[include.LocalKey] != null) .Select(x => x[include.LocalKey].ToString()) .ToList(); So all the parameters are passed as string which again gives error 42883: operator does not exist: uuid = text. It works if I remove ToString.