Skip to content

Commit

Permalink
Fixed silent errors or unreported errors due to try/catch blocks in Q…
Browse files Browse the repository at this point in the history
…uerier.php not throwing an error or exception. Optimized the model fields setters and getters.
  • Loading branch information
phrenotype committed Jun 29, 2024
1 parent 56b6f05 commit d2220d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions Q/Orm/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function __get($name)
$inProps = $this->__properties[$name] ?? null;
if($inProps){
if($inProps instanceof \Closure){
$evaluated = $this->$name();
return $this->$name();
}else{
return $inProps;
Expand Down
16 changes: 10 additions & 6 deletions Q/Orm/Querier.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static function raw($sql, array $params = [])
if ($pdo->inTransaction()) {
$pdo->rollBack();
}
throw new \Error($e);
}
}

Expand Down Expand Up @@ -301,8 +302,8 @@ public static function insert(array $fields, $table)
if ($pdo->inTransaction()) {
$pdo->rollBack();
}
throw new \Error($e);
}

$stmt = null;
return $pdo->lastInsertId();
}
Expand Down Expand Up @@ -338,6 +339,7 @@ public static function insertMany(array $assocs, $table)
if ($pdo->inTransaction()) {
$pdo->rollBack();
}
throw new \Error($e);
}
$stmt = null;
return $pdo->lastInsertId();
Expand Down Expand Up @@ -369,17 +371,18 @@ public static function update($fields, string $condition, array $placeholders, $

$stmt = $pdo->prepare($sql);

if(!$pdo->inTransaction()){
$pdo->beginTransaction();
if (!$pdo->inTransaction()) {
$pdo->beginTransaction();
}

try {
$stmt->execute($final_placeholders);
$pdo->commit();
} catch (\PDOException $e) {
if($pdo->inTransaction()){
if ($pdo->inTransaction()) {
$pdo->rollBack();
}
}
throw new \Error($e);
}
$stmt = null;
}
Expand Down Expand Up @@ -415,6 +418,7 @@ public static function delete(string $condition, array $placeholders, $table)
if ($pdo->inTransaction()) {
$pdo->rollBack();
}
throw new \Error($e);
}

$stmt = null;
Expand Down

0 comments on commit d2220d5

Please sign in to comment.