]> andersk Git - moira.git/blame_incremental - backup/esqlc_fix.pl
Don't try to do a get_user_account_by_login with a username longer than 8
[moira.git] / backup / esqlc_fix.pl
... / ...
CommitLineData
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
13open(SCHEMA,"../db/schema") || die "Could not open schema, stopped\n";
14
15while(<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
32while(<>) {
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.318072 seconds and 5 git commands to generate.