Gossamer Forum
Home : Products : DBMan : Customization :

Searching for Empty Fields

Quote Reply
Searching for Empty Fields
I need to search for records in which a particular field is empty. In my database there is no empty field "default" value, that is an empty field just looks like "| |" (2 contiguous field separators).

I have tried doing a regular expression search using //, but I get an error.

Any ideas?

Sincerely,
Lauren Stegman

Quote Reply
Re: Searching for Empty Fields In reply to
I don't know how to search for an empty field, Lauren. Sorry.



------------------
JPD







[This message has been edited by JPDeni (edited June 12, 1999).]
Quote Reply
Re: Searching for Empty Fields In reply to
JPDenni,

I have been able to find records with empty fields in an external script I use to generate metadata on my database. Here is the relevant part of the code:

Code:
$count = 0;
open (DB, '/default.db') or die "Nope: $!";
while (<DB> ) {
next if /^\s*$/;
next if /^#/;
next if /^guest/;
chomp;
@data = split (/\|/, $_, $#db_cols);
@dates = ($data[9], $data[10], $data[14], $data[18]);

if ($data[14] and $data[18]) {;}
else { print "Dates: @dates\n";
$count++;
}

}
close DB;

This code opens the database and puts the data from fields 9, 10, 14, and 18 in an array. Then if data exists in 14 and 18 it does nothing. If there is no data in 14 and 18 it prints out the array. Obviously I could do this better with a not statement, but I just wanted to show you my idea.

Can I implement someting similar to this into the sub query routine of db.cgi?

I thought about making a character like a tilde represent a blank field search. Then if one enters a tilde into a search field form a subroutine would run similar to the one I described above.

Can you offer any more help?

Thanks,
Lauren
Quote Reply
Re: Searching for Empty Fields In reply to
I see what you're doing, but I don't know how it would coordinate with the current search routine.

This is something that Alex will need to answer. I don't know enough about how the search routine works to be able to edit it very much.


------------------
JPD





Quote Reply
Re: Searching for Empty Fields In reply to
Just to let anyone following the thread know, I came accross a simple solution.

To find records with a particular field blank, simple do a "regular expression" query using the expression:

^\s*$

My original problem is that I was using the expression /^\s*$/ like you would in PERL and as the db.cgi script does in the validate_record subroutine to check for missing fields and see if they are allowed to be left blank.

Sincerely,

Lauren Stegman
Quote Reply
Re: Searching for Empty Fields In reply to
Superb! Thank you, Lauren. It's things like this that make it all worthwhile. Smile



------------------
JPD