Cach 資料庫學習筆記(3)

2022-09-07 16:24:21 字數 3212 閱讀 4661

目錄

query函式及其測試

重建索引表

management portal簡介

遠端訪問ensemble

query函式及其測試:

query工作原理:

.cls部分:

首先根據query傳入資料建立索引表idxa(需要在portal裡build)宣告query時設定函式名、傳入變數和傳出變數列表包含三個classmethod: execute, fetch, close

execute設定查詢資料時的依據,包含全部主鍵及索引,存入qhandle陣列裡

fetch為主體,傳入查詢依據(qhandle), row(需要得到的列表), atend(0可以進行下去,1終止)

query getplan(status as %integer, startdate as %integer) as %query(rowspec = "planno:%string,patientid:%string,startdate:%integer,enddate:%integer,module:%string,status:%integer,doctorid:%string") [ sqlproc ]

classmethod getplanexecute(byref qhandle as %binary, status as %integer, startdate as %integer) as %status

classmethod getplanclose(byref qhandle as %binary) as %status [ placeafter = getplanexecute ]

classmethod getplanfetch(byref qhandle as %binary, byref row as %list, byref atend as %integer = 0) as %status [ placeafter = getplanexecute ]

.mac檔案部分:

query邏輯:

啟動:傳入startdate和status,planno為空,根據status和idxa由後向前找到第一條資料的startdate進入while迴圈:目的是在不傳出有效資料的情況下不必跳出fetch

過程:判斷startdate是否符合條件,若不符合跳出並終止fetch根據idxa, status, startdate找到一條資料並設定planno判斷planno不為空的時候,進行查詢和傳出資料;否則按照之前的方法查詢下一條資料並再次進入迴圈傳出atend值(0可以繼續進入fetch,1終止fetch), row(返回的列表), planno, status, startdate根據這三者查詢下一條資料

getplan(planno, startdate, status) public

// -1表示從後向前查詢,因為該函式的目的是找時間最近的,因此從後向前查詢會避免很多問題

set startdate = $order(@$$$psplani@("idxa", status, startdate), -1)

while (startdate '= "")

next

set planno

= $order(@$$$psplani@("idxa",

status, startdate, planno), -1)

if (planno '

= ""

)

set startdate

= $order(@$$$psplani@("idxa",

status, startdate), -1)

}exit

set ret

= $listbuild(atend,

row, planno, startdate, status)

quit ret

}

query 的測試方法寫在routine中,

// do testgetplan^ps.plan()

testgetplan() public

do rs.close()

kill rs

quit

}

需要注意的是,非主鍵的屬性作為索引時,在i表裡小寫會自動轉成大寫;非必需的屬性作為索引,在i表裡會自動在前面加乙個空格。這裡我自己的推測是在索引時,非必需的屬性可能為空,而在routine中,是要根據這個屬性進行索引的,為防止可能為空的資料無法被索引到,會自動在前面加乙個空格。因此在寫query的routine時,要注意在編碼時加空格匹配;在test時,要注意大小寫和空格的問題。

重建索引表:

正常輸入資料後,資料存放在d表中,而query在查詢資料時,會使用索引表(i表)。i表是根據d表和cls檔案中的設定建立起來的

management portal/system explorer/sql

更改命名空間,開啟左側的tables下拉欄,找到需要重建的表名

在右側可以看到基本資訊,找到上面的action/rebuild indices即可建立i表

另外open table可以檢視當前表的所有內容,在當前頁的最下方可以調節顯示資料的條數

management portal簡介:

除了上述的system explorer/sql外,常用的還有system explorer/globals用於匯入匯出資料和檢視**;system operation進行配置;system administration進行管理等

遠端訪問ensemble:

首先關閉防火牆才能被其他伺服器遠端訪問。

訪問其他伺服器時,首先進行配置。

左鍵右下角圖示,prefered server/addedit…

localhost這一行可以看到自己的port/web server port配置情況,點選add新增其他伺服器ip位址、埠和網路埠儲存

再檢視prefered server即可看到當前的首選伺服器,在remote system access裡可以開啟任意可以遠端到的伺服器的studio/terminal/management portal/documentation

Cach 資料庫簡介

cach 是後關係型資料庫,獨一無二地提供了三種整合的可併發訪問同一資料方法 強大的物件訪問 高效能的sql訪問和豐富的多維訪問 cach 能夠加速網路應用程式的開發,尤其能提高事務處理速度和對事物資料的實時查詢。cach 的快速開發環境是構建各類應用的理想方法 cach 是可靠的,是在醫療衛生行業...

MySQL資料庫學習筆記(3)

mysql中的函式包括 字元函式 數值運算子與函式 比較運算子與函式 日期時間函式 資訊函式 聚合函式 加密函式等。1 字元函式 比如說,需要將姓和名一起輸出時 前導空格是指第乙個字元之前的空格,後續空格是指最後乙個字元之後的空格。注意 mysql中的字串編號從1開始。select substrin...

Flask學習筆記(3) 資料庫遷移

通過建立虛擬flask環境來遷移資料庫。mkvirtualenv flask tutorial python python3.6建立乙個名為flask tutorial的虛擬環境,如圖 可利用workon flask tutorial命令啟用這個虛擬環境。使用deactivate退出這個虛擬環境。在...