]> andersk Git - moira.git/blob - backup/esqlc_fix.pl
Found this version on Moira server. Has various fixes/adaptations.
[moira.git] / backup / esqlc_fix.pl
1 #!/usr/athena/bin/perl -i.bak
2
3 # Limitations:
4 # 1. Schema must have "create table tablename" all on one line
5 # 2. Fields (columns) must be declared "NOT NULL WITH DEFAULT"
6 # 3. C variables corresponding to database fields must use the
7 #    database field name with "t_" prefixed.
8 # 4. Field names, table names, and C "t_" variable names are of the same case
9 # 5. Only references within CURSOR loops are corrected.
10
11
12 # Step 1. Read the schema, so we know the proper field lengths
13 open(SCHEMA,"../db/schema") || die "Could not open schema, stopped\n";
14
15 while(<SCHEMA>) {
16     if(/create\s+table\s+/) {
17         ($table,$ignore) = split(' ',$');
18         next;
19     }
20     if(/\s+(\w+)\s+(VAR)?CHAR\((\d+)\)\s+NOT NULL WITH DEFAULT/) {
21         $fields{$table . "." . $1} = $3;
22     }
23 }
24
25
26 # Step 2. Read the code to be cleaned up
27
28 # Pass through most lines.
29 # Note the opening and closing of cursors.
30 # Play with IIcsGetio.  Change 4th argument if it's wrong.
31
32 while(<>) {
33     if(/IIwritio\(.*"select.*from\s+(\w+)"\);/) {
34         $table = $1;
35         next;
36     }
37     if(/IIcsGetio\((.*,.*,.*,(\d+),&?t_(\w+))\);/) {
38            $width = $2;
39            $field = $3;
40
41            $tablefield = $table . "." . $field;
42            $shouldbe = $fields{$tablefield};
43
44            if( $shouldbe && $shouldbe != $width ) {
45                s/(\(.*,.*,.*,)(\d+),/\1$shouldbe,/;
46            }
47        }
48 } continue {
49     print;
50 }
51
This page took 0.043035 seconds and 5 git commands to generate.