Skip to content

Commit 9866cfd

Browse files
committed
midb: avoid use of CONCAT() sqlite function
Leap 15.3/15.4/15.5/15.6 has 3.44, but AlmaLinux 9 has a lackluster version 3.34.1. CONCAT/CONCAT_WS was added in 3.43. Since the temporary name is irrelevant, we can put NULL there. References: GXH-114
1 parent 3479ac4 commit 9866cfd

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

exch/midb/mail_engine.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,11 +1801,11 @@ static BOOL mail_engine_sync_mailbox(IDB_ITEM *pidb,
18011801
return false;
18021802

18031803
/*
1804-
* rename all folders to temporary names so that there
1804+
* "rename" all folders to NULL temporarily so that there
18051805
* is no conflict when adding any new folders' names
18061806
* (name column is set to UNIQUE)
18071807
*/
1808-
auto ret = gx_sql_exec(pidb->psqlite, "UPDATE folders SET name=CONCAT('t',ROWID)");
1808+
auto ret = gx_sql_exec(pidb->psqlite, "UPDATE folders SET name=NULL");
18091809
if (ret != SQLITE_OK)
18101810
/* ignore */;
18111811

@@ -1858,7 +1858,7 @@ static BOOL mail_engine_sync_mailbox(IDB_ITEM *pidb,
18581858
parent_fid, folder_id);
18591859
gx_sql_exec(pidb->psqlite, qstr.c_str());
18601860
}
1861-
if (strcasecmp(encoded_name.c_str(), pstmt1.col_text(3)) != 0) {
1861+
if (strcasecmp(encoded_name.c_str(), znul(pstmt1.col_text(3))) != 0) {
18621862
auto ust = gx_sql_prep(pidb->psqlite, "UPDATE folders SET name=? "
18631863
"WHERE folder_id=?");
18641864
if (ust == nullptr ||
@@ -2167,7 +2167,7 @@ static int mail_engine_menum(int argc, char **argv, int sockd) try
21672167
rsp.reserve(65536);
21682168
while (pstmt.step() == SQLITE_ROW) {
21692169
rsp += std::to_string(pstmt.col_uint64(0)) + " " +
2170-
base64_encode(pstmt.col_text(1)) + "\r\n"s;
2170+
base64_encode(znul(pstmt.col_text(1))) + "\r\n"s;
21712171
count ++;
21722172
}
21732173
pstmt.finalize();
@@ -2784,7 +2784,8 @@ static int mail_engine_psubl(int argc, char **argv, int sockd) try
27842784
std::string rsp;
27852785
rsp.reserve(65536);
27862786
for (; pstmt.step() == SQLITE_ROW; ++count)
2787-
rsp += std::to_string(pstmt.col_uint64(0)) + " " + pstmt.col_text(1) + "\r\n"s;
2787+
rsp += std::to_string(pstmt.col_uint64(0)) + " " +
2788+
znul(pstmt.col_text(1)) + "\r\n"s;
27882789
pstmt.finalize();
27892790
pidb.reset();
27902791
rsp.insert(0, "TRUE " + std::to_string(count) + "\r\n");
@@ -3633,7 +3634,7 @@ static BOOL mail_engine_add_notification_folder(IDB_ITEM *pidb,
36333634
auto pstmt = gx_sql_prep(pidb->psqlite, qstr.c_str());
36343635
if (pstmt == nullptr || pstmt.step() != SQLITE_ROW)
36353636
return FALSE;
3636-
decoded_name = pstmt.col_text(0);
3637+
decoded_name = znul(pstmt.col_text(0));
36373638
}
36383639

36393640
static constexpr proptag_t tmp_proptags[] =
@@ -3707,7 +3708,7 @@ static void mail_engine_update_subfolders_name(IDB_ITEM *pidb,
37073708
return;
37083709
while (pstmt.step() == SQLITE_ROW) {
37093710
uint64_t folder_id = pstmt.col_int64(0);
3710-
auto ptoken = strrchr(pstmt.col_text(1), '/');
3711+
auto ptoken = strrchr(znul(pstmt.col_text(1)), '/');
37113712
if (ptoken == nullptr)
37123713
continue;
37133714
auto temp_name = parent_name + ptoken;
@@ -3748,7 +3749,7 @@ static void mail_engine_move_notification_folder(IDB_ITEM *pidb,
37483749
pstmt = gx_sql_prep(pidb->psqlite, qstr.c_str());
37493750
if (pstmt == nullptr || pstmt.step() != SQLITE_ROW)
37503751
return;
3751-
decoded_name = pstmt.col_text(0);
3752+
decoded_name = znul(pstmt.col_text(0));
37523753
pstmt.finalize();
37533754
}
37543755
static constexpr proptag_t tmp_proptag[] = {PR_DISPLAY_NAME};
@@ -3794,7 +3795,7 @@ static void mail_engine_modify_notification_folder(IDB_ITEM *pidb,
37943795
auto pstmt = gx_sql_prep(pidb->psqlite, qstr.c_str());
37953796
if (pstmt == nullptr || pstmt.step() != SQLITE_ROW)
37963797
return;
3797-
std::string decoded_name = pstmt.col_text(0);
3798+
std::string decoded_name = znul(pstmt.col_text(0));
37983799
uint64_t parent_fid = pstmt.col_uint64(1);
37993800
pstmt.finalize();
38003801

lib/dbop_sqlite.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,18 @@ static constexpr char tbl_midb_folders_2[] =
508508
" sort_field INTEGER DEFAULT 0);"
509509
"CREATE INDEX parent_fid_index2 ON folders(parent_fid);";
510510

511-
static constexpr char tbl_midb_folders_move2[] =
511+
static constexpr char tbl_midb_folders_3[] =
512+
"CREATE TABLE folders ("
513+
" folder_id INTEGER PRIMARY KEY,"
514+
" parent_fid INTEGER NOT NULL,"
515+
" commit_max INTEGER NOT NULL,"
516+
" name TEXT COLLATE NOCASE UNIQUE,"
517+
" uidnext INTEGER DEFAULT 0,"
518+
" unsub INTEGER DEFAULT 0,"
519+
" sort_field INTEGER DEFAULT 0);"
520+
"CREATE INDEX parent_fid_index3 ON folders(parent_fid);";
521+
522+
static constexpr char tbl_midb_folders_move2_3[] =
512523
"INSERT INTO folders SELECT folder_id, parent_fid, commit_max, name, uidnext, unsub, sort_field FROM u0";
513524

514525
static constexpr char tbl_midb_msgs_0[] =
@@ -564,7 +575,7 @@ static constexpr tbl_init tbl_midb_init_0[] = {
564575

565576
static constexpr tbl_init tbl_midb_init_top[] = {
566577
{"configurations", tbl_config_1},
567-
{"folders", tbl_midb_folders_2},
578+
{"folders", tbl_midb_folders_3},
568579
{"messages", tbl_midb_msgs_0},
569580
{"mapping", tbl_midb_mapping_0},
570581
TABLE_END,
@@ -616,7 +627,8 @@ static constexpr tblite_upgradefn tbl_pub_upgrade_list[] = {
616627

617628
static constexpr tblite_upgradefn tbl_midb_upgrade_list[] = {
618629
{1, nullptr, "configurations", tbl_config_1, tbl_config_move1},
619-
{2, nullptr, "folders", tbl_midb_folders_2, tbl_midb_folders_move2},
630+
{2, nullptr, "folders", tbl_midb_folders_2, tbl_midb_folders_move2_3},
631+
{3, nullptr, "folders", tbl_midb_folders_3, tbl_midb_folders_move2_3},
620632
TABLE_END,
621633
};
622634

0 commit comments

Comments
 (0)