Branch data Line data Source code
1 : : #include "precizer.h"
2 : :
3 : : /**
4 : : *
5 : : * @brief Print warnings and errors captured in the TEMP remember_history table.
6 : : *
7 : : * @details The table is created in db_init(). Output is produced only when
8 : : * --progress is enabled. If the database is unavailable or no rows
9 : : * are present, the function returns without output.
10 : : *
11 : : * @return SUCCESS on completion, FAILURE if a SQLite operation fails.
12 : : *
13 : : */
14 : 377 : Return show_remembered_messages(void)
15 : : {
16 : : // Show only with --progress
17 [ + + ]: 377 : if(config->progress != true)
18 : : {
19 : 316 : provide(SUCCESS);
20 : : }
21 : :
22 : : // DB not initialized yet (early failure): nothing to show
23 [ - + ]: 61 : if(config->db == NULL)
24 : : {
25 : 0 : provide(SUCCESS);
26 : : }
27 : :
28 : 61 : sqlite3_stmt *stmt = NULL;
29 : 61 : const char *select_sql =
30 : : "SELECT message FROM temp.remember_history ORDER BY id;";
31 : :
32 : 61 : int rc = sqlite3_prepare_v2(config->db,select_sql,-1,&stmt,NULL);
33 : :
34 [ - + ]: 61 : if(rc != SQLITE_OK)
35 : : {
36 : 0 : log_sqlite_error(config->db,rc,NULL,
37 : : "Failed to prepare remember_history query");
38 : 0 : provide(FAILURE);
39 : : }
40 : :
41 : 61 : bool printed_header = false;
42 : :
43 [ + + ]: 92 : while((rc = sqlite3_step(stmt)) == SQLITE_ROW)
44 : : {
45 [ + + ]: 31 : if(!printed_header)
46 : : {
47 : : // Print the header only when at least one row exists.
48 : 7 : slog(EVERY,BOLD "Warnings and errors encountered:" RESET "\n");
49 : 7 : printed_header = true;
50 : : }
51 : :
52 : 31 : const unsigned char *text = sqlite3_column_text(stmt,0);
53 : 31 : int text_len = sqlite3_column_bytes(stmt,0);
54 : :
55 [ + - + - ]: 31 : if(text != NULL && text_len > 0)
56 : : {
57 : : // Use length-bounded output; remember_history messages are not
58 : : // guaranteed to be null-terminated.
59 [ + - ]: 31 : if(text[text_len - 1] == '\n')
60 : : {
61 : 31 : slog(EVERY|UNDECOR,"%.*s",text_len,text);
62 : : } else {
63 : 0 : slog(EVERY|UNDECOR,"%.*s\n",text_len,text);
64 : : }
65 : : }
66 : : }
67 : :
68 [ - + ]: 61 : if(rc != SQLITE_DONE)
69 : : {
70 : 0 : log_sqlite_error(config->db,rc,NULL,
71 : : "Failed to read remember_history");
72 : 0 : sqlite3_finalize(stmt);
73 : 0 : provide(FAILURE);
74 : : }
75 : :
76 : 61 : sqlite3_finalize(stmt);
77 : :
78 : 61 : provide(SUCCESS);
79 : : }
|