f_rpt_cksql.srf 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. $PBExportHeader$f_rpt_cksql.srf
  2. $PBExportComments$分解SQL语句--函数
  3. global type f_rpt_cksql from function_object
  4. end type
  5. forward prototypes
  6. global subroutine f_rpt_cksql (string fsql, ref string ffield, ref string ffrom, ref string fwhere, ref string fgroup, ref string fsort)
  7. end prototypes
  8. global subroutine f_rpt_cksql (string fsql, ref string ffield, ref string ffrom, ref string fwhere, ref string fgroup, ref string fsort);string ls_sql//select ... from ... where ... group by ... order by ...
  9. int l[6]
  10. fsql=trim(fsql)
  11. ls_sql=lower(fsql)
  12. ls_sql=f_replace(ls_sql,'~n',' ')
  13. l[1]=pos(ls_sql,' from ')
  14. l[2]=pos(ls_sql,' where ')
  15. l[3]=pos(ls_sql,' group by ')
  16. l[4]=pos(ls_sql,' order by ')
  17. l[5]=len(ls_sql)
  18. ffield=trim(mid(fsql,8,l[1] -8))
  19. l[6]=l[5]+1
  20. if l[2]>0 then l[6]=min(l[6],l[2])
  21. if l[3]>0 then l[6]=min(l[6],l[3])
  22. if l[4]>0 then l[6]=min(l[6],l[4])
  23. ffrom=trim(mid(fsql,l[1]+6,l[6] -(l[1]+6)))
  24. if l[2]>0 then
  25. l[6]=l[5]+1
  26. if l[3]>0 then l[6]=min(l[6],l[3])
  27. if l[4]>0 then l[6]=min(l[6],l[4])
  28. fwhere=trim(mid(fsql,l[2]+7,l[6] -(l[2]+7)))
  29. else
  30. fwhere=''
  31. end if
  32. if l[3]>0 then
  33. l[6]=l[5]+1
  34. if l[4]>0 then l[6]=min(l[6],l[4])
  35. fgroup=trim(mid(fsql,l[3]+10,l[6] -(l[3]+10)))
  36. else
  37. fgroup=''
  38. end if
  39. if l[4]>0 then
  40. l[6]=l[5]+1
  41. fsort=trim(mid(fsql,l[4]+10,l[6] -(l[4]+10)))
  42. else
  43. fsort=''
  44. end if
  45. end subroutine