Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: database selecting then validating

by poj (Prior)
on May 24, 2012 at 19:39 UTC ( #972302=note: print w/replies, xml ) Need Help??


in reply to database selecting then validating

my $sql = 'select count(*) from users where empid=? and dept=?'; my ($count) = $dbh->selectrow_array($sql,undef,$empid,$dept); if ($count == 1){ # valid } else { # not valid }
poj

Replies are listed 'Best First'.
Re^2: database selecting then validating
by Anonymous Monk on May 25, 2012 at 11:33 UTC

    You could simplify that into (assuming a unique constraint on (empid, dept)):

    my $sql = 'select 1 from users where empid=? and dept=?'; if ($dbh->selectrow_array($sql, undef, $empid, $dept)) { # valid } else { # not valid }

    ...I'm always a bit wary of using Count(*) for exists-or-not-exists queries

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://972302]
help
Chatterbox?
Discipulus puts on AC hoping it goes better..
[Eily]: you should use DC instead, less variation
[Discipulus]: surprisingly i put ADCD in this precise moment!

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2017-06-26 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (577 votes). Check out past polls.