Skip to content

Commit bd8c708

Browse files
db-syntax-diffkawamura
authored andcommitted
add manuals and two scripts
1 parent f6cdcb2 commit bd8c708

File tree

3 files changed

+248
-0
lines changed

3 files changed

+248
-0
lines changed

bin/csvtool_utf8.pl

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#!/usr/bin/perl
2+
#
3+
# usage: perl csvtool_utf8.pl <CSV file> <TARGET_CHAR>
4+
#
5+
6+
use File::Basename;
7+
use utf8;
8+
use encoding 'utf-8';
9+
#
10+
# □ Java
11+
#
12+
# 00. フルパス名 PATHNAME
13+
# 01. クラス名 CLASS
14+
# 02. メソッド名 METHOD
15+
# 03. 行数 LINE
16+
# 04. カラム位置 COLUMN
17+
# 05. 非互換ID ID
18+
# 06. 非互換の分類 TYPE
19+
# 07. エラーレベル ERRORLV
20+
# 08. メッセージ MESSAGE
21+
# 09. SQL SQL
22+
23+
$PATHNAME = 0;
24+
$CLASS = 1;
25+
$METHOD = 2;
26+
$LINE = 3;
27+
$COLUMN = 4;
28+
$ID = 5;
29+
$TYPE = 6;
30+
$ERRORLV = 7;
31+
$MESSAGE = 8;
32+
$SQL = 9;
33+
$MAXCOL = 10;
34+
35+
my @messages = ();
36+
my $line = "";
37+
$" = ',';
38+
39+
open(IN, "<:encoding(shiftjis)" , "$ARGV[0]") or die "file open error.($ARGV[0]:$!)";
40+
41+
# 報告対象の有無を判定
42+
if ( $line = <IN> )
43+
{
44+
do
45+
{
46+
# CSV 解析
47+
my $tmp = $line;
48+
$tmp =~ s/(?:¥x0D¥x0A|[¥x0D¥x0A])?$/,/;
49+
my @onemsg = map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_}
50+
($tmp =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g);
51+
52+
# メッセージとSQLはダブルクォートで括っておく
53+
@onemsg[$MESSAGE] = '"' . @onemsg[$MESSAGE] . '"';
54+
@onemsg[$SQL] = '"' . @onemsg[$SQL] . '"';
55+
56+
#print "@onemsg[$ID] \n";
57+
#print "@onemsg\n";
58+
push(@messages, \@onemsg);
59+
}while ( $line = <IN> );
60+
61+
# 非互換IDでソート
62+
sort_messages_by_id(@messages);
63+
64+
close(IN);
65+
}
66+
else{
67+
print STDOUT "修正箇所はありませんでした。\n";
68+
close(IN);
69+
exit 0;
70+
}
71+
72+
#
73+
# 非互換IDでソートし、集計する。
74+
# 結果を <入力ファイル名>_id.csv に出力する。
75+
#
76+
sub sort_messages_by_id
77+
{
78+
my @msgs = @_;
79+
80+
my $arg_encoding = $ARGV[1];
81+
if ($arg_encoding eq 'eucjp') {$arg_encoding = "euc-jp";}
82+
83+
# ソート
84+
my @sort_id = sort { $a->[$ID] cmp $b->[$ID] # 非互換ID
85+
|| $a->[$PATHNAME] cmp $b->[$PATHNAME] # パス名
86+
|| $a->[$LINE] <=> $b->[$LINE] #
87+
|| $a->[$COLUMN] <=> $b->[$COLUMN] # カラム
88+
} @msgs;
89+
90+
# いまのメッセージ
91+
my $m = "";
92+
# 1つ前のメッセージ
93+
my $m_pre = "";
94+
my $count = 0;
95+
96+
my $id = $sort_id[0][$ID];
97+
#print "id = $id\n";
98+
99+
#各出力ファイルのオープン
100+
@extlist = ('.csv');
101+
($fn, $path, $ext) = fileparse($ARGV[0], @extlist);
102+
my $outfn = $path . $fn . "_id.csv";
103+
open(OUT, ">:encoding($arg_encoding)" , "$outfn") or die "file open error.($outfn:$!)";
104+
my $outfn_sjis = $path . $fn . "_id_sjis.csv";
105+
open(OUT2, ">:encoding(shiftjis)" , "$outfn_sjis") or die "file open error.($outfn_sjis:$!)";
106+
#メッセージID毎のファイルオープン
107+
# $outfn3 = $path . $fn. '_' . $id . '.csv';
108+
# open(OUT3, ">:encoding($arg_encoding)" , "$outfn3") or die "file open error.($outfn3:$!)";
109+
my $outfn4 = $path . $fn . '_' . $id . '.err';
110+
open(OUT4, ">:encoding($arg_encoding)" , "$outfn4") or die "file open error.($outfn4:$!)";
111+
112+
foreach $m (@sort_id)
113+
{
114+
#print "id = $id $m->[$ID]\n";
115+
if ($id ne $m->[$ID])
116+
{
117+
# 新しい非互換IDが現れたので、
118+
# これまで集計した非互換IDを持つメッセージの数を出力。
119+
print OUT "$m_pre->[$ID],$m_pre->[$TYPE],$m_pre->[$ERRORLV],$m_pre->[$MESSAGE],$count\n";
120+
print OUT2 "$m_pre->[$ID],$m_pre->[$TYPE],$m_pre->[$ERRORLV],$m_pre->[$MESSAGE],$count\r\n";
121+
# 新しい非互換IDを設定して、カウンタリセット。
122+
$id = $m->[$ID];
123+
$count = 0;
124+
125+
#メッセージID毎のファイルクローズ
126+
# close(OUT3);
127+
close(OUT4);
128+
#新しいメッセージIDでファイルオープン
129+
# $outfn3 = $path . $fn. '_' . $id . '.csv';
130+
# open(OUT3, ">:encoding($arg_encoding)" , "$outfn3") or die "file open error.($outfn3:$!)";
131+
$outfn4 = $path . $fn . '_' . $id . '.err';
132+
open(OUT4, ">:encoding($arg_encoding)" , "$outfn4") or die "file open error.($outfn4:$!)";
133+
134+
}
135+
$m_pre = $m;
136+
$count++;
137+
138+
# $comma = '';
139+
# for (my $i = 0; $i < $MAXCOL; $i++)
140+
# {
141+
# print OUT3 $comma . "$m->[$i]";
142+
# $comma = ',';
143+
# }
144+
# print OUT3 "\n";
145+
print OUT4 "$m->[$FILE]:$m->[$LINE]:$m->[$COLUMN]:$m->[$MESSAGE]\n";
146+
147+
}
148+
149+
# 新しい非互換ID。
150+
print OUT "$m_pre->[$ID],$m_pre->[$TYPE],$m_pre->[$ERRORLV],$m_pre->[$MESSAGE],$count\n";
151+
print OUT2 "$m_pre->[$ID],$m_pre->[$TYPE],$m_pre->[$ERRORLV],$m_pre->[$MESSAGE],$count\r\n";
152+
153+
#各出力ファイルのクローズ
154+
close(OUT);
155+
close(OUT2);
156+
# close(OUT3);
157+
close(OUT4);
158+
}

