sql: replace empty paramsv![] with empty tuples

This commit is contained in:
link2xt
2023-03-15 22:01:22 +00:00
parent 8db64726ea
commit f024909611
17 changed files with 49 additions and 67 deletions

View File

@@ -334,7 +334,7 @@ async fn set_dkim_works_timestamp(
async fn clear_dkim_works(context: &Context) -> Result<()> {
context
.sql
.execute("DELETE FROM sending_domains", paramsv![])
.execute("DELETE FROM sending_domains", ())
.await?;
Ok(())
}

View File

@@ -853,7 +853,7 @@ impl ChatId {
AND c.blocked=0
AND c.archived=1
",
paramsv![],
(),
)
.await?
} else {
@@ -2578,7 +2578,7 @@ pub async fn marknoticed_chat(context: &Context, chat_id: ChatId) -> Result<()>
"SELECT DISTINCT(m.chat_id) FROM msgs m
LEFT JOIN chats c ON m.chat_id=c.id
WHERE m.state=10 AND m.hidden=0 AND m.chat_id>9 AND c.blocked=0 AND c.archived=1",
paramsv![],
(),
|row| row.get::<_, ChatId>(0),
|ids| ids.collect::<Result<Vec<_>, _>>().map_err(Into::into)
)
@@ -3500,10 +3500,7 @@ pub(crate) async fn get_chat_cnt(context: &Context) -> Result<usize> {
// no database, no chats - this is no error (needed eg. for information)
let count = context
.sql
.count(
"SELECT COUNT(*) FROM chats WHERE id>9 AND blocked=0;",
paramsv![],
)
.count("SELECT COUNT(*) FROM chats WHERE id>9 AND blocked=0;", ())
.await?;
Ok(count)
} else {
@@ -3676,17 +3673,14 @@ pub(crate) async fn delete_and_reset_all_device_msgs(context: &Context) -> Resul
paramsv![ContactId::DEVICE],
)
.await?;
context
.sql
.execute("DELETE FROM devmsglabels;", paramsv![])
.await?;
context.sql.execute("DELETE FROM devmsglabels;", ()).await?;
// Insert labels for welcome messages to avoid them being readded on reconfiguration.
context
.sql
.execute(
r#"INSERT INTO devmsglabels (label) VALUES ("core-welcome-image"), ("core-welcome")"#,
paramsv![],
(),
)
.await?;
context.set_config(Config::QuotaExceeding, None).await?;

View File

@@ -424,7 +424,7 @@ impl Context {
match key {
Config::Selfavatar => {
self.sql
.execute("UPDATE contacts SET selfavatar_sent=0;", paramsv![])
.execute("UPDATE contacts SET selfavatar_sent=0;", ())
.await?;
match value {
Some(value) => {

View File

@@ -590,7 +590,7 @@ impl Context {
.unwrap_or_default();
let journal_mode = self
.sql
.query_get_value("PRAGMA journal_mode;", paramsv![])
.query_get_value("PRAGMA journal_mode;", ())
.await?
.unwrap_or_else(|| "unknown".to_string());
let e2ee_enabled = self.get_config_int(Config::E2eeEnabled).await?;
@@ -598,14 +598,11 @@ impl Context {
let bcc_self = self.get_config_int(Config::BccSelf).await?;
let send_sync_msgs = self.get_config_int(Config::SendSyncMsgs).await?;
let prv_key_cnt = self
.sql
.count("SELECT COUNT(*) FROM keypairs;", paramsv![])
.await?;
let prv_key_cnt = self.sql.count("SELECT COUNT(*) FROM keypairs;", ()).await?;
let pub_key_cnt = self
.sql
.count("SELECT COUNT(*) FROM acpeerstates;", paramsv![])
.count("SELECT COUNT(*) FROM acpeerstates;", ())
.await?;
let fingerprint_str = match SignedPublicKey::load_self(self).await {
Ok(key) => key.fingerprint().hex(),

View File

@@ -1173,7 +1173,7 @@ mod tests {
// No other messages are marked for deletion.
assert_eq!(
t.sql
.count("SELECT COUNT(*) FROM imap WHERE target=''", paramsv![],)
.count("SELECT COUNT(*) FROM imap WHERE target=''", ())
.await?,
0
);
@@ -1187,10 +1187,7 @@ mod tests {
.update_download_state(&t, DownloadState::Available)
.await?;
t.sql
.execute(
"UPDATE imap SET target=folder WHERE rfc724_mid='1000'",
paramsv![],
)
.execute("UPDATE imap SET target=folder WHERE rfc724_mid='1000'", ())
.await?;
delete_expired_imap_messages(&t).await?;
test_marked_for_deletion(&t, 1000).await?; // Delete downloadable anyway.
@@ -1201,10 +1198,7 @@ mod tests {
delete_expired_imap_messages(&t).await?;
test_marked_for_deletion(&t, 1010).await?;
t.sql
.execute(
"UPDATE imap SET target=folder WHERE rfc724_mid='1010'",
paramsv![],
)
.execute("UPDATE imap SET target=folder WHERE rfc724_mid='1010'", ())
.await?;
MsgId::new(1010)
@@ -1214,7 +1208,7 @@ mod tests {
// Keep downloadable for now.
assert_eq!(
t.sql
.count("SELECT COUNT(*) FROM imap WHERE target=''", paramsv![],)
.count("SELECT COUNT(*) FROM imap WHERE target=''", ())
.await?,
0
);

View File

@@ -697,7 +697,7 @@ async fn export_self_keys(context: &Context, dir: &Path) -> Result<()> {
.sql
.query_map(
"SELECT id, public_key, private_key, is_default FROM keypairs;",
paramsv![],
(),
|row| {
let id = row.get(0)?;
let public_key_blob: Vec<u8> = row.get(1)?;

View File

@@ -148,7 +148,7 @@ impl DcKey for SignedSecretKey {
WHERE addr=(SELECT value FROM config WHERE keyname="configured_addr")
AND is_default=1;
"#,
paramsv![],
(),
|row| {
let bytes: Vec<u8> = row.get(0)?;
Ok(bytes)
@@ -302,7 +302,7 @@ pub async fn store_self_keypair(
.context("failed to remove old use of key")?;
if default == KeyPairUse::Default {
transaction
.execute("UPDATE keypairs SET is_default=0;", paramsv![])
.execute("UPDATE keypairs SET is_default=0;", ())
.context("failed to clear default")?;
}
let is_default = match default {
@@ -592,7 +592,7 @@ i8pcjGO+IZffvyZJVRWfVooBJmWWbPB1pueo3tx8w3+fcuzpxz+RLFKaPyqXO+dD
let nrows = || async {
ctx.sql
.count("SELECT COUNT(*) FROM keypairs;", paramsv![])
.count("SELECT COUNT(*) FROM keypairs;", ())
.await
.unwrap()
};

View File

@@ -434,10 +434,7 @@ fn is_marker(txt: &str) -> bool {
/// Deletes all locations from the database.
pub async fn delete_all(context: &Context) -> Result<()> {
context
.sql
.execute("DELETE FROM locations;", paramsv![])
.await?;
context.sql.execute("DELETE FROM locations;", ()).await?;
context.emit_event(EventType::LocationChanged(None));
Ok(())
}

View File

@@ -1794,7 +1794,7 @@ pub async fn get_unblocked_msg_cnt(context: &Context) -> usize {
"SELECT COUNT(*) \
FROM msgs m LEFT JOIN chats c ON c.id=m.chat_id \
WHERE m.id>9 AND m.chat_id>9 AND c.blocked=0;",
paramsv![],
(),
)
.await
{
@@ -1814,7 +1814,7 @@ pub async fn get_request_msg_cnt(context: &Context) -> usize {
"SELECT COUNT(*) \
FROM msgs m LEFT JOIN chats c ON c.id=m.chat_id \
WHERE c.blocked=2;",
paramsv![],
(),
)
.await
{

View File

@@ -718,7 +718,7 @@ pub(crate) async fn deduplicate_peerstates(sql: &Sql) -> Result<()> {
FROM acpeerstates
GROUP BY addr
)",
paramsv![],
(),
)
.await?;

View File

@@ -163,7 +163,7 @@ impl BobState {
// guaranteed to only have one row.
sql.query_row_optional(
"SELECT id, invite, next_step, chat_id FROM bobstate;",
paramsv![],
(),
|row| {
let s = BobState {
id: row.get(0)?,

View File

@@ -220,7 +220,7 @@ impl Sql {
let addrs = self
.query_map(
"SELECT addr FROM acpeerstates;",
paramsv![],
(),
|row| row.get::<_, String>(0),
|addrs| {
addrs
@@ -742,7 +742,7 @@ pub async fn housekeeping(context: &Context) -> Result<()> {
.sql
.execute(
"DELETE FROM msgs_mdns WHERE msg_id NOT IN (SELECT id FROM msgs)",
paramsv![],
(),
)
.await
.ok_or_log_msg(context, "failed to remove old MDNs");
@@ -790,7 +790,7 @@ pub async fn remove_unused_files(context: &Context) -> Result<()> {
.sql
.query_map(
"SELECT value FROM config;",
paramsv![],
(),
|row| row.get::<_, String>(0),
|rows| {
for row in rows {
@@ -925,7 +925,7 @@ async fn maybe_add_from_param(
) -> Result<()> {
sql.query_map(
query,
paramsv![],
(),
|row| row.get::<_, String>(0),
|rows| {
for row in rows {

View File

@@ -391,7 +391,7 @@ UPDATE chats SET protected=1, type=120 WHERE type=130;"#,
sql.execute(
r#"
CREATE TABLE imap_sync (folder TEXT PRIMARY KEY, uidvalidity INTEGER DEFAULT 0, uid_next INTEGER DEFAULT 0);"#,
paramsv![]
()
)
.await?;
for c in &[

View File

@@ -155,7 +155,7 @@ impl Context {
.sql
.query_map(
"SELECT id, item FROM multi_device_sync ORDER BY id;",
paramsv![],
(),
|row| Ok((row.get::<_, u32>(0)?, row.get::<_, String>(1)?)),
|rows| {
let mut ids = vec![];
@@ -201,7 +201,7 @@ impl Context {
self.sql
.execute(
&format!("DELETE FROM multi_device_sync WHERE id IN ({ids});"),
paramsv![],
(),
)
.await?;
Ok(())

View File

@@ -398,7 +398,7 @@ impl TestContext {
SELECT id, msg_id, mime, recipients
FROM smtp
ORDER BY id DESC"#,
paramsv![],
(),
|row| {
let rowid: i64 = row.get(0)?;
let msg_id: MsgId = row.get(1)?;

View File

@@ -438,7 +438,7 @@ impl Context {
"DELETE FROM smtp_status_updates
WHERE msg_id IN (SELECT msg_id FROM smtp_status_updates LIMIT 1)
RETURNING msg_id, first_serial, last_serial, descr",
paramsv![],
(),
|row| {
let instance_id: MsgId = row.get(0)?;
let first_serial: StatusUpdateSerial = row.get(1)?;
@@ -1195,7 +1195,7 @@ mod tests {
);
assert_eq!(
t.sql
.count("SELECT COUNT(*) FROM msgs_status_updates;", paramsv![],)
.count("SELECT COUNT(*) FROM msgs_status_updates;", ())
.await?,
0
);
@@ -1543,14 +1543,14 @@ mod tests {
assert_eq!(
t.sql
.count("SELECT COUNT(*) FROM smtp_status_updates", paramsv![],)
.count("SELECT COUNT(*) FROM smtp_status_updates", ())
.await?,
1
);
t.flush_status_updates().await?;
assert_eq!(
t.sql
.count("SELECT COUNT(*) FROM smtp_status_updates", paramsv![],)
.count("SELECT COUNT(*) FROM smtp_status_updates", ())
.await?,
0
);
@@ -1580,7 +1580,7 @@ mod tests {
.await?;
assert_eq!(
t.sql
.count("SELECT COUNT(*) FROM smtp_status_updates", paramsv![],)
.count("SELECT COUNT(*) FROM smtp_status_updates", ())
.await?,
3
);
@@ -1606,7 +1606,7 @@ mod tests {
}
assert_eq!(
t.sql
.count("SELECT COUNT(*) FROM smtp_status_updates", paramsv![],)
.count("SELECT COUNT(*) FROM smtp_status_updates", ())
.await?,
2 - i
);
@@ -1648,7 +1648,7 @@ mod tests {
assert_eq!(
alice
.sql
.count("SELECT COUNT(*) FROM smtp_status_updates", paramsv![],)
.count("SELECT COUNT(*) FROM smtp_status_updates", ())
.await?,
0
);
@@ -2438,7 +2438,7 @@ sth_for_the = "future""#
assert_eq!(
alice
.sql
.count("SELECT COUNT(*) FROM msgs_status_updates;", paramsv![],)
.count("SELECT COUNT(*) FROM msgs_status_updates;", ())
.await?,
0
);
@@ -2461,7 +2461,7 @@ sth_for_the = "future""#
assert!(
alice
.sql
.count("SELECT COUNT(*) FROM msgs_status_updates;", paramsv![],)
.count("SELECT COUNT(*) FROM msgs_status_updates;", ())
.await?
> 0
);