Persist sqlite: Store client connection time.

pull/2396/merge
Roger A. Light 4 years ago
parent bc1adfd46d
commit 374f547b64

@ -28,6 +28,7 @@ int persist_sqlite__client_add_cb(int event, void *event_data, void *userdata)
struct mosquitto_evt_persist_client *ed = event_data;
struct mosquitto_sqlite *ms = userdata;
int rc = MOSQ_ERR_UNKNOWN;
time_t now;
UNUSED(event);
@ -42,14 +43,16 @@ int persist_sqlite__client_add_cb(int event, void *event_data, void *userdata)
sqlite3_bind_null(ms->client_add_stmt, 2);
}
if(sqlite3_bind_int64(ms->client_add_stmt, 3, ed->will_delay_time) == SQLITE_OK
&& sqlite3_bind_int64(ms->client_add_stmt, 4, ed->session_expiry_time) == SQLITE_OK
&& sqlite3_bind_int(ms->client_add_stmt, 5, ed->listener_port) == SQLITE_OK
&& sqlite3_bind_int(ms->client_add_stmt, 6, (int)ed->max_packet_size) == SQLITE_OK
&& sqlite3_bind_int(ms->client_add_stmt, 7, ed->max_qos) == SQLITE_OK
&& sqlite3_bind_int(ms->client_add_stmt, 8, ed->retain_available) == SQLITE_OK
&& sqlite3_bind_int(ms->client_add_stmt, 9, (int)ed->session_expiry_interval) == SQLITE_OK
&& sqlite3_bind_int(ms->client_add_stmt, 10, (int)ed->will_delay_interval) == SQLITE_OK
now = time(NULL);
if(sqlite3_bind_int64(ms->client_add_stmt, 3, now) == SQLITE_OK
&& sqlite3_bind_int64(ms->client_add_stmt, 4, ed->will_delay_time) == SQLITE_OK
&& sqlite3_bind_int64(ms->client_add_stmt, 5, ed->session_expiry_time) == SQLITE_OK
&& sqlite3_bind_int(ms->client_add_stmt, 6, ed->listener_port) == SQLITE_OK
&& sqlite3_bind_int(ms->client_add_stmt, 7, (int)ed->max_packet_size) == SQLITE_OK
&& sqlite3_bind_int(ms->client_add_stmt, 8, ed->max_qos) == SQLITE_OK
&& sqlite3_bind_int(ms->client_add_stmt, 9, ed->retain_available) == SQLITE_OK
&& sqlite3_bind_int(ms->client_add_stmt, 10, (int)ed->session_expiry_interval) == SQLITE_OK
&& sqlite3_bind_int(ms->client_add_stmt, 11, (int)ed->will_delay_interval) == SQLITE_OK
){
rc = sqlite3_step(ms->client_add_stmt);

@ -62,6 +62,7 @@ static int create_tables(struct mosquitto_sqlite *ms)
"("
"client_id TEXT PRIMARY KEY,"
"username TEXT,"
"connection_time INT64,"
"will_delay_time INT64,"
"session_expiry_time INT64,"
"listener_port INT,"
@ -153,10 +154,10 @@ static int prepare_statements(struct mosquitto_sqlite *ms)
/* Clients */
rc = sqlite3_prepare_v3(ms->db,
"INSERT OR REPLACE INTO clients "
"(client_id, username, will_delay_time, session_expiry_time, "
"(client_id, username, connection_time, will_delay_time, session_expiry_time, "
"listener_port, max_packet_size, max_qos, retain_available, "
"session_expiry_interval, will_delay_interval) "
"VALUES(?,?,?,?,?,?,?,?,?,?)",
"VALUES(?,?,?,?,?,?,?,?,?,?,?)",
-1, SQLITE_PREPARE_PERSISTENT,
&ms->client_add_stmt, NULL);
if(rc) goto fail;

Loading…
Cancel
Save