1<?php 2 3 4namespace ComboStrap; 5 6 7class SqliteResult 8{ 9 private $res; 10 /** 11 * @var SqliteRequest 12 */ 13 private $sqlite; 14 /** 15 * @var \helper_plugin_sqlite 16 */ 17 private $sqlitePlugin; 18 19 /** 20 * SqliteResult constructor. 21 */ 22 public function __construct(SqliteRequest $sqlite, $res) 23 { 24 $this->sqlite = $sqlite; 25 $this->res = $res; 26 $this->sqlitePlugin = $this->sqlite->getSqliteConnection()->getSqlitePlugin(); 27 28 } 29 30 public function getRows(): array 31 { 32 return $this->sqlitePlugin->res2arr($this->res); 33 } 34 35 public function close(): SqliteResult 36 { 37 $this->sqlitePlugin->res_close($this->res); 38 $this->res = null; 39 return $this; 40 } 41 42 public function getInsertId(): string 43 { 44 return $this->sqlitePlugin->getAdapter()->getDb()->lastInsertId(); 45 } 46 47 public function getChangeCount() 48 { 49 return $this->sqlitePlugin->countChanges($this->res); 50 } 51 52 public function getFirstCellValue() 53 { 54 return $this->sqlitePlugin->res2single($this->res); 55 } 56 57 public function getFirstCellValueAsInt(): int 58 { 59 return intval($this->getFirstCellValue()); 60 } 61 62 public function getFirstRow() 63 { 64 $rows = $this->getRows(); 65 if(sizeof($rows)>=1){ 66 return $rows[0]; 67 } 68 return []; 69 } 70 71 72} 73