Index: tw.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tw/tw.module,v
retrieving revision 1.1.2.47
diff -u -p -r1.1.2.47 tw.module
--- tw.module	15 Nov 2009 03:46:56 -0000	1.1.2.47
+++ tw.module	17 Dec 2009 02:20:49 -0000
@@ -539,6 +539,72 @@ function tw_get_dbname($dbconnection) {
 }
 
 /**
+ * Get the database properties from it's dbconnection key in $db_url, 
+ * and cache it.
+ *
+ * @param $dbconnection
+ *   The database key set in the settings.php file ('default').
+ * @param $property
+ *   Optional - The individual property you want returned.
+ * @return
+ *   If property was given, then the property value. Otherwise the whole
+ *   array of properties plus 'name'.
+ */
+function tw_get_dbinfo($dbkey = NULL, $property = NULL) {
+  //cache the parsed db properties.
+  static $db_url_parsed = array();
+  global $db_url;
+  
+  //if no dbkey is given, then return the full array of all the databases.
+  if(!isset($dbkey)) {
+    foreach($db_url as $dbkey => $url) {
+      $db_url_parsed[$dbkey] = tw_get_dbinfo($dbkey);
+    }
+    return $db_url_parsed;
+  } 
+  
+  if (!isset($db_url_parsed[$dbkey])) {
+      global $db_url;
+      $db_url_parsed[$dbkey] = parse_url($db_url[$dbkey]);
+      $db_url_parsed[$dbkey]['name'] = substr($db_url_parsed[$dbkey]['path'], 1);
+      $db_url_parsed[$dbkey]['path'] = $db_url[$dbkey];
+  }
+  // if a preporty was requested, then return just that property.
+  if(isset($property)) {
+    return $db_url_parsed[$dbkey][$property];
+  }
+  //else just return the whole array.
+  return $db_url_parsed[$dbkey];  
+}
+
+function tw_inspect_schema($tablename = '', $tabledb = 'default') {
+  // Tw can treat external mysql tables as internal, but we can revert
+  // if we find a period in the tablename. Todo: might be better to build
+  // this check direcly into schema_mysql.inc  
+  if (strpos($tablename, '.')) {
+    list($tabledb, $tablename) =  explode('.', $tablename);
+    $dbinfo = tw_get_dbinfo();
+    foreach($dbinfo as $dbkey => $db_detail) {
+      if($db_detail['name'] == $tabledb) {
+        $tabledb = $dbkey;
+        break;
+      }
+    }
+  }
+  db_set_active($tabledb);
+  // TODO: schema_mysql_inspect($name = NULL) takes $name [tablename] which
+  // limits the query to only get that table, which is probably a good idea.
+  $inspect = schema_invoke('inspect');
+  db_set_active('default');
+  //if a tablename was not given, return the whole schema
+  if ($tablename == '') {
+    return $inspect;
+  }
+  //return the schema for just this table.
+  return $inspect[$tablename];
+}
+
+/**
  * Construct a dbengine-specific qualified tablename
  * 
  * @param $dbconnection
