Постреляционная СУБД Cache

Объектный подход дает такие преимущества как: - естественное представление данных; - возможность разработки структур люб

195 24 1MB

Russian Pages 120 Year 2004

Report DMCA / Copyright

DOWNLOAD PDF FILE

Recommend Papers

Постреляционная СУБД Cache

  • Commentary
  • 1146074841*отл
  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Citation preview

. .,

. .

Caché (

)

2004

1

. ,

-

,

,

-

,

. :

-

; ; ; -

CASE-

-

. Versant, Jasmine, ODB-Jupiter, Caché . ,

., ,

,

. Caché

, . ,

Caché –

Web-

,

SQL

– ,

-

. Caché,

,

. Caché.

,

-

,

,

,

Cache. ,

,

-

. . .

.

.,

.

. ., InterSystems

. . .

-

. .,

. .

: . .

. .

2

1.

............................................8

1.1.

..........................................................8

1.2. 1.2.1. 1.2.2. 1.2.3. 1.2.4. 1.2.5. 1.2.6.

ODMG........................................................................9 ...............................................................................................................9 ..............................................................................................10 .....................................................................................................10 ............................................................................................11 .................................................................................................11 ...............................................................................................11

1.3. 1.3.1.

Caché ......................................................................................12 Caché..........................................................................12 2.

CACHÉ ................................................................14

3.

CACHÉ OBJECT SCRIPT ..............................................................19

3.1. 3.2. 3.2.1. 3.2.2. 3.2.3. 3.2.4. 3.2.5. 3.2.6. 3.2.7. 3.2.8. 3.2.9. 3.2.10. 3.2.11. 3.2.12. 3.2.13. 3.2.14. 3.2.15. 3. 3. 3.3.1. 3.3.2. 3.3.3. 3.3.4. 3.3.5. 3.3.6. 3.3.7. 3.3.8.

,

.........................................................................................19

.............................................................................................................................20 ............................................................................................20 Write .............................................................................................................21 Read ...............................................................................................................21 Set ..................................................................................................................22 .......................................................................................22 Do .................................................................................................................23 Kill .................................................................................................................23 Quit ................................................................................................................24 ................................................................................................................24 If ...........................................................................................................24 ..........................................................25 ......................................................................................25 $Case $Select ..........................................................................................25 For........................................................................................................26 While Do/While ................................................................................27 Caché ............................................................................................................27 ............................................................................................................27 Caché ....................................................................28 ...............................................................................28 ...................................................................................................29 ........................................................................................30 ....................................................................................................................31 ................................................................32 New ................................................................................................................32 3

3.3.8. 3.3.10. 3.3.11. 3.3.12.

...................................................................................................33 ...............................................................................................34 ..................................................................................................34 , , , , . ............................................................................................................................34

3.4. 3.4.1. 3.4.2. 3.4.3. 3.4.4.

@.................................................................................................35 ..............................................................................................................35 ....................................................................................................35 ...............................................................................................35 ......................................................................................................35

3.5. 3.5.1. 3.5.2. 3.5.3. 3.5.4. 3.5.5.

...........................................................................................................36 .........................................................................................36 ...................................................................................................36 – ? .......................................................................36 ..............................................................................37 ..................................................................................................38

3.6. 3.6.1. 3.6.2. 3.6.3. 3.6.4. 3.6.5. 3.6.6.

...........................................................................................................39 $ListBuild ......................................................................................................40 $ListLength....................................................................................................40 $List...............................................................................................................40 $ListGet .........................................................................................................40 $ListData .......................................................................................................41 $ListFind........................................................................................................41

3.7. 3.7.1. 3.7.2.

.................................................................................................................41 $ZDate ...........................................................................................................42 $ZDateH ........................................................................................................42

3.8.

5.1. 5.2. Э

..............................................................................................................................43 4.

CACHÉ...............................................................44

5.

............................................................................47 .................................................................................................47 .............................................................................................................47

5.3.

.........................................................................................................................48

5.4.

................................................................................................................48

5.5. 5.5.1. 5.5.2. 5.5.3. 5.5.4. 5.5.5. 5.5.6.

.............................................................................................................................48 ......................................................................................................49 .......................................................................................................49 ...........................................................................................................49 ................................................................................................................50 ...............................................................................................50 ....................................................................................................................51 4

5.5.7. 5.5.8. 5.5.9. 5.5.10. 5.5.11. 5.5.12.

......................52 ......................................................................................53 ....................................................................................................53 ...................................................................................................53 ...........................................................................................................54 .............................................................................................55

5.6. 5.6.1. 5.6.2. 5.6.3. 5.6.4. 5.6.5. 5.6.6. 5.6.7. 5.6.8. 5.6.9. 5.6.10.

................................................................................................................................55 .......................................................................................................55 ..............................56 .................................................................................56 .................................................................................56 .....................................................................................................57 ..................................................................................................................57 ..............................................................................................57 ....................................................................................58 ................................................................................................................58 .............................................................................................................59

5.7.

...................................................................60

5.8.

...............................................................................................................................61

5.9.

..............................................................................................................................61

5.10. 5.10.1. 5.10.2. 5.10.3. 5.10.4. 5.10.5. 5.10.6.

..............................................................................................................................61 ..................................................................................................................62 .................................................................................................62 .............................................................................................62 #IMPORT .................................................................................................63 SQL .............................................................................................................63 ....................................................................................................63

6.

........................................................................64

6.1.

................................................................................................64

6.2.

.......................................................................................64

6.3.

..........................................................................................................64

6.4.

............................................................................................64

6.5. 6.5.1. 6.5.2.

...........................................65 ............................................................65 , , ............................................................................................................66

6.6. 6.6.1. 6.6.2.

...................................66 .........................................66 .....66

6.7.

-

....................................................................................67 5

6.7.1. 6.7.2. 6.7.3. 6.7.4.

...............................................................................67 ................................................................67 ...................................................................68 .....................................................................69

6.8. 6.8.1. 6.8.2. 6.8.3. 6.8.4.

-

6.9.

..................................................................................69 .............................................................................69 ................................................................69 ...................................................................70 ...................................................................70 ..................................................................70

6.10.

...........................................................................................................71

6.11.

.....................................................................................................72

6.12. 6.12.1. 6.12.2.

..........................................................................................................72 ...........................................................................................72 .............................................................................73

6.13. 6.13.1. 6.13.2. 6.13.3. 6.13.4. 6.13.5.

.....................................................................................................73 .........................................................................................................73 .......................................................................74 ................................................................................................74 ...............................................................................74 .......................................................................................................75

6.14. 1. 2. 3. 4. 5. 6. 7. 8. 7.

......................................................................................75 ...........................................................................75 .........................................................................77 ......................................................................77 ..............................................................................79 ......................................................................................79 ..80 , ...................81 .......81 .............................................................83

7.1.

......................................................................................83

7.2.

.............................................................................83

7.3.

...............................................................83

7.4.

..............................................................................................................................84

7.5.

...........................................................................................................85

7.6. 7.6.1. 7.6.2.

...................................................85 $Data..............................................................................................................85 $Get ...............................................................................................................87 6

7.6.3. 7.6.4. 7.6.5. 7.6.6.

$Order............................................................................................................87 $Query ...........................................................................................................89 $QLength, $QSubscript.................................................................................90 Merge .............................................................................................................90

7.7. 7.7.1. 7.7.2. 7.7.3. 7.7.4.

...............................90 IDKEY.........................................................................................................91 .....................................................................................................................92 ........................................................................................................................93 ............................................................93 8.

CSP .................................................................95

8.1. 8.2. 8.3.

Caché .............................................................................................................95 ,

Caché..............................................................................95 ,

#server(…)# ...............................96

8.4. CSP .............................................................................................................................99 8.4.1. .........................................................................................................99 8.4.2. ........................................................................................................101 8.4.3. .......................................................................................................102 8.4.4. .........................................................................................................103 8.4.5. ...............................................................................................................103 8.4.6. .....................................................................................................104 8.4.7. JavaScriptHTML Caché Object Script (COS) 105 8.5.

.

%CSP.Request ..........................................................105

8.6.

%session ..............................................................................................................110

8.7.

............................112

8.8. .....................................................................................................................................117 ..........................................................................................120

7

1. 1.1. ,

,

,

.

. :

-

; ; ; . -

,

:

1.

, . . ,

,

,

. ,

-

,

, . . , . . .

2. ,

,

,

,

. .

, 3. .

,

,

. .

-

-

SQL

(join)

,

-

,

, . . .

, ,

. , «

. -

»,

. •

(

) :

,

• • •

,

; ; ; . ,

-

, ,

. , ,

Caché

SQL. InterSystems (www.intersystems.ru).

Caché

, 8

-

,

-

, . , ,

, -

, ,

.

1.2.

ODMG -

(

)

« », Group), .

,

. ODMG (Object Data Management -

,

. ODMG.

1.2.1. ODMG 2.0 .



.

-

,



. .

,

( (

). )

.



.



,

-

. . .



, .

, ,

-

,

. .

,

-



.

, . .

,

, ,

. .1

. .

9

1. 1.2.2. ,

. .

— identificator)

,

(OID — object -

, . .

. Versant

OID , yyyyyyyy —

xxxxxxxx:yyyyyyyy,

, xxxxxxxx —

.

OID ,

Jasmine

OID classnamexxxxxxxx, . .

classname —

. Caché,

,

. xxxxxxxx —

, ,

, .



-

: ,

. ,

:

,

,

OID,

,

.

,

— ,

.

1.2.3. . . -

:

,

,

-

. , ),

(

,

-

, . .

, . .

,

. ,

, , .2 «

(Adult)

«

» (MalePerson), «

,

. « » (Person), » (FemalePerson), « »

» (Child). 10

. MalePerson, FemalePerson, Adult MaleAdult, , ,

. Person. MalePerson Adult,

Child ,

,

-

.

2. 1.2.4. -

,

, «

»

-

, ,

,

. , ,

,

,

.

1.2.5. . , Language),

