@param string $query
@param int    $code

@return InvalidServerResponse
500908
public static function create(string $query, int $code = 0) : self
    {
        return new self(sprintf('Server returned an invalid response (%d) for query "%s". We could not parse it.', $code, $query));
    }
178205
public function execQuery(Query $query)
    {
        $this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        $this->connection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, $query->isSingle());
        $resultDataType = $query->getResultDataType();

        foreach ($query as $sql) {
            $sqlResult = $sql->getResult();
            if ($resultDataType instanceof DataInterface) {
                $sqlResult->setDataType($resultDataType);
            }

            try {
                if ($this->error->hasError()) {
                    throw new \PDOException($this->error->getMessage());
                    break;
                }
                $sqlQuery = $sql->toString();
                $totalRows = 0;
                if ($sql->getCommand() == 'SELECT' && !$query->isSingle()) {
                    $template = '{SQL}';
                    $templateCounter = 'SELECT COUNT(*) totalRows FROM (%s) fakeTable';
                    $templateParams = array(
                        'SQL' => $sqlQuery,
                        'LIMIT' => $query->getLimit(),
                        'OFFSET' => $query->getOffset(),
                    );
                    if ($query->getLimit()) {
                        switch ($this->config->getType()) {
                            case 'firebird':
                                $template = 'SELECT FIRST {LIMIT} SKIP {OFFSET} * FROM ({SQL}) fakeTable';
                            break;
                            case 'oci':
                                $templateCounter = 'SELECT COUNT(*) "totalRows" FROM (%s) "fakeTable"';
                                $template = 'SELECT a.* FROM (SELECT b.*, rownum "[]" FROM '.
                                            '({SQL}) b WHERE rownum <= {LIMIT}) a WHERE "[]" > {OFFSET}';
                            break;
                            default:
                                $template = 'SELECT * FROM ({SQL}) fakeTable LIMIT {LIMIT} OFFSET {OFFSET}';
                            break;
                        }
                    }

                    $resultCounter = $this->connection->prepare(sprintf($templateCounter, $sqlQuery));
                    $resultCounter->execute();
                    $totalRows = $resultCounter->fetch();

                    $sqlResult->setTotalRows((int) @$totalRows['totalRows']);
                    foreach ($templateParams as $key => $val) {
                        $template = str_replace('{'.$key.'}', $val, $template);
                    }
                    $sqlQuery = $template;
                }

                $result = $this->connection->prepare($sqlQuery);
                $stmt = $result->execute();
                $sql->execute();

                if ($sql->isRead()) {
                    $columns = $this->_define_column_types($result);

                    $sqlResult->setColumnTypes($columns);
                    $sqlResult->setAffected(0);
                    $sqlResult->setStartRow($query->getOffset());
                    if (!$sqlResult->getTotalRows()) {
                        $sqlResult->setTotalRows($result->rowCount());
                    }

                    $rows = $result->fetchAll(\PDO::FETCH_ASSOC);

                    foreach ($rows as $row) {
                        $data = $this->_merge_values($sql->getResult()->getDataType(), $row, $columns);
                        $sqlResult->add($data);
                    }

                    $sqlResult->setTotalShows($sqlResult->length());
                    $sqlResult->setEnd(microtime(true));
                } elseif ($sql->isWrite() || $sql->isDDL()) {
                    $insertId = $this->connection->lastInsertId();
                    $affected = $result->rowCount();
                    $endTime = microtime(true);
                    $sqlResult->setEnd($endTime);

                    $columns = array(
                        'affected' => 'integer',
                        'seconds' => 'double',
                    );

                    $row = array(
                        'affected' => $affected,
                        'seconds' => $sqlResult->getSeconds(),
                    );

                    $sqlResult->setColumnTypes($columns);
                    $sqlResult->setAffected($affected);

                    $data = new Data();
                    $this->_merge_values($data, $row, $columns);
                    $sqlResult->add($data);
                    $sqlResult->setInsertId($insertId);
                }
            } catch (\PDOException $e) {
                $sql->execute(false);
                $this->error->setMessage($e->getMessage().". \n".$sql->toString());
                $sqlResult->setEnd(microtime(true));
            } catch (\Exception $e) {
                $sql->execute(false);
                $this->error->setMessage($e->getMessage().". \n".$sql->toString());
                $sqlResult->setEnd(microtime(true));
            }
        }
    }
