Load Ingest Data
Results 1 to 1 of 1

Thread: ODBC with Perl

  1. #1
    Costi Zaboura is offline World Wide Support Manager
    Join Date
    Aug 2006
    Posts
    300
    Rep Power
    14

    ODBC with Perl

    ODBC Drivers - Perl with Attunity Connect


    Description

    How can I get Perl application talk to Connect ?


    Solution

    The perl module is an ODBC 3.0, we have to use some driver
    manager, to get it working you need to:
    1. Install perl module Bundle- DBI. (A bundle to install DBI and
    required modules).
    a. Download the file from
    http://www.cpan.org/authors/id/TIMB/DBI-1.21.tar.gz.
    b. Run "gzip -d DBI-1.21.tar.gz" and "tar -xvf DBI-1.21.tar".
    c. Enter the "DBI-1.21" directory run "perl Makefile.PL".
    d. Run "make"
    e. *As supersuer* run "make install".

    2. DBD-ODBC-0.33_3 comes with a lightweight generic ODBC driver
    manager called iodbc, to install it:
    a. Download the file from
    http://www.cpan.org/authors/id/J/JU/...-0.33_3.tar.gz
    b. Run "gzip -d DBD-ODBC-0.33_3.tar.gz" and "tar -xvf
    DBD-ODBC-0.33_3.tar".
    a. Enter the iodbcsrc directory under the DBD-ODBC-0.33_3 direcroty
    (path/to/DBD-ODBC-0.33_3/iodbcsrc).
    b. Run "gzip -d libiodbc-2.50.3.tar.gz" and tar- xvf
    "libiodbc-2.50.3.tar".
    c. Enter the "libiodbc-2.50.3" directory and run "./configure".
    d. Run "make"
    e. *As superuser* run "make install".

    3. Install perl module DBD::ODBC. (ODBC Driver for DBI).
    a. Enter the "DBD-ODBC-0.33_3" directory run "perl Makefile.PL -o
    /usr/local".
    b. Run "make"
    c. *As supersuer* run "make install".

    4. Configure an odbc.ini file, the simplest way is to create a
    file named ".odbc.ini" in your $HOME directory (dot-odbc-dot-ini),
    ofcourse you need to change this to the path of the Connect install:
    202 sun(dev) ~ >> cat > ~/.odbc.ini
    ;
    ; .odbc.ini
    ;
    [ODBC Data Sources]
    navdemo = Attunity Connect DSN to NAVDEMO
    [navdemo]
    Driver = $NAVROOT/lib/navcli.so
    Description = Attunity Connect DSN to NAVDEMO
    Host = localhost
    UserName = nav
    Password = nav
    TraceFile = /users/dev/dot/odbc.trace
    Trace = 1
    ^D

    5. Run the odbctst.pl program:
    208 sun(dev) ~/att >> cat > odbctst.pl
    #!/bin/perl
    use strict;
    use DBI;
    my @dat;
    # user "nav" with any password is the default user
    my $dbh = DBI->connect( "dbi:ODBC:navdemo",
    "nav",
    "nav",
    ) || die "Database connection not made:
    $DBI::errstr";
    my $sql = qq{ SELECT * FROM NATION };
    my $sth = $dbh->prepare( $sql );
    if($sth->execute)
    {
    while(@dat = $sth->fetchrow)
    {
    print "@dat\n";
    }
    }
    $dbh->disconnect();
    ^D
    209 sun(dev) ~/dot >> chmod +x odbctst.pl
    210 sun(dev) ~/dot >> ./odbctst.pl
    0 ALGERIA 0 2Cxhl7 L1iwk6hMh300izngN32CPwCikyLk6khMzSRA
    1 ARGENTINA 1 zQn3Okwz1wLn7PLS3OhCgn56kP5PyRikgi1B7lL
    ...




    odbctst.pl

    #!/bin/perl
    use strict;
    use DBI;
    my @dat;
    # user "nav" with any password is the default user
    my $dbh = DBI->connect( "dbi:ODBC:navdemo",
    "nav",
    "nav",
    ) || die "Database connection not made: $DBI::errstr";
    my $sql = qq{ SELECT * FROM NATION };
    my $sth = $dbh->prepare( $sql );
    if($sth->execute)
    {
    while(@dat = $sth->fetchrow)
    {
    print "@dat\n";
    }
    }
    $dbh->disconnect();



    odbc.ini

    ;
    ; odbc.ini
    ;
    [ODBC Data Sources]
    navdemo = Attunity Connect DSN to NAVDEMO
    [navdemo]
    Driver = $NAVROOT/lib/navcli.so
    Description = Attunity Connect DSN to NAVDEMO
    Host = localhost
    UserName = nav
    Password = nav
    TraceFile = /users/dev/dot/odbc.trace
    Trace = 1
    Last edited by Admin_attu; 09-28-2006 at 05:08 AM.
    To Find Out more About Attunity Technology:
    Attunity
    or:
    Contact Us

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •