views-sql-compliant-three-tier-naming-1971160-22.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. diff --git a/includes/handlers.inc b/includes/handlers.inc
  2. index 2a33d5d..f02bbb2 100644
  3. --- a/includes/handlers.inc
  4. +++ b/includes/handlers.inc
  5. @@ -1530,6 +1530,16 @@ class views_join {
  6. $right_table = $this->definition['table formula'];
  7. }
  8. + $table_data = views_fetch_data($this->table);
  9. +
  10. + if (!empty($table_data['table']['base']['search_path'])) {
  11. + $search_path = $table_data['table']['base']['search_path'] . '.' ;
  12. + } elseif (!empty($table_data['table']['search_path'])) {
  13. + $search_path = $table_data['table']['search_path'] . '.' ;
  14. + } else {
  15. + $search_path = '';
  16. + }
  17. +
  18. if ($this->left_table) {
  19. $left = $view_query->get_table_info($this->left_table);
  20. $left_field = "$left[alias].$this->left_field";
  21. @@ -1542,6 +1552,14 @@ class views_join {
  22. $condition = "$left_field = $table[alias].$this->field";
  23. $arguments = array();
  24. + if (!empty($table_data['table']['base']['search_path'])) {
  25. + $search_path = $table_data['table']['base']['search_path'] . '.' ;
  26. + } elseif (!empty($table_data['table']['search_path'])) {
  27. + $search_path = $table_data['table']['search_path'] . '.' ;
  28. + } else {
  29. + $search_path = '';
  30. + }
  31. +
  32. // Tack on the extra.
  33. if (isset($this->extra)) {
  34. if (is_array($this->extra)) {
  35. @@ -1612,7 +1630,7 @@ class views_join {
  36. }
  37. }
  38. - $select_query->addJoin($this->type, $right_table, $table['alias'], $condition, $arguments);
  39. + $select_query->addJoin($this->type, $search_path . $right_table, $table['alias'], $condition, $arguments);
  40. }
  41. }
  42. @@ -1644,6 +1662,8 @@ class views_join_subquery extends views_join {
  43. *
  44. */
  45. function build_join($select_query, $table, $view_query) {
  46. + $table_data = views_fetch_data($this->table);
  47. +
  48. if (empty($this->definition['table formula'])) {
  49. $right_table = "{" . $this->table . "}";
  50. }
  51. @@ -1651,6 +1671,14 @@ class views_join_subquery extends views_join {
  52. $right_table = $this->definition['table formula'];
  53. }
  54. + if (!empty($table_data['table']['base']['search_path'])) {
  55. + $search_path = $table_data['table']['base']['search_path'] . '.' ;
  56. + } elseif (!empty($table_data['table']['search_path'])) {
  57. + $search_path = $table_data['table']['search_path'] . '.' ;
  58. + } else {
  59. + $search_path = '';
  60. + }
  61. +
  62. // Add our join condition, using a subquery on the left instead of a field.
  63. $condition = "($this->left_query) = $table[alias].$this->field";
  64. $arguments = array();
  65. @@ -1704,7 +1732,7 @@ class views_join_subquery extends views_join {
  66. }
  67. }
  68. - $select_query->addJoin($this->type, $right_table, $table['alias'], $condition, $arguments);
  69. + $select_query->addJoin($this->type, $search_path . $right_table, $table['alias'], $condition, $arguments);
  70. }
  71. }
  72. diff --git a/includes/view.inc b/includes/view.inc
  73. index d8c0c1f..629d770 100644
  74. --- a/includes/view.inc
  75. +++ b/includes/view.inc
  76. @@ -202,6 +202,11 @@ class view extends views_db_object {
  77. var $base_database = NULL;
  78. /**
  79. + * Allow to set the search_path for databases which, unlike MySQL, are actually SQL-compliant
  80. + */
  81. + var $search_path = NULL;
  82. +
  83. + /**
  84. * Here comes a list of the possible handler which are active on this view.
  85. */
  86. @@ -899,6 +904,12 @@ class view extends views_db_object {
  87. $this->base_database = $views_data['table']['base']['database'];
  88. }
  89. + if (!empty($views_data['table']['base']['search_path'])) {
  90. + $this->search_path = $views_data['table']['base']['search_path'];
  91. + } elseif (!empty($views_data['table']['search_path'])) {
  92. + $this->search_path = $views_data['table']['search_path'];
  93. + }
  94. +
  95. // Load the options.
  96. $query_options = $this->display_handler->get_option('query');
  97. diff --git a/plugins/views_plugin_query_default.inc b/plugins/views_plugin_query_default.inc
  98. index 030c5ea..20889a7 100644
  99. --- a/plugins/views_plugin_query_default.inc
  100. +++ b/plugins/views_plugin_query_default.inc
  101. @@ -1290,8 +1290,13 @@ class views_plugin_query_default extends views_plugin_query {
  102. // Go ahead and build the query.
  103. // db_select doesn't support to specify the key, so use getConnection directly.
  104. + $table_prefix = '';
  105. + if (isset($this->view->search_path)) {
  106. + $table_prefix = $this->view->search_path . '.';
  107. + }
  108. +
  109. $query = Database::getConnection($target, $key)
  110. - ->select($this->base_table, $this->base_table, $options)
  111. + ->select($table_prefix . $this->base_table, $this->base_table, $options)
  112. ->addTag('views')
  113. ->addTag('views_' . $this->view->name);