bin/db_syntax_diff_wrapper.sh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/sh
2+
3+
if [ $# -eq 1 -a -f "$1" ]; then
4+
source "$1";
5+
else
6+
echo "$0 <controlfile_path>" >&2;
7+
exit 1;
8+
fi
9+
10+
CUR=`dirname $0`;
11+
cd $CUR;
12+
13+
OUTDIR="../output/$OUTPUT_DIR_NAME";
14+
TMPDIR="../tmp/$OUTPUT_DIR_NAME";
15+
if [ -e "$OUTDIR" ]; then
16+
echo "output directory is already exist.($OUTDIR)" >&2;
17+
exit 1;
18+
fi
19+
if [ -e "$TMPDIR" ]; then
20+
echo "tmp directory is already exist.($TMPDIR)" >&2;
21+
exit 1;
22+
fi
23+
mkdir -p "$OUTDIR";
24+
mkdir -p "$TMPDIR";
25+
STYLEDIR="../stylesheet"
26+
# 1. execute db_syntax_diff
27+
# > $TMPDIR/tmp.xml
28+
db_syntax_diff.pl -e "${TARGET_CHAR}" -i "${TARGET_PATH},${TARGET_EXT}" -o "${TMPDIR}/tmp.xml" -m "${TARGET_MODE}";
29+
if [ $? -ne 0 ]; then
30+
echo "db_syntax_diff.pl error." >&2;
31+
exit 1;
32+
fi
33+
34+
# 2. multibyte_space
35+
# > $TMPDIR/multibyte_space.xml
36+
java org.apache.xalan.xslt.Process -in "${TMPDIR}/tmp.xml" -xsl ${STYLEDIR}/erase_multibyte_space.xsl -out "${TMPDIR}/multibyte_space.xml";
37+
# 3. remove duplicate
38+
# > ${TMPDIR}/rm_duplicate.xml
39+
java org.apache.xalan.xslt.Process -in "${TMPDIR}/multibyte_space.xml" -xsl ${STYLEDIR}/erase_duplicate.xsl -out "${TMPDIR}/rm_duplicate.xml";
40+
41+
# 4. translate to csv
42+
if [ -z "${POSTGRESQL_VERSION}" -a -z "${ORAFCE_VERSION}" ]; then
43+
## 4-1. if version is NOT given
44+
## > ${OUTDIR}/result.csv
45+
java org.apache.xalan.xslt.Process -in "${TMPDIR}/rm_duplicate.xml" -xsl ${STYLEDIR}/make_csv.xsl -out "${OUTDIR}/result.csv";
46+
elif [ -z "${ORAFCE_VERSION}" -a -n "${POSTGRESQL_VERSION}" ]; then
47+
## 4-2. if PostgreSQL version is given
48+
## > ${TMPDIR}/adjust_version_PG.xml
49+
## > ${OUTDIR}/result.csv
50+
java org.apache.xalan.xslt.Process -in "${TMPDIR}/rm_duplicate.xml" -xsl ${STYLEDIR}/support_version.xsl -out "${TMPDIR}/adjust_version_PG.xml" -param product_val PostgreSQL -param version_val "${POSTGRESQL_VERSION}";
51+
java org.apache.xalan.xslt.Process -in "${TMPDIR}/adjust_version_PG.xml" -xsl ${STYLEDIR}/make_csv.xsl -out "${OUTDIR}/result.csv";
52+
elif [ -z "${POSTGRESQL_VERSION}" -a -n "${ORAFCE_VERSION}" ]; then
53+
## 4-3. if orafce version is given
54+
## > ${TMPDIR}/adjust_version_orafce.xml
55+
## > ${OUTDIR}/result.csv
56+
java org.apache.xalan.xslt.Process -in "${TMPDIR}/rm_duplicate.xml" -xsl ${STYLEDIR}/support_version.xsl -out "${TMPDIR}/adjust_version_orafce.xml" -param product_val orafce -param version_val "${ORAFCE_VERSION}";
57+
java org.apache.xalan.xslt.Process -in "${TMPDIR}/adjust_version_orafce.xml" -xsl ${STYLEDIR}/make_csv.xsl -out "${OUTDIR}/result.csv";
58+
else
59+
## 4-4. if PostgreSQL and orafce version is given
60+
## > ${TMPDIR}/adjust_version_PG.xml
61+
## > ${TMPDIR}/adjust_version_orafce.xml
62+
## > ${OUTDIR}/result.csv
63+
java org.apache.xalan.xslt.Process -in "${TMPDIR}/rm_duplicate.xml" -xsl ${STYLEDIR}/support_version.xsl -out "${TMPDIR}/adjust_version_PG.xml" -param product_val PostgreSQL -param version_val "${POSTGRESQL_VERSION}";
64+
java org.apache.xalan.xslt.Process -in "${TMPDIR}/adjust_version_PG.xml" -xsl ${STYLEDIR}/support_version.xsl -out "${TMPDIR}/adjust_version_orafce.xml" -param product_val orafce -param version_val "${ORAFCE_VERSION}";
65+
java org.apache.xalan.xslt.Process -in "${TMPDIR}/adjust_version_orafce.xml" -xsl ${STYLEDIR}/make_csv.xsl -out "${OUTDIR}/result.csv";
66+
fi
67+
68+
## clean tmpdir
69+
rm -rf "${TMPDIR}";
70+
71+
# 5. execute csvtool
72+
## 5-1. make csv & link solution files.
73+
cd ${OUTDIR};
74+
mkdir csv;
75+
mkdir editdata;
76+
mv result.csv csv/;
77+
cd csv;
78+
perl ../../../bin/csvtool_utf8.pl result.csv "${TARGET_CHAR}"
79+
if [ $? -ne 0 ]; then
80+
echo "csvtool_utf8.pl error." >&2;
81+
rm -rf "${TMPDIR}";
82+
exit 1;
83+
fi
84+
85+
if [ $(find -name "*.err" | wc -w) -ne 0 ]; then
86+
## 5-2. make data for editing.
87+
mv *.err ../editdata/
88+
fi
89+
90+
exit 0;

doc/db_syntax_diff_manual.zip

110 KB
Binary file not shown.

0 commit comments

Comments
 (0)