如何在所有表和所有字段中搜索字符串? [英] How to search all tables and all fields for a string?

查看:83
本文介绍了如何在所有表和所有字段中搜索字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在数据库的所有表中的所有字段中搜索用户提供的值,并显示包含该输入关键字的记录.像这样:

I want to search all fields in all tables of a database for a user supplied value and display records which contain that input keyword. Something like this:

FOR EACH _file WHERE (NOT _file-name   BEGINS "_" AND NOT _file-name  BEGINS "sys") 
    NO-LOCK:

    FOR EACH _field OF _file  
        NO-LOCK:

        ASSIGN
            ttable = _file._file-name 
            tfield = _field._field-name .

        FOR EACH &ttable WHERE ttable.tfield MATCHES "urpon frisbee " 
            NO-LOCK :

            MESSAGE "hai"
                VIEW-AS ALERT-BOX INFO BUTTONS OK.
            DISPLAY _file._file-name .
        END.

    END.
END.

推荐答案

您想研究动态查询".

procedure x:

  define input parameter tbl as character no-undo.
  define input parameter fld as character no-undo.
  define input parameter xyz as character no-undo.

  define variable qh as handle no-undo.
  define variable bh as handle no-undo.
  define variable fh as handle no-undo.

  create buffer bh for table tbl.
  create query qh.
  qh:set-buffers( bh ).
  qh:query-prepare( "for each " + tbl ).
  qh:query-open.

  qh:get-first( no-lock ).
  do while qh:query-off-end = no:
    fh = bh:buffer-field( fld ).
    if fh:buffer-value = xyz then  /* needs special handing if there are array fields in the db ... */
      do:
        display tbl fld bh:recid fh:buffer-value.
        pause.
      end.
    qh:get-next( no-lock ).
  end.

  delete object bh.
  delete object qh.

  return.

end.

for each _file no-lock where not _hidden:

  for each _field no-lock of _file:

    if _data-type <> "character" then next.  /* skip non-char fields */

    run x ( _file-name, _field-name, "urpon frisbee" ).

  end.

end.

这篇关于如何在所有表和所有字段中搜索字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