我正在尝试 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>();
不会有任何帮助,除了掩盖错误:我没有得到空指针,但是我没有从任何查询中得到任何结果< / strong>您在上方看到了。
将数据库的路径更改为以下内容也没关系:
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 DB在那里并且可以正常工作,至少手动查询在外壳中有效:
% 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>
我错过了我无法看到的非常明显的东西吗?