]>
Commit | Line | Data |
---|---|---|
6fb7536b | 1 | # $Source$ |
2 | # $Header$ | |
3 | # | |
4 | # This converts the file used to originally create the database | |
5 | # into a program to back it up. | |
6 | # This is not guaranteed to work for all data types; it may | |
7 | # need to be extended. | |
8 | ||
9 | BEGIN { print "/* This file automatically generated */"; | |
10 | print "/* Do not edit */"; | |
11 | print "#include <stdio.h>"; | |
3388d7f8 | 12 | print "EXEC SQL INCLUDE sqlca;"; |
d55654f4 | 13 | print "#include \"dump_db.h\""; |
3388d7f8 | 14 | print; |
15 | print "/* This file automatically generated */" > "bkup1.dc"; | |
16 | print "/* Do not edit */" >> "bkup1.dc" | |
17 | print "#include <stdio.h>" >> "bkup1.dc" | |
18 | print "FILE *open_file();" >> "bkup1.dc" | |
19 | print "do_backups(prefix)\n\tchar *prefix;\n{" >>"bkup1.dc" | |
6fb7536b | 20 | } |
21 | ||
3388d7f8 | 22 | $1=="#" { next; } |
23 | ||
24 | /^create/ { printf "dump_%s(f)\nFILE *f;\n{\n\tEXEC SQL BEGIN DECLARE SECTION;\n", $3; | |
25 | printf "\tdump_%s(open_file(prefix, \"%s\"));\n", $3, $3 >> "bkup1.dc" | |
26 | tablename = $3; | |
6fb7536b | 27 | rangename = substr(tablename, 1, 1); |
3388d7f8 | 28 | count = 0; |
29 | next;} | |
6fb7536b | 30 | |
3388d7f8 | 31 | NF>=2 { |
6fb7536b | 32 | vname[count] = $1; |
33 | printf "/* %s */\n", $0 | |
3388d7f8 | 34 | if ($2 ~ /INTEGER/ || $2 ~ /SMALLINT/ || $2 ~ /INTEGER1/) { |
35 | printf "\tint\tt_%s;\n", vname[count] | |
6fb7536b | 36 | vtype[count]="int" |
3388d7f8 | 37 | } else if ($2 ~ /CHAR\([0-9]*\)/) { |
38 | t = split($2, temp, "(") | |
39 | if (t != 2) printf "Can't parse %s\n", $2; | |
6fb7536b | 40 | t = split(temp[2], temp2, ")") |
41 | if (t != 2) printf "Can't parse %s\n", temp[2]; | |
3388d7f8 | 42 | printf "\tchar\tt_%s[%d];\n", vname[count], temp2[1]+1; |
6fb7536b | 43 | vtype[count]="str" |
3388d7f8 | 44 | } else if ($2 ~ /DATE/) { |
45 | printf "\tchar\tt_%s[26];\n", vname[count] | |
6fb7536b | 46 | vtype[count]="str" |
3388d7f8 | 47 | } else printf "Unknown data type %s\n", $2; |
6fb7536b | 48 | count++; |
49 | } | |
50 | ||
3388d7f8 | 51 | /^\);$/ { |
52 | printf "\tEXEC SQL END DECLARE SECTION;\n"; | |
53 | printf "\tEXEC SQL DECLARE c_%s CURSOR FOR\n", tablename; | |
54 | printf "\t\tSELECT * FROM %s;\n", tablename; | |
55 | printf "\tEXEC SQL OPEN c_%s;\n", tablename; | |
56 | printf "\twhile(1) {\n\tEXEC SQL FETCH c_%s INTO\n", tablename; | |
6fb7536b | 57 | for (i = 0; i < count; i++) { |
58 | if (i != 0) printf ",\n"; | |
3388d7f8 | 59 | printf "\t\t:t_%s", vname[i]; |
6fb7536b | 60 | } |
3388d7f8 | 61 | printf ";\n"; |
62 | printf "\tif(sqlca.sqlcode != 0) break;\n"; | |
6fb7536b | 63 | for (i = 0; i < count; i++) { |
3388d7f8 | 64 | if (i != 0) print "\tdump_sep(f);" |
65 | printf "\tdump_%s(f, t_%s);\n", vtype[i], vname[i]; | |
6fb7536b | 66 | } |
3388d7f8 | 67 | printf "\t\tdump_nl(f);\n"; |
68 | printf "\t}\n"; | |
69 | printf "\tEXEC SQL CLOSE c_%s;\n", tablename; | |
70 | printf "\tsafe_close(f);\n"; | |
71 | printf "}\n"; | |
6fb7536b | 72 | } |
73 | END { print "/* All done */" | |
3388d7f8 | 74 | print "}" >>"bkup1.dc" |
6fb7536b | 75 | } |