Я пытаюсь запрос SQLite встроенные ресурсы , но мне очень тяжело.Проблема в печально известном «не могу найти таблицу», но, похоже, я смотрю не в ту сторону.
Во-первых, это мой текущий код:
string filename = "Testing.CSV." + items[category][subcategory].file + "-" + App.current_language + ".db3";
var conn = new SQLiteConnection(filename);
var o = conn.GetTableInfo("Items");
var q = conn.Table<Items>().Where(x => (x.thenumber > 3 && x.thenumber < 20));
List<Items> u = conn.Table<Items>().ToList();
foreach(var i in q)
{
System.Diagnostics.Debug.Print("LINQ returned int {0} string '{1}'", i.thenumber, i.thelabel);
}
var p = conn.Query<int>("select thenumber from Items where thenumber > 3 and thenumber< 20 order by random() limit 1;", 1);
Добавление conn.CreateTable<Items>();
после создания соединения это не поможет, кроме маскировки ошибки: я не получаю нулевой указатель, но Я не получаю никаких результатов ни по каким запросам , которые вы видите выше.
Изменение пути БД к следующему также не имеет значения:
var embeddedResourceDbStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(filename);
var dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), filename);
var conn = new SQLiteConnection(dbPath);
Обратите внимание, что у меня есть тот же запрос к текстовому файлу (также встроенный ресурс) и онработает как чудо:
string filename = "Testing.CSV." + items[category][subcategory].file + "-" + App.current_language + ".txt";
var assembly = IntrospectionExtensions.GetTypeInfo(typeof(TestPage)).Assembly;
Stream stream = assembly.GetManifestResourceStream(filename);
StreamReader reader = new StreamReader(stream);
// Good old CSV, at least I can open it
List<string> lines = new List<string>(2);
// Load all its contents and query
while (!reader.EndOfStream)
{
string s = reader.ReadLine();
// ...
Отбрасывая любые сомнения, БД SQLite есть и работает, и по крайней мере ручной запрос работает в оболочке:
% sqlite3 /Users/sensei/Documents/Projects/playground/Testing/Testing/CSV/Test-en.db3
SQLite version 3.24.0 2018-06-04 19:24:41
Enter ".help" for usage hints.
sqlite> select thenumber from Items where thenumber > 3 and thenumber< 20 order by random() limit 1;
19
sqlite> select thenumber from Items where thenumber > 3 and thenumber< 20 order by random() limit 1;
17
sqlite> select thenumber from Items where thenumber > 3 and thenumber< 20 order by random() limit 1;
8
sqlite> select thenumber from Items where thenumber > 3 and thenumber< 20 order by random() limit 1;
5
sqlite>
Я пропустилчто-то ужасно очевидное, что я не могу так увидеть?