Closed kamzab95 closed 3 years ago
func encode<T>(_ value: T, forKey key: Key) throws where T: Swift.Encodable {
if let data = value as? Data {
self.encoder.setters.append(Expression(key.stringValue) <- data)
} else if let string = value as? String {
self.encoder.setters.append(Expression(key.stringValue) <- string)
} else {
let encoded = try JSONEncoder().encode(value)
let string = String(data: encoded, encoding: .utf8)
self.encoder.setters.append(Expression(key.stringValue) <- string)
}
}
Make the above modification in Coding.swift to fix this issue.
func encode<T>(_ value: T, forKey key: Key) throws where T: Swift.Encodable { if let data = value as? Data { self.encoder.setters.append(Expression(key.stringValue) <- data) } else if let string = value as? String { self.encoder.setters.append(Expression(key.stringValue) <- string) } else { let encoded = try JSONEncoder().encode(value) let string = String(data: encoded, encoding: .utf8) self.encoder.setters.append(Expression(key.stringValue) <- string) } }
Make the above modification in Coding.swift to fix this issue.
where is this class Coding.Swift ? can you please provide the class
where is this class Coding.Swift ? can you please provide the class
I think it's SQLite.swift/Sources/SQLite/Typed/Coding.swift line: 131 (class SQLiteEncoder)
where is this class Coding.Swift ? can you please provide the class
I think it's SQLite.swift/Sources/SQLite/Typed/Coding.swift line: 131 (class SQLiteEncoder)
So we need to modify library source code ?
where is this class Coding.Swift ? can you please provide the class
I think it's SQLite.swift/Sources/SQLite/Typed/Coding.swift line: 131 (class SQLiteEncoder)
Yes it is.
So we need to modify library source code ?
If you want to use it with Codable and optional values, yes you do.
You should check this too if you need to work with optional values : Issue 997
Duplicate of #997
Build Information
version: 0.12 master xcode: 11.3 iOS: 13.2 integrated with: Carthage
Description
For
Query
won't work properly if data were inserted to the database as Encodable. In this case name will never be found. Name, which is String? will be put to database as "\"aabbbbcccc\"". The issue is caused by this additional quotes.
The workaround for this issue is adding the quotes while creating the query :