f_getfromtable.srf 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. $PBExportHeader$f_getfromtable.srf
  2. $PBExportComments$从后台表中取数函数--自定义函数
  3. global type f_getfromtable from function_object
  4. end type
  5. forward prototypes
  6. global function string f_getfromtable (string table_get, string column_get, string cond_get, integer record_get)
  7. end prototypes
  8. global function string f_getfromtable (string table_get, string column_get, string cond_get, integer record_get);//column_get=字段英文名,cond_get=取数定位条件
  9. transaction t_report
  10. int li
  11. string ls_sql,ls_return
  12. if isvalid(w_rpt_edit) then
  13. t_report=w_rpt_edit.it_report
  14. elseif isvalid(w_rpt_preview) then//为了加快速度
  15. //t_report=w_rpt_preview.it_report
  16. else
  17. t_report=sqlca
  18. end if
  19. ls_sql="select "+column_get+" from "+table_get
  20. if trim(cond_get)>'' then ls_sql=ls_sql+" where "+cond_get
  21. prepare sqlsa from :ls_sql using t_report;
  22. describe sqlsa into sqlda;
  23. declare my_cursor dynamic cursor for sqlsa;
  24. open dynamic my_cursor using descriptor sqlda;
  25. for li=1 to record_get
  26. fetch my_cursor using descriptor sqlda;
  27. next
  28. if sqlda.numoutputs>0 then
  29. choose case sqlda.outparmtype[1]
  30. case TypeString!
  31. if t_report.sqlcode=0 then ls_return=GetDynamicString(sqlda,1)
  32. case TypeDate!
  33. if t_report.sqlcode=0 then ls_return=string(GetDynamicDate(sqlda,1),'yyyy/mm/dd')
  34. case TypeDateTime!
  35. if t_report.sqlcode=0 then ls_return=string(GetDynamicDatetime(sqlda,1))
  36. case TypeDecimal!,TypeDouble!,TypeInteger!,TypeLong!,TypeReal!
  37. if t_report.sqlcode=0 then ls_return=string(GetDynamicNumber(sqlda,1))
  38. case TypeTime!
  39. if t_report.sqlcode=0 then ls_return=string(GetDynamicTime(sqlda,1))
  40. end choose
  41. else
  42. ls_return='后台取数出错'
  43. end if
  44. close my_cursor;
  45. return ls_return
  46. end function