views-sql-compliant-three-tier-naming-1971160-30.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. diff --git a/includes/handlers.inc b/includes/handlers.inc
  2. index 680a54d..1d72aed 100644
  3. --- a/includes/handlers.inc
  4. +++ b/includes/handlers.inc
  5. @@ -1729,7 +1729,17 @@ class views_join {
  6. }
  7. }
  8. - $select_query->addJoin($this->type, $right_table, $table['alias'], $condition, $arguments);
  9. + $table_data = views_fetch_data($this->table);
  10. +
  11. + $scoped_right_table = $right_table;
  12. +
  13. + if (!empty($table_data['table']['base']['search_path'])) {
  14. + $scoped_right_table = $table_data['table']['base']['search_path'] . '.' . $right_table;
  15. + } elseif (!empty($table_data['table']['search_path'])) {
  16. + $scoped_right_table = $table_data['table']['search_path'] . '.' . $right_table;
  17. + }
  18. +
  19. + $select_query->addJoin($this->type, $scoped_right_table, $table['alias'], $condition, $arguments);
  20. }
  21. }
  22. @@ -1832,7 +1842,17 @@ class views_join_subquery extends views_join {
  23. }
  24. }
  25. - $select_query->addJoin($this->type, $right_table, $table['alias'], $condition, $arguments);
  26. + $table_data = views_fetch_data($this->table);
  27. +
  28. + $scoped_right_table = $right_table;
  29. +
  30. + if (!empty($table_data['table']['base']['search_path'])) {
  31. + $scoped_right_table = $table_data['table']['base']['search_path'] . '.' . $right_table;
  32. + } elseif (!empty($table_data['table']['search_path'])) {
  33. + $scoped_right_table = $table_data['table']['search_path'] . '.' . $right_table;
  34. + }
  35. +
  36. + $select_query->addJoin($this->type, $scoped_right_table, $table['alias'], $condition, $arguments);
  37. }
  38. }
  39. diff --git a/includes/view.inc b/includes/view.inc
  40. index d9fb43f..1cf5c50 100644
  41. --- a/includes/view.inc
  42. +++ b/includes/view.inc
  43. @@ -234,6 +234,11 @@ class view extends views_db_object {
  44. public $base_database = NULL;
  45. /**
  46. + * Allow to set the search_path for databases which, unlike MySQL, are actually SQL-compliant
  47. + */
  48. + var $search_path = NULL;
  49. +
  50. + /**
  51. * Here comes a list of the possible handler which are active on this view.
  52. */
  53. @@ -939,6 +944,12 @@ class view extends views_db_object {
  54. $this->base_database = $views_data['table']['base']['database'];
  55. }
  56. + if (!empty($views_data['table']['base']['search_path'])) {
  57. + $this->search_path = $views_data['table']['base']['search_path'];
  58. + } elseif (!empty($views_data['table']['search_path'])) {
  59. + $this->search_path = $views_data['table']['search_path'];
  60. + }
  61. +
  62. // Load the options.
  63. $query_options = $this->display_handler->get_option('query');
  64. diff --git a/plugins/views_plugin_query_default.inc b/plugins/views_plugin_query_default.inc
  65. index 7468dd9..f092515 100644
  66. --- a/plugins/views_plugin_query_default.inc
  67. +++ b/plugins/views_plugin_query_default.inc
  68. @@ -1308,8 +1308,13 @@ class views_plugin_query_default extends views_plugin_query {
  69. // Go ahead and build the query. db_select doesn't support to specify the
  70. // key, so use getConnection directly.
  71. + $scoped_base_table = $this->base_table;
  72. + if (isset($this->view->search_path)) {
  73. + $scoped_base_table = $this->view->search_path . '.' . $this->base_table;
  74. + }
  75. +
  76. $query = Database::getConnection($target, $key)
  77. - ->select($this->base_table, $this->base_table, $options)
  78. + ->select($scoped_base_table, $this->base_table, $options)
  79. ->addTag('views')
  80. ->addTag('views_' . $this->view->name);