]> andersk Git - moira.git/blame - backup/esqlc_fix.pl
handle signature as binary field
[moira.git] / backup / esqlc_fix.pl
CommitLineData
01a211e1 1#!/usr/athena/bin/perl -i.bak
7db32eca 2
01a211e1 3# Limitations:
7db32eca 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
01a211e1 9# 5. Only references within CURSOR loops are corrected.
7db32eca 10
11
01a211e1 12# Step 1. Read the schema, so we know the proper field lengths
7db32eca 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
7db32eca 26# Step 2. Read the code to be cleaned up
27
01a211e1 28# Pass through most lines.
29# Note the opening and closing of cursors.
30# Play with IIcsGetio. Change 4th argument if it's wrong.
7db32eca 31
32while(<>) {
33 if(/IIwritio\(.*"select.*from\s+(\w+)"\);/) {
34 $table = $1;
35 next;
36 }
01a211e1 37 if(/IIcsGetio\((.*,.*,.*,(\d+),&?t_(\w+))\);/) {
7db32eca 38 $width = $2;
39 $field = $3;
40
41 $tablefield = $table . "." . $field;
42 $shouldbe = $fields{$tablefield};
43
44 if( $shouldbe && $shouldbe != $width ) {
01a211e1 45 s/(\(.*,.*,.*,)(\d+),/\1$shouldbe,/;
7db32eca 46 }
47 }
48} continue {
01a211e1 49 print;
7db32eca 50}
51
This page took 0.232225 seconds and 5 git commands to generate.