前段时间看到有人在网上问如何通过Perl访问TimesTen,觉得这个问题比较有意思,找了相关资料试了下,通过一个开源的封装接口,Perl能正常访问TimesTen,实验步骤如下:
 
  • 创建一个DSN并能正常访问,创建一个用户test并赋予权限
[tt705@west-mountain info]$ ttisql ttcore

Copyright (c) 1996-2008, Oracle.  All rights reserved.
Type ? or "help" for help, type "exit" to quit ttIsql.
All commands must end with a semicolon character.

connect "DSN=ttcore";
Connection successful: DSN=ttcore;UID=tt705;DataStore=/home/tt705/TimesTen/tt705/info/ttcore;…CkptFrequency=300;TypeMode=0;
(Default setting AutoCommit=1)
Command> create user test identified by ‘test’;
Command> grant all to test;
 
  • 下载开源的封装好的Perl接口
 
可以到原网站上直接下载:http://www.perl.com/CPAN/modules/by-module/DBD/DBD-TimesTen-0.06.tar.gz , 如有问题可以参考README文件. 貌似最新的版本就是0.06,一直没有更新。
 
  • 解压并安装
 
[tt705@west-mountain ~]$ unzip DBD-TimesTen-0.06.tar.gz
[tt705@west-mountain ~]$ tar -xvf DBD-TimesTen-0.06.tar 
 
  • 设置系统变量
 
export    DBI_DSN=dbi:TimesTen:ttcore

export    DBI_USER=test
export    DBI_PASS=test

export    TT_HOME=/home/tt705/TimesTen/tt705
 
  • 修改Makefile.PL
[tt705@west-mountain ~]$ cd DBD-TimesTen-0.06
[tt705@west-mountain DBD-TimesTen-0.06]$ ls
ChangeLog  dbdimp.h           dbivport.h   MANIFEST       META.yml  t           TimesTen.pm
dbdimp.c   DBD-TimesTen.spec  Makefile.PL  MANIFEST.SKIP  README    TimesTen.h  TimesTen.xs


修改之前备份一下,原有的Makefile.PL是为client/server方式的连接准备的,我们要修改成direct方式的
[tt705@west-mountain DBD-TimesTen-0.06]$ cp Makefile.PL Makefile.PL.Client
[tt705@west-mountain DBD-TimesTen-0.06]$ vi Makefile.PL 


将第91行进行如下的修改,即将client/server模式的编译方式换成direct方式的 
$opts{LIBS} = "-L$timesten_home/lib -lttclient";
–>
$opts{LIBS} = "-L$timesten_home/lib -ltten";
 
 

  • make并安装
 
[tt705@west-mountain DBD-TimesTen-0.06]$ perl Makefile.PL
[tt705@west-mountain DBD-TimesTen-0.06]$ make
[tt705@west-mountain DBD-TimesTen-0.06]$ make install
 
可能会碰到有些目录权限的问题,赋予相应的权限即可。
 
  • 创建下面的应用程序保存为test.t文件
#!/usr/bin/perl
use strict;
use DBI;

MAIN:
{
my ($db, $st, $row);

$db = DBI->connect(’DBI:TimesTen:DSN=ttcore’, ‘test’, ‘test’)
or die $DBI::errstr;

$st = $db->prepare("select * from monitor")
or die $DBI::errstr;

$st->execute()
or die $DBI::errstr;

while ($row = $st->fetchrow_hashref())
{
foreach (keys %{$row})
{
printf "%s=%s\n", $_, $row->{$_};
}
}

$st->finish();
$db->disconnect();
};
  • 运行perl test.t 
[tt705@west-mountain DBD-TimesTen-0.06]$ perl test.t
REP_CONFLICT_COUNT=0
TEMP_IN_USE_HIGH_WATER=3521
DS_CHECKPOINTS_FUZZY=0
TIME_OF_1ST_CONNECT=Sun Sep 27 20:07:00 2009        
SYS5=0
DEADLOCKS=0
SYS13=0
SYS4=0
REP_XACT_COUNT=0

留言已经关闭