データ流し込みプロフラムの例
0001: #! /usr/bin/perl
0002: # ------------------------------------------------------------- #
0003: # loadBirdList.pl
0004: # ===============
0005: # option : user=<ユーザー名>
0006: # password=<パスワード>
0007: # hostname=<サーバーホスト名>
0008: # dbpath=<データベースファイルのパス>
0009: # encode=<文字セットエンコーディング>
0010: #
0011: # $Id: loadBirdList.pl,v 1.10 ########## $
0012: # ------------------------------------------------------------- #
0013: use strict;
0014: use IBPerl;
0015: use lib "/usr/lib/perl5/5.8.0/i386-linux-thread-multi";
0016: use Time::HiRes;
0017:
0018: my($elapsed_t1)=&Time::HiRes::time();
0019: my(%param);
0020: $param{user}="SYSDBA";
0021: $param{password}="********";
0022: $param{hostname}="localhost";
0023: $param{dbpath}="/DB/birds/birds.fdb";
0024: $param{encode}="EUCJ_0208";
0025: for (@ARGV){
0026: my($k, $v)=split("=", $_);
0027: $param{$k}=$v;
0028: }
0029: my($DB)=IBPerl::Connection->new(Path=>"$param{hostname}:$param{dbpath}",
0030: User=>$param{user},
0031: Password=>$param{password},
0032: Charset=>$param{encode});
0033: my($trans)=IBPerl::Transaction->new(Database=>$DB);
0034: my($cnt, $insO, $insF, $insG, $insS)=(0, 0, 0, 0, 0);
0035: $|=1;
0036: while (<STDIN>){
0037: chomp;
0038: # 空行スキップ
0039: next if ($_=~/^$/);
0040: # // で始まる行は無視
0041: next if (/^\/\//);
0042: $cnt++;
0043: print("o") if (($cnt % 50)==0);
0044: print(" $cnt\n") if (($cnt % 1000)==0);
0045: # シングルクォートのエスケープ
0046: s/\'/\'\'/g;
0047: # カンマ区切りを分解
0048: # フィールド 0:種の学名 1:種の英名 2:種の和名 3:属の学名 4:属の和名
0049: # 5:科の学名 6:科の和名 7:目の学名 8:目の和名
0050: my(@f)=split(",");
0051: # SQL 文生成
0052: my($sql)="EXECUTE PROCEDURE PSGFO_CHKINSERT(0,'".
0053: join("','", ($f[7],$f[8],$f[5],$f[6],$f[3],$f[4],$f[0],$f[2],$f[1],uc($f[1]))).
0054: "')";
0055: # Stored Procedure 実行
0056: my($st)=IBPerl::Statement->new(Transaction=>$trans, SQL=>$sql);
0057: $st->execute();
0058: # Retern 値取得
0059: my(%hash);
0060: $st->fetch(\%hash);
0061: $insO+=$hash{INSORDER};
0062: $insF+=$hash{INSFAMILY};
0063: $insG+=$hash{INSGENUS};
0064: $insS+=$hash{INSSPECIES};
0065: }
0066: $trans->commit();
0067: $DB->disconnect();
0068: my($elapsed_t2)=&Time::HiRes::time();
0069:
0070: printf("\n%d %d %d %d %d %6.3f sec. elapsed\n",
0071: $insO, $insF, $insG, $insS, $cnt, $elapsed_t2-$elapsed_t1);
0072: exit(0);
この HTML を検査する。( XHTML 1.0 Strict で書かれています )
Another HTML Lint Gateway ( Mirrored by htmllint.oosato.org )