1166128
protected function setQuery($query)
    {
        $this->uriString = null;

        $query = ltrim($query, '?');

        if (strpos($query, '#') !== false) {
            throw new InvalidArgumentException(
                'Query string must not include a URI fragment.'
            );
        }

        $this->query = static::encode($query);

        return $this;
    }
91906
public function getQueryHandler(string $code): QueryHandlerInterface
    {
        if (!array_key_exists($code, $this->queryHandlers)) {
            return $this->buildQueryHandler($code);
        }

        return $this->queryHandlers[$code];
    }
91161
public function query($query)
    {
        $results = $this->connection->{$this->type}(
            $this->getDn(),
            $query,
            $this->getSelects(),
            $onlyAttributes = false,
            $this->limit
        );

        return $this->newProcessor()->process($results);
    }
443198
function setQuery($query)
    {
        if ($query !== null) {
            $q = $this->getQuery();
            $q->with($q::parseWith($query));
        }

        return $this;
    }
794927
function query(string $query): \React\Promise\PromiseInterface {
        if($this->goingAway) {
            return \React\Promise\reject((new \Plasma\Exception('Client is closing all connections')));
        }
        
        $connection = $this->getOptimalConnection();
        
        return $connection->query($this, $query)->then(null, function (\Throwable $error) use (&$connection) {
            $this->checkinConnection($connection);
            throw $error;
        });
    }
650272
public static Query create(String query) 
		throws QueryParserException
	{
		QueryTokenizer tokenizer = new QueryTokenizerImpl();
		QueryParser parser = new QueryParserImpl();

		return parser.parse(tokenizer.tokenize(query));
	}
1020915
protected function validate($query)
    {
        if ($this->client->getIndex() == null) {
            throw new SearchException("Index cannot be null");
        }
        if ($this->client->getType() == null) {
            throw new SearchException("Type cannot be null");
        }
        if ($query == null) {
            throw new SearchException("Query can't be null");
        }
    }
147286
public function prepare($query)
    {
        $this->connect();
        $isObject = $query instanceof Query;
        $statement = $this->_connection->prepare($isObject ? $query->sql() : $query);
        $result = new MysqlStatement($statement, $this);
        if ($isObject && $query->isBufferedResultsEnabled() === false) {
            $result->bufferResults(false);
        }

        return $result;
    }
