Caleb Tennis
2/19/2006 5:32:00 PM
On Feb 19, 2006, at 11:28 AM, ngw wrote:
> Hi *,
> I need to find out if a MySQL db contains a certain table, if not I
> have
> to create it.
> I'm using the SHOW TABLES instruction that returns a Mysql::Result
> object, but after that I'm stuck, I don't know how to process the
> resultset without writing awful code :p
> I mean, I can resolve the problem by using a "state" variable inside a
> block and turn it to true if it finds the table, but I guess there's a
> more appropriate way to handle this kind of problems.
A show tables command just returns a query of table names, 1 per row.
I'm not sure if you need to do something more complex, but in MySQL
it's valid to do:
CREATE TABLE IF NOT EXISTS
Caleb