DMSQS ;SFISC/JHM-BUILD STANDARD SCHEMA ;7/31/97 13:55
;;22.0;VA FileMan;;Mar 30, 1999
;Per VHA Directive 10-93-142, this routine should not be modified.
Q
SCHEMA ;BUILD OR REPLACE SQLI SCHEMA
N SI,TT,IEN,FDA
S SI=$O(^DMSQ("S","B","SQLI",""))
S TT=1.521,IEN=$S(SI:SI,1:"+1")_","
S FDA(TT,IEN,.01)="SQLI" ; SCHEMA NAME
S FDA(TT,IEN,2)="FileMan SQL/ODBC interface tables" ; COMMENT
S SI=$$PUT^DMSQU(IEN,"FDA","ERR")
I $D(ERR)!'SI D ERR^DMSQU(1.521,"","SCHEMA: RECORD INSERT FAILED")
Q
ALLS Q:$G(DUZ(0))'["@" N TI,@$$NEW^DMSQU D ENV^DMSQU S TI=0
F S TI=$O(^DMSQ("T",TI)) Q:'TI D STEXE
Q
STATS(TI) ;DO NODE STATISTICS FOR TABLE TI
Q:$G(DUZ(0))'["@" ;NOT FOR NON-PROGRAMMERS
Q:'$D(^DMSQ("T",TI,0)) ;NO GLOBAL STRUCTURE ON FILE
N @$$NEW^DMSQU D ENV^DMSQU
STEXE N T,MT,G,G0,CND,K,O,INI,C,MC,I,CT,TT,IEN,FDA,ERR,PI,PEI,F
S T=^DMSQ("T",TI,0),MT=$P(T,U,4),(G0,G)=$G(^(1)) Q:G=""
S CND=$S(MT:"K(OI)]""""",1:"K(OI)"),INI=$S(MT:"",1:0),MC=5000
S (CT,O)=0,F="{K}" F Q:G'[F D
. S O=O+1,K="K("_O_")"
. S G(O)=$P(G,F)_K_")",C(O)=0,G=$P(G,F)_K_$P(G,F,2,9)
S K(1)=INI D CNT(1)
I CT=MC S OI=1 D
. F I=2:1:O S C(I)=C(I)/C(1)
. F S K(1)=$O(@G(1)),@("K="_CND) Q:'K S C(1)=C(1)+1
. F I=2:1:O S C(I)=C(I)*C(1) I C(I)["." D
. . S C(I)=$S(C(I)<10:+$J(C(I),"",2),C(I)<100:+$J(C(I),"",1),1:C(I)\1)
K ^STATS(TI) M ^STATS(TI)=C ;REMOVE AFTER DEBUG
;STORE T_ROW_COUNT IN SQLI_TABLE
S TT=1.5215,IEN=TI_"," K FDA
S FDA(TT,IEN,5)=C(O) ;NUMBER OF ROWS IN TABLE
S C=$$PUT^DMSQU(IEN,"FDA","ERR")
I $D(ERR)!'C D ERR^DMSQU(TT,"","STATS: RECORD INSERT FAILED")
;STORE P_ROW_COUNT IN SQLI_PRIMARY_KEY
S TT=1.5218,PEI=$O(^DMSQ("E","D",TI,"")),PI=0
F I=1:1 S PI=$O(^DMSQ("P","B",PEI,PI)) Q:'PI D
. S IEN=PI_"," K FDA
. S FDA(TT,IEN,5)=C(I) ;ESTIMATED ROW COUNT FOR THIS LEVEL
. S C=$$PUT^DMSQU(IEN,"FDA","ERR")
. I $D(ERR)!'C D ERR^DMSQU(TT,5,"STATS: KEY COUNT INSERT FAILED")
Q
CNT(OI) ;ACCUMULATE NODE COUNT
F S K(OI)=$O(@G(OI)) D Q:'OI
. I @CND D
. . S CT=CT+1,C(OI)=C(OI)+1 I CT=MC S OI=0
. . E I OI<O S OI=OI+1,K(OI)=INI
. E S OI=OI-1
Q
EP ;EDIT PROTECT ALL SQLI FILES
Q:$G(DUZ(0))'="@" N DMF,DMFI W !,"EDIT-PROTECTING SQLI FILES..."
S DMF=1.520
F S DMF=$O(^DD(DMF)) Q:DMF>1.52192 S DMFI=0 W DMF D
. F S DMFI=$O(^DD(DMF,DMFI)) Q:'DMFI D
. . W ?10,DMFI,?20,$G(^DD(DMF,DMFI,9))
. . S ^(9)="^" W "->^",!
W "Done" Q
EU ;EDIT UNPPROTECT ALL SQLI FILES
Q:$G(DUZ(0))'="@" N DMF,DMFI W !,"EDIT-UNPROTECTING SQLI FILES..."
S DMF=1.520
F S DMF=$O(^DD(DMF)) Q:DMF>1.52192 S DMFI=0 W DMF D
. F S DMFI=$O(^DD(DMF,DMFI)) Q:'DMFI D
. . W ?10,DMFI,?20,$G(^DD(DMF,DMFI,9))
. . S ^(9)="@" W "->@",!
W "Done" Q
DMSQS ;SFISC/JHM-BUILD STANDARD SCHEMA ;7/31/97 13:55
+1 ;;22.0;VA FileMan;;Mar 30, 1999
+2 ;Per VHA Directive 10-93-142, this routine should not be modified.
+3 QUIT
SCHEMA ;BUILD OR REPLACE SQLI SCHEMA
+1 NEW SI,TT,IEN,FDA
+2 SET SI=$ORDER(^DMSQ("S","B","SQLI",""))
+3 SET TT=1.521
SET IEN=$SELECT(SI:SI,1:"+1")_","
+4 ; SCHEMA NAME
SET FDA(TT,IEN,.01)="SQLI"
+5 ; COMMENT
SET FDA(TT,IEN,2)="FileMan SQL/ODBC interface tables"
+6 SET SI=$$PUT^DMSQU(IEN,"FDA","ERR")
+7 IF $DATA(ERR)!'SI
DO ERR^DMSQU(1.521,"","SCHEMA: RECORD INSERT FAILED")
+8 QUIT
ALLS IF $GET(DUZ(0))'["@"
QUIT
NEW TI,@$$NEW^DMSQU
DO ENV^DMSQU
SET TI=0
+1 FOR
SET TI=$ORDER(^DMSQ("T",TI))
IF 'TI
QUIT
DO STEXE
+2 QUIT
STATS(TI) ;DO NODE STATISTICS FOR TABLE TI
+1 ;NOT FOR NON-PROGRAMMERS
IF $GET(DUZ(0))'["@"
QUIT
+2 ;NO GLOBAL STRUCTURE ON FILE
IF '$DATA(^DMSQ("T",TI,0))
QUIT
+3 NEW @$$NEW^DMSQU
DO ENV^DMSQU
STEXE NEW T,MT,G,G0,CND,K,O,INI,C,MC,I,CT,TT,IEN,FDA,ERR,PI,PEI,F
+1 SET T=^DMSQ("T",TI,0)
SET MT=$PIECE(T,U,4)
SET (G0,G)=$GET(^(1))
IF G=""
QUIT
+2 SET CND=$SELECT(MT:"K(OI)]""""",1:"K(OI)")
SET INI=$SELECT(MT:"",1:0)
SET MC=5000
+3 SET (CT,O)=0
SET F="{K}"
FOR
IF G'[F
QUIT
Begin DoDot:1
+4 SET O=O+1
SET K="K("_O_")"
+5 SET G(O)=$PIECE(G,F)_K_")"
SET C(O)=0
SET G=$PIECE(G,F)_K_$PIECE(G,F,2,9)
End DoDot:1
+6 SET K(1)=INI
DO CNT(1)
+7 IF CT=MC
SET OI=1
Begin DoDot:1
+8 FOR I=2:1:O
SET C(I)=C(I)/C(1)
+9 FOR
SET K(1)=$ORDER(@G(1))
SET @("K="_CND)
IF 'K
QUIT
SET C(1)=C(1)+1
+10 FOR I=2:1:O
SET C(I)=C(I)*C(1)
IF C(I)["."
Begin DoDot:2
+11 SET C(I)=$SELECT(C(I)<10:+$JUSTIFY(C(I),"",2),C(I)<100:+$JUSTIFY(C(I),"",1),1:C(I)\1)
End DoDot:2
End DoDot:1
+12 ;REMOVE AFTER DEBUG
KILL ^STATS(TI)
MERGE ^STATS(TI)=C
+13 ;STORE T_ROW_COUNT IN SQLI_TABLE
+14 SET TT=1.5215
SET IEN=TI_","
KILL FDA
+15 ;NUMBER OF ROWS IN TABLE
SET FDA(TT,IEN,5)=C(O)
+16 SET C=$$PUT^DMSQU(IEN,"FDA","ERR")
+17 IF $DATA(ERR)!'C
DO ERR^DMSQU(TT,"","STATS: RECORD INSERT FAILED")
+18 ;STORE P_ROW_COUNT IN SQLI_PRIMARY_KEY
+19 SET TT=1.5218
SET PEI=$ORDER(^DMSQ("E","D",TI,""))
SET PI=0
+20 FOR I=1:1
SET PI=$ORDER(^DMSQ("P","B",PEI,PI))
IF 'PI
QUIT
Begin DoDot:1
+21 SET IEN=PI_","
KILL FDA
+22 ;ESTIMATED ROW COUNT FOR THIS LEVEL
SET FDA(TT,IEN,5)=C(I)
+23 SET C=$$PUT^DMSQU(IEN,"FDA","ERR")
+24 IF $DATA(ERR)!'C
DO ERR^DMSQU(TT,5,"STATS: KEY COUNT INSERT FAILED")
End DoDot:1
+25 QUIT
CNT(OI) ;ACCUMULATE NODE COUNT
+1 FOR
SET K(OI)=$ORDER(@G(OI))
Begin DoDot:1
+2 IF @CND
Begin DoDot:2
+3 SET CT=CT+1
SET C(OI)=C(OI)+1
IF CT=MC
SET OI=0
+4 IF '$TEST
IF OI<O
SET OI=OI+1
SET K(OI)=INI
End DoDot:2
+5 IF '$TEST
SET OI=OI-1
End DoDot:1
IF 'OI
QUIT
+6 QUIT
EP ;EDIT PROTECT ALL SQLI FILES
+1 IF $GET(DUZ(0))'="@"
QUIT
NEW DMF,DMFI
WRITE !,"EDIT-PROTECTING SQLI FILES..."
+2 SET DMF=1.520
+3 FOR
SET DMF=$ORDER(^DD(DMF))
IF DMF>1.52192
QUIT
SET DMFI=0
WRITE DMF
Begin DoDot:1
+4 FOR
SET DMFI=$ORDER(^DD(DMF,DMFI))
IF 'DMFI
QUIT
Begin DoDot:2
+5 WRITE ?10,DMFI,?20,$GET(^DD(DMF,DMFI,9))
+6 SET ^(9)="^"
WRITE "->^",!
End DoDot:2
End DoDot:1
+7 WRITE "Done"
QUIT
EU ;EDIT UNPPROTECT ALL SQLI FILES
+1 IF $GET(DUZ(0))'="@"
QUIT
NEW DMF,DMFI
WRITE !,"EDIT-UNPROTECTING SQLI FILES..."
+2 SET DMF=1.520
+3 FOR
SET DMF=$ORDER(^DD(DMF))
IF DMF>1.52192
QUIT
SET DMFI=0
WRITE DMF
Begin DoDot:1
+4 FOR
SET DMFI=$ORDER(^DD(DMF,DMFI))
IF 'DMFI
QUIT
Begin DoDot:2
+5 WRITE ?10,DMFI,?20,$GET(^DD(DMF,DMFI,9))
+6 SET ^(9)="@"
WRITE "->@",!
End DoDot:2
End DoDot:1
+7 WRITE "Done"
QUIT