Skip to content

Commit

Permalink
authpdo: add support for multi-rowset to _query
Browse files Browse the repository at this point in the history
This makes sure if user defined multiple query in one SQL, they are all executed rather than only the first one.
  • Loading branch information
phy25 committed Sep 9, 2019
1 parent 67d5efa commit 6a1b9bf
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/plugins/authpdo/auth.php
Expand Up @@ -683,10 +683,24 @@ protected function _query($sql, $arguments = array()) {
}

$sth->execute();
if(strtolower(substr($sql, 0, 6)) == 'select') {
$result = $sth->fetchAll();
} else {
$result = $sth->rowCount();
// only report last line's result
$hasnextrowset = true;
$currentsql = $sql;
while($hasnextrowset){
if(strtolower(substr($currentsql, 0, 6)) == 'select') {
$result = $sth->fetchAll();
} else {
$result = $sth->rowCount();
}
$semi_pos = strpos($currentsql, ';');
if($semi_pos){
$currentsql = trim(substr($currentsql, $semi_pos+1));
}
try{
$hasnextrowset = $sth->nextRowset(); // run next rowset
}catch(PDOException $rowset_e){
$hasnextrowset = false; // driver does not support multi-rowset, should be executed in one time
}
}
} catch(Exception $e) {
// report the caller's line
Expand Down

0 comments on commit 6a1b9bf

Please sign in to comment.