TimeTrex Community Edition v16.2.0

This commit is contained in:
2022-12-13 07:10:06 +01:00
commit 472f000c1b
6810 changed files with 2636142 additions and 0 deletions

View File

@ -0,0 +1,430 @@
<?php
/**
* LDAP driver.
*
* Provides a subset of ADOdb commands, allowing read-only access to an LDAP database.
*
* This file is part of ADOdb, a Database Abstraction Layer library for PHP.
*
* @package ADOdb
* @link https://adodb.org Project's web site and documentation
* @link https://github.com/ADOdb/ADOdb Source code and issue tracker
*
* The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
* and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
* any later version. This means you can use it in proprietary products.
* See the LICENSE.md file distributed with this source code for details.
* @license BSD-3-Clause
* @license LGPL-2.1-or-later
*
* @copyright 2000-2013 John Lim
* @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
* @author Joshua Eldridge <joshuae74@hotmail.com>
*/
// security - hide paths
if (!defined('ADODB_DIR')) die();
if (!defined('LDAP_ASSOC')) {
define('LDAP_ASSOC',ADODB_FETCH_ASSOC);
define('LDAP_NUM',ADODB_FETCH_NUM);
define('LDAP_BOTH',ADODB_FETCH_BOTH);
}
class ADODB_ldap extends ADOConnection {
var $databaseType = 'ldap';
var $dataProvider = 'ldap';
# Connection information
var $username = false;
var $password = false;
# Used during searches
var $filter;
var $dn;
var $version;
var $port = 389;
# Options configuration information
var $LDAP_CONNECT_OPTIONS;
# error on binding, eg. "Binding: invalid credentials"
var $_bind_errmsg = "Binding: %s";
// returns true or false
function _connect( $host, $username, $password, $ldapbase)
{
global $LDAP_CONNECT_OPTIONS;
if ( !function_exists( 'ldap_connect' ) ) return null;
if (strpos($host,'ldap://') === 0 || strpos($host,'ldaps://') === 0) {
$this->_connectionID = @ldap_connect($host);
} else {
$conn_info = array( $host,$this->port);
if ( strstr( $host, ':' ) ) {
$conn_info = explode( ':', $host );
}
$this->_connectionID = @ldap_connect( $conn_info[0], $conn_info[1] );
}
if (!$this->_connectionID) {
$e = 'Could not connect to ' . $conn_info[0];
$this->_errorMsg = $e;
if ($this->debug) ADOConnection::outp($e);
return false;
}
if( count( $LDAP_CONNECT_OPTIONS ) > 0 ) {
$this->_inject_bind_options( $LDAP_CONNECT_OPTIONS );
}
if ($username) {
$bind = @ldap_bind( $this->_connectionID, $username, $password );
} else {
$username = 'anonymous';
$bind = @ldap_bind( $this->_connectionID );
}
if (!$bind) {
$e = sprintf($this->_bind_errmsg,ldap_error($this->_connectionID));
$this->_errorMsg = $e;
if ($this->debug) ADOConnection::outp($e);
return false;
}
$this->_errorMsg = '';
$this->database = $ldapbase;
return $this->_connectionID;
}
/*
Valid Domain Values for LDAP Options:
LDAP_OPT_DEREF (integer)
LDAP_OPT_SIZELIMIT (integer)
LDAP_OPT_TIMELIMIT (integer)
LDAP_OPT_PROTOCOL_VERSION (integer)
LDAP_OPT_ERROR_NUMBER (integer)
LDAP_OPT_REFERRALS (boolean)
LDAP_OPT_RESTART (boolean)
LDAP_OPT_HOST_NAME (string)
LDAP_OPT_ERROR_STRING (string)
LDAP_OPT_MATCHED_DN (string)
LDAP_OPT_SERVER_CONTROLS (array)
LDAP_OPT_CLIENT_CONTROLS (array)
Make sure to set this BEFORE calling Connect()
Example:
$LDAP_CONNECT_OPTIONS = Array(
Array (
"OPTION_NAME"=>LDAP_OPT_DEREF,
"OPTION_VALUE"=>2
),
Array (
"OPTION_NAME"=>LDAP_OPT_SIZELIMIT,
"OPTION_VALUE"=>100
),
Array (
"OPTION_NAME"=>LDAP_OPT_TIMELIMIT,
"OPTION_VALUE"=>30
),
Array (
"OPTION_NAME"=>LDAP_OPT_PROTOCOL_VERSION,
"OPTION_VALUE"=>3
),
Array (
"OPTION_NAME"=>LDAP_OPT_ERROR_NUMBER,
"OPTION_VALUE"=>13
),
Array (
"OPTION_NAME"=>LDAP_OPT_REFERRALS,
"OPTION_VALUE"=>FALSE
),
Array (
"OPTION_NAME"=>LDAP_OPT_RESTART,
"OPTION_VALUE"=>FALSE
)
);
*/
function _inject_bind_options( $options ) {
foreach( $options as $option ) {
ldap_set_option( $this->_connectionID, $option["OPTION_NAME"], $option["OPTION_VALUE"] )
or die( "Unable to set server option: " . $option["OPTION_NAME"] );
}
}
/* returns _queryID or false */
function _query($sql,$inputarr=false)
{
$rs = @ldap_search( $this->_connectionID, $this->database, $sql );
$this->_errorMsg = ($rs) ? '' : 'Search error on '.$sql.': '.ldap_error($this->_connectionID);
return $rs;
}
function ErrorMsg()
{
return $this->_errorMsg;
}
function ErrorNo()
{
return @ldap_errno($this->_connectionID);
}
/* closes the LDAP connection */
function _close()
{
@ldap_close( $this->_connectionID );
$this->_connectionID = false;
}
function SelectDB($db) {
$this->database = $db;
return true;
} // SelectDB
function ServerInfo()
{
if( !empty( $this->version ) ) {
return $this->version;
}
$version = array();
/*
Determines how aliases are handled during search.
LDAP_DEREF_NEVER (0x00)
LDAP_DEREF_SEARCHING (0x01)
LDAP_DEREF_FINDING (0x02)
LDAP_DEREF_ALWAYS (0x03)
The LDAP_DEREF_SEARCHING value means aliases are dereferenced during the search but
not when locating the base object of the search. The LDAP_DEREF_FINDING value means
aliases are dereferenced when locating the base object but not during the search.
Default: LDAP_DEREF_NEVER
*/
ldap_get_option( $this->_connectionID, LDAP_OPT_DEREF, $version['LDAP_OPT_DEREF'] ) ;
switch ( $version['LDAP_OPT_DEREF'] ) {
case 0:
$version['LDAP_OPT_DEREF'] = 'LDAP_DEREF_NEVER';
case 1:
$version['LDAP_OPT_DEREF'] = 'LDAP_DEREF_SEARCHING';
case 2:
$version['LDAP_OPT_DEREF'] = 'LDAP_DEREF_FINDING';
case 3:
$version['LDAP_OPT_DEREF'] = 'LDAP_DEREF_ALWAYS';
}
/*
A limit on the number of entries to return from a search.
LDAP_NO_LIMIT (0) means no limit.
Default: LDAP_NO_LIMIT
*/
ldap_get_option( $this->_connectionID, LDAP_OPT_SIZELIMIT, $version['LDAP_OPT_SIZELIMIT'] );
if ( $version['LDAP_OPT_SIZELIMIT'] == 0 ) {
$version['LDAP_OPT_SIZELIMIT'] = 'LDAP_NO_LIMIT';
}
/*
A limit on the number of seconds to spend on a search.
LDAP_NO_LIMIT (0) means no limit.
Default: LDAP_NO_LIMIT
*/
ldap_get_option( $this->_connectionID, LDAP_OPT_TIMELIMIT, $version['LDAP_OPT_TIMELIMIT'] );
if ( $version['LDAP_OPT_TIMELIMIT'] == 0 ) {
$version['LDAP_OPT_TIMELIMIT'] = 'LDAP_NO_LIMIT';
}
/*
Determines whether the LDAP library automatically follows referrals returned by LDAP servers or not.
LDAP_OPT_ON
LDAP_OPT_OFF
Default: ON
*/
ldap_get_option( $this->_connectionID, LDAP_OPT_REFERRALS, $version['LDAP_OPT_REFERRALS'] );
if ( $version['LDAP_OPT_REFERRALS'] == 0 ) {
$version['LDAP_OPT_REFERRALS'] = 'LDAP_OPT_OFF';
} else {
$version['LDAP_OPT_REFERRALS'] = 'LDAP_OPT_ON';
}
/*
Determines whether LDAP I/O operations are automatically restarted if they abort prematurely.
LDAP_OPT_ON
LDAP_OPT_OFF
Default: OFF
*/
ldap_get_option( $this->_connectionID, LDAP_OPT_RESTART, $version['LDAP_OPT_RESTART'] );
if ( $version['LDAP_OPT_RESTART'] == 0 ) {
$version['LDAP_OPT_RESTART'] = 'LDAP_OPT_OFF';
} else {
$version['LDAP_OPT_RESTART'] = 'LDAP_OPT_ON';
}
/*
This option indicates the version of the LDAP protocol used when communicating with the primary LDAP server.
LDAP_VERSION2 (2)
LDAP_VERSION3 (3)
Default: LDAP_VERSION2 (2)
*/
ldap_get_option( $this->_connectionID, LDAP_OPT_PROTOCOL_VERSION, $version['LDAP_OPT_PROTOCOL_VERSION'] );
if ( $version['LDAP_OPT_PROTOCOL_VERSION'] == 2 ) {
$version['LDAP_OPT_PROTOCOL_VERSION'] = 'LDAP_VERSION2';
} else {
$version['LDAP_OPT_PROTOCOL_VERSION'] = 'LDAP_VERSION3';
}
/* The host name (or list of hosts) for the primary LDAP server. */
ldap_get_option( $this->_connectionID, LDAP_OPT_HOST_NAME, $version['LDAP_OPT_HOST_NAME'] );
ldap_get_option( $this->_connectionID, LDAP_OPT_ERROR_NUMBER, $version['LDAP_OPT_ERROR_NUMBER'] );
ldap_get_option( $this->_connectionID, LDAP_OPT_ERROR_STRING, $version['LDAP_OPT_ERROR_STRING'] );
ldap_get_option( $this->_connectionID, LDAP_OPT_MATCHED_DN, $version['LDAP_OPT_MATCHED_DN'] );
return $this->version = $version;
}
}
/*--------------------------------------------------------------------------------------
Class Name: Recordset
--------------------------------------------------------------------------------------*/
class ADORecordSet_ldap extends ADORecordSet{
var $databaseType = "ldap";
var $canSeek = false;
var $_entryID; /* keeps track of the entry resource identifier */
function __construct($queryID,$mode=false)
{
if ($mode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
}
switch ($mode)
{
case ADODB_FETCH_NUM:
$this->fetchMode = LDAP_NUM;
break;
case ADODB_FETCH_ASSOC:
$this->fetchMode = LDAP_ASSOC;
break;
case ADODB_FETCH_DEFAULT:
case ADODB_FETCH_BOTH:
default:
$this->fetchMode = LDAP_BOTH;
break;
}
parent::__construct($queryID);
}
function _initrs()
{
/*
This could be teaked to respect the $COUNTRECS directive from ADODB
It's currently being used in the _fetch() function and the
GetAssoc() function
*/
$this->_numOfRows = ldap_count_entries( $this->connection->_connectionID, $this->_queryID );
}
/*
Return whole recordset as a multi-dimensional associative array
*/
function GetAssoc($force_array = false, $first2cols = false, $fetchMode = -1)
{
$records = $this->_numOfRows;
$results = array();
for ( $i=0; $i < $records; $i++ ) {
foreach ( $this->fields as $k=>$v ) {
if ( is_array( $v ) ) {
if ( $v['count'] == 1 ) {
$results[$i][$k] = $v[0];
} else {
array_shift( $v );
$results[$i][$k] = $v;
}
}
}
}
return $results;
}
function GetRowAssoc($upper = ADODB_ASSOC_CASE)
{
$results = array();
foreach ( $this->fields as $k=>$v ) {
if ( is_array( $v ) ) {
if ( $v['count'] == 1 ) {
$results[$k] = $v[0];
} else {
array_shift( $v );
$results[$k] = $v;
}
}
}
return $results;
}
function GetRowNums()
{
$results = array();
foreach ( $this->fields as $k=>$v ) {
static $i = 0;
if (is_array( $v )) {
if ( $v['count'] == 1 ) {
$results[$i] = $v[0];
} else {
array_shift( $v );
$results[$i] = $v;
}
$i++;
}
}
return $results;
}
function _fetch()
{
if ( $this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0 ) {
return false;
}
if ( $this->_currentRow == 0 ) {
$this->_entryID = ldap_first_entry( $this->connection->_connectionID, $this->_queryID );
} else {
$this->_entryID = ldap_next_entry( $this->connection->_connectionID, $this->_entryID );
}
$this->fields = ldap_get_attributes( $this->connection->_connectionID, $this->_entryID );
$this->_numOfFields = $this->fields['count'];
switch ( $this->fetchMode ) {
case LDAP_ASSOC:
$this->fields = $this->GetRowAssoc();
break;
case LDAP_NUM:
$this->fields = array_merge($this->GetRowNums(),$this->GetRowAssoc());
break;
case LDAP_BOTH:
default:
$this->fields = $this->GetRowNums();
break;
}
return is_array( $this->fields );
}
function _close() {
@ldap_free_result( $this->_queryID );
$this->_queryID = false;
}
}

View File

@ -0,0 +1,937 @@
<?php
/**
* MySQL driver
*
* @deprecated
*
* This driver only supports the original non-transactional MySQL driver,
* which was deprecated in PHP version 5.5 and removed in PHP version 7.
* It is deprecated as of ADOdb version 5.20.0, use the mysqli driver
* instead, which supports both transactional and non-transactional updates.
*
* This file is part of ADOdb, a Database Abstraction Layer library for PHP.
*
* @package ADOdb
* @link https://adodb.org Project's web site and documentation
* @link https://github.com/ADOdb/ADOdb Source code and issue tracker
*
* The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
* and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
* any later version. This means you can use it in proprietary products.
* See the LICENSE.md file distributed with this source code for details.
* @license BSD-3-Clause
* @license LGPL-2.1-or-later
*
* @copyright 2000-2013 John Lim
* @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
*/
// security - hide paths
if (!defined('ADODB_DIR')) die();
if (! defined("_ADODB_MYSQL_LAYER")) {
define("_ADODB_MYSQL_LAYER", 1 );
class ADODB_mysql extends ADOConnection {
var $databaseType = 'mysql';
var $dataProvider = 'mysql';
var $hasInsertID = true;
var $hasAffectedRows = true;
var $metaTablesSQL = "SELECT
TABLE_NAME,
CASE WHEN TABLE_TYPE = 'VIEW' THEN 'V' ELSE 'T' END
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA=";
var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`";
var $fmtTimeStamp = "'Y-m-d H:i:s'";
var $hasLimit = true;
var $hasMoveFirst = true;
var $hasGenID = true;
var $isoDates = true; // accepts dates in ISO format
var $sysDate = 'CURDATE()';
var $sysTimeStamp = 'NOW()';
var $hasTransactions = false;
var $forceNewConnect = false;
var $poorAffectedRows = true;
var $clientFlags = 0;
var $charSet = '';
var $substr = "substring";
var $nameQuote = '`'; /// string to use to quote identifiers and names
var $compat323 = false; // true if compat with mysql 3.23
/**
* ADODB_mysql constructor.
*/
public function __construct() {
if(version_compare(PHP_VERSION, '7.0.0', '>=')) {
$this->outp_throw(
'mysql extension is not supported since PHP 7.0.0, use mysqli instead',
__METHOD__
);
die(1); // Stop execution even if not using Exceptions
} elseif(version_compare(PHP_VERSION, '5.5.0', '>=')) {
// If mysql extension is available just print a warning,
// otherwise die with an error message
if(function_exists('mysql_connect')) {
$this->outp('mysql extension is deprecated since PHP 5.5.0, consider using mysqli');
} else {
$this->outp_throw(
'mysql extension is not available, use mysqli instead',
__METHOD__
);
die(1); // Stop execution even if not using Exceptions
}
}
}
function setCharSet($charset)
{
if (!function_exists('mysql_set_charset')) {
return false;
}
if ($this->charSet !== $charset) {
$ok = @mysql_set_charset($charset,$this->_connectionID);
if ($ok) {
$this->charSet = $charset;
return true;
}
return false;
}
return true;
}
function serverInfo()
{
$arr['description'] = ADOConnection::GetOne("select version()");
$arr['version'] = ADOConnection::_findvers($arr['description']);
return $arr;
}
function ifNull( $field, $ifNull )
{
return " IFNULL($field, $ifNull) "; // if MySQL
}
function metaProcedures($NamePattern = false, $catalog = null, $schemaPattern = null)
{
// save old fetch mode
global $ADODB_FETCH_MODE;
$false = false;
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($this->fetchMode !== FALSE) {
$savem = $this->SetFetchMode(FALSE);
}
$procedures = array ();
// get index details
$likepattern = '';
if ($NamePattern) {
$likepattern = " LIKE '".$NamePattern."'";
}
$rs = $this->Execute('SHOW PROCEDURE STATUS'.$likepattern);
if (is_object($rs)) {
// parse index data into array
while ($row = $rs->FetchRow()) {
$procedures[$row[1]] = array(
'type' => 'PROCEDURE',
'catalog' => '',
'schema' => '',
'remarks' => $row[7],
);
}
}
$rs = $this->Execute('SHOW FUNCTION STATUS'.$likepattern);
if (is_object($rs)) {
// parse index data into array
while ($row = $rs->FetchRow()) {
$procedures[$row[1]] = array(
'type' => 'FUNCTION',
'catalog' => '',
'schema' => '',
'remarks' => $row[7]
);
}
}
// restore fetchmode
if (isset($savem)) {
$this->SetFetchMode($savem);
}
$ADODB_FETCH_MODE = $save;
return $procedures;
}
/**
* Retrieves a list of tables based on given criteria
*
* @param string $ttype Table type = 'TABLE', 'VIEW' or false=both (default)
* @param string $showSchema schema name, false = current schema (default)
* @param string $mask filters the table by name
*
* @return array list of tables
*/
function metaTables($ttype=false,$showSchema=false,$mask=false)
{
$save = $this->metaTablesSQL;
if ($showSchema && is_string($showSchema)) {
$this->metaTablesSQL .= $this->qstr($showSchema);
} else {
$this->metaTablesSQL .= "schema()";
}
if ($mask) {
$mask = $this->qstr($mask);
$this->metaTablesSQL .= " AND table_name LIKE $mask";
}
$ret = ADOConnection::MetaTables($ttype,$showSchema);
$this->metaTablesSQL = $save;
return $ret;
}
function metaIndexes ($table, $primary = FALSE, $owner=false)
{
// save old fetch mode
global $ADODB_FETCH_MODE;
$false = false;
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($this->fetchMode !== FALSE) {
$savem = $this->SetFetchMode(FALSE);
}
// get index details
$rs = $this->Execute(sprintf('SHOW INDEX FROM %s',$table));
// restore fetchmode
if (isset($savem)) {
$this->SetFetchMode($savem);
}
$ADODB_FETCH_MODE = $save;
if (!is_object($rs)) {
return $false;
}
$indexes = array ();
// parse index data into array
while ($row = $rs->FetchRow()) {
if ($primary == FALSE AND $row[2] == 'PRIMARY') {
continue;
}
if (!isset($indexes[$row[2]])) {
$indexes[$row[2]] = array(
'unique' => ($row[1] == 0),
'columns' => array()
);
}
$indexes[$row[2]]['columns'][$row[3] - 1] = $row[4];
}
// sort columns by order in the index
foreach ( array_keys ($indexes) as $index )
{
ksort ($indexes[$index]['columns']);
}
return $indexes;
}
/**
* Appropriately quotes strings with ' characters for insertion into the database.
*
* Relies on mysql_real_escape_string()
* @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:qstr
*
* @param string $s The string to quote
* @param bool $magic_quotes This param is not used since 5.21.0.
* It remains for backwards compatibility.
*
* @return string Quoted string
*/
function qStr($s, $magic_quotes=false)
{
if (is_null($s)) {
return 'NULL';
}
if (is_resource($this->_connectionID)) {
return "'" . mysql_real_escape_string($s, $this->_connectionID) . "'";
}
if ($this->replaceQuote[0] == '\\') {
$s = str_replace(array('\\', "\0"), array('\\\\', "\\\0"), $s);
}
return "'" . str_replace("'", $this->replaceQuote, $s) . "'";
}
protected function _insertID($table = '', $column = '')
{
return ADOConnection::GetOne('SELECT LAST_INSERT_ID()');
//return mysql_insert_id($this->_connectionID);
}
function getOne($sql,$inputarr=false)
{
global $ADODB_GETONE_EOF;
if ($this->compat323 == false && strncasecmp($sql,'sele',4) == 0) {
$rs = $this->SelectLimit($sql,1,-1,$inputarr);
if ($rs) {
$rs->Close();
if ($rs->EOF) return $ADODB_GETONE_EOF;
return reset($rs->fields);
}
} else {
return ADOConnection::GetOne($sql,$inputarr);
}
return false;
}
function beginTrans()
{
if ($this->debug) ADOConnection::outp("Transactions not supported in 'mysql' driver. Use 'mysqlt' or 'mysqli' driver");
}
function _affectedrows()
{
return mysql_affected_rows($this->_connectionID);
}
// See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
// Reference on Last_Insert_ID on the recommended way to simulate sequences
var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
var $_genSeqSQL = "create table if not exists %s (id int not null)";
var $_genSeqCountSQL = "select count(*) from %s";
var $_genSeq2SQL = "insert into %s values (%s)";
var $_dropSeqSQL = "drop table if exists %s";
function createSequence($seqname='adodbseq',$startID=1)
{
if (empty($this->_genSeqSQL)) return false;
$u = strtoupper($seqname);
$ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));
if (!$ok) return false;
return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
}
function genID($seqname='adodbseq',$startID=1)
{
// post-nuke sets hasGenID to false
if (!$this->hasGenID) return false;
$savelog = $this->_logsql;
$this->_logsql = false;
$getnext = sprintf($this->_genIDSQL,$seqname);
$holdtransOK = $this->_transOK; // save the current status
$rs = @$this->Execute($getnext);
if (!$rs) {
if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
$u = strtoupper($seqname);
$this->Execute(sprintf($this->_genSeqSQL,$seqname));
$cnt = $this->GetOne(sprintf($this->_genSeqCountSQL,$seqname));
if (!$cnt) $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
$rs = $this->Execute($getnext);
}
if ($rs) {
$this->genID = mysql_insert_id($this->_connectionID);
$rs->Close();
} else
$this->genID = 0;
$this->_logsql = $savelog;
return $this->genID;
}
function metaDatabases()
{
$qid = mysql_list_dbs($this->_connectionID);
$arr = array();
$i = 0;
$max = mysql_num_rows($qid);
while ($i < $max) {
$db = mysql_tablename($qid,$i);
if ($db != 'mysql') $arr[] = $db;
$i += 1;
}
return $arr;
}
// Format date column in sql string given an input format that understands Y M D
function sqlDate($fmt, $col=false)
{
if (!$col) $col = $this->sysTimeStamp;
$s = 'DATE_FORMAT('.$col.",'";
$concat = false;
$len = strlen($fmt);
for ($i=0; $i < $len; $i++) {
$ch = $fmt[$i];
switch($ch) {
default:
if ($ch == '\\') {
$i++;
$ch = substr($fmt,$i,1);
}
/** FALL THROUGH */
case '-':
case '/':
$s .= $ch;
break;
case 'Y':
case 'y':
$s .= '%Y';
break;
case 'M':
$s .= '%b';
break;
case 'm':
$s .= '%m';
break;
case 'D':
case 'd':
$s .= '%d';
break;
case 'Q':
case 'q':
$s .= "'),Quarter($col)";
if ($len > $i+1) $s .= ",DATE_FORMAT($col,'";
else $s .= ",('";
$concat = true;
break;
case 'H':
$s .= '%H';
break;
case 'h':
$s .= '%I';
break;
case 'i':
$s .= '%i';
break;
case 's':
$s .= '%s';
break;
case 'a':
case 'A':
$s .= '%p';
break;
case 'w':
$s .= '%w';
break;
case 'W':
$s .= '%U';
break;
case 'l':
$s .= '%W';
break;
}
}
$s.="')";
if ($concat) $s = "CONCAT($s)";
return $s;
}
// returns concatenated string
// much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator
function concat()
{
$s = "";
$arr = func_get_args();
// suggestion by andrew005@mnogo.ru
$s = implode(',',$arr);
if (strlen($s) > 0) return "CONCAT($s)";
else return '';
}
function offsetDate($dayFraction,$date=false)
{
if (!$date) $date = $this->sysDate;
$fraction = $dayFraction * 24 * 3600;
return '('. $date . ' + INTERVAL ' . $fraction.' SECOND)';
// return "from_unixtime(unix_timestamp($date)+$fraction)";
}
// returns true or false
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
if (!empty($this->port))
$argHostname .= ":".$this->port;
$this->_connectionID =
mysql_connect($argHostname,
$argUsername,
$argPassword,
$this->forceNewConnect,
$this->clientFlags
);
if ($this->_connectionID === false)
return false;
if ($argDatabasename)
return $this->SelectDB($argDatabasename);
return true;
}
// returns true or false
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
if (!empty($this->port)) $argHostname .= ":".$this->port;
$this->_connectionID =
mysql_pconnect($argHostname,
$argUsername,
$argPassword,
$this->clientFlags);
if ($this->_connectionID === false)
return false;
if ($this->autoRollback)
$this->RollbackTrans();
if ($argDatabasename)
return $this->SelectDB($argDatabasename);
return true;
}
function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
$this->forceNewConnect = true;
return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
}
function metaColumns($table, $normalize=true)
{
$this->_findschema($table,$schema);
if ($schema) {
$dbName = $this->database;
$this->SelectDB($schema);
}
global $ADODB_FETCH_MODE;
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
$rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
if ($schema) {
$this->SelectDB($dbName);
}
if (isset($savem)) $this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
if (!is_object($rs)) {
$false = false;
return $false;
}
$retarr = array();
while (!$rs->EOF){
$fld = new ADOFieldObject();
$fld->name = $rs->fields[0];
$type = $rs->fields[1];
// split type into type(length):
$fld->scale = null;
if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
$fld->type = $query_array[1];
$fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
$fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
} elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
$fld->type = $query_array[1];
$fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
} elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
$fld->type = $query_array[1];
$arr = explode(",",$query_array[2]);
$fld->enums = $arr;
$zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6
$fld->max_length = ($zlen > 0) ? $zlen : 1;
} else {
$fld->type = $type;
$fld->max_length = -1;
}
$fld->not_null = ($rs->fields[2] != 'YES');
$fld->primary_key = ($rs->fields[3] == 'PRI');
$fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
$fld->binary = (strpos($type,'blob') !== false || strpos($type,'binary') !== false);
$fld->unsigned = (strpos($type,'unsigned') !== false);
$fld->zerofill = (strpos($type,'zerofill') !== false);
if (!$fld->binary) {
$d = $rs->fields[4];
if ($d != '' && $d != 'NULL') {
$fld->has_default = true;
$fld->default_value = $d;
} else {
$fld->has_default = false;
}
}
if ($save == ADODB_FETCH_NUM) {
$retarr[] = $fld;
} else {
$retarr[strtoupper($fld->name)] = $fld;
}
$rs->MoveNext();
}
$rs->Close();
return $retarr;
}
// returns true or false
function selectDB($dbName)
{
$this->database = $dbName;
$this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions
if ($this->_connectionID) {
return @mysql_select_db($dbName,$this->_connectionID);
}
else return false;
}
// parameters use PostgreSQL convention, not MySQL
function selectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
{
$nrows = (int) $nrows;
$offset = (int) $offset;
$offsetStr =($offset>=0) ? ((integer)$offset)."," : '';
// jason judge, see PHPLens Issue No: 9220
if ($nrows < 0) $nrows = '18446744073709551615';
if ($secs)
$rs = $this->CacheExecute($secs,$sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
else
$rs = $this->Execute($sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
return $rs;
}
// returns queryID or false
function _query($sql,$inputarr=false)
{
return mysql_query($sql,$this->_connectionID);
/*
global $ADODB_COUNTRECS;
if($ADODB_COUNTRECS)
return mysql_query($sql,$this->_connectionID);
else
return @mysql_unbuffered_query($sql,$this->_connectionID); // requires PHP >= 4.0.6
*/
}
/* Returns: the last error message from previous database operation */
function errorMsg()
{
if ($this->_logsql) return $this->_errorMsg;
if (empty($this->_connectionID)) $this->_errorMsg = @mysql_error();
else $this->_errorMsg = @mysql_error($this->_connectionID);
return $this->_errorMsg;
}
/* Returns: the last error number from previous database operation */
function errorNo()
{
if ($this->_logsql) return $this->_errorCode;
if (empty($this->_connectionID)) return @mysql_errno();
else return @mysql_errno($this->_connectionID);
}
// returns true or false
function _close()
{
@mysql_close($this->_connectionID);
$this->charSet = '';
$this->_connectionID = false;
}
/*
* Maximum size of C field
*/
function charMax()
{
return 255;
}
/*
* Maximum size of X field
*/
function textMax()
{
return 4294967295;
}
public function metaForeignKeys($table, $owner = '', $upper = false, $associativee = false)
{
global $ADODB_FETCH_MODE;
if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC || $this->fetchMode == ADODB_FETCH_ASSOC) $associative = true;
if ( !empty($owner) ) {
$table = "$owner.$table";
}
$a_create_table = $this->getRow(sprintf('SHOW CREATE TABLE %s', $table));
if ($associative) {
$create_sql = isset($a_create_table["Create Table"]) ? $a_create_table["Create Table"] : $a_create_table["Create View"];
} else {
$create_sql = $a_create_table[1];
}
$matches = array();
if (!preg_match_all("/FOREIGN KEY \(`(.*?)`\) REFERENCES `(.*?)` \(`(.*?)`\)/", $create_sql, $matches)) return false;
$foreign_keys = array();
$num_keys = count($matches[0]);
for ( $i = 0; $i < $num_keys; $i ++ ) {
$my_field = explode('`, `', $matches[1][$i]);
$ref_table = $matches[2][$i];
$ref_field = explode('`, `', $matches[3][$i]);
if ( $upper ) {
$ref_table = strtoupper($ref_table);
}
// see https://sourceforge.net/p/adodb/bugs/100/
if (!isset($foreign_keys[$ref_table])) {
$foreign_keys[$ref_table] = array();
}
$num_fields = count($my_field);
for ( $j = 0; $j < $num_fields; $j ++ ) {
if ( $associative ) {
$foreign_keys[$ref_table][$ref_field[$j]] = $my_field[$j];
} else {
$foreign_keys[$ref_table][] = "{$my_field[$j]}={$ref_field[$j]}";
}
}
}
return $foreign_keys;
}
}
/*--------------------------------------------------------------------------------------
Class Name: Recordset
--------------------------------------------------------------------------------------*/
class ADORecordSet_mysql extends ADORecordSet{
var $databaseType = "mysql";
var $canSeek = true;
function __construct($queryID,$mode=false)
{
if ($mode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
}
switch ($mode)
{
case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;
case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;
case ADODB_FETCH_DEFAULT:
case ADODB_FETCH_BOTH:
default:
$this->fetchMode = MYSQL_BOTH; break;
}
$this->adodbFetchMode = $mode;
parent::__construct($queryID);
}
function _initrs()
{
//GLOBAL $ADODB_COUNTRECS;
// $this->_numOfRows = ($ADODB_COUNTRECS) ? @mysql_num_rows($this->_queryID):-1;
$this->_numOfRows = @mysql_num_rows($this->_queryID);
$this->_numOfFields = @mysql_num_fields($this->_queryID);
}
function fetchField($fieldOffset = -1)
{
if ($fieldOffset != -1) {
$o = @mysql_fetch_field($this->_queryID, $fieldOffset);
$f = @mysql_field_flags($this->_queryID,$fieldOffset);
if ($o) $o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich#att.com)
//$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
if ($o) $o->binary = (strpos($f,'binary')!== false);
}
else { /* The $fieldOffset argument is not provided thus its -1 */
$o = @mysql_fetch_field($this->_queryID);
//if ($o) $o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich#att.com)
$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
}
return $o;
}
function getRowAssoc($upper = ADODB_ASSOC_CASE)
{
if ($this->fetchMode == MYSQL_ASSOC && $upper == ADODB_ASSOC_CASE_LOWER) {
$row = $this->fields;
}
else {
$row = ADORecordSet::GetRowAssoc($upper);
}
return $row;
}
/* Use associative array to get fields array */
function fields($colname)
{
// added @ by "Michael William Miller" <mille562@pilot.msu.edu>
if ($this->fetchMode != MYSQL_NUM) return @$this->fields[$colname];
if (!$this->bind) {
$this->bind = array();
for ($i=0; $i < $this->_numOfFields; $i++) {
$o = $this->FetchField($i);
$this->bind[strtoupper($o->name)] = $i;
}
}
return $this->fields[$this->bind[strtoupper($colname)]];
}
function _seek($row)
{
if ($this->_numOfRows == 0) return false;
return @mysql_data_seek($this->_queryID,$row);
}
function moveNext()
{
if (@$this->fields = mysql_fetch_array($this->_queryID,$this->fetchMode)) {
$this->_updatefields();
$this->_currentRow += 1;
return true;
}
if (!$this->EOF) {
$this->_currentRow += 1;
$this->EOF = true;
}
return false;
}
function _fetch()
{
$this->fields = @mysql_fetch_array($this->_queryID,$this->fetchMode);
$this->_updatefields();
return is_array($this->fields);
}
function _close() {
@mysql_free_result($this->_queryID);
$this->_queryID = false;
}
function metaType($t,$len=-1,$fieldobj=false)
{
if (is_object($t)) {
$fieldobj = $t;
$t = $fieldobj->type;
$len = $fieldobj->max_length;
}
$t = strtoupper($t);
if (array_key_exists($t,$this->connection->customActualTypes))
return $this->connection->customActualTypes[$t];
$len = -1; // mysql max_length is not accurate
switch ($t) {
case 'STRING':
case 'CHAR':
case 'VARCHAR':
case 'TINYBLOB':
case 'TINYTEXT':
case 'ENUM':
case 'SET':
if ($len <= $this->blobSize) return 'C';
case 'TEXT':
case 'LONGTEXT':
case 'MEDIUMTEXT':
return 'X';
// php_mysql extension always returns 'blob' even if 'text'
// so we have to check whether binary...
case 'IMAGE':
case 'LONGBLOB':
case 'BLOB':
case 'MEDIUMBLOB':
case 'BINARY':
return !empty($fieldobj->binary) ? 'B' : 'X';
case 'YEAR':
case 'DATE': return 'D';
case 'TIME':
case 'DATETIME':
case 'TIMESTAMP': return 'T';
case 'INT':
case 'INTEGER':
case 'BIGINT':
case 'TINYINT':
case 'MEDIUMINT':
case 'SMALLINT':
if (!empty($fieldobj->primary_key)) return 'R';
else return 'I';
default: return ADODB_DEFAULT_METATYPE;
}
}
}
/**
* Class ADORecordSet_ext_mysql
*/
class ADORecordSet_ext_mysql extends ADORecordSet_mysql {
function moveNext()
{
return @adodb_movenext($this);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,124 @@
<?php
/**
* Portable MySQL driver
*
* @deprecated
*
* Extends the deprecated mysql driver, and was originally designed to be a
* portable driver in the same manner as oci8po and mssqlpo. Its functionality
* is exactly duplicated in the mysqlt driver, which is itself deprecated.
* This driver will be removed in ADOdb version 6.0.0.
*
* This file is part of ADOdb, a Database Abstraction Layer library for PHP.
*
* @package ADOdb
* @link https://adodb.org Project's web site and documentation
* @link https://github.com/ADOdb/ADOdb Source code and issue tracker
*
* The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
* and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
* any later version. This means you can use it in proprietary products.
* See the LICENSE.md file distributed with this source code for details.
* @license BSD-3-Clause
* @license LGPL-2.1-or-later
*
* @copyright 2000-2013 John Lim
* @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
*/
// security - hide paths
if (!defined('ADODB_DIR')) die();
include_once(ADODB_DIR."/drivers/adodb-mysql.inc.php");
class ADODB_mysqlt extends ADODB_mysql {
var $databaseType = 'mysqlt';
var $ansiOuter = true; // for Version 3.23.17 or later
var $hasTransactions = true;
var $autoRollback = true; // apparently mysql does not autorollback properly
function BeginTrans()
{
if ($this->transOff) return true;
$this->transCnt += 1;
$this->Execute('SET AUTOCOMMIT=0');
$this->Execute('BEGIN');
return true;
}
function CommitTrans($ok=true)
{
if ($this->transOff) return true;
if (!$ok) return $this->RollbackTrans();
if ($this->transCnt) $this->transCnt -= 1;
$this->Execute('COMMIT');
$this->Execute('SET AUTOCOMMIT=1');
return true;
}
function RollbackTrans()
{
if ($this->transOff) return true;
if ($this->transCnt) $this->transCnt -= 1;
$this->Execute('ROLLBACK');
$this->Execute('SET AUTOCOMMIT=1');
return true;
}
function RowLock($tables,$where='',$col='1 as adodbignore')
{
if ($this->transCnt==0) $this->BeginTrans();
if ($where) $where = ' where '.$where;
$rs = $this->Execute("select $col from $tables $where for update");
return !empty($rs);
}
}
class ADORecordSet_mysqlt extends ADORecordSet_mysql{
var $databaseType = "mysqlt";
function __construct($queryID,$mode=false)
{
if ($mode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
}
switch ($mode)
{
case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;
case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;
case ADODB_FETCH_DEFAULT:
case ADODB_FETCH_BOTH:
default: $this->fetchMode = MYSQL_BOTH; break;
}
$this->adodbFetchMode = $mode;
parent::__construct($queryID);
}
function MoveNext()
{
if (@$this->fields = mysql_fetch_array($this->_queryID,$this->fetchMode)) {
$this->_currentRow += 1;
return true;
}
if (!$this->EOF) {
$this->_currentRow += 1;
$this->EOF = true;
}
return false;
}
}
class ADORecordSet_ext_mysqlt extends ADORecordSet_mysqlt {
function MoveNext()
{
return adodb_movenext($this);
}
}

View File

@ -0,0 +1,141 @@
<?php
/**
* MySQL driver in transactional mode
*
* @deprecated
*
* This driver only supports the original MySQL driver in transactional mode. It
* is deprecated in PHP version 5.5 and removed in PHP version 7. It is deprecated
* as of ADOdb version 5.20.0. Use the mysqli driver instead, which supports both
* transactional and non-transactional updates
*
* This file is part of ADOdb, a Database Abstraction Layer library for PHP.
*
* @package ADOdb
* @link https://adodb.org Project's web site and documentation
* @link https://github.com/ADOdb/ADOdb Source code and issue tracker
*
* The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
* and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
* any later version. This means you can use it in proprietary products.
* See the LICENSE.md file distributed with this source code for details.
* @license BSD-3-Clause
* @license LGPL-2.1-or-later
*
* @copyright 2000-2013 John Lim
* @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
*/
// security - hide paths
if (!defined('ADODB_DIR')) die();
include_once(ADODB_DIR."/drivers/adodb-mysql.inc.php");
class ADODB_mysqlt extends ADODB_mysql {
var $databaseType = 'mysqlt';
var $ansiOuter = true; // for Version 3.23.17 or later
var $hasTransactions = true;
var $autoRollback = true; // apparently mysql does not autorollback properly
/* set transaction mode
SET [GLOBAL | SESSION] TRANSACTION ISOLATION LEVEL
{ READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE }
*/
function SetTransactionMode( $transaction_mode )
{
$this->_transmode = $transaction_mode;
if (empty($transaction_mode)) {
$this->Execute('SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ');
return;
}
if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
$this->Execute("SET SESSION TRANSACTION ".$transaction_mode);
}
function BeginTrans()
{
if ($this->transOff) return true;
$this->transCnt += 1;
$this->Execute('SET AUTOCOMMIT=0');
$this->Execute('BEGIN');
return true;
}
function CommitTrans($ok=true)
{
if ($this->transOff) return true;
if (!$ok) return $this->RollbackTrans();
if ($this->transCnt) $this->transCnt -= 1;
$ok = $this->Execute('COMMIT');
$this->Execute('SET AUTOCOMMIT=1');
return $ok ? true : false;
}
function RollbackTrans()
{
if ($this->transOff) return true;
if ($this->transCnt) $this->transCnt -= 1;
$ok = $this->Execute('ROLLBACK');
$this->Execute('SET AUTOCOMMIT=1');
return $ok ? true : false;
}
function RowLock($tables,$where='',$col='1 as adodbignore')
{
if ($this->transCnt==0) $this->BeginTrans();
if ($where) $where = ' where '.$where;
$rs = $this->Execute("select $col from $tables $where for update");
return !empty($rs);
}
}
class ADORecordSet_mysqlt extends ADORecordSet_mysql{
var $databaseType = "mysqlt";
function __construct($queryID,$mode=false)
{
if ($mode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
}
switch ($mode)
{
case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;
case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;
case ADODB_FETCH_DEFAULT:
case ADODB_FETCH_BOTH:
default: $this->fetchMode = MYSQL_BOTH; break;
}
$this->adodbFetchMode = $mode;
parent::__construct($queryID);
}
function MoveNext()
{
if (@$this->fields = mysql_fetch_array($this->_queryID,$this->fetchMode)) {
$this->_currentRow += 1;
return true;
}
if (!$this->EOF) {
$this->_currentRow += 1;
$this->EOF = true;
}
return false;
}
}
class ADORecordSet_ext_mysqlt extends ADORecordSet_mysqlt {
function MoveNext()
{
return adodb_movenext($this);
}
}

View File

@ -0,0 +1,922 @@
<?php
/**
* ADOdb base PDO driver
*
* This file is part of ADOdb, a Database Abstraction Layer library for PHP.
*
* @package ADOdb
* @link https://adodb.org Project's web site and documentation
* @link https://github.com/ADOdb/ADOdb Source code and issue tracker
*
* The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
* and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
* any later version. This means you can use it in proprietary products.
* See the LICENSE.md file distributed with this source code for details.
* @license BSD-3-Clause
* @license LGPL-2.1-or-later
*
* @copyright 2000-2013 John Lim
* @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
*/
// security - hide paths
if (!defined('ADODB_DIR')) die();
/*
enum pdo_param_type {
PDO::PARAM_NULL, 0
/* int as in long (the php native int type).
* If you mark a column as an int, PDO expects get_col to return
* a pointer to a long
PDO::PARAM_INT, 1
/* get_col ptr should point to start of the string buffer
PDO::PARAM_STR, 2
/* get_col: when len is 0 ptr should point to a php_stream *,
* otherwise it should behave like a string. Indicate a NULL field
* value by setting the ptr to NULL
PDO::PARAM_LOB, 3
/* get_col: will expect the ptr to point to a new PDOStatement object handle,
* but this isn't wired up yet
PDO::PARAM_STMT, 4 /* hierarchical result set
/* get_col ptr should point to a zend_bool
PDO::PARAM_BOOL, 5
/* magic flag to denote a parameter as being input/output
PDO::PARAM_INPUT_OUTPUT = 0x80000000
};
*/
function adodb_pdo_type($t)
{
switch($t) {
case 2: return 'VARCHAR';
case 3: return 'BLOB';
default: return 'NUMERIC';
}
}
/*----------------------------------------------------------------------------*/
class ADODB_pdo extends ADOConnection {
var $databaseType = "pdo";
var $dataProvider = "pdo";
var $fmtDate = "'Y-m-d'";
var $fmtTimeStamp = "'Y-m-d, h:i:sA'";
var $replaceQuote = "''"; // string to use to replace quotes
var $hasAffectedRows = true;
var $_bindInputArray = true;
var $_genIDSQL;
var $_genSeqSQL = "create table %s (id integer)";
var $_dropSeqSQL;
var $_autocommit = true;
var $_lastAffectedRows = 0;
var $_errormsg = false;
var $_errorno = false;
var $stmt = false;
var $_driver;
/*
* Describe parameters passed directly to the PDO driver
*
* @example $db->pdoOptions = [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION];
*/
public $pdoParameters = array();
function _UpdatePDO()
{
$d = $this->_driver;
$this->fmtDate = $d->fmtDate;
$this->fmtTimeStamp = $d->fmtTimeStamp;
$this->replaceQuote = $d->replaceQuote;
$this->sysDate = $d->sysDate;
$this->sysTimeStamp = $d->sysTimeStamp;
$this->random = $d->random;
$this->concat_operator = $d->concat_operator;
$this->nameQuote = $d->nameQuote;
$this->arrayClass = $d->arrayClass;
$this->hasGenID = $d->hasGenID;
$this->_genIDSQL = $d->_genIDSQL;
$this->_genSeqSQL = $d->_genSeqSQL;
$this->_dropSeqSQL = $d->_dropSeqSQL;
$d->_init($this);
}
function Time()
{
if (!empty($this->_driver->_hasdual)) {
$sql = "select $this->sysTimeStamp from dual";
}
else {
$sql = "select $this->sysTimeStamp";
}
$rs = $this->_Execute($sql);
if ($rs && !$rs->EOF) {
return $this->UnixTimeStamp(reset($rs->fields));
}
return false;
}
// returns true or false
function _connect($argDSN, $argUsername, $argPassword, $argDatabasename, $persist=false)
{
$at = strpos($argDSN,':');
$this->dsnType = substr($argDSN,0,$at);
if ($argDatabasename) {
switch($this->dsnType){
case 'sqlsrv':
$argDSN .= ';database='.$argDatabasename;
break;
case 'mssql':
case 'mysql':
case 'oci':
case 'pgsql':
case 'sqlite':
case 'firebird':
default:
$argDSN .= ';dbname='.$argDatabasename;
}
}
/*
* Configure for persistent connection if required,
* by adding the the pdo parameter into any provided
* ones
*/
if ($persist) {
$this->pdoParameters[\PDO::ATTR_PERSISTENT] = true;
}
try {
$this->_connectionID = new \PDO($argDSN, $argUsername, $argPassword, $this->pdoParameters);
} catch (Exception $e) {
$this->_connectionID = false;
$this->_errorno = -1;
//var_dump($e);
$this->_errormsg = 'Connection attempt failed: '.$e->getMessage();
return false;
}
if ($this->_connectionID) {
switch(ADODB_ASSOC_CASE){
case ADODB_ASSOC_CASE_LOWER:
$m = PDO::CASE_LOWER;
break;
case ADODB_ASSOC_CASE_UPPER:
$m = PDO::CASE_UPPER;
break;
default:
case ADODB_ASSOC_CASE_NATIVE:
$m = PDO::CASE_NATURAL;
break;
}
//$this->_connectionID->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_SILENT );
$this->_connectionID->setAttribute(PDO::ATTR_CASE,$m);
// Now merge in any provided attributes for PDO
foreach ($this->connectionParameters as $options) {
foreach($options as $k=>$v) {
if ($this->debug) {
ADOconnection::outp('Setting attribute: ' . $k . ' to ' . $v);
}
$this->_connectionID->setAttribute($k,$v);
}
}
$class = 'ADODB_pdo_'.$this->dsnType;
//$this->_connectionID->setAttribute(PDO::ATTR_AUTOCOMMIT,true);
switch($this->dsnType) {
case 'mssql':
case 'mysql':
case 'oci':
case 'pgsql':
case 'sqlite':
case 'sqlsrv':
case 'firebird':
case 'dblib':
include_once(ADODB_DIR.'/drivers/adodb-pdo_'.$this->dsnType.'.inc.php');
break;
}
if (class_exists($class)) {
$this->_driver = new $class();
}
else {
$this->_driver = new ADODB_pdo_base();
}
$this->_driver->_connectionID = $this->_connectionID;
$this->_UpdatePDO();
$this->_driver->database = $this->database;
return true;
}
$this->_driver = new ADODB_pdo_base();
return false;
}
function Concat()
{
$args = func_get_args();
if($this->_driver instanceof ADODB_pdo && method_exists($this->_driver, 'Concat')) {
return call_user_func_array(array($this->_driver, 'Concat'), $args);
}
return call_user_func_array('parent::Concat', $args);
}
/**
* Triggers a driver-specific request for a bind parameter
*
* @param string $name
* @param string $type
*
* @return string
*/
public function param($name,$type='C') {
$args = func_get_args();
if($this->_driver instanceof ADODB_pdo && method_exists($this->_driver, 'param')) {
// Return the driver specific entry, that mimics the native driver
return call_user_func_array(array($this->_driver, 'param'), $args);
}
// No driver specific method defined, use mysql format '?'
return call_user_func_array('parent::param', $args);
}
// returns true or false
function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
{
return $this->_connect($argDSN, $argUsername, $argPassword, $argDatabasename, true);
}
/*------------------------------------------------------------------------------*/
function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
{
$save = $this->_driver->fetchMode;
$this->_driver->fetchMode = $this->fetchMode;
$this->_driver->debug = $this->debug;
$ret = $this->_driver->SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
$this->_driver->fetchMode = $save;
return $ret;
}
function ServerInfo()
{
return $this->_driver->ServerInfo();
}
function MetaTables($ttype=false,$showSchema=false,$mask=false)
{
return $this->_driver->MetaTables($ttype,$showSchema,$mask);
}
function MetaColumns($table,$normalize=true)
{
return $this->_driver->MetaColumns($table,$normalize);
}
public function metaIndexes($table,$normalize=true,$owner=false)
{
if (method_exists($this->_driver,'metaIndexes'))
return $this->_driver->metaIndexes($table,$normalize,$owner);
}
/**
* Return a list of Primary Keys for a specified table.
*
* @param string $table
* @param bool $owner (optional) not used in this driver
*
* @return string[] Array of indexes
*/
public function metaPrimaryKeys($table,$owner=false)
{
if (method_exists($this->_driver,'metaPrimaryKeys'))
return $this->_driver->metaPrimaryKeys($table,$owner);
}
/**
* Returns a list of Foreign Keys associated with a specific table.
*
* @param string $table
* @param string $owner (optional) not used in this driver
* @param bool $upper
* @param bool $associative
*
* @return string[]|false An array where keys are tables, and values are foreign keys;
* false if no foreign keys could be found.
*/
public function metaForeignKeys($table, $owner = '', $upper = false, $associative = false) {
if (method_exists($this->_driver,'metaForeignKeys'))
return $this->_driver->metaForeignKeys($table, $owner, $upper, $associative);
}
/**
* List procedures or functions in an array.
*
* @param $procedureNamePattern A procedure name pattern; must match the procedure name as it is stored in the database.
* @param $catalog A catalog name; must match the catalog name as it is stored in the database.
* @param $schemaPattern A schema name pattern.
*
* @return false|array false if not supported, or array of procedures on current database with structure below
* Array(
* [name_of_procedure] => Array(
* [type] => PROCEDURE or FUNCTION
* [catalog] => Catalog_name
* [schema] => Schema_name
* [remarks] => explanatory comment on the procedure
* )
* )
*/
public function metaProcedures($procedureNamePattern = null, $catalog = null, $schemaPattern = null) {
if (method_exists($this->_driver,'metaProcedures'))
return $this->_driver->metaProcedures($procedureNamePattern,$catalog,$schemaPattern);
return false;
}
function InParameter(&$stmt,&$var,$name,$maxLen=4000,$type=false)
{
$obj = $stmt[1];
if ($type) {
$obj->bindParam($name, $var, $type, $maxLen);
}
else {
$obj->bindParam($name, $var);
}
}
function OffsetDate($dayFraction,$date=false)
{
return $this->_driver->OffsetDate($dayFraction,$date);
}
function SelectDB($dbName)
{
return $this->_driver->SelectDB($dbName);
}
function SQLDate($fmt, $col=false)
{
return $this->_driver->SQLDate($fmt, $col);
}
function ErrorMsg()
{
if ($this->_errormsg !== false) {
return $this->_errormsg;
}
if (!empty($this->_stmt)) {
$arr = $this->_stmt->errorInfo();
}
else if (!empty($this->_connectionID)) {
$arr = $this->_connectionID->errorInfo();
}
else {
return 'No Connection Established';
}
if ($arr) {
if (sizeof($arr)<2) {
return '';
}
if ((integer)$arr[0]) {
return $arr[2];
}
else {
return '';
}
}
else {
return '-1';
}
}
function ErrorNo()
{
if ($this->_errorno !== false) {
return $this->_errorno;
}
if (!empty($this->_stmt)) {
$err = $this->_stmt->errorCode();
}
else if (!empty($this->_connectionID)) {
$arr = $this->_connectionID->errorInfo();
if (isset($arr[0])) {
$err = $arr[0];
}
else {
$err = -1;
}
} else {
return 0;
}
if ($err == '00000') {
return 0; // allows empty check
}
return $err;
}
/**
* @param bool $auto_commit
* @return void
*/
function SetAutoCommit($auto_commit)
{
if($this->_driver instanceof ADODB_pdo && method_exists($this->_driver, 'SetAutoCommit')) {
$this->_driver->SetAutoCommit($auto_commit);
}
}
function SetTransactionMode($transaction_mode)
{
if($this->_driver instanceof ADODB_pdo && method_exists($this->_driver, 'SetTransactionMode')) {
return $this->_driver->SetTransactionMode($transaction_mode);
}
return parent::SetTransactionMode($transaction_mode);
}
function beginTrans()
{
if($this->_driver instanceof ADODB_pdo && method_exists($this->_driver, 'beginTrans')) {
return $this->_driver->beginTrans();
}
if (!$this->hasTransactions) {
return false;
}
if ($this->transOff) {
return true;
}
$this->transCnt += 1;
$this->_autocommit = false;
$this->SetAutoCommit(false);
return $this->_connectionID->beginTransaction();
}
function commitTrans($ok=true)
{
if($this->_driver instanceof ADODB_pdo && method_exists($this->_driver, 'commitTrans')) {
return $this->_driver->commitTrans($ok);
}
if (!$this->hasTransactions) {
return false;
}
if ($this->transOff) {
return true;
}
if (!$ok) {
return $this->rollbackTrans();
}
if ($this->transCnt) {
$this->transCnt -= 1;
}
$this->_autocommit = true;
$ret = $this->_connectionID->commit();
$this->SetAutoCommit(true);
return $ret;
}
function RollbackTrans()
{
if($this->_driver instanceof ADODB_pdo && method_exists($this->_driver, 'RollbackTrans')) {
return $this->_driver->RollbackTrans();
}
if (!$this->hasTransactions) {
return false;
}
if ($this->transOff) {
return true;
}
if ($this->transCnt) {
$this->transCnt -= 1;
}
$this->_autocommit = true;
$ret = $this->_connectionID->rollback();
$this->SetAutoCommit(true);
return $ret;
}
function Prepare($sql)
{
$this->_stmt = $this->_connectionID->prepare($sql);
if ($this->_stmt) {
return array($sql,$this->_stmt);
}
return false;
}
function PrepareStmt($sql)
{
$stmt = $this->_connectionID->prepare($sql);
if (!$stmt) {
return false;
}
$obj = new ADOPDOStatement($stmt,$this);
return $obj;
}
public function createSequence($seqname='adodbseq',$startID=1)
{
if($this->_driver instanceof ADODB_pdo && method_exists($this->_driver, 'createSequence')) {
return $this->_driver->createSequence($seqname, $startID);
}
return parent::CreateSequence($seqname, $startID);
}
function DropSequence($seqname='adodbseq')
{
if($this->_driver instanceof ADODB_pdo && method_exists($this->_driver, 'DropSequence')) {
return $this->_driver->DropSequence($seqname);
}
return parent::DropSequence($seqname);
}
function GenID($seqname='adodbseq',$startID=1)
{
if($this->_driver instanceof ADODB_pdo && method_exists($this->_driver, 'GenID')) {
return $this->_driver->GenID($seqname, $startID);
}
return parent::GenID($seqname, $startID);
}
/* returns queryID or false */
function _query($sql,$inputarr=false)
{
$ok = false;
if (is_array($sql)) {
$stmt = $sql[1];
} else {
$stmt = $this->_connectionID->prepare($sql);
}
if ($stmt) {
if ($this->_driver instanceof ADODB_pdo) {
$this->_driver->debug = $this->debug;
}
if ($inputarr) {
/*
* inputarr must be numeric
*/
$inputarr = array_values($inputarr);
$ok = $stmt->execute($inputarr);
}
else {
$ok = $stmt->execute();
}
}
$this->_errormsg = false;
$this->_errorno = false;
if ($ok) {
$this->_stmt = $stmt;
return $stmt;
}
if ($stmt) {
$arr = $stmt->errorinfo();
if ((integer)$arr[1]) {
$this->_errormsg = $arr[2];
$this->_errorno = $arr[1];
}
} else {
$this->_errormsg = false;
$this->_errorno = false;
}
return false;
}
// returns true or false
function _close()
{
$this->_stmt = false;
return true;
}
function _affectedrows()
{
return ($this->_stmt) ? $this->_stmt->rowCount() : 0;
}
protected function _insertID($table = '', $column = '')
{
return ($this->_connectionID) ? $this->_connectionID->lastInsertId() : 0;
}
/**
* Quotes a string to be sent to the database.
*
* If we have an active connection, delegates quoting to the underlying
* PDO object PDO::quote(). Otherwise, replace "'" by the value of
* $replaceQuote (same behavior as mysqli driver).
*
* @param string $s The string to quote
* @param bool $magic_quotes This param is not used since 5.21.0.
* It remains for backwards compatibility.
*
* @return string Quoted string
*/
function qStr($s, $magic_quotes = false)
{
if ($this->_connectionID) {
return $this->_connectionID->quote($s);
}
return "'" . str_replace("'", $this->replaceQuote, $s) . "'";
}
}
class ADODB_pdo_base extends ADODB_pdo {
var $sysDate = "'?'";
var $sysTimeStamp = "'?'";
function _init($parentDriver)
{
$parentDriver->_bindInputArray = true;
#$parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);
}
function ServerInfo()
{
return ADOConnection::ServerInfo();
}
function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
{
$ret = ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
return $ret;
}
function MetaTables($ttype=false,$showSchema=false,$mask=false)
{
return false;
}
function MetaColumns($table,$normalize=true)
{
return false;
}
}
class ADOPDOStatement {
var $databaseType = "pdo";
var $dataProvider = "pdo";
var $_stmt;
var $_connectionID;
function __construct($stmt,$connection)
{
$this->_stmt = $stmt;
$this->_connectionID = $connection;
}
function Execute($inputArr=false)
{
$savestmt = $this->_connectionID->_stmt;
$rs = $this->_connectionID->Execute(array(false,$this->_stmt),$inputArr);
$this->_connectionID->_stmt = $savestmt;
return $rs;
}
function InParameter(&$var,$name,$maxLen=4000,$type=false)
{
if ($type) {
$this->_stmt->bindParam($name,$var,$type,$maxLen);
}
else {
$this->_stmt->bindParam($name, $var);
}
}
function Affected_Rows()
{
return ($this->_stmt) ? $this->_stmt->rowCount() : 0;
}
function ErrorMsg()
{
if ($this->_stmt) {
$arr = $this->_stmt->errorInfo();
}
else {
$arr = $this->_connectionID->errorInfo();
}
if (is_array($arr)) {
if ((integer) $arr[0] && isset($arr[2])) {
return $arr[2];
}
else {
return '';
}
} else {
return '-1';
}
}
function NumCols()
{
return ($this->_stmt) ? $this->_stmt->columnCount() : 0;
}
function ErrorNo()
{
if ($this->_stmt) {
return $this->_stmt->errorCode();
}
else {
return $this->_connectionID->errorInfo();
}
}
}
/*--------------------------------------------------------------------------------------
Class Name: Recordset
--------------------------------------------------------------------------------------*/
class ADORecordSet_pdo extends ADORecordSet {
var $bind = false;
var $databaseType = "pdo";
var $dataProvider = "pdo";
function __construct($id,$mode=false)
{
if ($mode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
}
$this->adodbFetchMode = $mode;
switch($mode) {
case ADODB_FETCH_NUM: $mode = PDO::FETCH_NUM; break;
case ADODB_FETCH_ASSOC: $mode = PDO::FETCH_ASSOC; break;
case ADODB_FETCH_BOTH:
default: $mode = PDO::FETCH_BOTH; break;
}
$this->fetchMode = $mode;
$this->_queryID = $id;
parent::__construct($id);
}
function Init()
{
if ($this->_inited) {
return;
}
$this->_inited = true;
if ($this->_queryID) {
@$this->_initrs();
}
else {
$this->_numOfRows = 0;
$this->_numOfFields = 0;
}
if ($this->_numOfRows != 0 && $this->_currentRow == -1) {
$this->_currentRow = 0;
if ($this->EOF = ($this->_fetch() === false)) {
$this->_numOfRows = 0; // _numOfRows could be -1
}
} else {
$this->EOF = true;
}
}
function _initrs()
{
global $ADODB_COUNTRECS;
$this->_numOfRows = ($ADODB_COUNTRECS) ? @$this->_queryID->rowCount() : -1;
if (!$this->_numOfRows) {
$this->_numOfRows = -1;
}
$this->_numOfFields = $this->_queryID->columnCount();
}
// returns the field object
function FetchField($fieldOffset = -1)
{
$off=$fieldOffset+1; // offsets begin at 1
$o= new ADOFieldObject();
$arr = @$this->_queryID->getColumnMeta($fieldOffset);
if (!$arr) {
$o->name = 'bad getColumnMeta()';
$o->max_length = -1;
$o->type = 'VARCHAR';
$o->precision = 0;
# $false = false;
return $o;
}
//adodb_pr($arr);
$o->name = $arr['name'];
if (isset($arr['sqlsrv:decl_type']) && $arr['sqlsrv:decl_type'] <> "null")
{
/*
* If the database is SQL server, use the native built-ins
*/
$o->type = $arr['sqlsrv:decl_type'];
}
elseif (isset($arr['native_type']) && $arr['native_type'] <> "null")
{
$o->type = $arr['native_type'];
}
else
{
$o->type = adodb_pdo_type($arr['pdo_type']);
}
$o->max_length = $arr['len'];
$o->precision = $arr['precision'];
switch(ADODB_ASSOC_CASE) {
case ADODB_ASSOC_CASE_LOWER:
$o->name = strtolower($o->name);
break;
case ADODB_ASSOC_CASE_UPPER:
$o->name = strtoupper($o->name);
break;
}
return $o;
}
function _seek($row)
{
return false;
}
function _fetch()
{
if (!$this->_queryID) {
return false;
}
$this->fields = $this->_queryID->fetch($this->fetchMode);
return !empty($this->fields);
}
function _close()
{
$this->_queryID = false;
}
function Fields($colname)
{
if ($this->adodbFetchMode != ADODB_FETCH_NUM) {
return @$this->fields[$colname];
}
if (!$this->bind) {
$this->bind = array();
for ($i=0; $i < $this->_numOfFields; $i++) {
$o = $this->FetchField($i);
$this->bind[strtoupper($o->name)] = $i;
}
}
return $this->fields[$this->bind[strtoupper($colname)]];
}
}
class ADORecordSet_array_pdo extends ADORecordSet_array {}

View File

@ -0,0 +1,423 @@
<?php
/**
* PDO MySQL driver
*
* This file is part of ADOdb, a Database Abstraction Layer library for PHP.
*
* @package ADOdb
* @link https://adodb.org Project's web site and documentation
* @link https://github.com/ADOdb/ADOdb Source code and issue tracker
*
* The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
* and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
* any later version. This means you can use it in proprietary products.
* See the LICENSE.md file distributed with this source code for details.
* @license BSD-3-Clause
* @license LGPL-2.1-or-later
*
* @copyright 2000-2013 John Lim
* @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
*/
class ADODB_pdo_mysql extends ADODB_pdo {
var $metaTablesSQL = "SELECT
TABLE_NAME,
CASE WHEN TABLE_TYPE = 'VIEW' THEN 'V' ELSE 'T' END
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA=";
var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`";
var $sysDate = 'CURDATE()';
var $sysTimeStamp = 'NOW()';
var $hasGenID = true;
var $_genIDSQL = "UPDATE %s SET id=LAST_INSERT_ID(id+1);";
var $_genSeqSQL = "CREATE TABLE if NOT EXISTS %s (id int not null)";
var $_genSeqCountSQL = "SELECT count(*) FROM %s";
var $_genSeq2SQL = "INSERT INTO %s VALUES (%s)";
var $_dropSeqSQL = "drop table %s";
var $fmtTimeStamp = "'Y-m-d H:i:s'";
var $nameQuote = '`';
function _init($parentDriver)
{
$parentDriver->hasTransactions = false;
#$parentDriver->_bindInputArray = false;
$parentDriver->hasInsertID = true;
$parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
}
// dayFraction is a day in floating point
function OffsetDate($dayFraction, $date=false)
{
if (!$date) {
$date = $this->sysDate;
}
$fraction = $dayFraction * 24 * 3600;
return $date . ' + INTERVAL ' . $fraction . ' SECOND';
// return "from_unixtime(unix_timestamp($date)+$fraction)";
}
/**
* Get a list of indexes on the specified table.
*
* @param string $table The name of the table to get indexes for.
* @param bool $primary (Optional) Whether or not to include the primary key.
* @param bool $owner (Optional) Unused.
*
* @return array|bool An array of the indexes, or false if the query to get the indexes failed.
*/
function metaIndexes($table, $primary = false, $owner = false)
{
// save old fetch mode
global $ADODB_FETCH_MODE;
$false = false;
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($this->fetchMode !== FALSE) {
$savem = $this->setFetchMode(FALSE);
}
// get index details
$rs = $this->execute(sprintf('SHOW INDEXES FROM %s',$table));
// restore fetchmode
if (isset($savem)) {
$this->setFetchMode($savem);
}
$ADODB_FETCH_MODE = $save;
if (!is_object($rs)) {
return $false;
}
$indexes = array ();
// parse index data into array
while ($row = $rs->fetchRow()) {
if ($primary == FALSE AND $row[2] == 'PRIMARY') {
continue;
}
if (!isset($indexes[$row[2]])) {
$indexes[$row[2]] = array(
'unique' => ($row[1] == 0),
'columns' => array()
);
}
$indexes[$row[2]]['columns'][$row[3] - 1] = $row[4];
}
// sort columns by order in the index
foreach ( array_keys ($indexes) as $index )
{
ksort ($indexes[$index]['columns']);
}
return $indexes;
}
function Concat()
{
$s = '';
$arr = func_get_args();
// suggestion by andrew005#mnogo.ru
$s = implode(',', $arr);
if (strlen($s) > 0) {
return "CONCAT($s)";
}
return '';
}
function ServerInfo()
{
$arr['description'] = ADOConnection::GetOne('select version()');
$arr['version'] = ADOConnection::_findvers($arr['description']);
return $arr;
}
function MetaTables($ttype=false, $showSchema=false, $mask=false)
{
$save = $this->metaTablesSQL;
if ($showSchema && is_string($showSchema)) {
$this->metaTablesSQL .= $this->qstr($showSchema);
} else {
$this->metaTablesSQL .= 'schema()';
}
if ($mask) {
$mask = $this->qstr($mask);
$this->metaTablesSQL .= " like $mask";
}
$ret = ADOConnection::MetaTables($ttype, $showSchema);
$this->metaTablesSQL = $save;
return $ret;
}
/**
* @param bool $auto_commit
* @return void
*/
function SetAutoCommit($auto_commit)
{
$this->_connectionID->setAttribute(PDO::ATTR_AUTOCOMMIT, $auto_commit);
}
function SetTransactionMode($transaction_mode)
{
$this->_transmode = $transaction_mode;
if (empty($transaction_mode)) {
$this->Execute('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ');
return;
}
if (!stristr($transaction_mode, 'isolation')) {
$transaction_mode = 'ISOLATION LEVEL ' . $transaction_mode;
}
$this->Execute('SET SESSION TRANSACTION ' . $transaction_mode);
}
function MetaColumns($table, $normalize=true)
{
$this->_findschema($table, $schema);
if ($schema) {
$dbName = $this->database;
$this->SelectDB($schema);
}
global $ADODB_FETCH_MODE;
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($this->fetchMode !== false) {
$savem = $this->SetFetchMode(false);
}
$rs = $this->Execute(sprintf($this->metaColumnsSQL, $table));
if ($schema) {
$this->SelectDB($dbName);
}
if (isset($savem)) {
$this->SetFetchMode($savem);
}
$ADODB_FETCH_MODE = $save;
if (!is_object($rs)) {
$false = false;
return $false;
}
$retarr = array();
while (!$rs->EOF){
$fld = new ADOFieldObject();
$fld->name = $rs->fields[0];
$type = $rs->fields[1];
// split type into type(length):
$fld->scale = null;
if (preg_match('/^(.+)\((\d+),(\d+)/', $type, $query_array)) {
$fld->type = $query_array[1];
$fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
$fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
} elseif (preg_match('/^(.+)\((\d+)/', $type, $query_array)) {
$fld->type = $query_array[1];
$fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
} elseif (preg_match('/^(enum)\((.*)\)$/i', $type, $query_array)) {
$fld->type = $query_array[1];
$arr = explode(',', $query_array[2]);
$fld->enums = $arr;
$zlen = max(array_map('strlen', $arr)) - 2; // PHP >= 4.0.6
$fld->max_length = ($zlen > 0) ? $zlen : 1;
} else {
$fld->type = $type;
$fld->max_length = -1;
}
$fld->not_null = ($rs->fields[2] != 'YES');
$fld->primary_key = ($rs->fields[3] == 'PRI');
$fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
$fld->binary = (strpos($type, 'blob') !== false);
$fld->unsigned = (strpos($type, 'unsigned') !== false);
if (!$fld->binary) {
$d = $rs->fields[4];
if ($d != '' && $d != 'NULL') {
$fld->has_default = true;
$fld->default_value = $d;
} else {
$fld->has_default = false;
}
}
if ($save == ADODB_FETCH_NUM) {
$retarr[] = $fld;
} else {
$retarr[strtoupper($fld->name)] = $fld;
}
$rs->MoveNext();
}
$rs->Close();
return $retarr;
}
// returns true or false
function SelectDB($dbName)
{
$this->database = $dbName;
$this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions
$try = $this->Execute('use ' . $dbName);
return ($try !== false);
}
// parameters use PostgreSQL convention, not MySQL
function SelectLimit($sql, $nrows=-1, $offset=-1, $inputarr=false, $secs=0)
{
$nrows = (int) $nrows;
$offset = (int) $offset;
$offsetStr =($offset>=0) ? "$offset," : '';
// jason judge, see PHPLens Issue No: 9220
if ($nrows < 0) {
$nrows = '18446744073709551615';
}
if ($secs) {
$rs = $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows", $inputarr);
} else {
$rs = $this->Execute($sql . " LIMIT $offsetStr$nrows", $inputarr);
}
return $rs;
}
function SQLDate($fmt, $col=false)
{
if (!$col) {
$col = $this->sysTimeStamp;
}
$s = 'DATE_FORMAT(' . $col . ",'";
$concat = false;
$len = strlen($fmt);
for ($i=0; $i < $len; $i++) {
$ch = $fmt[$i];
switch($ch) {
default:
if ($ch == '\\') {
$i++;
$ch = substr($fmt, $i, 1);
}
// FALL THROUGH
case '-':
case '/':
$s .= $ch;
break;
case 'Y':
case 'y':
$s .= '%Y';
break;
case 'M':
$s .= '%b';
break;
case 'm':
$s .= '%m';
break;
case 'D':
case 'd':
$s .= '%d';
break;
case 'Q':
case 'q':
$s .= "'),Quarter($col)";
if ($len > $i+1) {
$s .= ",DATE_FORMAT($col,'";
} else {
$s .= ",('";
}
$concat = true;
break;
case 'H':
$s .= '%H';
break;
case 'h':
$s .= '%I';
break;
case 'i':
$s .= '%i';
break;
case 's':
$s .= '%s';
break;
case 'a':
case 'A':
$s .= '%p';
break;
case 'w':
$s .= '%w';
break;
case 'W':
$s .= '%U';
break;
case 'l':
$s .= '%W';
break;
}
}
$s .= "')";
if ($concat) {
$s = "CONCAT($s)";
}
return $s;
}
function GenID($seqname='adodbseq',$startID=1)
{
$getnext = sprintf($this->_genIDSQL,$seqname);
$holdtransOK = $this->_transOK; // save the current status
$rs = @$this->Execute($getnext);
if (!$rs) {
if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
$this->Execute(sprintf($this->_genSeqSQL,$seqname));
$cnt = $this->GetOne(sprintf($this->_genSeqCountSQL,$seqname));
if (!$cnt) $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
$rs = $this->Execute($getnext);
}
if ($rs) {
$this->genID = $this->_connectionID->lastInsertId($seqname);
$rs->Close();
} else {
$this->genID = 0;
}
return $this->genID;
}
function createSequence($seqname='adodbseq',$startID=1)
{
if (empty($this->_genSeqSQL)) {
return false;
}
$ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname,$startID));
if (!$ok) {
return false;
}
return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
}
}

