Пример #1
0
 /**
  * Returns the GeometryEngine to use for calculations.
  *
  * @return GeometryEngine
  *
  * @throws GeometryEngineException
  */
 public static function get()
 {
     if (self::$engine === null) {
         throw GeometryEngineException::noEngineSet();
     }
     return self::$engine;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 protected function executeQuery($query, array $parameters)
 {
     if (isset($this->statements[$query])) {
         $statement = $this->statements[$query];
     } else {
         // Temporary set the error reporting level to 0 to avoid any warning.
         $errorReportingLevel = error_reporting(0);
         $statement = $this->sqlite3->prepare($query);
         // Restore the original error reporting level.
         error_reporting($errorReportingLevel);
         $errorCode = $this->sqlite3->lastErrorCode();
         if ($errorCode !== 0) {
             $exception = new SQLite3Exception($this->sqlite3->lastErrorMsg(), $errorCode);
             if ($errorCode === 1) {
                 // SQL error cause by a missing function, this must be reported with a GeometryEngineException.
                 throw GeometryEngineException::operationNotSupportedByEngine($exception);
             } else {
                 // Other SQLite3 error; we cannot trigger the original E_WARNING, so we throw this exception instead.
                 throw $exception;
             }
         } else {
             $this->statements[$query] = $statement;
         }
     }
     $index = 1;
     foreach ($parameters as $parameter) {
         if ($parameter instanceof Geometry) {
             if ($parameter->isEmpty()) {
                 $statement->bindValue($index++, $parameter->asText(), SQLITE3_TEXT);
                 $statement->bindValue($index++, $parameter->SRID(), SQLITE3_INTEGER);
             } else {
                 $statement->bindValue($index++, $parameter->asBinary(), SQLITE3_BLOB);
                 $statement->bindValue($index++, $parameter->SRID(), SQLITE3_INTEGER);
             }
         } else {
             if ($parameter === null) {
                 $type = SQLITE3_NULL;
             } elseif (is_int($parameter)) {
                 $type = SQLITE3_INTEGER;
             } elseif (is_float($parameter)) {
                 $type = SQLITE3_FLOAT;
             } else {
                 $type = SQLITE3_TEXT;
             }
             $statement->bindValue($index++, $parameter, $type);
         }
     }
     $result = $statement->execute();
     return $result->fetchArray(SQLITE3_NUM);
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 protected function executeQuery($query, array $parameters)
 {
     $errMode = $this->pdo->getAttribute(\PDO::ATTR_ERRMODE);
     $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     try {
         if (!isset($this->statements[$query])) {
             $this->statements[$query] = $this->pdo->prepare($query);
         }
         $statement = $this->statements[$query];
         $index = 1;
         foreach ($parameters as $parameter) {
             if ($parameter instanceof Geometry) {
                 if ($parameter->isEmpty()) {
                     $statement->bindValue($index++, $parameter->asText(), \PDO::PARAM_STR);
                     $statement->bindValue($index++, $parameter->SRID(), \PDO::PARAM_INT);
                 } else {
                     $statement->bindValue($index++, $parameter->asBinary(), \PDO::PARAM_LOB);
                     $statement->bindValue($index++, $parameter->SRID(), \PDO::PARAM_INT);
                 }
             } else {
                 $statement->bindValue($index++, $parameter);
             }
         }
         $statement->execute();
         $result = $statement->fetch(\PDO::FETCH_NUM);
     } catch (\PDOException $e) {
         $errorClass = substr($e->getCode(), 0, 2);
         // 42XXX = syntax error or access rule violation; reported on undefined function.
         // 22XXX = data exception; reported by MySQL 5.7 on unsupported geometry.
         if ($errorClass == '42' || $errorClass == '22') {
             throw GeometryEngineException::operationNotSupportedByEngine($e);
         }
         throw $e;
     }
     $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, $errMode);
     return $result;
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function boundingPolygons(Geometry $g)
 {
     throw GeometryEngineException::unimplementedMethod(__METHOD__);
 }