**************************************************************************************** ************** dostęp do bazy MS-SQL (nie mylić z MySQL!) z poziomu Unixa ************** **************************************************************************************** Problem: musimy się dostać spod perla w unixie do bazy Microsoftowej. Poniżej przedstawiam krótki opis jak to wykonać. Jako, że w temacie baz danych mocno nie siedzę, część rzeczy napisana jest dość ogólnikowo - celowo - nie chcę się wymądrzać w temacie, o którym mam blade pojęcie. Niemniej rozwiązanie poniższe działa, czyli cel został osiągnięty. 1) instalujemy pakiet FreeTDS - http://freetds.org W chwili pisania tego tekstu - `Fri Mar 5 12:50:51 CET 2004` jest to wersja freetds-0.62.1: http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz Instalacja nie powinna sprawić większych problemów, na Slaczku 9.1 sprowadzała się do ./configure && make && make install , na RH 7 sytuacja wyglądała podobnie. 2) Następnie instalujemy Sybperla => http://www.peppler.org/downloads/sybperl-2.16.tar.gz I tu może pojawić się problem na starszych systemach - Sybperl wymaga bowiem `Perl 5.002 or later`, także jeśli masz starszego, to musisz albo upgreadnąć, albo zainstalować w innej lokalizacji nowszego perla. INSTALACJA sybperla. perl Makefile.PL Can't find any Sybase libraries under /lib. Please set the SYBASE environment correctly, or edit CONFIG and set SYBASE correctly there. at ./util/config.pl line 76. Ano, rzuca się o ściężkę do bibliotek Sybasa, należy podać ścieżkę w której zainstalowany został Freetds - domyślnie w /usr/local , no to robimy: root@dell:/p/sybperl-2.16# export SYBASE=/usr/local && perl Makefile.PL Unknown OpenClient version found - may be FreeTDS. The sybperl modules need access to a Sybase server to run the tests. Szczerze mowiac nie wiem co tu nalezy dokladnie podac, ja zostawilem default - enter. To clear an entry please enter 'undef' Sybase server to use (default: SYBASE): User ID to log in to Sybase (default: sa): Password (default: undef): * Writing login information, including password, to file PWD. * * * * natępnie make && make install * * 3) Dalej potrzebujemy DBD-Sybase - w chwili obecnej to jest DBD-Sybase-1.02.tar * * root@dell:/p/DBD-Sybase-1.02# perl Makefile.PL * * perl zwróci takie komunikaty: * * Sybase OpenClient found. * The DBD::Sybase module need access to a Sybase server to run the tests. * To clear an entry please enter 'undef' * Sybase server to use (default: troll): * User ID to log in to Sybase (default: sa): * Password (default: undef): * Sybase database to use on troll (default: undef): * Checking if your kit is complete... * Looks good * Note (probably harmless): No library found for -lcs * Note (probably harmless): No library found for -lsybtcl * Note (probably harmless): No library found for -lcomn * Note (probably harmless): No library found for -lintl * Using DBI 1.40 (for perl 5.008 on i486-linux) installed in /usr/lib/perl5/site_perl/5.8.0/i486-linux/auto/DBI * Writing Makefile for DBD::Sybase * * potem standardowo make && make install * * * No i to de facto wszystko. Możemy spróbować zrobić jakiegoś prostego Selecta: * * * => vi /skrypciol * * # * use DBI; * * * my $dbh = DBI->connect("dbi:Sybase:server=10.0.0.18:1433", 'mysqluser', 'mysqlpassword', {PrintError => 0}); * * die "Unable for connect to server $DBI::errstr" * unless $dbh; * * my $rc; * my $sth; * * $sth = $dbh->prepare("select * from tabela1"); * if($sth->execute) { * while(@dat = $sth->fetchrow) { * print "@dat\n"; * } * } * * -------------------------------------------------------- * Tabela zawiare trzy rekordy 1,2,3 * * * root@dell:/p/DBD-Sybase-1.02# /skrypciol * 1 * 2 * 3 * * * * to tyle * * ^marek/(o)\rojcanet/(-)pl$ * 05-03-2004