View File

@ -0,0 +1,323 @@
<?php
/**
* PDO PostgreSQL (pgsql) driver
*
* This file is part of ADOdb, a Database Abstraction Layer library for PHP.
*
* @package ADOdb
* @link https://adodb.org Project's web site and documentation
* @link https://github.com/ADOdb/ADOdb Source code and issue tracker
*
* The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
* and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
* any later version. This means you can use it in proprietary products.
* See the LICENSE.md file distributed with this source code for details.
* @license BSD-3-Clause
* @license LGPL-2.1-or-later
*
* @copyright 2000-2013 John Lim
* @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
*/
class ADODB_pdo_pgsql extends ADODB_pdo {
var $metaDatabasesSQL = "select datname from pg_database where datname not in ('template0','template1') order by 1";
var $metaTablesSQL = "select tablename,'T' from pg_tables where tablename not like 'pg\_%'
and tablename not in ('sql_features', 'sql_implementation_info', 'sql_languages',
'sql_packages', 'sql_sizing', 'sql_sizing_profiles')
union
select viewname,'V' from pg_views where viewname not like 'pg\_%'";
//"select tablename from pg_tables where tablename not like 'pg_%' order by 1";
var $isoDates = true; // accepts dates in ISO format
var $sysDate = "CURRENT_DATE";
var $sysTimeStamp = "CURRENT_TIMESTAMP";
var $blobEncodeType = 'C';
var $metaColumnsSQL = "SELECT a.attname,t.typname,a.attlen,a.atttypmod,a.attnotnull,a.atthasdef,a.attnum
FROM pg_class c, pg_attribute a,pg_type t
WHERE relkind in ('r','v') AND (c.relname='%s' or c.relname = lower('%s')) and a.attname not like '....%%'
AND a.attnum > 0 AND a.atttypid = t.oid AND a.attrelid = c.oid ORDER BY a.attnum";
// used when schema defined
var $metaColumnsSQL1 = "SELECT a.attname, t.typname, a.attlen, a.atttypmod, a.attnotnull, a.atthasdef, a.attnum
FROM pg_class c, pg_attribute a, pg_type t, pg_namespace n
WHERE relkind in ('r','v') AND (c.relname='%s' or c.relname = lower('%s'))
and c.relnamespace=n.oid and n.nspname='%s'
and a.attname not like '....%%' AND a.attnum > 0
AND a.atttypid = t.oid AND a.attrelid = c.oid ORDER BY a.attnum";
// get primary key etc -- from Freek Dijkstra
var $metaKeySQL = "SELECT ic.relname AS index_name, a.attname AS column_name,i.indisunique AS unique_key, i.indisprimary AS primary_key
FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a WHERE bc.oid = i.indrelid AND ic.oid = i.indexrelid AND (i.indkey[0] = a.attnum OR i.indkey[1] = a.attnum OR i.indkey[2] = a.attnum OR i.indkey[3] = a.attnum OR i.indkey[4] = a.attnum OR i.indkey[5] = a.attnum OR i.indkey[6] = a.attnum OR i.indkey[7] = a.attnum) AND a.attrelid = bc.oid AND bc.relname = '%s'";
var $hasAffectedRows = true;
var $hasLimit = false; // set to true for pgsql 7 only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10
// below suggested by Freek Dijkstra
var $true = 't'; // string that represents TRUE for a database
var $false = 'f'; // string that represents FALSE for a database
var $fmtDate = "'Y-m-d'"; // used by DBDate() as the default date format used by the database
var $fmtTimeStamp = "'Y-m-d G:i:s'"; // used by DBTimeStamp as the default timestamp fmt.
var $hasMoveFirst = true;
var $hasGenID = true;
var $_genIDSQL = "SELECT NEXTVAL('%s')";
var $_genSeqSQL = "CREATE SEQUENCE %s START %s";
var $_dropSeqSQL = "DROP SEQUENCE %s";
var $metaDefaultsSQL = "SELECT d.adnum as num, d.adsrc as def from pg_attrdef d, pg_class c where d.adrelid=c.oid and c.relname='%s' order by d.adnum";
var $random = 'random()'; /// random function
var $concat_operator='||';
function _init($parentDriver)
{
$parentDriver->hasTransactions = false; ## <<< BUG IN PDO pgsql driver
$parentDriver->hasInsertID = true;
$parentDriver->_nestedSQL = true;
}
function ServerInfo()
{
$arr['description'] = ADOConnection::GetOne("select version()");
$arr['version'] = ADOConnection::_findvers($arr['description']);
return $arr;
}
function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
{
$nrows = (int) $nrows;
$offset = (int) $offset;
$offsetStr = ($offset >= 0) ? " OFFSET $offset" : '';
$limitStr = ($nrows >= 0) ? " LIMIT $nrows" : '';
if ($secs2cache)
$rs = $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
else
$rs = $this->Execute($sql."$limitStr$offsetStr",$inputarr);
return $rs;
}
function MetaTables($ttype=false,$showSchema=false,$mask=false)
{
$info = $this->ServerInfo();
if ($info['version'] >= 7.3) {
$this->metaTablesSQL = "
select tablename,'T' from pg_tables
where tablename not like 'pg\_%' and schemaname not in ( 'pg_catalog','information_schema')
union
select viewname,'V' from pg_views
where viewname not like 'pg\_%' and schemaname not in ( 'pg_catalog','information_schema')";
}
if ($mask) {
$save = $this->metaTablesSQL;
$mask = $this->qstr(strtolower($mask));
if ($info['version']>=7.3)
$this->metaTablesSQL = "
select tablename,'T' from pg_tables
where tablename like $mask and schemaname not in ( 'pg_catalog','information_schema')
union
select viewname,'V' from pg_views
where viewname like $mask and schemaname not in ( 'pg_catalog','information_schema')";
else
$this->metaTablesSQL = "
select tablename,'T' from pg_tables where tablename like $mask
union
select viewname,'V' from pg_views where viewname like $mask";
}
$ret = ADOConnection::MetaTables($ttype,$showSchema);
if ($mask) {
$this->metaTablesSQL = $save;
}
return $ret;
}
function MetaColumns($table,$normalize=true)
{
global $ADODB_FETCH_MODE;
$schema = false;
$this->_findschema($table,$schema);
if ($normalize) $table = strtolower($table);
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
if ($schema) $rs = $this->Execute(sprintf($this->metaColumnsSQL1,$table,$table,$schema));
else $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table,$table));
if (isset($savem)) $this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
if ($rs === false) {
$false = false;
return $false;
}
if (!empty($this->metaKeySQL)) {
// If we want the primary keys, we have to issue a separate query
// Of course, a modified version of the metaColumnsSQL query using a
// LEFT JOIN would have been much more elegant, but postgres does
// not support OUTER JOINS. So here is the clumsy way.
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$rskey = $this->Execute(sprintf($this->metaKeySQL,($table)));
// fetch all result in once for performance.
$keys = $rskey->GetArray();
if (isset($savem)) $this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
$rskey->Close();
unset($rskey);
}
$rsdefa = array();
if (!empty($this->metaDefaultsSQL)) {
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$sql = sprintf($this->metaDefaultsSQL, ($table));
$rsdef = $this->Execute($sql);
if (isset($savem)) $this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
if ($rsdef) {
while (!$rsdef->EOF) {
$num = $rsdef->fields['num'];
$s = $rsdef->fields['def'];
if (strpos($s,'::')===false && substr($s, 0, 1) == "'") { /* quoted strings hack... for now... fixme */
$s = substr($s, 1);
$s = substr($s, 0, strlen($s) - 1);
}
$rsdefa[$num] = $s;
$rsdef->MoveNext();
}
} else {
ADOConnection::outp( "==> SQL => " . $sql);
}
unset($rsdef);
}
$retarr = array();
while (!$rs->EOF) {
$fld = new ADOFieldObject();
$fld->name = $rs->fields[0];
$fld->type = $rs->fields[1];
$fld->max_length = $rs->fields[2];
if ($fld->max_length <= 0) $fld->max_length = $rs->fields[3]-4;
if ($fld->max_length <= 0) $fld->max_length = -1;
if ($fld->type == 'numeric') {
$fld->scale = $fld->max_length & 0xFFFF;
$fld->max_length >>= 16;
}
// dannym
// 5 hasdefault; 6 num-of-column
$fld->has_default = ($rs->fields[5] == 't');
if ($fld->has_default) {
$fld->default_value = $rsdefa[$rs->fields[6]];
}
//Freek
if ($rs->fields[4] == $this->true) {
$fld->not_null = true;
}
// Freek
if (is_array($keys)) {
foreach($keys as $key) {
if ($fld->name == $key['column_name'] AND $key['primary_key'] == $this->true)
$fld->primary_key = true;
if ($fld->name == $key['column_name'] AND $key['unique_key'] == $this->true)
$fld->unique = true; // What name is more compatible?
}
}
if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;
else $retarr[($normalize) ? strtoupper($fld->name) : $fld->name] = $fld;
$rs->MoveNext();
}
$rs->Close();
if (empty($retarr)) {
$false = false;
return $false;
} else return $retarr;
}
function BeginTrans()
{
if (!$this->hasTransactions) {
return false;
}
if ($this->transOff) {
return true;
}
$this->transCnt += 1;
return $this->_connectionID->beginTransaction();
}
function CommitTrans($ok = true)
{
if (!$this->hasTransactions) {
return false;
}
if ($this->transOff) {
return true;
}
if (!$ok) {
return $this->RollbackTrans();
}
if ($this->transCnt) {
$this->transCnt -= 1;
}
$this->_autocommit = true;
$ret = $this->_connectionID->commit();
return $ret;
}
function RollbackTrans()
{
if (!$this->hasTransactions) {
return false;
}
if ($this->transOff) {
return true;
}
if ($this->transCnt) {
$this->transCnt -= 1;
}
$this->_autocommit = true;
$ret = $this->_connectionID->rollback();
return $ret;
}
function SetTransactionMode( $transaction_mode )
{
$this->_transmode = $transaction_mode;
if (empty($transaction_mode)) {
$this->_connectionID->query('SET TRANSACTION ISOLATION LEVEL READ COMMITTED');
return;
}
if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
$this->_connectionID->query("SET TRANSACTION ".$transaction_mode);
}
/**
* Returns a driver-specific format for a bind parameter
*
* Unlike the native driver, we use :name parameters
* instead of offsets
*
* @param string $name
* @param string $type (ignored in driver)
*
* @return string
*/
public function param($name,$type='C') {
if (!$name) {
return '';
}
return sprintf(':%s', $name);
}
}

