-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The `FALSE` constant was introduced in sqlite version 3.23.0, but Android does not support this version of sqlite until API level 30; we support back to Android API 27 so we have to use `0` as the constant for `FALSE` instead.
- Loading branch information
Showing
4 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
zcash_client_sqlite/src/wallet/init/migrations/support_legacy_sqlite.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
//! A migration that removes the use of `FALSE` in sqlite view definitions. | ||
//! This is necessary to support older | ||
use std::collections::HashSet; | ||
|
||
use rusqlite; | ||
use schemer; | ||
use schemer_rusqlite::RusqliteMigration; | ||
use uuid::Uuid; | ||
|
||
use crate::wallet::init::{migrations::tx_retrieval_queue, WalletMigrationError}; | ||
|
||
pub(super) const MIGRATION_ID: Uuid = Uuid::from_u128(0xc9ed1fb5_b2c3_467f_89dc_2591dcca5562); | ||
|
||
const DEPENDENCIES: &[Uuid] = &[tx_retrieval_queue::MIGRATION_ID]; | ||
|
||
pub(super) struct Migration; | ||
|
||
impl schemer::Migration for Migration { | ||
fn id(&self) -> Uuid { | ||
MIGRATION_ID | ||
} | ||
|
||
fn dependencies(&self) -> HashSet<Uuid> { | ||
DEPENDENCIES.iter().copied().collect() | ||
} | ||
|
||
fn description(&self) -> &'static str { | ||
"Removes the FALSE keyword from the v_tx_outputs view definition" | ||
} | ||
} | ||
|
||
impl RusqliteMigration for Migration { | ||
type Error = WalletMigrationError; | ||
|
||
fn up(&self, transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> { | ||
transaction.execute_batch( | ||
r#" | ||
DROP VIEW v_tx_outputs; | ||
CREATE VIEW v_tx_outputs AS | ||
-- select all outputs received by the wallet | ||
SELECT transactions.txid AS txid, | ||
ro.pool AS output_pool, | ||
ro.output_index AS output_index, | ||
sent_notes.from_account_id AS from_account_id, | ||
ro.account_id AS to_account_id, | ||
NULL AS to_address, | ||
ro.value AS value, | ||
ro.is_change AS is_change, | ||
ro.memo AS memo | ||
FROM v_received_outputs ro | ||
JOIN transactions | ||
ON transactions.id_tx = ro.transaction_id | ||
-- join to the sent_notes table to obtain `from_account_id` | ||
LEFT JOIN sent_notes ON sent_notes.id = ro.sent_note_id | ||
UNION | ||
-- select all outputs sent from the wallet to external recipients | ||
SELECT transactions.txid AS txid, | ||
sent_notes.output_pool AS output_pool, | ||
sent_notes.output_index AS output_index, | ||
sent_notes.from_account_id AS from_account_id, | ||
NULL AS to_account_id, | ||
sent_notes.to_address AS to_address, | ||
sent_notes.value AS value, | ||
0 AS is_change, | ||
sent_notes.memo AS memo | ||
FROM sent_notes | ||
JOIN transactions | ||
ON transactions.id_tx = sent_notes.tx | ||
LEFT JOIN v_received_outputs ro ON ro.sent_note_id = sent_notes.id | ||
-- exclude any sent notes for which a row exists in the v_received_outputs view | ||
WHERE ro.account_id IS NULL | ||
"#, | ||
)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn down(&self, _: &rusqlite::Transaction) -> Result<(), WalletMigrationError> { | ||
Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::wallet::init::migrations::tests::test_migrate; | ||
|
||
#[test] | ||
fn migrate() { | ||
test_migrate(&[super::MIGRATION_ID]); | ||
} | ||
} |