summaryrefslogtreecommitdiffstats
path: root/data/table.awk
blob: c097ec26f405b8ba636a75e8f890f622509ef7ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/awk

BEGIN {
    # Begin a transaction
    print "BEGIN TRANSACTION;"

    # Create english table
    print "CREATE TABLE IF NOT EXISTS phrases ( "      \
        "id INTEGER PRIMARY KEY NOT NULL,"             \
        "tabkeys TEXT NOT NULL,"                       \
        "phrase TEXT NOT NULL,"                        \
        "freq INTEGER NOT NULL DEFAULT (10)"           \
        ");";

    # Create desc table
    print "CREATE TABLE IF NOT EXISTS desc (name TEXT PRIMARY KEY, value TEXT);";
    print "INSERT OR IGNORE INTO desc VALUES ('version', '1.12.0');";

    id = 1;
}

# Insert data into phrases table
NF == 4 {
    printf "INSERT INTO phrases (id, tabkeys, phrase) VALUES (%d, '%s', '%s');\n", id, $3, $1;
    id++;
}

#quit sqlite3
END {
    # Commit the transcation
    print "COMMIT;"
}