[drupal-devel] Detecting table existence/absence in a Drupally-correct way

Gerhard Killesreiter killesreiter at physik.uni-freiburg.de
Thu Apr 14 04:01:53 UTC 2005



On Wed, 13 Apr 2005, Syscrusher wrote:

> Good evening!

Goood morning!

> Is there a well-behaved way to use Drupal's DB abstraction to find
> out if a table exists? I'm working on a migration feature, and need
> to be able to detect the existence of the table so that I can issue
> a user-friendly "you don't need to do this step" message if the
> table isn't there.

You could do "CREATE TABLE IF NOT EXISTS foo ...." and take out the user
intervention completely.

sed -e 's/CREATE TABLE \([a-z0-9_]*\)/CREATE TABLE IF NOT EXISTS \1/' \
< database.mysql > database-if-exists.mysql

should create a proper Drupal db file with that clause for all tables.

Cheers,
	Gerhard




More information about the drupal-devel mailing list