jdavidb (email not shown publicly)
http://voiceofjohn.blogspot.com/
J. David Blackstone has a Bachelor of Science in Computer Science and Engineering and nine years of experience at a wireless telecommunications company, where he learned Perl and never looked back. J. David has an advantage in that he works really hard, he has a passion for writing good software, and he knows many of the world's best Perl programmers.
DBD::ODBC (Score:3, Informative)
We use DBD::ODBC and have been very happy. We connect like this (took me a while to work out so hope this helps...)
my $dsn = join "", (
"dbi:ODBC:",
"Driver={SQL Server};",
"Server=gort;",
"UID=gpd;",
"PWD=gpd;",
"Database=gort_db",
);
my $user = 'gpd';
my $passwd = 'gpd';
my $db_options = {
PrintError => 1,
RaiseError => 1,
AutoCommit => 0, #Use transactions
};
my $dbh =
DBI->connect($dsn, $user, $passwd, $db_options)
or exit_msg("Can't connect: $DBI::errstr");
Sorry about the formatting. The 'code' tag doesn't do what I'd like...
Reply to This
Re:DBD::ODBC (Score:2)
Thanks for the help, and even more for the sample code! You'll probably find pudge's wonderful ecode tag will help you out.
J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
Re:DBD::ODBC (Score:1)
Re:DBD::ODBC (Score:1)
That certainly hasn't been my experience - perhaps things have changed with recent versions of DBI. I understood that RaiseError was a property of the database handle object which wouldn't exist until the connect method had returned successfully. Errors during the connect itself are handled by returning undef and storing the error message in $DBI::errstr.
Re:DBD::ODBC (Score:2)
I think you have misunderstood. My understanding is that if you have RaiseError set in the options you pass to the connect method, connect will die if unsuccessful. I just ran a short experiment to check, and it is true for Oracle, at least when you attempt to log in to an instance with an incorrect password. YMMV with other drivers or other specific errors, I suppose.
I now connect always with RaiseError => 1, PrintError => 0 (to avoid duplicates; DBI docs say to do this, btw), and AutoCommit =
J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
Re:DBD::ODBC (Score:1)
It probably was different at one time. Found this in the Change log:
Re:DBD::ODBC (Score:1)
Thanks very much for that piece of detective work. The 'or die' on my connect calls is obviously a piece of baggage I've been carrying far too long.
Re:DBD::ODBC (Score:2)
You must undergo the cleansing ritual of purging cargo cult code!!! :)
Could be worse. I still deal with programs from people who wrote open FILE, "$filename" || die "Cant open file", leaving the apostrophe out of can't because they never understood the difference between single and double quotes, and the folklore persisted to nearly every programmer here except me that you couldn't use contractions in the die statement...
J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
DBD::Sybase ... (Score:1)
-derby
Re:DBD::Sybase ... (Score:2)
Thanks. I thought I had heard something like that, but couldn't remember that Sybase was the DBMS in question, so I couldn't find anything with google.
J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
DBD::ODBC (Score:1)
Re:DBD::ODBC (Score:1)
"dbi:ODBC:$dsn"string, but that gets to be a hassle when there are alot of databases, or if you need to port the code to another machine(s) where the dsn's are not set up.If you mean from Linux... (Score:2)
I started off using DBD::Sybase, but it has some problems (with exceptions IIRC) when talking to MS SQL Server.
For the ODBC layer I use unixODBC and of course freeTDS.
Re:If you mean from Linux... (Score:2)
So either way I'm going to need to install freeTDS. Looks like I need to start there.
This is from Solaris, if it makes any difference. (All Unices are the same to me, though; and usually to the code.)
J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers