【问题标题】:Using FMDB + SQLCipher with Rubymotion?将 FMDB + SQLCipher 与 Rubymotion 一起使用?
【发布时间】:2013-01-13 15:24:14
【问题描述】:
我在使用 rubymotion 构建的应用程序中使用 FMDB 处理 sqlite 数据库。
我想用 SQLCipher 加密数据库,但当我尝试使用 SQLCipher 方法(例如 sqlite3_key)时遇到问题?
有人试过吗?
**********添加:
当我尝试使用 SQLCipher api 提供的 sqlite3_key 方法加密数据库时,它会抛出异常,并告知方法未定义。
【问题讨论】:
标签:
ios6
fmdb
rubymotion
sqlcipher
cocoapods
【解决方案1】:
我认为您可以通过添加 SQLCipher pod 然后使用 FMDB FMDatabase.setKey 方法来做到这一点,而无需编写任何 C。
在Rakefile
app.pods do
pod 'FMDB'
pod 'SQLCipher'
end
然后在你的Database.rb
class Database
def self.connection
unless @connection
@connection = FMDatabase.databaseWithPath(db_path)
@connection.traceExecution = true if $debug
@connection.open
@connection.setKey 'MySecretKey'
end
end
end
现在你应该可以用
查询数据库了
Database.connection.executeSelect 'SELECT * from some_table'