OQL (Object Query

SQL ,

ODMG.

, XML.

(

SQL. ) — XML QL ( ,

1998

.

XQL). -

. 1.2.6. ,

, .

, :

(

), •

. ,

, ,

-

;

• •

, -

; , ,

,

-

. . 11

1.3.

Caché Caché

1997

,

,

-

InterSystems. Caché 5.0. 1978 IDC, InterSystems

.



. Chase Manhattan, Lloyd Bank, -

, , .

InterSystems .



Caché

: , ,

,



.

Caché. , -



,

-

,

.

.

Caché (



,

«

. -

), »

. -

, . ,



. .



,

Caché

.

-

. SQL. ,

-

Caché SQL •

Caché. CSP

1.3.1.

Web-

Caché Caché: ,



,

.

-

. .

, Caché

,

,



.

,

. Caché Objects. ,

, .

.

12

2.

Caché Caché • • • • • •

: Studio Terminal

SQLCaché.

, « • • • • • •

,

-

» :

CSPCaché Caché.

«

» Caché

.4

Cache.dat. C:\CacheSys\MGR\User. « » . «

. Caché «

-

…» 1

.

».

14

4.

«

».

.5

.

5. (namespace), , «

».

User. ,

Caché Studio Web:

.

-

-

15



, CSP-

• •

• • •

Caché Object Script(COS)

, ;

, : Caché Object Script, Basic, Java, SQL, JavaScript, HTML,

XML; ,

; ; ; , WEB-

,

,

,

. Caché :

. ,

, CSP-

,

-

.

.

-

. Caché Studio

6.

. 6.

Caché Studio. ,

Caché Terminal ,

, . ENTER. . 7.

,

. .

-

.

16

7.

Caché Terminal Caché

Caché ,

. /

Caché ,

,

Caché.

Caché,

. 8.

8.

Caché

.

17

-

SQL,

. . 9.

9.

SQL-

.

18

3.

Caché Object Script

Caché (COS). COS — (ANSI MUMPS). . Script: • •

.

Caché Object Script M . CachéObject

: set set=12,

-

, COS ,

Caché

Caché-

: ,

.

,



set –

. .



-

.

• • • • • •

, : $Piece, $Select

.

$ . . .

: write, read

. .

. . . /

3.1.

. SQL.

, ObjectScript

,

,

.

, ,

, .

– ,

( . String, string,

)

STRING

,

. :

. ,

– . .

( (Direct Access), . «^».

, , ,

1.

) -

.

,

31

-

7-

-

. 2. 3.



«%». ASCII.

4.

. : Read, Set,

For.

Kill : Set Article=”

.

” 19

Read “ ”, number Kill Article, number :

Caché . String.



. .



,

,

. ,



. $.

-

— $Horolog, . -

– . “^$”.

.

,

^$Job

(

$S[torage]

,

-

.

.1). 1

> write $S > 16694336

$ZN[ame]

>write $ZN >

$ZV[ersion] $J[OB]

Caché , , . ,

$ZPI

3.2. 3.2.1. :




. -

.

.

• • • •

: 2

.

. , –

.

,

. .

,

-

. (

Caché

Terminal): 20

USER> SET··nextvar=" " ·, USER> SET·nextvar=" " USER> KILL··SET·nextvar=5··WRITE USER> KILL·SET·nextvar=5 3.2.2.

:

Write Write : Write
:

,

,

,

.

. Write .

: !– #– ?n –

; ; n

.

: SAMPLES>write " SAMPLES>write !, "

", !, "

SAMPLES>write !, "

", ?10, "

!!!” ", !, "

", !

", ?50, "

", !

SAMPLES> write a 1 SAMPLES>write 7.95 * 1.15 9.1425 3.2.3.

Read -

. Read
:

,

,

,

.

. : !– #– ?n – *( :(
#


,

. write .

.

-

:

SAMPLES>read x SAMPLES>write "

: ", x 21

: READ

,

-

write. :

(

.)

.

Enter,

. , SAMPLES>read !, " 5

: ", z#5 .

SAMPLES>read ?30, " : SAMPLES>read !, " 5 SAMPLES> 3.2.4.

:

5 : abcde : : ", n 5

: ", x:5

:

Set Set

Set Set Set Set >

< (< < (
, < 2>, < >=< >,
= < 1>, < >.< 1>.
= < 2> 3>, …) = < > 2>.
>,
.
) =
set x = 4 + 2 SAMPLES>write x 6

, ,

, . Set sum=sum+(num#10)+(num\10) .

3.2.6.

, 2 : Set sum=sum+num#10+num\10.

Do ObjectScript

, Do. P1: Do ^P1, P2 , . . ,

%,

,

-

: P1 –

, P1: Do P2^P1,

. ^ -

.

: Do ^sum. a b: Do ^sum(a, b). Do sum. ,

, – %SQROOT. ^(^–

Do, ).

,

-

,

.

,

.

(

-

.

:

SAMPLES>Do ^%SQROOT Square root of: 100 is: 10 Square root of: , ),

, . (^).

-

:

Set %X = 523 Do INT^%SQROOT Write %Y %X, INT

%SQROOT.

523 3.2.7.

Kill Kill

, .

Kill < > Kill Write . : SAMPLES>set a = 1, b = 2, c = 3, d = 4, e = 5 SAMPLES>write a=1

-

INT %Y.

: -

23

b=2 c=3 d=4 e=5 SAMPLES>kill c SAMPLES>write a=1 b=2 d=4 e=5 3.2.8.

Quit . . 2

Quit

,

-

. . Caché Studio .

, undefined variable

, .

, Caché Terminal. SAMPLES>

,

:

: SAMPLES 2d0>. Q( Quit) . FINED> : SAMPLES>do ^badroutine start+3^badroutine Quit, SAMPLES 2d0>Quit SAMPLES>

, ^badroutine

[,< 2>,...,< 3>] , . code , . . , 1: Set x=0,y=-1,a=0 if xupto) set t1=1, t2=1, fib=1 write ! while (fib'>upto) { write fib," " set fib=t1+t2, t1=t2 ,t2= fib } Caché Terminal: SAMPLES>do ^fibonacci : 100 1 2 3 5 8 13 21 34 55 89 1 2 3 5 8 13 21 34 55 89

3. 3.

Caché

3.3.1. Caché 1.

3 MAC) SQL, (OBJ). (

( , ,

2.

: ObjectScript,

INT)

ObjectScript. .

SQL 3.

( MACInclude –

,

HTML.

INC)

,

-

. –

-

. 4.

(.OBJ) –

,

. . .

. RTN,

. . 27

Caché Studio. Caché Terminal. +

,

.

:

SAMPLES>do ^badroutine start+3^badroutine SAMPLES 2do>quit SAMPLES> ,

,

,

. .

end quit

-

:

;

3.3.2.

Caché Caché . –

,

-

,

.

MAC, ASCII,

-

,

. (

), - (

), ; (

).

,

,

: _ -

),

-

. : Do ^RoutineName ( ,

.

– ,

, ),

%(

,

.

-

. [

] [

] [

] , ,

-

, . 3.3.3. , ,

,

,

Quit.

. : Label ([param [= default]]) // // Quit // , , Label – , param – .

-

Quit , default – ,

-

. Do Label[(param)] C

: Do Label^Routine[(param)] 28

Routine – , Routine, param –

Routine.Mac, Label – .

1. , set x=1,y=2 do minim(x,y) // write !,"x=",x," y=",y quit minim(a=0,b=0) // if (a>b) { set mn=b } else { set mn=a} write !,"min=",mn quit

routine.Mac

minim

:

:

do minim(x,y) minim do minim^routine(9,2)

: ,

: do minim^routine() (^)

,

Do minim(x,y),

,

. N-

: + : Do minim+3^routine –

.

,

.

.

3.3.4. Caché

(

)

,

. . .

, , . .

Caché

. : $Function(Arg1, Arg2, …).

-

$.

.

.3

. 3

-

$Ascii, $CASE, $Char, $Random, $Select, $Stack, $Text, $View $Data, $Get, $Order, $Name, $Query, $QSubscript, $QLength $Extract, $Find, $Length, $Piece, $Reverse, $Translate $FNumber, $Justify, $Inumber, $NUMBER $List, $ListBuild, $ListData, $ListFind, $ListGet, 29

,

$ListLength $Increment $ZABS, $ZEXP, $ZLN, $ZSIN $ZDate, $ZDateTime, $ZDateH, ZTime, ZtimeH $ZWAscii, $ZWChar, $ZF,$ZHex, $ZLAscii, $ZLChar, $ZSEArch, $ZSEEK $ZCONVert, $ZCyc, $ZSTRIP $ZBitAND, $ZbitCount, $Zboolean

Caché. 3.3.5. ,

-

. ,

,

.

,

.

: (
. .

.

: Set < Do
=$$< >(

>(

) )

Do

. . Do,

,

: Do
^
(

)

: Set
=$$
^
(

)

1. , FRnd.Mac: set a=200,b=100 set r=$$Rnd(a,b) // write !,"r=",r Quit Rnd(m,n) // Quit $Random(m-n)+1+m : set r=$$Rnd^FRnd(200,100) 2. func1.Mac set x=6,y=2 set mn=$$minim(x,y) // write !,"x=",x," y=",y,”min=”,mn

minim:

30

quit minim(a,b) // write "minim" if (a>b) { quit b } else { quit a} quit : Set m=$$minim^func1(9,2) 3.3.6. ObjectScript, ,

, ,

.

{}.

: <
(

)[
{
]

> [Quit
]

} –

,

,

-

. –

.

,

,

.

-

public-



. public. Private ( , public –

: private

,

)–

. : (
)[=
] :

Do Proc(
) :

Do Proc^Routine(< Proc – , Routine – 1: proc2.Mac set c=1,d=3 do MyProc(1,2) // quit MyProc(X,Y)[A,B] Public { write "X+Y=", X+Y, ! set A=1,B=4 write "A+B=", A+B, ! }

>)

// . :

: 31

Do MyProc(1,2) : Do MyProc^proc2(1,2) 2.

proc2.Mac,

MyProc x, y

MyProc. abc,

-

a, b: set c=1,d=3 do MyProc(1,2) // MyProc MyProc(X,Y)[A,B] Public { write "X+Y=", X+Y, ! set A=1,B=4 do abc(X,Y) // write "A=", A, " B= ", B, ! }

abc

// abc, abc(n,m)[A,B] { set n=9,m=5 write "a=",A,"b=",B }

MyProc

MyProc

3.3.7. , ,

-

,

,

. 1 .3.3.3.

x

y,

routine.Mac,

minim,

-

,

.

. .

Caché 1.

«

»

Kill

: ,

-

Quit

.

2.

New ,

3. 4.

. .

public

private

, .

3.3.8.

New New

, .

.

: New [(

)]

New –

P1

, : New a,b // : //

a

.

b

32

New a Set a=1 Do P2 Write Quit P2 // New x, y Set x=a, y=3 Quit a x

P1

y .

P2, . . P2

P1.

-

. ,

,

P2. New

. (private) ,

New New

public-

, public-

New,

Quit .

,

public-

,

.

, abc set name="Tom" do MyProc(9,4) write !,"abc name= ", name

abc.Mac:

MyProc(x,y)[name]{ New name Set name="John" write !,"MyProc name = ",name Do xyz() Quit } xyz()[name] { write !,"xyz name = ",name }

“John”

“xyz” name, . . name – publicname ( ) public“MyProc”. ^abc MyProc name = John xyz name = John abc name= Tom

“abc” . “name”

New

“Tom”,

:

3.3.8. • • •



:

. :

33



.

3.3.10. New.

-

Kill. . . :

. Set a=1, b=2, c=3 Do p1(a,b,c) // write … P1(r,s,t) // Set summ = r+s+t Quit

-

. ,

,

.

3.3.11. –

-

. , Kill var // var Do P1(.var) // … P1(x) // Set x=0, x(1)=1, x(2), x(3)=3 … Quit

,

.

:

x

P1 var, var(1), var(2), var(3). : Do ^Summ(a, b, c, .var) 3.3.12.

,

,

,

,

.

,

• • • • •

• • •



. private

: public. . . . .

: public public; ,

. ;

,

. ,

. ,

Caché ObjectScript ,

, . 34

: ObjectScript .

3.4.

@

• • • •

: :

(

,

).

:

. :

.

:

.

3.4.1. . : Set pname=”Prog1” do @pname // Set var=”locvar” Set @var=4 //

Prog1 locvar

4

3.4.2. ,

for,

-

. : Set isetarg=”x=1”, @isetarg // set x=1 Set ikill=”(e,f,g)” Kill @ikill Set inew=”(a,b,c)” New @inew 3.4.3. . –

-

. , (

):

: Set x(2, 5,3)=“IndInd” Set feld=”x(2,5)”, d1=3 Write @feld@(d1) : IndInd x(2,5)

3.

3.4.4. . Set lvmuster=”1.3N” If eingabe ‘?@lvmuster Do error

:

35

3.5. Caché

,

. COS

,

-

. ,

. ,

.

-

. SAMPLES>set x = 4 write x + 2 6 SAMPLES>set x = "5" write x * 2 10 SAMPLES>set x = "fred" write x + 3 3 SAMPLES>set x = "32hut" write x / 4 8 SAMPLES>write +x 32 SAMPLES>write 5 + 2, ?10, "5" + "2" , ?20, "5 + 2" 7 7 5+2 SAMPLES> 3.5.1. ).

^( kill,

, .

-

:

SAMPLES>set x = 4 SAMPLES>set ^x = " SAMPLES>kill SAMPLES>write SAMPLES>write ^x

"

: SAMPLES > kill ^x. 3.5.2. : (_)– (?) – ject Script.

, ,

3.5.3.

Cache Ob– ?

?– .
?
,

< о - о>[< о - о>] < - > . .4

1 (true), , ,
– ,

, .5

-

. 36

4 3(

) 1

1.3

3 3

.3 3

3.

,

.

0 5

(

A

C

)

U

E

L

ANP

N

"abd"

P : 1. 348?3N – 2.

, . .



3

date

. .

.

.

: if date?2N1P2N1P4N write “ 3. 4. 1U.AP –

”. : 2N1”.”2N1”.”4N.



,

. 3.5.4. : $Length(< , $Extract(
,[< >,
]) – . 3>) –

2>,
,
,
,
) – ,

>,
,
) –

-

,

, .

, $Justify(< ,



. >,
,
) – ,

. ,

.

Caché.

. 37

SAMPLES>write $length(" 18 SAMPLES>write $extract(" ; 8 SAMPLES>write $find(" 11 SAMPLES>write $piece("

?") ", 8, 12) 12 ", "

") ", " ", 2)

SAMPLES>write $justify(3.1415, 10, 3) 3.142 $Piece , , ,

. .

.

“-“ – . $Piece .

: «22-55-77», ,

,

, :

$Piece(< >, < : SAMPLES>write $piece("

>[, ]) ", " ")

: SAMPLES>write $piece("

", " ", 1)

SAMPLES>set street=$piece(" SAMPLES>write street

^

^35^630058", "^", 2)



: SAMPLES>write $piece(" ^35 , $Length

^

: ,

SAMPLES>write $length(" 4

^35^630058", "^",2,3)

^

. ^35^630058", "^")

3.5.5. $Extract Set.

$Piece

-

$Extract

,

. SAMPLES>set empty="" SAMPLES>set $extract(empty, 4) = "abcde" ; "abcde" SAMPLES>write empty . . . abcde SAMPLES>set $extract(empty, 4, 5) = "12345" ; "12345" SAMPLES>write empty . . .12345cde $Piece .

3

, . . 4-

4

5-

Set . 38

SAMPLES>set empty="" SAMPLES>set $piece(empty, "^", 3) = "abcde" write empty ^^abcde SAMPLES>write $length(empty, "^") 3 SAMPLES>set $piece(empty, "^", 2) = "9/9/1999" write empty ^9/9/1999^abcde SAMPLES>write $piece($piece(empty, "^", 2), "/", 3) 1999 SAMPLES>

3.6. Object Script . , , , 3-

. L1={ , L2={

. : } . .

,

,

,

,

L3={

,

} ,,

L4={

,

, “ ”,

: L1. }

4

,

-

. }

4

,

3-

. , L5={ Caché

,

,{

-

: ,

-

,

-

},

}.

. ,

• • • • •

,

.

-

: . . . . . .

USER> Set L2=$ListBuild(“ .6

”,”

,

$ListBuild: ”,” ”) . 6

$ListBuild $ListLength $List $ListGet

$LB $LL $LI $LG

$ListData

$LD

$ListFind

$LF

, . ,

$Get -

39

3.6.1.

$ListBuild .

:

$LISTBUILD(element,...) $LB(element,...)

element – .

,

.

,

X:

SET X=$LISTBUILD("Red","Blue","Green")

3.6.2.

$ListLength .

:

$LISTLENGTH(list) $LL(list)

list

.

:

WRITE $LISTLENGTH($LISTBUILD("Red","Blue","Green")); WRITE $LISTLENGTH("") ; 0

3.6.3.

3

$List .

:

$LIST(list,position,end) $LI(list,position,end)

list

, Position –

, End –

. • • •

: $LIST(list) $LIST(list,position) $LIST(list,position,end) , position :

. . , end.

-

WRITE $LIST($LISTBUILD("RED","BLUE","GREEN")) ; WRITE $LIST($LISTBUILD("RED","BLUE","GREEN"),1) ; SET X=$LISTBUILD("Red","Blue","Green") WRITE $LIST(X,2) ; Blue

RED RED

SET X=$LISTBUILD("Green ","White ","Brown ","Black ") SET LIST2=$LIST(X,3,-1) WRITE LIST2 ; BrownBlack

$List

Set

,

. $List

.

.

:

>Set L1=$LISTBUILD("RED","BLUE","GREEN") >Set $List(L1,2)= "hhhh" ; hhhh >Write $List(L1,2) hhhh > Set $List(L1,4)= "abcd" ; 4-

3.6.4.

$ListGet , .

: $LISTGET(list,position,default) $LG(list,position,default)

list 40

Position – Default –

,

.

: SET LIST=$LISTBUILD("A","B","C") WRITE $LISTGET(LIST) ; WRITE $LISTGET(LIST,1) ; SET LIST=$LISTBUILD("A","B","C") WRITE $LISTGET(LIST,4) ; WRITE $LISTGET(LIST,4,"ERR");

3.6.5.

A A , . . 4"ERR"

$ListData ,

.

:

$LISTDATA(list,position) $LD(list,position)

list – Position –

. 1 (true) –

, 0 (false) – .

-

:

KILL Y SET X=$LISTBUILD("Red",,Y,"","Green") WRITE $LISTDATA(X,2) ; 0 WRITE $LISTDATA(X,3) ;

я



0 WRITE $LISTDATA("")

я

;

0 WRITE $LISTDATA(X,0) ; 0 WRITE $LISTDATA(X,6) ; 6- я

0

3.6.6.

я

5-

$ListFind .

:

$LISTFIND(list,value,startafter) $LF(list,value,startafter)

list – Startafter –

, value -

. ,

.

.

,

. ,

.

-

,

(0),

-

:

SET X=$LISTBUILD("A","B","C","D") WRITE $LISTFIND(X,"B") 2 SET X=$LISTBUILD("A","B","C","D") WRITE $LISTFIND(X,"B",2) 0

3.7. ObjectScript

– ,

0

. 12/31/1840

2980013

-

41

12/31/9999. 15/12/2003.

,

:

$Horolog.

, ,

. $Horolog , . USER> write $Horolog 59469,47554 3.7.1.

1 2 ,2 , 13 9

$ZDate $ZDate 9 – . – 4–

:

. .

: ,

,

,

-

. , 10 –

:1– 0–

,

-

. . –

.

: « ».



. –1 (

–1,

1).

: SAMPLES> write !,$Zdate($Horolog, 2, " ") 27 2003 SAMPLES>write $zdate($horolog) 11/24/2003 SAMPLES>write $zdate($horolog, 2) 24 Nov 2003 SAMPLES>write $zdate($horolog, 10) 1 ; USER>write $zdate(11111111111111111111, 1,,,,,,, -1) -1 3.7.2.

-

$ZDateH $ZDateH

. ,

, ,

-

. $ZDate. , $ZDateH

, . T

( ) SAMPLES >write $ZDateH("24/11/2003", 4) 59497 SAMPLES >w $ZDateH("21/05/2002", 4) 58945 SAMPLES>write $ ZDateH ("21/9/1999", 5,,,,,,, -1) -1 SAMPLES>write $ ZDateH ("21 SEP", 5,,,,,,, -1)

,

.

42

59433 SAMPLES>write $ ZDateH ("SEP 21 1998", 5,,,,,,, -1) 57607 SAMPLES>write $ ZDateH ("T+12", 5,,,,,,, -1) 59509 SAMPLES>write $ ZDateH ("MAT 3", 5,,,,,,, -1) -1

3.8. Caché .

. Caché

.

,

,

-

. . , MyVar Set MyVar=7 Set MyVar(22)=-1 Set MyVar(-3)=89 Set MyVar(“MyString”)=”gg” Set MyVar(-123409, “MyString”)=”k” Set MyVar(“MyString”, 2398)=23 Set MyVar(1.2, 3, 4, “Five”, “Six”, 7)

:

, ,

, MyVar(22)

,

. ,

, MyVar(10). . .

.

,

, . .

, ,

:

, -

.

43

4.

Caché

Caché Data Management Group).

ODMG (Object –

,

.

Caché

-

, . .

.

, (

). Caché : ).

. Caché • •

( (

-

. 10.

). (

.

)

-

, ,

. -

.

.

• •

: . .

(%String, %Integer, %Float, %Date – .

Caché .). Caché

-

. -

-

-

10.

Caché

. : . : reference),

OREF (object ,

. OID

– OID (object ID). , .

OID . OREF –

, -

OREF. 44

, .

(OID) Caché,

,

(OREF).

-

: -

. ,

.

. ,

,

-

. ,

, %New()

,

, %Close() –

. %RegisteredObject. ,

.

-

, . Caché.

-

, . (

. )

%SerialObject

.

-

, , ,

.

. -

: -

. – OREF.

-

, .

OID, . %Persistent. , : . . – OID OREF. ,

%Persistent ,

, 2

OID

,

, OREF .

Caché : .

Caché

-

. .

Caché

.

Caché

. .

. . , . .

,

. 45

.

• •

Caché

Caché; ; Caché SQL Gateway. Caché : . UDL (unified definition language), markup language). run-time . .

:

, ,

XML (extensible

46

5. 5.1. .

-

.7: 7

(

)[

]

: 48

Property Total As %Float (SCALE = 2); Property Description As %Library.String (MAXLEN = 300); Property PlayingNow As %Library.Boolean [ InitialExpression = 1 ]; Property Rating As %Library.String (VALUELIST = ",G,PG,PG-13,R"); Property Pr As %String [ Required ]; Property SALARY As %Integer (MINVAL = "0", MAXVAL = "1000000"); Property SecretName As %String (MAXLEN = "20") [ Private, Required ]; : Relationship Chapter As Chapter [Inverse = Book, Cardinality = Many]; •

Caché

: ,



,

,

(CLOB’ ),

. -



. ,



, .

,

,

,

-

(private).

. -

( ).

5.5.1. (public) , . . «

».

5.5.2. , . •

-

:



– Get(), Set(),

,



.

– ,

,

-

. ,

,

.

, . ,

. ,

,

-

. 5.5.3. , .

, .

: ,

Calculated –

.

-

. Description – .

,

Caché

-

.

49

Final –

,

. .

,

.

InitialExpression –

. .

. private.

Private –

,

private.

. .

Required – required.

-

. Transient –

,

. -

transient. . Type – ,

,

, .

-

(%String).

. 5.5.4. • • • • • •

:

5.5.5. .

,

,

.

Property Count As %Integer; Count , %Integer –

,

. ,

• • •



:

Property Count As %Integer(MAXVAL = 100); , : ; ; .





:

: ,

(

-

) SQL, ODBC, ActiveX

( . Java,

),

. ,

Caché

. 8. 8 50

SQLBINARY, BINARY RAW, VBINARY

%Binary %Boolean

(0-

, 1-

VARYING,

) MONEY, SMALLMONEY

%Currency (

%Date

DATE

)

%Float

DOUBLE, DOUBLE FLOAT, REAL

PRECISION,

%Integer

BIT, INT, INTEGER, SMALLINT, TINYINT $List,

%List Caché %Name

“ .

-

” -

%Numeric

DEC, DECIMAL, NUMBER, NUMERIC

%Status CHAR, CHAR VARYING, CHARACTER, CHARACTER VARYING, NATIONAL CHAR, NATIONAL CHAR VARYING, NATIONAL CHARACTER, NATIONAL CHARACTER VARYING, NATIONAL VARCHAR, NCHAR, NVARCHAR, VARCHAR, VARCHAR2

%String

TIME

%Time %TimeStamp

,

-

TIMESTAMP

5.5.6. , . MAXLEN — MAXVAL — MINLEN —. MINVAL —

: ,

;

; ,

;

; 51

FORMAT —

. .

$FNUMBER, SCALE — PATTERN — PATTERN TRUNCATE — , ODBCDELIMITER — ODBC. VALUELIST – DISPLAYLIST –

. ,

.

-

Caché. 1, MAXLEN ( -

),

0, %List,

. -

.

,

-

, VALUELIST. .9

,

. 9

MAXLEN, MINLEN

%Binary %Boolean %Currency

DISPLAYLIST, FORMAT, MAXVAL, MINVAL, VALUELIST

%Date

DISPLAYLIST, FORMAT, MAXVAL, MINVAL, VALUELIST

%Float

DISPLAYLIST, FORMAT, MAXVAL, MINVAL, SCALE, VALUELIST, XSDTYPE

%Integer

DISPLAYLIST, FORMAT, MAXVAL, MINVAL, VALUELIST, XSDTYPE

%List

ODBCDELIMITER

%Name

COLLATION, INDEXSUBSCRIPTS, MAXLEN, XSDTYPE

%Numeric

DISPLAYLIST, FORMAT, MAXVAL, MINVAL, SCALE, VALUELIST

%Status %String

COLLATION, DISPLAYLIST, MAXLEN, MINLEN, PATTERN, TRUNCATE, VALUELIST, XSDTYPE

%Time

DISPLAYLIST, FORMAT, MAXVAL, MINVAL, VALUELIST

%TimeStamp

DISPLAYLIST, MAXVAL, MINVAL, VALUELIST

5.5.7. , Caché

.

. 10

. 52

10 Display Logical

-

Storage ODBC

ODBC

SQL

, : 11 DisplayToLogical() LogicalToDisplay () LogicalToODBC()

ODBC (

)

(

)

ODBCToLogical()

ODBC

LogicaToStorage() (

)

(

)

StorageToLogical() . Person %Library.Date. Person Caché DateOfBirthDisplayToLogical(), DateOfBirthLogicalToDisplay() .

DateOfBirth . .

5.5.8. Caché

.

-

, . .

, Doctor: Property Doc As Doctor;

Doc,

5.5.9. .

-

, ,

.

, , ,

,

– ,

,

. . Property Adr As Address; Adr , Address –

.

5.5.10. . Caché :

(List)

(Array).

53

, . . .

:< .

,

>
,

:

2.04.1999 10.05.2001 20.11.2002 ,

.

,

Colors

%String: Property Colors As %String [collection = list]; , Caché Doctors Property Doctors As Doctor [collection = array];

,

,

, Doctor:

5.5.11.

(Binary Large Objects)

. Caché SQL CLOBs (Character Large Objects) ,

CLOBs

, .

, , Caché

. BLOBs , ,

, BLOBs -

.

-

, . CHARACTERSTREAM ( ) BINARYSTREAM( ). %STREAM. : Class MyApp.JournalEntry Extends %Persistent [ClassType = persistent] { Property ItemDate As %Date; Property PictureOfTheDay As %Stream [ Collection = binarystream ]; Property EventsOfTheDay As %Stream [ Collection = characterstream ]; } MyApp.JournalEntry : PictureOfTheDay – , EventsOfTheDay – . , , Caché . STORAGE GLOBAL, FILE. LOCATION , , . , . : Property GMemo As %Stream (STORAGE="GLOBAL", LOCATION="^MyStream") [collection = binarystream]; Property FMemo As %Stream (STORAGE="FILE", LOCATION="C:\Stream") [collection = binarystream]; GMemo ^MyStream, FMemo C:\Stream.

54

GLOBAL

-

^PackageClassS. .

5.5.12. . , der.

$Or-

, abc Property abc [ MultiDimensional ];

: abc:

Set x = $DATA(obj.abc) Set x = $DATA(obj.abc(3)) Set x = $GET(obj.abc(3)) Set x = $ORDER(obj.abc("hello",3)) KILL obj.abc obj – oref. , . , KidsGet, KidsSet, SQL .

-

Kids KidsLogicalToDisplay.

5.6. – Caché

,

.

.

,

,

-

. . , Caché Object Script (COS). . %Library.Status,

, ,

,

, .

. ClassMethod, Method. , ClassMethod < { }

: >(

)[

]

: Method < { }

>(

)[

]

5.6.1. .

-

. , ).

, ,

( Calculate

:

Method Calculate(count As %Integer, name, state As %String = "CA") { // ... }

55

count

state

%String.

%Integer

%String, %String, .

. .

.

, name

5.6.2. : Method Test(flag As %Integer = 0) { }

,

.

5.6.3. ,

.

,

ByRef.

:

Method Swap(ByRef x As %Integer, ByRef y As %Integer) { Set temp = x Set x = y Set y = temp }

, ,

, ByRef,

Output.

,

-

. Method CreateObject(Output newobj As MyApp.MyClass) As %Status { Set newobj = ##class(MyApp.MyClass).%New() Quit $$$OK }

Caché Object Script (ByRef Output),

, :

Do obj.Swap(.arg1, .arg2)

5.6.4. , .

,

, ,

-

.

,

( ,

).

(OREF)

.

:

Method MethodName() As ReturnType { }

MethodName ,

, ReturnType

, %Integer:

.

Method Add(x As %Integer, y As %Integer) As %Integer { Quit x + y }

,

:

Method FindPerson(id As %String) As Person { Set person = ##class(Person).%OpenId(id) Quit person }

56

5.6.5. public

private. Private. Public-

, .

Caché private.

»

«

(protected). 5.6.6. ObjectScript), “Basic”, Language.

“Java”. .

: “Caché” (Caché ,

, ,

: Class MyApp.Test { /// Basic Method TestB() As %Integer [ Language = basic] { ' Basic Print "Э " Return 1 } /// Cache ObjectScript Method TestC() As %Integer [ Language = cache] { // Cache ObjectScript Write "Э " Quit 1 } }

. , , Caché-

Caché ObjectScript Basic, . Caché Java Binding), Java, Java)

. Java( Java- . Java

JVM (

-

. Java-

-

Java-

.

5.6.7. .

, ,

.

: ClassMethod –

.

,

. ClassMethod. Description –

, .

,

.

-

. Final –

, ,

. Private –

.

. -

, (

).

, . . Final

private,

-

private57

.

public. (

,

-

«protected» “private” , ReturnType –

). .

(“ ” ), ReturnType , SQLProc –

,

ReturnType

-

. . . SQL.

-

. 5.6.8. ,

. ##this.

:

set sc= ##this.%Save() ##this, %Save –

-

. . ,

##this

.

-

. :

.

%New() – %OpenId() – %DeleteId() –

. .

5.6.9. .

, : Do oref.MethodName(arglist) Set value = oref.MethodName(arglist)

oref MethodName , .

,

,

, arglist , ,

Admit

Patient

: Do pat.Admit()

pat

OREF Patient. , SearchMedicalHistory : Set result = pat.SearchMedicalHistory("MUMPS") pat OREFPatient result SearchMedicalHistory. . . , .

Patient

-

,

,

-

:

Do ##class(Classname).MethodName(arglist) Set value = ##class(Classname).MethodName(arglist)

Classname , arglist

, MethodName . Value

, ,

,

. 58

.

,

ReportCard: Do ##class(MyApp.ReportCard).PurgeAll() MyApp – . , Exists , :

PurgeAll

%File,

,

-

Set exists = ##class(%File).Exists("\temp\file.txt")

exists

true (1),

,

false (0),

.

5.6.10. • • • •

Caché

:

-



-

,

Caché Object Script. .

.

,

Speak

-

Dog:

Class MyApp.Dog Extends %Persistent [ClassType = persistent] { Method Speak() As %String { Quit "Woof, Woof" } }

SQL

HTML,

Caché ObjectScript, .

Basic,

-

: Write dog.Speak()

//

:

Woof, Woof



-

Caché Object Script. ,

.

SQL,

HTML. . ,

,

,

,

. Speak

, :

-

-

Method Speak() As %String [CodeMode = expression] { "Woof, Woof" }

: Write dog.Speak()

: Write "Woof, Woof"

.

. : Caché -

-

.



Caché. ,

,

-

. .

,

:

Method Call() [ CodeMode = call ]

59

{

Tag^Routine }

“Tag^Routine”

Tag

Routine.



,

Caché Object Script. . .

5.7. –

,

,

. . .

,

. ,

MyApp.A

:

XYZ

100

Class MyApp.A { Parameter XYZ = 100; }

MyApp.B

.

Class MyApp.B Extends MyApp.A { Parameter XYZ = 200; }

.

-

,

. , .

, . ,

MAXVAL,

%Integer %Integer.

NumKids

-

:

Property NumKids As %Integer (MAXVAL=10);

, 10

MAXVAL

я

асса %Integer

NumKids. :

. NumKidsIsValidDT, 10.

, ,

NumKids

IntegerLessThanTen. PROPERTYVALI, ,

DATION. :

• • •

0– 1– 2(

. )–

. ,

,

-

60

.

, .

5.8. .

,

. Caché Object Script, SQL. ResultSet – , Caché Object ActiveX, Java. , SQL SQL.

Script, (View),

,

5.9. –

,

.

-

. ,

.

Student

« Student,

, »

Person

,

.

,

. .

. EXACT – UPPER – ALPHAUP – SPACE – PLUS – MINUS –

: ; ; ; ; ; .

,

, .

,

, .

5.10. . , : “Inventory”. “Accounting”

, “Inventory”.

: “Accounting” ,

-

61

,

,

-

: Do ##class(Accounting.Invoice).Method() Do ##class(Inventory.Item).Method()

, : Do ##class(Invoice).Method()

: ,

-

. ,

Caché.

Caché

,

,

.

5.10.1. . . «TestClass»

, “Test.Subtest” : “Test_TestClass”.

,



“.”, “Test.Subtest.TestClass” .

, SQL :

31



,

,

25

. ,

.

5.10.2. . Caché Studio .

– , ,

-

. .

:

Class Accounting.Invoice { }

Invoice Caché Studio, ,

“Accounting”. , «

».

5.10.3. •

: .



:

-

. ,

.

:

// я Lab.Patient Set patient = ##class(Lab.Patient).%New()

, ,

#IMPORT

.MAC

, “%Library”.

.

-

“User”

:

// я Person Set person = ##class(Person).%New()

62

// , Set person = ##class(User.Person).%New()

5.10.4.

#IMPORT #IMPORT

,

.

:

#import Lab // К "Patient" Lab Set patient = ##class(Patient).%New()

#IMPORT #import #import // П Set pat // П Set inv

Lab Accounting "Patient" = ##class(Patient).%OpenId(1) "Invoice" = ##class(Invoice).%OpenId(1)

MAC: Lab & Аccounting Lab & Accounting

#IMPORT . ,

, #IMPORT.

. IMPORT

, .

,

-

: #import User

, ,

User

-

: #import MyPackage #import User

5.10.5.

SQL

Team.Player ( “Team.Player” (

Player Player “User”

SQL . “Team”), “Team”).

,

“SQLUser”. SQLUser.Person.

User.Person

, MyTest.Test.MyClass ( MyClass, “MyTest.Test”) MyTest_Test.MyClass (MyClass – , “MyTest_Test” – ). SQLUser. :

, .

:

Select ID, Name from Person // Т : Select ID, Name from SQLUser.Person

5.10.6. •



« “%Library” – “%Library” “User” –

»

:

%class -% class

“User”

63

6. 6.1. %New: Set oref = ##class(Classname).%New()

oref

OREF

Classname

,

. ##class() – ,

,

. Person

:

Set person = ##class(MyApp.Person).%New()

%New

. -

%OnNew .

, -

.

6.2. : 1. OID – 2. ID – 3. OREF –

.

OID ID Set OID = $LB( ID, “ . ”) : Set OID=$LB(ID,”User.Books”)

:

6.3. ID,

: Set oref = ##class(Classname).%OpenId(ID)

oref – , ID .

,

OREF

, Classname . Classname

,

-

Sample.Person ID 22:

Set person = ##class(Sample.Person).%OpenId(22) Write person.Name,!

person

OREF

Person. OID:

, Set oref = ##class(Classname).%Open(oid)

oref

OREF,

Classname

,

oid

OID

. %OpenId. , .

6.4. , , ,

-

,

,

,

. -

. :

Set oref.PropertyName = value

64

oref .



OREF ,

Name

Set person.Name = "А

person

, PropertyName Person

, value :

"

OREF

Person





Name.

. :

set ..< >=< set ..Adress=”

>.

:

35”. ##this,

OREFSet ##this.Name=”

: ”

• • • •

:

:

-

-

.

6.5. ,

, .

,

,

,

,

-

.

,

,

.

6.5.1. . ,

OREF.

,

-

(ID). : Set oref.PropertyName = RefOref

oref – RefOref –

OREF OREF

, PropertyName – ,

-

,

.

,

Car

,

Person,

person

OREF ID,

Person.

-

: Set car.Owner = person

car –

OREF

Car

-

: Do oref.PropertyNameSetObjectId(RefId)

oref –

OREF , RefId – ID , SetObject ( ID). , ( Car)

, PropertyName – . OID) SetObjectId ( ( :

Person)

Do car.OwnerSetObjectId(PersonId)

car

OREF

Car

PersonId

ID

Person. GetObject

GetObjectId.

65

6.5.2.

,

,

-

,

-

: Set oref.PropertyName.RefPropertyName = value

oref –

OREF , RefPropertyName – , value –

, PropertyName –

,

-

.

, Car,

Name

Owner

-

:

А

Set car.Owner.Name = "И

car –

OREF-

"

Car

"

"

.

6.6. ,

. •

: -



-

. .

6.6.1. – 1. 2.

OREF

-

: %New; ,

: Set oref.PropertyName = EmbeddedOref

oref –

OREF

-

, PropertyName – , EmbeddedOref – OREF

; 3.

, . :

.

,

Address:

Set address = ##class(Address).%New()

Home

Person:

Set person.Home = address

address – Person.

OREF

Address

person –

OREF

: Set person.Home.State = "MA"

6.6.2. –

-

: Set oref.PropertyName.EmbPropertyName = value

66

oref

OREF , PropertyName , EmbPropertyName

-

-

,

. , Set Set Set Set

Home

Person

:

person.Home.Street = "One Memorial Drive" person.Home.City = "Cambridge" person.Home.State = "MA" person.Home.Zip = 02142

person – OREF Drive, Cambridge, MA 02142”.

Person

6.7.

“One Memorial

. .

-

,

.

, . . ,

,



,

. .

• •

: . ,

.

-

.

6.7.1. ,

:

Do oref.PropertyName.Insert(data)

oref – data –

OREF ,

. ,

, PropertyName – “



, -

:

Do person.FavoriteColors.Insert("

person –

OREF

")

Person. n,

:

Do oref.PropertyName.SetAt(data,n)

oref – .

OREF

, PropertyName –

,

:

,

Do person.FavoriteColors.SetAt("

, data –

",2)

. .

"

".

n: Do oref.PropertyName.InsertAt(data,n)

. “

”, “

”, “

“ ”, “

”, “ ”

”, “

Do person.FavoriteColors.InsertAt("

,

:

” : ",2).

6.7.2. . ,

,

,

: Do oref.PropertyName.Insert(ItemOref)

67

oref – OREF , ItemOref –

OREF Vaccination

, PropertyName – . Patient,

,

:

Do pat.Vaccination.Insert(vac)

pat –

OREF

Patient, vac –

OREF

Vaccinati-

on. ,

,

n,

: Do oref.PropertyName.SetAt(ItemOref,n)

oref – OREF , ItemOref – , .

n

OREF

, PropertyName –

.

,

-

,

,

-

: Do pat.Vaccination.SetAt(vac,2)

pat – Vaccination, n

OREF

Patient, vac –

OREF .

, :

,

,

Do oref.PropertyName.InsertAt(ItemOref,n)

. , Vaccination

Patient:

Do pat.Vaccination.InsertAt(vac,3)

pat –

OREF

Patient, vac

OREF

Vaccination.

6.7.3. ,

, ,

-

.

,

,

. .

,

-

: Do oref.PropertyName.InsertObject(itemoid)

oref – OID :

.

OREF ,

, PropertyName

-

,

itemoid – -

Do per.Pets.InsertObject(DogOid)

per –

OREF

Person, Pets –

-

, DogOid

OID

Dog. n,

:

Do oref.PropertyName.SetObjectAt(ItemOid,n)

oref OID

.

OREF ,

, PropertyName

-

, ItemOid , -

: Do per.Pets.SetObjectAt(DogOid,3)

per

OREF

Person n

DogOid :

OID

Dog.

Do oref.PropertyName.InsertObjectAt(ItemOid,n)

.

,

: Do per.Pets.InsertObject(DogOid,1)

per –

OREF

Person

DogOid –

OID

Dog.

68

6.7.4. ,

,

: Set oref.PropertyName.GetAt(n).ListPropertyName = data

oref – , ListPropertyName ,

OREF GetAt

,

; PropertyName

name (

n.

, data )

. :

Set per.Pets.GetAt(2).Name = "Rover"

per

OREF

Person

6.8.

Rover

.

( ).

, -

, ,

.

. • •

-

:

. ,

.

6.8.1. : Do oref.PropertyName.SetAt(data,key)

oref

OREF

, key

, PropertyName .

, ,

Colors

Do paint.Colors.SetAt("255,0,0","



paint ”

-

OREF

, data

-

Palette:

")

Palette, Colors

-

,

,

“255,0,0”.

6.8.2. ,

,

, : Do oref.PropertyName.SetAt(ElementOref,key)

oref – OREF ElementOref OREF , Vaccination Patient:

,

, PropertyName key ,

, .

Do pat.Vaccination.SetAt(vac,"04/08/99")

pat – OREF , “04/08/99” .

Patient, Vaccination – ,

, vac –

OREF

-

69

6.8.3. ,

, .

,

, .

, : Do oref.PropertyName.SetObjectAt(ElementOid,key)

oref –

OREF , key –

OID

, PropertyName – ,

, ElementOid , :

. ,

Do per.Pets.SetObjectAt(DogOid,"Д

, “

per – ”

OREF ,

")

Person, Pets –

OID,

DogOid.

6.8.4. ,

:

Set oref.PropertyName.GetAt(key).ArrayPropertyName = data

oref – , key

OREF

,

, PropertyName , Vaccination,

, 02/23/98:

-

.

Set pat.Vaccination.GetAt("02/23/98").Type = "Polio"

pat – 2/23/98 «Polio».

OREF

Patient,

GetAt

,

Type

6.9. List ,

Array

-

.12. 12 я

я

List

Clear() Count()

Array

-

Define(key) Find(element,key)

key ,

(key). (

,

)

-

«»,

GetAt(key) key. ,

GetNext(. key) key,

,

GetPrevious(. key) key, Insert(element) InsertAt

key. key. 70

(element,key)

. .

InsertOrdered (element)

,

-

. ( ) Next(key)

(

)

-

(

)

-

key Previous(key) key RemoveAt(key)

key

SetAt (element, key)

key.

6.10. : Do oref.PropertyName.Write(data)

oref – , Write

OREF %Stream ( .

, PropertyName , data

),

,

, -

Note

Visit

: Do Visit.Note.Write(note)

visit – ,

OREF ,

Visit, Note –

, note .

. 13

. 13

Write(data) Read(.length)

data length

. ,

. ,

WriteLine(data) ( ) ReadLine(. length) ( ) Rewind()

,

.

data

-

. (

length) .

-

-

. GoToEnd() CopyFrom(stream) OutputToDevice() LineTerminator

«

» stream. , CR LF.

. ,

WriteLine()

. ReadLine().

71

AtEnd

(1),

-

-

. .

User.Person

Memo,

-

.

.

Set pers=##class(User.Person).%OpenId(ID) Do pers.Memo.WriteLine(“ я ”) … Do pers.Memo.WriteLine(“ яя ”) Do pers.%Save() Quit

Set pers=##class(User.Person).%OpenId(ID) Do pers.Memo.Rewind() While ‘pers.Memo.AtEnd { Set length=99 write pers.Memo.ReadLine(.length),! } Quit

6.11. %Save()

:

Do oref.%Save()

oref – %Save .

oref

. ,

-

Set sc=oref.%Save()

sc –

,

%Save, oref –

-

. ,

$$$ISOK $$$ISERR

1,

, 1,

0

, 0 DisplayError()

, $system.Status

. . Caché

. Person

OREF

per

: Set sc = per.%Save() If $$$ISERR(sc) { Do $System.Status.DisplayError() }

6.12. ,

.

-

.

6.12.1. OID .

,

%Delete , .

%DeleteId. ID -

%Delete: Do ##class(Classname).%Delete(oid)

72

Set sc = ##class(Classname).%Delete(oid)

%DeleteId: Do ##class(Classname).%DeleteId(id) Set sc = ##class(Classname).%DeleteId(id)

classname sc – ,

, oid

OID

,

, id – ID . :

, Person

.

Set sc = ##class(Person).%Delete(oid)

oid .

OID

Person,

,

Person ID=24

sc :

Set sc = ##class(Person).%DeleteId(«24”)

sc

.

6.12.2. , Extent,

%Delete-

,

.

Do ##class(Classname).%DeleteExtent() Set sc = ##class(Classname).%DeleteExtent()

Classname

, sc

, ,

. . ,

Person,

-

: Do ##class(Person).%DeleteExtent()

%DeleteExtent

%OnDelete,

-

. , ,

-

%KillExtent: Do ##class(Classname).%KillExtent()

%KillExtent

,

,

,

.

,

-

.

6.13. Caché

%ResultSet

-

.

:

1. 2. 3. 4.

6.13.1. %ResultSet. • • • • •

%ResultSet: GetParamCount() – GetParamName(n) – GetColumnCount() – GetColumnName(n) – GetColumnHeading(n) –

, ,

-

n,

n,

n-

. 73



Prepare() –

• •

, QueryIsValid() Execute() –

• • • •

, 1(true) –

, . , 0(false) –

.

,

-

. Next() – Data(< GetData(n) – Close() –

. >) – . .

6.13.2. , %New():

%ResultSet

Set rset = ##class(%ResultSet).%New()

%ResultSet

:

Set rset.ClassName = class Set rset.QueryName = query

rset – , query –

OREF

%ResultSet, class . :

,

-

Set rset = ##class(%ResultSet).%New(”%DynamicQuery:SQL”) Set rset.ClassName = "Sample.Person" Set rset.QueryName = "ByName" Do rset.Execute() While (rset.Next()) { Write rset.Data("Name"),! }

%ResultSet SQL-

,

Prepare:

Set rset = ##class(%ResultSet).%New("%DynamicQuery:SQL") Do rset.Prepare("SELECT Name FROM Sample.Person WHERE Name %STARTSWITH 'A'") Do rset.Execute() While (rset.Next()) { Write rset.Data("Name"),! }

6.13.3. : Do rset.Execute(arglist)

rset

OREF ,

%ResultSet, arglist

-

.

6.13.4. : Do rset.Next()

rset – Next

OREF

0,

%ResultSet. . .

-

,

: If ('rset.Next()) { Quit

74

}

, %ResultSet. Data .

Data

. .

Set code = rset.Data("Code")

: Set data = rset.GetData(n)

data –

,

n. ,

GetDataByName: Set data = rset.GetDataByName(fieldname)

data

fieldname.

,

Data. , Next

.

6.13.5. ,

:

Do rset.Close() Set sc = rset.Close()

sc Close

, , , , Close ,

.

. %ResultSet. %ResultSet ClassName QueryName %ResultSet .

%ResultSet

-

-

:

// Result я Sample.Person:ByName Set rset = ##class(%ResultSet).%New("Sample.Person:ByName") Set columns = rset.GetColumnCount() // В Set sc = rset.Execute("A") // И While (rset.Next()) { Write "------------------------",! // For col = 1:1:columns { Write rset.GetColumnName(col),": " Write rset.GetData(col),! } } Do rset.Close()

ActiveX

Java ActiveX

Java-

%ResultSet .

-

6.14. 1. 1.

«

: » (Category), .

, : CategoryName –

. 75

2.

« » (Books) – , Authors – , :

. , CountPage – « », Decsription –

COS-

Category

Title – , Category – .

-

Books.

-

, Category

. : : Class User.Category Extends %Persistent [ ClassType = persistent, ProcedureBlock] { Property CategoryName As %String; } Class User.Books Extends %Persistent [ ClassType = persistent, ProcedureBlock ] { Property Authors As %String [ Collection = list ]; Property Title As %String; Property Category As User.Category; Property Cena As %Numeric; Property CountPage As %Integer; Property Decsription As %String(MAXLEN = 100); } : for { read !, " :", cat Quit:cat="" set ct=##class(User.Category).%New() set ct.CategoryName =cat set xx=ct.%Save() for { read !, " ", title Quit:title="" set bk=##class(User.Books).%New() set bk.Title = title read !, " : ",Author do bk.Authors.Insert(Author) set bk.Category =ct read !, " : ",desc set bk.Decsription =desc read !, " : ",kol set bk.CountPage =kol read !, " : ",price set bk.Cena =price set xx=bk.%Save() } }

76

2. ks ID=58,

COSAuthors –

,

%String. // ID=58 set bk=##class(Books).%OpenId(58) // do bk.Authors.Clear() set i=1 // Id=58 for { read !," ",avt Quit:avt="" do bk.Authors.InsertAt(avt,i) set i=i+1 } set xx=bk.%Save() // Set r=##class(%ResultSet).%New(”%DynamicQuery:SQL”) Do r.Prepare("Select ID, Title from Books ") Do r.Execute() While(r.Next()) { write ! write ?5,r.Get("ID")," ",r.Get("Title") set id=r.Get("ID") set bk=##class(User.Books).%OpenId(id) set kol=bk.Authors.Count() write !,"kol=",kol for k=1:1:kol { write !,?15,bk.Authors.GetAt(k) } } 3. Person ( Fio – Adres – DataR –

,

)

,

Address .

Address Ind – City – Street – House – Flat – :

:

,

. COSAddress

:

,

Person

-

. 77

: Person

:

Class User.Person Extends %Persistent [ ClassType = persistent, ProcedureBlock ] { Property Adres As Address; Property DataR As %Date; Property Fio As %String; } Address

// for {

:

Class User.Address Extends %SerialObject [ ClassType = serial, ProcedureBlock ] { Property Flat As %Integer; Property House As %String(MAXLEN = 5); Property Street As %String; Property City As %String(MAXLEN = 15); Property Ind As %String(MAXLEN = 6); } Person, . : Address. Person SQL. Person read !," ",fio Quit:fio="" set pr=##class(Person).%New() // Person set pr.Fio=fio read !," ",dataR set pr.DataR=$ZdateH(dataR) write !," :" read !," ",ind set pr.Adres.Ind=ind read !," ",city set pr.Adres.City=city read !," ",street set pr.Adres.Street=street read !," ",house set pr.Adres.House=house read !," ",flat set pr.Adres.Flat=flat set yy=pr.%Save()

} // Person Pech Set r=##class(%ResultSet).%New(”%DynamicQuery:SQL”) Do r.Prepare("Select ID from Person") Do r.Execute() While(r.Next()) 78

{ write ! write ?5,"ID ",r.Get("ID") set id=r.Get("ID") set bk=##class(User.Person).%OpenId(id) write !,"FIO ","DataR ","Ind ", "City ","Street ","House ","Flat " write ! set k=1 write bk.Fio set k=k+10 write ?k,$ZDate(bk.DataR) set k=k+10 write ?k,bk.Adres.Ind set k=k+10 write ?k,bk.Adres.City set k=k+10 write ?k,bk.Adres.Street set k=k+10 write ?k,bk.Adres.House set k=k+10 write ?k,bk.Adres.Flat } 4. Books, .

.

: Method AlterBook(title As %String, authors As %String, countpage As %String, desc As %String, categ As Category, cena As %Numeric) { // set ..Title=title do ..Authors.InsertAt(authors,1) do ..CategorySetObjectId(categ) set ..CountPage=countpage set ..Decsription=desc set ..Cena=cena set sc= ##this.%Save() } : set bk=##class(Books).%OpenId(5) do bk.AlterBook(“ ”, “ .”, 560,” ”,1,350) 5. Books, . ,

OREF-

.

: ClassMethod AddBook(title As %String, author As %String, countpage As %String, desc As %String, categ As Category, cena As %Numeric) as Books { // set book=##class(Books).%New() 79

set book.Title=title Set book.CountPage=countpage Set book.Decsription=desc Set book.Cena=cena do book.CategorySetObjectId(categ) do book.Authors.InsertAt(author,1) set sc=book.%Save() Quit book } : Set bk=##class(Books).AddBook(“ bk – OREF-

”, “ c

.”, 560,” ”,1,350) .

6. Human

ID, Fam –

,Im –

. ,

,

, age –

, dat – ,

-

. : Human Class User.Human Extends %Persistent [ ClassType = persistent, ProcedureBlock ] { Property Fam As %String; Property Im As %String; Property age As %Integer; Property dat As %Date; } : / write !," " for { read !," ",fam Quit: fam=”” read !," ",im read !," ",vozr // Set n=##class(User.Human).%New() Set n.Fam=fam, n.Im=im, n.age=vozr // Set sc=n.%Save() } // write !," " Set r=##class(%ResultSet).%New(”%DynamicQuery:SQL”) Do r.Prepare("Select ID,Fam,Im,age from Human") Do r.Execute() While(r.Next()) { write !,r.Data("ID")," ", r.Data("Fam")," ",r.Data("Im")," ",r.Data("age") } 80

7.

,

// write " " read !," ", klass write !," ", klass write ! Set r=##class(%ResultSet).%New(”%DynamicQuery:SQL”) Do r.Prepare("Select * from "_klass) if 'r.QueryIsValid() { write !," " quit } Do r.Execute() // set k=1 for i=1:1:r.GetColumnCount() { write ?k,r.GetColumnName(i) set k=k+10 } // While(r.Next()) { write ! set k=1 for i=1:1:r.GetColumnCount() { write ?k,r.Get( r.GetColumnName(i)) set k=k+10 } } 8. Books – Title – . Authors : Property Authors As %String [ Collection = list ]; : Books, .

, Description –

-

Authors

-

, Authors –

Set r=##class(%ResultSet).%New(”%DynamicQuery:SQL”) Do r.Prepare("Select ID,Title,Authors from Books") if 'r.QueryIsValid() { write !," " quit } Do r.Execute() // set k=1 for i=1:1:r.GetColumnCount() { write ?k, r.GetColumnName(i) set k=k+15 } // ID, Title, Authors

,

//

81

while (r.Next()) { Set IID= r.Data("ID") write !,IID, ?20, r.Data("Title") set b=##class(Books).%OpenId(IID) set k=b.Authors.Count() // //

Authors

,

Count

. for i=1:1:k { write ?40, b.Authors.GetAt(i),! // } }

82

7. 7.1. , .

,

,

-

. , .

-

. 14

: 14

Name= Book(Nomer)= Name –

|

^Name= ^Book(Nomer)= .

.

,

,

|

. ^Name –

. Book ^Book – ^Name.

Name

, , . .

^Book

-

.

7.2. Set. . Set A=1, A(3)=2, A(3,7)=”Monday”, A(3,7,25)=”holiday”. A, A(3), A(3,7), A(3,7,25). . – A(3,7) , ,

:

, ,

-

A(3,4). .

, : Set month(“ Set Fio=Univer(«

.

”)=9 // », 104) // . ,

1023

.

7.3. Caché • •

.

-

: .

:

.

+ 1, 0.7

. 2.40 -100 -15 0

. , 5

. 6.1

11

“!”

“AA”

“ZZ”

“a”

“z”

“ ”





: “ ” “ ”.

83

7.4. ,

,

, .

Caché Set

.

Set ^Univer(“

. : . .”, “22-33-45”)

”)=$ListBuild(“ ,

. : For i =1:1:$ListLength(^Univer(“ { Write !, $List ( ^ Univer(“ }

”)) ”) , i) Kill.

: Kill ^ Univer(“

-

”). .

,

ZKill,

.

-

$List. «

».

^Univer,

-

: ^Univer= “N-

” ,

– ^Univer(
)=
|


: ^Univer(“ ^Univer(“ ^Univer(“

”) = ”) = ”) =

. .| 22-33-45 . .| 34-32-12 . .| 45-90-78 ,

,

. . (

) :

^Univer(
,
)=

.

”, 104) = ”, 105) = ”, 106) =

. . . . . .

: ^Univer(“ ^Univer(“ ^Univer(“ (…)

: ^Univer(
,
, )=

|

|

: ^Univer(“ ^Univer(“ ^Univer(“

Set ^Univer= "NSet ^Univer(" Set ^Univer("

”, 104, 91232) = ”, 104, 91233) = ”, 104, 91234) =

. .| . .| . .|

10,3| 67-56-32 45,9| 78-56-34 10,78| 33-45-67

: " ") = $ListBuild(" ") = $ListBuild("

. .","22-33-45") . .","34-32-12") 84

Set ^Univer(" Set ^Univer(" Set ^Univer(" Set ^Univer(" Set ^Univer(" 10,3","67-56-32") Set ^Univer(" 45,9","78-56-34") Set ^Univer(" 10,78","33-45-67")

") = $ListBuild(" . .","45-90-78") ", 104) = " . ." ", 105) = " . ." ", 106) = " . ." ", 104, 91232) = $ListBuild(" . ."," ", 104, 91233) = $ListBuild("

. .","

", 104, 91234) = $ListBuild("



. .","

: (

,

).



, . ,

: ,

, ,



. • Caché

. -

,

«

Caché,

-

» [2].

7.5. Caché. B*,

.

-

, (balanced tree, ,

B*-

B-

).

, ,

-

.

.

7.6. 7.6.1.

$Data - $D) – .

$Data (

,

,

-

, .

.

: $DATA(variable,target) $D(variable,target) variable – , target – . , , $DATA.

,

.

. 15 15

0 10 (

)

, . .

, ,

$DATA(y)

85

10,

set x=y

. ,

1 ,

.

«»

.

11(

. )

-

. 1

.

11

,

. $Data . If $Data(^Univer(“

: ”, 104))#10 write “

-

” If $Data((^Univer(“ ,

1

10 11,

”, 110))#10=0 write “ $Data 1,

”. -

. . 10 : , If ($Data(^Univer(“ { Set Fio=^Univer(“ write Fio }

1, 0

1

,

10, 10, 0. ,

11

. : ”, 104))#10 ”, 104)

,

-

. $Get ( $G). : Set Fio=$Get(^Univer(“ ”, 110),””) , Fio – “ ”. . , . , – , , . ^client . ^client(5) John Jones // ^client(5,1) 23 Bay Rd./Boston/MA 02049 // ^client(5,1,1) Checking/45673/1248.00 // ^client(5,1,2) Savings/27564/3270.00 // ^client(5,1,3) Reserve Credit/32456/125.00 // ^client(5,1,4) Loan/81263/460.00 //

, ^client, ,



. ,

:

: Set ^client(5)="John Jones" // Set ^client(5,1)=$ListBuild("23 Bay Rd.","Boston","MA 02049") // Set ^client(5,1,1)=$ListBuild("Checking","45673","1248.00") // Set ^client(5,1,2)=$ListBuild("Savings","27564","3270.00") // Set ^client(5,1,3)=$ListBuild("Reserve Credit","32456","125.00") // Set ^client(5,1,4)=$ListBuild("Loan","81263","460.00") //

86

. $DATA=0 $DATA=10 2 3 .

1,2,

3 1

$DATA , 2

. , ,

. WRITE

.

$List Start Read !," Read !," For i=s : 1 : s + n { // If $Data(^client(i)) { If $Data(^client(i))=10 { Write !," :

-

: ",n : ",s

"}Else {Write !,"

If $Data(^client(i,1)) { // If $Data(^client(i,1))=10 {Write !," Else { // Write !," : ",$List(^client(i,1),1) Write " , ",$List(^client(i,1),2) Write " , ",$List(^client(i,1),3) } }

:

: " ,^client(i)}

"}

For j=1:1:4 {// If $Data(^client(i,1,j)) { Write !," : ",$List(^client(i,1,j),1) Write ?30," #: ",$List(^client(i,1,j),2) Write ?50," : ",$List(^client(i,1,j),3) } } } } Write !," " Quit 7.6.2.

$Get $Get

, .

$Get(
[,
]) ,

. : Set Fio=$Get(^Univer(“ 7.6.3.

”, 110),””)

$Order – $Order ($O)

.

87

.

,

^Univer. ^Univer(“ ”) = ^Univer(“ ”) = ^Univer(“ ”) = write $Order(^Univer(“

-

. .| 22-33-45 . .| 34-32-12 . .| 45-90-78 ”)) ^Univer(“

: “

”.

-

”), ,

”.



, . .

.

,

-

, .

,

: Set x=”” For { Set x=$Order(^Univer(x)) Quit: x=”” Write !,x }

1.

,

, ,

> write $Order(^Univer(“ > 104

,

-

: ”, 004))

2.

, ,

, 104

-

115.

Set x=104 For { Set x=$Order(^Univer(“ Quit:x=””!(x>115) Write !, x }

”, x))

3.

: Set x=”” For { Set x=$Order(^Univer(x), -1) Quit:x=”” Write !, x} :

4.





? : > write $Order(^Univer(“ > 104 //

”, ””)) :

Set Fac=" ", x="" For { Set x=$Order(^Univer(Fac,x)) 88

Quit:x="" Write !, x } 104.

: : Set Fac=" ", Gr=104, x="" For { Set x=$Order(^Univer(Fac,Gr,x)) Quit:x="" Write "№ ",x,! Write " :",$List(^Univer(Fac,Gr,x),1) ,! Write " :",$List(^Univer(Fac,Gr,x),2) ,! Write " :",$List(^Univer(Fac,Gr,x),3) ,! } 7.6.4.

$Query $Query

. , ^Univer=”N^Univer(“ ^Univer(“ ^Univer(“ ^Univer(“ ^Univer(“ ^Univer(“ ^Univer(“ ^Univer(“ ^Univer(“

, . :

$Order

” ”) = . .| 22-33-45 ”) = . .| 34-32-12 ”) = . .| 45-90-78 ”, 104) = . . ”, 105) = . . ”, 106) = . . ”, 104, 91232) = . .| ”, 104, 91233) = . .| ”, 104, 91234) = . .|

> write $Query(^Univer(“ ^Univer("

10,3| 67-56-32 45,9| 78-56-34 10,78| 33-45-67

”)) ",104)

> write $Query(^Univer(" ^Univer("

",104)) ",104,91232)

> write $Query(^Univer(" $Query(^Univer("

",104,91232)) ",104,91233))

> write $Query(^Univer(" $Query(^Univer(" , , ,

",104,91233)) ",104,91234)) , .

-

: set x="^Univer("" for { set x=$Query(@x) Quit:x="" write !,x }

"")"

89

$Query

$Order

,

,

–1(

1)

«

»

-

. 7.6.5.

$QLength, $QSubscript $Qlength ($QL) . . . sn), n. : > write $QL("(^Univer("" 3 >write $QL(" ") 0

,

Name (s1, s2,…,

"",104,91232)")

. 0.

-

,

,

: write $QL(1). $QSubscript : $QS[ubscript] (,) namevalue – , intexpr – , . Name (s1, s2,…, sn), $QS(Name (s1, s2,…, sn), m) m, mwrite $QS("^Univer("" "",104,91232)", 2) 104 7.6.6.

-

:

Merge Merge (

,

M)

-

,

.

Merge < < ,

>=< >

:

>


– . .

:

Merge copy=^Univer ^Univer

copy.

copy(i)

^Univer(i). ,

,

,

-

: Merge ^Math(“

”)=^Univer(“

”) .

7.7. ,

%CacheStorage, ,

(

-

).

90

: :

• •

. ,

, . . “D”,

.

-

, “I”.

,



. ID.

,

ID $Increment.

-

, , .

,

MyApp.Person

-

. Class MyApp.Person Extends %Persistent [ClassType = persistent] { Property Name As %String; Property Age As %Integer; } , : ^MyApp.PersonD = 2 // ( ^MyApp.PersonD(1) = $LB("",19," ") ^MyApp.PersonD(2) = $LB("",20," ") , , . . . %OpenId, %Persistent, , .

7.7.1.

)

, Person,

IDKEY IDKEY . IDKEY , ,

ID, , , , ,

ID. ID

. IDKEY,

ID. Person , IDKEY, Name. Class MyApp.Person Extends %Persistent [ClassType = persistent] { Index IDKEY On Name [ Idkey ]; Property Name As %String; Property Age As %Integer; } Person, : ^MyApp.PersonD(" ") = $LB("",19) ^MyApp.PersonD(" ") = $LB("",20)

-

,

,

-

-

91

,

.

ID

,

,

-

,

Name, . IDKEY

, . Class MyApp.Person Extends %Persistent [ClassType = persistent] { Index IDKEY On (Name,Age) [ Idkey ]; Property Name As %String; Property Age As %Integer; } : ^MyApp.PersonD(" ^MyApp.PersonD("

",19) = $LB("") ",20) = $LB("")

7.7.2. ,

,

,

. .

,

-

,

MyApp.Person : Class MyApp.Person Extends %Persistent [ClassType = persistent] { Property Name As %String; Property Age As %Integer; } , MyApp.Student, : Class MyApp.Student Extends Person [ClassType = persistent] { Property Subject As %String; Property Mark As %Float; } MyApp.Student, : ^MyApp.PersonD = 2 // ^MyApp.PersonD(1) = $LB("Student",19," ") ^MyApp.PersonD(1,"Student") = $LB(3.2," ") ^MyApp.PersonD(2) = $LB("Student",20," ") ^MyApp.PersonD(2,"Student") = $LB(3.8," ") , Person, , , Student . , Student Person. , SQL , Person, Person, Student. ,

, ,

. “Student”,

,

Student.

92

7.7.3. , ,

. Caché SQL . Caché Object

-

SQL ,

.

7.7.4. ID.

,

-

MyApp.Person

Name. Class MyApp.Person Extends %Persistent [ClassType = persistent] { Index NameIdx On Name; Property Name As %String; Property Age As %Integer; } Person, : // ^MyApp.PersonD = 3 // ^MyApp.PersonD(1) = $LB("",34,"Jones") ^MyApp.PersonD(2) = $LB("",22,"Smith") ^MyApp.PersonD(3) = $LB("",45,"Jones") // ^MyApp.PersonI("NameIdx"," JONES",1) = "" ^MyApp.PersonI("NameIdx"," JONES",3) = "" ^MyApp.PersonI("NameIdx"," SMITH",2) = "" : 1.

,

2.

,

, “I”

-

. , -

. 3.

. SQLUPPER, ,

-

.

,

, Exact. Index NameIdx On Name As Exact; ID

4.

,

:

,

-

; 5.

, .

,

, ,

-

.

93

, , son,

Per-

, Name.

$Order. Write $Order(^MyApp.PersonI("NameIdx"," JONES",-1)) . . , , Id : Write $Order(^MyApp.PersonI("NameIdx"," JONES",1)) 3, Id , NES", . . 1 .

: ,

1. " JONES".

-

" JO-

94

8.

CSP CSP (Caché Server Pages) ,

WebCSP

Caché. ,

Web-

-

. . CSP-

CSP-

.

CSP-

CSP,

Caché

Server Pages.

.

,

HTTP,

,

CSP-

, ,

HTML.

,

• • • • •

Web, Caché. Caché Web-

CSP; ,

: Caché

JavaScript;

; CSP-

; HTML.

8.1.

Caché Caché

#(…)#

, .

:

… ! #($Zdate($Horolog,4,” “)#

!



#(…)# -

CSP.

-

Caché.

8.2.

,

Caché


#(^Visit)#

( ^Visit

-

),

1.

2. Web



id=2

Human:

Human 2.

: Fam

ID

Im,

.

8.3.

,

#server(…)#

1. Login.csp, . 10. “

” , –

. , . onClick “CheckPassword”.

. «

-

» :



96

:
:




csp:object

: #(Hum.Fam)#
: #(Hum.Im)#
: #(Hum.age)#


99

: CSPBIND

CSPBind.

HTML ,

:

,

CSPBind

.

:

NAME ,

-

,

CSPBind PUT

IN-

. Caché,

,

ClassName

(

, SELECT). CSPField

,

Class-

, CSPQuery. (

CSPField Name) (

SELECT). ,

CSPQuery

ID. , SELECT). CSPField

( ,

-

CSPQuery. ,

CSPRequired

,

. JavaScript

CSPValid

,

.

, , Fam –

,Im –

, age –

Human .

Human.







ID :
:
:


Id – -

-

100

:




8.4.2.

CSP-

SQL. • • •

.

,

-

: ; SQL-

; . . .

:

CLASSNAME

Caché.

,

-

, . NAME

, CSP-

QUERYNAME

Caché. ,

-

, ,

P1,P2,…P16

. ,

-

. Human

1.

HTML-

,

-

Fam. byHuman SELECT %ID,age,dat,Fam,Im FROM Human ORDER BY Fam. , . hum.Get(< >) – .

#(hum.Get("ID"))# #(hum.Get("Fam"))#

:

101

#(hum.Get("Im"))# #(hum.Get("dat"))# #(hum.Get("age"))#


Human,

-

Fam. 8.4.3.

.

,

, -

. : CONDITION

, , -

COUNTER

. . ,

1, -

1 . CURSOR

. SQL-

.

SQL-

.

SQL-

. INTO

-

,

.

. 1. .

• • • • • • • • • •



  • - #(i)#.

: - 1. - 2. - 3. - 4. - 5. - 6. - 7. - 8. - 9. - 10. 2.

while.

, . :

: #(Fam)#, : #(Im)# : #(age)#


3. thor,Title).

,

Books(Id, Auwhile

:





#(query.Get("Title"))#


8.4.4.

CSP.

.

-

: COUNTER STEP FROM TO

.


  • #(i)#.

: • • • • •

8.4.5.

0. 1.5. 3. 4.5. 6.

103



CSP. ObjectScript . true, .

CONDITION, ,

,

Basic

CONDITION

1:



2: HTML

:



#(Cat.Get("CategoryName"))#

8.4.6.

, . Caché

, ,

.

-

CSP. Caché Object Script,

-

:

ARGUMENTS NAME RETURNTYPE .



.

-->

104



1: 2: :

&Javascript set sum=c1+c2 &Javascript

8.4.7.

JavaScript-

HTML COS JavaScript- . &JavaScript < JavaScript ;> &JS < JavaScript ;> : &JS< alert(“ ”);>

HTML&HTML< -HTML > : If (t=0) ! (t=6) { &HTML< > Write ^day(t) } else { Write ^day(t) }

8.5.

. CSP-

:« : ID, Fam, Im, %request :

/

.

Caché Object Script (COS) :

:

%CSP.Request

CSP%request. , ». . , %request

%CSP.Request, HTML %request . ,

105

я Count

я %Library.Integer

-

(%Library.String)

Get

-

,

-

(%Library.String), -

Kill

(%Library.String) %request

Next

%Library.String

- «» (%Library.String)

, Set

(%Library.String)

: 1) %request.Get(“Fam”) – 2) %request.Set(“Length”,12) – 3) %request.Kill(“Length”) – .

Fam. Length %request ,

-

, 4) %request.Next(“CustomerID”) – . %request.Next(“”) – 5) %request.Count(“Authors”) – for I=1:1: %request.Count(“Authors”) { Set x=%request.Get(“Authors”, , i ) … } я 1. ,

Fam – .

12. Length

. CustomerID . Authors.

%request

Human(ID,Fam,Im, dat, age), , Im – , dat – , age – webBrowHuman.csp, .

.

web.

.

12.

106

12. BrowHuman.csp ID – CSPBind1.csp. CSPBind1.csp . , . 13.

13.

, BrowHuman.csp

webID

CSPBind1.csp.

BrowHuman.csp ID CSPBind1.csp :

CSPBind1.csp ID %request, :

. BrowHuman.csp:

107





ID


#(hum.Get("ID"))#
#(hum.Get("Fam"))# #(hum.Get("Im"))# #(hum.Get("dat"))# #(hum.Get("age"))#


CSPBind1.csp:





:
:
:
:






objid=#(%request.Get("Id"))# ID

CSPBind1.csp

-

. 108

CSPBind1.csp Form, . . CSPformname_new()

,

CSPBind

. , Caché formname_save(), formname – .

,

2. , «Search.csp».

14.

%request , . 14.

«Search.csp»

Search.csp.

Search.csp :





:



"submit" (« %request,

PersonSearch.csp,

»)

webGet()

"SearchFor". . Q2 : Query Q2(P1 As %Integer = 44) As %SQLQuery(CONTAINID = 1) { SELECT %ID,age,dat,Fam,Im FROM Human WHERE (Fam = :P1) ORDER BY Fam } PersonSearch.csp



Q2,

-

:

109



req= #(%request.Get("SearchFor"))#


: #(query.Get("Fam"))#
: #(query.Get("Im"))#
: #(query.Get("age"))#
:#(query.Get("dat"))#





8.6.

%session %CSP.Session. ,

%session

%session, -

, .

, .

,

,

Web-

,

HTTP .

,

, Web%session ,

.

, -

. %session .

«

/

»

,

”Admin” “Name” %session Set session: Do %session.Set(“Name”,”Admin”) , , Name : %session.Get(“Name”). %session , , . %session . 17. %session %CSP.Session : (http://127.0.0.1:1972/apps/documatic?CLASSNAME=%25CSP.Session). 17 я я ( ) Count

%Library.Integer

-

(

Get

)

-

%session

-

-

( ,

-

) 110

Kill

-

Next

%Library.String

OnAppTime Out onStart

,

-

-

, EndSession 1 %Library.Boolean

%session, ,

IsDefined

%Library.Boolean

,

-

Set

-

,

CSP . Page.

CSPSession1.csp Page.

Session.csp, Session.csp Session.csp:

-



session

1 #(%session.Get("Page"))# Page

2

Session1.csp:



session

2 Page #(%session.Get("Page"))#

111

8.7. : Books,

,

,

. , . « » (Books) – . Title – , Authors – , CountPage – , Category – , « », Decsription – . : AddBook AlterBook . : Class User.Books Extends %Persistent [ ClassType = persistent, ProcedureBlock ] { Property Authors As %String [ Collection = list ]; Property Category As User.Category; Property CountPage As %Integer; Property Decsription As %String(MAXLEN = 100); Property Title As %String; Property Cena As %Numeric;

-

,

-

Method AlterBook(title As %String, authors As %String, countpage As %String, desc As %String, categ As Category, cena As %Numeric) { // set ..Title=title do ..Authors.InsertAt(authors,1) do ..CategorySetObjectId(categ) set ..CountPage=countpage set ..Decsription=desc set ..Cena=cena set sc= ##this.%Save() } ClassMethod AddBook(title As %String, author As %String, countpage As %String, desc As %String, categ As Category, cena As %Numeric) as Books { // set book=##class(Books).%New() set book.Title=title Set book.CountPage=countpage Set book.Decsription=desc Set book.Cena=cena do book.CategorySetObjectId(categ) do book.Authors.InsertAt(author,1) set sc=book.%Save() Quit book } Index IndBooks On Title As Exact; } «

» (Category), , . : Class User.Category Extends %Persistent [ ClassType = persistent, ProcedureBlock ] 112

{ Property CategoryName As %String; Index InxCat On CategoryName As Exact [ Data = CategoryName ]; Method AltCateg(categoryname As %String) As %Status { // : Set ..CategoryName=categoryname Quit ..%Save() } } : csp1. BookBrowse.csp – 2. AddBooks1.csp – 3. AlterDel1.csp –

: .

BookBrowse.csp AddBooks1.csp, ID BookBrowse.csp

«

»

« ». AlterDel1.csp, -

. AddBooks1.csp , Browse.csp,

AlterDel1.csp

Cache,

Action Form. BookBrowse.csp ,

BookBrowse.csp –

.

.

submit,

BookBookBrowse.csp .

. 15.

113

15. BookBrowse.csp BookBrowse.csp:











ID


#(query.Get("ID"))#
#(query.Get("Title"))# #(query.Get("Authors"))# #(query.Get("CategoryName"))# #(query.Get("CountPage"))#


AddBooks1.csp – AddBooks1.csp

. 16.

115

16.

AddBooks1.csp AddBooks1.csp:





:
:
:

#(Cat.Get("CategoryName"))#


:



AlterDel1.csp – AlterDel1.csp

17.

. 17.

AlterDel1.csp 116

AlterDel1.csp:







#(%request.Get("ID"))#
ID:
:
:
:



#(Cat.Get("CategoryName"))#


:




OnClick: onclick = "#server (..Method(…) .

8.8.

Abonent , Password – . Abonent

Fio – Login

, Login – Password. Select-

SQL,

-

.

117

. Abonent Login: Index LoginIndex On Login As Exact; , CheckPassw,

Login .

,

0(

) $Order (

, .

Abonent, Password id

.

7, .7.6.3). .7.7.4 7.

, -

:

ClassMethod CheckPassw(log As %String, passw As %String) As %Status { set id=$Order(^User.AbonentI("LoginIndex",log,-1)) if id="" quit 0 Set obj=##class(User.Abonent).%OpenId(id) if obj.Password=passw quit id quit 0 }

word.

cspVvodParol.csp.

.



Login VvodParol.csp

Pass.18.

18 ,

« », CheckParol.csp, VvodParol.csp.

submit,

-

, CheckParol.csp

. 19.

118

19 CheckParol.csp

Cache-

,

.

VvodParol.csp

:



Cache Server Page


:
:




CheckParol.csp

:

Cache Server Page








119

1. 2.

Caché, ., ё

.,

Caché 5.0. ., -

3. 4.

.,

. ., , .

, , 2001 , .

Caché . .,

5. « «

. .,

. .,

. ., », .

,

6.

, , 2001 Caché 5.0.

, 2001 Caché»,

. .

120