class views_data_export_plugin_query_pgsql_batched in Views data export 7.4
Same name and namespace in other branches
- 7.3 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_query_pgsql_batched
Hierarchy
- class \views_object
Expanded class hierarchy of views_data_export_plugin_query_pgsql_batched
1 string reference to 'views_data_export_plugin_query_pgsql_batched'
- views_data_export_plugin_display_export::initialize_index in plugins/
views_data_export_plugin_display_export.inc - Called on export initialization.
File
- plugins/
views_data_export_plugin_display_export.inc, line 920 - Contains the bulk export display plugin.
View source
class views_data_export_plugin_query_pgsql_batched extends views_data_export_plugin_query_default_batched {
/**
* Executes the query and fills the associated view object with according
* values.
*
* Values to set: $view->result, $view->total_rows, $view->execute_time,
* $view->current_page.
*/
function execute(&$view) {
$display_handler =& $view->display_handler;
$external = FALSE;
// Whether this query will run against an external database.
$query = $view->build_info['query'];
$count_query = $view->build_info['count_query'];
$query
->addMetaData('view', $view);
$count_query
->addMetaData('view', $view);
if (empty($this->options['disable_sql_rewrite'])) {
$base_table_data = views_fetch_data($this->base_table);
if (isset($base_table_data['table']['base']['access query tag'])) {
$access_tag = $base_table_data['table']['base']['access query tag'];
$query
->addTag($access_tag);
$count_query
->addTag($access_tag);
}
}
$items = array();
if ($query) {
$additional_arguments = module_invoke_all('views_query_substitutions', $view);
// Count queries must be run through the preExecute() method.
// If not, then hook_query_node_access_alter() may munge the count by
// adding a distinct against an empty query string
// (e.g. COUNT DISTINCT(1) ...) and no pager will return.
// See pager.inc > PagerDefault::execute()
// http://api.drupal.org/api/drupal/includes--pager.inc/function/PagerDefault::execute/7
// See http://drupal.org/node/1046170.
$count_query
->preExecute();
// Build the count query.
$count_query = $count_query
->countQuery();
// Add additional arguments as a fake condition.
// XXX: this doesn't work... because PDO mandates that all bound arguments
// are used on the query. TODO: Find a better way to do this.
if (!empty($additional_arguments)) {
// $query->where('1 = 1', $additional_arguments);
// $count_query->where('1 = 1', $additional_arguments);
}
$start = microtime(TRUE);
if ($this->pager
->use_count_query() || !empty($view->get_total_rows)) {
$this->pager
->execute_count_query($count_query);
}
// Let the pager modify the query to add limits.
$this->pager
->pre_execute($query);
if (!empty($this->limit) || !empty($this->offset)) {
// We can't have an offset without a limit, so provide a very large limit instead.
$limit = intval(!empty($this->limit) ? $this->limit : 999999);
$offset = intval(!empty($this->offset) ? $this->offset : 0);
$query
->range($offset, $limit);
}
try {
// The $query is final and ready to go, we are going to redirect it to
// become an insert into our table, sneaky!
// Our query will look like:
// CREATE TABLE {idx} SELECT @row := @row + 1 AS weight_alias, cl.* FROM
// (-query-) AS cl, (SELECT @row := 0) AS r
// We do some magic to get the row count.
$display_handler->batched_execution_state->sandbox['weight_field_alias'] = $display_handler
->_weight_alias_create($view);
$display_handler->batched_execution_state->sandbox['field_aliases'] = $display_handler
->field_aliases_create($view);
$select_aliases = array();
foreach ($display_handler->batched_execution_state->sandbox['field_aliases'] as $hash => $alias) {
$select_aliases[] = "cl.{$alias} AS {$hash}";
}
// TODO: this could probably be replaced with a query extender and new query type.
$query
->preExecute();
$args = $query
->getArguments();
// Create temporary sequence
$seq_name = $display_handler
->index_tablename() . '_seq';
db_query('CREATE TEMP sequence ' . $seq_name);
// Query uses sequence to create row number
$insert_query = 'CREATE TABLE {' . $display_handler
->index_tablename() . "} AS SELECT nextval('" . $seq_name . "') AS " . $display_handler->batched_execution_state->sandbox['weight_field_alias'] . ', ' . implode(', ', $select_aliases) . ' FROM (' . (string) $query . ') AS cl';
db_query($insert_query, $args);
$view->result = array();
$this->pager
->post_execute($view->result);
if ($this->pager
->use_pager()) {
$view->total_rows = $this->pager
->get_total_items();
}
// Now create an index for the weight field, otherwise the queries on the
// index will take a long time to execute.
db_add_unique_key($display_handler
->index_tablename(), $display_handler->batched_execution_state->sandbox['weight_field_alias'], array(
$display_handler->batched_execution_state->sandbox['weight_field_alias'],
));
} catch (Exception $e) {
$view->result = array();
debug('Exception: ' . $e
->getMessage());
}
}
$view->execute_time = microtime(TRUE) - $start;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
views_data_export_plugin_query_pgsql_batched:: |
function |
Executes the query and fills the associated view object with according
values. Overrides views_data_export_plugin_query_default_batched:: |
||
views_object:: |
public | property | Handler's definition. | |
views_object:: |
public | property | Except for displays, options for the object will be held here. | 1 |
views_object:: |
function | Collect this handler's option definition and alter them, ready for use. | ||
views_object:: |
public | function | Views handlers use a special construct function. | 4 |
views_object:: |
public | function | Destructor. | 2 |
views_object:: |
public | function | 1 | |
views_object:: |
public | function | ||
views_object:: |
public | function | Always exports the option, regardless of the default value. | |
views_object:: |
public | function | Set default options on this object. | 1 |
views_object:: |
public | function | Set default options. | |
views_object:: |
public | function | Let the handler know what its full definition is. | |
views_object:: |
public | function | Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away. | |
views_object:: |
public | function | Unpack a single option definition. | |
views_object:: |
public | function | Unpacks each handler to store translatable texts. | |
views_object:: |
public | function | ||
views_plugin:: |
public | property | The current used views display. | |
views_plugin:: |
public | property | The plugin name of this plugin, for example table or full. | |
views_plugin:: |
public | property | The plugin type of this plugin, for example style or query. | |
views_plugin:: |
public | property |
The top object of a view. Overrides views_object:: |
1 |
views_plugin:: |
public | function | Provide a list of additional theme functions for the theme info page. | |
views_plugin:: |
public | function | Return the human readable name of the display. | |
views_plugin:: |
public | function | Provide a full list of possible theme templates used by this style. | |
views_plugin:: |
public | function | Validate that the plugin is correct and can be saved. | 3 |
views_plugin_query:: |
public | function |
Validate the options form. Overrides views_plugin:: |
|
views_plugin_query:: |
public | function | Render the pager, if necessary. | |
views_plugin_query:: |
public | function | Control how all WHERE and HAVING groups are put together. | |
views_plugin_query:: |
public | function | Set a LIMIT on the query, specifying a maximum number of results. | |
views_plugin_query:: |
public | function | Set an OFFSET on the query, specifying a number of results to skip | |
views_plugin_query:: |
public | function | Create a new grouping for the WHERE or HAVING clause. | |
views_plugin_query:: |
public | function |
Returns the summary of the settings in the display. Overrides views_plugin:: |
|
views_plugin_query_default:: |
public | property | A flag as to whether or not to make the primary field distinct. | |
views_plugin_query_default:: |
public | property | An array of fields. | |
views_plugin_query_default:: |
public | property | An array mapping table aliases and field names to field aliases. | |
views_plugin_query_default:: |
public | property | Should this query be optimized for counts, for example no sorts. | |
views_plugin_query_default:: |
public | property | A simple array of group by clauses. | |
views_plugin_query_default:: |
public | property | The default operator to use when connecting the WHERE groups. May be AND or OR. | |
views_plugin_query_default:: |
public | property | ||
views_plugin_query_default:: |
public | property | An array of sections of the HAVING query. Each section is in itself an array of pieces and a flag as to whether or not it should be AND or OR. | |
views_plugin_query_default:: |
public | property | The table header to use for tablesort. This matters because tablesort needs to modify the query and needs the header. | |
views_plugin_query_default:: |
public | property | Is the view marked as not distinct. | |
views_plugin_query_default:: |
public | property | A simple array of order by clauses. | |
views_plugin_query_default:: |
public | property |
The current used pager plugin. Overrides views_plugin_query:: |
|
views_plugin_query_default:: |
public | property | Defines the distinct type. | |
views_plugin_query_default:: |
public | property | Holds an array of relationships, which are aliases of the primary table that represent different ways to join the same table in. | |
views_plugin_query_default:: |
public | property | Holds an array of tables and counts added so that we can create aliases. | |
views_plugin_query_default:: |
public | property | A list of tables in the order they should be added, keyed by alias. | |
views_plugin_query_default:: |
public | property | Query tags which will be passed over to the dbtng query object. | |
views_plugin_query_default:: |
public | property | An array of sections of the WHERE query. Each section is in itself an array of pieces and a flag as to whether or not it should be AND or OR. | |
views_plugin_query_default:: |
public | function | Add a field to the query table, possibly with an alias. This will automatically call ensure_table to make sure the required table exists, *unless* $table is unset. | |
views_plugin_query_default:: |
public | function | Add a simple GROUP BY clause to the query. | |
views_plugin_query_default:: |
public | function | Add a simple HAVING clause to the query. | |
views_plugin_query_default:: |
public | function | Add a complex HAVING clause to the query. | |
views_plugin_query_default:: |
public | function | Add an ORDER BY clause to the query. | |
views_plugin_query_default:: |
public | function | A relationship is an alternative endpoint to a series of table joins. | |
views_plugin_query_default:: |
public | function |
Add a signature to the query, if such a thing is feasible. Overrides views_plugin_query:: |
|
views_plugin_query_default:: |
public | function | Add a table to the query, ensuring the path exists. | |
views_plugin_query_default:: |
public | function | Adds a query tag to the sql object. | |
views_plugin_query_default:: |
public | function | Add a simple WHERE clause to the query. | |
views_plugin_query_default:: |
public | function | Add a complex WHERE clause to the query. | |
views_plugin_query_default:: |
public | function | Fix a join to adhere to the proper relationship. | |
views_plugin_query_default:: |
public | function |
Let modules modify the query just prior to finalizing it. Overrides views_plugin_query:: |
|
views_plugin_query_default:: |
public | function |
Builds the necessary info to execute the query. Overrides views_plugin_query:: |
|
views_plugin_query_default:: |
public | function | Construct the "WHERE" or "HAVING" part of the query. | |
views_plugin_query_default:: |
public | function | Remove all fields that may've been added. | |
views_plugin_query_default:: |
public | function | Build fields array. | |
views_plugin_query_default:: |
public | function | Make sure that the specified table can be properly linked to the primary table in the JOINs. This function uses recursion. If the tables needed to complete the path back to the primary table are not in the query they will be added, but additional… | |
views_plugin_query_default:: |
public | function | Ensure a table exists in the queue; if it already exists it won't do anything, but if it doesn't it will add the table queue. It will ensure a path leads back to the relationship table. | |
views_plugin_query_default:: |
public | function |
Get aggregation info for group by queries. Overrides views_plugin_query:: |
|
views_plugin_query_default:: |
public | function | Returns the alias for the given field added to $table. | |
views_plugin_query_default:: |
public | function | Retrieve join data from the larger join data cache. | |
views_plugin_query_default:: |
public | function |
Returns the according entity objects for the given query results. Overrides views_plugin_query:: |
|
views_plugin_query_default:: |
public | function | Get the information associated with a table. | |
views_plugin_query_default:: |
public | function | Get the arguments attached to the WHERE and HAVING clauses of this query. | |
views_plugin_query_default:: |
public | function |
Constructor; Create the basic query object and fill with default values. Overrides views_plugin_query:: |
|
views_plugin_query_default:: |
public | function | ||
views_plugin_query_default:: |
public | function |
Add settings for the ui. Overrides views_plugin_query:: |
|
views_plugin_query_default:: |
public | function |
Special submit handling. Overrides views_plugin_query:: |
|
views_plugin_query_default:: |
public | function |
Information about options for all kinds of purposes will be held here. Overrides views_object:: |
|
views_plugin_query_default:: |
public | function | Generates a unique placeholder used in the db query. | |
views_plugin_query_default:: |
public | function |
Generate a query and a countquery from all of the information supplied
to the object. Overrides views_plugin_query:: |
|
views_plugin_query_default:: |
public | function | Add a table to the query without ensuring the path. | |
views_plugin_query_default:: |
public | function | Set what field the query will count() on for paging. | |
views_plugin_query_default:: |
public | function | Set the view to be distinct. | |
views_plugin_query_default:: |
public | function | Set the table header. |