? .svn ? tw_external_tables.patch ? help/.svn ? tests/.svn ? tw_import/.svn ? tw_import/tests/.svn Index: tw.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/tw/tw.module,v retrieving revision 1.1.2.44 diff -u -p -r1.1.2.44 tw.module --- tw.module 17 Oct 2009 23:32:11 -0000 1.1.2.44 +++ tw.module 6 Nov 2009 01:22:06 -0000 @@ -517,6 +517,25 @@ function tw_quote_identifier($identifier return $quote . $identifier . $quote; } +/** + * Get the database name from it's dbconnection key in $db_url, and cache it. + * + * @param $dbconnection + * The database key set in the settings.php file ('default'). + * @return + * The database name from the database path. + */ +function tw_get_dbname($dbconnection) { + static $real_db_name = array(); + if (!isset($real_db_name[$dbconnection])) { + global $db_url; + $url = parse_url($db_url[$dbconnection ]); + $real_db_name[$dbconnection] = substr($url['path'], 1); + + } + return $real_db_name[$dbconnection]; +} + ////////////////////////////////////////////////////////// // Drupal core hooks // Index: tw.views_default.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/tw/tw.views_default.inc,v retrieving revision 1.1.2.19 diff -u -p -r1.1.2.19 tw.views_default.inc --- tw.views_default.inc 17 Oct 2009 23:28:47 -0000 1.1.2.19 +++ tw.views_default.inc 6 Nov 2009 01:22:06 -0000 @@ -39,7 +39,7 @@ function tw_views_default_views() { global $db_url; $url = parse_url($db_url[$dbconnection ]); $truedbname = substr($url['path'], 1); - $rawtablename = $tablename; + $rawtablename = tw_get_dbname($dbconnection) .'.'. $tablename; $cleantablename = $truedbname . '_' . $tablename; } // Create a basic table view, with exclusion flags, for each import table Index: tw_tablebuild.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/tw/Attic/tw_tablebuild.inc,v retrieving revision 1.1.2.9 diff -u -p -r1.1.2.9 tw_tablebuild.inc --- tw_tablebuild.inc 17 Oct 2009 23:28:47 -0000 1.1.2.9 +++ tw_tablebuild.inc 6 Nov 2009 01:22:06 -0000 @@ -57,13 +57,19 @@ function _tw_generate_views_table_data($ // Load the schema so we can get table comments. $schema = drupal_get_schema($tablename); $dbconnection = $tblrow->dbconnection; + + + $dbname = tw_get_dbname($dbconnection); + + if ($dbconnection == 'default') { $rawtablename = schema_unprefix_table($tablename); $disptablename = $tablename; } else { - $rawtablename = $tablename; - $disptablename = $dbconnection . '.' . $tablename; + $rawtablename = $dbname .'.'. $tablename; + $disptablename = $dbname .'.'. $tablename; + $dbconnection = 'default'; } $twtid = $tblrow->twtid; $table = array(); @@ -118,7 +124,7 @@ function _tw_generate_views_table_data($ 'title' => $t('Database table @tablename', array('@tablename' => $disptablename)), 'help' => (!empty($schema['description'])) ? $t($schema['description']) : $help, 'weight' => 10, - 'database' => $dbconnection, + //'database' => $dbconnection, ), ); } @@ -131,7 +137,7 @@ function _tw_generate_views_relationship $t = $export ? '_tw_t_wrap' : 't'; $where = is_null($twtids) ? '' : 'WHERE twt1.twtid IN (' . db_placeholders($twtids) . ')'; // Now that all tables are present, fill in relationships defined by foreign keys - $sql = "SELECT twt1.tablename AS tbl1, twc1.colname AS col1, twt2.tablename AS tbl2, + $sql = "SELECT twt1.tablename AS tbl1, twc1.colname AS col1, twt1.dbconnection AS dbcon1, twt2.tablename AS tbl2, twc2.colname AS col2, twt2.twtid AS twtid2, twt2.dbconnection AS dbcon2, twr.automatic FROM {tw_relationships} twr @@ -148,8 +154,8 @@ function _tw_generate_views_relationship $i = 0; while ($row = db_fetch_array($result)) { extract($row); - $rawtbl1 = schema_unprefix_table($tbl1); - $rawtbl2 = schema_unprefix_table($tbl2); + $rawtbl1 = tw_get_dbname($dbcon1) .'.'. schema_unprefix_table($tbl1); + $rawtbl2 = tw_get_dbname($dbcon2) .'.'. schema_unprefix_table($tbl2); if ($automatic) { // Use Views joins (automatically include right-table fields in left-table views) $disptablename = $dbcon2 . '.' . $tbl2;