Closed (fixed)
Project:
Drupal core
Version:
5.x-dev
Component:
database system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
27 Aug 2005 at 11:15 UTC
Updated:
26 Apr 2007 at 02:16 UTC
I just wanted to check if a table exists, from within a drupal module of course.
I found out, that the difference between the MySQL and the PostgreSQL syntax for this problem is vast.
Maybe someone wants to write two database specific functions, db_table_exists($table) ? I could only do the MySQL part...
Comments
Comment #1
maggam commentedHas this been completed? If not, I can work on this.
Comment #2
maggam commented//Input: tablename
//Return: 0, table does NOT exist
//Return: 1, table does exist
function db_table_exists($tablename)
{
$dbconn = pg_connect("host=127.0.01 dbname=test user=drupal password=foo")
or die('Could not connect: ' . pg_last_error());
$query="SELECT exists( select * from pg_tables where tablename='$tablename' and schemaname='public')";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
$answer=pg_fetch_array($result,0,PGSQL_NUM);
if ($answer[0]=='t'){ return 1; } else {return 0;}
}
Example:
echo db_table_exists(tsearch_index);
Let me know if you need anything else :-)
Comment #3
Cvbge commentedHi,
thanks for your help, but please read some existing drupal core code to see how we do things, and http://drupal.org/node/316 for contrubutor's guide. Also browsing some other issues with patches might be a good idea.
Comment #4
maggam commentedI was not too sure what the Parent needed, so I wrote this up for him. He can incorporate this into his code, whichever way he likes, with standards ofcourse.
Comment #5
webchickThis was actually fixed in Drupal 5. :)
Comment #6
(not verified) commented