perl sybase connection error on x86pc-solaris - perl

I have a Solaris system with x86 CPU, when I try to connect to sybase db with perl, i got the following error(the error was generated when I run the script in debug mode and step into function DBD::Sybase::db::_login at Sybase.pm in line 94)
ct_con_props(CS_PASSWORD) failed at /usr/local/lib/perl5/site_perl/5.8.8/i86pc-solaris/DBD/Sybase.pm line 94.
at /usr/local/lib/perl5/site_perl/5.8.8/i86pc-solaris/DBD/Sybase.pm line 94
DBD::Sybase::dr::connect('DBI::dr=HASH(0x8613a5c)', 'server=server1', 'user1, 'password1', 'HASH(0x86b4e5c)') called at /usr/local/lib/perl5/site_perl/5.8.8/i86pc-solaris/DBI.pm line 617
DBI::_ANON_/usr/local/lib/perl5/site_perl/5.8.8/i86pc-solaris/DBI.pm:679 called at /usr/local/lib/perl5/site_perl/5.8.8/i86pc-solaris/DBI.pm line 681
DBI::connect('DBI', 'DBI:Sybase:server=server1', 'user1, 'password1') called at ./test.pl line 28
DBI::CODE(0x83fcdd4)(/usr/local/lib/perl5/site_perl/5.8.8/i86pc-solaris/DBI.pm:618):
618: $user = '' if !defined $user;
from the message, it seems there is something wrong with the password? but I am sure the password was correct and the same code works very well on a Spark-solaris system, could anyone tell me what's wrong, or tell me how can I get into the function DBD::Sybase::db::_login($this, $server, $user, $auth, $attr)? looks like this function was in an .xs file, but I can not find where is it, and can not debug into it.
if I run the script withtout debug, i got the following error
ct_con_props(CS_PASSWORD) failed at /usr/local/lib/perl5/site_perl/5.8.8/i86pc-solaris/DBD/Sybase.pm line 94.
DBI connect('server=server1','user1’,...) failed: OpenClient message: LAYER = (1) ORIGIN = (4) SEVERITY = (6) NUMBER = (221)
Server server1, database
Message String: ct__string_extended_encryption: user api layer: internal common library error: error string not available
at ./test.pl line 28
Connect failed at ./test.pl line 28.
here is the code of sub connect in Sybase.pm
sub connect {
my($drh, $dbase, $user, $auth, $attr) = #_;
my $ifile = '';
my $server = $dbase || $ENV{DSQUERY} || 'SYBASE';
my($this) = DBI::_new_dbh($drh, {
'Name' => $server,
'Username' => $user,
'CURRENT_USER' => $user,
});
DBD::Sybase::db::_login($this, $server, $user, $auth, $attr)
or return undef;
return $this;
}

After sending a email to Michael Peppler(the module writer), I got the following answer and the issue was fixed.
The issue is the lib3p directory, which contains libraries that are loaded at run time directly by OpenClient, in particular for things like password encryption, etc.
This directory obviously needs to be in LD_LIBRARY_PATH, or be referenced in the default library search paths.
So basically, I need to add the path of OCS-15 folder to LD_LIBRARY_PATH

Related

Sybase Warning messages from perl DBI

I am connecting to sybase 12 from a perl script and calling storedprocs, I get the following warnings
DBD::Sybase::db prepare failed: Server message number=2401 severity=11 state=2 line=0 server=SERVER_NAME text=Character
set conversion is not available between client character set 'utf8' and server character set 'iso_1'.
Server message number=2411 severity=10 state=1 line=0 server=SERVER_NAME text=No conversions will be done.
at line 210.
Now, I understand these are only warnings, and my process works perfectly fine, but I am calling my stored proc in a loop and throughout the day and hence it creates a lot of warning message in my log files which causes the entire process to run a bit slower than expected. Can someone help me how can i suppress these please?
You can use a callback to handle the messages you want ignored. See the DBD::Sybase docs. The below is derived from the docs. You specify the message numbers you would like to ignore.
%blocked_msgs = map { $_ => 1 } ( 2401, 2411 );
sub err_handler {
my($err, $sev, $state, $line, $server, $proc, $msg, $sql, $err_type) = #_;
if ( exists $blocked_msgs{$err} ) { # it's a blocked message
return 0; # This is not an error
}
return 1;
}
This is how you might use it:
$dbh = DBI->connect('dbi:Sybase:server=troll', 'sa', '');
$dbh->{syb_err_handler} = \&err_handler;
$dbh->do("exec someproc");
$dbh->disconnect;

How to create trigger in DB with help of `DBIx::Class` using add_trigger method?

I want to add trigger into my database. I use DBIx::Class and follow these examples: 1, 2.
My code is:
package App::Schema;
use base qw/DBIx::Class::Schema/;
__PACKAGE__->load_namespaces();
sub sqlt_deploy_hook {
my ($self, $schema) = #_;
$schema->add_trigger( name => 'foo' );
}
1;
But I get this error:
Failed to translate to YAML: translate: Error with producer 'SQL::Translator::Producer::YAML': Can't call method "name" on an undefined value at /home/kes/work/projects/x/app/local/lib/perl5/SQL/Translator/Schema/Trigger.pm line 198
When run command with all environment variables as required by dbic-migration:
dbic-migration --force --schema_class App::Schema --database PostgreSQL -Ilib prepare
Which point me somewhere into SQL::Translator::Schema::Trigger
What did I miss? How to fix this error?
UPD
Even when I add all arguments I got error:
Failed to translate to YAML: translate: Error with parser 'SQL::Translator::Parser::DBIx::Class': Table named users doesn't exist at /home/kes/work/projects/x/app/local/lib/perl5/SQL/Translator/Schema/Trigger.pm line 54
Here the target line:
my $table = $args->{schema}->get_table($arg)
or die "Table named $arg doesn't exist";
Modified code:
sub sqlt_deploy_hook {
my ($self, $schema) = #_;
warn "TABLES: " ,$schema->get_tables ,"\n";
$schema->add_trigger(()
,name => 'foo'
,perform_action_when => 'after'
,database_events => 'insert'
,on_table => 'users'
,action => 'text'
,scope => 'row'
);
}
This code produce next warnings:
TABLES: users
TABLES: dbix_class_deploymenthandler_versions
But DB has only one table at the moment. I expect it at least should produce:
TABLES: users dbix_class_deploymenthandler_versions
How to create trigger in DB?
There maybe the problem with DBIx::Class::ResultSource::default_sqlt_deploy_hook:
which was originally designed to expect the Result class name and the $sqlt_table instance of the table being deployed
As work around add next line of code before add_trigger:
return unless grep $_ eq 'users', $schema->get_tables;
But the recommend way is to create deploy/upgrade/downgrade .sql files manually

Can't call method "verify" on an undefined value

• I am working to migrate a Linux server to a newer one from Ubuntu 10.04 to 12.04
• This server is responsible for executing several a number of Perl modules via crontabs.
• These Perl Modules rely heavily on 30-40 perl extensions.
• I have installed all Perl extensions and the crontabs are able to process successfully except for several Syntax errors caused by the newer versions of these PERL extensions.
• I need some help with modifying the syntax to get the Perl script to process as intended.
This is my error message:
2015/12/28 12:56:48 ./cms.pl 88 FATAL main - Can't call method "verify" on an undefined value at pm/Emails/Core.pm line 438.
Code:
#===================================================================================================
# Send an eamil
# Args: enable_clients?, BCC Arrayref [admin1#a.com, ...], Hashref { email_address, email_subject, email_body }
#===================================================================================================
sub pm::Emails::Core::send_email {
my ($self, $enable_clients, $bcc, $email) = #_;
# die('Invalid BCC array') unless $bcc;
die('Invalid Email hashref') unless ($email && $email->{email_address} && $email->{email_subject} && $email->{email_body});
$email->{email_address} = trim $email->{email_address}; # Trim the email address just to be sure no invalid emails sneak in
my $mime = undef;
my $smtp = undef;
###
# Get a handle to the logger
my $logger = Log::Log4perl->get_logger();
die('Failed to create logger') unless $logger;
###
###
# Send the email using the local SMTP server
# SPAM FILTER NOTES:
# We are sending the email as inlined HTML.
# Sending the email as a multipart with HTML & PlainText is getting flagged as SPAM.
{
my $msg = join(', ',
(
'Time:' . localtime(),
'Sending Email TO: ' . $email->{email_address},
#'BCC: ' . join(',', #$bcc),
'SUBJECT: ' . $email->{email_subject},
'Clients Enabled: ' . ($enable_clients ? 'true' : 'false')
)
);
$logger->warn($msg);
open(FILE, '>>/var/log/mail.log') or die('Failed to open mail log: /var/log/mail.log');
print FILE $msg . "\n";
close FILE;
}
###
if (!defined($self->{_phpversion_})) {
$self->{_phpversion_} = `php -r 'print phpversion();' 2>/dev/null`;
}
###
# Generate the MIME email message
$mime = MIME::Lite->new(
Subject => $email->{email_subject},
To => $email->{email_address},
Type => 'text/html',
Data => $email->{email_body},
'Reply-To' => 'test#test.com',
'Return-Path' => 'test#test.com',
From => 'test#test.com',
Organization => 'Testing',
'X-Mailer' => 'PHP' . $self->{_phpversion_}
);
###
# Check to see if we are sending the email to clients, if not then redirect to another account & update the subject
if ($enable_clients) {
$logger->warn('Sending email to clients is enabled!');
} else {
use Sys::Hostname;
$logger->warn('Sending email to clients is disabled!');
$email->{email_address} = 'test#test.com';
$email->{email_subject} = '<' . hostname . ' - ADMIN ONLY EMAIL> ' . $email->{email_subject};
$mime->replace(Subject => $email->{email_subject});
}
$mime->preamble('');
$mime->top_level(1);
$mime = $mime->as_string();
###
###
# Connect to the SMTP server & send the message
$logger->debug('Connecting to SMPT server');
$smtp = Net::SMTP->new('localhost', Timeout => 60, Debug => 0, Hello => 'test.com');
$logger->debug('Connected to SMPT server');
###
###
# Verify we can send the email to the included addresses
foreach my $email_address (($email->{email_address}), #$bcc) {
$logger->debug('Verifying Email address: ' . $email_address);
next if $smtp->verify($email_address);
$logger->warn('Failed to verify email address: ' . $email_address . ', re-connecting to SMPT');
$smtp = Net::SMTP->new('localhost', Timeout => 60, Debug => 1, Hello => 'test.com');
die('Failed to reconnect to SMPT server') unless $smtp;
last;
}
###
###
# Send the email message
$smtp->mail('test#test.com');
$smtp->bcc(#$bcc, { Notify => ['FAILURE','DELAY', 'SUCCESS'] });
$smtp->to($email->{email_address}, { Notify => ['FAILURE','DELAY', 'SUCCESS'] });
$smtp->data; # This will start the data connection for the message body
$smtp->datasend( $mime ); # This will send the data for the message body
$smtp->dataend; # This will end the message body and send the message to the user
$smtp->quit;
###
use List::Util qw[min];
sleep(min(1, int(rand(2))));
}
Any help on this is greatly appreciated.
You don't create the $smtp object (using $smtp = Net::SMTP->new(...)) until three lines after you try to call the verify() method on it. So of course it's going to be undefined at that point.
The only way that this could ever work is if the $smtp is also created earlier on in code that you haven't shown us. But assuming that you have shown us all mentions of $smtp, then this code can't possibly have worked on the old server only. This is not a problem that is caused by a newer version of Perl, it's a logic error that would never have worked.
The obvious way to fix this is to re-order the code so that the object is created before you try to use it. But as I can only see a small amount of the code, I have no way of knowing whether this would have knock-on effects elsewhere.
Have you considered paying a Perl programmer to help you carry out these migrations? Expecting free consultancy from StackOverflow isn't really a sustainable business model :-/
Update: Ok, so now you've added more code, we can see that the $smtp is initialised a few lines before the call to verify. So why are you getting the error?
If you read the documentation for Net::SMTP, in the section describing the new() method, it says:
On failure undef will be returned and $# will contain the reason for
the failure.
It looks like this is what is happening. But your code isn't checking the return code from the new() and is assuming that it will always work - which is a pretty strange assumption to make. To fine out what is going wrong, you'll need to add some debugging output to the two lines that create your SMTP object. Where you have:
$smtp = Net::SMTP->new(...);
Change it to:
$smtp = Net::SMTP->new(...)
or die $#;
That way, if you fail to connect to the SMTP server, your program will die with a (hopefully) useful error message which will enable you to investigate further.
Incidentally, I don't know where your code comes from, but no-one really recommends Net::SMTP these days. It's all rather low-level. You would be better off looking at Email::Sender or Email::Stuffer (that's the kind of useful knowledge that a Perl programmer would bring to this project..
Hey Guys just Wanted to follow up on this problem. I tried all of your suggestions and was unable to get a solution.
However more in-depth research of the SMTP/Mail running on this machine revealed that it was running Postfix, it turns out this script was written for SendMail. Simply did the following:
Uninstall Postfix-
sudo apt-get purge postfix
Install Sendmail-
sudo apt-get install sendmail
All was resolved, thank you guys for all your help.

methods like opencurrentdatabase in perl

I am new to perl. I am asked to execute a macro in ms access database using perl. This is the code i used
$oAccess = Win32::OLE->GetActiveObject('Access.Application');
$oAccess ->OpenCurrentDatabase($path);
$oAccess ->{DoCmd}->RunMacro("DO ALL");
Today when i was executing the program i found that only if the access database is open the code works fine else it returns the following error
Can't call method "OpenCurrentDatabase" on an undefined value at auto.pl line 30
So I was wondering if i could find any other code which would serve the purpose without an open ms access database.
my $MSAccess;
eval {$MSAccess = Win32::OLE->GetActiveObject('Access.Application')};
die "Access not installed" if $#;
unless (defined $MSAccess) {
$MSAccess = Win32::OLE->new('Access.Application','Quit')
or die "Unable to start Access";
}
$MSAccess->{visible} = 0;

Net::Google::Spreadsheets 500 error, what am I doing wrong?

I'm trying to use Net::Google::Spreadsheets to manipulate a Google Docs spreadsheet (side note: you may have seen my previous question where I was trying to work from the inside of Google Docs, now I'm trying a different angle)
I'm trying an example pretty much straight out of the perldoc:
#!/usr/bin/perl
use strict;
use warnings;
use Net::Google::Spreadsheets;
my $service = Net::Google::Spreadsheets->new(
username => 'my.email#gmail.com',
password => 'mypassword'
);
my #spreadsheets = $service->spreadsheets();
# find a spreadsheet by key
my $spreadsheet = $service->spreadsheet(
{
title => 'Perl Test' # This is a spreadsheet I manually created already
}
);
# find a worksheet by title
my $worksheet = $spreadsheet->worksheet(
{
title => 'Sheet1'
}
);
my $cell = $worksheet->cell({col => 1, row => 1});
# update input value of a cell
$cell->input_value('new value');
When I run my code, I get this error:
request for 'https://spreadsheets.google.com/feeds/worksheets/tNdoUPkz7MhRAtVoBaaZVHQ/private/full?title=Sheet1' failed:
500 Internal Server Error
Internal Error
at /usr/local/share/perl/5.10.1/Net/Google/DataAPI/Role/Service.pm line 96
Net::Google::DataAPI::Role::Service::request('Net::Google::Spreadsheets=HASH(0x167ce60)', 'HASH(0x1c63ba8)') called at /usr/local/share/perl/5.10.1/Net/Google/DataAPI/Role/Service.pm line 158
Net::Google::DataAPI::Role::Service::get_feed('Net::Google::Spreadsheets=HASH(0x167ce60)', 'https://spreadsheets.google.com/feeds/worksheets/tNdoUPkz7MhR...', 'HASH(0x1a38d58)') called at /usr/local/share/perl/5.10.1/Net/Google/DataAPI.pm line 106
Net::Google::Spreadsheets::Spreadsheet::worksheets('Net::Google::Spreadsheets::Spreadsheet=HASH(0x1a36460)', 'HASH(0x1a38d58)') called at /usr/local/share/perl/5.10.1/Net/Google/DataAPI.pm line 119
Net::Google::Spreadsheets::Spreadsheet::worksheet('Net::Google::Spreadsheets::Spreadsheet=HASH(0x1a36460)', 'HASH(0x1a38d58)') called at spreadsheet_test.pl line 22
And then if I try to open up the Perl Test spreadsheet from within Google Docs, Google itself gives me the equivalent of a 500 error.
So what am I doing wrong?