Gossamer Forum
Home : Products : DBMan : Customization :

Solution for mismatched number of fields in database and database cfg file

Quote Reply
Solution for mismatched number of fields in database and database cfg file
The common suggestion to prevent your search results has been to simply seed your database with spare fields and use them up as more are needed. What I've done is to add a few lines of code that will silently pad the correct number of fields into your search results. No more barber poling around!

in db.cgi sub query after

$line = $_; chomp ($line); # Remove trailing new line.
@values = &split_decode($line);

add the following:

# Here we test to see if the table definition has more fields than the database line we are reading.
# If a field is added to the table def and there is a discrepency, we will correct the count line
# line by line. Otherwise the reported results would "barber pole" around when the search results are rendered.
while ($#values < $#db_cols) {
push (@values,"");
}

#
# if we have more fields in the table than in the table spec, we need to fail the search and complain.
if ($#values > $#db_cols) {
return ("Table has more fields than the table definition. Contact the system administrator to resolve this issue. Record $values[$db_key_pos]");
}


That's it. If you have more fields than in the cfg file, it will fail the search and provide an error message. If you have recently added a field to the cfg file, and records with too few fields will be simply absorbed.

Wes