Caché Database Learning notes (2)

Source: Internet
Author: User
Tags class definition

Directory:

Create a new Class (table) (class file) with Create routine (. Mac. Inc)

Add a function to a class (Classmethod)

Use of terminal

===============================================

===============================================

Create a new Class (table) (class file) with Create routine (. Mac. Inc)

A. cls file corresponds to a. mac file and an. inc file, property and function (method/ Query) definition is placed in a. cls file, a specific handler is written to the. mac file, and constants are defined in the. inc file, which is defined as a specific variable name to use when using the array of function calls, making. Mac and file easy to read

File/new.../general

Cache class definition (. cls)

Cache basic routine (. mac/.int)

Enter the appropriate package name and the newly created class name to get a class file named Package.Class.cls, which can be found in Workspace/project.

When you create a new class, a class corresponds to a table, and all the actions of the table Form a class, and the classes that are placed under the same package are associated, and in practice, the classes under a package describe different aspects of the same big problem. The concrete establishment and the classification way through the database design way to guide, here does not say much.

The new file is shown with the code in curly braces

A feature in a Class (table):

property, primary key, index, method.

New property:

Direct Write statements:

Property ID as%string [Required];

You can create a new property named ID, which is a string type (note case-sensitive), and the required attribute in the table cannot be empty

You can also find a button for the new property and create a new one by following the new wizard

If the relationship between the table and the table is a parent-child table, such as the parent table is the basic information, the child table is the details, to establish a link between the two tables in the attribute: (the parent table in the following example is CLASS1, the child table is CLASS2, together under the P-package)

The attributes in the p.class1.cls need to be written:

Relationship Class2 as p.class2 [cardinality = children, inverse = Class1];

The attributes in the p.class1.cls need to be written:

Relationship Class1 as p.class1 [cardinality = parent, inverse = Class2];

To set the primary key:

Index PK on (PR1, PR2) [IdKey, PrimaryKey, Unique];

Set index: Find by in Query

Index Idxa on (PR1, PR2);

Here Pr1 and PR2 can be primary keys or not primary keys

When connecting to other tables, that is, the specific property name is in the other table, which is also reflected in this table:

Property Revisioninfo as Cm.revisioninfo;

This means that this table has a set of attributes Revisioninfo in the table Cm.revisioninfo, as well as this set of properties in this list.

=======================================================

Add Method (SetData):

To write a method, you need to operate the (. cls.mac.inc) three files simultaneously:

. cls Files:

Classmethod SetData (Planno as%string, Patientid as%string, StartDate as%integer, EndDate as%integer, Module as%string , Status as%integer, Doctorid as%string, UserId as%string, TerminalName as%string, Terminalip as%string, DeviceType A S%integer) as%integer{    set ret = 0    SET ret = $ $SetData ^ps.plan (Planno, Patientid, StartDate, EndDate, Module, S Tatus, Doctorid, UserId, TerminalName, Terminalip, DeviceType)    Quit Ret}

Define the Classmethod name is SetData, in parentheses for the incoming parameter and type, set the return initial value of 0, and then call the SetData function in routine (the call successfully returned 1, set in routine), exit the function and return to RET

. mac Files

#Include%occstatus#include ps.plan.storage#include chrodiseaconst#include Cm.RevisionInfo.StorageSetData (Planno, Patientid, StartDate, EndDate, Module, Status, Doctorid, UserId, TerminalName, Terminalip, DeviceType) public{Set Ret = $$ $SetDataFailed Set key = Planno set oref = # #Class ("Ps.plan").%O    Penid (Key) if ($IsObject (oref) = 0) {Set oref = # #Class ("Ps.plan").%new ()} if ($IsObject (oref) = 1) {Set oref. Planno = Planno Set oref. Patientid = Patientid Set oref. StartDate = StartDate Set oref. EndDate = EndDate Set oref. module = Module Set oref. Status = Status Set oref. Doctorid = Doctorid Set revisioninfo = $ $GetNewRevisionInfo ^cm.revisioninfo (UserId, TerminalName, Ter Minalip, DeviceType) Set oref. Revisioninfo.datetime = $ListGet (Revisioninfo, $$ $CmRevisionInfoDateTime) Set oref. Revisioninfo.userid = $LisTget (Revisioninfo, $$ $CmRevisionInfoUserId) Set oref. Revisioninfo.username = $ListGet (Revisioninfo, $$ $CmRevisionInfoUserName) Set oref. Revisioninfo.terminalname = $ListGet (Revisioninfo, $$ $CmRevisionInfoTerminalName) Set oref. Revisioninfo.terminalip = $ListGet (Revisioninfo, $$ $CmRevisionInfoTerminalIP) Set oref.       Revisioninfo.devicetype = $ListGet (Revisioninfo, $$ $CmRevisionInfoDeviceType) Set sc = Oref.%save () If $$ $ISOK (SC) {set Ret = $$ $SetDataSuccess} else {Set errmsg = $Sys Tem.  Status.geterrortext (SC, "") Do Writeserverlog^cm.commonlibrary ("", "", ErrMsg)} Kill oref} Quit Ret}

