Thread DBI TRUE - FALSE - UNKNOWN (15 answers)
Opened by Gast at 2009-12-26 11:03

Gast Gast
 2009-12-26 11:03
#129709 #129709
Hi,

ich habe eine Frage zum letzten Kapitel dieser Anleitung:
Introduction to retrieving data from your database
"Handling NULL data"

Warum wird in meinem Skript in der dritte Ausgabe ( where col1 <> Y ) alles außer 'Y' ausgegeben, warum gibt es keinen UNKNOWN Status?

Code (perl): (dl )
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
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl
use 5.010;
use warnings;
use strict;
use DBI;

my $table = 'null_value_table';


open my $fh, '>', $table or die $!;
while ( my $row = <DATA> ) {
    print $fh $row;
}
close $fh or die $!;



my $dbh = DBI->connect( "DBI:CSV:" );
my $sth;


say "\nselect all\n";
$sth = $dbh->prepare( "SELECT * FROM $table" );
$sth->execute();
while ( my @row = $sth->fetchrow_array ) {
    say "@row";
}


say "\n\n\nselect where col1 = Y\n";
$sth = $dbh->prepare( "SELECT * FROM $table WHERE col1 = 'Y'" );
$sth->execute();
while ( my @row = $sth->fetchrow_array ) {
    say "@row";
}


say "\n\n\nselect where col1 <> Y\n";
$sth = $dbh->prepare( "SELECT * FROM $table WHERE col1 <> 'Y'" );
$sth->execute();
while ( my @row = $sth->fetchrow_array ) {
    say "@row";
}


$dbh->disconnect;

__DATA__
col0,col1
1,Y
2,N
3,NULL
4,undef
5,0
6,''
7,



Modedit GwenDragon: Link repariert

Last edited: 2009-12-26 16:20:06 +0100 (CET)

View full thread DBI TRUE - FALSE - UNKNOWN