?? powerbuilder 使用數據存儲代替游標.txt
字號:
PowerBuilder 使用數據存儲代替游標
Datastore 是 PwerBuilder中不可視的數據窗口控制。與數據窗口相比除了視覺以外其他各個方面都極其相似。
由于datastore具有對數據的交互操作,所以用它來代替在程序中經常使用的游標Cursors. 使用datastore檢索數據比游標的速度快,并對數據的分組變得容易,提高比較高級的過濾功能,在程序中不需要變量也可以訪問數據,并且在PB中使編碼變得相對簡單。
使用datastore對數據也有缺點:
使用datastore時候必須有檢索對應數據的數據窗口對象;
你使用后必須及時的釋放datastore占用的內存空間,一面產生內存空洞;
下面舉個簡單的例子說明如何人在程序中使用游標和datastore進行查詢數據,它們具有一曲同工之效:
1,下面是采用游標的方式取得可戶信息的事例程序;
String ls_cust_code,ls_customer_name,ls_address
DECLARE lc_my_cursor CURSOR FOR
SELECT customers.cust_id,customers.cust_name,customers.cust_address
FROM customers ORDER BY cust_code;
OPEN lc_my_cursor;
FETCH lc_my_cursor INTO :ls_cust_code,:ls_customer_name,ls_address;
DO WHILE SQLCA.SQLCODE = 0
FETCH lc_my_cursor INTO :ls_cust_code,:ls_customer_name,:ls_address;
LOOP
CLOSE lc_my_cursor
2,采用Datastore實現上面同樣的功能:
String ls_cust_code,ls_customer_name,ls_address
long ll_row,ll_row_count
datastore lds_dstastore
lds_datastore = CREATE datastore
lds_datastore.datao b j e c t = "d_customers"
lds_datastore.settranso b j e c t(sqlca)
lds_datastore.retrieve()
ll_row_count = lds_datastore.rowcount()
FOR ll_row = 1 to ll_row_count
ls_cust_code = lds_datastore.getitemstring(ll_row,"cust_id")
ls_cust_code = lds_datastore.getitemstring(ll_row,"cust_name")
ls_cust_code = lds_datastore.getitemstring(ll_row,"cust_address")
NEXT
DESTROY lds_datastore
說明:上面的數據窗口對象包括數據庫中Customers表中的cust_id,cust_name,cust_address
列。以上是游標和datastore的轉換,請廣大網友借鑒。
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -