1 | BMXADO2 ; IHS/CIHA/GIS - BMX ADO RECORDSET UTILS ;
|
---|
2 | ;;2.31;BMX;;Jul 25, 2011
|
---|
3 | ;
|
---|
4 | ;
|
---|
5 | GEN(BMXY,BMXF) ;EP - Generate an ADO Schema string from a list of fields
|
---|
6 | ;BMXY Is an out-parameter called by reference.
|
---|
7 | ;On return, BMXY will be a zero-based one-dimensional array each node of which will
|
---|
8 | ;contain the schema corresponding to the fields info in BMXF
|
---|
9 | ;
|
---|
10 | ;BMXF is an in-parameter called by reference.
|
---|
11 | ;On input, BMXF will contain the field info on which to build the schema string.
|
---|
12 | ;
|
---|
13 | ;Field info in BMXF is arranged in a zero-based one-dimensional array.
|
---|
14 | ;Node 0 of BMXF contains the KEYFIELDNAME^FILENUMBER^READONLY
|
---|
15 | ;where KEYFIELDNAME is the name of the unique key field in the database and
|
---|
16 | ;FILENUMBER is the FileMan file number and
|
---|
17 | ;READONLY denotes whether the entire recordset is updateable.
|
---|
18 | ;
|
---|
19 | ;Each subsequent node of the BMXF arrray contains field info in the form
|
---|
20 | ;1FILE#^2FIELD#^3LENGTH^4DATATYPE^5ALIAS^6READONLY^7KEYFIELD^8NULLOK
|
---|
21 | ;If FILE# AND FIELD# are defined, the LENGTH and DATATYPE will be taken from the FileMan data dictionary
|
---|
22 | ;If ALIAS is defined, the schema string will use ALIAS as the column name
|
---|
23 | ;READONLY, KEYFIELD and NULLOK are binary fields. Note that there should be only one field
|
---|
24 | ;in the recordset having KEYFIELD=TRUE
|
---|
25 | ;
|
---|
26 | ;New column info format is @@@meta@@@KEYFIELD|FILE#
|
---|
27 | ; For each field: ^1FILE#|2FIELD#|3DATATYPE|4LENGTH|5FIELDNAME|6READONLY|7KEYFIELD|8NULL ALLOWED
|
---|
28 | ;example:
|
---|
29 | ;BMXY(0)="@@@meta@@@BMXIEN|2160010^"
|
---|
30 | ;BMXY(1)="2160010|.001|I|10|BMXIEN|TRUE|TRUE|FALSE^"
|
---|
31 | ;
|
---|
32 | S BMXY(0)="@@@meta@@@"_$G(BMXF(0))
|
---|
33 | N BMXI,BMXS,BMXFM,BMXDD,BMXTYP,BMXLEN,BMXLEN2,BMXNAM,BMXKEY,BMXREAD,BMXNULL
|
---|
34 | S BMXI=0
|
---|
35 | F S BMXI=$O(BMXF(BMXI)) Q:'+BMXI D
|
---|
36 | . N BMXFM,BMXDD,BMXTYP,BMXLEN,BMXLEN2,BMXNAM,BMXKEY,BMXREAD,BMXNULL
|
---|
37 | . S (BMXDD,BMXTYP,BMXLEN,BMXLEN2,BMXNAM,BMXKEY,BMXREAD,BMXNULL)=""
|
---|
38 | . S BMXFM=0 ;Flag indicating whether BMXF(BMXI) is a FileMan field
|
---|
39 | . S BMXY(BMXI)=""
|
---|
40 | . I BMXF(BMXI) S BMXY(BMXI)=$P(BMXF(BMXI),U,1,2) S BMXFM=1
|
---|
41 | . I BMXFM D ;Look in ^DD for attributes
|
---|
42 | . . S BMXDD=$G(^DD($P(BMXF(BMXI),U),$P(BMXF(BMXI),U,2),0))
|
---|
43 | . . ;column name
|
---|
44 | . . S BMXNAM=$P(BMXDD,U)
|
---|
45 | . . S BMXNAM=$TR(BMXNAM," ","_")
|
---|
46 | . . ;Data type
|
---|
47 | . . I $P(BMXDD,U,2)["P" S BMXDD=$$PTYPE(BMXDD)
|
---|
48 | . . S BMXTYP=$P(BMXDD,U,2)
|
---|
49 | . . S BMXTYP=$S(BMXTYP["F":"T",BMXTYP["S":"T",BMXTYP["D":"D")
|
---|
50 | . . I BMXTYP["N" S BMXTYP=$S($P(BMXTYP,",",2)>0:"N",1:"I")
|
---|
51 | . . ;default columnn lengths based on type
|
---|
52 | . . I BMXTYP="N"!(BMXTYP="I") S BMXLEN=$P(BMXDD,U,2),BMXLEN=$P(BMXLEN,","),BMXLEN=$E(BMXLEN,3,$L(BMXLEN))
|
---|
53 | . . I BMXTYP="I" S BMXLEN2=$P(BMXDD,U,2),BMXLEN2=$P(BMXLEN,",",2),BMXLEN=BMXLEN+BMXLEN2+1
|
---|
54 | . . I BMXTYP="T" S BMXLEN=0
|
---|
55 | . . I BMXTYP="D" S BMXLEN=30
|
---|
56 | . . S BMXNULL="TRUE" S:$P(BMXDD,U,2)["R" BMXNULL="FALSE"
|
---|
57 | . ;Look in BMXF for user-specified attributes
|
---|
58 | . S:$P(BMXF(BMXI),U,5)]"" BMXNAM=$P(BMXF(BMXI),U,5) ;Alias
|
---|
59 | . ;Set KEY, NULL and READONLY
|
---|
60 | . S BMXNULL="TRUE",BMXREAD="TRUE",BMXKEY="FALSE"
|
---|
61 | . I $P(BMXF(BMXI),U,7)="TRUE" S BMXKEY="TRUE",BMXNULL="FALSE",BMXREAD="TRUE"
|
---|
62 | . E S:$P(BMXF(BMXI),U,8)]"" BMXNULL=$P(BMXF(BMXI),U,8) S:$P(BMXF(BMXI),U,6)]"" BMXREAD=$P(BMXF(BMXI),U,6)
|
---|
63 | . ;Set BMXY node
|
---|
64 | . S $P(BMXY(BMXI),"|",3)=BMXTYP
|
---|
65 | . S $P(BMXY(BMXI),"|",4)=BMXLEN
|
---|
66 | . S $P(BMXY(BMXI),"|",5)=BMXNAM
|
---|
67 | . S $P(BMXY(BMXI),"|",6)=BMXREAD
|
---|
68 | . S $P(BMXY(BMXI),"|",7)=BMXKEY
|
---|
69 | . S $P(BMXY(BMXI),"|",8)=BMXNULL
|
---|
70 | ;
|
---|
71 | Q
|
---|
72 | PTYPE(BMXDD) ;
|
---|
73 | ;Traverse pointer chain to retrieve data type of pointed-to field
|
---|
74 | N BMXFILE
|
---|
75 | I $P(BMXDD,U,2)'["P" Q BMXDD
|
---|
76 | S BMXFILE=$P(BMXDD,U,2)
|
---|
77 | S BMXFILE=+$P(BMXFILE,"P",2)
|
---|
78 | S BMXDD=$G(^DD(BMXFILE,".01",0))
|
---|
79 | S BMXDD=$$PTYPE(BMXDD)
|
---|
80 | Q BMXDD
|
---|