Made IDbStatement::execute return number of affected rows.
This commit is contained in:
parent
5a1fdccced
commit
24db1bd83d
5 changed files with 17 additions and 9 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
0.2408.182001
|
0.2408.401736
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
// IDbStatement.php
|
// IDbStatement.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2024-08-03
|
// Updated: 2024-09-13
|
||||||
|
|
||||||
namespace Index\Data;
|
namespace Index\Data;
|
||||||
|
|
||||||
|
@ -58,8 +58,10 @@ interface IDbStatement extends ICloseable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes this statement.
|
* Executes this statement.
|
||||||
|
*
|
||||||
|
* @return int|string Number of rows affected by the query.
|
||||||
*/
|
*/
|
||||||
function execute(): void;
|
function execute(): int|string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets this statement for reuse.
|
* Resets this statement for reuse.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
// MariaDBStatement.php
|
// MariaDBStatement.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2024-08-03
|
// Updated: 2024-09-13
|
||||||
|
|
||||||
namespace Index\Data\MariaDB;
|
namespace Index\Data\MariaDB;
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ class MariaDBStatement implements IDbStatement {
|
||||||
return $this->statement->insert_id;
|
return $this->statement->insert_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(): void {
|
public function execute(): int|string {
|
||||||
$args = [''];
|
$args = [''];
|
||||||
|
|
||||||
foreach($this->params as $key => $param) {
|
foreach($this->params as $key => $param) {
|
||||||
|
@ -154,6 +154,8 @@ class MariaDBStatement implements IDbStatement {
|
||||||
|
|
||||||
if(!$this->statement->execute())
|
if(!$this->statement->execute())
|
||||||
throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
|
|
||||||
|
return $this->statement->affected_rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reset(): void {
|
public function reset(): void {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
// NullDbStatement.php
|
// NullDbStatement.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2024-08-03
|
// Updated: 2024-09-13
|
||||||
|
|
||||||
namespace Index\Data\NullDb;
|
namespace Index\Data\NullDb;
|
||||||
|
|
||||||
|
@ -27,7 +27,9 @@ class NullDbStatement implements IDbStatement {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(): void {}
|
public function execute(): int|string {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public function reset(): void {}
|
public function reset(): void {}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
// SQLiteStatement.php
|
// SQLiteStatement.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2024-08-03
|
// Updated: 2024-09-13
|
||||||
|
|
||||||
namespace Index\Data\SQLite;
|
namespace Index\Data\SQLite;
|
||||||
|
|
||||||
|
@ -83,11 +83,13 @@ class SQLiteStatement implements IDbStatement {
|
||||||
return $this->connection->getLastInsertId();
|
return $this->connection->getLastInsertId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(): void {
|
public function execute(): int|string {
|
||||||
$result = $this->statement->execute();
|
$result = $this->statement->execute();
|
||||||
if($result === false)
|
if($result === false)
|
||||||
throw new RuntimeException((string)$this->connection->getLastErrorString(), $this->connection->getLastErrorCode());
|
throw new RuntimeException((string)$this->connection->getLastErrorString(), $this->connection->getLastErrorCode());
|
||||||
$this->result = $result;
|
$this->result = $result;
|
||||||
|
|
||||||
|
return $this->connection->getAffectedRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reset(): void {
|
public function reset(): void {
|
||||||
|
|
Loading…
Reference in a new issue