Mailing List Archive



Back to the month index Back to the list index

Howie (caffeine@toodarkpark.org)
Sun, 30 Nov 1997 04:52:29 -0500 (EST)


Date: Sun, 30 Nov 1997 04:52:29 -0500 (EST)
From: Howie <caffeine@toodarkpark.org>
Subject: Re: How do I duplicate tables?
Message-ID: <Pine.LNX.3.96.971130043320.12025E-100000@brap.toodarkpark.org>

On Fri, 28 Nov 1997, Wei-Cheng Chu wrote:

> Hi!
>
> Can anyone tell me how to duplicate a new table from an existing one
> in the same database in C programs in msql-2.0.3?
>
> I've check msql.h and found that there's a declaration for function
> msqlCreateTable(), but it seems not to be described in the manual.
> Can I use it? If I can, how should I use it?
>
> If I can't, I think the only way is to use msqlQuery(). But I don't
> want the SQL statement for the table definition fixed in the source
> since the definition of the "template table" maybe changed some other
> day. So how can I dynamically obtain an existing table's definition and
> convert it into a SQL statement for creating new tables?

using the m_field struct, IS_PRI_KEY(), and IS_NOT_NULL() one can 'dupe'
the table definition quite easily.

look through the src of msqldump - its using msqlListFields()
and msqlFetchField(). more specifically, 'int getTableStructure(table)'
( from msqldump.c ) has everything you'd need.

---
Howie <caffeine@toodarkpark.org>   NeXTmail accepted as of Sat-15-Nov
URL: http://www.toodarkpark.org    Business: http://www.cgishop.com
Unix, Motif, NEXTSTEP              CGI/Database programming in C,ObjC,PERL
Visit the MySQL Apps and Website list @ http://www.cgishop.com/bin/mysqllist