… | |
… | |
7 | |
7 | |
8 | =cut |
8 | =cut |
9 | |
9 | |
10 | BEGIN { |
10 | BEGIN { |
11 | $VERSION = 0.1; |
11 | $VERSION = 0.1; |
12 | require XSLoader; |
12 | use XSLoader; |
13 | XSLoader::load __PACKAGE__, $VERSION; |
13 | XSLoader::load __PACKAGE__, $VERSION; |
14 | } |
14 | } |
15 | |
15 | |
16 | sub new { |
16 | sub new { |
17 | my ($class, $dsn, $user, $pass) = @_; |
17 | my ($class, $dsn, $user, $pass) = @_; |
… | |
… | |
46 | [ 3 => "zusatz1"], |
46 | [ 3 => "zusatz1"], |
47 | [ 4 => "zusatz2"], |
47 | [ 4 => "zusatz2"], |
48 | [ 5 => "zusatz3"], |
48 | [ 5 => "zusatz3"], |
49 | [ 6 => "vorwahl"], |
49 | [ 6 => "vorwahl"], |
50 | [ 7 => "strasse"], |
50 | [ 7 => "strasse"], |
51 | [ 8 => "haus"], |
51 | [ 8 => "hausnr"], |
52 | [ 9 => "plz"], |
52 | [ 9 => "plz"], |
53 | [10 => "ort"], |
53 | [10 => "ort"], |
54 | [11 => "branche"], |
54 | [11 => "branche"], |
55 | ); |
55 | ); |
56 | |
56 | |
… | |
… | |
64 | |
64 | |
65 | while (@pred) { |
65 | while (@pred) { |
66 | my ($column, $type, $match) = splice @pred, 0, 3, (); |
66 | my ($column, $type, $match) = splice @pred, 0, 3, (); |
67 | $select .= " and "; |
67 | $select .= " and "; |
68 | if ($column eq "nummer") { |
68 | if ($column eq "nummer") { |
69 | $select .= "($column between ? and ?)"; |
|
|
70 | if ($type eq "exact") { |
69 | if ($type eq "exact") { |
|
|
70 | $select .= "$column = ?"; |
|
|
71 | push @args, nummer2str $match, 10; |
|
|
72 | } elsif ($type eq "prefix") { |
|
|
73 | $select .= "($column between ? and ?)"; |
71 | push @args, |
74 | push @args, |
72 | (pack "H*", (substr "${match}000000000000", 0, 12) . sprintf "%x0", 12 - length $match), |
75 | (nummer2str $match), |
73 | (pack "H*", (substr "${match}000000000000", 0, 12) . sprintf "%xf", 12 - length $match); |
76 | (nummer2str $match, 10); |
74 | } elsif ($type eq "prefix") { |
|
|
75 | push @args, |
|
|
76 | (pack "H*", (substr "${match}00000000000000", 0, 14)), |
|
|
77 | (pack "H*", (substr "${match}a0000000000000", 0, 14)); |
|
|
78 | } else { |
77 | } else { |
79 | croak "illegal search type '$type', must be one of exact, prefix"; |
78 | croak "illegal search type '$type', must be one of exact, prefix"; |
80 | } |
79 | } |
81 | } else { |
80 | } else { |
82 | push @args, $match; |
81 | push @args, $match; |
… | |
… | |
95 | croak "illegal search type '$type', must be one of exact, like, regexp or match"; |
94 | croak "illegal search type '$type', must be one of exact, like, regexp or match"; |
96 | } |
95 | } |
97 | } |
96 | } |
98 | } |
97 | } |
99 | |
98 | |
|
|
99 | warn $select, @args; |
100 | my $st = sql_exec $self->{dbh}, $select, @args |
100 | my $st = sql_exec $self->{dbh}, $select, @args |
101 | or die "sql_exec returned no statement handle"; |
101 | or die "sql_exec returned no statement handle"; |
102 | |
102 | |
103 | return bless { |
103 | return bless { |
104 | dinfo => $self, |
104 | dinfo => $self, |