[interchange-cvs] interchange - jon modified lib/Vend/Interpolate.pm
interchange-cvs at icdevgroup.org
interchange-cvs at icdevgroup.org
Sat Nov 17 18:30:34 EST 2007
User: jon
Date: 2007-11-17 23:30:33 GMT
Modified: lib/Vend Interpolate.pm
Log:
Add option to use a custom SQL function as a counter.
This allows something other than a plain database sequence to be used to
replace counter files, for example to allow character prefixes or suffixes
with sequences, or to avoid writing files locally when in a cluster
environment.
For example, if you create a function called "custom_counter" in PostgreSQL,
you would set up catalog.cfg like this:
UserDB default sql_counter "userdb:custom_counter('userdb_username_seq')"
Route default sql_counter "transactions:custom_counter('order_number_seq')"
And whatever the custom_counter function returns will be used by Interchange.
Revision Changes Path
2.292 +9 -2 interchange/lib/Vend/Interpolate.pm
rev 2.292, prev_rev 2.291
Index: Interpolate.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.291
retrieving revision 2.292
diff -u -u -r2.291 -r2.292
--- Interpolate.pm 15 Nov 2007 00:29:39 -0000 2.291
+++ Interpolate.pm 17 Nov 2007 23:30:33 -0000 2.292
@@ -1,6 +1,6 @@
# Vend::Interpolate - Interpret Interchange tags
#
-# $Id: Interpolate.pm,v 2.291 2007/11/15 00:29:39 jon Exp $
+# $Id: Interpolate.pm,v 2.292 2007/11/17 23:30:33 jon Exp $
#
# Copyright (C) 2002-2007 Interchange Development Group
# Copyright (C) 1996-2002 Red Hat, Inc.
@@ -28,7 +28,7 @@
require Exporter;
@ISA = qw(Exporter);
-$VERSION = substr(q$Revision: 2.291 $, 10);
+$VERSION = substr(q$Revision: 2.292 $, 10);
@EXPORT = qw (
@@ -2162,6 +2162,13 @@
$opt->{sql},
);
}
+ elsif($seq =~ /\(/) {
+#::logDebug("found custom SQL function for sequence: $seq");
+ my $sql = "SELECT $seq";
+ my $sth = $dbh->prepare($sql) or die $diemsg;
+ $sth->execute or die $diemsg;
+ ($val) = $sth->fetchrow_array;
+ }
elsif($dsn =~ /^dbi:mysql:/i) {
$seq ||= $tab;
$dbh->do("INSERT INTO $seq VALUES (0)") or die $diemsg;
More information about the interchange-cvs
mailing list