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
9 BEGIN { print "/* This file automatically generated */";
10 print "/* Do not edit */";
11 print "#include <stdio.h>";
12 print "EXEC SQL INCLUDE sqlca;";
13 print "#include \"dump_db.h\"";
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"
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"
27 rangename = substr(tablename, 1, 1);
33 printf "/* %s */\n", $0
34 if ($2 ~ /INTEGER/ || $2 ~ /SMALLINT/ || $2 ~ /INTEGER1/) {
35 printf "\tint\tt_%s;\n", vname[count]
37 } else if ($2 ~ /CHAR\([0-9]*\)/) {
38 t = split($2, temp, "(")
39 if (t != 2) printf "Can't parse %s\n", $2;
40 t = split(temp[2], temp2, ")")
41 if (t != 2) printf "Can't parse %s\n", temp[2];
42 printf "\tchar\tt_%s[%d];\n", vname[count], temp2[1]+1;
43 if ($1 == "signature") {
48 } else if ($2 ~ /DATE/) {
49 printf "\tchar\tt_%s[26];\n", vname[count]
51 } else printf "Unknown data type %s\n", $2;
56 printf "\tEXEC SQL END DECLARE SECTION;\n";
57 printf "\tEXEC SQL DECLARE c_%s CURSOR FOR\n", tablename;
58 printf "\t\tSELECT * FROM %s;\n", tablename;
59 printf "\tEXEC SQL OPEN c_%s;\n", tablename;
60 printf "\twhile(1) {\n\tEXEC SQL FETCH c_%s INTO\n", tablename;
61 for (i = 0; i < count; i++) {
62 if (i != 0) printf ",\n";
63 printf "\t\t:t_%s", vname[i];
66 printf "\tif(sqlca.sqlcode != 0) break;\n";
67 for (i = 0; i < count; i++) {
68 if (i != 0) print "\tdump_sep(f);"
69 printf "\tdump_%s(f, t_%s);\n", vtype[i], vname[i];
71 printf "\t\tdump_nl(f);\n";
73 printf "\tEXEC SQL CLOSE c_%s;\n", tablename;
74 printf "\tsafe_close(f);\n";
77 END { print "/* All done */"
78 print "}" >>"bkup1.dc"