Unix Technical Forum

DBD::Informix

This is a discussion on DBD::Informix within the Informix forums, part of the Database Server Software category; --> I'm having a little trouble using the DBI functions table_info(), column_info(), and primary_key_info() functions which I've never tried using ...


Go Back   Unix Technical Forum > Database Server Software > Informix

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-20-2008, 07:47 AM
Mark J Fenbers
 
Posts: n/a
Default DBD::Informix

I'm having a little trouble using the DBI functions table_info(),
column_info(), and primary_key_info() functions which I've never tried
using before now. I'm not certain what sort of values I should specify
as arguments. For table_info(), it returns a valid statement handle
from which I can 'fetch' the records, but it fetches records for every
table in the database REGARDLESS of what my arguments are. I guess
DBD::Informix doesn't support the filters (as suggested in the DBI
documentation). I can live with that. But for column_info() and
primary_key_info(), I have NEVER been successful at getting a valid
(defined) statement handle back from the function call REGARDLESS of
what my arguments are.

Can someone provide sample code or otherwise explain what I am doing
wrong? Here is the pertinent code I have...


use DBI;
use strict;

my $dbh ->connect( ... );

my $sth = $dbh->primary_key_info('%','oper','crest'); # this returns
undef regardless of what my arguments are...
my $data = $sth->fetchall_arrayref; # error: $sth is null (not
defined)...


Any ideas?

Mark

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-20-2008, 07:47 AM
Mark J Fenbers
 
Posts: n/a
Default Re: DBD::Informix

Ah. I found in this document
http://search.cpan.org/~johnl/DBD-In...mix/Summary.pm
where these functions are not implemented. (

This is unforntunate because our agency uses 3 different databases, and
making this app portable among all three will be very difficult at best.

But it does say that "The keys/indexes of a table be fetched by querying on
the system catalog.", but it gives no further details. What is the logical
way to determine the primary keys of a given table using a system catalog?
(I'm not sure I even understand what a system catalog is...)

Mark



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-20-2008, 07:49 AM
Art S. Kagel
 
Posts: n/a
Default Re: DBD::Informix

On Wed, 29 Sep 2004 16:01:01 -0400, Mark J Fenbers wrote:

> Ah. I found in this document
> http://search.cpan.org/~johnl/DBD-In...mix/Summary.pm
> where these functions are not implemented. (
>
> This is unforntunate because our agency uses 3 different databases, and
> making this app portable among all three will be very difficult at best.
>
> But it does say that "The keys/indexes of a table be fetched by querying on
> the system catalog.", but it gives no further details. What is the logical
> way to determine the primary keys of a given table using a system catalog?
> (I'm not sure I even understand what a system catalog is...)


Every Relational Database has a system catalog. It's how the server knows the
location of data and how to understand a table's record structure. Read the
Informix Administrator's Guide and Administrator's Reference for more info.
Tables are defined in systables, column types and names in syscolumns, indexes
(important as primary keys are maintained by a unique index on the key) are
defined in sysindexes (in 7.xx, in 9.xx it's sysindices and sysindexes is a
VIEW), constraints (like primary key constraints) are defined in
sysconstraints. Joining these tables will give you what you need. However,
it's not simple:

- Find the tabname in systables and use it's tabid to join to sysconstraints

- Find the sysconstraints record with constrtype = 'P' and use the idxname
column to join to sysindexes

- The colno's stored in sysindexes.part1 -> part16 (or partN * -1 if negative)
are used with tabid to join to syscolumns to determine the column names of
the primary key.

To do this in a single query is messy (you have to join to syscolumns 16
times as outer joins, except for the first), but it can be done. Jonathan
Leffler posts the query for printing key column lists about once a year.
Search the CDI archives on the IIUG web site.

Art S. Kagel
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:45 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com