mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
Fix FTS5
This commit is contained in:
1 parent
7f7554f601
commit
61d7740767
2 files changed
+45
-34
No files matched your search
+8
-8
@@ -69,40 +69,40 @@ public struct FTS5: VirtualTableModule {
|
||||
}
|
||||
|
||||
if let tokenizer = definition.tokenizer {
|
||||
let tokenizerSQL = tokenizer
|
||||
let tokenizerSQL = try tokenizer
|
||||
.components
|
||||
.joined(separator: " ")
|
||||
.sqlExpression
|
||||
.quotedSQL()
|
||||
.quotedSQL(db)
|
||||
arguments.append("tokenize=\(tokenizerSQL)")
|
||||
}
|
||||
|
||||
switch definition.contentMode {
|
||||
case let .raw(content, contentRowID):
|
||||
if let content = content {
|
||||
let quotedContent = content.sqlExpression.quotedSQL()
|
||||
let quotedContent = try content.sqlExpression.quotedSQL(db)
|
||||
arguments.append("content=\(quotedContent)")
|
||||
}
|
||||
if let contentRowID = contentRowID {
|
||||
let quotedContentRowID = contentRowID.sqlExpression.quotedSQL()
|
||||
let quotedContentRowID = try contentRowID.sqlExpression.quotedSQL(db)
|
||||
arguments.append("content_rowid=\(quotedContentRowID)")
|
||||
}
|
||||
case let .synchronized(contentTable):
|
||||
arguments.append("content=\(contentTable.sqlExpression.quotedSQL())")
|
||||
try arguments.append("content=\(contentTable.sqlExpression.quotedSQL(db))")
|
||||
if let rowIDColumn = try db.primaryKey(contentTable).rowIDColumn {
|
||||
let quotedRowID = rowIDColumn.sqlExpression.quotedSQL()
|
||||
let quotedRowID = try rowIDColumn.sqlExpression.quotedSQL(db)
|
||||
arguments.append("content_rowid=\(quotedRowID)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if let prefixes = definition.prefixes {
|
||||
let prefix = prefixes
|
||||
let prefix = try prefixes
|
||||
.sorted()
|
||||
.map { "\($0)" }
|
||||
.joined(separator: " ")
|
||||
.sqlExpression
|
||||
.quotedSQL()
|
||||
.quotedSQL(db)
|
||||
arguments.append("prefix=\(prefix)")
|
||||
}
|
||||
|
||||
|
||||
@@ -59,14 +59,17 @@ public struct FTS5TokenizerDescriptor {
|
||||
if separators.isEmpty {
|
||||
components = ["ascii"]
|
||||
} else {
|
||||
components = [
|
||||
"ascii",
|
||||
"separators",
|
||||
separators
|
||||
.map { String($0) }
|
||||
.joined()
|
||||
.sqlExpression
|
||||
.quotedSQL()]
|
||||
components = DatabaseQueue().inDatabase { db in
|
||||
// Assume quoting a string never fails
|
||||
try! [
|
||||
"ascii",
|
||||
"separators",
|
||||
separators
|
||||
.map { String($0) }
|
||||
.joined()
|
||||
.sqlExpression
|
||||
.quotedSQL(db)]
|
||||
}
|
||||
}
|
||||
return FTS5TokenizerDescriptor(components: components)
|
||||
}
|
||||
@@ -126,29 +129,37 @@ public struct FTS5TokenizerDescriptor {
|
||||
// TODO: test "=" and "\"", "(" and ")" as separators, with
|
||||
// both FTS3Pattern(matchingAnyTokenIn:tokenizer:)
|
||||
// and Database.create(virtualTable:using:)
|
||||
components.append(contentsOf: [
|
||||
"separators",
|
||||
separators
|
||||
.sorted()
|
||||
.map { String($0) }
|
||||
.joined()
|
||||
.sqlExpression
|
||||
.quotedSQL()
|
||||
])
|
||||
let separatorComponents = DatabaseQueue().inDatabase { db in
|
||||
// Assume quoting a string never fails
|
||||
try! [
|
||||
"separators",
|
||||
separators
|
||||
.sorted()
|
||||
.map { String($0) }
|
||||
.joined()
|
||||
.sqlExpression
|
||||
.quotedSQL(db)
|
||||
]
|
||||
}
|
||||
components.append(contentsOf: separatorComponents)
|
||||
}
|
||||
if !tokenCharacters.isEmpty {
|
||||
// TODO: test "=" and "\"", "(" and ")" as tokenCharacters, with
|
||||
// both FTS3Pattern(matchingAnyTokenIn:tokenizer:)
|
||||
// and Database.create(virtualTable:using:)
|
||||
components.append(contentsOf: [
|
||||
"tokenchars",
|
||||
tokenCharacters
|
||||
.sorted()
|
||||
.map { String($0) }
|
||||
.joined()
|
||||
.sqlExpression
|
||||
.quotedSQL()
|
||||
])
|
||||
let tokenCharactersComponents = DatabaseQueue().inDatabase { db in
|
||||
// Assume quoting a string never fails
|
||||
try! [
|
||||
"tokenchars",
|
||||
tokenCharacters
|
||||
.sorted()
|
||||
.map { String($0) }
|
||||
.joined()
|
||||
.sqlExpression
|
||||
.quotedSQL(db)
|
||||
]
|
||||
}
|
||||
components.append(contentsOf: tokenCharactersComponents)
|
||||
}
|
||||
return FTS5TokenizerDescriptor(components: components)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user