1000025
public function request(&$query)
    {
        global $_web_access_compress_reply;
        global $_web_access_post_xmlrpc;
        global $_web_access_retry_timeout;
        global $_web_access_retry_timeout_max;

        $query['State'] = 'BAD';
        $query['HDatas'] = '';
        $query['Datas'] = '';
        $query['DatasSize'] = 0;
        $query['DatasSent'] = 0;
        $query['Response'] = '';
        $query['ResponseSize'] = 0;
        $query['Headers'] = array();
        $query['Close'] = false;
        $query['Times'] = array(
            'open' => array(-1.0, -1.0),
            'send' => array(-1.0, -1.0),
            'receive' => array(-1.0, -1.0, 0),
        );


        // if async, in error, and maximal timeout, then forget the request and return false.
        if (($query['Callback'] != null) && ($this->_state == 'BAD')) {
            if ($this->_bad_timeout > $_web_access_retry_timeout_max) {
                $this->console->writeln($this->_webaccess_str.'$f00Request refused for consecutive errors $555('.$this->_bad_timeout
                    ." / ".$_web_access_retry_timeout_max.")");

                return false;
            } else {
                // if not max then accept the request
                // and try a request (minimum $_web_access_retry_timeout/2 after previous try)
                $time = time();
                $timeout = ($this->_bad_timeout / 2) - ($time - $this->_bad_time);
                if ($timeout < 0) {
                    $timeout = 0;
                }
                $this->_bad_time = $time - $this->_bad_timeout + $timeout;
            }
        }

        // build datas to send
        if (($query['Callback'] == null) || (is_array($query['Callback']) &&
                isset($query['Callback'][0]) &&
                is_callable($query['Callback'][0]))
        ) {

            if (is_string($query['QueryDatas']) && strlen($query['QueryDatas']) > 0) {
                $msg = "POST ".$query['Path']." HTTP/1.1\r\n";
                $msg .= "Host: ".$this->_host."\r\n";
                $msg .= "User-Agent: ".$this->_agent."\r\n";
                $msg .= "Cache-Control: no-cache\r\n";

                if ($_web_access_compress_reply) {
                    // ask compression of response if gzdecode() and/or gzinflate() is available
                    if (function_exists('gzdecode') && function_exists('gzinflate')) {
                        $msg .= "Accept-Encoding: deflate, gzip\r\n";
                    } elseif (function_exists('gzdecode')) {
                        $msg .= "Accept-Encoding: gzip\r\n";
                    } elseif (function_exists('gzinflate')) {
                        $msg .= "Accept-Encoding: deflate\r\n";
                    }
                }

                // echo "\nData:\n\n".$query['QueryDatas']."\n";  // for debug purposes, don't remove!

                if ($query['IsXmlrpc'] === true) {
                    if ($_web_access_post_xmlrpc) {
                        $msg .= "Content-type: application/x-www-form-urlencoded; charset=UTF-8\r\n";

                        echo "\n=========================== Data =================================\n\n".$query['Datas']."\n";

                        $query['QueryDatas'] = "xmlrpc=".urlsafe_base64_encode($query['QueryDatas']);
                    } else {
                        $msg .= "Content-type: text/xml; charset=UTF-8\r\n";
                    }

                    if ($this->_compress_request == 'gzip' && function_exists('gzencode')) {
                        $msg .= "Content-Encoding: gzip\r\n";
                        $query['QueryDatas'] = gzencode($query['QueryDatas']);
                    } elseif ($this->_compress_request == 'deflate' && function_exists('gzdeflate')) {
                        $msg .= "Content-Encoding: deflate\r\n";
                        $query['QueryDatas'] = gzdeflate($query['QueryDatas']);
                    }
                } elseif (is_string($query['IsXmlrpc'])) {
                    $msg .= "Content-type: ".$query['IsXmlrpc']."\r\n";
                    $msg .= "Accept: */*\r\n";
                } else {
                    $msg .= "Content-type: ".$query['MimeType']."\r\n";
                    $msg .= "Accept: */*\r\n";
                }

                $msg .= "Content-length: ".strlen($query['QueryDatas'])."\r\n";

                $query['HDatas'] = $msg;

                $query['State'] = 'OPEN';
                $query['Retries'] = 0;

                // print_r($msg); for debugging purposes - don't remove

                // add the query in spool
                $this->_spool[] = &$query;

                if ($query['Callback'] == null) {
                    $this->_wait = true;
                    $this->_open($query['OpenTimeout'], $query['WaitTimeout']); // wait more in not callback mode
                    $this->_spool = array();
                    $this->_wait = false;

                    return $query['Response'];
                } else {
                    $this->_open();
                }
            } else {
                $msg = "GET ".$query['Path']." HTTP/1.1\r\n";
                $msg .= "Host: ".$this->_host."\r\n";
                $msg .= "User-Agent: ".$this->_agent."\r\n";
                $msg .= "Cache-Control: no-cache\r\n";
                if ($_web_access_compress_reply) {
                    // ask compression of response if gzdecode() and/or gzinflate() is available
                    if (function_exists('gzdecode') && function_exists('gzinflate')) {
                        $msg .= "Accept-Encoding: deflate, gzip\r\n";
                    } elseif (function_exists('gzdecode')) {
                        $msg .= "Accept-Encoding: gzip\r\n";
                    } elseif (function_exists('gzinflate')) {
                        $msg .= "Accept-Encoding: deflate\r\n";
                    }
                }
                $msg .= "Content-type: ".$query['MimeType']."; charset=UTF-8\r\n";
                $msg .= "Content-length: ".strlen($query['QueryDatas'])."\r\n";
                $query['HDatas'] = $msg;

                $query['State'] = 'OPEN';
                $query['Retries'] = 0;

                // add the query in spool
                $this->_spool[] = &$query;

                if ($query['Callback'] == null) {
                    $this->_wait = true;
                    $this->_open($query['OpenTimeout'], $query['WaitTimeout']); // wait more in not callback mode
                    $this->_spool = array();
                    $this->_wait = false;

                    return $query['Response'];
                } else {
                    $this->_open();
                }
            }

        } else {

            $this->console->writeln($this->_webaccess_str.'Bad callback function:$fff '.$query['Callback']);

            return false;
        }

        return true;
    }
