TomBascom
Curmudgeon
This morning a customer asked for a way to scan a (smallish) database for any occurrences of a certain string. He was not terribly inclined to write a program for each table and was hoping for a simple utility.
So I cobbled this together:
So I cobbled this together:
Code:
/* scan.p
*
*/
define variable tbl as character no-undo.
define variable q as handle no-undo. /* query */
define variable b as handle no-undo. /* buffer */
define variable f as handle no-undo. /* field */
define variable t as character no-undo.
define variable i as integer no-undo.
define variable j as integer no-undo.
define variable k as integer no-undo.
update t label "target" with side-labels.
create query q.
for each _file no-lock where _tbl-type = "t":
display _file-name.
create buffer b for table _file-name.
q:set-buffers( b ).
q:query-prepare( "for each " + _file-name + " no-lock" ).
q:query-open.
q:get-next( no-lock ).
do while q:query-off-end = false:
do i = 1 to b:num-fields:
f = b:buffer-field( i ).
if f:data-type = "character" and f:buffer-value() matches t then
do:
display
b:recid format ">>>>>>>>>>>9" label "recid"
_file-name format "x(20)" label "table"
f:name format "x(20)" label "field name"
f:buffer-value format "x(30)" label "value"
.
down 1.
end.
end.
q:get-next( no-lock ).
end.
delete object b.
end.