mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-09-23 16:43:49 +08:00
Persistence: Store cmsg_id and sub id for client_msgs.
This commit is contained in:
@@ -33,13 +33,16 @@ int persist_sqlite__client_msg_add_cb(int event, void *event_data, void *userdat
|
||||
UNUSED(event);
|
||||
|
||||
if(sqlite3_bind_text(ms->client_msg_add_stmt, 1, ed->client_id, (int)strlen(ed->client_id), SQLITE_STATIC) == SQLITE_OK
|
||||
&& sqlite3_bind_int64(ms->client_msg_add_stmt, 2, (int64_t)ed->store_id) == SQLITE_OK
|
||||
&& sqlite3_bind_int(ms->client_msg_add_stmt, 3, ed->dup) == SQLITE_OK
|
||||
&& sqlite3_bind_int(ms->client_msg_add_stmt, 4, ed->direction) == SQLITE_OK
|
||||
&& sqlite3_bind_int(ms->client_msg_add_stmt, 5, ed->mid) == SQLITE_OK
|
||||
&& sqlite3_bind_int(ms->client_msg_add_stmt, 6, ed->qos) == SQLITE_OK
|
||||
&& sqlite3_bind_int(ms->client_msg_add_stmt, 7, ed->retain) == SQLITE_OK
|
||||
&& sqlite3_bind_int(ms->client_msg_add_stmt, 8, ed->state) == SQLITE_OK
|
||||
&& sqlite3_bind_int64(ms->client_msg_add_stmt, 2, (int64_t)ed->cmsg_id) == SQLITE_OK
|
||||
&& sqlite3_bind_int64(ms->client_msg_add_stmt, 3, (int64_t)ed->store_id) == SQLITE_OK
|
||||
&& sqlite3_bind_int(ms->client_msg_add_stmt, 4, ed->dup) == SQLITE_OK
|
||||
&& sqlite3_bind_int(ms->client_msg_add_stmt, 5, ed->direction) == SQLITE_OK
|
||||
&& sqlite3_bind_int(ms->client_msg_add_stmt, 6, ed->mid) == SQLITE_OK
|
||||
&& sqlite3_bind_int(ms->client_msg_add_stmt, 7, ed->qos) == SQLITE_OK
|
||||
&& sqlite3_bind_int(ms->client_msg_add_stmt, 8, ed->retain) == SQLITE_OK
|
||||
&& sqlite3_bind_int(ms->client_msg_add_stmt, 9, ed->state) == SQLITE_OK
|
||||
&& sqlite3_bind_int(ms->client_msg_add_stmt, 10, (int)ed->subscription_identifier) == SQLITE_OK
|
||||
|
||||
){
|
||||
|
||||
ms->event_count++;
|
||||
|
||||
@@ -91,13 +91,15 @@ static int create_tables(struct mosquitto_sqlite *ms)
|
||||
"CREATE TABLE IF NOT EXISTS client_msgs "
|
||||
"("
|
||||
"client_id TEXT NOT NULL,"
|
||||
"cmsg_id INT64,"
|
||||
"store_id INT64,"
|
||||
"dup INTEGER,"
|
||||
"direction INTEGER,"
|
||||
"mid INTEGER,"
|
||||
"qos INTEGER,"
|
||||
"retain INTEGER,"
|
||||
"state INTEGER"
|
||||
"state INTEGER,"
|
||||
"subscription_identifier INTEGER"
|
||||
//"state INTEGER,"
|
||||
//"FOREIGN KEY (client_id) REFERENCES clients(client_id) "
|
||||
//"ON DELETE CASCADE,"
|
||||
@@ -178,8 +180,8 @@ static int prepare_statements(struct mosquitto_sqlite *ms)
|
||||
/* Client messages */
|
||||
rc = sqlite3_prepare_v3(ms->db,
|
||||
"INSERT INTO client_msgs "
|
||||
"(client_id,store_id,dup,direction,mid,qos,retain,state) "
|
||||
"VALUES(?,?,?,?,?,?,?,?)",
|
||||
"(client_id,cmsg_id,store_id,dup,direction,mid,qos,retain,state,subscription_identifier) "
|
||||
"VALUES(?,?,?,?,?,?,?,?,?,?)",
|
||||
-1, SQLITE_PREPARE_PERSISTENT,
|
||||
&ms->client_msg_add_stmt, NULL);
|
||||
if(rc) goto fail;
|
||||
|
||||
@@ -296,7 +296,7 @@ static int client_msg_restore(struct mosquitto_sqlite *ms)
|
||||
long count = 0, failed = 0;
|
||||
|
||||
rc = sqlite3_prepare_v2(ms->db,
|
||||
"SELECT client_id, store_id, dup, direction, mid, qos, retain, state "
|
||||
"SELECT client_id, cmsg_id, store_id, dup, direction, mid, qos, retain, state, subscription_identifier "
|
||||
"FROM client_msgs ORDER BY rowid",
|
||||
-1, &stmt, NULL);
|
||||
|
||||
@@ -308,13 +308,15 @@ static int client_msg_restore(struct mosquitto_sqlite *ms)
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW){
|
||||
msg.client_id = (const char *)sqlite3_column_text(stmt, 0);
|
||||
msg.store_id = (uint64_t)sqlite3_column_int64(stmt, 1);
|
||||
msg.dup = sqlite3_column_int(stmt, 2);
|
||||
msg.direction = (uint8_t)sqlite3_column_int(stmt, 3);
|
||||
msg.mid = (uint16_t)sqlite3_column_int(stmt, 4);
|
||||
msg.qos = (uint8_t)sqlite3_column_int(stmt, 5);
|
||||
msg.retain = sqlite3_column_int(stmt, 6);
|
||||
msg.state = (uint8_t)sqlite3_column_int(stmt, 7);
|
||||
msg.cmsg_id = (uint64_t)sqlite3_column_int64(stmt, 1);
|
||||
msg.store_id = (uint64_t)sqlite3_column_int64(stmt, 2);
|
||||
msg.dup = sqlite3_column_int(stmt, 3);
|
||||
msg.direction = (uint8_t)sqlite3_column_int(stmt, 4);
|
||||
msg.mid = (uint16_t)sqlite3_column_int(stmt, 5);
|
||||
msg.qos = (uint8_t)sqlite3_column_int(stmt, 6);
|
||||
msg.retain = sqlite3_column_int(stmt, 7);
|
||||
msg.state = (uint8_t)sqlite3_column_int(stmt, 8);
|
||||
msg.subscription_identifier = (uint32_t)sqlite3_column_int(stmt, 9);
|
||||
|
||||
rc = mosquitto_persist_client_msg_add(&msg);
|
||||
if(rc == MOSQ_ERR_SUCCESS){
|
||||
|
||||
Reference in New Issue
Block a user