From f39c97fb5385856b4dfab2190c0281bb8cfdb7d8 Mon Sep 17 00:00:00 2001 From: Martin Kamerbeek Date: Fri, 5 Jan 2007 12:44:33 +0000 Subject: [PATCH] Fixed a dsn parsing bug in the sqlform --- docs/changelog/7.x.x.txt | 2 +- lib/WebGUI/Asset/Wobject/SQLForm.pm | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 2543174fd..f48c69dc1 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,5 +1,5 @@ 7.3.4 - + - fix: SQLForm - cannot add new asset (Martin Kamerbeek / Oqapi) 7.3.3 - fix: Wiki Purge throws fatal diff --git a/lib/WebGUI/Asset/Wobject/SQLForm.pm b/lib/WebGUI/Asset/Wobject/SQLForm.pm index c69874070..f892040bb 100644 --- a/lib/WebGUI/Asset/Wobject/SQLForm.pm +++ b/lib/WebGUI/Asset/Wobject/SQLForm.pm @@ -627,13 +627,32 @@ An instanciated databaselink object. Defaults to the databaselink of the sqlform =cut sub _databaseLinkHasPrivileges { - my (@privileges, @grants, $databaseName); + my (@privileges, @grants, $databaseName, @dsnEntries); my $self = shift; my $wantedPrivileges = shift; my $dbLink = shift || $self->_getDbLink; - ($databaseName = $dbLink->get->{DSN}) =~ s/^[^:]*:[^:]*:([^:]*)(:.*)?$/$1/; + # DSN can have a potpourri of forms + # DBI:mysql:dbName:dbHost:dbPort (databaseHost and dbPort are optional) + # DBI:mysql:database=dbName;host=dbHost (databaseHost is optional) + # But also this: + # DBI:mysql:db=dbName;dbHost:dbPort etc, etc. + # The following code tries to extract the databasename + @dsnEntries = split(/[:;]/, $dbLink->get->{DSN}); + if ($dsnEntries[2] !~ /=/) { + $databaseName = $dsnEntries[2]; + } else { + foreach (@dsnEntries) { + if ($_ =~ m/^(database|db|dbname)=(.+)$/) { + $databaseName = $2; + last; + } + } + } + + # Get all the grants for the db link user and fetch the one referring to the + # database of the db link. @grants = $dbLink->db->buildArray('show grants for current_user'); foreach (@grants) { @@ -642,6 +661,7 @@ sub _databaseLinkHasPrivileges { } } + # Check ik all required privs are present. return 1 if (isIn('ALL PRIVILEGES', @privileges)); foreach (@$wantedPrivileges) {