fat32compat & ascii as separate columns in DB

This commit is contained in:
Vincent Riquer 2013-10-08 16:55:01 +02:00
parent 142c5438e6
commit 1b801cbe12
4 changed files with 59 additions and 5 deletions

View File

@ -1,18 +1,18 @@
#!/bin/bash #!/bin/bash
currentdbversion=1 currentdbversion=2
checkDatabaseVersion() { checkDatabaseVersion() {
local dbversion local dbversion
if dbversion=$(Select atom version <<<"1 = 1") if dbversion=$(Select atom version <<<"\"1\" = 1")
then then
if (( dbversion == currentdbversion )) if (( dbversion == currentdbversion ))
then then
return 0 return 0
elif (( dbversion < currentversion )) elif (( dbversion < currentdbversion ))
then then
until (( dbversion == currentversion )) until (( dbversion == currentdbversion ))
do do
upgradedatabase_${dbversion}_$((dbversion+1)) upgradedatabase_${dbversion}_$((dbversion+1))
dbversion=$(Select atom version <<<"1 = 1") dbversion=$(Select atom version <<<"\"1\" = 1")
done done
else else
echo "Database schema version $dbversion is higher than echo "Database schema version $dbversion is higher than
@ -23,4 +23,5 @@ checkDatabaseVersion() {
else else
Insert atom 1 <<<"version $currentdbversion" Insert atom 1 <<<"version $currentdbversion"
fi fi
exit
} }

View File

@ -0,0 +1,37 @@
#!/bin/bash
upgradedatabase_1_2() {
echo "Upgrading database to version 2... (backup is $database.bak_v1)"
cp "$database" "$database.bak_v1"
echo 'ALTER TABLE destination_files ADD COLUMN fat32compat INTEGER;' >&3
echo 'ALTER TABLE destination_files ADD COLUMN ascii INTEGER;' >&3
echo '
SELECT id,
rename_pattern
FROM destination_files;
SELECT "AtOM::NoMoreData";' >&3
read -u4 data
while [[ $data != AtOM::NoMoreData ]]
do
datas+=( "$data" )
read -u4 data
done
echo 'BEGIN TRANSACTION;' >&3
for data in "${datas[@]}"
do
id="${data%%::AtOM:SQL:Sep::*}"
rename_pattern="${data#*::AtOM:SQL:Sep::}"
IFS=':'
read pattern fat32 <<<"$rename_pattern"
IFS="$oldIFS"
Update destination_files \
rename_pattern "$pattern" \
fat32compat "$fat32" \
ascii 0 \
<<<"id = $id"
done
echo 'COMMIT;' >&3
Update atom version 2 <<<"1 = 1"
}

14
lib/tools/ascii Normal file
View File

@ -0,0 +1,14 @@
#!/bin/bash
ascii() {
coproc toascii {
perl -e '
use utf8;
use Text::Unidecode;
use open qw(:std :utf8);
$| = 1;
while (<>) {
print(unidecode($_));
}'
}
}

View File

@ -22,6 +22,8 @@ CREATE TABLE IF NOT EXISTS destination_files (
filename TEXT, filename TEXT,
old_filename TEXT, old_filename TEXT,
rename_pattern TEXT, rename_pattern TEXT,
fat32compat INTEGER,
ascii INTEGER,
last_change FLOAT NOT NULL DEFAULT 0, last_change FLOAT NOT NULL DEFAULT 0,
source_file_id INTEGER, source_file_id INTEGER,
destination_id INTEGER, destination_id INTEGER,