|
@@ -263,10 +263,11 @@ int ProtoParserPrivate::getMessage(bool before, uint64_t idx, int count, int typ
|
|
return false;
|
|
return false;
|
|
return true; }, [&](auto stmt) {
|
|
return true; }, [&](auto stmt) {
|
|
sqlite3_bind_int(stmt, 1, type);
|
|
sqlite3_bind_int(stmt, 1, type);
|
|
- sqlite3_bind_int(stmt, 2, line);
|
|
|
|
- sqlite3_bind_text(stmt, 3, target, strlen(target), nullptr);
|
|
|
|
- if (idx != 0)
|
|
|
|
- sqlite3_bind_int64(stmt, 4, idx); });
|
|
|
|
|
|
+ sqlite3_bind_int(stmt, 2, line);
|
|
|
|
+ bindText(stmt, 3, target);
|
|
|
|
+ if (idx != 0)
|
|
|
|
+ sqlite3_bind_int64(stmt, 4, idx);
|
|
|
|
+ });
|
|
#else
|
|
#else
|
|
if (before)
|
|
if (before)
|
|
{
|
|
{
|
|
@@ -334,7 +335,7 @@ int ProtoParserPrivate::getConversation(const char *keyword, const char *types,
|
|
return false;
|
|
return false;
|
|
return true; }, [&](auto stmt) {
|
|
return true; }, [&](auto stmt) {
|
|
if (keyword != nullptr && strlen(keyword) > 0)
|
|
if (keyword != nullptr && strlen(keyword) > 0)
|
|
- sqlite3_bind_text(stmt, 1, keyword, strlen(keyword), nullptr); });
|
|
|
|
|
|
+ bindText(stmt, 1, keyword); });
|
|
#else
|
|
#else
|
|
std::set<int> intTypes, intLines;
|
|
std::set<int> intTypes, intLines;
|
|
parseIntArray(types, intTypes);
|
|
parseIntArray(types, intTypes);
|
|
@@ -434,6 +435,24 @@ int64_t ProtoParserPrivate::getMaxId(const char *sql)
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void ProtoParserPrivate::bindText(struct sqlite3_stmt *stmt, int col, const char *str)
|
|
|
|
+{
|
|
|
|
+ if (str == nullptr)
|
|
|
|
+ {
|
|
|
|
+ sqlite3_bind_null(stmt, col);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ char *s = strdup(str);
|
|
|
|
+ sqlite3_bind_text(stmt, col, s, strlen(s), freeStr);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void ProtoParserPrivate::freeStr(void *ptr)
|
|
|
|
+{
|
|
|
|
+ free(ptr);
|
|
|
|
+}
|
|
|
|
+
|
|
int ProtoParserPrivate::insert(const char *sql, std::function<bool(struct sqlite3_stmt *stmt)> cb)
|
|
int ProtoParserPrivate::insert(const char *sql, std::function<bool(struct sqlite3_stmt *stmt)> cb)
|
|
{
|
|
{
|
|
struct sqlite3_stmt *stmt = nullptr;
|
|
struct sqlite3_stmt *stmt = nullptr;
|
|
@@ -534,12 +553,12 @@ int ProtoParserPrivate::update(GetFriendsResult &result)
|
|
return false;
|
|
return false;
|
|
auto entry = result.entry(i);
|
|
auto entry = result.entry(i);
|
|
auto err = sqlite3_reset(stmt);
|
|
auto err = sqlite3_reset(stmt);
|
|
- sqlite3_bind_text(stmt, 0, entry.uid().c_str(), entry.uid().length(), nullptr);
|
|
|
|
|
|
+ bindText(stmt, 0, entry.uid().c_str());
|
|
sqlite3_bind_int(stmt, 1, entry.state());
|
|
sqlite3_bind_int(stmt, 1, entry.state());
|
|
sqlite3_bind_int64(stmt, 2, entry.update_dt());
|
|
sqlite3_bind_int64(stmt, 2, entry.update_dt());
|
|
- sqlite3_bind_text(stmt, 3, entry.alias().c_str(), entry.alias().length(), nullptr);
|
|
|
|
|
|
+ bindText(stmt, 3, entry.alias().c_str());
|
|
sqlite3_bind_int(stmt, 4, entry.blacked());
|
|
sqlite3_bind_int(stmt, 4, entry.blacked());
|
|
- sqlite3_bind_text(stmt, 5, entry.extra().c_str(), entry.extra().length(), nullptr);
|
|
|
|
|
|
+ bindText(stmt, 5, entry.extra().c_str());
|
|
i++;
|
|
i++;
|
|
return true;
|
|
return true;
|
|
});
|
|
});
|
|
@@ -594,11 +613,11 @@ int ProtoParserPrivate::update(GetUserSettingResult &result)
|
|
return insert(sql, [&](auto stmt) {
|
|
return insert(sql, [&](auto stmt) {
|
|
if (i >= n)
|
|
if (i >= n)
|
|
return false;
|
|
return false;
|
|
- auto entry = result.entry(i);
|
|
|
|
|
|
+ auto& entry = result.entry(i);
|
|
auto err = sqlite3_reset(stmt);
|
|
auto err = sqlite3_reset(stmt);
|
|
sqlite3_bind_int(stmt, 0, entry.scope());
|
|
sqlite3_bind_int(stmt, 0, entry.scope());
|
|
- sqlite3_bind_text(stmt, 1, entry.key().c_str(), entry.key().length(), nullptr);
|
|
|
|
- sqlite3_bind_text(stmt, 2, entry.value().c_str(), entry.value().length(), nullptr);
|
|
|
|
|
|
+ bindText(stmt, 1, entry.key().c_str());
|
|
|
|
+ bindText(stmt, 2, entry.value().c_str());
|
|
sqlite3_bind_int64(stmt, 0, entry.update_dt());
|
|
sqlite3_bind_int64(stmt, 0, entry.update_dt());
|
|
i++;
|
|
i++;
|
|
return true;
|
|
return true;
|
|
@@ -757,20 +776,20 @@ int ProtoParserPrivate::update(PullMessageResult &result, uint64_t &head)
|
|
ret = insert(sql.c_str(), [&](auto stmt) {
|
|
ret = insert(sql.c_str(), [&](auto stmt) {
|
|
if (i >= n)
|
|
if (i >= n)
|
|
return false;
|
|
return false;
|
|
- auto entry = result.message(i);
|
|
|
|
|
|
+ auto& entry = result.message(i);
|
|
auto err = sqlite3_reset(stmt);
|
|
auto err = sqlite3_reset(stmt);
|
|
|
|
|
|
int col = 1;
|
|
int col = 1;
|
|
sqlite3_bind_int64(stmt, col++, entry.message_id());
|
|
sqlite3_bind_int64(stmt, col++, entry.message_id());
|
|
- sqlite3_bind_text(stmt, col++, entry.from_user().c_str(), entry.from_user().length(), nullptr);
|
|
|
|
|
|
+ bindText(stmt, col++, entry.from_user().c_str());
|
|
sqlite3_bind_int(stmt, col++, entry.conversation().type());
|
|
sqlite3_bind_int(stmt, col++, entry.conversation().type());
|
|
- sqlite3_bind_text(stmt, col++, entry.conversation().target().c_str(), entry.conversation().target().length(), nullptr);
|
|
|
|
|
|
+ bindText(stmt, col++, entry.conversation().target().c_str());
|
|
sqlite3_bind_int(stmt, col++, entry.conversation().line());
|
|
sqlite3_bind_int(stmt, col++, entry.conversation().line());
|
|
sqlite3_bind_blob(stmt, col++, entry.content().data().c_str(), entry.content().data().length(), nullptr);
|
|
sqlite3_bind_blob(stmt, col++, entry.content().data().c_str(), entry.content().data().length(), nullptr);
|
|
- sqlite3_bind_text(stmt, col++, entry.content().searchable_content().c_str(), entry.content().searchable_content().length(), nullptr);
|
|
|
|
|
|
+ bindText(stmt, col++, entry.content().searchable_content().c_str());
|
|
sqlite3_bind_int64(stmt, col++, entry.server_timestamp());
|
|
sqlite3_bind_int64(stmt, col++, entry.server_timestamp());
|
|
sqlite3_bind_int(stmt, col++, entry.content().type());
|
|
sqlite3_bind_int(stmt, col++, entry.content().type());
|
|
- sqlite3_bind_text(stmt, col++, entry.to_user().c_str(), entry.to_user().length(), nullptr);
|
|
|
|
|
|
+ bindText(stmt, col++, entry.to_user().c_str());
|
|
i++;
|
|
i++;
|
|
#if defined DUMP || defined DUMP_MESSAGE
|
|
#if defined DUMP || defined DUMP_MESSAGE
|
|
MqttLog(MQTT_LOG_INFO, "insert message %lld, type: %d, line: %d, target: %s", entry.message_id(), entry.conversation().type(), entry.conversation().line(), entry.conversation().target().c_str());
|
|
MqttLog(MQTT_LOG_INFO, "insert message %lld, type: %d, line: %d, target: %s", entry.message_id(), entry.conversation().type(), entry.conversation().line(), entry.conversation().target().c_str());
|
|
@@ -788,7 +807,7 @@ int ProtoParserPrivate::update(PullMessageResult &result, uint64_t &head)
|
|
Message msg;
|
|
Message msg;
|
|
toMessage(stmt, msg);
|
|
toMessage(stmt, msg);
|
|
|
|
|
|
- MqttLog(MQTT_LOG_INFO, "getMessage: %lld, type: %d, line: %d", msg.message_id(), msg.conversation().type(), msg.conversation().line());
|
|
|
|
|
|
+ MqttLog(MQTT_LOG_INFO, "getMessage: %lld, type: %d, line: %d, target: %s", msg.message_id(), msg.conversation().type(), msg.conversation().line(), msg.conversation().target().c_str());
|
|
|
|
|
|
return true;
|
|
return true;
|
|
});
|
|
});
|
|
@@ -845,15 +864,15 @@ void ProtoParserPrivate::test()
|
|
|
|
|
|
int col = 1;
|
|
int col = 1;
|
|
sqlite3_bind_int64(stmt, col++, entry.message_id());
|
|
sqlite3_bind_int64(stmt, col++, entry.message_id());
|
|
- sqlite3_bind_text(stmt, col++, entry.from_user().c_str(), entry.from_user().length(), nullptr);
|
|
|
|
|
|
+ bindText(stmt, col++, entry.from_user().c_str());
|
|
sqlite3_bind_int(stmt, col++, entry.conversation().type());
|
|
sqlite3_bind_int(stmt, col++, entry.conversation().type());
|
|
- sqlite3_bind_text(stmt, col++, entry.conversation().target().c_str(), entry.conversation().target().length(), nullptr);
|
|
|
|
|
|
+ bindText(stmt, col++, entry.conversation().target().c_str());
|
|
sqlite3_bind_int(stmt, col++, entry.conversation().line());
|
|
sqlite3_bind_int(stmt, col++, entry.conversation().line());
|
|
sqlite3_bind_blob(stmt, col++, entry.content().data().c_str(), entry.content().data().length(), nullptr);
|
|
sqlite3_bind_blob(stmt, col++, entry.content().data().c_str(), entry.content().data().length(), nullptr);
|
|
- sqlite3_bind_text(stmt, col++, entry.content().searchable_content().c_str(), entry.content().searchable_content().length(), nullptr);
|
|
|
|
|
|
+ bindText(stmt, col++, entry.content().searchable_content().c_str());
|
|
sqlite3_bind_int64(stmt, col++, entry.server_timestamp());
|
|
sqlite3_bind_int64(stmt, col++, entry.server_timestamp());
|
|
sqlite3_bind_int(stmt, col++, entry.content().type());
|
|
sqlite3_bind_int(stmt, col++, entry.content().type());
|
|
- sqlite3_bind_text(stmt, col++, entry.to_user().c_str(), entry.to_user().length(), nullptr);
|
|
|
|
|
|
+ bindText(stmt, col++, entry.to_user().c_str());
|
|
i++;
|
|
i++;
|
|
#if defined DUMP || defined DUMP_MESSAGE
|
|
#if defined DUMP || defined DUMP_MESSAGE
|
|
MqttLog(MQTT_LOG_INFO, "insert message %lld, type: %d, line: %d, target: %s", entry.message_id(), entry.conversation().type(), entry.conversation().line(), entry.conversation().target().c_str());
|
|
MqttLog(MQTT_LOG_INFO, "insert message %lld, type: %d, line: %d, target: %s", entry.message_id(), entry.conversation().type(), entry.conversation().line(), entry.conversation().target().c_str());
|