PDOException example

$stmt->allowRowCount = TRUE;
          return $stmt->rowCount();

        case Database::RETURN_INSERT_ID:
          $sequence_name = $options['sequence_name'] ?? NULL;
          return $this->lastInsertId($sequence_name);

        case Database::RETURN_NULL:
          return NULL;

        default:
          throw new \PDOException('Invalid return directive: ' . $options['return']);

      }
    }
    catch (\Exception $e) {
      $this->exceptionHandler()->handleExecutionException($e$stmt$args$options);
    }
  }

  /** * Expands out shorthand placeholders. * * Drupal supports an alternate syntax for doing arrays of values. We * therefore need to expand them out into a full, executable query string. * * @param string $query * The query string to modify. * @param array $args * The arguments for the query. * * @return bool * TRUE if the query was modified, FALSE otherwise. * * @throws \InvalidArgumentException * This exception is thrown when: * - A placeholder that ends in [] is supplied, and the supplied value is * not an array. * - A placeholder that does not end in [] is supplied, and the supplied * value is an array. */
$content = 'foobar';
        $stream = $this->createStream($content);
        $exception = null;

        $selectStmt->expects($this->atLeast(2))->method('fetchAll')
            ->willReturnCallback(function D) use (&$exception$stream) {
                return $exception ? [[$streamtime() + 42]] : [];
            });

        $insertStmt->expects($this->once())->method('execute')
            ->willReturnCallback(function D) use (&$exception) {
                throw $exception = new \PDOException('', '23');
            });

        $storage = new PdoSessionHandler($pdo);
        $result = $storage->read('foo');

        $this->assertSame($content$result);
    }

    public function testReadingRequiresExactlySameId()
    {
        $storage = new PdoSessionHandler($this->getMemorySqlitePdo());
        


    return $return;
  }

  /** * Throw a PDO Exception based on the last PDO error. */
  protected function throwPDOException(): void {
    $error_info = $this->connection->errorInfo();
    // We rebuild a message formatted in the same way as PDO.     $exception = new \PDOException("SQLSTATE[" . $error_info[0] . "]: General error " . $error_info[1] . ": " . $error_info[2]);
    $exception->errorInfo = $error_info;
    throw $exception;
  }

  /** * Grab a PDOStatement object from a given query and its arguments. * * Some drivers (including SQLite) will need to perform some preparation * themselves to get the statement right. * * @param $query * The query. * @param array|null $args * An array of arguments. This can be NULL. * * @return object * A PDOStatement object. */

class CategoryNonExistentExceptionHandlerTest extends TestCase
{
    public function testExceptionHandler(): void
    {
        $handler = new CategoryNonExistentExceptionHandler();

        static::assertEquals(ExceptionHandlerInterface::PRIORITY_DEFAULT, $handler->getPriority());

        $afterException = new ForeignKeyConstraintViolationException(
            new PDOException('SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`shopware`.`category`, CONSTRAINT `fk.category.after_category_id` FOREIGN KEY (`after_category_id`, `after_category_version_id`) REFERENCES `category` (`id`, `version_id`) ON DELETE SET NULL O)'),
            new Query('SOME QUERY', [][])
        );

        $matched = $handler->matchException($afterException);

        static::assertInstanceOf(CategoryException::class$matched);
        static::assertEquals('Category to insert after not found.', $matched->getMessage());

        static::assertNull($handler->matchException(new \Exception('Some other exception')));
    }
}
$connection->method('get')->willReturn($doctrineEnvelop);
        $connection->expects($this->once())->method('reject');

        $receiver = new DoctrineReceiver($connection$serializer);
        $receiver->get();
    }

    public function testOccursRetryableExceptionFromConnection()
    {
        $serializer = $this->createSerializer();
        $connection = $this->createMock(Connection::class);
        $driverException = class_exists(Exception::class) ? Exception::new(new \PDOException('Deadlock', 40001)) : new PDOException(new \PDOException('Deadlock', 40001));
        if (!class_exists(Version::class)) {
            // This is doctrine/dbal 3.x             $deadlockException = new DeadlockException($driverException, null);
        } else {
            $deadlockException = new DeadlockException('Deadlock', $driverException);
        }

        $connection->method('get')->willThrowException($deadlockException);
        $receiver = new DoctrineReceiver($connection$serializer);
        $this->assertSame([]$receiver->get());
        $this->assertSame([]$receiver->get());
        
    $this->next();

    return $return;
  }

  /** * Throw a PDO Exception based on the last PDO error. */
  protected function throwPDOException() {
    $error_info = $this->connection->errorInfo();
    // We rebuild a message formatted in the same way as PDO.     $exception = new \PDOException("SQLSTATE[" . $error_info[0] . "]: General error " . $error_info[1] . ": " . $error_info[2]);
    $exception->errorInfo = $error_info;
    throw $exception;
  }

  /** * Grab a PDOStatement object from a given query and its arguments. * * Some drivers (including SQLite) will need to perform some preparation * themselves to get the statement right. * * @param $query * The query. * @param array|null $args * An array of arguments. This can be NULL. * * @return \PDOStatement * A PDOStatement object. */
Home | Imprint | This part of the site doesn't use cookies.