From a9f45865e625ec107efc8758373463f1116b94db Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 25 Jul 2007 23:46:20 +0000 Subject: [PATCH] Add optional database connection parameters to the DatabaseLink. This replaces the old, automatic setting of LongReadLen and LongTruncOk in SQL.pm, and is much more flexible. Fix some documentation with allowMacroAccess in the DatabaseLink. Additional tests for DatabaseLink. Document the new parameter behavior in the changelog and gotchas file. --- docs/changelog/7.x.x.txt | 2 ++ docs/gotcha.txt | 4 ++++ docs/upgrades/upgrade_7.3.22-7.4.0.pl | 11 +++++++---- lib/WebGUI/DatabaseLink.pm | 10 +++++++--- lib/WebGUI/Operation/DatabaseLink.pm | 15 ++++++++++++--- lib/WebGUI/SQL.pm | 23 +++++++++++++++-------- lib/WebGUI/i18n/English/WebGUI.pm | 26 ++++++++++++++++++++++---- t/DatabaseLink.t | 16 +++++++++------- 8 files changed, 78 insertions(+), 29 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index f4c2865fb..635c685c1 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -97,6 +97,8 @@ - Add user to transactions list and pending transactions. - fix: autolinking in wiki pages with manual links didn't work properly - fix: javascript errors in SQL Form date inputs in IE + - Added optional parameters for DatabaseLinks so that users can setup their + database's with things like LongReadLen, etc. 7.3.22 - fix: relative links sent out in emails don't work properly diff --git a/docs/gotcha.txt b/docs/gotcha.txt index 34e41f822..a3bbd3306 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -21,6 +21,10 @@ save you many hours of grief. the userProfileData table will need to be updated to reflect these changes. + * DatabaseLinks no longer automatically set LongReadLen and LongTruncOk + for Oracle or ODBC databases. These parameters, and others, can now + be set in the DatabaseLink. + * WebGUI now requires the following additional perl modules to operate, and you should install them prior to upgrading: diff --git a/docs/upgrades/upgrade_7.3.22-7.4.0.pl b/docs/upgrades/upgrade_7.3.22-7.4.0.pl index 90f3388c5..3e69036a5 100644 --- a/docs/upgrades/upgrade_7.3.22-7.4.0.pl +++ b/docs/upgrades/upgrade_7.3.22-7.4.0.pl @@ -33,18 +33,21 @@ addNewsletter($session); addHttpProxyUrlPatternFilter($session); addCanStartThreadToCS($session); addPostCaptchaToCS($session); -addMacroAccessToDatabaseLinks($session); +addFieldsToDatabaseLinks($session); finish($session); # this line required #------------------------------------------------- -sub addMacroAccessToDatabaseLinks { +sub addFieldsToDatabaseLinks { my $session = shift; - print "\tAdding allowMacroAccess setting to Database Links..." unless ($quiet); - + print "\tAdding new fields to Database Links...\n" unless ($quiet); + print "\t\tAdding allowMacroAccess setting to Database Links...\n" unless ($quiet); $session->db->write("ALTER TABLE databaseLink add column allowMacroAccess integer NOT NULL default 0"); + print "\t\tAdding additionalParameters setting to Database Links..." unless ($quiet); + $session->db->write("ALTER TABLE databaseLink add column additionalParameters VARCHAR(255) NOT NULL default ''"); + print "OK\n"; return; } diff --git a/lib/WebGUI/DatabaseLink.pm b/lib/WebGUI/DatabaseLink.pm index a3e796232..32ab90c1d 100644 --- a/lib/WebGUI/DatabaseLink.pm +++ b/lib/WebGUI/DatabaseLink.pm @@ -229,14 +229,17 @@ sub db { if (defined $self->{_dbh}) { return $self->{_dbh}; } - my $dsn = $self->{_databaseLink}{DSN}; - my $username = $self->{_databaseLink}{username}; + + my $dsn = $self->{_databaseLink}{DSN}; + my $username = $self->{_databaseLink}{username}; my $identifier = $self->{_databaseLink}{identifier}; + my $parameters = $self->{_databaseLink}{additionalParameters}; + if ($self->getId eq "0") { $self->{_dbh} = $self->session->db; return $self->{_dbh}; } elsif ($dsn =~ /\DBI\:\w+\:\w+/i) { - my $dbh = WebGUI::SQL->connect($self->session,$dsn,$username,$identifier); + my $dbh = WebGUI::SQL->connect($self->session,$dsn,$username,$identifier,$parameters); unless (defined $dbh) { $self->session->errorHandler->warn("Cannot connect to DatabaseLink [".$self->getId."]"); } @@ -331,6 +334,7 @@ sub new { title=>"WebGUI Database", allowedKeywords=>"select\ndescribe\ndesc\nshow\ncall", allowMacroAccess=>0, + additionalParameters=>'', ); } else { %databaseLink = $session->db->quickHash("select * from databaseLink where databaseLinkId=?",[$databaseLinkId]); diff --git a/lib/WebGUI/Operation/DatabaseLink.pm b/lib/WebGUI/Operation/DatabaseLink.pm index 91e1e22e6..0b0855853 100644 --- a/lib/WebGUI/Operation/DatabaseLink.pm +++ b/lib/WebGUI/Operation/DatabaseLink.pm @@ -193,12 +193,20 @@ sub www_editDatabaseLink { -hoverHelp => $i18n->get('allowed keywords description'), -value => $db{allowedKeywords}, ); - $f->yesNo( + $f->yesNo( -name => "allowMacroAccess", -label => $i18n->get('allow access from macros'), - -defaultValue=>0, + -hoverHelp => $i18n->get('allow access from macros help'), + -defaultValue=>0, -value => $db{allowMacroAccess}, ); + $f->textarea( + -name => "additionalParameters", + -label => $i18n->get('additional parameters'), + -hoverHelp => $i18n->get('additional parameters help'), + -defaultValue=>'', + -value => $db{additionalParameters}, + ); $f->submit; $output .= $f->print; return _submenu($session,$output,"990"); @@ -228,7 +236,8 @@ sub www_editDatabaseLinkSave { DSN=>$session->form->process("DSN"), allowedKeywords=>$allowedKeywords, allowMacroAccess=>$session->form->process("allowMacroAccess"), - }; + additionalParameters=>$session->form->process("additionalParameters"), + }; if ($session->form->process("dlid") eq "new") { WebGUI::DatabaseLink->create($session,$params); } else { diff --git a/lib/WebGUI/SQL.pm b/lib/WebGUI/SQL.pm index 263da3848..bd2ebd98b 100644 --- a/lib/WebGUI/SQL.pm +++ b/lib/WebGUI/SQL.pm @@ -312,20 +312,27 @@ The password to use to connect to the database defined by dsn. =cut sub connect { - my $class = shift; + my $class = shift; my $session = shift; - my $dsn = shift; - my $user = shift; - my $pass = shift; + my $dsn = shift; + my $user = shift; + my $pass = shift; + my $params = shift; + my $dbh = DBI->connect($dsn,$user,$pass,{RaiseError=>0,AutoCommit=>1 }); + unless (defined $dbh) { $session->errorHandler->error("Couldn't connect to database: $dsn"); return undef; } - if ( $dsn =~ /Oracle/ || $dsn =~ /ODBC/ ) { # Set specific attributes for long Oracle and ODBC DSNs - $dbh->{LongReadLen} = 512 * 1024; - $dbh->{LongTruncOk} = 1; - } + + ##Set specific attributes for this database. + my @params = split /\s*\n\s*/, $params; + foreach my $param ( @params ) { + my ($paramName, $paramValue) = split /\s*=\s*/, $param; + $dbh->{$paramName} = $paramValue; + } + bless {_dbh=>$dbh, _session=>$session}, $class; } diff --git a/lib/WebGUI/i18n/English/WebGUI.pm b/lib/WebGUI/i18n/English/WebGUI.pm index 86486a4dd..6b5d4abf0 100644 --- a/lib/WebGUI/i18n/English/WebGUI.pm +++ b/lib/WebGUI/i18n/English/WebGUI.pm @@ -3315,10 +3315,28 @@ a user.|, lastUpdated => 1165511447, }, - 'allow access from macros' => { - message => q|Allow access from Macro's|, - lastUpdated => 0, - }, + 'allow access from macros' => { + message => q|Allow access from Macro's|, + lastUpdated => 0, + }, + + 'allow access from macros help' => { + message => q|Are macros allowed to access this DatabaseLink?|, + lastUpdated => 1185397688, + }, + + 'additional parameters' => { + message => q|Additional database parameters|, + lastUpdated => 1185397688, + }, + + 'additional parameters help' => { + message => q|

Specify additional parameters for your database connection. Use 1 per line, and separate the name of the parameter from the value with an equal sign, like this:

+

LongReadLen=1024
+LongTruncOk=1

+|, + lastUpdated => 1185397688, + }, 'preview' => { message => q|Preview|, diff --git a/t/DatabaseLink.t b/t/DatabaseLink.t index 8cff754b5..c2545211c 100644 --- a/t/DatabaseLink.t +++ b/t/DatabaseLink.t @@ -147,6 +147,7 @@ cmp_deeply( title => undef, allowedKeywords => undef, allowMacroAccess => 0, + additionalParameters => '', }, 'create: passing no params autovivifies the databaseLinkId, but that is all', ); @@ -156,13 +157,14 @@ $dbLink->delete(); is(scalar keys %{WebGUI::DatabaseLink->getList($session)}, $startingDbLinks, 'new DatabaseLink deleted'); my $dbLinkParams = { - DSN => 'DBI:mysql:myDb:myHost', - username => 'dbUser', - identifier => 'dbPass', - title => 'Access to my Awesome DB', - allowedKeywords => 'SELECT UPDATE', - databaseLinkId => 'fooBarBaz', - allowMacroAccess => 0, + DSN => 'DBI:mysql:myDb:myHost', + username => 'dbUser', + identifier => 'dbPass', + title => 'Access to my Awesome DB', + allowedKeywords => 'SELECT UPDATE', + databaseLinkId => 'fooBarBaz', + allowMacroAccess => 0, + additionalParameters => '', }; $dbLink = WebGUI::DatabaseLink->create($session, $dbLinkParams);