File: bind.pl

package info (click to toggle)
libdbd-oracle-perl 1.83-3
  • links: PTS, VCS
  • area: contrib
  • in suites: sid
  • size: 1,724 kB
  • sloc: ansic: 8,354; perl: 7,868; makefile: 20
file content (45 lines) | stat: -rwxr-xr-x 1,060 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env perl
#
# bind.pl
#
# This shows how a placeholder may be used to implement a simple lookup.

use DBI;

use strict;

# Set trace level if '-# trace_level' option is given
DBI->trace( shift ) if 1 < @ARGV && $ARGV[0] =~ /^-#/ && shift;

die "syntax: $0 [-# trace] base user pass" if 3 > @ARGV;
my ( $inst, $user, $pass ) = @ARGV;

# Connect to database
my $dbh = DBI->connect( "dbi:Oracle:$inst", $user, $pass,
    { AutoCommit => 0, RaiseError => 1, PrintError => 0 } )
    or die $DBI::errstr;

# Prepare the SELECT statement using a placeholder
my $sth = $dbh->prepare( 'SELECT created FROM all_users WHERE username = ?' );

my ( $created );
$| = 1;
print "Enter an empty line to finish\n";
print "Userid? ";
while ( <STDIN> ) {
    chomp;
    last if ! $_;
    $sth->execute( uc( $_ ) );

    # Note that the variable is in parentheses to force array context
    if ( ( $created ) = $sth->fetchrow_array ) {
        print "$created\n";
    }
    else {
        print "unknown\n";
    }
    print "Userid? ";
}

$sth->finish;
$dbh->disconnect;