List:Internals« Previous MessageNext Message »
From:Stewart Smith Date:April 6 2006 4:04am
Subject:RE: getting table meta data (primary key, in this case)
View as plain text  
On Wed, 2006-04-05 at 11:28 -0700, Rick James wrote:
> If I could use Perl, I would do...
> 
> 1. Get output from "SHOW CREATE TABLE foo" 
> 2. foreach line:
> 2a.  if ($lin =~ m{^\s*PRIMARY KEY.*\((.*)\)})
>              commalist of keys in the PK is in $1
> 2b.  if ($lin =~ m{^\s*UNIQUE.*\((.*)\)})
>      AND you don't already have the PK,
>              commalist of keys in the PK is in $1
> 

but you'd query INFORMATION_SCHEMA in 5.0 and above though :)

possibly have a look at the I_S code in sql_show.cc to see how it
generates the table.
-- 
Stewart Smith, Software Engineer
MySQL AB, www.mysql.com
Office: +14082136540 Ext: 6616
VoIP: 6616@stripped
Mobile: +61 4 3 8844 332

Jumpstart your cluster:
http://www.mysql.com/consulting/packaged/cluster.html

Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc
Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc
Thread
getting table meta data (primary key, in this case)Eric Prud'hommeaux1 Apr
  • Re: getting table meta data (primary key, in this case)SGreen3 Apr
    • Re: getting table meta data (primary key, in this case)Eric Prud'hommeaux3 Apr
      • Re: getting table meta data (primary key, in this case)Eric Prud'hommeaux5 Apr
        • RE: getting table meta data (primary key, in this case)Rick James5 Apr
          • RE: getting table meta data (primary key, in this case)Stewart Smith6 Apr
          • RE: getting table meta data (primary key, in this case)Stewart Smith6 Apr
        • Re: getting table meta data (primary key, in this case)Sergei Golubchik6 Apr
          • Re: getting table meta data (primary key, in this case)Eric Prud'hommeaux6 Apr
            • Re: getting table meta data (primary key, in this case)Sergei Golubchik10 Apr
              • Re: getting table meta data (primary key, in this case)Eric Prud'hommeaux15 Apr
                • Re: getting table meta data (primary key, in this case)Sergei Golubchik18 Apr
                • Re: getting table meta data (primary key, in this case)Sanja Byelkin18 Apr
  • Re: getting table meta data (primary key, in this case)Sergei Golubchik3 Apr
Re: getting table meta data (primary key, in this case)Sergei Golubchik10 Apr
  • Re: getting table meta data (primary key, in this case)Eric Prud'hommeaux10 Apr
    • Re: getting table meta data (primary key, in this case)Eric Prud'hommeaux11 Apr