Here, Chrodiseaconst sets all the state variables used in the project, such as isOK in the code. The Ps.Plan.Storage.inc file sets the macro file that corresponds to each property of the table, sets the number used when the array element is called to the corresponding variable name, makes the code easy to read, and Cm.RevisionInfo.Storage is the same.

First, set the return initial value, set the primary key, if it already exists, open the value corresponding to the primary key, otherwise new; Set the value of each property as the passed parameter; Determine whether it is successful or not; Finally releases the cache and returns a RET exit.

. inc File

#Define    Pspland "^ps.pland" #Define    Psplani "^ps.plani" #Define psplanpatientid 2#define psplanstartdate 3# Define psplanenddate 4#define psplanmodule 5#define psplanstatus 6#define psplandoctorid 7#Define PsPlanRevisionInfo 8

Defining macros

==================================================

Add a method (simple check table):

. CLS:

Classmethod Getpatientplan (Planno as%string) as%list{    set ret = ""    set ret = $ $GetPatientPlan ^ps.plan (Planno) 
    quit Ret}

Enter a parameter (Planno) to return a list that matches the find criteria. First, the initial value is empty, then the routine is called and the exit is returned.

. Mac:

Getpatientplan (Planno) public{Set Ret = "" Set data = $Get (@[email protected] (Planno)) If (Data ' = "") {Set Patientid = $ListGet (data,$$ $PsPlanPatientId) Set StartDate = $ListGet (data,$$ $PsPlanStartDate) Set EndDate = $ListGet (data,$$ $PsPlanEndDate) Set Mo Dule = $ListGet (data,$$ $PsPlanModule) Set Status = $ListGet (data,$$                $PsPlanStatus) Set Doctorid = $ListGet (data,$$ $PsPlanDoctorId) Set Revisioninfo = $ListGet (data,$$ $PsPlanRevisionInfo) Set DateTime = $ListGet (Revisioninfo, $$  $CmRevisionInfoDateTime) Set UserId = $ListGet (Revisioninfo, $$ $CmRevisionInfoUserId) set                  UserName = $ListGet (Revisioninfo, $$ $CmRevisionInfoUserName) Set TerminalName = $ListGet (revisioninfo, $$ $CmRevisionInfoTerminalName) Set terminalip = $ListGet (Revisioninfo, $$ $CmRevisionInfoTerminalI P) Set DeviceType = $ListGet (Revisioninfo, $$ $CmRevisionInfoDeviceType) set Revisi Oninforet = $ListBuild (DateTime, UserId, UserName, TerminalName, Terminalip, devicetype) Set Ret = $ListBuild    (Patientid, StartDate, EndDate, Module, Status, Doctorid, Revisioninforet)} Quit Ret}

Similarly, the initial value is set first, then the search condition is found from the D table (in this case because the primary key is found, so no index is needed), and then the returned list content, the last build list, is returned.

=================================================

Use of Terminal:

A command-line operation that is used to perform instruction operations on a database or to test a method that has been written.

such as test Classmethod can enter the command

W # #class (Ps.plan). SetData ("xx", "yy", ...)

Test Query

Do Testgetplan^ps.plan ()

(There should be a corresponding test method in routine Testgetplan ())

Note that the first time you open the user name password, you need to change it to the corresponding namespace each time you open it:

Zn "Namespace"

Caché Database Learning notes (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.