Skip to content

Commit

Permalink
Handle $stmt->rowCount() for SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
kamshory committed Oct 26, 2024
1 parent 13c32e9 commit e4f7098
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/Database/PicoDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,18 @@ public function fetch($sql, $tentativeType = PDO::FETCH_ASSOC, $defaultValue = n

try {
$stmt->execute($params);
$result = $stmt->rowCount() > 0 ? $stmt->fetch($tentativeType) : $defaultValue;
if($this->getDatabaseType() == PicoDatabaseType::DATABASE_TYPE_SQLITE)
{
$result = $stmt->fetch($tentativeType);
if($result === false)
{
$result = $defaultValue;
}
}
else
{
$result = $stmt->rowCount() > 0 ? $stmt->fetch($tentativeType) : $defaultValue;
}
} catch (PDOException $e) {
$result = $defaultValue;
}
Expand All @@ -340,7 +351,15 @@ public function isRecordExists($sql, $params = null)

try {
$stmt->execute($params);
return $stmt->rowCount() > 0;
if($this->getDatabaseType() == PicoDatabaseType::DATABASE_TYPE_SQLITE)
{
$result = $stmt->fetch();
return $result !== false;
}
else
{
return $stmt->rowCount() > 0;
}
} catch (PDOException $e) {
throw new PDOException($e->getMessage(), intval($e->getCode()));
}
Expand All @@ -367,7 +386,18 @@ public function fetchAll($sql, $tentativeType = PDO::FETCH_ASSOC, $defaultValue

try {
$stmt->execute($params);
$result = $stmt->rowCount() > 0 ? $stmt->fetchAll($tentativeType) : $defaultValue;
if($this->getDatabaseType() == PicoDatabaseType::DATABASE_TYPE_SQLITE)
{
$result = $stmt->fetch($tentativeType);
if($result === false)
{
$result = $defaultValue;
}
}
else
{
$result = $stmt->rowCount() > 0 ? $stmt->fetchAll($tentativeType) : $defaultValue;
}
} catch (PDOException $e) {
$result = $defaultValue;
}
Expand Down

0 comments on commit e4f7098

Please sign in to comment.