0

I am using SQLite-net-PCL v.1.3.3 in a Xamarin Forms UWP project, and cannot understand this behaviour; don't know if it's a bug or something I haven't understood. I think I should be able to query columns from a table (FnImage, in the example below), and populate a collection of local objects (Test, below), with each instance in that collection of Test objects having the column values from a row in the FnImage table. I do not want to just create a local collection of rows from the FnImage table for memory management reasons; my result set should just include the data in the columns I am querying.

Task.Run(async () =>
{
var v = await mySQLiteAsyncConnection.QueryAsync<Test>("select 'Name', 'DbBytesThumbnail' from FnImage where 'Id' > ? ", 0);
...
});

public class Test {
public byte[] DbBytesThumbnail { get; set; }
public string Name { get; set; }
}

The code does create a collection with a single instance of Test in it (there should be more, given the data in the FnImage table), and both properties in that single instance are null. I've tried mapping 'select 'Name' as Name, 'DbBytesThumbnail' as DbBytesThumbnail...', changing the name of the properties in the local Test object and the "as" clause in the query, changing bits of syntax in the query (";" at the end, with and without single quotes, etc...) and spent hours on this with no success.

The FnImage table exists, the type mappings are correct, and I am using these classes/tables elsewhere with no problems (with the myAsyncConnection.Table() syntax). The Task does not enter a Faulted state / no Exception is thrown. Is this an issue with SQLite-net-PCL, or what I am doing with it? 

Thoughts and insights v welcome...

2
  • Instead of Names of columns, If you just have * and no where condition, Is it returning data ? Commented Jun 7, 2017 at 17:28
  • When I do that - var hhid2 = await _db.Db.QueryAsync<Test>("select * from FnImage"); - I enter a world of syntax pain where select * is throwing an exception as follows: Exception thrown: 'SQLite.SQLiteException' in SQLite-net.dll Exception thrown: 'SQLite.SQLiteException' in (near " from FnImage": syntax error) (near " from FnImage": syntax error). I don't know if I'm doing something wrong with the simple Select *.... I've also tried with a semi-colon to end the SQL statement, but I get the same syntax error. Commented Jun 7, 2017 at 18:36

1 Answer 1

2

I have tested your code and reproduced your issue .The problem is your SQL statement is malformed. If you want to query columns from a table, please try to use the following SQL statement.

"select Name, DbBytesThumbnail from FnImage where Id > ? "
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.