如何打开chat.db进行阅读

时间:2018-10-29 19:36:15

标签: c++ macos sqlite imessage

我正在尝试使用SQLite3库打开Messages db(〜/ Library / Messages / chat.db):

int rc = sqlite3_open_v2("/Users/username/Library/Messages/chat.db", &m_db, SQLITE_OPEN_READONLY, NULL);
if (rc != SQLITE_OK) {
      fprintf(stderr, "Cannot open database [%d]: %s\n",
              sqlite3_extended_errcode(m_db),
              sqlite3_errmsg(m_db));
              sqlite3_close(m_db);
       } else {
              qDebug() << "Database: connection ok";
       }

返回

Cannot open database [14]: unable to open database file

根据https://www.sqlite.org/rescode.html#cantopen,其中14是SQLITE_CANTOPEN

复制chat.db文件后,可以使用上面的代码正确打开。

同时,使用内置的cli,我可以从终端访问原始路径的db:

> sqlite3 ~/Library/Messages/chat.db

SQLite version 3.22.0 2018-01-22 18:45:57
Enter ".help" for usage hints.
sqlite> .tables
_SqliteDatabaseProperties  kvtable
attachment                 message
chat                       message_attachment_join
chat_handle_join           message_processing_task
chat_message_join          sync_deleted_attachments
deleted_messages           sync_deleted_chats
handle                     sync_deleted_messages

如何以编程方式打开数据库?

0 个答案:

没有答案