トリガー作成スクリプト
0001: #! /bin/bash 0002: # ------------------------------------------------------------ # 0003: # CreateTrigger.sh 0004: # ================ 0005: # 0006: # CreateTrigger.sh { <option> } 0007: # <option> : -d Trigger を削除する 0008: # -r Trigger を再作成する 0009: # 既定値は新規作成 0010: # encode=UTF8 CHARACTER SET を UTF8 にする 0011: # 既定値は EUCJ_0208 0012: # dbpath=<path> <path> の DBFILE を使う 0013: # 既定値は /DB/birds/birds.fdb 0014: # 0015: # $Id: CreateTrigger.sh,v 1.7 ########## $ 0016: # ------------------------------------------------------------ # 0017: encode="EUCJ_0208" 0018: dbpath="localhost:/DB/birds/birds.fdb" 0019: while [ "${1}" != "" ]; do 0020: if [ "${1:0:1}" == "-" ]; then 0021: param=${1} 0022: else 0023: if [ "${1:0:7}" == "encode=" ]; then 0024: encode=${1:7} 0025: fi 0026: if [ "${1:0:7}" == "dbpath=" ]; then 0027: dbpath=${1:7} 0028: fi 0029: fi 0030: shift 0031: done 0032: 0033: if [ "${param}" == "-d" ] || [ "${param}" == "-r" ]; then 0034: echo '**** DROP TRIGGER ****' 0035: isql<<EOF 0036: CONNECT "${dbpath}" USER "SYSDBA" PASSWORD "********"; 0037: DROP TRIGGER TR_SEQNOORDERTAB; 0038: DROP TRIGGER TR_SEQNOFAMILY; 0039: DROP TRIGGER TR_SEQNOGENUS; 0040: DROP TRIGGER TR_SEQNOSPECIES; 0041: DROP TRIGGER TR_SEQNOACCLOG; 0042: COMMIT; 0043: QUIT; 0044: EOF 0045: if [ "${param}" == "-d" ]; then 0046: exit 0047: fi 0048: fi 0049: 0050: echo '**** CREATE TRIGGER ****' 0051: isql<<EOF 0052: CONNECT $dbpath USER SYSDBA PASSWORD ********; 0053: /**************************************************************/ 0054: /* TRIGGER : SEQNOORDERTAB */ 0055: /* */ 0056: /* ORDERTAB の SEQNO を採番、更新する */ 0057: /* */ 0058: /**************************************************************/ 0059: SET TERM !! ; 0060: CREATE TRIGGER TR_SEQNOORDERTAB FOR ORDERTAB 0061: BEFORE INSERT 0062: AS 0063: DECLARE VARIABLE MAXSEQ INTEGER; 0064: BEGIN 0065: SELECT COUNTMAX FROM COUNTERTAB WHERE TABLENAME='ORDERTAB' INTO MAXSEQ; 0066: IF (MAXSEQ IS NOT NULL) THEN 0067: MAXSEQ=MAXSEQ+1; 0068: ELSE 0069: MAXSEQ=1; 0070: NEW.SEQNO=MAXSEQ; 0071: UPDATE COUNTERTAB SET COUNTMAX=:MAXSEQ WHERE TABLENAME='ORDERTAB'; 0072: END 0073: !! 0074: SET TERM ;!! 0075: COMMIT; 0076: 0077: /**************************************************************/ 0078: /* TRIGGER : SEQNOFAMILY */ 0079: /* */ 0080: /* FAMILY の SEQNO を採番、更新する */ 0081: /* */ 0082: /**************************************************************/ 0083: SET TERM !! ; 0084: CREATE TRIGGER TR_SEQNOFAMILY FOR FAMILY 0085: BEFORE INSERT 0086: AS 0087: DECLARE VARIABLE MAXSEQ INTEGER; 0088: BEGIN 0089: SELECT COUNTMAX FROM COUNTERTAB WHERE TABLENAME='FAMILY' INTO MAXSEQ; 0090: IF (MAXSEQ IS NOT NULL) THEN 0091: MAXSEQ=MAXSEQ+1; 0092: ELSE 0093: MAXSEQ=1; 0094: NEW.SEQNO=MAXSEQ; 0095: UPDATE COUNTERTAB SET COUNTMAX=:MAXSEQ WHERE TABLENAME='FAMILY'; 0096: END 0097: !! 0098: SET TERM ;!! 0099: COMMIT; 0100: 0101: /**************************************************************/ 0102: /* TRIGGER : SEQNOGENUS */ 0103: /* */ 0104: /* GENUS の SEQNO を採番、更新する */ 0105: /* */ 0106: /**************************************************************/ 0107: SET TERM !! ; 0108: CREATE TRIGGER TR_SEQNOGENUS FOR GENUS 0109: BEFORE INSERT 0110: AS 0111: DECLARE VARIABLE MAXSEQ INTEGER; 0112: BEGIN 0113: SELECT COUNTMAX FROM COUNTERTAB WHERE TABLENAME='GENUS' INTO MAXSEQ; 0114: IF (MAXSEQ IS NOT NULL) THEN 0115: MAXSEQ=MAXSEQ+1; 0116: ELSE 0117: MAXSEQ=1; 0118: NEW.SEQNO=MAXSEQ; 0119: UPDATE COUNTERTAB SET COUNTMAX=:MAXSEQ WHERE TABLENAME='GENUS'; 0120: END 0121: !! 0122: SET TERM ;!! 0123: COMMIT; 0124: 0125: /**************************************************************/ 0126: /* TRIGGER : SEQNOSPECIES */ 0127: /* */ 0128: /* SPECIES の SEQNO を採番、更新する */ 0129: /* */ 0130: /**************************************************************/ 0131: SET TERM !! ; 0132: CREATE TRIGGER TR_SEQNOSPECIES FOR SPECIES 0133: BEFORE INSERT 0134: AS 0135: DECLARE VARIABLE MAXSEQ INTEGER; 0136: BEGIN 0137: SELECT COUNTMAX FROM COUNTERTAB WHERE TABLENAME='SPECIES' INTO MAXSEQ; 0138: IF (MAXSEQ IS NOT NULL) THEN 0139: MAXSEQ=MAXSEQ+1; 0140: ELSE 0141: MAXSEQ=1; 0142: NEW.SEQNO=MAXSEQ; 0143: UPDATE COUNTERTAB SET COUNTMAX=:MAXSEQ WHERE TABLENAME='SPECIES'; 0144: END 0145: !! 0146: SET TERM ;!! 0147: COMMIT; 0148: 0149: /**************************************************************/ 0150: /* TRIGGER : SEQNOACCLOG */ 0151: /* */ 0152: /* ACCLOG の SEQNO を採番、更新する */ 0153: /* */ 0154: /**************************************************************/ 0155: SET TERM !! ; 0156: CREATE TRIGGER TR_SEQNOACCLOG FOR ACCLOG 0157: BEFORE INSERT 0158: AS 0159: DECLARE VARIABLE MAXSEQ INTEGER; 0160: BEGIN 0161: SELECT COUNTMAX FROM COUNTERTAB WHERE TABLENAME='ACCLOG' INTO MAXSEQ; 0162: IF (MAXSEQ IS NOT NULL) THEN 0163: MAXSEQ=MAXSEQ+1; 0164: ELSE 0165: MAXSEQ=1; 0166: NEW.SEQNO=MAXSEQ; 0167: UPDATE COUNTERTAB SET COUNTMAX=:MAXSEQ WHERE TABLENAME='ACCLOG'; 0168: END 0169: !! 0170: SET TERM ;!! 0171: COMMIT; 0172: 0173: QUIT; 0174: EOF 0175: exit
この HTML を検査する。( XHTML 1.0 Strict で書かれています )
Another HTML Lint Gateway ( Mirrored by htmllint.oosato.org )