http://qs1969.pair.com?node_id=82375


in reply to Perl Access Database

You have at least two options:
1. You can edit the properties of your MS Access database in the design window. Fields can be designated to accept blank values. However, for referential integrity when relating to other tables, this is not an elegant solution.
2. The best solution is to test a field for an undefined value prior to inserting data into the table. Simply, insert a text value "NULL". Here is an example of code I wrote to prevent just such an occurence:

sub validate { $valid_data = 1; @parameters = qw/LASTNAME FIRSTNAME RANK BILLET EMAIL ERO UNIT DSN RUC NOMEN NSN SERNO COMPANY CONDITION DEFECT SHIP +MENT CORRECT COMMENTS/; @req_param = qw/LASTNAME FIRSTNAME RANK BILLET EMAIL ERO UNIT DSN RUC NOMEN NSN SERNO COMPANY/; foreach $response (@parameters) { print h3($response, " = ", uc(param($response))), hr; $CGI_hash{$response} = param($response); # remove punctuation( ' )which will crash the SQL $CGI_hash{$response} =~ s/'//g; # remove hyphens from numbers for consistency $CGI_hash{"NSN"} =~ s/-//g; # database demands non-blank values if ($CGI_hash{$response} eq "") { $CGI_hash{$response} = "NULL"; } $accumulator = $accumulator . uc($CGI_hash{$response}) . "','" +; } &parse_nulls; chop($accumulator); chop($accumulator); $NSN_len = length($CGI_hash{"NSN"}); if ($NSN_len != 13) { $valid_data = 0; } return;


I hope this helps you.

Replies are listed 'Best First'.
Re: Re: Perl Access Database
by Anonymous Monk on May 24, 2001 at 17:08 UTC
    It's beginning to look like I need to know more about Access Databases. BTW what is handling the file/recordlock when I'm using ODBC? Thanks for you help! Also is there a proper way to thank everyone who has posted solutions?