View File

@ -0,0 +1,25 @@
<?php
/**
* ADOdb PostgreSQL driver
*
* NOTE: Since ADOdb 3.31, this file is no longer used, and the "postgres"
* driver is remapped to the latest available postgres version. Maintaining
* multiple postgres drivers is no easy job, so hopefully this will ensure
* greater consistency and fewer bugs.
*
* This file is part of ADOdb, a Database Abstraction Layer library for PHP.
*
* @package ADOdb
* @link https://adodb.org Project's web site and documentation
* @link https://github.com/ADOdb/ADOdb Source code and issue tracker
*
* The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
* and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
* any later version. This means you can use it in proprietary products.
* See the LICENSE.md file distributed with this source code for details.
* @license BSD-3-Clause
* @license LGPL-2.1-or-later
*
* @copyright 2000-2013 John Lim
* @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
*/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,352 @@
<?php
/**
* ADOdb PostgreSQL 7 driver
*
* This file is part of ADOdb, a Database Abstraction Layer library for PHP.
*
* @package ADOdb
* @link https://adodb.org Project's web site and documentation
* @link https://github.com/ADOdb/ADOdb Source code and issue tracker
*
* The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
* and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
* any later version. This means you can use it in proprietary products.
* See the LICENSE.md file distributed with this source code for details.
* @license BSD-3-Clause
* @license LGPL-2.1-or-later
*
* @copyright 2000-2013 John Lim
* @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
*/
// security - hide paths
if (!defined('ADODB_DIR')) die();
include_once(ADODB_DIR."/drivers/adodb-postgres64.inc.php");
class ADODB_postgres7 extends ADODB_postgres64 {
var $databaseType = 'postgres7';
var $hasLimit = true; // set to true for pgsql 6.5+ only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10
var $ansiOuter = true;
var $charSet = true; //set to true for Postgres 7 and above - PG client supports encodings
// Richard 3/18/2012 - Modified SQL to return SERIAL type correctly AS old driver no longer return SERIAL as data type.
var $metaColumnsSQL = "
SELECT
a.attname,
CASE
WHEN x.sequence_name != ''
THEN 'SERIAL'
ELSE t.typname
END AS typname,
a.attlen, a.atttypmod, a.attnotnull, a.atthasdef, a.attnum
FROM
pg_class c,
pg_attribute a
JOIN pg_type t ON a.atttypid = t.oid
LEFT JOIN (
SELECT
c.relname as sequence_name,
c1.relname as related_table,
a.attname as related_column
FROM pg_class c
JOIN pg_depend d ON d.objid = c.oid
LEFT JOIN pg_class c1 ON d.refobjid = c1.oid
LEFT JOIN pg_attribute a ON (d.refobjid, d.refobjsubid) = (a.attrelid, a.attnum)
WHERE c.relkind = 'S' AND c1.relname = '%s'
) x ON x.related_column= a.attname
WHERE
c.relkind in ('r','v')
AND (c.relname='%s' or c.relname = lower('%s'))
AND a.attname not like '....%%'
AND a.attnum > 0
AND a.attrelid = c.oid
ORDER BY
a.attnum";
// used when schema defined
var $metaColumnsSQL1 = "
SELECT
a.attname,
CASE
WHEN x.sequence_name != ''
THEN 'SERIAL'
ELSE t.typname
END AS typname,
a.attlen, a.atttypmod, a.attnotnull, a.atthasdef, a.attnum
FROM
pg_class c,
pg_namespace n,
pg_attribute a
JOIN pg_type t ON a.atttypid = t.oid
LEFT JOIN (
SELECT
c.relname as sequence_name,
c1.relname as related_table,
a.attname as related_column
FROM pg_class c
JOIN pg_depend d ON d.objid = c.oid
LEFT JOIN pg_class c1 ON d.refobjid = c1.oid
LEFT JOIN pg_attribute a ON (d.refobjid, d.refobjsubid) = (a.attrelid, a.attnum)
WHERE c.relkind = 'S' AND c1.relname = '%s'
) x ON x.related_column= a.attname
WHERE
c.relkind in ('r','v')
AND (c.relname='%s' or c.relname = lower('%s'))
AND c.relnamespace=n.oid and n.nspname='%s'
AND a.attname not like '....%%'
AND a.attnum > 0
AND a.atttypid = t.oid
AND a.attrelid = c.oid
ORDER BY a.attnum";
function __construct()
{
parent::__construct();
if (ADODB_ASSOC_CASE !== ADODB_ASSOC_CASE_NATIVE) {
$this->rsPrefix .= 'assoc_';
}
$this->_bindInputArray = true;
}
// the following should be compat with postgresql 7.2,
// which makes obsolete the LIMIT limit,offset syntax
function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
{
$nrows = (int) $nrows;
$offset = (int) $offset;
$offsetStr = ($offset >= 0) ? " OFFSET ".((integer)$offset) : '';
$limitStr = ($nrows >= 0) ? " LIMIT ".((integer)$nrows) : '';
if ($secs2cache)
$rs = $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
else
$rs = $this->Execute($sql."$limitStr$offsetStr",$inputarr);
return $rs;
}
/*
function Prepare($sql)
{
$info = $this->ServerInfo();
if ($info['version']>=7.3) {
return array($sql,false);
}
return $sql;
}
*/
/**
* Generate the SQL to retrieve MetaColumns data
* @param string $table Table name
* @param string $schema Schema name (can be blank)
* @return string SQL statement to execute
*/
protected function _generateMetaColumnsSQL($table, $schema)
{
if ($schema) {
return sprintf($this->metaColumnsSQL1, $table, $table, $table, $schema);
}
else {
return sprintf($this->metaColumnsSQL, $table, $table, $schema);
}
}
public function metaForeignKeys($table, $owner = '', $upper = false, $associative = false)
{
# Regex isolates the 2 terms between parenthesis using subexpressions
$regex = '^.*\((.*)\).*\((.*)\).*$';
$sql="
SELECT
lookup_table,
regexp_replace(consrc, '$regex', '\\2') AS lookup_field,
dep_table,
regexp_replace(consrc, '$regex', '\\1') AS dep_field
FROM (
SELECT
pg_get_constraintdef(c.oid) AS consrc,
t.relname AS dep_table,
ft.relname AS lookup_table
FROM pg_constraint c
JOIN pg_class t ON (t.oid = c.conrelid)
JOIN pg_class ft ON (ft.oid = c.confrelid)
JOIN pg_namespace nft ON (nft.oid = ft.relnamespace)
LEFT JOIN pg_description ds ON (ds.objoid = c.oid)
JOIN pg_namespace n ON (n.oid = t.relnamespace)
WHERE c.contype = 'f'::\"char\"
ORDER BY t.relname, n.nspname, c.conname, c.oid
) constraints
WHERE
dep_table='".strtolower($table)."'
ORDER BY
lookup_table,
dep_table,
dep_field";
$rs = $this->Execute($sql);
if (!$rs || $rs->EOF) return false;
$a = array();
while (!$rs->EOF) {
$lookup_table = $rs->fields('lookup_table');
$fields = $rs->fields('dep_field') . '=' . $rs->fields('lookup_field');
if ($upper) {
$lookup_table = strtoupper($lookup_table);
$fields = strtoupper($fields);
}
$a[$lookup_table][] = str_replace('"','', $fields);
$rs->MoveNext();
}
return $a;
}
function _query($sql,$inputarr=false)
{
if (! $this->_bindInputArray) {
// We don't have native support for parameterized queries, so let's emulate it at the parent
return ADODB_postgres64::_query($sql, $inputarr);
}
$this->_pnum = 0;
$this->_errorMsg = false;
// -- added Cristiano da Cunha Duarte
if ($inputarr) {
$sqlarr = explode('?',trim($sql));
$sql = '';
$i = 1;
$last = sizeof($sqlarr)-1;
foreach($sqlarr as $v) {
if ($last < $i) $sql .= $v;
else $sql .= $v.' $'.$i;
$i++;
}
$rez = pg_query_params($this->_connectionID,$sql, $inputarr);
} else {
$rez = pg_query($this->_connectionID,$sql);
}
// check if no data returned, then no need to create real recordset
if ($rez && pg_num_fields($rez) <= 0) {
if ($this->_resultid !== false) {
pg_free_result($this->_resultid);
}
$this->_resultid = $rez;
return true;
}
return $rez;
}
/**
* Retrieve the client connection's current character set.
* If no charsets were compiled into the server, the function will always
* return 'SQL_ASCII'.
* @see https://www.php.net/manual/en/function.pg-client-encoding.php
*
* @return string|false The character set, or false if it can't be determined.
*/
function getCharSet()
{
if (!$this->_connectionID) {
return false;
}
$this->charSet = pg_client_encoding($this->_connectionID);
return $this->charSet ?: false;
}
/**
* Sets the client-side character set (encoding).
*
* Allows managing client encoding - very important if the database and
* the output target (i.e. HTML) don't match; for instance, you may have a
* UNICODE database and server your pages as WIN1251, etc.
*
* Supported on PostgreSQL 7.0 and above. Available charsets depend on
* PostgreSQL version and the distribution's compile flags.
*
* @param string $charset The character set to switch to.
*
* @return bool True if the character set was changed successfully, false otherwise.
*/
function setCharSet($charset)
{
if ($this->charSet !== $charset) {
if (!$this->_connectionID || pg_set_client_encoding($this->_connectionID, $charset) != 0) {
return false;
}
$this->getCharSet();
}
return true;
}
}
/*--------------------------------------------------------------------------------------
Class Name: Recordset
--------------------------------------------------------------------------------------*/
class ADORecordSet_postgres7 extends ADORecordSet_postgres64{
var $databaseType = "postgres7";
// 10% speedup to move MoveNext to child class
function MoveNext()
{
if (!$this->EOF) {
$this->_currentRow++;
if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) {
$this->_prepfields();
if ($this->fields !== false) {
return true;
}
}
$this->fields = false;
$this->EOF = true;
}
return false;
}
}
class ADORecordSet_assoc_postgres7 extends ADORecordSet_postgres64{
var $databaseType = "postgres7";
function _fetch()
{
if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0) {
return false;
}
$this->_prepfields();
if ($this->fields !== false) {
$this->_updatefields();
return true;
}
return false;
}
function MoveNext()
{
if (!$this->EOF) {
$this->_currentRow++;
if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) {
$this->_prepfields();
if ($this->fields !== false) {
$this->_updatefields();
return true;
}
}
$this->fields = false;
$this->EOF = true;
}
return false;
}
}

