Skip to content

Commit

Permalink
Update sqlite_query.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérémie Fréreault committed Nov 16, 2024
1 parent e32658d commit a335430
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions common/dataphyre/modules/sql/sqlite_query.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* This software is provided "as is", without any warranty of any kind.
*/


namespace dataphyre;

register_shutdown_function(function(){
Expand Down Expand Up @@ -309,24 +308,24 @@ public static function sqlite_count(string $dbms_cluster, string $location, stri
if(is_array($vars)){
$stmt=$conn->prepare("SELECT COUNT(*) as count FROM ".$location." ".$params);
if($stmt===false){
return 0; // Return 0 ifpreparation fails
return 0; // Return 0 if preparation fails
}
foreach($vars as $index => $var){
$stmt->bindValue($index + 1, $var);
}
$result=$stmt->execute();
if($result===false){
return 0; // Return 0 ifexecution fails
return 0; // Return 0 if execution fails
}
$row=$result->fetchArray(SQLITE3_ASSOC);
$stmt->close();
return $row['count'] ?? 0; // Return count or 0 ifnot found
return $row['count'] ?? 0; // Return count or 0 if not found
}
$result=$conn->querySingle("SELECT COUNT(*) as count FROM ".$location." ".$params, true);
if($result===false){
return 0; // Return 0 ifquery fails
return 0; // Return 0 if query fails
}
return $result['count'] ?? 0; // Return count or 0 ifnot found
return $result['count'] ?? 0; // Return count or 0 if not found
}

public static function sqlite_update(string $dbms_cluster, string $location, string $fields, string $params, array $vars) : bool|int {
Expand All @@ -340,14 +339,14 @@ public static function sqlite_update(string $dbms_cluster, string $location, str
if(is_array($vars)){
$stmt=$conn->prepare("UPDATE ".$location." SET ".$fields." ".$params);
if($stmt===false){
return false; // Return false ifpreparation fails
return false; // Return false if preparation fails
}
foreach($vars as $index => $value){
$stmt->bindValue($index + 1, $value);
}
$result=$stmt->execute();
$stmt->close();
return $result !== false; // Return true ifexecution is successful
return $result !== false; // Return true if execution is successful
} else {
return $conn->exec("UPDATE ".$location." SET ".$fields." ".$params) !== false;
}
Expand Down Expand Up @@ -381,7 +380,7 @@ public static function sqlite_insert(string $dbms_cluster, string $location, str
$execute_insert=function($conn) use ($location, $fields, $fields_question_marks, $vars){
$stmt=$conn->prepare("INSERT OR IGNORE INTO ".$location." (".$fields.") VALUES (".$fields_question_marks.")");
if($stmt===false){
return false; // Return false ifpreparation fails
return false; // Return false if preparation fails
}
foreach($vars as $index => $value){
$stmt->bindValue($index + 1, $value);
Expand Down Expand Up @@ -416,7 +415,7 @@ public static function sqlite_delete(string $dbms_cluster, string $location, str
$query="DELETE FROM ".$location." ".$params;
$stmt=$conn->prepare($query);
if($stmt===false){
return false; // Return false ifpreparation fails
return false; // Return false if preparation fails
}
if(isset($vars)){
foreach($vars as $index => $value){
Expand Down

0 comments on commit a335430

Please sign in to comment.