Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
}
],
"require": {
"php": "^7.0",
"amphp/amp": "^2",
"amphp/sql": "dev-master"
},
Expand Down
8 changes: 4 additions & 4 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ final public function isAlive(): bool
*
* @throws FailureException
*/
final public function lastUsedAt(): int
final public function getLastUsedAt(): int
{
if (! $this->handle) {
throw new FailureException('Not connected');
}

return $this->handle->lastUsedAt();
return $this->handle->getLastUsedAt();
}

/**
Expand Down Expand Up @@ -183,7 +183,7 @@ final public function listen(string $channel): Promise
*
* @throws FailureException
*/
final public function transaction(int $isolation = Transaction::ISOLATION_COMMITTED): Promise
final public function beginTransaction(int $isolation = Transaction::ISOLATION_COMMITTED): Promise
{
if (! $this->handle) {
throw new FailureException('Not connected');
Expand Down Expand Up @@ -213,7 +213,7 @@ final public function transaction(int $isolation = Transaction::ISOLATION_COMMIT

$this->busy = new Deferred;

return new ConnectionTransaction($this->handle, $isolation, $this->release);
return new ConnectionTransaction($this->handle, $this->release, $isolation);
});
}

Expand Down
8 changes: 4 additions & 4 deletions src/ConnectionTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ final class ConnectionTransaction implements Transaction