View File

@ -0,0 +1,64 @@
<?php
/**
* ADOdb PostgreSQL 8 driver
*
* This file is part of ADOdb, a Database Abstraction Layer library for PHP.
*
* @package ADOdb
* @link https://adodb.org Project's web site and documentation
* @link https://github.com/ADOdb/ADOdb Source code and issue tracker
*
* The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
* and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
* any later version. This means you can use it in proprietary products.
* See the LICENSE.md file distributed with this source code for details.
* @license BSD-3-Clause
* @license LGPL-2.1-or-later
*
* @copyright 2000-2013 John Lim
* @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
*/
// security - hide paths
if (!defined('ADODB_DIR')) die();
include_once(ADODB_DIR."/drivers/adodb-postgres7.inc.php");
class ADODB_postgres8 extends ADODB_postgres7
{
var $databaseType = 'postgres8';
// From PostgreSQL 8.0 onwards, the adsrc column used in earlier versions to
// retrieve the default value is obsolete and should not be used (see #562).
var $metaDefaultsSQL = "SELECT d.adnum as num, pg_get_expr(d.adbin, d.adrelid) as def
FROM pg_attrdef d, pg_class c
WHERE d.adrelid=c.oid AND c.relname='%s'
ORDER BY d.adnum";
/**
* Retrieve last inserted ID
* Don't use OIDs, since as per {@link http://php.net/function.pg-last-oid php manual }
* they won't be there in Postgres 8.1
* (and they're not what the application wants back, anyway).
* @param string $table
* @param string $column
* @return int last inserted ID for given table/column, or the most recently
* returned one if $table or $column are empty
*/
protected function _insertID($table = '', $column = '')
{
return empty($table) || empty($column)
? $this->GetOne("SELECT lastval()")
: $this->GetOne("SELECT currval(pg_get_serial_sequence('$table', '$column'))");
}
}
class ADORecordSet_postgres8 extends ADORecordSet_postgres7
{
var $databaseType = "postgres8";
}
class ADORecordSet_assoc_postgres8 extends ADORecordSet_assoc_postgres7
{
var $databaseType = "postgres8";
}

View File

@ -0,0 +1,40 @@
<?php
/**
* ADOdb PostgreSQL 9+ driver
*
* This file is part of ADOdb, a Database Abstraction Layer library for PHP.
*
* @package ADOdb
* @link https://adodb.org Project's web site and documentation
* @link https://github.com/ADOdb/ADOdb Source code and issue tracker
*
* The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
* and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
* any later version. This means you can use it in proprietary products.
* See the LICENSE.md file distributed with this source code for details.
* @license BSD-3-Clause
* @license LGPL-2.1-or-later
*
* @copyright 2000-2013 John Lim
* @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
*/
// security - hide paths
if (!defined('ADODB_DIR')) die();
include_once(ADODB_DIR."/drivers/adodb-postgres8.inc.php");
class ADODB_postgres9 extends ADODB_postgres8
{
var $databaseType = 'postgres9';
}
class ADORecordSet_postgres9 extends ADORecordSet_postgres8
{
var $databaseType = "postgres9";
}
class ADORecordSet_assoc_postgres9 extends ADORecordSet_assoc_postgres8
{
var $databaseType = "postgres9";
}