167774
public function queriedDelete(Query $query)
    {
        if ($query->getLimit()
            || $query->getSort()
            || ($query instanceof RqlQuery && $query->getGroupBy())
            || $query->getSelect()) {
            throw new InvalidArgumentException('Only where clause allowed for delete');
        }

        $conditionBuilder = new SqlConditionBuilder(
            $this->getDbTable()->getAdapter(),
            $this->getDbTable()->getTable()
        );

        $sql = new Sql($this->getDbTable()->getAdapter());
        $delete = $sql->delete($this->getDbTable()->getTable());
        $delete->where($conditionBuilder->__invoke($query->getQuery()));
        $sqlString = $sql->buildSqlString($delete);

        $adapter = $this->dbTable->getAdapter();
        $shouldDeletedIds = array_map(function ($item) {
            return $item[$this->getIdentifier()];
        }, $this->query($query));

        try {
            $statement = $adapter->getDriver()->createStatement($sqlString);
            $result = $statement->execute();
        } catch (\Throwable $e) {
            throw new DataStoreException("Can't delete records using query", 0, $e);
        }

        if (count($shouldDeletedIds) === $result->getAffectedRows()) {
            return $shouldDeletedIds;
        } else {
            $result = $this->query($query);

            foreach ($result as $record) {
                if (in_array($record[$this->getIdentifier()], $shouldDeletedIds)) {
                    unset($shouldDeletedIds[$record[$this->getIdentifier()]]);
                }
            }
        }

        return $shouldDeletedIds;
    }
1362683
public function load(Queries\Interfaces\SearchQueryInterface $query): ServiceInterface
    {
        $this->query = $query;

        $parameters = [
            static::INPUT => trim($this->query->getInput()),
            static::SESSION_TOKEN => $this->query->getToken(),
            static::LANGUAGE => $this->query->getLanguage()->getValue(),
            static::COMPONENTS => static::COUNTRY . mb_strtolower($this->config->getCountry()),
            static::KEY => $this->config->getKey(),
        ];

        if ($this->query instanceof Queries\Interfaces\CitySearchInterface) {
            $parameters[static::TYPE] = static::CITIES;
        } elseif ($this->query instanceof Queries\Interfaces\StreetSearchInterface) {
            $parameters[static::INPUT] = trim($this->query->getType()) . ' ' . $parameters[static::INPUT];
            $parameters[static::TYPE] = static::ADDRESS;
        } else {
            throw new Exceptions\InvalidQueryType($this->query);
        }

        $response = $this->client->request('GET', $this->config->getUrl(), [
            GuzzleHttp\RequestOptions::QUERY => $parameters,
        ]);

        $responseBody = $response->getBody();
        $data = json_decode($responseBody, true);

        if (json_last_error() !== JSON_ERROR_NONE || !array_key_exists(static::STATUS, $data)) {
            throw new Exceptions\InvalidResponse($response);
        }

        $status = new Enums\SearchStatus($data[static::STATUS]);

        $this->validateStatus($status);

        if ($this->existPredictionWrapper($data)) {
            $this->locations = $this->fetchResults($data[static::PREDICTION_COLLECTION]);
        }

        return $this;
    }
