游标和datastore的处理效率对比,datastore有明显优势。
datastore代码:
string ls_temp,ls_get,ls_empname
Long ll_rowcnt
time lt_1
int i
datastore ds_temp
ddlb_1.reset()
string ERRORS, sql_syntax
string presentation_str, dwsyntax_str
sql_syntax = "SELECT emp_name FROM EMPLOYEES "
presentation_str = "style(type=grid)"
dwsyntax_str = SQLCA.SyntaxFromSQL(sql_syntax, presentation_str, ERRORS)
IF Len(ERRORS) > 0 THEN
MessageBox("Caution", "SyntaxFromSQL caused these errors: " + ERRORS)
RETURN
END IF
ds_temp = Create datastore
ds_temp.Create( dwsyntax_str, ERRORS)
IF Len(ERRORS) > 0 THEN
MessageBox("Caution", "Create cause these errors: " + ERRORS)
RETURN
END IF
ds_temp.settransobject(sqlca)
ds_temp.retrieve()
ll_rowcnt = ds_temp.rowcount()
For i=1 To ll_rowcnt
ls_empname = ds_temp.object.emp_name[i]
ddlb_1.additem(ls_empname)
Next
另外,datastore还可以完成一些更复杂的逻辑,以及更*的数据读取,所以PB开发中是可以使用datastore替代游标的。