Useless use of a (constant|hash element) in void context?
Andrew Creer
ac at mail.market-research.com
Sun Oct 5 19:04:44 CDT 2003
On Mon, Oct 06, 2003 at 09:46:17AM +1000, Fox, Michael wrote:
>
> 1) You seem to have () instead of {} in your anonymous hash constructor
>
> 2) Have you tried the primary key method as in
> @key_column_names = $dbh->primary_key( $catalog, $schema, $table );
> It works for me for Oracle, don't know about MySQL
For MySQL the DBI methods
$sth->{NAME}
$sth->{TYPE}
$sth->{PRECISION}
$sth->{SCALE}
$sth->{NULLABLE}
all return arrays of relavent data after you have done a
$sth->execute()
Using these will make your code more portable.
>
> Michael Fox
>
> -----Original Message-----
> From: ADFH [mailto:mpm at bachelorguy.com]
> Sent: Sunday, 5 October 2003 3:38 PM
> To: melbourne-pm at pm.org
> Cc: mpm at bachelorguy.com
> Subject: Useless use of a (constant|hash element) in void context?
>
>
> Basically I'm writing a generic "insert/update" function into my program
> that goes and checks the table it's inserting data into for prompts as
> to what kind of sanity checking it should do on the data, whether what
> it thinks is the primary key is indeed the primary key, whether it
> should insert or update etc. etc. etc.
>
> To do this, I'm getting MySQL to give me output of SHOW COLUMNS on the
> specific table, then wanting to store this in a hash. I then plan to
> parse the data received from the end user's browser, to see if it's the
> correct type, within range etc. etc. then quote/escape it appropriately.
>
> The function is being used for several tables with varying numbers of
> columns and data types. I don't forsee the script being placed under a
> lot of load and at this point I don't want to duplicate similar code
> with only slight alterations to check each table.
>
> Is there something I should use that already does this? Is my thinking
> flawed? Am I reinventing the wheel in regards to some DBI/DBD function I
> haven't found?
>
> Anyway, a bit of the code I'm working on gives me an error I've not seen
> before. In this particular script I'm writing, I've been getting a
> little more adventurous with references and functions etc. etc. and am a
> bit out of my depth I think (I did some netizen courses years ago, and
> have been using their doco, the camel book, cpan and the perl man pages
> since).
>
> What am I doing wrong here? I'm thinking I've just borked up some
> bracket types somewhere.
>
> my $statement= "SHOW COLUMNS FROM ${table_names{$table}}";
> my $sth=$dbh->prepare($statement);
> $sth->execute();
> my (%dbct, $dbr_ref);
> while ($dbr_ref=$sth->fetchrow_hashref("NAME_lc")) {
> $dbct{$dbr_ref->{'field'}}=(
> type => $dbr_ref->{'type'},
> key => $dbr_ref->{'key'},
> blank => $dbr_ref->{'null'}
> ); # Line 152
> }
> $sth->finish();
>
> Gives warnings:
>
> [Sun Oct 5 15:22:29 2003] index.cgi: Useless use of a constant in void
> context at index.cgi line 152.
> [Sun Oct 5 15:22:29 2003] index.cgi: Useless use of hash element in void
> context at index.cgi line 152.
> [Sun Oct 5 15:22:29 2003] index.cgi: Useless use of a constant in void
> context at index.cgi line 152.
> [Sun Oct 5 15:22:29 2003] index.cgi: Useless use of hash element in void
> context at index.cgi line 152.
> [Sun Oct 5 15:22:29 2003] index.cgi: Useless use of a constant in void
> context at index.cgi line 152.
>
> Using:
>
> MySQL 4.0.14
> Perl v5.8.1 built for i386-linux-thread-multi
>
>
>
> Australia Post is committed to providing our customers with excellent service. If we can assist you in any way please either telephone 13 13 18 or visit our website www.auspost.com.au.
>
> CAUTION
>
> This e-mail and any files transmitted with it are privileged and confidential information intended for the use of the addressee. The confidentiality and/or privilege in this e-mail is not waived, lost or destroyed if it has been transmitted to you in error. If you have received this e-mail in error you must (a) not disseminate, copy or take any action in reliance on it; (b) please notify Australia Post immediately by return e-mail to the sender; and (c) please delete the original e-mail.
--
Andrew Creer Phone + 61 3 9689 5299
Systems Developer Fax + 61 3 9689 5399
Horizon Research Corporation US Toll Free 1877 342 0928
More information about the Melbourne-pm
mailing list