/**
* @param Handle $handle
* @param int $isolation
* @param callable $release
* @param int $isolation
*
* @throws \Error If the isolation level is invalid.
*/
public function __construct(Handle $handle, int $isolation = SqlTransaction::ISOLATION_COMMITTED, callable $release)
public function __construct(Handle $handle, callable $release, int $isolation = SqlTransaction::ISOLATION_COMMITTED)
{
switch ($isolation) {
case SqlTransaction::ISOLATION_UNCOMMITTED:
Expand Down Expand Up @@ -62,9 +62,9 @@ public function __destruct()
/**
* {@inheritdoc}
*/
public function lastUsedAt(): int
public function getLastUsedAt(): int
{
return $this->handle->lastUsedAt();
return $this->handle->getLastUsedAt();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/PgSqlCommandResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public function __destruct()
/**
* @return int Number of rows affected by the INSERT, UPDATE, or DELETE query.
*/
public function affectedRows(): int
public function getAffectedRowCount(): int
{
return \pg_affected_rows($this->handle);
}

/**
* @return string
*/
public function lastOid(): string
public function getLastOid(): string
{
return (string) \pg_last_oid($this->handle);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PgSqlHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function isAlive(): bool
/**
* {@inheritdoc}
*/
public function lastUsedAt(): int
public function getLastUsedAt(): int
{
return $this->lastUsedAt;
}
Expand Down
22 changes: 9 additions & 13 deletions src/PgSqlResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ final class PgSqlResultSet implements ResultSet
/** @var mixed Last row emitted. */
private $currentRow;

/** @var int Next row fetch type. */
private $type = self::FETCH_ASSOC;

/** @var int[] */
private $fieldTypes = [];

Expand Down Expand Up @@ -56,10 +53,9 @@ public function __destruct()
/**
* {@inheritdoc}
*/
public function advance(int $type = self::FETCH_ASSOC): Promise
public function advance(): Promise
{
$this->currentRow = null;
$this->type = $type;

if (++$this->position > \pg_num_rows($this->handle)) {
return new Success(false);
Expand All @@ -71,7 +67,7 @@ public function advance(int $type = self::FETCH_ASSOC): Promise
/**
* {@inheritdoc}
*/
public function getCurrent()
public function getCurrent(int $type = self::FETCH_ASSOC)
{
if ($this->currentRow !== null) {
return $this->currentRow;
Expand All @@ -98,7 +94,7 @@ public function getCurrent()
$result[$column] = $this->cast($column, $result[$column]);
}

if ($this->type === self::FETCH_ARRAY) {
if ($type === self::FETCH_ARRAY) {
return $this->currentRow = $result;
}

Expand All @@ -107,11 +103,11 @@ public function getCurrent()
$assoc[$name] = $result[$index];
}

if ($this->type === self::FETCH_ASSOC) {
if ($type === self::FETCH_ASSOC) {
return $this->currentRow = $assoc;
}

if ($this->type === self::FETCH_OBJECT) {
if ($type === self::FETCH_OBJECT) {
return $this->currentRow = (object) $assoc;
}

Expand Down Expand Up @@ -243,7 +239,7 @@ public function numRows(): int
/**
* @return int Number of fields in each row.
*/
public function numFields(): int
public function getFieldCount(): int
{
return \pg_num_fields($this->handle);
}
Expand All @@ -255,9 +251,9 @@ public function numFields(): int
*
* @throws \Error If the field number does not exist in the result.
*/
public function fieldName(int $fieldNum): string
public function getFieldName(int $fieldNum): string
{
if (0 > $fieldNum || $this->numFields() <= $fieldNum) {
if (0 > $fieldNum || $this->getFieldCount() <= $fieldNum) {
throw new \Error(\sprintf('No field with index %d in result', $fieldNum));
}

Expand All @@ -271,7 +267,7 @@ public function fieldName(int $fieldNum): string
*
* @throws \Error If the field name does not exist in the result.
*/
public function fieldNum(string $fieldName): int
public function getFieldIndex(string $fieldName): int
{
$result = \pg_field_num($this->handle, $fieldName);

Expand Down
5 changes: 1 addition & 4 deletions src/PgSqlStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ final class PgSqlStatement implements Statement
/** @var string */
private $sql;

/** @var Internal\ReferenceQueue */
private $queue;

/** @var string[] */
private $params;

Expand Down Expand Up @@ -58,7 +55,7 @@ public function getQuery(): string
}

/** {@inheritdoc} */
public function lastUsedAt(): int
public function getLastUsedAt(): int
{
return $this->lastUsedAt;
}
Expand Down
4 changes: 2 additions & 2 deletions src/PooledResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function __construct(ResultSet $result, callable $release)
$this->result = $result;
}

public function numFields(): int
public function getFieldCount(): int
{
return $this->result->numFields();
return $this->result->getFieldCount();
}
}
14 changes: 5 additions & 9 deletions src/PqBufferedResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ final class PqBufferedResultSet implements ResultSet
/** @var mixed Last row emitted. */
private $currentRow;

/** @var int Next row fetch type. */
private $type = self::FETCH_ASSOC;

/**
* @param pq\Result $result PostgreSQL result object.
*/
Expand All @@ -32,10 +29,9 @@ public function __construct(pq\Result $result)
/**
* {@inheritdoc}
*/
public function advance(int $type = self::FETCH_ASSOC): Promise
public function advance(): Promise
{
$this->currentRow = null;
$this->type = $type;

if (++$this->position > $this->result->numRows) {
return new Success(false);
Expand All @@ -47,7 +43,7 @@ public function advance(int $type = self::FETCH_ASSOC): Promise
/**
* {@inheritdoc}
*/
public function getCurrent()
public function getCurrent(int $type = self::FETCH_ASSOC)
{
if ($this->currentRow !== null) {
return $this->currentRow;
Expand All @@ -57,7 +53,7 @@ public function getCurrent()
throw new \Error("No more rows remain in the result set");
}

switch ($this->type) {
switch ($type) {
case self::FETCH_ASSOC:
return $this->currentRow = $this->result->fetchRow(pq\Result::FETCH_ASSOC);
case self::FETCH_ARRAY:
Expand All @@ -69,12 +65,12 @@ public function getCurrent()
}
}

public function numRows(): int
public function getNumRows(): int
{
return $this->result->numRows;
}

public function numFields(): int
public function getFieldCount(): int
{
return $this->result->numCols;
}
Expand Down
2 changes: 1 addition & 1 deletion src/PqCommandResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(pq\Result $result)
/**
* @return int Number of rows affected by the INSERT, UPDATE, or DELETE query.
*/
public function affectedRows(): int
public function getAffectedRowCount(): int
{
return $this->result->affectedRows;
}
Expand Down
2 changes: 1 addition & 1 deletion src/PqHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function isAlive(): bool
/**
* {@inheritdoc}
*/
public function lastUsedAt(): int
public function getLastUsedAt(): int
{
return $this->lastUsedAt;
}
Expand Down
2 changes: 1 addition & 1 deletion src/PqStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getQuery(): string
}

/** {@inheritdoc} */
public function lastUsedAt(): int
public function getLastUsedAt(): int
{
return $this->lastUsedAt;
}
Expand Down
12 changes: 4 additions & 8 deletions src/PqUnbufferedResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ final class PqUnbufferedResultSet implements ResultSet
/** @var array|object Last row emitted. */
private $currentRow;

/** @var int Next row fetch type. */
private $type = self::FETCH_ASSOC;

/**
* @param callable(): $fetch Function to fetch next result row.
* @param \pq\Result $result PostgreSQL result object.
Expand All @@ -44,18 +41,17 @@ public function __construct(callable $fetch, pq\Result $result, callable $releas
/**
* {@inheritdoc}
*/
public function advance(int $type = self::FETCH_ASSOC): Promise
public function advance(): Promise
{
$this->currentRow = null;
$this->type = $type;

return $this->producer->advance();
}

/**
* {@inheritdoc}
*/
public function getCurrent()
public function getCurrent(int $type = self::FETCH_ASSOC)
{
if ($this->currentRow !== null) {
return $this->currentRow;
Expand All @@ -64,7 +60,7 @@ public function getCurrent()
/** @var \pq\Result $result */
$result = $this->producer->getCurrent();

switch ($this->type) {
switch ($type) {
case self::FETCH_ASSOC:
return $this->currentRow = $result->fetchRow(pq\Result::FETCH_ASSOC);
case self::FETCH_ARRAY:
Expand All @@ -79,7 +75,7 @@ public function getCurrent()
/**
* @return int Number of fields (columns) in each result set.
*/
public function numFields(): int
public function getFieldCount(): int
{
return $this->numCols;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ interface ResultSet extends SqlResultSet
*
* @return int
*/
public function numFields(): int;
public function getFieldCount(): int;
}
Loading