| Revision: | 1.1 |
| Committed: | Mon Feb 5 14:08:22 2001 UTC (25 years, 3 months ago) by root |
| Branch: | MAIN |
| CVS Tags: | DEVEL9916, BEFORE_5_8_REGEX_FIX, kis-loewenstein, PAPP_0_12, papp_last_stable, Klinik_Kis_25032002_2245, kis-loewenstein-2002-10-07_0200, rel-1_0, DEVEL7952, rel-2_0, DEVEL9021, rel-1_02, rel-1_03, klinik-loewenstein, pre_big_pcode_semantic_change, rel-1_04, rel-1_05, rel-2_001, rel-2_002, klinik-loewenstein-05052002, HEAD |
| Log Message: | *** empty log message *** |
| # | Content |
|---|---|
| 1 | # this is of historical interest at best ;) well, actually the |
| 2 | # calls to fancydie are quite nice... |
| 3 | |
| 4 | my %_sql_st; |
| 5 | |
| 6 | sub sql_exec($;@) { |
| 7 | my $statement = shift; |
| 8 | my $st = $_sql_st{$statement}; |
| 9 | unless($st) { |
| 10 | $st = $db->prepare($statement) or fancydie "unable to prepare statement", $statement; |
| 11 | $_sql_st{$statement} = $st; |
| 12 | } |
| 13 | if (ref $_[0]) { |
| 14 | my $bind = shift; |
| 15 | $sql_exec = $st->execute(@_) or fancydie $db->errstr, "Unable to execute statement `$statement` with ".join(":",@_); |
| 16 | $st->bind_columns(@$bind) or fancydie $db->errstr, "Unable to bind_columns to statement `$statement` with ".join(":",@_); |
| 17 | } else { |
| 18 | $sql_exec = $st->execute(@_) or fancydie $db->errstr, "Unable to execute statement `$statement` with ".join(":",@_); |
| 19 | } |
| 20 | $st; |
| 21 | } |
| 22 | |
| 23 | sub sql_fetch { |
| 24 | my $r = &sql_exec->fetchrow_arrayref; |
| 25 | $r ? wantarray ? @{$r} |
| 26 | : $r->[0] |
| 27 | : (); |
| 28 | } |
| 29 | |
| 30 | sub sql_fetchall { |
| 31 | my $r = &sql_exec->fetchall_arrayref; |
| 32 | ref $r && @$r ? @{$r->[0]}==1 ? map @$_,@$r |
| 33 | : @$r |
| 34 | : (); |
| 35 | } |
| 36 | |
| 37 | sub sql_exists($;@) { |
| 38 | my $select = shift; |
| 39 | my @args = @_; |
| 40 | $select = "select count(*) > 0 from $select limit 1"; |
| 41 | @_ = ($select, @_); |
| 42 | goto &sql_fetch; |
| 43 | } |
| 44 |