【发布时间】:2020-06-15 08:44:19
【问题描述】:
在以下每个示例中,是否需要复制 blob.0 或 text?你怎么知道的?
设置
import SQLite3
private let static_destructor = unsafeBitCast(0, to: sqlite3_destructor_type.self)
private let transient_destructor = unsafeBitCast(-1, to: sqlite3_destructor_type.self)
示例
-
bind_blobfunc bind_blob(_ stmt: OpaquePointer, _ blob: (UnsafeRawPointer, Int32)) { sqlite3_bind_blob(stmt, 1, blob.0, blob.1, transient_destructor) } -
bind_blobsfunc bind_blobs(_ stmt: OpaquePointer, _ blobs: [(UnsafeRawPointer, Int32)]) { for (index, blob) in blobs.enumerated() { sqlite3_bind_blob(stmt, Int32(index+1), blob.0, blob.1, transient_destructor) } } -
bind_textfunc bind_text(_ stmt: OpaquePointer, _ text: String) { sqlite3_bind_text(stmt, 1, text, -1, transient_destructor) } -
bind_textsfunc bind_texts(_ stmt: OpaquePointer, _ texts: [String]) { for (index, text) in texts.enumerated() { sqlite3_bind_text(stmt, Int32(index+1), text, -1, transient_destructor) } }
也就是说,我应该在任何示例中使用static_destructor 而不是transient_destructor 吗?
【问题讨论】:
-
您可以编辑您的问题以包含实际代码,而不是描述代码?
-
@robmayoff 当然。完毕。 :-) 谢谢。