query.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. <?php
  2. /**
  3. * @file
  4. * Contains SearchApiViewsQuery.
  5. */
  6. /**
  7. * Views query class using a Search API index as the data source.
  8. */
  9. class SearchApiViewsQuery extends views_plugin_query {
  10. /**
  11. * Number of results to display.
  12. *
  13. * @var int
  14. */
  15. protected $limit;
  16. /**
  17. * Offset of first displayed result.
  18. *
  19. * @var int
  20. */
  21. protected $offset;
  22. /**
  23. * The index this view accesses.
  24. *
  25. * @var SearchApiIndex
  26. */
  27. protected $index;
  28. /**
  29. * The query that will be executed.
  30. *
  31. * @var SearchApiQueryInterface
  32. */
  33. protected $query;
  34. /**
  35. * The results returned by the query, after it was executed.
  36. *
  37. * @var array
  38. */
  39. protected $search_api_results = array();
  40. /**
  41. * Array of all encountered errors.
  42. *
  43. * Each of these is fatal, meaning that a non-empty $errors property will
  44. * result in an empty result being returned.
  45. *
  46. * @var array
  47. */
  48. protected $errors;
  49. /**
  50. * Whether to abort the search instead of executing it.
  51. *
  52. * @var bool
  53. */
  54. protected $abort = FALSE;
  55. /**
  56. * The names of all fields whose value is required by a handler.
  57. *
  58. * The format follows the same as Search API field identifiers (parent:child).
  59. *
  60. * @var array
  61. */
  62. protected $fields;
  63. /**
  64. * The query's sub-filters representing the different Views filter groups.
  65. *
  66. * @var array
  67. */
  68. protected $filters = array();
  69. /**
  70. * The conjunction with which multiple filter groups are combined.
  71. *
  72. * @var string
  73. */
  74. public $group_operator = 'AND';
  75. /**
  76. * Create the basic query object and fill with default values.
  77. */
  78. public function init($base_table, $base_field, $options) {
  79. try {
  80. $this->errors = array();
  81. parent::init($base_table, $base_field, $options);
  82. $this->fields = array();
  83. if (substr($base_table, 0, 17) == 'search_api_index_') {
  84. $id = substr($base_table, 17);
  85. $this->index = search_api_index_load($id);
  86. $this->query = $this->index->query(array(
  87. 'parse mode' => $this->options['parse_mode'],
  88. ));
  89. }
  90. }
  91. catch (Exception $e) {
  92. $this->errors[] = $e->getMessage();
  93. }
  94. }
  95. /**
  96. * Add a field that should be retrieved from the results by this view.
  97. *
  98. * @param $field
  99. * The field's identifier, as used by the Search API. E.g., "title" for a
  100. * node's title, "author:name" for a node's author's name.
  101. *
  102. * @return SearchApiViewsQuery
  103. * The called object.
  104. */
  105. public function addField($field) {
  106. $this->fields[$field] = TRUE;
  107. return $field;
  108. }
  109. /**
  110. * Adds a sort to the query.
  111. *
  112. * @param string $selector
  113. * The field to sort on. All indexed fields of the index are valid values.
  114. * In addition, these special fields may be used:
  115. * - search_api_relevance: sort by relevance;
  116. * - search_api_id: sort by item id;
  117. * - search_api_random: random sort (available only if the server supports
  118. * the "search_api_random_sort" feature).
  119. * @param string $order
  120. * The order to sort items in - either 'ASC' or 'DESC'. Defaults to 'ASC'.
  121. */
  122. public function add_selector_orderby($selector, $order = 'ASC') {
  123. if (!$this->errors) {
  124. $this->query->sort($selector, $order);
  125. }
  126. }
  127. /**
  128. * Provides a sorting method as present in the Views default query plugin.
  129. *
  130. * This is provided so that the "Global: Random" sort included in Views will
  131. * work properly with Search API Views. Random sorting is only supported if
  132. * the active search server supports the "search_api_random_sort" feature,
  133. * though, otherwise the call will be ignored.
  134. *
  135. * This method can only be used to sort randomly, as would be done with the
  136. * default query plugin. All other calls are ignored.
  137. *
  138. * @param string|null $table
  139. * Only "rand" is recognized here, all other calls are ignored.
  140. * @param string|null $field
  141. * Is ignored and only present for compatibility reasons.
  142. * @param string $order
  143. * Either "ASC" or "DESC".
  144. * @param string|null $alias
  145. * Is ignored and only present for compatibility reasons.
  146. * @param array $params
  147. * The following optional parameters are recognized:
  148. * - seed: a predefined seed for the random generator.
  149. *
  150. * @see views_plugin_query_default::add_orderby()
  151. */
  152. public function add_orderby($table, $field = NULL, $order = 'ASC', $alias = '', $params = array()) {
  153. $server = $this->getIndex()->server();
  154. if ($table == 'rand') {
  155. if ($server->supportsFeature('search_api_random_sort')) {
  156. $this->add_selector_orderby('search_api_random', $order);
  157. if ($params) {
  158. $this->setOption('search_api_random_sort', $params);
  159. }
  160. }
  161. else {
  162. $variables['%server'] = $server->label();
  163. watchdog('search_api_views', 'Tried to sort results randomly on server %server which does not support random sorting.', $variables, WATCHDOG_WARNING);
  164. }
  165. }
  166. }
  167. /**
  168. * Defines the options used by this query plugin.
  169. *
  170. * Adds some access options.
  171. */
  172. public function option_definition() {
  173. return parent::option_definition() + array(
  174. 'search_api_bypass_access' => array(
  175. 'default' => FALSE,
  176. ),
  177. 'entity_access' => array(
  178. 'default' => FALSE,
  179. ),
  180. 'parse_mode' => array(
  181. 'default' => 'terms',
  182. ),
  183. );
  184. }
  185. /**
  186. * Add settings for the UI.
  187. *
  188. * Adds an option for bypassing access checks.
  189. */
  190. public function options_form(&$form, &$form_state) {
  191. parent::options_form($form, $form_state);
  192. $form['search_api_bypass_access'] = array(
  193. '#type' => 'checkbox',
  194. '#title' => t('Bypass access checks'),
  195. '#description' => t('If the underlying search index has access checks enabled, this option allows to disable them for this view.'),
  196. '#default_value' => $this->options['search_api_bypass_access'],
  197. );
  198. if ($this->index && $this->index->getEntityType()) {
  199. $form['entity_access'] = array(
  200. '#type' => 'checkbox',
  201. '#title' => t('Additional access checks on result entities'),
  202. '#description' => t("Execute an access check for all result entities. This prevents users from seeing inappropriate content when the index contains stale data, or doesn't provide access checks. However, result counts, paging and other things won't work correctly if results are eliminated in this way, so only use this as a last ressort (and in addition to other checks, if possible)."),
  203. '#default_value' => $this->options['entity_access'],
  204. );
  205. }
  206. $form['parse_mode'] = array(
  207. '#type' => 'select',
  208. '#title' => t('Parse mode'),
  209. '#description' => t('Choose how the search keys will be parsed.'),
  210. '#options' => array(),
  211. '#default_value' => $this->options['parse_mode'],
  212. );
  213. foreach ($this->query->parseModes() as $key => $mode) {
  214. $form['parse_mode']['#options'][$key] = $mode['name'];
  215. if (!empty($mode['description'])) {
  216. $states['visible'][':input[name="query[options][parse_mode]"]']['value'] = $key;
  217. $form["parse_mode_{$key}_description"] = array(
  218. '#type' => 'item',
  219. '#title' => $mode['name'],
  220. '#description' => $mode['description'],
  221. '#states' => $states,
  222. );
  223. }
  224. }
  225. }
  226. /**
  227. * Builds the necessary info to execute the query.
  228. */
  229. public function build(&$view) {
  230. if (!empty($this->errors)) {
  231. return;
  232. }
  233. $this->view = $view;
  234. // Setup the nested filter structure for this query.
  235. if (!empty($this->where)) {
  236. // If the different groups are combined with the OR operator, we have to
  237. // add a new OR filter to the query to which the filters for the groups
  238. // will be added.
  239. if ($this->group_operator === 'OR') {
  240. $base = $this->query->createFilter('OR');
  241. $this->query->filter($base);
  242. }
  243. else {
  244. $base = $this->query;
  245. }
  246. // Add a nested filter for each filter group, with its set conjunction.
  247. foreach ($this->where as $group_id => $group) {
  248. if (!empty($group['conditions']) || !empty($group['filters'])) {
  249. $group += array('type' => 'AND');
  250. // For filters without a group, we want to always add them directly to
  251. // the query.
  252. $filter = ($group_id === '') ? $this->query : $this->query->createFilter($group['type']);
  253. if (!empty($group['conditions'])) {
  254. foreach ($group['conditions'] as $condition) {
  255. list($field, $value, $operator) = $condition;
  256. $filter->condition($field, $value, $operator);
  257. }
  258. }
  259. if (!empty($group['filters'])) {
  260. foreach ($group['filters'] as $nested_filter) {
  261. $filter->filter($nested_filter);
  262. }
  263. }
  264. // If no group was given, the filters were already set on the query.
  265. if ($group_id !== '') {
  266. $base->filter($filter);
  267. }
  268. }
  269. }
  270. }
  271. // Initialize the pager and let it modify the query to add limits.
  272. $view->init_pager();
  273. $this->pager->query();
  274. // Set the search ID, if it was not already set.
  275. if ($this->query->getOption('search id') == get_class($this->query)) {
  276. $this->query->setOption('search id', 'search_api_views:' . $view->name . ':' . $view->current_display);
  277. }
  278. // Add the "search_api_bypass_access" option to the query, if desired.
  279. if (!empty($this->options['search_api_bypass_access'])) {
  280. $this->query->setOption('search_api_bypass_access', TRUE);
  281. }
  282. // If the View and the Panel conspire to provide an overridden path then
  283. // pass that through as the base path.
  284. if (!empty($this->view->override_path) && strpos(current_path(), $this->view->override_path) !== 0) {
  285. $this->query->setOption('search_api_base_path', $this->view->override_path);
  286. }
  287. // Save query information for Views UI.
  288. $view->build_info['query'] = (string) $this->query;
  289. }
  290. /**
  291. * {@inheritdoc}
  292. */
  293. public function alter(&$view) {
  294. parent::alter($view);
  295. drupal_alter('search_api_views_query', $view, $this);
  296. }
  297. /**
  298. * Executes the query and fills the associated view object with according
  299. * values.
  300. *
  301. * Values to set: $view->result, $view->total_rows, $view->execute_time,
  302. * $view->pager['current_page'].
  303. */
  304. public function execute(&$view) {
  305. if ($this->errors || $this->abort) {
  306. if (error_displayable()) {
  307. foreach ($this->errors as $msg) {
  308. drupal_set_message(check_plain($msg), 'error');
  309. }
  310. }
  311. $view->result = array();
  312. $view->total_rows = 0;
  313. $view->execute_time = 0;
  314. return;
  315. }
  316. // Calculate the "skip result count" option, if it wasn't already set to
  317. // FALSE.
  318. $skip_result_count = $this->query->getOption('skip result count', TRUE);
  319. if ($skip_result_count) {
  320. $skip_result_count = !$this->pager || (!$this->pager->use_count_query() && empty($view->get_total_rows));
  321. $this->query->setOption('skip result count', $skip_result_count);
  322. }
  323. try {
  324. // Trigger pager pre_execute().
  325. if ($this->pager) {
  326. $this->pager->pre_execute($this->query);
  327. }
  328. // Views passes sometimes NULL and sometimes the integer 0 for "All" in a
  329. // pager. If set to 0 items, a string "0" is passed. Therefore, we unset
  330. // the limit if an empty value OTHER than a string "0" was passed.
  331. if (!$this->limit && $this->limit !== '0') {
  332. $this->limit = NULL;
  333. }
  334. // Set the range. (We always set this, as there might even be an offset if
  335. // all items are shown.)
  336. $this->query->range($this->offset, $this->limit);
  337. $start = microtime(TRUE);
  338. // Execute the search.
  339. $results = $this->query->execute();
  340. $this->search_api_results = $results;
  341. // Store the results.
  342. if (!$skip_result_count) {
  343. $this->pager->total_items = $view->total_rows = $results['result count'];
  344. if (!empty($this->pager->options['offset'])) {
  345. $this->pager->total_items -= $this->pager->options['offset'];
  346. }
  347. $this->pager->update_page_info();
  348. }
  349. $view->result = array();
  350. if (!empty($results['results'])) {
  351. $this->addResults($results['results'], $view);
  352. }
  353. // We shouldn't use $results['performance']['complete'] here, since
  354. // extracting the results probably takes considerable time as well.
  355. $view->execute_time = microtime(TRUE) - $start;
  356. // Trigger pager post_execute().
  357. if ($this->pager) {
  358. $this->pager->post_execute($view->result);
  359. }
  360. }
  361. catch (Exception $e) {
  362. $this->errors[] = $e->getMessage();
  363. // Recursion to get the same error behaviour as above.
  364. $this->execute($view);
  365. }
  366. }
  367. /**
  368. * Aborts this search query.
  369. *
  370. * Used by handlers to flag a fatal error which shouldn't be displayed but
  371. * still lead to the view returning empty and the search not being executed.
  372. *
  373. * @param string|null $msg
  374. * Optionally, a translated, unescaped error message to display.
  375. */
  376. public function abort($msg = NULL) {
  377. if ($msg) {
  378. $this->errors[] = $msg;
  379. }
  380. $this->abort = TRUE;
  381. }
  382. /**
  383. * Helper function for adding results to a view in the format expected by the
  384. * view.
  385. */
  386. protected function addResults(array $results, $view) {
  387. $rows = array();
  388. $missing = array();
  389. $items = array();
  390. // First off, we try to gather as much field values as possible without
  391. // loading any items.
  392. foreach ($results as $id => $result) {
  393. if (!empty($this->options['entity_access']) && ($entity_type = $this->index->getEntityType())) {
  394. $entity = $this->index->loadItems(array($id));
  395. if (!$entity || !entity_access('view', $entity_type, reset($entity))) {
  396. continue;
  397. }
  398. }
  399. $row = array();
  400. // Include the loaded item for this result row, if present, or the item
  401. // ID.
  402. if (!empty($result['entity'])) {
  403. $row['entity'] = $result['entity'];
  404. }
  405. else {
  406. $row['entity'] = $id;
  407. }
  408. $row['_entity_properties']['search_api_relevance'] = $result['score'];
  409. $row['_entity_properties']['search_api_excerpt'] = empty($result['excerpt']) ? '' : $result['excerpt'];
  410. // Gather any fields from the search results.
  411. if (!empty($result['fields'])) {
  412. $row['_entity_properties'] += search_api_get_sanitized_field_values($result['fields']);
  413. }
  414. // Check whether we need to extract any properties from the result item.
  415. $missing_fields = array_diff_key($this->fields, $row['_entity_properties']);
  416. if ($missing_fields) {
  417. $missing[$id] = $missing_fields;
  418. if (is_object($row['entity'])) {
  419. $items[$id] = $row['entity'];
  420. }
  421. else {
  422. $ids[] = $id;
  423. }
  424. }
  425. // Save the row values for adding them to the Views result afterwards.
  426. $rows[$id] = (object) $row;
  427. }
  428. // Load items of those rows which haven't got all field values, yet.
  429. if (!empty($ids)) {
  430. $items += $this->index->loadItems($ids);
  431. }
  432. // $items now includes all loaded items from which fields still need to be
  433. // extracted.
  434. foreach ($items as $id => $item) {
  435. // Extract item properties.
  436. $wrapper = $this->index->entityWrapper($item, FALSE);
  437. $rows[$id]->_entity_properties += $this->extractFields($wrapper, $missing[$id]);
  438. $rows[$id]->entity = $item;
  439. }
  440. // Finally, add all rows to the Views result set.
  441. $view->result = array_values($rows);
  442. }
  443. /**
  444. * Helper function for extracting all necessary fields from a result item.
  445. *
  446. * Usually, this method isn't needed anymore as the properties are now
  447. * extracted by the field handlers themselves.
  448. */
  449. protected function extractFields(EntityMetadataWrapper $wrapper, array $all_fields) {
  450. $fields = array();
  451. foreach ($all_fields as $key => $true) {
  452. $fields[$key]['type'] = 'string';
  453. }
  454. $fields = search_api_extract_fields($wrapper, $fields, array('sanitized' => TRUE));
  455. $ret = array();
  456. foreach ($all_fields as $key => $true) {
  457. $ret[$key] = isset($fields[$key]['value']) ? $fields[$key]['value'] : '';
  458. }
  459. return $ret;
  460. }
  461. /**
  462. * Returns the according entity objects for the given query results.
  463. *
  464. * This is necessary to support generic entity handlers and plugins with this
  465. * query backend.
  466. *
  467. * If the current query isn't based on an entity type, the method will return
  468. * an empty array.
  469. */
  470. public function get_result_entities($results, $relationship = NULL, $field = NULL) {
  471. list($type, $wrappers) = $this->get_result_wrappers($results, $relationship, $field);
  472. $return = array();
  473. foreach ($wrappers as $i => $wrapper) {
  474. try {
  475. // Get the entity ID beforehand for possible watchdog messages.
  476. $id = $wrapper->value(array('identifier' => TRUE));
  477. // Only add results that exist.
  478. if ($entity = $wrapper->value()) {
  479. $return[$i] = $entity;
  480. }
  481. else {
  482. watchdog('search_api_views', 'The search index returned a reference to an entity with ID @id, which does not exist in the database. Your index may be out of sync and should be rebuilt.', array('@id' => $id), WATCHDOG_ERROR);
  483. }
  484. }
  485. catch (EntityMetadataWrapperException $e) {
  486. watchdog_exception('search_api_views', $e, "%type while trying to load search result entity with ID @id: !message in %function (line %line of %file).", array('@id' => $id), WATCHDOG_ERROR);
  487. }
  488. }
  489. return array($type, $return);
  490. }
  491. /**
  492. * Returns the according metadata wrappers for the given query results.
  493. *
  494. * This is necessary to support generic entity handlers and plugins with this
  495. * query backend.
  496. */
  497. public function get_result_wrappers($results, $relationship = NULL, $field = NULL) {
  498. $type = $this->index->getEntityType() ? $this->index->getEntityType() : $this->index->item_type;
  499. $wrappers = array();
  500. $load_items = array();
  501. foreach ($results as $row_index => $row) {
  502. if (isset($row->entity)) {
  503. // If this entity isn't load, register it for pre-loading.
  504. if (!is_object($row->entity)) {
  505. $load_items[$row->entity] = $row_index;
  506. }
  507. else {
  508. $wrappers[$row_index] = $this->index->entityWrapper($row->entity);
  509. }
  510. }
  511. }
  512. // If the results are entities, we pre-load them to make use of a multiple
  513. // load. (Otherwise, each result would be loaded individually.)
  514. if (!empty($load_items)) {
  515. $items = $this->index->loadItems(array_keys($load_items));
  516. foreach ($items as $id => $item) {
  517. $wrappers[$load_items[$id]] = $this->index->entityWrapper($item);
  518. }
  519. }
  520. // Apply the relationship, if necessary.
  521. $selector_suffix = '';
  522. if ($field && ($pos = strrpos($field, ':'))) {
  523. $selector_suffix = substr($field, 0, $pos);
  524. }
  525. if ($selector_suffix || ($relationship && !empty($this->view->relationship[$relationship]))) {
  526. // Use EntityFieldHandlerHelper to compute the correct data selector for
  527. // the relationship.
  528. $handler = (object) array(
  529. 'view' => $this->view,
  530. 'relationship' => $relationship,
  531. 'real_field' => '',
  532. );
  533. $selector = EntityFieldHandlerHelper::construct_property_selector($handler);
  534. $selector .= ($selector ? ':' : '') . $selector_suffix;
  535. list($type, $wrappers) = EntityFieldHandlerHelper::extract_property_multiple($wrappers, $selector);
  536. }
  537. return array($type, $wrappers);
  538. }
  539. /**
  540. * API function for accessing the raw Search API query object.
  541. *
  542. * @return SearchApiQueryInterface
  543. * The search query object used internally by this handler.
  544. */
  545. public function getSearchApiQuery() {
  546. return $this->query;
  547. }
  548. /**
  549. * API function for accessing the raw Search API results.
  550. *
  551. * @return array
  552. * An associative array containing the search results, as specified by
  553. * SearchApiQueryInterface::execute().
  554. */
  555. public function getSearchApiResults() {
  556. return $this->search_api_results;
  557. }
  558. //
  559. // Query interface methods (proxy to $this->query)
  560. //
  561. public function createFilter($conjunction = 'AND', $tags = array()) {
  562. if (!$this->errors) {
  563. return $this->query->createFilter($conjunction, $tags);
  564. }
  565. }
  566. public function keys($keys = NULL) {
  567. if (!$this->errors) {
  568. $this->query->keys($keys);
  569. }
  570. return $this;
  571. }
  572. public function fields(array $fields) {
  573. if (!$this->errors) {
  574. $this->query->fields($fields);
  575. }
  576. return $this;
  577. }
  578. /**
  579. * Adds a nested filter to the search query object.
  580. *
  581. * If $group is given, the filter is added to the relevant filter group
  582. * instead.
  583. */
  584. public function filter(SearchApiQueryFilterInterface $filter, $group = NULL) {
  585. if (!$this->errors) {
  586. $this->where[$group]['filters'][] = $filter;
  587. }
  588. return $this;
  589. }
  590. /**
  591. * Set a condition on the search query object.
  592. *
  593. * If $group is given, the condition is added to the relevant filter group
  594. * instead.
  595. */
  596. public function condition($field, $value, $operator = '=', $group = NULL) {
  597. if (!$this->errors) {
  598. $this->where[$group]['conditions'][] = array($field, $value, $operator);
  599. }
  600. return $this;
  601. }
  602. public function sort($field, $order = 'ASC') {
  603. if (!$this->errors) {
  604. $this->query->sort($field, $order);
  605. }
  606. return $this;
  607. }
  608. public function range($offset = NULL, $limit = NULL) {
  609. if (!$this->errors) {
  610. $this->query->range($offset, $limit);
  611. }
  612. return $this;
  613. }
  614. public function getIndex() {
  615. return $this->index;
  616. }
  617. public function &getKeys() {
  618. if (!$this->errors) {
  619. return $this->query->getKeys();
  620. }
  621. $ret = NULL;
  622. return $ret;
  623. }
  624. public function getOriginalKeys() {
  625. if (!$this->errors) {
  626. return $this->query->getOriginalKeys();
  627. }
  628. }
  629. public function &getFields() {
  630. if (!$this->errors) {
  631. return $this->query->getFields();
  632. }
  633. $ret = NULL;
  634. return $ret;
  635. }
  636. public function getFilter() {
  637. if (!$this->errors) {
  638. return $this->query->getFilter();
  639. }
  640. }
  641. public function &getSort() {
  642. if (!$this->errors) {
  643. return $this->query->getSort();
  644. }
  645. $ret = NULL;
  646. return $ret;
  647. }
  648. public function getOption($name, $default = NULL) {
  649. if (!$this->errors) {
  650. return $this->query->getOption($name, $default);
  651. }
  652. return $default;
  653. }
  654. public function setOption($name, $value) {
  655. if (!$this->errors) {
  656. return $this->query->setOption($name, $value);
  657. }
  658. return NULL;
  659. }
  660. public function &getOptions() {
  661. if (!$this->errors) {
  662. return $this->query->getOptions();
  663. }
  664. $ret = NULL;
  665. return $ret;
  666. }
  667. }