Re: db independant method of determining PKs

	I posted this message to DBI users and got this reply.  I'm reposting here
because I would like to suggest that this behaviour be incorporated into the
DBI spec.
	Perhaps there could a PK flag included with the statement handles meta
attributes.  Or the column name of the primary key could be in the
"TABLE_PK" attribute of the table attributes (like "TABLE_NAME,
	I don't have a lot of experience in this area but it seems to me it would
not be too difficult for the DBD module to tell which column of the table is
the primary key.

	I guess it also brings up the issue of alternate keys, they may be more
difficult for a DBD module to discover though because they are usually
implemented solely with a unique index.

	Anyway, just wanted to pass along an idea...

> -----Original Message-----
> From: Bill Cowan []
> Sent: Monday, March 26, 2001 4:36 PM
> To: Tim Harsch
> Cc:
> Subject: Re: db independant method of determining PKs
> Assuming ODBC gives the 'database independant method', see DBD::ODBC doc
> for ODBC mechanism to do this.
> Will also need to check ODBC API reference on SQLPrimaryKey call on
> which this DBD::ODBC call is based. ODBC doc desecribes the result set
> of info about the primary key columns.
> ----------------- Sample Code ------------------------------------
>     #-- Make the DBD::ODBC call to get primary key metedata.
>     #-- Note: $dbh->func and the last parameter identify the 'private'
>     #-- functions that a specific DBD driver may proivde (not available
>     #-- from the general DBI interface.
>     my $sth = $dbh->func($Parm{DbName}, $Parm{Schema}, $Parm{TableName},
>                          'GetPrimaryKeys');
>     if (not $sth) {
> 	#-- Error handling
>         exit;
>     }
>     #-- Fetch all rows in the result set of column metadata.
>     while (my $RowHashRef = $sth->fetchrow_hashref()) {
>           #-- Process result set for ODBC request.
>     }
> Tim Harsch wrote:
> >
> > Hi all,
> >     Is there any database independant method, namely thru DBI,
> of determing which column of a table is the primary key?
> >     If not, has there been any discussion amongst the
> developers to include it in the DBI spec?
> >
> > Thanks,
> > Tim Harsch
> -- Bill
> ------------------------------------------------------------------------
> Metagenix, Inc:  Leading the Way in Data Migration.
> Web: for more details.
> Bill Cowan,, 919-490-0034 X-218, Fax: 919-490-0143

3/27/2001 2:41:06 AM 1960 articles. 0 followers. Follow

0 Replies

Similar Articles

[PageSpeed] 44