有人可以告诉我,如何只搜索字典中的一部分键(在VB.NET中)?
我使用以下示例代码:
Dim PriceList As New Dictionary(Of String, Double)(System.StringComparer.OrdinalIgnoreCase)
PriceList.Add("Spaghetti alla carbonara", 21.65)
PriceList.Add("Spaghetti aglio e olio", 22.65)
PriceList.Add("Spaghetti alla napoletana", 23.65)
PriceList.Add("Spaghetti alla puttanesca ", 24.65)
PriceList.Add("Spaghetti alla gricia ", 25.65)
PriceList.Add("Spaghetti alle vongole", 26.65)
PriceList.Add("Spaghetti Bolognese", 27.65)
If PriceList.ContainsKey("spaghetti bolognese") Then
Dim price As Double = PriceList.Item("spaghetti bolognese")
Console.WriteLine("Found, price: " & price)
End If
If Not PriceList.ContainsKey("Bolognese") Then
Console.WriteLine("How can I search for only a part of a key?")
End If
Run Code Online (Sandbox Code Playgroud)
如果我只知道像"Bolognese"这样的关键部分,或者只是像"Bolo"这样的单词的一部分,那么如何在完整的密钥中搜索这部分?
我将图片中的二进制数据写入我的 SQLite 数据库到一个名为“icondata”的 BLOB 字段中。
CREATE TABLE pictures(id INTEGER PRIMARY KEY AUTOINCREMENT, icondata BLOB)
Run Code Online (Sandbox Code Playgroud)
写入二进制数据的代码片段是:
SQLcommand.CommandText = "INSERT INTO pictures (id, icondata) VALUES (" & MyInteger & "," & "@img)"
SQLcommand.Prepare()
SQLcommand.Parameters.Add("@img", DbType.Binary, PicData.Length)
SQLcommand.Parameters("@img").Value = PicData
Run Code Online (Sandbox Code Playgroud)
这工作正常,我可以使用SQlite Spy 之类的工具在数据库中找到 BLOB 值。
但是如何搜索特定的“icondata”BLOB?
如果我尝试:
SQLcommand.CommandText = "SELECT id FROM pictures WHERE icondata=@img"
Run Code Online (Sandbox Code Playgroud)
并具有与上述相同的参数:
SQLcommand.Prepare()
SQLcommand.Parameters.Add("@img", DbType.Binary, PicData.Length)
SQLcommand.Parameters("@img").Value = PicData
Dim SQLreader As SQLite.SQLiteDataReader = SQLcommand.ExecuteReader()
While SQLreader.Read()
... Process found database entries....
End While
Run Code Online (Sandbox Code Playgroud)
我没有得到任何结果。
如果我将 SELECT …
如何使用 FTS5 表在 SQLite3 数据库中搜索(价格)范围?
这是一个高度简化的示例表:
CREATE VIRTUAL TABLE fruits USING fts5 (id, name, price);
INSERT INTO fruits (id,name,price) VALUES (1, 'Apple with A', 5);
INSERT INTO fruits (id,name,price) VALUES (2, 'Pineapple with B', 10);
INSERT INTO fruits (id,name,price) VALUES (3, 'Cucumber with C', 20);
INSERT INTO fruits (id,name,price) VALUES (4, 'Melon with D', 25);
INSERT INTO fruits (id,name,price) VALUES (5, 'Kiwi with E', 30);
INSERT INTO fruits (id,name,price) VALUES (6, 'Cucumber with F', 35);
INSERT INTO fruits (id,name,price) VALUES …Run Code Online (Sandbox Code Playgroud)