includes/dbal.php
changeset 1147 7ddd475bc661
parent 1143 e271ae801c62
child 1165 ce8aaa2956d1
--- a/includes/dbal.php	Sun Dec 06 18:22:02 2009 -0500
+++ b/includes/dbal.php	Sun Dec 06 21:51:32 2009 -0500
@@ -511,6 +511,28 @@
     return mysql_affected_rows();
   }
   
+  /**
+   * Get a list of columns in the given table
+   * @param string Table
+   * @return array
+   */
+  
+  function columns_in($table)
+  {
+    if ( !is_string($table) )
+      return false;
+    $q = $this->sql_query("SHOW COLUMNS IN $table;");
+    if ( !$q )
+      $this->_die();
+    
+    $columns = array();
+    while ( $row = $this->fetchrow_num() )
+    {
+      $columns[] = $row[0];
+    }
+    return $columns;
+  }
+  
   function sql_type_cast(&$value)
 	{
 		if ( is_float($value) )
@@ -1219,6 +1241,30 @@
     return pg_affected_rows();
   }
   
+  /**
+   * Get a list of columns in the given table
+   * @param string Table
+   * @return array
+   */
+  
+  function columns_in($table)
+  {
+    if ( !is_string($table) )
+      return false;
+    $q = $this->sql_query("SELECT * FROM $table LIMIT 1 OFFSET 0;");
+    if ( !$q )
+      $this->_die();
+    if ( $this->numrows() < 1 )
+    {
+      // FIXME: Have another way to do this if the table is empty
+      return false;
+    }
+    
+    $row = $this->fetchrow();
+    $this->free_result();
+    return array_keys($row);
+  }
+  
   function sql_type_cast(&$value)
 	{
 		if ( is_float($value) )