Make descriptions unicode explicitely
[montanha:montanha.git] / update-totals
1 #!/bin/bash -e
2
3 if [ -z $1 ] || ! test -f $1; then
4     echo 'Give me an SQLite database to work on!'
5     exit 1
6 fi
7
8 sqlite3 $1 'drop table if exists totals_per_nature;'
9 sqlite3 $1 'create table totals_per_nature as select expenses.nature as nature, sum(expenses.expensed) as expensed from expenses group by expenses.nature;'
10 sqlite3 $1 'drop table if exists totals_per_legislator;'
11 sqlite3 $1 'create table totals_per_legislator as select legislators.id as id, legislators.name as name, legislators.party as party, sum(expenses.expensed) as expensed from legislators, expenses where legislators.id = expenses.legislator_id group by legislators.name, legislators.party order by expensed desc;'
12 sqlite3 $1 'drop table if exists totals_per_party;'
13 sqlite3 $1 'create table totals_per_party as select legislators.party as party, count(distinct(legislators.id)) as num_legislators, sum(expenses.expensed) as expensed from legislators, expenses where legislators.id = expenses.legislator_id group by party;'
14 sqlite3 $1 'drop table if exists totals_per_supplier;'
15 sqlite3 $1 'create table totals_per_supplier as select suppliers.name as name, suppliers.cnpj as cnpj, sum(expenses.expensed) as expensed from suppliers, expenses where suppliers.cnpj = expenses.supplier_cnpj group by cnpj order by expensed desc;'
16