[interchange-cvs] interchange - heins modified 2 files
interchange-core@interchange.redhat.com
interchange-core@interchange.redhat.com
Wed Jul 3 14:33:01 2002
User: heins
Date: 2002-07-03 18:32:09 GMT
Modified: lib/Vend Interpolate.pm
Modified: lib/Vend/Table DBI.pm
Log:
* Allow DBI tables with one column
* Add method to return db handle from DBI types
* Add sql sequence counter capability to [counter ...] tag, will document.
Revision Changes Path
2.75 +54 -2 interchange/lib/Vend/Interpolate.pm
rev 2.75, prev_rev 2.74
Index: Interpolate.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /anon_cvs/repository/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.74
retrieving revision 2.75
diff -u -r2.74 -r2.75
--- Interpolate.pm 3 Jul 2002 15:01:59 -0000 2.74
+++ Interpolate.pm 3 Jul 2002 18:32:08 -0000 2.75
@@ -1,6 +1,6 @@
# Vend::Interpolate - Interpret Interchange tags
#=20
-# $Id: Interpolate.pm,v 2.74 2002/07/03 15:01:59 mheins Exp $
+# $Id: Interpolate.pm,v 2.75 2002/07/03 18:32:08 mheins Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
#
@@ -27,7 +27,7 @@
require Exporter;
@ISA =3D qw(Exporter);
=20
-$VERSION =3D substr(q$Revision: 2.74 $, 10);
+$VERSION =3D substr(q$Revision: 2.75 $, 10);
=20
@EXPORT =3D qw (
=20
@@ -2546,6 +2546,58 @@
my $file =3D shift || 'etc/counter';
my $opt =3D shift;
#::logDebug("counter: file=3D$file start=3D$opt->{start}");
+ if($opt->{sql}) {
+ my ($tab, $seq) =3D split /:+/, $opt->{sql}, 2;
+ my $db =3D database_exists_ref($tab);
+ my $dbh;
+ my $dsn;
+ if($opt->{bypass}) {
+ $dsn =3D $opt->{dsn} || $ENV{DBI_DSN};
+ $dbh =3D DBI->connect(
+ $dsn,
+ $opt->{user},
+ $opt->{pass},
+ $opt->{attr},
+ );
+ }
+ else {
+ $dbh =3D $db->dbh();
+ $dsn =3D $db->config('DSN');
+ }
+
+ my $val;
+
+ eval {
+ my $diemsg =3D errmsg(
+ "Counter sequence '%s' failed, using file.\n",
+ $opt->{sql},
+ );
+ if(! $dbh) {
+ die errmsg(
+ "No database handle for counter sequence '%s', using file.",
+ $opt->{sql},
+ );
+ }=20
+ elsif($dsn =3D~ /^dbi:mysql:/i) {
+ $dbh->do("INSERT INTO $tab VALUES (0)") or die $diemsg;
+ my $sth =3D $dbh->prepare("select LAST_INSERT_ID()")
+ or die $diemsg;
+ $sth->execute() or die $diemsg;
+ ($val) =3D $sth->fetchrow_array;
+ }
+ elsif($dsn =3D~ /^dbi:Pg:/i) {
+ my $sth =3D $dbh->prepare("select nextval('$seq')")
+ or die $diemsg;
+ $sth->execute()
+ or die $diemsg;
+ ($val) =3D $sth->fetchrow_array;
+ }
+
+ };
+
+ return $val if defined $val;
+ }
+
$file =3D $Vend::Cfg->{VendRoot} . "/$file"
unless Vend::Util::file_name_is_absolute($file);
my $ctr =3D new Vend::CounterFile $file, $opt->{start} || undef;
2.20 +9 -3 interchange/lib/Vend/Table/DBI.pm
rev 2.20, prev_rev 2.19
Index: DBI.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /anon_cvs/repository/interchange/lib/Vend/Table/DBI.pm,v
retrieving revision 2.19
retrieving revision 2.20
diff -u -r2.19 -r2.20
--- DBI.pm 28 Jun 2002 05:06:05 -0000 2.19
+++ DBI.pm 3 Jul 2002 18:32:08 -0000 2.20
@@ -1,6 +1,6 @@
# Vend::Table::DBI - Access a table stored in an DBI/DBD database
#
-# $Id: DBI.pm,v 2.19 2002/06/28 05:06:05 mheins Exp $
+# $Id: DBI.pm,v 2.20 2002/07/03 18:32:08 mheins Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
#
@@ -20,7 +20,7 @@
# MA 02111-1307 USA.
=20
package Vend::Table::DBI;
-$VERSION =3D substr(q$Revision: 2.19 $, 10);
+$VERSION =3D substr(q$Revision: 2.20 $, 10);
=20
use strict;
=20
@@ -597,7 +597,7 @@
=20
=20
die "DBI: no column names returned for $tablename\n"
- unless defined $config->{NAME}[1];
+ unless defined $config->{NAME}[0];
=20
# Check if we have a non-first-column key
if($config->{KEY}) {
@@ -638,6 +638,12 @@
return 1 if $Global::HotDBI->{$Vend::Cat};
undef $DBI_connect_cache{$cfg->{dsn_id}};
$s->[$DBI]->disconnect();
+}
+
+sub dbh {
+ my ($s) =3D shift;
+ $s =3D $s->import_db() if ! defined $s->[$DBI];
+ return $s->[$DBI];
}
=20
sub columns {