views_data_export-postgresql-1293788-2.patch 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. diff --git a/plugins/views_data_export_plugin_display_export.inc b/plugins/views_data_export_plugin_display_export.inc
  2. index 3356a8c..bf6761a 100644
  3. --- a/plugins/views_data_export_plugin_display_export.inc
  4. +++ b/plugins/views_data_export_plugin_display_export.inc
  5. @@ -544,7 +544,16 @@ class views_data_export_plugin_display_export extends views_plugin_display_feed
  6. $select_aliases[] = "cl.$alias AS $hash";
  7. }
  8. - $insert_query = 'CREATE TABLE {' . $this->index_tablename() . '} SELECT @row := @row + 1 AS ' . $this->batched_execution_state->sandbox['weight_field_alias'] . ', ' . implode(', ', $select_aliases) . ' FROM (' . $query . ') AS cl, (SELECT @row := 0) AS r';
  9. + if ($this->_get_database_driver() == 'pgsql') {
  10. + // Create temporary sequence
  11. + $seq_name = $this->index_tablename() . '_seq';
  12. + $create_seq_query = 'CREATE TEMP sequence ' . $seq_name;
  13. + // query uses sequence to create row number
  14. + $insert_query = 'CREATE TABLE {' . $this->index_tablename() . "} AS SELECT nextval('".$seq_name."') AS " . $this->batched_execution_state->sandbox['weight_field_alias'] . ', ' . implode(', ', $select_aliases) . ' FROM (' . $query . ') AS cl';
  15. + }
  16. + else {
  17. + $insert_query = 'CREATE TABLE {' . $this->index_tablename() . '} SELECT @row := @row + 1 AS ' . $this->batched_execution_state->sandbox['weight_field_alias'] . ', ' . implode(', ', $select_aliases) . ' FROM (' . $query . ') AS cl, (SELECT @row := 0) AS r';
  18. + }
  19. // Allow for a view to query an external database.
  20. if (isset($view->base_database)) {
  21. @@ -552,6 +561,9 @@ class views_data_export_plugin_display_export extends views_plugin_display_feed
  22. $external = TRUE;
  23. }
  24. + if ($this->_get_database_driver() == 'pgsql') {
  25. + db_query($create_seq_query);
  26. + }
  27. db_query($insert_query, $args);
  28. // Now create an index for the weight field, otherwise the queries on the
  29. @@ -778,7 +790,7 @@ class views_data_export_plugin_display_export extends views_plugin_display_feed
  30. */
  31. function is_compatible() {
  32. $incompatible_drivers = array (
  33. - 'pgsql',
  34. + //'pgsql',
  35. );
  36. $db_driver = $this->_get_database_driver();
  37. return !in_array($db_driver, $incompatible_drivers);