349144
public function execute($query, $args) {
		/*
		 * INITIALIZE
		 */
		
		//validate query
		if (!is_string($query) || empty($query))
			throw new \InvalidArgumentException("Query is not a valid string");

		//open connection
		$this->driver->connect();
		
		/*
		 * CACHE CONTROL
		 */
		
		$cachedValue = $resultMap = null;
		$cacheable = false; //if mapped value is cacheable
		
		//check if there is a value stored in cache with the given key
		if (array_key_exists('cache.key', $this->config) && isset($this->cacheProvider)) {
			//build cache key
			$cacheKey = (new CacheKeyFormatter($this->typeManager))->format($this->config['cache.key'], $args, $this->config);

			//check if key is present
			if ($this->cacheProvider->exists($cacheKey)) {
				$cachedValue = $this->cacheProvider->fetch($cacheKey);
				
				if (is_array($cachedValue) || is_object($cachedValue)) {
					//get cache metadata
					$cacheMeta = $this->extractCacheMetadata($this->config['cache.metakey'], $cachedValue);
					
					//no metadata, we didn't stored it
					if (is_null($cacheMeta)) 
						return $cachedValue;
					
					//create mapper instance
					$mapper = (new \ReflectionClass($cacheMeta->class))->newInstance($this->driver->buildTypeManager(), $cacheMeta->resultMap);
					
					if (!empty($cacheMeta->groups))
						$mapper->setGroupKeys($cacheMeta->groups);
					
					//build mapping callback (method tells if this is a list or a single row)
					$mappingCallback = [$mapper, $cacheMeta->method];
					
					//set resultmap (allows further processing)
					$resultMap = $cacheMeta->resultMap;
				}
				else
					return $cachedValue;
			}
		}
		
		if (is_null($cachedValue)) {
			/*
			 * GENERATE QUERY
			 */
				
			//build statement
			$stmt = $this->driver->buildStatement($this->typeManager)->format($query, $args, $this->config);
			
			//debug query
			if (array_key_exists('callback.debug', $this->config)) 
				call_user_func($this->config['callback.debug'], $stmt);
			
			/*
			 * PARSE MAPPING EXPRESSION
			 */
	
			//build mapping callback
			if (array_key_exists('map.type', $this->config)) {
				//get mapping type
				$mappingType = $this->config['map.type'];
				
				//object mapping type: object, object:class, object[column], object[column:type], etc
				if (preg_match(self::OBJECT_TYPE_REGEX, $mappingType, $matches)) {
					//get class, if any
					if (empty($matches[1])) { //no class defined, use default
						$defaultClass = 'stdClass';
						$resultMap = array_key_exists('map.result', $this->config) ? $this->config['map.result'] : null; //obtain result map
						$mapper = new StdClassMapper($this->typeManager, $resultMap);
					}
					else {
						//remove leading ':'
						$defaultClass = strtolower($matches[1]);
						$resultMap = array_key_exists('map.result', $this->config) ? $this->config['map.result'] : null;
						
						//get mapping class
						if ($defaultClass == 'stdclass')
							$mapper = new StdClassMapper($this->typeManager, $resultMap);
						elseif ($defaultClass == 'arrayobject')
							$mapper = new ArrayObjectMapper($this->typeManager, $resultMap);
						elseif (Profiler::getClassProfile($matches[1])->isEntity()) { //check if defined class is an entity
							$mapper = new EntityMapper($this->typeManager, $matches[1]);
							$resultMap = $matches[1];
						}
						else {
							$mapper = new ObjectMapper($this->typeManager, $matches[1]);
							$resultMap = null;
						}
					}
					
					//generate a new object mapper object
					$group = $groupType = $index = $indexType = null;
					
					if (count($matches) > 2) {
						$mappingCallback = [$mapper, 'mapList'];
					
						//obtain group
						if (array_key_exists('callback.group', $this->config)) {
							$group = $this->config['callback.group'];
							$groupType = 'callable';
						}
						elseif (isset($matches[2]) && ($matches[2] == '0' || !empty($matches[2]))) {
							$group = $matches[2];
							$groupType = (isset($matches[3]) && !empty($matches[3])) ? $matches[3] : null;
						}
					
						//obtain index
						if (array_key_exists('callback.index', $this->config)) {
							$index = $this->config['callback.index'];
							$indexType = 'callable';
						}
						elseif (isset($matches[5]) && ($matches[5] == '0' || !empty($matches[5]))) {
							$index = $matches[5];
							$indexType = (isset($matches[6]) && !empty($matches[6])) ? $matches[6] : null;
						}
					
						//add index and group to mapper parameters
						$mappingParams = [$index, $indexType, $group, $groupType];
					}
					else
						$mappingCallback = [$mapper, 'mapResult']; //set default method
				}
				//array mapping type: array, array[], array[column], array[column:type]
				elseif (preg_match(self::ARRAY_TYPE_REGEX, $mappingType, $matches)) {
					//obtain result map
					$resultMap = array_key_exists('map.result', $this->config) ? $this->config['map.result'] : null;
						
					//generate a new array mapper object
					$mapper = new ArrayMapper($this->typeManager, $resultMap);
					
					if (count($matches) > 1) {
						$mappingCallback = [$mapper, 'mapList'];
						$group = $groupType = $index = $indexType = null;
					
						//obtain group and group type
						if (array_key_exists('callback.group', $this->config)) {
							$group = $this->config['callback.group'];
							$groupType = 'callable';
						}
						elseif (isset($matches[1]) && ($matches[1] == '0' || !empty($matches[1]))) {
							$group = $matches[1];
							$groupType = (isset($matches[2]) && !empty($matches[2])) ? $matches[2] : null;
						}
					
						//obtain index and index type
						if (array_key_exists('callback.index', $this->config)) {
							$index = $this->config['callback.index'];
							$indexType = 'callable';
						}
						elseif (isset($matches[4]) && ($matches[4] == '0' || !empty($matches[4]))) {
							$index = $matches[4];
							$indexType = (isset($matches[5]) && !empty($matches[5])) ? $matches[5] : null;
						}
							
						//add index and group to mapper parameters
						$mappingParams = [$index, $indexType, $group, $groupType];
					}
					else
						$mappingCallback = [$mapper, 'mapResult'];
				}
				//simple mapping type: integer, string, float, etc
				elseif (preg_match(self::SIMPLE_TYPE_REGEX, $mappingType, $matches)) {					
					//get type handler
					$typeHandler = $this->typeManager->getTypeHandler($matches[1]);
					
					if ($typeHandler === false)
						throw new \InvalidArgumentException("Unknown type '{$matches[1]}'");
						
					//create mapper instance
					$mapper = new ScalarTypeMapper($typeHandler);
						
					//set mapping callback
					$mappingCallback = [$mapper, empty($matches[2]) ? 'mapResult' : 'mapList'];
				}
				else
					throw new \InvalidArgumentException("Unrecognized mapping expression '$mappingType'");
			}
			else {
				//obtain result map
				$resultMap = array_key_exists('map.result', $this->config) ? $this->config['map.result'] : null;
					
				//generate mapper
				$mapper = new ArrayMapper($this->typeManager, $resultMap);
					
				//use default mapping type
				$mappingCallback = [$mapper, 'mapList'];
				
				//check for group callback
				if (array_key_exists('callback.group', $this->config)) {
					$group = $this->config['callback.group'];
					$groupType = 'callable';
				}
				else
					$group = $groupType = null;
				
				//check for index callback
				if (array_key_exists('callback.index', $this->config)) {
					$index = $this->config['callback.index'];
					$indexType = 'callable';
				}
				else
					$index = $indexType = null;
				
				$mappingParams = [$index, $indexType, $group, $groupType];
			}
			
			/*
			 * EXECUTE QUERY
			 */
				
			//run query
			$result = $this->driver->query($stmt);
				
			//check query execution
			if ($result === false)
				$this->driver->throwQueryException($stmt);
			
			//check if result is successful
			if ($result === true) {
				//free result
				$this->driver->freeResult($result);
				return true;
			}
			
			/*
			 * INVOKE EMPTY RESULT CALLBACK
			 */
				
			$ri = $this->driver->buildResultIterator($result);
				
			//check if result is empty
			if ($ri->countRows() === 0) {
				if (array_key_exists('callback.empty', $this->config))
					return call_user_func($this->config['callback.empty'], $result);
			}
			else
				$cacheable = true;
			
			/*
			 * ADD CUSTOM MAPPING OPTIONS
			 */
				
			//add defined mapping parameters
			if (array_key_exists('map.params', $this->config)) {
				if (!empty($mappingParams))
					$mappingParams = array_merge($mappingParams, $this->config['map.params']);
				else
					$mappingParams = $this->config['map.params'];
			}
				
			//build mapping callback parameters
			if (isset($mappingParams))
				array_unshift($mappingParams, $ri);
			else
				$mappingParams = [$ri];
			
			/*
			 * MAP RESULT
			 */
				
			//call mapping callback
			$mappedResult = call_user_func_array($mappingCallback, $mappingParams);
				
			//free result
			$this->driver->freeResult($result);
			
			/*
			 * CACHEABLE ATTRIBUTES
			 */
			
			if (isset($resultMap)) {
				$copy = $this->__copy(); //clone current instance
				
				if ($mappingCallback[1] == 'mapList') { //list of rows
					if ($mapper->hasGroupKeys()) { //grouped
						foreach ($mapper->getGroupKeys() as $group) {
							foreach (array_keys($mappedResult[$group]) as $k)
								$mapper->evaluateAttributes($mappedResult[$group][$k], $copy);
						}
					}
					else { //list
						foreach (array_keys($mappedResult) as $k)
							$mapper->evaluateAttributes($mappedResult[$k], $copy);
					}
				}
				else //single row
					$mapper->evaluateAttributes($mappedResult, $copy);
			}
			
			/*
			 * CACHE STORE
			 */
			
			//check if obtained value can be stored
			if (isset($this->cacheProvider) && $cacheable) {
				//build value wrapper
				if ($mapper instanceof ComplexMapper)
					$this->injectCacheMetadata($this->config['cache.metakey'], $mappedResult, get_class($mapper), $mappingCallback[1], $mapper->getGroupKeys(), $resultMap);
				
				//store value
				if (array_key_exists('cache.ttl', $this->config))
					$this->cacheProvider->store($cacheKey, $mappedResult, intval($this->config['cache.ttl']));
				else
					$this->cacheProvider->store($cacheKey, $mappedResult);
			}
		}
		
		/*
		 * DYNAMIC ATTRIBUTES
		 */

		if (!empty($resultMap) && $this->config['depth.limit'] > $this->config['depth.current']) {
			$icopy = $this->__icopy();			
			
			if ($mappingCallback[1] == 'mapList' && !empty($mappedResult)) {
				if ($mapper->hasGroupKeys()) {
					foreach ($mapper->getGroupKeys() as $group) {
						foreach (array_keys($mappedResult[$group]) as $k) {
							$mapper->evaluateDynamicAttributes($mappedResult[$group][$k], $icopy);
							$mapper->evaluateAssociations($mappedResult[$group][$k], $icopy);
						}
					}
				}
				else {
					foreach (array_keys($mappedResult) as $k) {
						$mapper->evaluateDynamicAttributes($mappedResult[$k], $icopy);
						$mapper->evaluateAssociations($mappedResult[$k], $icopy);
					}
				}
			}
			elseif ($mappingCallback[1] != 'mapList' && !is_null($mappedResult)) {
				$mapper->evaluateDynamicAttributes($mappedResult, $icopy);
				$mapper->evaluateAssociations($mappedResult, $icopy);
			}
		}
		
		/*
		 * TRAVERSING CALLBACK
		 */
		
		if (array_key_exists('callback.each', $this->config)) {
			$eachCallback = $this->config['callback.each'];
			$copy = isset($copy) ? $copy : $this->__copy();
		
			if ($eachCallback instanceof \Closure) {
				//check if mapped result is a list
				if ($mappingCallback[1] == 'mapList' && !empty($mappedResult)) {
					if ($mapper instanceof ComplexMapper && $mapper->hasGroupKeys()) {
						foreach ($mapper->getGroupKeys() as $group) {
							foreach (array_keys($mappedResult[$group]) as $k)
								$eachCallback->__invoke($mappedResult[$group][$k], $copy);
						}
					}
					else {
						foreach (array_keys($mappedResult) as $k)
							$eachCallback->__invoke($mappedResult[$k], $copy);
					}
				}
				elseif (!is_null($mappedResult))
					$eachCallback->__invoke($mappedResult, $copy);
			}
			else {
				//this closure avoids getting "expected to be a reference"-style messages
				$c = function (&$mappedResult) use ($eachCallback) {
					call_user_func($eachCallback, $mappedResult, $copy);
				};
		
				//call traverse callback
				if ($mappingCallback[1] == 'mapList' && !empty($mappedResult)) {
					if ($mapper instanceof ComplexMapper && $mapper->hasGroupKeys()) {
						foreach ($mapper->getGroupKeys() as $group) {
							foreach (array_keys($mappedResult[$group]) as $k)
								$c->__invoke($mappedResult[$group][$k]);
						}
					}
					else {
						foreach (array_keys($mappedResult) as $k)
							$c->__invoke($mappedResult[$k]);
					}
				}
				elseif (!is_null($mappedResult))
					$c->__invoke($mappedResult);
			}
		}
		
		/*
		 * FILTER CALLBACK
		 */
		
		//apply filter
		if (array_key_exists('callback.filter', $this->config)) {
			$filterCallback = $this->config['callback.filter'];
		
			//check if mapped result is a list
			if ($mappingCallback[1] == 'mapList' && !empty($mappedResult)) {
				if ($mapper instanceof ComplexMapper && $mapper->hasGroupKeys()) {
					foreach ($mapper->getGroupKeys() as $group)
						$mappedResult[$group] = array_filter($mappedResult[$group], $filterCallback);
				}
				else
					$mappedResult = array_filter($mappedResult, $filterCallback);
			}
			elseif (!is_null($mappedResult)) {
				if (!call_user_func($filterCallback, $mappedResult))
					$mappedResult = null;
			}
		}
		
		return $mappedResult;
	}
5277
protected function executeQuery($query)
        {
            $res = @odbc_exec($this->_lnk, $query);
            if(!$res) {
                $error = odbc_errormsg($this->_lnk);
                $this->log('Query failed: '.$error);
                throw new Exception('Executing query failed ' . $error, self::QUERY_FAILED);
            }
            return $res;
        }
204002
protected function processQuery($query)
    {
        if (null === $processed = json_decode($this->adapter->getContent($query))) {
            throw new \RuntimeException(sprintf("Impossible to process this query: %s", $query));
        }

        if ('ERROR' === $processed->status) {
            // it looks that the API does still have the old error object structure.
            if (isset($processed->error_message)) {
                $errorMessage = $processed->error_message;
            }

            if (isset($processed->message)) {
                $errorMessage = $processed->message;
            }

            throw new \RuntimeException(sprintf("%s: %s", $errorMessage, $query));
        }

        return $processed;
    }
649902
public function validateQuery($query)
    {
        if (!is_string($query) && !method_exists($query, '__toString')) {
            throw new InvalidArgumentException(
                'Query must be a string'
            );
        }

        if (strpos($query, '#') !== false) {
            throw new InvalidArgumentException(
                'Query must not contain a URI fragment'
            );
        }
    }