From 6854cb3f4d8219cf1829e32122eb2502a916eae9 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 1 Feb 2020 09:05:48 +0100 Subject: initial checkin --- .../adodb-php/drivers/adodb-pdo_sqlite.inc.php | 206 +++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 vendor/adodb/adodb-php/drivers/adodb-pdo_sqlite.inc.php (limited to 'vendor/adodb/adodb-php/drivers/adodb-pdo_sqlite.inc.php') diff --git a/vendor/adodb/adodb-php/drivers/adodb-pdo_sqlite.inc.php b/vendor/adodb/adodb-php/drivers/adodb-pdo_sqlite.inc.php new file mode 100644 index 0000000..2d2f8be --- /dev/null +++ b/vendor/adodb/adodb-php/drivers/adodb-pdo_sqlite.inc.php @@ -0,0 +1,206 @@ +pdoDriver = $parentDriver; + $parentDriver->_bindInputArray = true; + $parentDriver->hasTransactions = false; // // should be set to false because of PDO SQLite driver not supporting changing autocommit mode + $parentDriver->hasInsertID = true; + } + + function ServerInfo() + { + $parent = $this->pdoDriver; + @($ver = array_pop($parent->GetCol("SELECT sqlite_version()"))); + @($enc = array_pop($parent->GetCol("PRAGMA encoding"))); + + $arr['version'] = $ver; + $arr['description'] = 'SQLite '; + $arr['encoding'] = $enc; + + return $arr; + } + + function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) + { + $nrows = (int) $nrows; + $offset = (int) $offset; + $parent = $this->pdoDriver; + $offsetStr = ($offset >= 0) ? " OFFSET $offset" : ''; + $limitStr = ($nrows >= 0) ? " LIMIT $nrows" : ($offset >= 0 ? ' LIMIT 999999999' : ''); + if ($secs2cache) + $rs = $parent->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr); + else + $rs = $parent->Execute($sql."$limitStr$offsetStr",$inputarr); + + return $rs; + } + + function GenID($seq='adodbseq',$start=1) + { + $parent = $this->pdoDriver; + // if you have to modify the parameter below, your database is overloaded, + // or you need to implement generation of id's yourself! + $MAXLOOPS = 100; + while (--$MAXLOOPS>=0) { + @($num = array_pop($parent->GetCol("SELECT id FROM {$seq}"))); + if ($num === false || !is_numeric($num)) { + @$parent->Execute(sprintf($this->_genSeqSQL ,$seq)); + $start -= 1; + $num = '0'; + $cnt = $parent->GetOne(sprintf($this->_genSeqCountSQL,$seq)); + if (!$cnt) { + $ok = $parent->Execute(sprintf($this->_genSeq2SQL,$seq,$start)); + } + if (!$ok) return false; + } + $parent->Execute(sprintf($this->_genIDSQL,$seq,$num)); + + if ($parent->affected_rows() > 0) { + $num += 1; + $parent->genID = intval($num); + return intval($num); + } + } + if ($fn = $parent->raiseErrorFn) { + $fn($parent->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num); + } + return false; + } + + function CreateSequence($seqname='adodbseq',$start=1) + { + $parent = $this->pdoDriver; + $ok = $parent->Execute(sprintf($this->_genSeqSQL,$seqname)); + if (!$ok) return false; + $start -= 1; + return $parent->Execute("insert into $seqname values($start)"); + } + + function SetTransactionMode($transaction_mode) + { + $parent = $this->pdoDriver; + $parent->_transmode = strtoupper($transaction_mode); + } + + function BeginTrans() + { + $parent = $this->pdoDriver; + if ($parent->transOff) return true; + $parent->transCnt += 1; + $parent->_autocommit = false; + return $parent->Execute("BEGIN {$parent->_transmode}"); + } + + function CommitTrans($ok=true) + { + $parent = $this->pdoDriver; + if ($parent->transOff) return true; + if (!$ok) return $parent->RollbackTrans(); + if ($parent->transCnt) $parent->transCnt -= 1; + $parent->_autocommit = true; + + $ret = $parent->Execute('COMMIT'); + return $ret; + } + + function RollbackTrans() + { + $parent = $this->pdoDriver; + if ($parent->transOff) return true; + if ($parent->transCnt) $parent->transCnt -= 1; + $parent->_autocommit = true; + + $ret = $parent->Execute('ROLLBACK'); + return $ret; + } + + + // mark newnham + function MetaColumns($tab,$normalize=true) + { + global $ADODB_FETCH_MODE; + + $parent = $this->pdoDriver; + $false = false; + $save = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; + if ($parent->fetchMode !== false) $savem = $parent->SetFetchMode(false); + $rs = $parent->Execute("PRAGMA table_info('$tab')"); + if (isset($savem)) $parent->SetFetchMode($savem); + if (!$rs) { + $ADODB_FETCH_MODE = $save; + return $false; + } + $arr = array(); + while ($r = $rs->FetchRow()) { + $type = explode('(',$r['type']); + $size = ''; + if (sizeof($type)==2) + $size = trim($type[1],')'); + $fn = strtoupper($r['name']); + $fld = new ADOFieldObject; + $fld->name = $r['name']; + $fld->type = $type[0]; + $fld->max_length = $size; + $fld->not_null = $r['notnull']; + $fld->primary_key = $r['pk']; + $fld->default_value = $r['dflt_value']; + $fld->scale = 0; + if ($save == ADODB_FETCH_NUM) $arr[] = $fld; + else $arr[strtoupper($fld->name)] = $fld; + } + $rs->Close(); + $ADODB_FETCH_MODE = $save; + return $arr; + } + + function MetaTables($ttype=false,$showSchema=false,$mask=false) + { + $parent = $this->pdoDriver; + + if ($mask) { + $save = $this->metaTablesSQL; + $mask = $this->qstr(strtoupper($mask)); + $this->metaTablesSQL .= " AND name LIKE $mask"; + } + + $ret = $parent->GetCol($this->metaTablesSQL); + + if ($mask) { + $this->metaTablesSQL = $save; + } + return $ret; + } +} -- cgit v1.2.3-70-g09d2