如何在Sqlite中使用通配符来匹配目录路径
本文关键字:路径 通配符 Sqlite | 更新日期: 2023-09-27 18:16:10
我有一个包含文件夹路径的db,我想找到一些文件夹包含的所有文件夹。我得到部分结果:
select * from pathTable where Path like ?||'%'
给定c:''root''1
c:''root''1 Copy
c:''root''1''2
c:''root''1''3''3a
c:''root''1''4
什么时候?为"c:''root''1",上述查询返回
c:''root''1
c:''root''1 Copy
我也想得到所有的子文件夹。我怀疑Sqlite在存储路径中的"'"上出错了。有人知道我做错了什么吗?
为了允许字符串参数通过@符号"完全"转义,我必须这样做。
void printPaths()
{
string mypath = @"c:''root''1";
string sql = ("select * from paths where pathdesc like @mypath");
SQLiteCommand command = new SQLiteCommand(sql,m_dbConnection);
command.Parameters.AddWithValue("@mypath", mypath+"%");
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
Console.WriteLine("ID: " + reader["pathid"] + "'tpathdesc: " + reader["pathdesc"]);
Console.ReadLine();
}