R
rickcasey
I modified a small subroutine in a larger Perl module that we are
attempting to port from a version that uses a commercial database
(Sybase) to an open source one (PostGres). One small modification has
resulted in this error message that I don't understand:
"Can't modify non-lvalue subroutine call at
lib/NHGRI/LDM/TableManager.pm line 1159."
1) does the message mean I cannot modify this subroutine at all?
2) or, hopefully, is there something wrong with my Perl syntax?
(judging from other group messages that also mention this error, I hope
it's the latter.)
TIA,
Rick
Here is what the code looks like around line 1159:
sub getQuotableFieldsHash {
my $self = shift;
my $dbh = $self->{dbc}->connect;
my $table = $self->{table};
my $db_type = $self->getDBD();
my %quotable = ();
my %quoted_types = ();
my $sql;
if ($db_type eq "Sybase") {
%quoted_types = (text => 1, varchar => 1, char => 1, datetime => 1);
$sql = qq!
SELECT c.name as Field,
t.name as Type
FROM sysobjects o, syscolumns c, systypes t
WHERE c.id = o.id
AND t.usertype = c.usertype
AND o.name = '$table'!;
} elsif ($db_type eq "Oracle") {
%quoted_types = (varchar2 => 1, nvarchar2 => 1, long => 1, char => 1,
nchar => 1, date => 1, clob => 1, nclob => 1);
$sql = qq!
SELECT column_name, data_type
FROM all_tab_columns
WHERE table_name = '$table'
!;
} elsif ($db_type eq "Pg") {
# (rc, 20Jan05)
# Here is where the SQL must get all columns in all tables from
PostGres system tables,
# Here, we make use of the convenient system view Columns in
information_schema.
%quoted_types = (varchar2 => 1, nvarchar2 => 1, long => 1, char => 1,
nchar => 1, date => 1, clob => 1, nclob => 1);
$sql = qq!
select column_name, data_type
from information_schema.columns
WHERE table_name = '$table'
!;
}
1159--> $dbh->errstr = $dbh->errstr . $sql;
my $ra_result = $dbh->selectall_arrayref($sql) or croak
$dbh->errstr;
foreach my $ra_row (@{$ra_result}) {
my $dtype = lc($ra_row->[1]);
my $field_name = $ra_row->[0];
$field_name = uc($field_name); #if ($db_type eq "Oracle");
$quotable{$field_name} = 1 if $quoted_types{$dtype};
}
return \%quotable;
attempting to port from a version that uses a commercial database
(Sybase) to an open source one (PostGres). One small modification has
resulted in this error message that I don't understand:
"Can't modify non-lvalue subroutine call at
lib/NHGRI/LDM/TableManager.pm line 1159."
1) does the message mean I cannot modify this subroutine at all?
2) or, hopefully, is there something wrong with my Perl syntax?
(judging from other group messages that also mention this error, I hope
it's the latter.)
TIA,
Rick
Here is what the code looks like around line 1159:
sub getQuotableFieldsHash {
my $self = shift;
my $dbh = $self->{dbc}->connect;
my $table = $self->{table};
my $db_type = $self->getDBD();
my %quotable = ();
my %quoted_types = ();
my $sql;
if ($db_type eq "Sybase") {
%quoted_types = (text => 1, varchar => 1, char => 1, datetime => 1);
$sql = qq!
SELECT c.name as Field,
t.name as Type
FROM sysobjects o, syscolumns c, systypes t
WHERE c.id = o.id
AND t.usertype = c.usertype
AND o.name = '$table'!;
} elsif ($db_type eq "Oracle") {
%quoted_types = (varchar2 => 1, nvarchar2 => 1, long => 1, char => 1,
nchar => 1, date => 1, clob => 1, nclob => 1);
$sql = qq!
SELECT column_name, data_type
FROM all_tab_columns
WHERE table_name = '$table'
!;
} elsif ($db_type eq "Pg") {
# (rc, 20Jan05)
# Here is where the SQL must get all columns in all tables from
PostGres system tables,
# Here, we make use of the convenient system view Columns in
information_schema.
%quoted_types = (varchar2 => 1, nvarchar2 => 1, long => 1, char => 1,
nchar => 1, date => 1, clob => 1, nclob => 1);
$sql = qq!
select column_name, data_type
from information_schema.columns
WHERE table_name = '$table'
!;
}
1159--> $dbh->errstr = $dbh->errstr . $sql;
my $ra_result = $dbh->selectall_arrayref($sql) or croak
$dbh->errstr;
foreach my $ra_row (@{$ra_result}) {
my $dtype = lc($ra_row->[1]);
my $field_name = $ra_row->[0];
$field_name = uc($field_name); #if ($db_type eq "Oracle");
$quotable{$field_name} = 1 if $quoted_types{$dtype};
}
return \%quotable;