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.
This commit is contained in:
parent
350d7f6e01
commit
a9f45865e6
8 changed files with 78 additions and 29 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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|<p>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: </p>
|
||||
<p>LongReadLen=1024<br />
|
||||
LongTruncOk=1</p>
|
||||
|,
|
||||
lastUpdated => 1185397688,
|
||||
},
|
||||
|
||||
'preview' => {
|
||||
message => q|Preview|,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue