From 7cfc8eaa72ebb3169c005648555718a352e3c1b1 Mon Sep 17 00:00:00 2001 From: Prasad <prasad@vtiger.com> Date: Sun, 12 Sep 2021 23:53:50 +0530 Subject: [PATCH] Updated adodb for PHP 8 support --- libraries/adodb/LICENSE.md | 11 +- libraries/adodb/README.md | 53 +- libraries/adodb/adodb-active-record.inc.php | 212 +- libraries/adodb/adodb-active-recordx.inc.php | 90 +- libraries/adodb/adodb-csvlib.inc.php | 48 +- libraries/adodb/adodb-datadict.inc.php | 349 +-- libraries/adodb/adodb-error.inc.php | 42 +- libraries/adodb/adodb-errorhandler.inc.php | 25 +- libraries/adodb/adodb-errorpear.inc.php | 27 +- libraries/adodb/adodb-exceptions.inc.php | 39 +- libraries/adodb/adodb-iterator.inc.php | 26 - libraries/adodb/adodb-lib.inc.php | 871 ++++---- libraries/adodb/adodb-loadbalancer.inc.php | 773 +++++++ libraries/adodb/adodb-memcache.lib.inc.php | 94 +- libraries/adodb/adodb-pager.inc.php | 44 +- libraries/adodb/adodb-pear.inc.php | 31 +- libraries/adodb/adodb-perf.inc.php | 78 +- libraries/adodb/adodb-php4.inc.php | 16 - libraries/adodb/adodb-time.inc.php | 244 ++- libraries/adodb/adodb-xmlschema.inc.php | 71 +- libraries/adodb/adodb-xmlschema03.inc.php | 259 +-- libraries/adodb/adodb.inc.php | 1867 +++++++++++------ libraries/adodb/composer.json | 10 +- libraries/adodb/contrib/toxmlrpc.inc.php | 181 -- libraries/adodb/cute_icons_for_site/adodb.gif | Bin 1091 -> 0 bytes .../adodb/cute_icons_for_site/adodb2.gif | Bin 1458 -> 0 bytes .../adodb/datadict/datadict-access.inc.php | 29 +- libraries/adodb/datadict/datadict-db2.inc.php | 108 +- .../adodb/datadict/datadict-firebird.inc.php | 134 +- .../adodb/datadict/datadict-generic.inc.php | 29 +- .../adodb/datadict/datadict-ibase.inc.php | 29 +- .../adodb/datadict/datadict-informix.inc.php | 29 +- .../adodb/datadict/datadict-mssql.inc.php | 33 +- .../datadict/datadict-mssqlnative.inc.php | 180 +- .../adodb/datadict/datadict-mysql.inc.php | 34 +- .../adodb/datadict/datadict-oci8.inc.php | 97 +- .../adodb/datadict/datadict-postgres.inc.php | 285 ++- .../adodb/datadict/datadict-sapdb.inc.php | 32 +- .../adodb/datadict/datadict-sqlite.inc.php | 38 +- .../adodb/datadict/datadict-sybase.inc.php | 29 +- libraries/adodb/docs/README.md | 4 +- libraries/adodb/docs/changelog.md | 965 +++++++-- libraries/adodb/docs/changelog_v2.x.md | 10 +- libraries/adodb/docs/changelog_v3.x.md | 8 +- libraries/adodb/docs/changelog_v4+5.md | 8 +- libraries/adodb/docs/changelog_v4.x.md | 183 +- libraries/adodb/drivers/adodb-access.inc.php | 57 +- libraries/adodb/drivers/adodb-ado.inc.php | 46 +- libraries/adodb/drivers/adodb-ado5.inc.php | 46 +- .../adodb/drivers/adodb-ado_access.inc.php | 41 +- .../adodb/drivers/adodb-ado_mssql.inc.php | 111 +- libraries/adodb/drivers/adodb-ads.inc.php | 1526 +++++++------- .../adodb/drivers/adodb-borland_ibase.inc.php | 41 +- libraries/adodb/drivers/adodb-csv.inc.php | 63 +- libraries/adodb/drivers/adodb-db2.inc.php | 1796 +++++++++++++--- libraries/adodb/drivers/adodb-db2oci.inc.php | 86 +- libraries/adodb/drivers/adodb-db2ora.inc.php | 43 +- libraries/adodb/drivers/adodb-fbsql.inc.php | 40 +- .../adodb/drivers/adodb-firebird.inc.php | 889 +++++++- libraries/adodb/drivers/adodb-ibase.inc.php | 110 +- .../adodb/drivers/adodb-informix.inc.php | 41 +- .../adodb/drivers/adodb-informix72.inc.php | 45 +- libraries/adodb/drivers/adodb-ldap.inc.php | 44 +- libraries/adodb/drivers/adodb-mssql.inc.php | 483 ++--- libraries/adodb/drivers/adodb-mssql_n.inc.php | 123 +- .../adodb/drivers/adodb-mssqlnative.inc.php | 845 ++++---- libraries/adodb/drivers/adodb-mssqlpo.inc.php | 46 +- libraries/adodb/drivers/adodb-mysql.inc.php | 235 ++- libraries/adodb/drivers/adodb-mysqli.inc.php | 1252 +++++++---- libraries/adodb/drivers/adodb-mysqlpo.inc.php | 56 +- libraries/adodb/drivers/adodb-mysqlt.inc.php | 48 +- libraries/adodb/drivers/adodb-netezza.inc.php | 58 +- libraries/adodb/drivers/adodb-oci8.inc.php | 154 +- libraries/adodb/drivers/adodb-oci805.inc.php | 33 +- libraries/adodb/drivers/adodb-oci8po.inc.php | 152 +- .../adodb/drivers/adodb-oci8quercus.inc.php | 47 +- libraries/adodb/drivers/adodb-odbc.inc.php | 162 +- .../adodb/drivers/adodb-odbc_db2.inc.php | 119 +- .../adodb/drivers/adodb-odbc_mssql.inc.php | 128 +- .../drivers/adodb-odbc_mssql2012.inc.php | 37 + .../adodb/drivers/adodb-odbc_oracle.inc.php | 50 +- libraries/adodb/drivers/adodb-odbtp.inc.php | 66 +- .../adodb/drivers/adodb-odbtp_unicode.inc.php | 52 +- libraries/adodb/drivers/adodb-oracle.inc.php | 39 +- libraries/adodb/drivers/adodb-pdo.inc.php | 224 +- .../adodb/drivers/adodb-pdo_dblib.inc.php | 190 ++ .../adodb/drivers/adodb-pdo_firebird.inc.php | 452 ++++ .../adodb/drivers/adodb-pdo_mssql.inc.php | 31 +- .../adodb/drivers/adodb-pdo_mysql.inc.php | 147 +- libraries/adodb/drivers/adodb-pdo_oci.inc.php | 40 +- .../adodb/drivers/adodb-pdo_pgsql.inc.php | 104 +- .../adodb/drivers/adodb-pdo_sqlite.inc.php | 46 +- .../adodb/drivers/adodb-pdo_sqlsrv.inc.php | 138 +- .../adodb/drivers/adodb-postgres.inc.php | 37 +- .../adodb/drivers/adodb-postgres64.inc.php | 273 +-- .../adodb/drivers/adodb-postgres7.inc.php | 104 +- .../adodb/drivers/adodb-postgres8.inc.php | 38 +- .../adodb/drivers/adodb-postgres9.inc.php | 30 +- libraries/adodb/drivers/adodb-proxy.inc.php | 53 +- libraries/adodb/drivers/adodb-sapdb.inc.php | 109 +- .../adodb/drivers/adodb-sqlanywhere.inc.php | 83 +- libraries/adodb/drivers/adodb-sqlite.inc.php | 106 +- libraries/adodb/drivers/adodb-sqlite3.inc.php | 334 ++- .../adodb/drivers/adodb-sqlitepo.inc.php | 51 +- libraries/adodb/drivers/adodb-sybase.inc.php | 73 +- .../adodb/drivers/adodb-sybase_ase.inc.php | 44 +- libraries/adodb/drivers/adodb-text.inc.php | 341 +++ libraries/adodb/drivers/adodb-vfp.inc.php | 43 +- libraries/adodb/lang/adodb-ar.inc.php | 22 +- libraries/adodb/lang/adodb-bg.inc.php | 24 +- libraries/adodb/lang/adodb-ca.inc.php | 23 +- libraries/adodb/lang/adodb-cn.inc.php | 23 +- libraries/adodb/lang/adodb-cz.inc.php | 23 +- libraries/adodb/lang/adodb-da.inc.php | 22 +- libraries/adodb/lang/adodb-de.inc.php | 78 +- libraries/adodb/lang/adodb-en.inc.php | 19 + libraries/adodb/lang/adodb-eo.inc.php | 22 +- libraries/adodb/lang/adodb-es.inc.php | 22 +- libraries/adodb/lang/adodb-fa.inc.php | 22 +- libraries/adodb/lang/adodb-fr.inc.php | 19 + libraries/adodb/lang/adodb-hu.inc.php | 23 +- libraries/adodb/lang/adodb-id.inc.php | 55 + libraries/adodb/lang/adodb-it.inc.php | 23 +- libraries/adodb/lang/adodb-nl.inc.php | 22 +- libraries/adodb/lang/adodb-oc.inc.php | 51 + libraries/adodb/lang/adodb-pl.inc.php | 22 +- libraries/adodb/lang/adodb-pt-br.inc.php | 23 +- libraries/adodb/lang/adodb-ro.inc.php | 22 +- libraries/adodb/lang/adodb-ru.inc.php | 22 +- libraries/adodb/lang/adodb-sv.inc.php | 22 +- libraries/adodb/lang/adodb-th.inc.php | 22 +- libraries/adodb/lang/adodb-uk.inc.php | 22 +- libraries/adodb/pear/Auth/Container/ADOdb.php | 58 +- libraries/adodb/pear/auth_adodb_example.php | 23 +- libraries/adodb/perf/perf-db2.inc.php | 33 +- libraries/adodb/perf/perf-informix.inc.php | 35 +- libraries/adodb/perf/perf-mssql.inc.php | 34 +- libraries/adodb/perf/perf-mssqlnative.inc.php | 34 +- libraries/adodb/perf/perf-mysql.inc.php | 45 +- libraries/adodb/perf/perf-oci8.inc.php | 33 +- libraries/adodb/perf/perf-postgres.inc.php | 36 +- libraries/adodb/phpdoc | 20 + libraries/adodb/pivottable.inc.php | 27 +- libraries/adodb/rsfilter.inc.php | 25 +- libraries/adodb/server.php | 61 +- .../adodb/session/adodb-compress-bzip2.php | 46 +- .../adodb/session/adodb-compress-gzip.php | 38 +- .../adodb/session/adodb-cryptsession.php | 39 +- .../adodb/session/adodb-cryptsession2.php | 39 +- .../adodb/session/adodb-encrypt-mcrypt.php | 32 +- libraries/adodb/session/adodb-encrypt-md5.php | 31 +- .../adodb/session/adodb-encrypt-secret.php | 39 +- .../adodb/session/adodb-encrypt-sha1.php | 24 +- libraries/adodb/session/adodb-sess.txt | 6 +- .../adodb/session/adodb-session-clob.php | 39 +- .../adodb/session/adodb-session-clob2.php | 40 +- libraries/adodb/session/adodb-session.php | 49 +- libraries/adodb/session/adodb-session2.php | 142 +- libraries/adodb/session/crypt.inc.php | 27 +- .../adodb/session/old/adodb-cryptsession.php | 44 +- .../adodb/session/old/adodb-session-clob.php | 41 +- libraries/adodb/session/old/adodb-session.php | 44 +- libraries/adodb/session/old/crypt.inc.php | 26 +- libraries/adodb/session/session_schema.xml | 2 +- libraries/adodb/session/session_schema2.xml | 2 +- libraries/adodb/toexport.inc.php | 28 +- libraries/adodb/tohtml.inc.php | 43 +- libraries/adodb/xmlschema03.dtd | 36 +- 168 files changed, 14692 insertions(+), 7303 deletions(-) delete mode 100644 libraries/adodb/adodb-iterator.inc.php create mode 100644 libraries/adodb/adodb-loadbalancer.inc.php delete mode 100644 libraries/adodb/adodb-php4.inc.php delete mode 100644 libraries/adodb/contrib/toxmlrpc.inc.php delete mode 100644 libraries/adodb/cute_icons_for_site/adodb.gif delete mode 100644 libraries/adodb/cute_icons_for_site/adodb2.gif create mode 100644 libraries/adodb/drivers/adodb-odbc_mssql2012.inc.php create mode 100644 libraries/adodb/drivers/adodb-pdo_dblib.inc.php create mode 100644 libraries/adodb/drivers/adodb-pdo_firebird.inc.php create mode 100644 libraries/adodb/drivers/adodb-text.inc.php create mode 100644 libraries/adodb/lang/adodb-id.inc.php create mode 100644 libraries/adodb/lang/adodb-oc.inc.php create mode 100644 libraries/adodb/phpdoc diff --git a/libraries/adodb/LICENSE.md b/libraries/adodb/LICENSE.md index b8191587b..d00e2b1f2 100644 --- a/libraries/adodb/LICENSE.md +++ b/libraries/adodb/LICENSE.md @@ -1,19 +1,22 @@ ADOdb License ============= -ADOdb is dual licensed under BSD and LGPL. +The ADOdb Library is dual-licensed, released under both the +[BSD 3-clause](#bsd-3-clause-license) and the +[GNU Lesser General Public License (LGPL) v2.1](#gnu-lesser-general-public-license) +or, at your option, any later version. In plain English, you do not need to distribute your application in source code form, nor do you need to distribute ADOdb source code, provided you follow the rest of terms of the BSD license. -For more info about ADOdb, visit http://adodb.sourceforge.net/ +For more information about ADOdb, visit https://adodb.org/ BSD 3-Clause License -------------------- -(c) 2000-2013 John Lim (jlim@natsoft.com) -(c) 2014 Damien Regad, Mark Newnham and the ADOdb community +(c) 2000-2013 John Lim (jlim@natsoft.com) +(c) 2014 Damien Regad, Mark Newnham and the ADOdb community All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/libraries/adodb/README.md b/libraries/adodb/README.md index 958cca56f..e432b2fb0 100644 --- a/libraries/adodb/README.md +++ b/libraries/adodb/README.md @@ -1,28 +1,22 @@ -ADOdb Library for PHP5 +ADOdb Library for PHP ====================== [](https://gitter.im/adodb/adodb?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](https://sourceforge.net/projects/adodb/files/latest/download) (c) 2000-2013 John Lim (jlim@natsoft.com) -(c) 2014 Damien Regad, Mark Newnham and the ADOdb community - -Released under both [BSD 3-Clause](https://github.com/ADOdb/ADOdb/blob/master/LICENSE.md#bsd-3-clause-license) -and [GNU Lesser GPL library 2.1](https://github.com/ADOdb/ADOdb/blob/master/LICENSE.md#gnu-lesser-general-public-license) -licenses. -This means you can use it in proprietary products; +(c) 2014 Damien Regad, Mark Newnham and the + [ADOdb community](https://github.com/ADOdb/ADOdb/graphs/contributors) + +The ADOdb Library is dual-licensed, released under both the +[BSD 3-Clause](https://github.com/ADOdb/ADOdb/blob/master/LICENSE.md#bsd-3-clause-license) +and the +[GNU Lesser General Public Licence (LGPL) v2.1](https://github.com/ADOdb/ADOdb/blob/master/LICENSE.md#gnu-lesser-general-public-license) +or, at your option, any later version. +This means you can use it in proprietary products; see [License](https://github.com/ADOdb/ADOdb/blob/master/LICENSE.md) for details. -Home page: http://adodb.org/ - -> **WARNING: known issue with Associative Fetch Mode in ADOdb v5.19 --- PLEASE UPGRADE TO v5.20 !** -> When fetching data in Associative mode (i.e. when `$ADODB_FETCH_MODE` is -> set to *ADODB_FETCH_ASSOC*), recordsets do not return any data (empty strings) -> when using some database drivers. The problem has been reported on MSSQL, -> Interbase and Foxpro, but possibly affects other drivers as well; all drivers -> derived from the above are also impacted. -> For further details, please refer to [Issue #20](https://github.com/ADOdb/ADOdb/issues/20). +Home page: https://adodb.org/ Introduction @@ -33,8 +27,8 @@ need for a database class library to hide the differences between the different databases (encapsulate the differences) so we can easily switch databases. -The library currently supports MySQL, Interbase, Sybase, PostgreSQL, Oracle, -Microsoft SQL server, Foxpro ODBC, Access ODBC, Informix, DB2, +The library currently supports MySQL, Firebird & Interbase, PostgreSQL, SQLite3, Oracle, +Microsoft SQL Server, Foxpro ODBC, Access ODBC, Informix, DB2, Sybase, Sybase SQL Anywhere, generic ODBC and Microsoft's ADO. We hope more people will contribute drivers to support other databases. @@ -54,12 +48,12 @@ You can debug using: <?php include('adodb/adodb.inc.php'); -$db = ADONewConnection($driver); # eg. 'mysql' or 'oci8' +$db = adoNewConnection($driver); # eg. 'mysqli' or 'oci8' $db->debug = true; -$db->Connect($server, $user, $password, $database); -$rs = $db->Execute('select * from some_small_table'); +$db->connect($server, $user, $password, $database); +$rs = $db->execute('select * from some_small_table'); print "<pre>"; -print_r($rs->GetRows()); +print_r($rs->getRows()); print "</pre>"; ``` @@ -67,14 +61,14 @@ print "</pre>"; Documentation and Examples ========================== -Refer to the [ADOdb website](http://adodb.org/) for library documentation and examples. The documentation can also be [downloaded for offline viewing](https://sourceforge.net/projects/adodb/files/Documentation/). +Refer to the [ADOdb website](https://adodb.org/) for library documentation and examples. The documentation can also be [downloaded for offline viewing](https://sourceforge.net/projects/adodb/files/Documentation/). -- [Main documentation](http://adodb.org/dokuwiki/doku.php?id=v5:userguide:userguide_index): Query, update and insert records using a portable API. -- [Data dictionary](http://adodb.org/dokuwiki/doku.php?id=v5:dictionary:dictionary_index) describes how to create database tables and indexes in a portable manner. -- [Database performance monitoring](http://adodb.org/dokuwiki/doku.php?id=v5:performance:performance_index) allows you to perform health checks, tune and monitor your database. -- [Database-backed sessions](http://adodb.org/dokuwiki/doku.php?id=v5:session:session_index). +- [Main documentation](https://adodb.org/dokuwiki/doku.php?id=v5:userguide:userguide_index): Query, update and insert records using a portable API. +- [Data dictionary](https://adodb.org/dokuwiki/doku.php?id=v5:dictionary:dictionary_index) describes how to create database tables and indexes in a portable manner. +- [Database performance monitoring](https://adodb.org/dokuwiki/doku.php?id=v5:performance:performance_index) allows you to perform health checks, tune and monitor your database. +- [Database-backed sessions](https://adodb.org/dokuwiki/doku.php?id=v5:session:session_index). -There is also a [tutorial](http://adodb.org/dokuwiki/doku.php?id=v5:userguide:mysql_tutorial) that contrasts ADOdb code with PHP native MySQL code. +There is also a [tutorial](https://adodb.org/dokuwiki/doku.php?id=v5:userguide:mysql_tutorial) that contrasts ADOdb code with PHP native MySQL code. Files @@ -102,7 +96,6 @@ https://github.com/ADOdb/ADOdb/issues You may also find legacy issues in -- the old [ADOdb forums](http://phplens.com/lens/lensforum/topics.php?id=4) on phplens.com - the [SourceForge tickets section](http://sourceforge.net/p/adodb/_list/tickets) However, please note that they are not actively monitored and should diff --git a/libraries/adodb/adodb-active-record.inc.php b/libraries/adodb/adodb-active-record.inc.php index a7f0adf7f..8f3b00538 100644 --- a/libraries/adodb/adodb-active-record.inc.php +++ b/libraries/adodb/adodb-active-record.inc.php @@ -1,23 +1,25 @@ <?php -/* - -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Latest version is available at http://adodb.sourceforge.net - - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Active Record implementation. Superset of Zend Framework's. - - Version 0.92 - - See http://www-128.ibm.com/developerworks/java/library/j-cb03076/?ca=dgr-lnxw01ActiveRecord - for info on Ruby on Rails Active Record implementation -*/ - +/** + * Active Record implementation. Superset of Zend Framework's. + * + * 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 + */ + +include_once(ADODB_DIR.'/adodb-lib.inc.php'); global $_ADODB_ACTIVE_DBS; global $ADODB_ACTIVE_CACHESECS; // set to true to enable caching of metadata such as field info @@ -46,41 +48,37 @@ class ADODB_Active_Table { // $db = database connection // $index = name of index - can be associative, for an example see -// http://phplens.com/lens/lensforum/msgs.php?id=17790 +// PHPLens Issue No: 17790 // returns index into $_ADODB_ACTIVE_DBS function ADODB_SetDatabaseAdapter(&$db, $index=false) { global $_ADODB_ACTIVE_DBS; - foreach($_ADODB_ACTIVE_DBS as $k => $d) { - if (PHP_VERSION >= 5) { - if ($d->db === $db) { - return $k; - } - } else { - if ($d->db->_connectionID === $db->_connectionID && $db->database == $d->db->database) { - return $k; - } - } + foreach($_ADODB_ACTIVE_DBS as $k => $d) { + if($d->db === $db) { + return $k; } + } - $obj = new ADODB_Active_DB(); - $obj->db = $db; - $obj->tables = array(); + $obj = new ADODB_Active_DB(); + $obj->db = $db; + $obj->tables = array(); - if ($index == false) { - $index = sizeof($_ADODB_ACTIVE_DBS); - } + if ($index == false) { + $index = sizeof($_ADODB_ACTIVE_DBS); + } - $_ADODB_ACTIVE_DBS[$index] = $obj; + $_ADODB_ACTIVE_DBS[$index] = $obj; - return sizeof($_ADODB_ACTIVE_DBS)-1; + return sizeof($_ADODB_ACTIVE_DBS)-1; } class ADODB_Active_Record { static $_changeNames = true; // dynamically pluralize table names - static $_quoteNames = false; + + /** @var bool|string Allows override of global $ADODB_QUOTE_FIELDNAMES */ + public $_quoteNames; static $_foreignSuffix = '_id'; // var $_dbat; // associative index pointing to ADODB_Active_DB eg. $ADODB_Active_DBS[_dbat] @@ -120,7 +118,12 @@ class ADODB_Active_Record { // php5 constructor function __construct($table = false, $pkeyarr=false, $db=false) { - global $ADODB_ASSOC_CASE,$_ADODB_ACTIVE_DBS; + global $_ADODB_ACTIVE_DBS, $ADODB_QUOTE_FIELDNAMES; + + // Set the local override for field quoting, only if not defined yet + if (!isset($this->_quoteNames)) { + $this->_quoteNames = $ADODB_QUOTE_FIELDNAMES; + } if ($db == false && is_object($pkeyarr)) { $db = $pkeyarr; @@ -374,7 +377,7 @@ class ADODB_Active_Record { // update metadata function UpdateActiveTable($pkeys=false,$forceUpdate=false) { - global $ADODB_ASSOC_CASE,$_ADODB_ACTIVE_DBS , $ADODB_CACHE_DIR, $ADODB_ACTIVE_CACHESECS; + global $_ADODB_ACTIVE_DBS , $ADODB_CACHE_DIR, $ADODB_ACTIVE_CACHESECS; global $ADODB_ACTIVE_DEFVALS,$ADODB_FETCH_MODE; $activedb = $_ADODB_ACTIVE_DBS[$this->_dbat]; @@ -463,8 +466,8 @@ class ADODB_Active_Record { $attr = array(); $keys = array(); - switch($ADODB_ASSOC_CASE) { - case 0: + switch (ADODB_ASSOC_CASE) { + case ADODB_ASSOC_CASE_LOWER: foreach($cols as $name => $fldobj) { $name = strtolower($name); if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value)) { @@ -480,7 +483,7 @@ class ADODB_Active_Record { } break; - case 1: + case ADODB_ASSOC_CASE_UPPER: foreach($cols as $name => $fldobj) { $name = strtoupper($name); @@ -499,7 +502,6 @@ class ADODB_Active_Record { break; default: foreach($cols as $name => $fldobj) { - $name = ($fldobj->name); if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value)) { $this->$name = $fldobj->default_value; @@ -510,7 +512,7 @@ class ADODB_Active_Record { $attr[$name] = $fldobj; } foreach($pkeys as $k => $name) { - $keys[$name] = $cols[$name]->name; + $keys[$name] = $cols[strtoupper($name)]->name; } break; } @@ -522,7 +524,7 @@ class ADODB_Active_Record { $activetab->_created = time(); $s = serialize($activetab); if (!function_exists('adodb_write_file')) { - include(ADODB_DIR.'/adodb-csvlib.inc.php'); + include_once(ADODB_DIR.'/adodb-csvlib.inc.php'); } adodb_write_file($fname,$s); } @@ -700,9 +702,14 @@ class ADODB_Active_Record { $val = false; } - if (is_null($val) || $val === false) { + if (is_null($val) || $val === false) + { + $SQL = sprintf("SELECT MAX(%s) FROM %s", + $this->nameQuoter($db,$fieldname), + $this->nameQuoter($db,$this->_table) + ); // this might not work reliably in multi-user environment - return $db->GetOne("select max(".$fieldname.") from ".$this->_table); + return $db->GetOne($SQL); } return $val; } @@ -749,10 +756,11 @@ class ADODB_Active_Record { foreach($keys as $k) { $f = $table->flds[$k]; if ($f) { - $parr[] = $k.' = '.$this->doquote($db,$this->$k,$db->MetaType($f->type)); + $columnName = $this->nameQuoter($db,$k); + $parr[] = $columnName.' = '.$this->doquote($db,$this->$k,$db->MetaType($f->type)); } } - return implode(' and ', $parr); + return implode(' AND ', $parr); } @@ -774,7 +782,7 @@ class ADODB_Active_Record { function Load($where=null,$bindarr=false, $lock = false) { - global $ADODB_FETCH_MODE; + global $ADODB_FETCH_MODE; $db = $this->DB(); if (!$db) { @@ -788,7 +796,9 @@ class ADODB_Active_Record { $savem = $db->SetFetchMode(false); } - $qry = "select * from ".$this->_table; + $qry = sprintf("SELECT * FROM %s", + $this->nameQuoter($db,$this->_table) + ); if($where) { $qry .= ' WHERE '.$where; @@ -813,7 +823,7 @@ class ADODB_Active_Record { } # useful for multiple record inserts - # see http://phplens.com/lens/lensforum/msgs.php?id=17795 + # see PHPLens Issue No: 17795 function Reset() { $this->_where=null; @@ -862,7 +872,7 @@ class ADODB_Active_Record { $val = $this->$name; if(!is_array($val) || !is_null($val) || !array_key_exists($name, $table->keys)) { $valarr[] = $val; - $names[] = $this->_QName($name,$db); + $names[] = $this->nameQuoter($db,$name); $valstr[] = $db->Param($cnt); $cnt += 1; } @@ -871,12 +881,18 @@ class ADODB_Active_Record { if (empty($names)){ foreach($table->flds as $name=>$fld) { $valarr[] = null; - $names[] = $name; + $names[] = $this->nameQuoter($db,$name); $valstr[] = $db->Param($cnt); $cnt += 1; } } - $sql = 'INSERT INTO '.$this->_table."(".implode(',',$names).') VALUES ('.implode(',',$valstr).')'; + + $tableName = $this->nameQuoter($db,$this->_table); + $sql = sprintf('INSERT INTO %s (%s) VALUES (%s)', + $tableName, + implode(',',$names), + implode(',',$valstr) + ); $ok = $db->Execute($sql,$valarr); if ($ok) { @@ -907,7 +923,14 @@ class ADODB_Active_Record { $table = $this->TableInfo(); $where = $this->GenWhere($db,$table); - $sql = 'DELETE FROM '.$this->_table.' WHERE '.$where; + + $tableName = $this->nameQuoter($db,$this->_table); + + $sql = sprintf('DELETE FROM %s WHERE %s', + $tableName, + $where + ); + $ok = $db->Execute($sql); return $ok ? true : false; @@ -927,8 +950,6 @@ class ADODB_Active_Record { // returns 0 on error, 1 on update, 2 on insert function Replace() { - global $ADODB_ASSOC_CASE; - $db = $this->DB(); if (!$db) { return false; @@ -968,17 +989,32 @@ class ADODB_Active_Record { $pkey = array($pkey); } - if ($ADODB_ASSOC_CASE == 0) { - foreach($pkey as $k => $v) - $pkey[$k] = strtolower($v); - } - elseif ($ADODB_ASSOC_CASE == 1) { - foreach($pkey as $k => $v) { - $pkey[$k] = strtoupper($v); - } + switch (ADODB_ASSOC_CASE) { + case ADODB_ASSOC_CASE_LOWER: + foreach ($pkey as $k => $v) { + $pkey[$k] = strtolower($v); + } + break; + case ADODB_ASSOC_CASE_UPPER: + foreach ($pkey as $k => $v) { + $pkey[$k] = strtoupper($v); + } + break; } - $ok = $db->Replace($this->_table,$arr,$pkey); + $newArr = array(); + foreach($arr as $k=>$v) + $newArr[$this->nameQuoter($db,$k)] = $v; + $arr = $newArr; + + $newPkey = array(); + foreach($pkey as $k=>$v) + $newPkey[$k] = $this->nameQuoter($db,$v); + $pkey = $newPkey; + + $tableName = $this->nameQuoter($db,$this->_table); + + $ok = $db->Replace($tableName,$arr,$pkey); if ($ok) { $this->_saved = true; // 1= update 2=insert if ($ok == 2) { @@ -1050,7 +1086,7 @@ class ADODB_Active_Record { } $valarr[] = $val; - $pairs[] = $this->_QName($name,$db).'='.$db->Param($cnt); + $pairs[] = $this->nameQuoter($db,$name).'='.$db->Param($cnt); $cnt += 1; } @@ -1059,7 +1095,13 @@ class ADODB_Active_Record { return -1; } - $sql = 'UPDATE '.$this->_table." SET ".implode(",",$pairs)." WHERE ".$where; + $tableName = $this->nameQuoter($db,$this->_table); + + $sql = sprintf('UPDATE %s SET %s WHERE %s', + $tableName, + implode(',',$pairs), + $where); + $ok = $db->Execute($sql,$valarr); if ($ok) { $this->_original = $neworig; @@ -1077,6 +1119,31 @@ class ADODB_Active_Record { return array_keys($table->flds); } + /** + * Quotes the table, column and field names. + * + * This honours the internal {@see $_quoteNames} property, which overrides + * the global $ADODB_QUOTE_FIELDNAMES directive. + * + * @param ADOConnection $db The database connection + * @param string $name The table or column name to quote + * + * @return string The quoted name + */ + private function nameQuoter($db, $name) + { + global $ADODB_QUOTE_FIELDNAMES; + + $save = $ADODB_QUOTE_FIELDNAMES; + $ADODB_QUOTE_FIELDNAMES = $this->_quoteNames; + + $string = _adodb_quote_fieldname($db, $name); + + $ADODB_QUOTE_FIELDNAMES = $save; + + return $string; + } + }; function adodb_GetActiveRecordsClass(&$db, $class, $table,$whereOrderBy,$bindarr, $primkeyArr, @@ -1086,6 +1153,7 @@ global $_ADODB_ACTIVE_DBS; $save = $db->SetFetchMode(ADODB_FETCH_NUM); + $qry = "select * from ".$table; if (!empty($whereOrderBy)) { @@ -1124,7 +1192,7 @@ global $_ADODB_ACTIVE_DBS; // arrRef will be the structure that knows about our objects. // It is an associative array. // We will, however, return arr, preserving regular 0.. order so that - // obj[0] can be used by app developpers. + // obj[0] can be used by app developers. $arrRef = array(); $bTos = array(); // Will store belongTo's indices if any foreach($rows as $row) { diff --git a/libraries/adodb/adodb-active-recordx.inc.php b/libraries/adodb/adodb-active-recordx.inc.php index 7f553f1e0..5de5b1309 100644 --- a/libraries/adodb/adodb-active-recordx.inc.php +++ b/libraries/adodb/adodb-active-recordx.inc.php @@ -1,27 +1,27 @@ <?php -/* - -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Latest version is available at http://adodb.sourceforge.net - - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Active Record implementation. Superset of Zend Framework's. - - This is "Active Record eXtended" to support JOIN, WORK and LAZY mode by Chris Ravenscroft chris#voilaweb.com - - Version 0.9 - - See http://www-128.ibm.com/developerworks/java/library/j-cb03076/?ca=dgr-lnxw01ActiveRecord - for info on Ruby on Rails Active Record implementation -*/ - - - // CFR: Active Records Definitions +/** + * Active Record implementation. Superset of Zend Framework's. + * + * This is "Active Record eXtended" to support JOIN, WORK and LAZY mode + * + * 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 + */ + +// CFR: Active Records Definitions define('ADODB_JOIN_AR', 0x01); define('ADODB_WORK_AR', 0x02); define('ADODB_LAZY_AR', 0x03); @@ -66,25 +66,19 @@ function ADODB_SetDatabaseAdapter(&$db) { global $_ADODB_ACTIVE_DBS; - foreach($_ADODB_ACTIVE_DBS as $k => $d) { - if (PHP_VERSION >= 5) { - if ($d->db === $db) { - return $k; - } - } else { - if ($d->db->_connectionID === $db->_connectionID && $db->database == $d->db->database) { - return $k; - } - } + foreach($_ADODB_ACTIVE_DBS as $k => $d) { + if ($d->db === $db) { + return $k; } + } - $obj = new ADODB_Active_DB(); - $obj->db = $db; - $obj->tables = array(); + $obj = new ADODB_Active_DB(); + $obj->db = $db; + $obj->tables = array(); - $_ADODB_ACTIVE_DBS[] = $obj; + $_ADODB_ACTIVE_DBS[] = $obj; - return sizeof($_ADODB_ACTIVE_DBS)-1; + return sizeof($_ADODB_ACTIVE_DBS)-1; } @@ -137,7 +131,7 @@ class ADODB_Active_Record { // if $options['new'] is true, we forget all relations function __construct($table = false, $pkeyarr=false, $db=false, $options=array()) { - global $ADODB_ASSOC_CASE,$_ADODB_ACTIVE_DBS; + global $_ADODB_ACTIVE_DBS; if ($db == false && is_object($pkeyarr)) { $db = $pkeyarr; @@ -410,7 +404,7 @@ class ADODB_Active_Record { // update metadata function UpdateActiveTable($pkeys=false,$forceUpdate=false) { - global $ADODB_ASSOC_CASE,$_ADODB_ACTIVE_DBS , $ADODB_CACHE_DIR, $ADODB_ACTIVE_CACHESECS; + global $_ADODB_ACTIVE_DBS , $ADODB_CACHE_DIR, $ADODB_ACTIVE_CACHESECS; global $ADODB_ACTIVE_DEFVALS, $ADODB_FETCH_MODE; $activedb = $_ADODB_ACTIVE_DBS[$this->_dbat]; @@ -491,8 +485,8 @@ class ADODB_Active_Record { $attr = array(); $keys = array(); - switch($ADODB_ASSOC_CASE) { - case 0: + switch (ADODB_ASSOC_CASE) { + case ADODB_ASSOC_CASE_LOWER: foreach($cols as $name => $fldobj) { $name = strtolower($name); if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value)) { @@ -508,7 +502,7 @@ class ADODB_Active_Record { } break; - case 1: + case ADODB_ASSOC_CASE_UPPER: foreach($cols as $name => $fldobj) { $name = strtoupper($name); @@ -551,7 +545,7 @@ class ADODB_Active_Record { $activetab->_created = time(); $s = serialize($activetab); if (!function_exists('adodb_write_file')) { - include(ADODB_DIR.'/adodb-csvlib.inc.php'); + include_once(ADODB_DIR.'/adodb-csvlib.inc.php'); } adodb_write_file($fname,$s); } @@ -1060,8 +1054,6 @@ class ADODB_Active_Record { // returns 0 on error, 1 on update, 2 on insert function Replace() { - global $ADODB_ASSOC_CASE; - $db = $this->DB(); if (!$db) { return false; @@ -1097,7 +1089,7 @@ class ADODB_Active_Record { } - switch ($ADODB_ASSOC_CASE == 0) { + switch (ADODB_ASSOC_CASE) { case ADODB_ASSOC_CASE_LOWER: foreach($pkey as $k => $v) { $pkey[$k] = strtolower($v); @@ -1300,7 +1292,7 @@ function adodb_GetActiveRecordsClass(&$db, $class, $tableObj,$whereOrderBy,$bind if (!isset($_ADODB_ACTIVE_DBS)) { - include(ADODB_DIR.'/adodb-active-record.inc.php'); + include_once(ADODB_DIR.'/adodb-active-record.inc.php'); } if (!class_exists($class)) { $db->outp_throw("Unknown class $class in GetActiveRecordsClass()",'GetActiveRecordsClass'); @@ -1311,7 +1303,7 @@ function adodb_GetActiveRecordsClass(&$db, $class, $tableObj,$whereOrderBy,$bind // arrRef will be the structure that knows about our objects. // It is an associative array. // We will, however, return arr, preserving regular 0.. order so that - // obj[0] can be used by app developpers. + // obj[0] can be used by app developers. $arrRef = array(); $bTos = array(); // Will store belongTo's indices if any foreach($rows as $row) { diff --git a/libraries/adodb/adodb-csvlib.inc.php b/libraries/adodb/adodb-csvlib.inc.php index bfd8d9b87..c81254bfc 100644 --- a/libraries/adodb/adodb-csvlib.inc.php +++ b/libraries/adodb/adodb-csvlib.inc.php @@ -1,4 +1,26 @@ <?php +/** + * Library for CSV serialization. + * + * This is used by the csv/proxy driver and is the CacheExecute() + * serialization format. + * + * 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(); @@ -6,32 +28,12 @@ if (!defined('ADODB_DIR')) die(); global $ADODB_INCLUDED_CSV; $ADODB_INCLUDED_CSV = 1; -/* - - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. See License.txt. - Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Library for CSV serialization. This is used by the csv/proxy driver and is the - CacheExecute() serialization format. - - ==== NOTE ==== - Format documented at http://php.weblogs.com/ADODB_CSV - ============== -*/ - /** * convert a recordset into special format * * @param rs the recordset * - * @return the CSV formated data + * @return the CSV formatted data */ function _rs2serialize(&$rs,$conn=false,$sql='') { @@ -89,7 +91,7 @@ $ADODB_INCLUDED_CSV = 1; * @param err returns the error message * @param timeout dispose if recordset has been alive for $timeout secs * -* @return recordset, or false if error occured. If no +* @return recordset, or false if error occurred. If no * error occurred in sql INSERT/UPDATE/DELETE, * empty recordset is returned */ @@ -249,10 +251,8 @@ $ADODB_INCLUDED_CSV = 1; fclose($fp); @$arr = unserialize($text); - //var_dump($arr); if (!is_array($arr)) { $err = "Recordset had unexpected EOF (in serialized recordset)"; - if (get_magic_quotes_runtime()) $err .= ". Magic Quotes Runtime should be disabled!"; return $false; } $rs = new $rsclass(); diff --git a/libraries/adodb/adodb-datadict.inc.php b/libraries/adodb/adodb-datadict.inc.php index cc0d823a9..dbed95da7 100644 --- a/libraries/adodb/adodb-datadict.inc.php +++ b/libraries/adodb/adodb-datadict.inc.php @@ -1,32 +1,35 @@ <?php - /** - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4 for best viewing. - - DOCUMENTATION: - - See adodb/tests/test-datadict.php for docs and examples. -*/ - -/* - Test script for parser -*/ + * ADOdb Data Dictionary base class. + * + * 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(); -function Lens_ParseTest() +/** + * Test script for parser + */ +function lens_ParseTest() { $str = "`zcol ACOL` NUMBER(32,2) DEFAULT 'The \"cow\" (and Jim''s dog) jumps over the moon' PRIMARY, INTI INT AUTO DEFAULT 0, zcol2\"afs ds"; print "<p>$str</p>"; -$a= Lens_ParseArgs($str); +$a= lens_ParseArgs($str); print "<pre>"; print_r($a); print "</pre>"; @@ -53,7 +56,7 @@ if (!function_exists('ctype_alnum')) { @param tokenchars Include the following characters in tokens apart from A-Z and 0-9 @returns 2 dimensional array containing parsed tokens. */ -function Lens_ParseArgs($args,$endstmtchar=',',$tokenchars='_.-') +function lens_ParseArgs($args,$endstmtchar=',',$tokenchars='_.-') { $pos = 0; $intoken = false; @@ -164,6 +167,7 @@ function Lens_ParseArgs($args,$endstmtchar=',',$tokenchars='_.-') class ADODB_DataDict { + /** @var ADOConnection */ var $connection; var $debug = false; var $dropTable = 'DROP TABLE %s'; @@ -179,45 +183,60 @@ class ADODB_DataDict { var $serverInfo = array(); var $autoIncrement = false; var $dataProvider; - var $invalidResizeTypes4 = array('CLOB','BLOB','TEXT','DATE','TIME'); // for changetablesql + var $invalidResizeTypes4 = array('CLOB','BLOB','TEXT','DATE','TIME'); // for changeTableSQL var $blobSize = 100; /// any varchar/char field this size or greater is treated as a blob - /// in other words, we use a text area for editting. + /// in other words, we use a text area for editing. + /** @var string Uppercase driver name */ + var $upperName; + + /* + * Indicates whether a BLOB/CLOB field will allow a NOT NULL setting + * The type is whatever is matched to an X or X2 or B type. We must + * explicitly set the value in the driver to switch the behaviour on + */ + public $blobAllowsNotNull; + /* + * Indicates whether a BLOB/CLOB field will allow a DEFAULT set + * The type is whatever is matched to an X or X2 or B type. We must + * explicitly set the value in the driver to switch the behaviour on + */ + public $blobAllowsDefaultValue; - function GetCommentSQL($table,$col) + function getCommentSQL($table,$col) { return false; } - function SetCommentSQL($table,$col,$cmt) + function setCommentSQL($table,$col,$cmt) { return false; } - function MetaTables() + function metaTables() { - if (!$this->connection->IsConnected()) return array(); - return $this->connection->MetaTables(); + if (!$this->connection->isConnected()) return array(); + return $this->connection->metaTables(); } - function MetaColumns($tab, $upper=true, $schema=false) + function metaColumns($tab, $upper=true, $schema=false) { - if (!$this->connection->IsConnected()) return array(); - return $this->connection->MetaColumns($this->TableName($tab), $upper, $schema); + if (!$this->connection->isConnected()) return array(); + return $this->connection->metaColumns($this->tableName($tab), $upper, $schema); } - function MetaPrimaryKeys($tab,$owner=false,$intkey=false) + function metaPrimaryKeys($tab,$owner=false,$intkey=false) { - if (!$this->connection->IsConnected()) return array(); - return $this->connection->MetaPrimaryKeys($this->TableName($tab), $owner, $intkey); + if (!$this->connection->isConnected()) return array(); + return $this->connection->metaPrimaryKeys($this->tableName($tab), $owner, $intkey); } - function MetaIndexes($table, $primary = false, $owner = false) + function metaIndexes($table, $primary = false, $owner = false) { - if (!$this->connection->IsConnected()) return array(); - return $this->connection->MetaIndexes($this->TableName($table), $primary, $owner); + if (!$this->connection->isConnected()) return array(); + return $this->connection->metaIndexes($this->tableName($table), $primary, $owner); } - function MetaType($t,$len=-1,$fieldobj=false) + function metaType($t,$len=-1,$fieldobj=false) { static $typeMap = array( 'VARCHAR' => 'C', @@ -323,15 +342,15 @@ class ADODB_DataDict { "SQLBOOL" => 'L' ); - if (!$this->connection->IsConnected()) { + if (!$this->connection->isConnected()) { $t = strtoupper($t); if (isset($typeMap[$t])) return $typeMap[$t]; - return 'N'; + return ADODB_DEFAULT_METATYPE; } - return $this->connection->MetaType($t,$len,$fieldobj); + return $this->connection->metaType($t,$len,$fieldobj); } - function NameQuote($name = NULL,$allowBrackets=false) + function nameQuote($name = NULL,$allowBrackets=false) { if (!is_string($name)) { return FALSE; @@ -360,16 +379,16 @@ class ADODB_DataDict { return $name; } - function TableName($name) + function tableName($name) { if ( $this->schema ) { - return $this->NameQuote($this->schema) .'.'. $this->NameQuote($name); + return $this->nameQuote($this->schema) .'.'. $this->nameQuote($name); } - return $this->NameQuote($name); + return $this->nameQuote($name); } - // Executes the sql array returned by GetTableSQL and GetIndexSQL - function ExecuteSQLArray($sql, $continueOnError = true) + // Executes the sql array returned by getTableSQL and getIndexSQL + function executeSQLArray($sql, $continueOnError = true) { $rez = 2; $conn = $this->connection; @@ -377,10 +396,10 @@ class ADODB_DataDict { foreach($sql as $line) { if ($this->debug) $conn->debug = true; - $ok = $conn->Execute($line); + $ok = $conn->execute($line); $conn->debug = $saved; if (!$ok) { - if ($this->debug) ADOConnection::outp($conn->ErrorMsg()); + if ($this->debug) ADOConnection::outp($conn->errorMsg()); if (!$continueOnError) return 0; $rez = 1; } @@ -406,17 +425,17 @@ class ADODB_DataDict { N: Numeric or decimal number */ - function ActualType($meta) + function actualType($meta) { return $meta; } - function CreateDatabase($dbname,$options=false) + function createDatabase($dbname,$options=false) { - $options = $this->_Options($options); + $options = $this->_options($options); $sql = array(); - $s = 'CREATE DATABASE ' . $this->NameQuote($dbname); + $s = 'CREATE DATABASE ' . $this->nameQuote($dbname); if (isset($options[$this->upperName])) $s .= ' '.$options[$this->upperName]; @@ -427,7 +446,7 @@ class ADODB_DataDict { /* Generates the SQL to create index. Returns an array of sql strings. */ - function CreateIndexSQL($idxname, $tabname, $flds, $idxoptions = false) + function createIndexSQL($idxname, $tabname, $flds, $idxoptions = false) { if (!is_array($flds)) { $flds = explode(',',$flds); @@ -435,27 +454,27 @@ class ADODB_DataDict { foreach($flds as $key => $fld) { # some indexes can use partial fields, eg. index first 32 chars of "name" with NAME(32) - $flds[$key] = $this->NameQuote($fld,$allowBrackets=true); + $flds[$key] = $this->nameQuote($fld,$allowBrackets=true); } - return $this->_IndexSQL($this->NameQuote($idxname), $this->TableName($tabname), $flds, $this->_Options($idxoptions)); + return $this->_indexSQL($this->nameQuote($idxname), $this->tableName($tabname), $flds, $this->_options($idxoptions)); } - function DropIndexSQL ($idxname, $tabname = NULL) + function dropIndexSQL ($idxname, $tabname = NULL) { - return array(sprintf($this->dropIndex, $this->NameQuote($idxname), $this->TableName($tabname))); + return array(sprintf($this->dropIndex, $this->nameQuote($idxname), $this->tableName($tabname))); } - function SetSchema($schema) + function setSchema($schema) { $this->schema = $schema; } - function AddColumnSQL($tabname, $flds) + function addColumnSQL($tabname, $flds) { - $tabname = $this->TableName ($tabname); + $tabname = $this->tableName($tabname); $sql = array(); - list($lines,$pkey,$idxs) = $this->_GenFields($flds); + list($lines,$pkey,$idxs) = $this->_genFields($flds); // genfields can return FALSE at times if ($lines == null) $lines = array(); $alter = 'ALTER TABLE ' . $tabname . $this->addCol . ' '; @@ -464,7 +483,7 @@ class ADODB_DataDict { } if (is_array($idxs)) { foreach($idxs as $idx => $idxdef) { - $sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']); + $sql_idxs = $this->createIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']); $sql = array_merge($sql, $sql_idxs); } } @@ -474,19 +493,19 @@ class ADODB_DataDict { /** * Change the definition of one column * - * As some DBM's can't do that on there own, you need to supply the complete defintion of the new table, - * to allow, recreating the table and copying the content over to the new table + * As some DBMs can't do that on their own, you need to supply the complete definition of the new table, + * to allow recreating the table and copying the content over to the new table * @param string $tabname table-name * @param string $flds column-name and type for the changed column - * @param string $tableflds='' complete defintion of the new table, eg. for postgres, default '' - * @param array/string $tableoptions='' options for the new table see CreateTableSQL, default '' + * @param string $tableflds='' complete definition of the new table, eg. for postgres, default '' + * @param array/string $tableoptions='' options for the new table see createTableSQL, default '' * @return array with SQL strings */ - function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') + function alterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') { - $tabname = $this->TableName ($tabname); + $tabname = $this->tableName($tabname); $sql = array(); - list($lines,$pkey,$idxs) = $this->_GenFields($flds); + list($lines,$pkey,$idxs) = $this->_genFields($flds); // genfields can return FALSE at times if ($lines == null) $lines = array(); $alter = 'ALTER TABLE ' . $tabname . $this->alterCol . ' '; @@ -495,7 +514,7 @@ class ADODB_DataDict { } if (is_array($idxs)) { foreach($idxs as $idx => $idxdef) { - $sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']); + $sql_idxs = $this->createIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']); $sql = array_merge($sql, $sql_idxs); } @@ -506,71 +525,71 @@ class ADODB_DataDict { /** * Rename one column * - * Some DBM's can only do this together with changeing the type of the column (even if that stays the same, eg. mysql) + * Some DBMs can only do this together with changeing the type of the column (even if that stays the same, eg. mysql) * @param string $tabname table-name * @param string $oldcolumn column-name to be renamed * @param string $newcolumn new column-name - * @param string $flds='' complete column-defintion-string like for AddColumnSQL, only used by mysql atm., default='' + * @param string $flds='' complete column-definition-string like for addColumnSQL, only used by mysql atm., default='' * @return array with SQL strings */ - function RenameColumnSQL($tabname,$oldcolumn,$newcolumn,$flds='') + function renameColumnSQL($tabname,$oldcolumn,$newcolumn,$flds='') { - $tabname = $this->TableName ($tabname); + $tabname = $this->tableName($tabname); if ($flds) { - list($lines,$pkey,$idxs) = $this->_GenFields($flds); + list($lines,$pkey,$idxs) = $this->_genFields($flds); // genfields can return FALSE at times if ($lines == null) $lines = array(); - list(,$first) = each($lines); + $first = current($lines); list(,$column_def) = preg_split("/[\t ]+/",$first,2); } - return array(sprintf($this->renameColumn,$tabname,$this->NameQuote($oldcolumn),$this->NameQuote($newcolumn),$column_def)); + return array(sprintf($this->renameColumn,$tabname,$this->nameQuote($oldcolumn),$this->nameQuote($newcolumn),$column_def)); } /** * Drop one column * - * Some DBM's can't do that on there own, you need to supply the complete defintion of the new table, + * Some DBM's can't do that on their own, you need to supply the complete definition of the new table, * to allow, recreating the table and copying the content over to the new table * @param string $tabname table-name * @param string $flds column-name and type for the changed column - * @param string $tableflds='' complete defintion of the new table, eg. for postgres, default '' - * @param array/string $tableoptions='' options for the new table see CreateTableSQL, default '' + * @param string $tableflds='' complete definition of the new table, eg. for postgres, default '' + * @param array/string $tableoptions='' options for the new table see createTableSQL, default '' * @return array with SQL strings */ - function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') + function dropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') { - $tabname = $this->TableName ($tabname); + $tabname = $this->tableName($tabname); if (!is_array($flds)) $flds = explode(',',$flds); $sql = array(); $alter = 'ALTER TABLE ' . $tabname . $this->dropCol . ' '; foreach($flds as $v) { - $sql[] = $alter . $this->NameQuote($v); + $sql[] = $alter . $this->nameQuote($v); } return $sql; } - function DropTableSQL($tabname) + function dropTableSQL($tabname) { - return array (sprintf($this->dropTable, $this->TableName($tabname))); + return array (sprintf($this->dropTable, $this->tableName($tabname))); } - function RenameTableSQL($tabname,$newname) + function renameTableSQL($tabname,$newname) { - return array (sprintf($this->renameTable, $this->TableName($tabname),$this->TableName($newname))); + return array (sprintf($this->renameTable, $this->tableName($tabname),$this->tableName($newname))); } /** Generate the SQL to create table. Returns an array of sql strings. */ - function CreateTableSQL($tabname, $flds, $tableoptions=array()) + function createTableSQL($tabname, $flds, $tableoptions=array()) { - list($lines,$pkey,$idxs) = $this->_GenFields($flds, true); + list($lines,$pkey,$idxs) = $this->_genFields($flds, true); // genfields can return FALSE at times if ($lines == null) $lines = array(); - $taboptions = $this->_Options($tableoptions); - $tabname = $this->TableName ($tabname); - $sql = $this->_TableSQL($tabname,$lines,$pkey,$taboptions); + $taboptions = $this->_options($tableoptions); + $tabname = $this->tableName($tabname); + $sql = $this->_tableSQL($tabname,$lines,$pkey,$taboptions); // ggiunta - 2006/10/12 - KLUDGE: // if we are on autoincrement, and table options includes REPLACE, the @@ -579,12 +598,12 @@ class ADODB_DataDict { // creating sql that double-drops the sequence if ($this->autoIncrement && isset($taboptions['REPLACE'])) unset($taboptions['REPLACE']); - $tsql = $this->_Triggers($tabname,$taboptions); + $tsql = $this->_triggers($tabname,$taboptions); foreach($tsql as $s) $sql[] = $s; if (is_array($idxs)) { foreach($idxs as $idx => $idxdef) { - $sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']); + $sql_idxs = $this->createIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']); $sql = array_merge($sql, $sql_idxs); } } @@ -594,13 +613,13 @@ class ADODB_DataDict { - function _GenFields($flds,$widespacing=false) + function _genFields($flds,$widespacing=false) { if (is_string($flds)) { $padding = ' '; $txt = $flds.$padding; $flds = array(); - $flds0 = Lens_ParseArgs($txt,','); + $flds0 = lens_ParseArgs($txt,','); $hasparam = false; foreach($flds0 as $f0) { $f1 = array(); @@ -643,8 +662,8 @@ class ADODB_DataDict { $pkey = array(); $idxs = array(); foreach($flds as $fld) { - $fld = _array_change_key_case($fld); - + if (is_array($fld)) + $fld = array_change_key_case($fld,CASE_UPPER); $fname = false; $fdefault = false; $fautoinc = false; @@ -660,18 +679,23 @@ class ADODB_DataDict { $funsigned = false; $findex = ''; $funiqueindex = false; + $fOptions = array(); //----------------- // Parse attributes foreach($fld as $attr => $v) { - if ($attr == 2 && is_numeric($v)) $attr = 'SIZE'; - else if (is_numeric($attr) && $attr > 1 && !is_numeric($v)) $attr = strtoupper($v); + if ($attr == 2 && is_numeric($v)) + $attr = 'SIZE'; + elseif ($attr == 2 && strtoupper($ftype) == 'ENUM') + $attr = 'ENUM'; + else if (is_numeric($attr) && $attr > 1 && !is_numeric($v)) + $attr = strtoupper($v); switch($attr) { case '0': case 'NAME': $fname = $v; break; case '1': - case 'TYPE': $ty = $v; $ftype = $this->ActualType(strtoupper($v)); break; + case 'TYPE': $ty = $v; $ftype = $this->actualType(strtoupper($v)); break; case 'SIZE': $dotat = strpos($v,'.'); if ($dotat === false) $dotat = strpos($v,','); @@ -697,6 +721,8 @@ class ADODB_DataDict { // let INDEX keyword create a 'very standard' index on column case 'INDEX': $findex = $v; break; case 'UNIQUE': $funiqueindex = true; break; + case 'ENUM': + $fOptions['ENUM'] = $v; break; } //switch } // foreach $fld @@ -708,7 +734,7 @@ class ADODB_DataDict { } $fid = strtoupper(preg_replace('/^`(.+)`$/', '$1', $fname)); - $fname = $this->NameQuote($fname); + $fname = $this->nameQuote($fname); if (!strlen($ftype)) { if ($this->debug) ADOConnection::outp("Undefined TYPE for field '$fname'"); @@ -717,14 +743,24 @@ class ADODB_DataDict { $ftype = strtoupper($ftype); } - $ftype = $this->_GetSize($ftype, $ty, $fsize, $fprec); + $ftype = $this->_getSize($ftype, $ty, $fsize, $fprec, $fOptions); - if ($ty == 'X' || $ty == 'X2' || $ty == 'B') $fnotnull = false; // some blob types do not accept nulls + if (($ty == 'X' || $ty == 'X2' || $ty == 'XL' || $ty == 'B') && !$this->blobAllowsNotNull) + /* + * some blob types do not accept nulls, so we override the + * previously defined value + */ + $fnotnull = false; - if ($fprimary) $pkey[] = $fname; + if ($fprimary) + $pkey[] = $fname; - // some databases do not allow blobs to have defaults - if ($ty == 'X') $fdefault = false; + if (($ty == 'X' || $ty == 'X2' || $ty == 'XL' || $ty == 'B') && !$this->blobAllowsDefaultValue) + /* + * some databases do not allow blobs to have defaults, so we + * override the previously defined value + */ + $fdefault = false; // build list of indexes if ($findex != '') { @@ -769,11 +805,11 @@ class ADODB_DataDict { // convert default date into database-aware code if ($ty == 'T') { - $fdefault = $this->connection->DBTimeStamp($fdefault); + $fdefault = $this->connection->dbTimeStamp($fdefault); } else { - $fdefault = $this->connection->DBDate($fdefault); + $fdefault = $this->connection->dbDate($fdefault); } } else @@ -783,7 +819,7 @@ class ADODB_DataDict { $fdefault = $this->connection->qstr($fdefault); } } - $suffix = $this->_CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned); + $suffix = $this->_createSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned); // add index creation if ($widespacing) $fname = str_pad($fname,24); @@ -806,19 +842,38 @@ class ADODB_DataDict { $ftype is the actual type $ty is the type defined originally in the DDL */ - function _GetSize($ftype, $ty, $fsize, $fprec) + function _getSize($ftype, $ty, $fsize, $fprec, $options=false) { if (strlen($fsize) && $ty != 'X' && $ty != 'B' && strpos($ftype,'(') === false) { $ftype .= "(".$fsize; if (strlen($fprec)) $ftype .= ",".$fprec; $ftype .= ')'; } + + /* + * Handle additional options + */ + if (is_array($options)) + { + foreach($options as $type=>$value) + { + switch ($type) + { + case 'ENUM': + $ftype .= '(' . $value . ')'; + break; + + default: + } + } + } + return $ftype; } // return string must begin with space - function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) + function _createSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) { $suffix = ''; if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault"; @@ -827,7 +882,7 @@ class ADODB_DataDict { return $suffix; } - function _IndexSQL($idxname, $tabname, $flds, $idxoptions) + function _indexSQL($idxname, $tabname, $flds, $idxoptions) { $sql = array(); @@ -856,25 +911,26 @@ class ADODB_DataDict { return $sql; } - function _DropAutoIncrement($tabname) + function _dropAutoIncrement($tabname) { return false; } - function _TableSQL($tabname,$lines,$pkey,$tableoptions) + function _tableSQL($tabname,$lines,$pkey,$tableoptions) { $sql = array(); if (isset($tableoptions['REPLACE']) || isset ($tableoptions['DROP'])) { $sql[] = sprintf($this->dropTable,$tabname); if ($this->autoIncrement) { - $sInc = $this->_DropAutoIncrement($tabname); + $sInc = $this->_dropAutoIncrement($tabname); if ($sInc) $sql[] = $sInc; } if ( isset ($tableoptions['DROP']) ) { return $sql; } } + $s = "CREATE TABLE $tabname (\n"; $s .= implode(",\n", $lines); if (sizeof($pkey)>0) { @@ -898,7 +954,7 @@ class ADODB_DataDict { GENERATE TRIGGERS IF NEEDED used when table has auto-incrementing field that is emulated using triggers */ - function _Triggers($tabname,$taboptions) + function _triggers($tabname,$taboptions) { return array(); } @@ -906,7 +962,7 @@ class ADODB_DataDict { /** Sanitize options, so that array elements with no keys are promoted to keys */ - function _Options($opts) + function _options($opts) { if (!is_array($opts)) return array(); $newopts = array(); @@ -938,25 +994,25 @@ class ADODB_DataDict { This function changes/adds new fields to your table. You don't have to know if the col is new or not. It will check on its own. */ - function ChangeTableSQL($tablename, $flds, $tableoptions = false, $dropOldFlds=false, $forceAlter = false) // GS Fix for constraint impl - forceAlter + function changeTableSQL($tablename, $flds, $tableoptions = false, $dropOldFlds=false) { global $ADODB_FETCH_MODE; $save = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; - if ($this->connection->fetchMode !== false) $savem = $this->connection->SetFetchMode(false); + if ($this->connection->fetchMode !== false) $savem = $this->connection->setFetchMode(false); // check table exists $save_handler = $this->connection->raiseErrorFn; $this->connection->raiseErrorFn = ''; - $cols = $this->MetaColumns($tablename); + $cols = $this->metaColumns($tablename); $this->connection->raiseErrorFn = $save_handler; - if (isset($savem)) $this->connection->SetFetchMode($savem); + if (isset($savem)) $this->connection->setFetchMode($savem); $ADODB_FETCH_MODE = $save; - if ( $forceAlter == false && empty($cols)) { // GS Fix for constraint impl - return $this->CreateTableSQL($tablename, $flds, $tableoptions); + if ( empty($cols)) { + return $this->createTableSQL($tablename, $flds, $tableoptions); } if (is_array($flds)) { @@ -976,7 +1032,7 @@ class ADODB_DataDict { $c = $cols[$k]; $ml = $c->max_length; - $mt = $this->MetaType($c->type,$ml); + $mt = $this->metaType($c->type,$ml); if (isset($c->scale)) $sc = $c->scale; else $sc = 99; // always force change if scale not known. @@ -998,16 +1054,16 @@ class ADODB_DataDict { // already exists, alter table instead - list($lines,$pkey,$idxs) = $this->_GenFields($flds); + list($lines,$pkey,$idxs) = $this->_genFields($flds); // genfields can return FALSE at times if ($lines == null) $lines = array(); - $alter = 'ALTER TABLE ' . $this->TableName($tablename); + $alter = 'ALTER TABLE ' . $this->tableName($tablename); $sql = array(); foreach ( $lines as $id => $v ) { if ( isset($cols[$id]) && is_object($cols[$id]) ) { - $flds = Lens_ParseArgs($v,','); + $flds = lens_ParseArgs($v,','); // We are trying to change the size of the field, if not allowed, simply ignore the request. // $flds[1] holds the type, $flds[2] holds the size -postnuke addition @@ -1028,39 +1084,6 @@ class ADODB_DataDict { if ( !isset($lines[$id]) ) $sql[] = $alter . $this->dropCol . ' ' . $v->name; } - - // GS Fix for constraint impl -- start - if($forceAlter == false) { - return $sql; - } - - $sqlarray = array(); - $alter .= implode(",\n", $sql); - if (sizeof($pkey)>0) { - $alter .= ",\n PRIMARY KEY ("; - $alter .= implode(", ",$pkey).")"; - } - - if (isset($tableoptions['CONSTRAINTS'])) { - $alter .= "\n".$tableoptions['CONSTRAINTS']; - } - - if (isset($tableoptions[$this->upperName.'_CONSTRAINTS'])) { - $alter .= "\n".$tableoptions[$this->upperName.'_CONSTRAINTS']; - } - - if (isset($tableoptions[$this->upperName])) { - $alter .= $tableoptions[$this->upperName]; - } - $sqlarray[] = $alter; - - $taboptions = $this->_Options($tableoptions); - $tsql = $this->_Triggers($this->TableName($tablename),$taboptions); - foreach($tsql as $s) { - $sqlarray[] = $s; - } - // GS Fix for constraint impl -- end - - return $sqlarray; + return $sql; } } // class diff --git a/libraries/adodb/adodb-error.inc.php b/libraries/adodb/adodb-error.inc.php index d42a06a83..517cf9b01 100644 --- a/libraries/adodb/adodb-error.inc.php +++ b/libraries/adodb/adodb-error.inc.php @@ -1,19 +1,27 @@ <?php /** - * @version v5.20.9 21-Dec-2016 - * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - * @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - * Released under both BSD license and Lesser GPL library license. - * Whenever there is any discrepancy between the two licenses, - * the BSD license will take precedence. + * Error handling code and constants. * - * Set tabs to 4 for best viewing. + * Adapted from the PEAR DB error handling code. + * Portions (c)1997-2002 The PHP Group * - * The following code is adapted from the PEAR DB error handling code. - * Portions (c)1997-2002 The PHP Group. + * 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 */ - if (!defined("DB_ERROR")) define("DB_ERROR",-1); if (!defined("DB_ERROR_SYNTAX")) { @@ -70,6 +78,10 @@ function adodb_error($provider,$dbType,$errno) case 'oracle': case 'oci8': $map = adodb_error_oci8(); break; + // As discussed in https://github.com/ADOdb/ADOdb/issues/201#issuecomment-188154980 + // firebird uses the ibase error handler for now. This may change if and + // when the PHP driver is updated to use the new SQLSTATE error codes + case 'firebird': case 'ibase': $map = adodb_error_ibase(); break; case 'odbc': $map = adodb_error_odbc(); break; @@ -111,7 +123,7 @@ function adodb_error_pg($errormsg) 'could not serialize access due to' => DB_ERROR_SERIALIZATION_FAILURE ); reset($error_regexps); - while (list($regexp,$code) = each($error_regexps)) { + foreach ($error_regexps as $regexp => $code) { if (preg_match("/$regexp/mi", $errormsg)) { return $code; } @@ -245,9 +257,9 @@ static $MAP = array( 1006 => DB_ERROR_CANNOT_CREATE, 1007 => DB_ERROR_ALREADY_EXISTS, 1008 => DB_ERROR_CANNOT_DROP, - 1045 => DB_ERROR_ACCESS_VIOLATION, + 1045 => DB_ERROR_ACCESS_VIOLATION, 1046 => DB_ERROR_NODBSELECTED, - 1049 => DB_ERROR_NOSUCHDB, + 1049 => DB_ERROR_NOSUCHDB, 1050 => DB_ERROR_ALREADY_EXISTS, 1051 => DB_ERROR_NOSUCHTABLE, 1054 => DB_ERROR_NOSUCHFIELD, @@ -257,8 +269,8 @@ static $MAP = array( 1136 => DB_ERROR_VALUE_COUNT_ON_ROW, 1146 => DB_ERROR_NOSUCHTABLE, 1048 => DB_ERROR_CONSTRAINT, - 2002 => DB_ERROR_CONNECT_FAILED, - 2005 => DB_ERROR_CONNECT_FAILED + 2002 => DB_ERROR_CONNECT_FAILED, + 2005 => DB_ERROR_CONNECT_FAILED ); return $MAP; diff --git a/libraries/adodb/adodb-errorhandler.inc.php b/libraries/adodb/adodb-errorhandler.inc.php index 7f36ba1ee..0cd3f218b 100644 --- a/libraries/adodb/adodb-errorhandler.inc.php +++ b/libraries/adodb/adodb-errorhandler.inc.php @@ -1,18 +1,23 @@ <?php /** - * @version v5.20.9 21-Dec-2016 - * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - * @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - * Released under both BSD license and Lesser GPL library license. - * Whenever there is any discrepancy between the two licenses, - * the BSD license will take precedence. + * ADOdb Default Error Handler. * - * Set tabs to 4 for best viewing. + * This file is part of ADOdb, a Database Abstraction Layer library for PHP. * - * Latest version is available at http://php.weblogs.com + * @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 + */ // added Claudio Bustos clbustos#entelchile.net if (!defined('ADODB_ERROR_HANDLER_TYPE')) define('ADODB_ERROR_HANDLER_TYPE',E_USER_ERROR); diff --git a/libraries/adodb/adodb-errorpear.inc.php b/libraries/adodb/adodb-errorpear.inc.php index 474d6d5ba..2bb15947e 100644 --- a/libraries/adodb/adodb-errorpear.inc.php +++ b/libraries/adodb/adodb-errorpear.inc.php @@ -1,17 +1,24 @@ <?php /** - * @version v5.20.9 21-Dec-2016 - * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - * @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - * Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. + * Error Handler with PEAR support. * - * Set tabs to 4 for best viewing. + * This file is part of ADOdb, a Database Abstraction Layer library for PHP. * - * Latest version is available at http://php.weblogs.com + * @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 + */ + include_once('PEAR.php'); if (!defined('ADODB_ERROR_HANDLER')) define('ADODB_ERROR_HANDLER','ADODB_Error_PEAR'); @@ -78,7 +85,7 @@ global $ADODB_Last_PEAR_Error; /** * Returns last PEAR_Error object. This error might be for an error that -* occured several sql statements ago. +* occurred several sql statements ago. */ function ADODB_PEAR_Error() { diff --git a/libraries/adodb/adodb-exceptions.inc.php b/libraries/adodb/adodb-exceptions.inc.php index 9c66ac398..9f1176f0f 100644 --- a/libraries/adodb/adodb-exceptions.inc.php +++ b/libraries/adodb/adodb-exceptions.inc.php @@ -1,21 +1,24 @@ <?php - /** - * @version v5.20.9 21-Dec-2016 - * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - * @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - * Released under both BSD license and Lesser GPL library license. - * Whenever there is any discrepancy between the two licenses, - * the BSD license will take precedence. + * Error handling using Exceptions. + * + * This file is part of ADOdb, a Database Abstraction Layer library for PHP. * - * Set tabs to 4 for best viewing. + * @package ADOdb + * @link https://adodb.org Project's web site and documentation + * @link https://github.com/ADOdb/ADOdb Source code and issue tracker * - * Latest version is available at http://php.weblogs.com + * 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 * - * Exception-handling code using PHP5 exceptions (try-catch-throw). + * @copyright 2000-2013 John Lim + * @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community */ - if (!defined('ADODB_ERROR_HANDLER_TYPE')) define('ADODB_ERROR_HANDLER_TYPE',E_USER_ERROR); define('ADODB_ERROR_HANDLER','adodb_throw'); @@ -60,14 +63,14 @@ var $database = ''; } /** -* Default Error Handler. This will be called with the following params +* Default Error Handler. * -* @param $dbms the RDBMS you are connecting to -* @param $fn the name of the calling function (in uppercase) -* @param $errno the native error number from the database -* @param $errmsg the native error msg from the database -* @param $p1 $fn specific parameter - see below -* @param $P2 $fn specific parameter - see below +* @param string $dbms the RDBMS you are connecting to +* @param string $fn the name of the calling function (in uppercase) +* @param int $errno the native error number from the database +* @param string $errmsg the native error msg from the database +* @param mixed $p1 $fn specific parameter - see below +* @param mixed $p2 $fn specific parameter - see below */ function adodb_throw($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection) diff --git a/libraries/adodb/adodb-iterator.inc.php b/libraries/adodb/adodb-iterator.inc.php deleted file mode 100644 index cfc067bc8..000000000 --- a/libraries/adodb/adodb-iterator.inc.php +++ /dev/null @@ -1,26 +0,0 @@ -<?php - -/* - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4. - - Declares the ADODB Base Class for PHP5 "ADODB_BASE_RS", and supports iteration with - the ADODB_Iterator class. - - $rs = $db->Execute("select * from adoxyz"); - foreach($rs as $k => $v) { - echo $k; print_r($v); echo "<br>"; - } - - - Iterator code based on http://cvs.php.net/cvs.php/php-src/ext/spl/examples/cachingiterator.inc?login=2 - - - Moved to adodb.inc.php to improve performance. - */ diff --git a/libraries/adodb/adodb-lib.inc.php b/libraries/adodb/adodb-lib.inc.php index 60285305f..ced5e1261 100644 --- a/libraries/adodb/adodb-lib.inc.php +++ b/libraries/adodb/adodb-lib.inc.php @@ -1,25 +1,40 @@ <?php +/** + * Helper functions. + * + * Less commonly used functions are placed here to reduce size of adodb.inc.php. + * + * 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(); global $ADODB_INCLUDED_LIB; $ADODB_INCLUDED_LIB = 1; -/* - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. See License.txt. - Set tabs to 4 for best viewing. - - Less commonly used functions are placed here to reduce size of adodb.inc.php. -*/ - function adodb_strip_order_by($sql) { - $rez = preg_match('/(\sORDER\s+BY\s(?:[^)](?!LIMIT))*)/is', $sql, $arr); + $rez = preg_match_all('/(\sORDER\s+BY\s(?:[^)](?!LIMIT))*)/is', $sql, $arr); + if ($arr) + { + $tmp = array_pop($arr); + $arr = [1=>array_pop($tmp)]; + } if ($arr) if (strpos($arr[1], '(') !== false) { $at = strpos($sql, $arr[1]); @@ -39,6 +54,7 @@ function adodb_strip_order_by($sql) } else { $sql = str_replace($arr[1], '', $sql); } + return $sql; } @@ -118,272 +134,259 @@ function adodb_transpose(&$arr, &$newarr, &$hdr, &$fobjs) } } -// Force key to upper. -// See also http://www.php.net/manual/en/function.array-change-key-case.php -function _array_change_key_case($an_array) -{ - if (is_array($an_array)) { - $new_array = array(); - foreach($an_array as $key=>$value) - $new_array[strtoupper($key)] = $value; - - return $new_array; - } - - return $an_array; -} function _adodb_replace(&$zthis, $table, $fieldArray, $keyCol, $autoQuote, $has_autoinc) { - if (count($fieldArray) == 0) return 0; - $first = true; - $uSet = ''; - - if (!is_array($keyCol)) { - $keyCol = array($keyCol); - } - foreach($fieldArray as $k => $v) { - if ($v === null) { - $v = 'NULL'; - $fieldArray[$k] = $v; - } else if ($autoQuote && /*!is_numeric($v) /*and strncmp($v,"'",1) !== 0 -- sql injection risk*/ strcasecmp($v,$zthis->null2null)!=0) { - $v = $zthis->qstr($v); - $fieldArray[$k] = $v; - } - if (in_array($k,$keyCol)) continue; // skip UPDATE if is key + // Add Quote around table name to support use of spaces / reserved keywords + $table=sprintf('%s%s%s', $zthis->nameQuote,$table,$zthis->nameQuote); - if ($first) { - $first = false; - $uSet = "$k=$v"; - } else - $uSet .= ",$k=$v"; - } + if (count($fieldArray) == 0) return 0; - $where = false; - foreach ($keyCol as $v) { - if (isset($fieldArray[$v])) { - if ($where) $where .= ' and '.$v.'='.$fieldArray[$v]; - else $where = $v.'='.$fieldArray[$v]; - } + if (!is_array($keyCol)) { + $keyCol = array($keyCol); + } + $uSet = ''; + foreach($fieldArray as $k => $v) { + if ($v === null) { + $v = 'NULL'; + $fieldArray[$k] = $v; + } else if ($autoQuote && /*!is_numeric($v) /*and strncmp($v,"'",1) !== 0 -- sql injection risk*/ strcasecmp($v,$zthis->null2null)!=0) { + $v = $zthis->qstr($v); + $fieldArray[$k] = $v; } + if (in_array($k,$keyCol)) continue; // skip UPDATE if is key - if ($uSet && $where) { - $update = "UPDATE $table SET $uSet WHERE $where"; + // Add Quote around column name to support use of spaces / reserved keywords + $uSet .= sprintf(',%s%s%s=%s',$zthis->nameQuote,$k,$zthis->nameQuote,$v); + } + $uSet = ltrim($uSet, ','); - $rs = $zthis->Execute($update); + // Add Quote around column name in where clause + $where = ''; + foreach ($keyCol as $v) { + if (isset($fieldArray[$v])) { + $where .= sprintf(' and %s%s%s=%s ', $zthis->nameQuote,$v,$zthis->nameQuote,$fieldArray[$v]); + } + } + if ($where) { + $where = substr($where, 5); + } + if ($uSet && $where) { + $update = "UPDATE $table SET $uSet WHERE $where"; + $rs = $zthis->Execute($update); - if ($rs) { - if ($zthis->poorAffectedRows) { - /* - The Select count(*) wipes out any errors that the update would have returned. - http://phplens.com/lens/lensforum/msgs.php?id=5696 - */ - if ($zthis->ErrorNo()<>0) return 0; + if ($rs) { + if ($zthis->poorAffectedRows) { + // The Select count(*) wipes out any errors that the update would have returned. + // PHPLens Issue No: 5696 + if ($zthis->ErrorNo()<>0) return 0; - # affected_rows == 0 if update field values identical to old values - # for mysql - which is silly. + // affected_rows == 0 if update field values identical to old values + // for mysql - which is silly. + $cnt = $zthis->GetOne("select count(*) from $table where $where"); + if ($cnt > 0) return 1; // record already exists + } else { + if (($zthis->Affected_Rows()>0)) return 1; + } + } else + return 0; + } - $cnt = $zthis->GetOne("select count(*) from $table where $where"); - if ($cnt > 0) return 1; // record already exists - } else { - if (($zthis->Affected_Rows()>0)) return 1; - } - } else - return 0; - } + $iCols = $iVals = ''; + foreach($fieldArray as $k => $v) { + if ($has_autoinc && in_array($k,$keyCol)) continue; // skip autoinc col - // print "<p>Error=".$this->ErrorNo().'<p>'; - $first = true; - foreach($fieldArray as $k => $v) { - if ($has_autoinc && in_array($k,$keyCol)) continue; // skip autoinc col + // Add Quote around Column Name + $iCols .= sprintf(',%s%s%s',$zthis->nameQuote,$k,$zthis->nameQuote); + $iVals .= ",$v"; + } + $iCols = ltrim($iCols, ','); + $iVals = ltrim($iVals, ','); - if ($first) { - $first = false; - $iCols = "$k"; - $iVals = "$v"; - } else { - $iCols .= ",$k"; - $iVals .= ",$v"; - } - } - $insert = "INSERT INTO $table ($iCols) VALUES ($iVals)"; - $rs = $zthis->Execute($insert); - return ($rs) ? 2 : 0; + $insert = "INSERT INTO $table ($iCols) VALUES ($iVals)"; + $rs = $zthis->Execute($insert); + return ($rs) ? 2 : 0; } -// Requires $ADODB_FETCH_MODE = ADODB_FETCH_NUM function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=false, $size=0, $selectAttr='',$compareFields0=true) { - $hasvalue = false; - - if ($multiple or is_array($defstr)) { - if ($size==0) $size=5; - $attr = ' multiple size="'.$size.'"'; - if (!strpos($name,'[]')) $name .= '[]'; - } else if ($size) $attr = ' size="'.$size.'"'; - else $attr =''; + global $ADODB_FETCH_MODE; - $s = '<select name="'.$name.'"'.$attr.' '.$selectAttr.'>'; - if ($blank1stItem) - if (is_string($blank1stItem)) { - $barr = explode(':',$blank1stItem); - if (sizeof($barr) == 1) $barr[] = ''; - $s .= "\n<option value=\"".$barr[0]."\">".$barr[1]."</option>"; - } else $s .= "\n<option></option>"; + $s = _adodb_getmenu_select($name, $defstr, $blank1stItem, $multiple, $size, $selectAttr); - if ($zthis->FieldCount() > 1) $hasvalue=true; - else $compareFields0 = true; + $hasvalue = $zthis->FieldCount() > 1; + if (!$hasvalue) { + $compareFields0 = true; + } $value = ''; - $optgroup = null; - $firstgroup = true; - $fieldsize = $zthis->FieldCount(); while(!$zthis->EOF) { $zval = rtrim(reset($zthis->fields)); - if ($blank1stItem && $zval=="") { + if ($blank1stItem && $zval == "") { $zthis->MoveNext(); continue; } - if ($fieldsize > 1) { - if (isset($zthis->fields[1])) - $zval2 = rtrim($zthis->fields[1]); - else - $zval2 = rtrim(next($zthis->fields)); - } - $selected = ($compareFields0) ? $zval : $zval2; - - $group = ''; - if ($fieldsize > 2) { - $group = rtrim($zthis->fields[2]); - } -/* - if ($optgroup != $group) { - $optgroup = $group; - if ($firstgroup) { - $firstgroup = false; - $s .="\n<optgroup label='". htmlspecialchars($group) ."'>"; - } else { - $s .="\n</optgroup>"; - $s .="\n<optgroup label='". htmlspecialchars($group) ."'>"; - } + if ($hasvalue) { + if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC) { + // Get 2nd field's value regardless of its name + $zval2 = current(array_slice($zthis->fields, 1, 1)); + } else { + // With NUM or BOTH fetch modes, we have a numeric index + $zval2 = $zthis->fields[1]; + } + $zval2 = trim($zval2); + $value = 'value="' . htmlspecialchars($zval2) . '"'; } -*/ - if ($hasvalue) - $value = " value='".htmlspecialchars($zval2)."'"; - if (is_array($defstr)) { + $s .= _adodb_getmenu_option($defstr, $compareFields0 ? $zval : $zval2, $value, $zval); - if (in_array($selected,$defstr)) - $s .= "\n<option selected='selected'$value>".htmlspecialchars($zval).'</option>'; - else - $s .= "\n<option".$value.'>'.htmlspecialchars($zval).'</option>'; - } - else { - if (strcasecmp($selected,$defstr)==0) - $s .= "\n<option selected='selected'$value>".htmlspecialchars($zval).'</option>'; - else - $s .= "\n<option".$value.'>'.htmlspecialchars($zval).'</option>'; - } $zthis->MoveNext(); } // while - // closing last optgroup - if($optgroup != null) { - $s .= "\n</optgroup>"; - } return $s ."\n</select>\n"; } -// Requires $ADODB_FETCH_MODE = ADODB_FETCH_NUM function _adodb_getmenu_gp(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=false, $size=0, $selectAttr='',$compareFields0=true) { - $hasvalue = false; - - if ($multiple or is_array($defstr)) { - if ($size==0) $size=5; - $attr = ' multiple size="'.$size.'"'; - if (!strpos($name,'[]')) $name .= '[]'; - } else if ($size) $attr = ' size="'.$size.'"'; - else $attr =''; + global $ADODB_FETCH_MODE; - $s = '<select name="'.$name.'"'.$attr.' '.$selectAttr.'>'; - if ($blank1stItem) - if (is_string($blank1stItem)) { - $barr = explode(':',$blank1stItem); - if (sizeof($barr) == 1) $barr[] = ''; - $s .= "\n<option value=\"".$barr[0]."\">".$barr[1]."</option>"; - } else $s .= "\n<option></option>"; + $s = _adodb_getmenu_select($name, $defstr, $blank1stItem, $multiple, $size, $selectAttr); - if ($zthis->FieldCount() > 1) $hasvalue=true; - else $compareFields0 = true; + $hasvalue = $zthis->FieldCount() > 1; + $hasgroup = $zthis->FieldCount() > 2; + if (!$hasvalue) { + $compareFields0 = true; + } $value = ''; - $optgroup = null; - $firstgroup = true; - $fieldsize = sizeof($zthis->fields); + $optgroup = null; + $firstgroup = true; while(!$zthis->EOF) { $zval = rtrim(reset($zthis->fields)); + $group = ''; if ($blank1stItem && $zval=="") { $zthis->MoveNext(); continue; } - if ($fieldsize > 1) { - if (isset($zthis->fields[1])) - $zval2 = rtrim($zthis->fields[1]); - else - $zval2 = rtrim(next($zthis->fields)); + if ($hasvalue) { + if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC) { + // Get 2nd field's value regardless of its name + $fields = array_slice($zthis->fields, 1); + $zval2 = current($fields); + if ($hasgroup) { + $group = trim(next($fields)); + } + } else { + // With NUM or BOTH fetch modes, we have a numeric index + $zval2 = $zthis->fields[1]; + if ($hasgroup) { + $group = trim($zthis->fields[2]); + } + } + $zval2 = trim($zval2); + $value = "value='".htmlspecialchars($zval2)."'"; } - $selected = ($compareFields0) ? $zval : $zval2; - $group = ''; - if (isset($zthis->fields[2])) { - $group = rtrim($zthis->fields[2]); - } - - if ($optgroup != $group) { - $optgroup = $group; - if ($firstgroup) { - $firstgroup = false; - $s .="\n<optgroup label='". htmlspecialchars($group) ."'>"; - } else { - $s .="\n</optgroup>"; - $s .="\n<optgroup label='". htmlspecialchars($group) ."'>"; - } + if ($optgroup != $group) { + $optgroup = $group; + if ($firstgroup) { + $firstgroup = false; + } else { + $s .="\n</optgroup>"; + } + $s .="\n<optgroup label='". htmlspecialchars($group) ."'>"; } - if ($hasvalue) - $value = " value='".htmlspecialchars($zval2)."'"; + $s .= _adodb_getmenu_option($defstr, $compareFields0 ? $zval : $zval2, $value, $zval); - if (is_array($defstr)) { - - if (in_array($selected,$defstr)) - $s .= "\n<option selected='selected'$value>".htmlspecialchars($zval).'</option>'; - else - $s .= "\n<option".$value.'>'.htmlspecialchars($zval).'</option>'; - } - else { - if (strcasecmp($selected,$defstr)==0) - $s .= "\n<option selected='selected'$value>".htmlspecialchars($zval).'</option>'; - else - $s .= "\n<option".$value.'>'.htmlspecialchars($zval).'</option>'; - } $zthis->MoveNext(); } // while - // closing last optgroup - if($optgroup != null) { - $s .= "\n</optgroup>"; + // closing last optgroup + if($optgroup != null) { + $s .= "\n</optgroup>"; } return $s ."\n</select>\n"; } +/** + * Generate the opening SELECT tag for getmenu functions. + * + * ADOdb internal function, used by _adodb_getmenu() and _adodb_getmenu_gp(). + * + * @param string $name + * @param string $defstr + * @param bool $blank1stItem + * @param bool $multiple + * @param int $size + * @param string $selectAttr + * + * @return string HTML + */ +function _adodb_getmenu_select($name, $defstr = '', $blank1stItem = true, + $multiple = false, $size = 0, $selectAttr = '') +{ + if ($multiple || is_array($defstr)) { + if ($size == 0 ) { + $size = 5; + } + $attr = ' multiple size="' . $size . '"'; + if (!strpos($name,'[]')) { + $name .= '[]'; + } + } elseif ($size) { + $attr = ' size="' . $size . '"'; + } else { + $attr = ''; + } + + $html = '<select name="' . $name . '"' . $attr . ' ' . $selectAttr . '>'; + if ($blank1stItem) { + if (is_string($blank1stItem)) { + $barr = explode(':',$blank1stItem); + if (sizeof($barr) == 1) { + $barr[] = ''; + } + $html .= "\n<option value=\"" . $barr[0] . "\">" . $barr[1] . "</option>"; + } else { + $html .= "\n<option></option>"; + } + } + + return $html; +} + +/** + * Print the OPTION tags for getmenu functions. + * + * ADOdb internal function, used by _adodb_getmenu() and _adodb_getmenu_gp(). + * + * @param string $defstr Default values + * @param string $compare Value to compare against defaults + * @param string $value Ready-to-print `value="xxx"` (or empty) string + * @param string $display Display value + * + * @return string HTML + */ +function _adodb_getmenu_option($defstr, $compare, $value, $display) +{ + if ( is_array($defstr) && in_array($compare, $defstr) + || !is_array($defstr) && strcasecmp($compare, $defstr) == 0 + ) { + $selected = ' selected="selected"'; + } else { + $selected = ''; + } + + return "\n<option $value$selected>" . htmlspecialchars($display) . '</option>'; +} /* Count the number of records this sql statement will return by using @@ -401,10 +404,23 @@ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0) { $qryRecs = 0; - if (!empty($zthis->_nestedSQL) || preg_match("/^\s*SELECT\s+DISTINCT/is", $sql) || - preg_match('/\s+GROUP\s+BY\s+/is',$sql) || - preg_match('/\s+UNION\s+/is',$sql)) { + /* + * These databases require a "SELECT * FROM (SELECT" type + * statement to have an alias for the result + */ + $requiresAlias = ''; + $requiresAliasArray = array('postgres9','postgres','mysql','mysqli','mssql','mssqlnative','sqlsrv'); + if (in_array($zthis->databaseType,$requiresAliasArray) + || in_array($zthis->dsnType,$requiresAliasArray) + ) { + $requiresAlias = '_ADODB_ALIAS_'; + } + if (!empty($zthis->_nestedSQL) + || preg_match("/^\s*SELECT\s+DISTINCT/is", $sql) + || preg_match('/\s+GROUP\s+BY\s+/is',$sql) + || preg_match('/\s+UNION\s+/is',$sql) + ) { $rewritesql = adodb_strip_order_by($sql); // ok, has SELECT DISTINCT or GROUP BY so see if we can use a table alias @@ -415,27 +431,47 @@ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0) $rewritesql = "SELECT ".$hint[0]." COUNT(*) FROM (".$rewritesql.")"; } else $rewritesql = "SELECT COUNT(*) FROM (".$rewritesql.")"; - - } else if (strncmp($zthis->databaseType,'postgres',8) == 0 || strncmp($zthis->databaseType,'mysql',5) == 0) { - $rewritesql = "SELECT COUNT(*) FROM ($rewritesql) _ADODB_ALIAS_"; } else { - $rewritesql = "SELECT COUNT(*) FROM ($rewritesql)"; + $rewritesql = "SELECT COUNT(*) FROM ($rewritesql) $requiresAlias"; } + } else { - // now replace SELECT ... FROM with SELECT COUNT(*) FROM - if ( strpos($sql, '_ADODB_COUNT') !== FALSE ) { - $rewritesql = preg_replace('/^\s*?SELECT\s+_ADODB_COUNT(.*)_ADODB_COUNT\s/is','SELECT COUNT(*) ',$sql); - } else { - $rewritesql = preg_replace('/^\s*SELECT\s.*\s+FROM\s/Uis','SELECT COUNT(*) FROM ',$sql); + // Replace 'SELECT ... FROM' with 'SELECT COUNT(*) FROM' + // Parse the query one char at a time starting after the SELECT + // to find the FROM clause's position, ignoring any sub-queries. + $start = stripos($sql, 'SELECT') + 7; + if ($start === false) { + // Not a SELECT statement - probably should trigger an exception here + return 0; } + $len = strlen($sql); + $numParentheses = 0; + for ($pos = $start; $pos < $len; $pos++) { + switch ($sql[$pos]) { + case '(': $numParentheses++; continue 2; + case ')': $numParentheses--; continue 2; + } + // Ignore whatever is between parentheses (sub-queries) + if ($numParentheses > 0) { + continue; + } + // Exit loop if 'FROM' keyword was found + if (strtoupper(substr($sql, $pos, 4)) == 'FROM') { + break; + } + } + $rewritesql = 'SELECT COUNT(*) ' . substr($sql, $pos); + // fix by alexander zhukov, alex#unipack.ru, because count(*) and 'order by' fails // with mssql, access and postgresql. Also a good speedup optimization - skips sorting! - // also see http://phplens.com/lens/lensforum/msgs.php?id=12752 + // also see PHPLens Issue No: 12752 $rewritesql = adodb_strip_order_by($rewritesql); } if (isset($rewritesql) && $rewritesql != $sql) { - if (preg_match('/\sLIMIT\s+[0-9]+/i',$sql,$limitarr)) $rewritesql .= $limitarr[0]; + if (preg_match('/\sLIMIT\s+[0-9]+/i',$sql,$limitarr)) { + $rewritesql .= $limitarr[0]; + } if ($secs2cache) { // we only use half the time of secs2cache because the count can quickly @@ -444,18 +480,23 @@ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0) } else { $qryRecs = $zthis->GetOne($rewritesql,$inputarr); - } + } if ($qryRecs !== false) return $qryRecs; } + //-------------------------------------------- // query rewrite failed - so try slower way... - // strip off unneeded ORDER BY if no UNION - if (preg_match('/\s*UNION\s*/is', $sql)) $rewritesql = $sql; - else $rewritesql = $rewritesql = adodb_strip_order_by($sql); + if (preg_match('/\s*UNION\s*/is', $sql)) { + $rewritesql = $sql; + } else { + $rewritesql = $rewritesql = adodb_strip_order_by($sql); + } - if (preg_match('/\sLIMIT\s+[0-9]+/i',$sql,$limitarr)) $rewritesql .= $limitarr[0]; + if (preg_match('/\sLIMIT\s+[0-9]+/i',$sql,$limitarr)) { + $rewritesql .= $limitarr[0]; + } if ($secs2cache) { $rstest = $zthis->CacheExecute($secs2cache,$rewritesql,$inputarr); @@ -465,18 +506,11 @@ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0) if (!$rstest) $rstest = $zthis->Execute($sql,$inputarr); } if ($rstest) { - $qryRecs = $rstest->RecordCount(); + $qryRecs = $rstest->RecordCount(); if ($qryRecs == -1) { - global $ADODB_EXTENSION; - // some databases will return -1 on MoveLast() - change to MoveNext() - if ($ADODB_EXTENSION) { - while(!$rstest->EOF) { - adodb_movenext($rstest); - } - } else { - while(!$rstest->EOF) { - $rstest->MoveNext(); - } + // some databases will return -1 on MoveLast() - change to MoveNext() + while(!$rstest->EOF) { + $rstest->MoveNext(); } $qryRecs = $rstest->_currentRow; } @@ -639,148 +673,193 @@ function _adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputarr return $rsreturn; } -function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq=false,$force=2) +/** + * Performs case conversion and quoting of the given field name. + * + * See Global variable $ADODB_QUOTE_FIELDNAMES. + * + * @param ADOConnection $zthis + * @param string $fieldName + * + * @return string Quoted field name + */ +function _adodb_quote_fieldname($zthis, $fieldName) { global $ADODB_QUOTE_FIELDNAMES; - if (!$rs) { - printf(ADODB_BAD_RS,'GetUpdateSQL'); - return false; - } + // Case conversion - defaults to UPPER + $case = is_bool($ADODB_QUOTE_FIELDNAMES) ? 'UPPER' : $ADODB_QUOTE_FIELDNAMES; + switch ($case) { + case 'LOWER': + $fieldName = strtolower($fieldName); + break; + case 'NATIVE': + // Do nothing + break; + case 'UPPER': + case 'BRACKETS': + default: + $fieldName = strtoupper($fieldName); + break; + } - $fieldUpdatedCount = 0; - $arrFields = _array_change_key_case($arrFields); + // Quote field if requested, or necessary (field contains space) + if ($ADODB_QUOTE_FIELDNAMES || strpos($fieldName, ' ') !== false ) { + if ($ADODB_QUOTE_FIELDNAMES === 'BRACKETS') { + return $zthis->leftBracket . $fieldName . $zthis->rightBracket; + } else { + return $zthis->nameQuote . $fieldName . $zthis->nameQuote; + } + } else { + return $fieldName; + } +} - $hasnumeric = isset($rs->fields[0]); - $setFields = ''; +function _adodb_getupdatesql(&$zthis, &$rs, $arrFields, $forceUpdate=false, $force=2) +{ + if (!$rs) { + printf(ADODB_BAD_RS,'GetUpdateSQL'); + return false; + } - // Loop through all of the fields in the recordset - for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) { - // Get the field from the recordset - $field = $rs->FetchField($i); + $fieldUpdatedCount = 0; + if (is_array($arrFields)) + $arrFields = array_change_key_case($arrFields,CASE_UPPER); - // If the recordset field is one - // of the fields passed in then process. - $upperfname = strtoupper($field->name); - if (adodb_key_exists($upperfname,$arrFields,$force)) { + $hasnumeric = isset($rs->fields[0]); + $setFields = ''; - // If the existing field value in the recordset - // is different from the value passed in then - // go ahead and append the field name and new value to - // the update query. + // Loop through all of the fields in the recordset + for ($i=0, $max=$rs->fieldCount(); $i < $max; $i++) { + // Get the field from the recordset + $field = $rs->fetchField($i); - if ($hasnumeric) $val = $rs->fields[$i]; - else if (isset($rs->fields[$upperfname])) $val = $rs->fields[$upperfname]; - else if (isset($rs->fields[$field->name])) $val = $rs->fields[$field->name]; - else if (isset($rs->fields[strtolower($upperfname)])) $val = $rs->fields[strtolower($upperfname)]; - else $val = ''; + // If the recordset field is one + // of the fields passed in then process. + $upperfname = strtoupper($field->name); + if (adodb_key_exists($upperfname, $arrFields, $force)) { + // If the existing field value in the recordset + // is different from the value passed in then + // go ahead and append the field name and new value to + // the update query. - if ($forceUpdate || strcmp($val, $arrFields[$upperfname])) { - // Set the counter for the number of fields that will be updated. - $fieldUpdatedCount++; + if ($hasnumeric) $val = $rs->fields[$i]; + else if (isset($rs->fields[$upperfname])) $val = $rs->fields[$upperfname]; + else if (isset($rs->fields[$field->name])) $val = $rs->fields[$field->name]; + else if (isset($rs->fields[strtolower($upperfname)])) $val = $rs->fields[strtolower($upperfname)]; + else $val = ''; - // Based on the datatype of the field - // Format the value properly for the database - $type = $rs->MetaType($field->type); + if ($forceUpdate || strcmp($val, $arrFields[$upperfname])) { + // Set the counter for the number of fields that will be updated. + $fieldUpdatedCount++; + // Based on the datatype of the field + // Format the value properly for the database + $type = $rs->metaType($field->type); - if ($type == 'null') { - $type = 'C'; - } + if ($type == 'null') { + $type = 'C'; + } - if ((strpos($upperfname,' ') !== false) || ($ADODB_QUOTE_FIELDNAMES)) { - switch ($ADODB_QUOTE_FIELDNAMES) { - case 'LOWER': - $fnameq = $zthis->nameQuote.strtolower($field->name).$zthis->nameQuote;break; - case 'NATIVE': - $fnameq = $zthis->nameQuote.$field->name.$zthis->nameQuote;break; - case 'UPPER': - default: - $fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;break; - } - } else - $fnameq = $upperfname; + $fnameq = _adodb_quote_fieldname($zthis, $field->name); - //********************************************************// - if (is_null($arrFields[$upperfname]) + //********************************************************// + if (is_null($arrFields[$upperfname]) || (empty($arrFields[$upperfname]) && strlen($arrFields[$upperfname]) == 0) - || $arrFields[$upperfname] === $zthis->null2null - ) - { - switch ($force) { + || $arrFields[$upperfname] === $zthis->null2null + ) { - //case 0: - // //Ignore empty values. This is allready handled in "adodb_key_exists" function. - //break; + switch ($force) { - case 1: - //Set null - $setFields .= $field->name . " = null, "; - break; + //case 0: + // // Ignore empty values. This is already handled in "adodb_key_exists" function. + // break; + + case 1: + // set null + $setFields .= $fnameq . " = null, "; + break; + + case 2: + // set empty + $arrFields[$upperfname] = ""; + $setFields .= _adodb_column_sql($zthis, 'U', $type, $upperfname, $fnameq, $arrFields); + break; - case 2: - //Set empty - $arrFields[$upperfname] = ""; - $setFields .= _adodb_column_sql($zthis, 'U', $type, $upperfname, $fnameq,$arrFields, $magicq); - break; default: - case 3: - //Set the value that was given in array, so you can give both null and empty values - if (is_null($arrFields[$upperfname]) || $arrFields[$upperfname] === $zthis->null2null) { - $setFields .= $field->name . " = null, "; - } else { - $setFields .= _adodb_column_sql($zthis, 'U', $type, $upperfname, $fnameq,$arrFields, $magicq); - } - break; - } - //********************************************************// - } else { - //we do this so each driver can customize the sql for - //DB specific column types. - //Oracle needs BLOB types to be handled with a returning clause - //postgres has special needs as well - $setFields .= _adodb_column_sql($zthis, 'U', $type, $upperfname, $fnameq, - $arrFields, $magicq); + case 3: + // set the value that was given in array, so you can give both null and empty values + if (is_null($arrFields[$upperfname]) || $arrFields[$upperfname] === $zthis->null2null) { + $setFields .= $fnameq . " = null, "; + } else { + $setFields .= _adodb_column_sql($zthis, 'U', $type, $upperfname, $fnameq, $arrFields); + } + break; + + case ADODB_FORCE_NULL_AND_ZERO: + + switch ($type) { + case 'N': + case 'I': + case 'L': + $setFields .= $fnameq . ' = 0, '; + break; + default: + $setFields .= $fnameq . ' = null, '; + break; + } + break; + } + //********************************************************// + } else { + // we do this so each driver can customize the sql for + // DB specific column types. + // Oracle needs BLOB types to be handled with a returning clause + // postgres has special needs as well + $setFields .= _adodb_column_sql($zthis, 'U', $type, $upperfname, $fnameq, $arrFields); } } } + } - // If there were any modified fields then build the rest of the update query. - if ($fieldUpdatedCount > 0 || $forceUpdate) { - // Get the table name from the existing query. - if (!empty($rs->tableName)) $tableName = $rs->tableName; - else { - preg_match("/FROM\s+".ADODB_TABLE_REGEX."/is", $rs->sql, $tableName); - $tableName = $tableName[1]; - } - // Get the full where clause excluding the word "WHERE" from - // the existing query. - preg_match('/\sWHERE\s(.*)/is', $rs->sql, $whereClause); - - $discard = false; - // not a good hack, improvements? - if ($whereClause) { - #var_dump($whereClause); - if (preg_match('/\s(ORDER\s.*)/is', $whereClause[1], $discard)); - else if (preg_match('/\s(LIMIT\s.*)/is', $whereClause[1], $discard)); - else if (preg_match('/\s(FOR UPDATE.*)/is', $whereClause[1], $discard)); - else preg_match('/\s.*(\) WHERE .*)/is', $whereClause[1], $discard); # see http://sourceforge.net/tracker/index.php?func=detail&aid=1379638&group_id=42718&atid=433976 - } else - $whereClause = array(false,false); + // If there were any modified fields then build the rest of the update query. + if ($fieldUpdatedCount > 0 || $forceUpdate) { + // Get the table name from the existing query. + if (!empty($rs->tableName)) { + $tableName = $rs->tableName; + } else { + preg_match("/FROM\s+".ADODB_TABLE_REGEX."/is", $rs->sql, $tableName); + $tableName = $tableName[1]; + } - if ($discard) - $whereClause[1] = substr($whereClause[1], 0, strlen($whereClause[1]) - strlen($discard[1])); + // Get the full where clause excluding the word "WHERE" from the existing query. + preg_match('/\sWHERE\s(.*)/is', $rs->sql, $whereClause); - $sql = 'UPDATE '.$tableName.' SET '.substr($setFields, 0, -2); - if (strlen($whereClause[1]) > 0) - $sql .= ' WHERE '.$whereClause[1]; + $discard = false; + // not a good hack, improvements? + if ($whereClause) { + #var_dump($whereClause); + if (preg_match('/\s(ORDER\s.*)/is', $whereClause[1], $discard)); + else if (preg_match('/\s(LIMIT\s.*)/is', $whereClause[1], $discard)); + else if (preg_match('/\s(FOR UPDATE.*)/is', $whereClause[1], $discard)); + else preg_match('/\s.*(\) WHERE .*)/is', $whereClause[1], $discard); # see https://sourceforge.net/p/adodb/bugs/37/ + } else { + $whereClause = array(false, false); + } - return $sql; + if ($discard) { + $whereClause[1] = substr($whereClause[1], 0, strlen($whereClause[1]) - strlen($discard[1])); + } - } else { - return false; + $sql = 'UPDATE '.$tableName.' SET '.substr($setFields, 0, -2); + if (strlen($whereClause[1]) > 0) { + $sql .= ' WHERE '.$whereClause[1]; + } + return $sql; + } else { + return false; } } @@ -791,10 +870,10 @@ function adodb_key_exists($key, &$arr,$force=2) return (!empty($arr[$key])) || (isset($arr[$key]) && strlen($arr[$key])>0); } - if (isset($arr[$key])) return true; + if (isset($arr[$key])) + return true; ## null check below - if (ADODB_PHPVER >= 0x4010) return array_key_exists($key,$arr); - return false; + return array_key_exists($key,$arr); } /** @@ -804,18 +883,18 @@ function adodb_key_exists($key, &$arr,$force=2) * * */ -function _adodb_getinsertsql(&$zthis,&$rs,$arrFields,$magicq=false,$force=2) +function _adodb_getinsertsql(&$zthis, &$rs, $arrFields, $force=2) { static $cacheRS = false; static $cacheSig = 0; static $cacheCols; - global $ADODB_QUOTE_FIELDNAMES; $tableName = ''; $values = ''; $fields = ''; $recordSet = null; - $arrFields = _array_change_key_case($arrFields); + if (is_array($arrFields)) + $arrFields = array_change_key_case($arrFields,CASE_UPPER); $fieldInsertedCount = 0; if (is_string($rs)) { @@ -859,19 +938,7 @@ static $cacheCols; $upperfname = strtoupper($field->name); if (adodb_key_exists($upperfname,$arrFields,$force)) { $bad = false; - if ((strpos($upperfname,' ') !== false) || ($ADODB_QUOTE_FIELDNAMES)) { - switch ($ADODB_QUOTE_FIELDNAMES) { - case 'LOWER': - $fnameq = $zthis->nameQuote.strtolower($field->name).$zthis->nameQuote;break; - case 'NATIVE': - $fnameq = $zthis->nameQuote.$field->name.$zthis->nameQuote;break; - case 'UPPER': - default: - $fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;break; - } - } else - $fnameq = $upperfname; - + $fnameq = _adodb_quote_fieldname($zthis, $field->name); $type = $recordSet->MetaType($field->type); /********************************************************/ @@ -882,29 +949,44 @@ static $cacheCols; { switch ($force) { - case 0: // we must always set null if missing + case ADODB_FORCE_IGNORE: // we must always set null if missing $bad = true; break; - case 1: + case ADODB_FORCE_NULL: $values .= "null, "; break; - case 2: + case ADODB_FORCE_EMPTY: //Set empty $arrFields[$upperfname] = ""; - $values .= _adodb_column_sql($zthis, 'I', $type, $upperfname, $fnameq,$arrFields, $magicq); + $values .= _adodb_column_sql($zthis, 'I', $type, $upperfname, $fnameq, $arrFields); break; default: - case 3: + case ADODB_FORCE_VALUE: //Set the value that was given in array, so you can give both null and empty values if (is_null($arrFields[$upperfname]) || $arrFields[$upperfname] === $zthis->null2null) { $values .= "null, "; } else { - $values .= _adodb_column_sql($zthis, 'I', $type, $upperfname, $fnameq, $arrFields, $magicq); + $values .= _adodb_column_sql($zthis, 'I', $type, $upperfname, $fnameq, $arrFields); } break; + + case ADODB_FORCE_NULL_AND_ZERO: + switch ($type) + { + case 'N': + case 'I': + case 'L': + $values .= '0, '; + break; + default: + $values .= "null, "; + break; + } + break; + } // switch /*********************************************************/ @@ -913,8 +995,7 @@ static $cacheCols; //DB specific column types. //Oracle needs BLOB types to be handled with a returning clause //postgres has special needs as well - $values .= _adodb_column_sql($zthis, 'I', $type, $upperfname, $fnameq, - $arrFields, $magicq); + $values .= _adodb_column_sql($zthis, 'I', $type, $upperfname, $fnameq, $arrFields); } if ($bad) continue; @@ -965,7 +1046,7 @@ static $cacheCols; * @return string * */ -function _adodb_column_sql_oci8(&$zthis,$action, $type, $fname, $fnameq, $arrFields, $magicq) +function _adodb_column_sql_oci8(&$zthis,$action, $type, $fname, $fnameq, $arrFields) { $sql = ''; @@ -997,7 +1078,7 @@ function _adodb_column_sql_oci8(&$zthis,$action, $type, $fname, $fnameq, $arrFie } else { //this is to maintain compatibility //with older adodb versions. - $sql = _adodb_column_sql($zthis, $action, $type, $fname, $fnameq, $arrFields, $magicq,false); + $sql = _adodb_column_sql($zthis, $action, $type, $fname, $fnameq, $arrFields, false); } break; @@ -1020,19 +1101,19 @@ function _adodb_column_sql_oci8(&$zthis,$action, $type, $fname, $fnameq, $arrFie } else { //this is to maintain compatibility //with older adodb versions. - $sql = _adodb_column_sql($zthis, $action, $type, $fname, $fnameq, $arrFields, $magicq,false); + $sql = _adodb_column_sql($zthis, $action, $type, $fname, $fnameq, $arrFields, false); } break; default: - $sql = _adodb_column_sql($zthis, $action, $type, $fname, $fnameq, $arrFields, $magicq,false); + $sql = _adodb_column_sql($zthis, $action, $type, $fname, $fnameq, $arrFields, false); break; } return $sql; } -function _adodb_column_sql(&$zthis, $action, $type, $fname, $fnameq, $arrFields, $magicq, $recurse=true) +function _adodb_column_sql(&$zthis, $action, $type, $fname, $fnameq, $arrFields, $recurse=true) { if ($recurse) { @@ -1041,7 +1122,7 @@ function _adodb_column_sql(&$zthis, $action, $type, $fname, $fnameq, $arrFields, if ($type == 'L') $type = 'C'; break; case 'oci8': - return _adodb_column_sql_oci8($zthis, $action, $type, $fname, $fnameq, $arrFields, $magicq); + return _adodb_column_sql_oci8($zthis, $action, $type, $fname, $fnameq, $arrFields); } } @@ -1050,7 +1131,7 @@ function _adodb_column_sql(&$zthis, $action, $type, $fname, $fnameq, $arrFields, case "C": case "X": case 'B': - $val = $zthis->qstr($arrFields[$fname],$magicq); + $val = $zthis->qstr($arrFields[$fname]); break; case "D": @@ -1080,9 +1161,7 @@ function _adodb_column_sql(&$zthis, $action, $type, $fname, $fnameq, $arrFields, if ($action == 'I') return $val . ", "; - return $fnameq . "=" . $val . ", "; - } @@ -1094,8 +1173,16 @@ function _adodb_debug_execute(&$zthis, $sql, $inputarr) foreach($inputarr as $kk=>$vv) { if (is_string($vv) && strlen($vv)>64) $vv = substr($vv,0,64).'...'; if (is_null($vv)) $ss .= "($kk=>null) "; - else $ss .= "($kk=>'$vv') "; + else + { + if (is_array($vv)) + { + $vv = sprintf("Array Of Values: [%s]", implode(',',$vv)); + } + $ss .= "($kk=>'$vv') "; + } } + $ss = "[ $ss ]"; } $sqlTxt = is_array($sql) ? $sql[0] : $sql; diff --git a/libraries/adodb/adodb-loadbalancer.inc.php b/libraries/adodb/adodb-loadbalancer.inc.php new file mode 100644 index 000000000..2e4f3928d --- /dev/null +++ b/libraries/adodb/adodb-loadbalancer.inc.php @@ -0,0 +1,773 @@ +<?php +/** + * ADOdb Load Balancer + * + * ADOdbLoadBalancer is a class that allows the user to do read/write splitting + * and load balancing across multiple servers. It can handle and load balance + * any number of write capable (AKA: master) or readonly (AKA: slave) connections, + * including dealing with connection failures and retrying queries on a different + * connection instead. + * + * 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 2016 Mike Benoit and the ADOdb community + */ + +/** + * Class ADOdbLoadBalancer + */ +class ADOdbLoadBalancer +{ + /** + * @var bool Once a write or readonly connection is made, stick to that connection for the entire request. + */ + public $enable_sticky_sessions = true; + + + /** + * @var bool|array All connections to each database. + */ + protected $connections = false; + + /** + * @var bool|array Just connections to the write capable database. + */ + protected $connections_write = false; + + /** + * @var bool|array Just connections to the readonly database. + */ + protected $connections_readonly = false; + + /** + * @var array Counts of all connections and their types. + */ + protected $total_connections = array('all' => 0, 'write' => 0, 'readonly' => 0); + + /** + * @var array Weights of all connections for each type. + */ + protected $total_connection_weights = array('all' => 0, 'write' => 0, 'readonly' => 0); + + /** + * @var bool When in transactions, always use this connection. + */ + protected $pinned_connection_id = false; + + /** + * @var array Last connection_id for each database type. + */ + protected $last_connection_id = array('write' => false, 'readonly' => false, 'all' => false); + + /** + * @var bool Session variables that must be maintained across all connections, ie: SET TIME ZONE. + */ + protected $session_variables = false; + + /** + * @var bool Called immediately after connecting to any DB. + */ + protected $user_defined_session_init_sql = false; + + + /** + * Defines SQL queries that are executed each time a new database connection is established. + * + * @param $sql + * @return bool + */ + public function setSessionInitSQL($sql) + { + $this->user_defined_session_init_sql[] = $sql; + + return true; + } + + /** + * Adds a new database connection to the pool, but no actual connection is made until its needed. + * + * @param $obj + * @return bool + * @throws Exception + */ + public function addConnection($obj) + { + if ($obj instanceof ADOdbLoadBalancerConnection) { + $this->connections[] = $obj; + end($this->connections); + $i = key($this->connections); + + $this->total_connections[$obj->type]++; + $this->total_connections['all']++; + + $this->total_connection_weights[$obj->type] += abs($obj->weight); + $this->total_connection_weights['all'] += abs($obj->weight); + + if ($obj->type == 'write') { + $this->connections_write[] = $i; + } else { + $this->connections_readonly[] = $i; + } + + return true; + } + + throw new Exception('Connection object is not an instance of ADOdbLoadBalancerConnection'); + } + + /** + * Removes a database connection from the pool. + * + * @param $i + * @return bool + */ + public function removeConnection($i) + { + if (isset($this->connections[$i])) { + $obj = $this->connections[ $i ]; + + $this->total_connections[ $obj->type ]--; + $this->total_connections['all']--; + + $this->total_connection_weights[ $obj->type ] -= abs($obj->weight); + $this->total_connection_weights['all'] -= abs($obj->weight); + + if ($obj->type == 'write') { + unset($this->connections_write[array_search($i, $this->connections_write)]); + // Reindex array. + $this->connections_write = array_values($this->connections_write); + } else { + unset($this->connections_readonly[array_search($i, $this->connections_readonly)]); + // Reindex array. + $this->connections_readonly = array_values($this->connections_readonly); + } + + // Remove any sticky connections as well. + if ($this->last_connection_id[$obj->type] == $i) { + $this->last_connection_id[$obj->type] = false; + } + + unset($this->connections[$i]); + + return true; + } + + return false; + } + + /** + * Returns a database connection of the specified type. + * + * Takes into account the connection weight for load balancing. + * + * @param string $type Type of database connection, either: 'write' capable or 'readonly' + * @return bool|int|string + */ + private function getConnectionByWeight($type) + { + if ($type == 'readonly') { + $total_weight = $this->total_connection_weights['all']; + } else { + $total_weight = $this->total_connection_weights['write']; + } + + $i = false; + if (is_array($this->connections)) { + $n = 0; + $num = mt_rand(0, $total_weight); + foreach ($this->connections as $i => $connection_obj) { + if ($connection_obj->weight > 0 && ($type == 'readonly' || $connection_obj->type == 'write')) { + $n += $connection_obj->weight; + if ($n >= $num) { + break; + } + } + } + } + + return $i; + } + + /** + * Returns the proper database connection when taking into account sticky sessions and load balancing. + * + * @param $type + * @return bool|int|mixed|string + */ + public function getLoadBalancedConnection($type) + { + if ($this->total_connections == 0) { + $connection_id = 0; + } else { + if ($this->enable_sticky_sessions == true && $this->last_connection_id[$type] !== false) { + $connection_id = $this->last_connection_id[$type]; + } else { + if ($type == 'write' && $this->total_connections['write'] == 1) { + $connection_id = $this->connections_write[0]; + } else { + $connection_id = $this->getConnectionByWeight($type); + } + } + } + + return $connection_id; + } + + /** + * Returns the ADODB connection object by connection_id. + * + * Ensures that it's connected and the session variables are executed. + * + * @param $connection_id + * @return bool|ADOConnection + * @throws Exception + */ + private function _getConnection($connection_id) + { + if (isset($this->connections[$connection_id])) { + $connection_obj = $this->connections[$connection_id]; + /** @var ADOConnection $adodb_obj */ + $adodb_obj = $connection_obj->getADOdbObject(); + if (is_object($adodb_obj) && $adodb_obj->_connectionID == false) { + try { + if ($connection_obj->persistent_connection == true) { + $adodb_obj->Pconnect( + $connection_obj->host, + $connection_obj->user, + $connection_obj->password, + $connection_obj->database + ); + } else { + $adodb_obj->Connect( + $connection_obj->host, + $connection_obj->user, + $connection_obj->password, + $connection_obj->database + ); + } + } catch (Exception $e) { + // Connection error, see if there are other connections to try still. + throw $e; // No connections left, reThrow exception so application can catch it. + } + + if (is_array($this->user_defined_session_init_sql)) { + foreach ($this->user_defined_session_init_sql as $session_init_sql) { + $adodb_obj->Execute($session_init_sql); + } + } + $this->executeSessionVariables($adodb_obj); + } + + return $adodb_obj; + } else { + throw new Exception('Unable to return Connection object...'); + } + } + + /** + * Returns the ADODB connection object by database type. + * + * Ensures that it's connected and the session variables are executed. + * + * @param string $type + * @param null $pin_connection + * @return ADOConnection|bool + * @throws Exception + */ + public function getConnection($type = 'write', $pin_connection = null) + { + while (($type == 'write' && $this->total_connections['write'] > 0) + || ($type == 'readonly' && $this->total_connections['all'] > 0) + ) { + if ($this->pinned_connection_id !== false) { + $connection_id = $this->pinned_connection_id; + } else { + $connection_id = $this->getLoadBalancedConnection($type); + } + + if ($connection_id !== false) { + try { + $adodb_obj = $this->_getConnection($connection_id); + // $connection_obj = $this->connections[$connection_id]; + break; + } catch (Exception $e) { + // Connection error, see if there are other connections to try still. + $this->removeConnection($connection_id); + if ( ($type == 'write' && $this->total_connections['write'] == 0) + || ($type == 'readonly' && $this->total_connections['all'] == 0) + ) { + throw $e; + } + } + } else { + throw new Exception('Connection ID is invalid!'); + } + } + + $this->last_connection_id[$type] = $connection_id; + + if ($pin_connection === true) { + $this->pinned_connection_id = $connection_id; + } elseif ($pin_connection === false && $adodb_obj->transOff <= 1) { + // UnPin connection only if we are 1 level deep in a transaction. + $this->pinned_connection_id = false; + + // When unpinning connection, reset last_connection_id so readonly + // queries don't get stuck on the write capable connection. + $this->last_connection_id['write'] = false; + $this->last_connection_id['readonly'] = false; + } + + return $adodb_obj; + } + + /** + * This is a hack to work around pass by reference error. + * + * Parameter 1 to ADOConnection::GetInsertSQL() expected to be a reference, + * value given in adodb-loadbalancer.inc.php on line 83 + * + * @param $arr + * @return array + */ + private function makeValuesReferenced($arr) + { + $refs = array(); + + foreach ($arr as $key => $value) { + $refs[$key] = &$arr[$key]; + } + + return $refs; + } + + /** + * Allow setting session variables that are maintained across connections. + * + * Its important that these are set using name/value, so it can determine + * if the same variable is set multiple times causing bloat/clutter when + * new connections are established. For example if the time_zone is set to + * many different ones through the course of a single connection, a new + * connection should only set it to the most recent value. + * + * @param $name + * @param $value + * @param bool $execute_immediately + * @return array|bool|mixed + * @throws Exception + */ + public function setSessionVariable($name, $value, $execute_immediately = true) + { + $this->session_variables[$name] = $value; + + if ($execute_immediately == true) { + return $this->executeSessionVariables(); + } else { + return true; + } + } + + /** + * Executes the session variables on a given ADODB object. + * + * @param ADOConnection|bool $adodb_obj + * @return array|bool|mixed + * @throws Exception + */ + private function executeSessionVariables($adodb_obj = false) + { + if (is_array($this->session_variables)) { + $sql = ''; + foreach ($this->session_variables as $name => $value) { + // $sql .= 'SET SESSION '. $name .' '. $value; + // MySQL uses: SET SESSION foo_bar='foo' + // PGSQL uses: SET SESSION foo_bar 'foo' + // So leave it up to the user to pass the proper value with '=' if needed. + // This may be a candidate to move into ADOdb proper. + $sql .= 'SET SESSION ' . $name . ' ' . $value; + } + + if ($adodb_obj !== false) { + return $adodb_obj->Execute($sql); + } else { + return $this->ClusterExecute($sql); + } + } + + return false; + } + + /** + * Executes the same SQL QUERY on the entire cluster of connections. + * Would be used for things like SET SESSION TIME ZONE calls and such. + * + * @param $sql + * @param bool $inputarr + * @param bool $return_all_results + * @param bool $existing_connections_only + * @return array|bool|mixed + * @throws Exception + */ + public function clusterExecute( + $sql, + $inputarr = false, + $return_all_results = false, + $existing_connections_only = true + ) { + if (is_array($this->connections) && count($this->connections) > 0) { + foreach ($this->connections as $key => $connection_obj) { + if ($existing_connections_only == false + || ($existing_connections_only == true + && $connection_obj->getADOdbObject()->_connectionID !== false + ) + ) { + $adodb_obj = $this->_getConnection($key); + if (is_object($adodb_obj)) { + $result_arr[] = $adodb_obj->Execute($sql, $inputarr); + } + } + } + + if (isset($result_arr) && $return_all_results == true) { + return $result_arr; + } else { + // Loop through all results checking to see if they match, if they do return the first one + // otherwise return an array of all results. + if (isset($result_arr)) { + foreach ($result_arr as $result) { + if ($result == false) { + return $result_arr; + } + } + + return $result_arr[0]; + } else { + // When using lazy connections, there are cases where + // setSessionVariable() is called early on, but there are + // no connections to execute the queries on yet. + // This captures that case and forces a RETURN TRUE to occur. + // As likely the queries will be executed as soon as a + // connection is established. + return true; + } + } + } + + return false; + } + + /** + * Determines if a SQL query is read-only or not. + * + * @param string $sql SQL Query to test. + * @return bool + */ + public function isReadOnlyQuery($sql) + { + if ( stripos($sql, 'SELECT') === 0 + && stripos($sql, 'FOR UPDATE') === false + && stripos($sql, ' INTO ') === false + && stripos($sql, 'LOCK IN') === false + ) { + return true; + } + + return false; + } + + /** + * Use this instead of __call() as it significantly reduces the overhead of call_user_func_array(). + * + * @param $sql + * @param bool $inputarr + * @return array|bool|mixed + * @throws Exception + */ + public function execute($sql, $inputarr = false) + { + $type = 'write'; + $pin_connection = null; + + // Prevent leading spaces from causing isReadOnlyQuery/stripos from failing. + $sql = trim($sql); + + // SELECT queries that can write and therefore must be run on a write capable connection. + // SELECT ... FOR UPDATE; + // SELECT ... INTO ... + // SELECT .. LOCK IN ... (MYSQL) + if ($this->isReadOnlyQuery($sql) == true) { + $type = 'readonly'; + } elseif (stripos($sql, 'SET') === 0) { + // SET SQL statements should likely use setSessionVariable() instead, + // so state is properly maintained across connections, especially when they are lazily created. + return $this->ClusterExecute($sql, $inputarr); + } + + $adodb_obj = $this->getConnection($type, $pin_connection); + if ($adodb_obj !== false) { + return $adodb_obj->Execute($sql, $inputarr); + } + + return false; + } + + /** + * Magic method to intercept method and callback to the proper ADODB object for write/readonly connections. + * + * @param string $method ADODB method to call. + * @param array $args Arguments to the ADODB method. + * @return bool|mixed + * @throws Exception + */ + public function __call($method, $args) + { + $type = 'write'; + $pin_connection = null; + + // Intercept specific methods to determine if they are read-only or not. + $method = strtolower($method); + switch ($method) { + // case 'execute': // This is the direct overloaded function above instead. + case 'getone': + case 'getrow': + case 'getall': + case 'getcol': + case 'getassoc': + case 'selectlimit': + if ($this->isReadOnlyQuery(trim($args[0])) == true) { + $type = 'readonly'; + } + break; + case 'cachegetone': + case 'cachegetrow': + case 'cachegetall': + case 'cachegetcol': + case 'cachegetassoc': + case 'cacheexecute': + case 'cacheselect': + case 'pageexecute': + case 'cachepageexecute': + $type = 'readonly'; + break; + // case 'ignoreerrors': + // // When ignoreerrors is called, PIN to the connection until its called again. + // if (!isset($args[0]) || (isset($args[0]) && $args[0] == FALSE)) { + // $pin_connection = TRUE; + // } else { + // $pin_connection = FALSE; + // } + // break; + + // Manual transactions + case 'begintrans': + case 'settransactionmode': + $pin_connection = true; + break; + case 'rollbacktrans': + case 'committrans': + $pin_connection = false; + break; + // Smart transactions + case 'starttrans': + $pin_connection = true; + break; + case 'completetrans': + case 'failtrans': + // getConnection() will only unpin the transaction if we're exiting the last nested transaction + $pin_connection = false; + break; + + // Functions that don't require any connection and therefore + // shouldn't force a connection be established before they run. + case 'qstr': + case 'escape': + case 'binddate': + case 'bindtimestamp': + case 'setfetchmode': + $type = false; // No connection necessary. + break; + + // Default to assuming write connection is required to be on the safe side. + default: + break; + } + + if ($type === false) { + if (is_array($this->connections) && count($this->connections) > 0) { + foreach ($this->connections as $key => $connection_obj) { + $adodb_obj = $connection_obj->getADOdbObject(); + return call_user_func_array(array($adodb_obj, $method), $this->makeValuesReferenced($args)); // Just makes the function call on the first object. + } + } + } else { + $adodb_obj = $this->getConnection($type, $pin_connection); + if (is_object($adodb_obj)) { + $result = call_user_func_array(array($adodb_obj, $method), $this->makeValuesReferenced($args)); + + return $result; + } + } + return false; + } + + /** + * Magic method to proxy property getter calls back to the proper ADODB object currently in use. + * + * @param $property + * @return mixed + * @throws Exception + */ + public function __get($property) + { + if (is_array($this->connections) && count($this->connections) > 0) { + foreach ($this->connections as $key => $connection_obj) { + // Just returns the property from the first object. + return $connection_obj->getADOdbObject()->$property; + } + } + + return false; + } + + /** + * Magic method to proxy property setter calls back to the proper ADODB object currently in use. + * + * @param $property + * @param $value + * @return mixed + * @throws Exception + */ + public function __set($property, $value) + { + // Special function to set object properties on all objects + // without initiating a connection to the database. + if (is_array($this->connections) && count($this->connections) > 0) { + foreach ($this->connections as $key => $connection_obj) { + $connection_obj->getADOdbObject()->$property = $value; + } + + return true; + } + + return false; + } + + /** + * Override the __clone() magic method. + */ + private function __clone() + { + } +} + +/** + * Class ADOdbLoadBalancerConnection + */ +class ADOdbLoadBalancerConnection +{ + /** + * @var bool ADOdb drive name. + */ + protected $driver = false; + + /** + * @var bool ADODB object. + */ + protected $adodb_obj = false; + + /** + * @var string Type of connection, either 'write' capable or 'readonly' + */ + public $type = 'write'; + + /** + * @var int Weight of connection, lower receives less queries, higher receives more queries. + */ + public $weight = 1; + + /** + * @var bool Determines if the connection persistent. + */ + public $persistent_connection = false; + + /** + * @var string Database connection host + */ + public $host = ''; + + /** + * @var string Database connection user + */ + public $user = ''; + + /** + * @var string Database connection password + */ + public $password = ''; + + /** + * @var string Database connection database name + */ + public $database = ''; + + /** + * ADOdbLoadBalancerConnection constructor to setup the ADODB object. + * + * @param $driver + * @param string $type + * @param int $weight + * @param bool $persistent_connection + * @param string $argHostname + * @param string $argUsername + * @param string $argPassword + * @param string $argDatabaseName + */ + public function __construct( + $driver, + $type = 'write', + $weight = 1, + $persistent_connection = false, + $argHostname = '', + $argUsername = '', + $argPassword = '', + $argDatabaseName = '' + ) { + if ($type !== 'write' && $type !== 'readonly') { + return false; + } + + $this->adodb_obj = ADONewConnection($driver); + + $this->type = $type; + $this->weight = $weight; + $this->persistent_connection = $persistent_connection; + + $this->host = $argHostname; + $this->user = $argUsername; + $this->password = $argPassword; + $this->database = $argDatabaseName; + + return true; + } + + /** + * Returns the ADODB object for this connection. + * + * @return bool + */ + public function getADOdbObject() + { + return $this->adodb_obj; + } +} diff --git a/libraries/adodb/adodb-memcache.lib.inc.php b/libraries/adodb/adodb-memcache.lib.inc.php index 42d2be62e..7f110e749 100644 --- a/libraries/adodb/adodb-memcache.lib.inc.php +++ b/libraries/adodb/adodb-memcache.lib.inc.php @@ -1,4 +1,23 @@ <?php +/** + * Memory caching. + * + * 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(); @@ -9,37 +28,14 @@ $ADODB_INCLUDED_MEMCACHE = 1; global $ADODB_INCLUDED_CSV; if (empty($ADODB_INCLUDED_CSV)) include_once(ADODB_DIR.'/adodb-csvlib.inc.php'); -/* - - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. See License.txt. - Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - -Usage: - -$db = NewADOConnection($driver); -$db->memCache = true; /// should we use memCache instead of caching in files -$db->memCacheHost = array($ip1, $ip2, $ip3); -$db->memCachePort = 11211; /// this is default memCache port -$db->memCacheCompress = false; /// Use 'true' to store the item compressed (uses zlib) - -$db->Connect(...); -$db->CacheExecute($sql); - - Note the memcache class is shared by all connections, is created during the first call to Connect/PConnect. - - Class instance is stored in $ADODB_CACHE -*/ - class ADODB_Cache_MemCache { var $createdir = false; // create caching directory structure? + // $library will be populated with the proper library on connect + // and is used later when there are differences in specific calls + // between memcache and memcached + var $library = false; + //----------------------------- // memcache specific variables @@ -60,18 +56,23 @@ $db->CacheExecute($sql); // implement as lazy connection. The connection only occurs on CacheExecute call function connect(&$err) { - if (!function_exists('memcache_pconnect')) { - $err = 'Memcache module PECL extension not found!'; + // do we have memcache or memcached? + if (class_exists('Memcache')) { + $this->library='Memcache'; + $memcache = new MemCache; + } elseif (class_exists('Memcached')) { + $this->library='Memcached'; + $memcache = new MemCached; + } else { + $err = 'Neither the Memcache nor Memcached PECL extensions were found!'; return false; } - $memcache = new MemCache; - if (!is_array($this->hosts)) $this->hosts = array($this->hosts); $failcnt = 0; foreach($this->hosts as $host) { - if (!@$memcache->addServer($host,$this->port,true)) { + if (!@$memcache->addServer($host,$this->port)) { $failcnt += 1; } } @@ -93,8 +94,25 @@ $db->CacheExecute($sql); } if (!$this->_memcache) return false; - if (!$this->_memcache->set($filename, $contents, $this->compress ? MEMCACHE_COMPRESSED : 0, $secs2cache)) { - if ($debug) ADOConnection::outp(" Failed to save data at the memcached server!<br>\n"); + $failed=false; + switch ($this->library) { + case 'Memcache': + if (!$this->_memcache->set($filename, $contents, $this->compress ? MEMCACHE_COMPRESSED : 0, $secs2cache)) { + $failed=true; + } + break; + case 'Memcached': + if (!$this->_memcache->set($filename, $contents, $secs2cache)) { + $failed=true; + } + break; + default: + $failed=true; + break; + } + + if($failed) { + if ($debug) ADOConnection::outp(" Failed to save data at the memcache server!<br>\n"); return false; } @@ -110,7 +128,7 @@ $db->CacheExecute($sql); $rs = $this->_memcache->get($filename); if (!$rs) { - $err = 'Item with such key doesn\'t exists on the memcached server.'; + $err = 'Item with such key doesn\'t exist on the memcache server.'; return $false; } @@ -176,8 +194,8 @@ $db->CacheExecute($sql); $del = $this->_memcache->delete($filename); if ($debug) - if (!$del) ADOConnection::outp("flushcache: $key entry doesn't exist on memcached server!<br>\n"); - else ADOConnection::outp("flushcache: $key entry flushed from memcached server!<br>\n"); + if (!$del) ADOConnection::outp("flushcache: $key entry doesn't exist on memcache server!<br>\n"); + else ADOConnection::outp("flushcache: $key entry flushed from memcache server!<br>\n"); return $del; } diff --git a/libraries/adodb/adodb-pager.inc.php b/libraries/adodb/adodb-pager.inc.php index fa77d55c7..cfe981d32 100644 --- a/libraries/adodb/adodb-pager.inc.php +++ b/libraries/adodb/adodb-pager.inc.php @@ -1,28 +1,24 @@ <?php +/** + * Recordset pagination with First/Prev/Next/Last links + * + * 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 + */ -/* - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4 for best viewing. - - This class provides recordset pagination with - First/Prev/Next/Last links. - - Feel free to modify this class for your own use as - it is very basic. To learn how to use it, see the - example in adodb/tests/testpaging.php. - - "Pablo Costa" <pablo@cbsp.com.br> implemented Render_PageLinks(). - - Please note, this class is entirely unsupported, - and no free support requests except for bug reports - will be entertained by the author. - -*/ class ADODB_Pager { var $id; // unique id for pager (defaults to 'adodb') var $db; // ADODB connection object @@ -275,7 +271,7 @@ class ADODB_Pager { } //------------------------------------------------------ - // override this to control overall layout and formating + // override this to control overall layout and formatting function RenderLayout($header,$grid,$footer,$attributes='border=1 bgcolor=beige') { echo "<table ".$attributes."><tr><td>", diff --git a/libraries/adodb/adodb-pear.inc.php b/libraries/adodb/adodb-pear.inc.php index c8f09331b..c48ef132d 100644 --- a/libraries/adodb/adodb-pear.inc.php +++ b/libraries/adodb/adodb-pear.inc.php @@ -1,18 +1,25 @@ <?php /** - * @version v5.20.9 21-Dec-2016 - * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - * @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - * Released under both BSD license and Lesser GPL library license. - * Whenever there is any discrepancy between the two licenses, - * the BSD license will take precedence. + * PEAR DB Emulation Layer for ADOdb. * - * Set tabs to 4 for best viewing. + * The following code is modelled on PEAR DB code by Stig Bakken <ssb@fast.no> + * and Tomas V.V.Cox <cox@idecnet.com>. Portions (c)1997-2002 The PHP Group. * - * PEAR DB Emulation Layer for ADODB. + * This file is part of ADOdb, a Database Abstraction Layer library for PHP. * - * The following code is modelled on PEAR DB code by Stig Bakken <ssb@fast.no> | - * and Tomas V.V.Cox <cox@idecnet.com>. Portions (c)1997-2002 The PHP Group. + * @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 */ /* @@ -336,7 +343,7 @@ class DB $parsed['hostspec'] = urldecode($str); } - // Get dabase if any + // Get database if any // $dsn => database if (!empty($dsn)) { $parsed['database'] = $dsn; @@ -358,7 +365,7 @@ class DB */ function assertExtension($name) { - if (!extension_loaded($name)) { + if (function_exists('dl') && !extension_loaded($name)) { $dlext = (strncmp(PHP_OS,'WIN',3) === 0) ? '.dll' : '.so'; @dl($name . $dlext); } diff --git a/libraries/adodb/adodb-perf.inc.php b/libraries/adodb/adodb-perf.inc.php index 69218c6e0..d9d8a9937 100644 --- a/libraries/adodb/adodb-perf.inc.php +++ b/libraries/adodb/adodb-perf.inc.php @@ -1,22 +1,23 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. See License.txt. - Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Library for basic performance monitoring and tuning. - - My apologies if you see code mixed with presentation. The presentation suits - my needs. If you want to separate code from presentation, be my guest. Patches - are welcome. - -*/ +/** + * performance monitoring and tuning. + * + * 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 + */ if (!defined('ADODB_DIR')) include_once(dirname(__FILE__).'/adodb.inc.php'); include_once(ADODB_DIR.'/tohtml.inc.php'); @@ -147,7 +148,7 @@ function adodb_log_sql(&$connx,$sql,$inputarr) if (empty($d)) $d = date("'Y-m-d H:i:s'"); if ($conn->dataProvider == 'oci8' && $dbT != 'oci8po') { $isql = "insert into $perf_table values($d,:b,:c,:d,:e,:f)"; - } else if ($dbT == 'odbc_mssql' || $dbT == 'informix' || strncmp($dbT,'odbtp',4)==0) { + } else if ($dbT == 'mssqlnative' || $dbT == 'odbc_mssql' || $dbT == 'informix' || strncmp($dbT,'odbtp',4)==0) { $timer = $arr['f']; if ($dbT == 'informix') $sql2 = substr($sql2,0,230); @@ -166,7 +167,13 @@ function adodb_log_sql(&$connx,$sql,$inputarr) global $ADODB_PERF_MIN; if ($errN != 0 || $time >= $ADODB_PERF_MIN) { + if($conn instanceof ADODB_mysqli && $conn->_queryID) { + mysqli_free_result($conn->_queryID); + } $ok = $conn->Execute($isql,$arr); + if($conn instanceof ADODB_mysqli && $conn->_queryID){ + mysqli_free_result($conn->_queryID); + } } else $ok = true; @@ -226,7 +233,7 @@ class adodb_perf { var $cliFormat = "%32s => %s \r\n"; var $sql1 = 'sql1'; // used for casting sql1 to text for mssql var $explain = true; - var $helpurl = '<a href="http://adodb.sourceforge.net/docs-adodb.htm#logsql">LogSQL help</a>'; + var $helpurl = '<a href="https://adodb.org/dokuwiki/doku.php?id=v5:performance:logsql">LogSQL help</a>'; var $createTableSQL = false; var $maxLength = 2000; @@ -260,12 +267,6 @@ processes 69293 // Algorithm is taken from // http://social.technet.microsoft.com/Forums/en-US/winservergen/thread/414b0e1b-499c-411e-8a02-6a12e339c0f1/ if (strncmp(PHP_OS,'WIN',3)==0) { - if (PHP_VERSION == '5.0.0') return false; - if (PHP_VERSION == '5.0.1') return false; - if (PHP_VERSION == '5.0.2') return false; - if (PHP_VERSION == '5.0.3') return false; - if (PHP_VERSION == '4.3.10') return false; # see http://bugs.php.net/bug.php?id=31737 - static $FAIL = false; if ($FAIL) return false; @@ -590,7 +591,7 @@ Committed_AS: 348732 kB } /* - Raw function returning array of poll paramters + Raw function returning array of poll parameters */ function PollParameters() { @@ -691,12 +692,6 @@ Committed_AS: 348732 kB } $this->conn->LogSQL($savelog); - // magic quotes - - if (isset($_GET['sql']) && get_magic_quotes_gpc()) { - $_GET['sql'] = $_GET['sql'] = str_replace(array("\\'",'\"'),array("'",'"'),$_GET['sql']); - } - if (!isset($_SESSION['ADODB_PERF_SQL'])) $nsql = $_SESSION['ADODB_PERF_SQL'] = 10; else $nsql = $_SESSION['ADODB_PERF_SQL']; @@ -721,7 +716,7 @@ Committed_AS: 348732 kB if (empty($_GET['hidem'])) echo "<table border=1 width=100% bgcolor=lightyellow><tr><td colspan=2> - <b><a href=http://adodb.sourceforge.net/?perf=1>ADOdb</a> Performance Monitor</b> <font size=1>for $app</font></tr><tr><td> + <b><a href=https://adodb.org/dokuwiki/doku.php?id=v5:performance:performance_index>ADOdb</a> Performance Monitor</b> <font size=1>for $app</font></tr><tr><td> <a href=?do=stats><b>Performance Stats</b></a> <a href=?do=viewsql><b>View SQL</b></a> <a href=?do=tables><b>View Tables</b></a> <a href=?do=poll><b>Poll Stats</b></a>", $allowsql ? ' <a href=?do=dosql><b>Run SQL</b></a>' : '', @@ -764,7 +759,6 @@ Committed_AS: 348732 kB echo $this->Tables(); break; } global $ADODB_vers; - echo "<p><div align=center><font size=1>$ADODB_vers Sponsored by <a href=http://phplens.com/>phpLens</a></font></div>"; } /* @@ -953,7 +947,7 @@ Committed_AS: 348732 kB <?php if (!isset($_REQUEST['sql'])) return; - $sql = $this->undomq(trim($sql)); + $sql = trim($sql); if (substr($sql,strlen($sql)-1) === ';') { $print = true; $sqla = $this->SplitSQL($sql); @@ -997,18 +991,6 @@ Committed_AS: 348732 kB return $arr; } - function undomq($m) - { - if (get_magic_quotes_gpc()) { - // undo the damage - $m = str_replace('\\\\','\\',$m); - $m = str_replace('\"','"',$m); - $m = str_replace('\\\'','\'',$m); - } - return $m; -} - - /************************************************************************/ /** diff --git a/libraries/adodb/adodb-php4.inc.php b/libraries/adodb/adodb-php4.inc.php deleted file mode 100644 index 132f25d0a..000000000 --- a/libraries/adodb/adodb-php4.inc.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -/* - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4. -*/ - - -class ADODB_BASE_RS { -} diff --git a/libraries/adodb/adodb-time.inc.php b/libraries/adodb/adodb-time.inc.php index 4d2016c71..cfbdc6a5c 100644 --- a/libraries/adodb/adodb-time.inc.php +++ b/libraries/adodb/adodb-time.inc.php @@ -1,78 +1,67 @@ <?php -/* -ADOdb Date Library, part of the ADOdb abstraction library -Download: http://adodb.sourceforge.net/#download - -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - -PHP native date functions use integer timestamps for computations. -Because of this, dates are restricted to the years 1901-2038 on Unix -and 1970-2038 on Windows due to integer overflow for dates beyond -those years. This library overcomes these limitations by replacing the -native function's signed integers (normally 32-bits) with PHP floating -point numbers (normally 64-bits). - -Dates from 100 A.D. to 3000 A.D. and later -have been tested. The minimum is 100 A.D. as <100 will invoke the -2 => 4 digit year conversion. The maximum is billions of years in the -future, but this is a theoretical limit as the computation of that year -would take too long with the current implementation of adodb_mktime(). - -This library replaces native functions as follows: - -<pre> - getdate() with adodb_getdate() - date() with adodb_date() - gmdate() with adodb_gmdate() - mktime() with adodb_mktime() - gmmktime() with adodb_gmmktime() - strftime() with adodb_strftime() - strftime() with adodb_gmstrftime() -</pre> - -The parameters are identical, except that adodb_date() accepts a subset -of date()'s field formats. Mktime() will convert from local time to GMT, -and date() will convert from GMT to local time, but daylight savings is -not handled currently. - -This library is independant of the rest of ADOdb, and can be used -as standalone code. - -PERFORMANCE - -For high speed, this library uses the native date functions where -possible, and only switches to PHP code when the dates fall outside -the 32-bit signed integer range. - -GREGORIAN CORRECTION - -Pope Gregory shortened October of A.D. 1582 by ten days. Thursday, -October 4, 1582 (Julian) was followed immediately by Friday, October 15, -1582 (Gregorian). - -Since 0.06, we handle this correctly, so: - -adodb_mktime(0,0,0,10,15,1582) - adodb_mktime(0,0,0,10,4,1582) - == 24 * 3600 (1 day) - -============================================================================= - -COPYRIGHT - -(c) 2003-2014 John Lim and released under BSD-style license except for code by -jackbbs, which includes adodb_mktime, adodb_get_gmt_diff, adodb_is_leap_year -and originally found at http://www.php.net/manual/en/function.mktime.php - -============================================================================= - -BUG REPORTS - -These should be posted to the ADOdb forums at - - http://phplens.com/lens/lensforum/topics.php?id=4 +/** + * ADOdb Date Library. + * + * PHP native date functions use integer timestamps for computations. + * Because of this, dates are restricted to the years 1901-2038 on Unix + * and 1970-2038 on Windows due to integer overflow for dates beyond + * those years. This library overcomes these limitations by replacing the + * native function's signed integers (normally 32-bits) with PHP floating + * point numbers (normally 64-bits). + * + * Dates from 100 A.D. to 3000 A.D. and later have been tested. + * The minimum is 100 A.D. as <100 will invoke the 2 => 4 digit year + * conversion. The maximum is billions of years in the future, but this + * is a theoretical limit as the computation of that year would take too + * long with the current implementation of adodb_mktime(). + * + * Replaces native functions as follows: + * - getdate() with adodb_getdate() + * - date() with adodb_date() + * - gmdate() with adodb_gmdate() + * - mktime() with adodb_mktime() + * - gmmktime() with adodb_gmmktime() + * - strftime() with adodb_strftime() + * - strftime() with adodb_gmstrftime() + * + * The parameters are identical, except that adodb_date() accepts a subset + * of date()'s field formats. Mktime() will convert from local time to GMT, + * and date() will convert from GMT to local time, but daylight savings is + * not handled currently. + * + * To improve performance, the native date functions are used whenever + * possible, the library only switches to PHP code when the dates fall outside + * of the 32-bit signed integer range. + * + * This library is independent of the rest of ADOdb, and can be used + * as standalone code. + * + * GREGORIAN CORRECTION + * + * Pope Gregory shortened October of A.D. 1582 by ten days. Thursday, + * October 4, 1582 (Julian) was followed immediately by Friday, October 15, + * 1582 (Gregorian). We handle this correctly, so: + * adodb_mktime(0, 0, 0, 10, 15, 1582) - adodb_mktime(0, 0, 0, 10, 4, 1582) + * == 24 * 3600 (1 day) + * + * 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 2003-2013 John Lim + * @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community + */ +/* ============================================================================= FUNCTION DESCRIPTIONS @@ -267,7 +256,7 @@ Changed adodb_get_gm_diff to use DateTimeZone(). * Now adodb_mktime(0,0,0,24,1,2037) works correctly. - 15 July 2007 0.30 -Added PHP 5.2.0 compatability fixes. +Added PHP 5.2.0 compatibility fixes. * gmtime behaviour for 1970 has changed. We use the actual date if it is between 1970 to 2038 to get the * timezone, otherwise we use the current year as the baseline to retrieve the timezone. * Also the timezone's in php 5.2.* support historical data better, eg. if timezone today was +8, but @@ -347,7 +336,7 @@ January!!!), changed adodb_get_gmt_diff() to ignore daylight savings. - 9 Aug 2003 0.10 Fixed bug with dates after 2038. -See http://phplens.com/lens/lensforum/msgs.php?id=6980 +See PHPLens Issue No: 6980 - 1 July 2003 0.09 Added support for Q (Quarter). @@ -403,8 +392,6 @@ First implementation. */ define('ADODB_DATE_VERSION',0.35); -$ADODB_DATETIME_CLASS = (PHP_VERSION >= 5.2); - /* This code was originally for windows. But apparently this problem happens also with Linux, RH 7.3 and later! @@ -420,6 +407,9 @@ $ADODB_DATETIME_CLASS = (PHP_VERSION >= 5.2); if (!defined('ADODB_ALLOW_NEGATIVE_TS')) define('ADODB_NO_NEGATIVE_TS',1); +if (!DEFINED('ADODB_FUTURE_DATE_CUTOFF_YEARS')) + DEFINE('ADODB_FUTURE_DATE_CUTOFF_YEARS',200); + function adodb_date_test_date($y1,$m,$d=13) { $h = round(rand()% 24); @@ -528,8 +518,8 @@ function adodb_date_test() if (adodb_year_digit_check(50) != 1950) print "Err 2-digit 1950<br>"; if (adodb_year_digit_check(90) != 1990) print "Err 2-digit 1990<br>"; - // Test string formating - print "<p>Testing date formating</p>"; + // Test string formatting + print "<p>Testing date formatting</p>"; $fmt = '\d\a\t\e T Y-m-d H:i:s a A d D F g G h H i j l L m M n O \R\F\C2822 r s t U w y Y z Z 2003'; $s1 = date($fmt,0); @@ -733,13 +723,12 @@ function adodb_get_gmt_diff_ts($ts) */ function adodb_get_gmt_diff($y,$m,$d) { -static $TZ,$tzo; -global $ADODB_DATETIME_CLASS; + static $TZ,$tzo; if (!defined('ADODB_TEST_DATES')) $y = false; else if ($y < 1970 || $y >= 2038) $y = false; - if ($ADODB_DATETIME_CLASS && $y !== false) { + if ($y !== false) { $dt = new DateTime(); $dt->setISODate($y,$m,$d); if (empty($tzo)) { @@ -816,7 +805,7 @@ global $_month_table_normal,$_month_table_leaf; if ($marr[$m] < $d) return false; - if ($y < 1000 && $y > 3000) return false; + if ($y < 1000 || $y > 3000) return false; return true; } @@ -829,13 +818,23 @@ global $_month_table_normal,$_month_table_leaf; function _adodb_getdate($origd=false,$fast=false,$is_gmt=false) { static $YRS; -global $_month_table_normal,$_month_table_leaf; +global $_month_table_normal,$_month_table_leaf, $_adodb_last_date_call_failed; + + $_adodb_last_date_call_failed = false; $d = $origd - ($is_gmt ? 0 : adodb_get_gmt_diff_ts($origd)); $_day_power = 86400; $_hour_power = 3600; $_min_power = 60; + $cutoffDate = time() + (60 * 60 * 24 * 365 * ADODB_FUTURE_DATE_CUTOFF_YEARS); + + if ($d > $cutoffDate) + { + $d = $cutoffDate; + $_adodb_last_date_call_failed = true; + } + if ($d < -12219321600) $d -= 86400*10; // if 15 Oct 1582 or earlier, gregorian correction $_month_table_normal = array("",31,28,31,30,31,30,31,31,30,31,30,31); @@ -1021,20 +1020,20 @@ global $_month_table_normal,$_month_table_leaf; 0 => $origd ); } -/* - if ($isphp5) - $dates .= sprintf('%s%04d',($gmt<=0)?'+':'-',abs($gmt)/36); - else - $dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36); - break;*/ -function adodb_tz_offset($gmt,$isphp5) + +/** + * Compute timezone offset. + * + * @param int $gmt Time offset from GMT, in seconds + * @param bool $ignored Param leftover from removed PHP4-compatibility code + * kept to avoid altering function signature. + * @return string + */ +function adodb_tz_offset($gmt, $ignored=true) { - $zhrs = abs($gmt)/3600; + $zhrs = abs($gmt) / 3600; $hrs = floor($zhrs); - if ($isphp5) - return sprintf('%s%02d%02d',($gmt<=0)?'+':'-',floor($zhrs),($zhrs-$hrs)*60); - else - return sprintf('%s%02d%02d',($gmt<0)?'+':'-',floor($zhrs),($zhrs-$hrs)*60); + return sprintf('%s%02d%02d', ($gmt <= 0) ? '+' : '-', $hrs, ($zhrs - $hrs) * 60); } @@ -1067,10 +1066,8 @@ function adodb_date2($fmt, $d=false, $is_gmt=false) */ function adodb_date($fmt,$d=false,$is_gmt=false) { -static $daylight; -global $ADODB_DATETIME_CLASS; -static $jan1_1971; - + static $daylight; + static $jan1_1971; if (!isset($daylight)) { $daylight = function_exists('adodb_daylight_sv'); @@ -1079,7 +1076,15 @@ static $jan1_1971; if ($d === false) return ($is_gmt)? @gmdate($fmt): @date($fmt); if (!defined('ADODB_TEST_DATES')) { - if ((abs($d) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range + + /* + * Format 'Q' is an ADOdb custom format, not supported in PHP + * so if there is a 'Q' in the format, we force it to use our + * function. There is a trivial overhead in this + */ + + if ((abs($d) <= 0x7FFFFFFF) && strpos($fmt,'Q') === false) + { // check if number in 32-bit signed range if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= $jan1_1971) // if windows, must be +ve integer return ($is_gmt)? @gmdate($fmt,$d): @date($fmt,$d); @@ -1102,8 +1107,6 @@ static $jan1_1971; $max = strlen($fmt); $dates = ''; - $isphp5 = PHP_VERSION >= 5; - /* at this point, we have the following integer vars to manipulate: $year, $month, $day, $hour, $min, $secs @@ -1114,12 +1117,9 @@ static $jan1_1971; $dates .= date('e'); break; case 'T': - if ($ADODB_DATETIME_CLASS) { - $dt = new DateTime(); - $dt->SetDate($year,$month,$day); - $dates .= $dt->Format('T'); - } else - $dates .= date('T'); + $dt = new DateTime(); + $dt->SetDate($year,$month,$day); + $dates .= $dt->Format('T'); break; // YEAR case 'L': $dates .= $arr['leap'] ? '1' : '0'; break; @@ -1138,14 +1138,16 @@ static $jan1_1971; $gmt = adodb_get_gmt_diff($year,$month,$day); - $dates .= ' '.adodb_tz_offset($gmt,$isphp5); + $dates .= ' '.adodb_tz_offset($gmt); break; case 'Y': $dates .= $year; break; case 'y': $dates .= substr($year,strlen($year)-2,2); break; // MONTH case 'm': if ($month<10) $dates .= '0'.$month; else $dates .= $month; break; - case 'Q': $dates .= ($month+3)>>2; break; + case 'Q': + $dates .= ceil($month / 3); + break; case 'n': $dates .= $month; break; case 'M': $dates .= date('M',mktime(0,0,0,$month,2,1971)); break; case 'F': $dates .= date('F',mktime(0,0,0,$month,2,1971)); break; @@ -1153,6 +1155,9 @@ static $jan1_1971; case 't': $dates .= $arr['ndays']; break; case 'z': $dates .= $arr['yday']; break; case 'w': $dates .= adodb_dow($year,$month,$day); break; + case 'W': + $dates .= sprintf('%02d',ceil( $arr['yday'] / 7) - 1); + break; case 'l': $dates .= gmdate('l',$_day_power*(3+adodb_dow($year,$month,$day))); break; case 'D': $dates .= gmdate('D',$_day_power*(3+adodb_dow($year,$month,$day))); break; case 'j': $dates .= $day; break; @@ -1171,7 +1176,7 @@ static $jan1_1971; case 'O': $gmt = ($is_gmt) ? 0 : adodb_get_gmt_diff($year,$month,$day); - $dates .= adodb_tz_offset($gmt,$isphp5); + $dates .= adodb_tz_offset($gmt); break; case 'H': @@ -1375,7 +1380,7 @@ global $ADODB_DATE_LOCALE; $sep = substr($tstr,2,1); $hasAM = strrpos($tstr,'M') !== false; */ - # see http://phplens.com/lens/lensforum/msgs.php?id=14865 for reasoning, and changelog for version 0.24 + # see PHPLens Issue No: 14865 for reasoning, and changelog for version 0.24 $dstr = gmstrftime('%x',31366800); // 30 Dec 1970, 1 am $sep = substr($dstr,2,1); $tstr = strtoupper(gmstrftime('%X',31366800)); // 30 Dec 1970, 1 am @@ -1460,3 +1465,16 @@ global $ADODB_DATE_LOCALE; $ret = adodb_date($fmtdate, $ts, $is_gmt); return $ret; } + +/** +* Returns the status of the last date calculation and whether it exceeds +* the limit of ADODB_FUTURE_DATE_CUTOFF_YEARS +* +* @return boolean +*/ +function adodb_last_date_status() +{ + global $_adodb_last_date_call_failed; + + return $_adodb_last_date_call_failed; +} diff --git a/libraries/adodb/adodb-xmlschema.inc.php b/libraries/adodb/adodb-xmlschema.inc.php index 5077789b0..58e3affd6 100644 --- a/libraries/adodb/adodb-xmlschema.inc.php +++ b/libraries/adodb/adodb-xmlschema.inc.php @@ -1,21 +1,29 @@ <?php -// Copyright (c) 2004 ars Cognita Inc., all rights reserved -/* ****************************************************************************** - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. -*******************************************************************************/ /** + * ADOdb XML Schema (v0.2). + * * xmlschema is a class that allows the user to quickly and easily * build a database on any ADOdb-supported platform using a simple * XML schema. * - * Last Editor: $Author: jlim $ - * @author Richard Tango-Lowy & Dan Cech - * @version $Revision: 1.12 $ + * 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 * - * @package axmls - * @tutorial getting_started.pkg + * @copyright 2004-2005 ars Cognita Inc., all rights reserved + * @copyright 2005-2013 John Lim + * @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community + * @author Richard Tango-Lowy + * @author Dan Cech */ function _file_get_contents($file) @@ -240,7 +248,6 @@ class dbTable extends dbObject { * @access private */ var $drop_field = array(); - var $alter; // GS Fix for constraint impl /** * Iniitializes a new table object. @@ -251,10 +258,6 @@ class dbTable extends dbObject { function __construct( &$parent, $attributes = NULL ) { $this->parent = $parent; $this->name = $this->prefix($attributes['NAME']); - // GS Fix for constraint impl - if(isset($attributes['ALTER'])) { - $this->alter = $attributes['ALTER']; - } } /** @@ -329,12 +332,12 @@ class dbTable extends dbObject { if( isset( $this->current_field ) ) { $this->addFieldOpt( $this->current_field, $this->currentElement, $cdata ); } else { - $this->addTableOpt( $cdata, 'CONSTRAINTS' ); // GS Fix for constraint impl + $this->addTableOpt( $cdata ); } break; // Table option case 'OPT': - $this->addTableOpt( $cdata, 'mysql' ); // GS Fix for constraint impl + $this->addTableOpt( $cdata ); break; default: @@ -468,13 +471,9 @@ class dbTable extends dbObject { * @param string $opt Table option * @return array Options */ - function addTableOpt( $opt, $key = NULL) { // GS Fix for constraint impl - if ($key) { - $this->opts[$key] = $opt; - } else { - if(isset($this->currentPlatform)) { - $this->opts[$this->parent->db->databaseType] = $opt; - } + function addTableOpt( $opt ) { + if(isset($this->currentPlatform)) { + $this->opts[$this->parent->db->databaseType] = $opt; } return $this->opts; } @@ -557,7 +556,7 @@ class dbTable extends dbObject { } } - if( empty( $legacy_fields ) && !isset($this->alter)) { // GS Fix for constraint impl + if( empty( $legacy_fields ) ) { // Create the new table $sql[] = $xmls->dict->CreateTableSQL( $this->name, $fldarray, $this->opts ); logMsg( end( $sql ), 'Generated CreateTableSQL' ); @@ -568,7 +567,7 @@ class dbTable extends dbObject { // Use ChangeTableSQL case 'ALTER': logMsg( 'Generated ChangeTableSQL (ALTERing table)' ); - $sql[] = $xmls->dict->ChangeTableSQL( $this->name, $fldarray, $this->opts, false, $this->alter ); // GS Fix for constraint impl + $sql[] = $xmls->dict->ChangeTableSQL( $this->name, $fldarray, $this->opts ); break; case 'REPLACE': logMsg( 'Doing upgrade REPLACE (testing)' ); @@ -1263,12 +1262,6 @@ class adoSchema { */ var $objectPrefix = ''; - /** - * @var long Original Magic Quotes Runtime value - * @access private - */ - var $mgq; - /** * @var long System debug * @access private @@ -1312,14 +1305,9 @@ class adoSchema { * @param object $db ADOdb database connection object. */ function __construct( $db ) { - // Initialize the environment - $this->mgq = get_magic_quotes_runtime(); - ini_set("magic_quotes_runtime", 0); - #set_magic_quotes_runtime(0); - $this->db = $db; $this->debug = $this->db->debug; - $this->dict = NewDataDictionary( $this->db ); + $this->dict = newDataDictionary( $this->db ); $this->sqlArray = array(); $this->schemaVersion = XMLS_SCHEMA_VERSION; $this->executeInline( XMLS_EXECUTE_INLINE ); @@ -2203,10 +2191,7 @@ class adoSchema { * Call this method to clean up after an adoSchema object that is no longer in use. * @deprecated adoSchema now cleans up automatically. */ - function Destroy() { - ini_set("magic_quotes_runtime", $this->mgq ); - #set_magic_quotes_runtime( $this->mgq ); - } + function Destroy() {} } /** diff --git a/libraries/adodb/adodb-xmlschema03.inc.php b/libraries/adodb/adodb-xmlschema03.inc.php index c1ecb885d..de1ea26c7 100644 --- a/libraries/adodb/adodb-xmlschema03.inc.php +++ b/libraries/adodb/adodb-xmlschema03.inc.php @@ -1,21 +1,29 @@ <?php -// Copyright (c) 2004-2005 ars Cognita Inc., all rights reserved -/* ****************************************************************************** - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. -*******************************************************************************/ /** + * ADOdb XML Schema (v0.3). + * * xmlschema is a class that allows the user to quickly and easily * build a database on any ADOdb-supported platform using a simple * XML schema. * - * Last Editor: $Author: jlim $ - * @author Richard Tango-Lowy & Dan Cech - * @version $Revision: 1.62 $ + * 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 * - * @package axmls - * @tutorial getting_started.pkg + * 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 2004-2005 ars Cognita Inc., all rights reserved + * @copyright 2005-2013 John Lim + * @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community + * @author Richard Tango-Lowy + * @author Dan Cech */ function _file_get_contents($file) @@ -145,7 +153,7 @@ class dbObject { * * @access private */ - function _tag_open( &$parser, $tag, $attributes ) { + function _tag_open( $parser, $tag, $attributes ) { } @@ -154,7 +162,7 @@ class dbObject { * * @access private */ - function _tag_cdata( &$parser, $cdata ) { + function _tag_cdata( $parser, $cdata ) { } @@ -163,7 +171,7 @@ class dbObject { * * @access private */ - function _tag_close( &$parser, $tag ) { + function _tag_close( $parser, $tag ) { } @@ -204,7 +212,7 @@ class dbObject { * @param string $field Field. * @return string Field ID. */ - function FieldID( $field ) { + function fieldID( $field ) { return strtoupper( preg_replace( '/^`(.+)`$/', '$1', $field ) ); } } @@ -283,7 +291,7 @@ class dbTable extends dbObject { * * @access private */ - function _tag_open( &$parser, $tag, $attributes ) { + function _tag_open( $parser, $tag, $attributes ) { $this->currentElement = strtoupper( $tag ); switch( $this->currentElement ) { @@ -345,8 +353,16 @@ class dbTable extends dbObject { * * @access private */ - function _tag_cdata( &$parser, $cdata ) { + function _tag_cdata( $parser, $cdata ) { switch( $this->currentElement ) { + // Table or field comment + case 'DESCR': + if( isset( $this->current_field ) ) { + $this->addFieldOpt( $this->current_field, $this->currentElement, $cdata ); + } else { + $this->addTableComment( $cdata ); + } + break; // Table/field constraint case 'CONSTRAINT': if( isset( $this->current_field ) ) { @@ -373,7 +389,7 @@ class dbTable extends dbObject { * * @access private */ - function _tag_close( &$parser, $tag ) { + function _tag_close( $parser, $tag ) { $this->currentElement = ''; switch( strtoupper( $tag ) ) { @@ -449,7 +465,7 @@ class dbTable extends dbObject { * @return array Field specifier array */ function addField( $name, $type, $size = NULL, $opts = NULL ) { - $field_id = $this->FieldID( $name ); + $field_id = $this->fieldID( $name ); // Set the field index so we know where we are $this->current_field = $field_id; @@ -506,11 +522,15 @@ class dbTable extends dbObject { */ function addTableOpt( $opt ) { if(isset($this->currentPlatform)) { - $this->opts[$this->parent->db->databaseType] = $opt; + $this->opts[$this->parent->db->dataProvider] = $opt; } return $this->opts; } + function addTableComment( $opt ) { + $this->opts['comment'] = $opt; + return $this->opts; + } /** * Generates the SQL that will create the table in the database @@ -522,9 +542,9 @@ class dbTable extends dbObject { $sql = array(); // drop any existing indexes - if( is_array( $legacy_indexes = $xmls->dict->MetaIndexes( $this->name ) ) ) { + if( is_array( $legacy_indexes = $xmls->dict->metaIndexes( $this->name ) ) ) { foreach( $legacy_indexes as $index => $index_details ) { - $sql[] = $xmls->dict->DropIndexSQL( $index, $this->name ); + $sql[] = $xmls->dict->dropIndexSQL( $index, $this->name ); } } @@ -534,10 +554,10 @@ class dbTable extends dbObject { } // if table exists - if( is_array( $legacy_fields = $xmls->dict->MetaColumns( $this->name ) ) ) { + if( is_array( $legacy_fields = $xmls->dict->metaColumns( $this->name ) ) ) { // drop table if( $this->drop_table ) { - $sql[] = $xmls->dict->DropTableSQL( $this->name ); + $sql[] = $xmls->dict->dropTableSQL( $this->name ); return $sql; } @@ -545,7 +565,7 @@ class dbTable extends dbObject { // drop any existing fields not in schema foreach( $legacy_fields as $field_id => $field ) { if( !isset( $this->fields[$field_id] ) ) { - $sql[] = $xmls->dict->DropColumnSQL( $this->name, $field->name ); + $sql[] = $xmls->dict->dropColumnSQL( $this->name, $field->name ); } } // if table doesn't exist @@ -591,21 +611,21 @@ class dbTable extends dbObject { if( empty( $legacy_fields ) ) { // Create the new table - $sql[] = $xmls->dict->CreateTableSQL( $this->name, $fldarray, $this->opts ); - logMsg( end( $sql ), 'Generated CreateTableSQL' ); + $sql[] = $xmls->dict->createTableSQL( $this->name, $fldarray, $this->opts ); + logMsg( end( $sql ), 'Generated createTableSQL' ); } else { // Upgrade an existing table logMsg( "Upgrading {$this->name} using '{$xmls->upgrade}'" ); switch( $xmls->upgrade ) { // Use ChangeTableSQL case 'ALTER': - logMsg( 'Generated ChangeTableSQL (ALTERing table)' ); - $sql[] = $xmls->dict->ChangeTableSQL( $this->name, $fldarray, $this->opts ); + logMsg( 'Generated changeTableSQL (ALTERing table)' ); + $sql[] = $xmls->dict->changeTableSQL( $this->name, $fldarray, $this->opts ); break; case 'REPLACE': logMsg( 'Doing upgrade REPLACE (testing)' ); - $sql[] = $xmls->dict->DropTableSQL( $this->name ); - $sql[] = $xmls->dict->CreateTableSQL( $this->name, $fldarray, $this->opts ); + $sql[] = $xmls->dict->dropTableSQL( $this->name ); + $sql[] = $xmls->dict->createTableSQL( $this->name, $fldarray, $this->opts ); break; // ignore table default: @@ -698,7 +718,7 @@ class dbIndex extends dbObject { * * @access private */ - function _tag_open( &$parser, $tag, $attributes ) { + function _tag_open( $parser, $tag, $attributes ) { $this->currentElement = strtoupper( $tag ); switch( $this->currentElement ) { @@ -725,7 +745,7 @@ class dbIndex extends dbObject { * * @access private */ - function _tag_cdata( &$parser, $cdata ) { + function _tag_cdata( $parser, $cdata ) { switch( $this->currentElement ) { // Index field name case 'COL': @@ -741,7 +761,7 @@ class dbIndex extends dbObject { * * @access private */ - function _tag_close( &$parser, $tag ) { + function _tag_close( $parser, $tag ) { $this->currentElement = ''; switch( strtoupper( $tag ) ) { @@ -758,7 +778,7 @@ class dbIndex extends dbObject { * @return string Field list */ function addField( $name ) { - $this->columns[$this->FieldID( $name )] = $name; + $this->columns[$this->fieldID( $name )] = $name; // Return the field list return $this->columns; @@ -795,7 +815,7 @@ class dbIndex extends dbObject { } } - return $xmls->dict->CreateIndexSQL( $this->name, $this->parent->name, $this->columns, $this->opts ); + return $xmls->dict->createIndexSQL( $this->name, $this->parent->name, $this->columns, $this->opts ); } /** @@ -841,7 +861,7 @@ class dbData extends dbObject { * * @access private */ - function _tag_open( &$parser, $tag, $attributes ) { + function _tag_open( $parser, $tag, $attributes ) { $this->currentElement = strtoupper( $tag ); switch( $this->currentElement ) { @@ -863,7 +883,7 @@ class dbData extends dbObject { * * @access private */ - function _tag_cdata( &$parser, $cdata ) { + function _tag_cdata( $parser, $cdata ) { switch( $this->currentElement ) { // Index field name case 'F': @@ -879,7 +899,7 @@ class dbData extends dbObject { * * @access private */ - function _tag_close( &$parser, $tag ) { + function _tag_close( $parser, $tag ) { $this->currentElement = ''; switch( strtoupper( $tag ) ) { @@ -903,7 +923,7 @@ class dbData extends dbObject { // Set the field index so we know where we are if( isset( $attributes['NAME'] ) ) { - $this->current_field = $this->FieldID( $attributes['NAME'] ); + $this->current_field = $this->fieldID( $attributes['NAME'] ); } else { $this->current_field = count( $this->data[$this->row] ); } @@ -935,12 +955,12 @@ class dbData extends dbObject { * @return array Array containing index creation SQL */ function create( &$xmls ) { - $table = $xmls->dict->TableName($this->parent->name); + $table = $xmls->dict->tableName($this->parent->name); $table_field_count = count($this->parent->fields); - $tables = $xmls->db->MetaTables(); + $tables = $xmls->db->metaTables(); $sql = array(); - $ukeys = $xmls->db->MetaPrimaryKeys( $table ); + $ukeys = $xmls->db->metaPrimaryKeys( $table ); if( !empty( $this->parent->indexes ) and !empty( $ukeys ) ) { foreach( $this->parent->indexes as $indexObj ) { if( !in_array( $indexObj->name, $ukeys ) ) $ukeys[] = $indexObj->name; @@ -1027,19 +1047,19 @@ class dbData extends dbObject { $where .= $key . ' = ' . $xmls->db->qstr( $mfields[$key] ); } } - $records = $xmls->db->Execute( 'SELECT * FROM ' . $table . ' WHERE ' . $where ); - switch( $records->RecordCount() ) { + $records = $xmls->db->execute( 'SELECT * FROM ' . $table . ' WHERE ' . $where ); + switch( $records->recordCount() ) { case 0: // No matching record, so safe to insert. logMsg( "No matching records. Inserting new row with unique data" ); - $sql[] = $xmls->db->GetInsertSQL( $records, $mfields ); + $sql[] = $xmls->db->getInsertSQL( $records, $mfields ); break; case 1: // Exactly one matching record, so we can update if the mode permits. logMsg( "One matching record..." ); if( $mode == XMLS_MODE_UPDATE ) { logMsg( "...Updating existing row from unique data" ); - $sql[] = $xmls->db->GetUpdateSQL( $records, $mfields ); + $sql[] = $xmls->db->getUpdateSQL( $records, $mfields ); } break; default: @@ -1115,7 +1135,7 @@ class dbQuerySet extends dbObject { * * @access private */ - function _tag_open( &$parser, $tag, $attributes ) { + function _tag_open( $parser, $tag, $attributes ) { $this->currentElement = strtoupper( $tag ); switch( $this->currentElement ) { @@ -1137,7 +1157,7 @@ class dbQuerySet extends dbObject { /** * XML Callback to process CDATA elements */ - function _tag_cdata( &$parser, $cdata ) { + function _tag_cdata( $parser, $cdata ) { switch( $this->currentElement ) { // Line of queryset SQL data case 'QUERY': @@ -1153,7 +1173,7 @@ class dbQuerySet extends dbObject { * * @access private */ - function _tag_close( &$parser, $tag ) { + function _tag_close( $parser, $tag ) { $this->currentElement = ''; switch( strtoupper( $tag ) ) { @@ -1353,12 +1373,6 @@ class adoSchema { */ var $objectPrefix = ''; - /** - * @var long Original Magic Quotes Runtime value - * @access private - */ - var $mgq; - /** * @var long System debug * @access private @@ -1407,14 +1421,9 @@ class adoSchema { * @param object $db ADOdb database connection object. */ function __construct( $db ) { - // Initialize the environment - $this->mgq = get_magic_quotes_runtime(); - #set_magic_quotes_runtime(0); - ini_set("magic_quotes_runtime", 0); - $this->db = $db; $this->debug = $this->db->debug; - $this->dict = NewDataDictionary( $this->db ); + $this->dict = newDataDictionary( $this->db ); $this->sqlArray = array(); $this->schemaVersion = XMLS_SCHEMA_VERSION; $this->executeInline( XMLS_EXECUTE_INLINE ); @@ -1439,7 +1448,7 @@ class adoSchema { * @param string $method Upgrade method (ALTER|REPLACE|BEST|NONE) * @returns string Upgrade method used */ - function SetUpgradeMethod( $method = '' ) { + function setUpgradeMethod( $method = '' ) { if( !is_string( $method ) ) { return FALSE; } @@ -1487,7 +1496,7 @@ class adoSchema { * @param int $mode XMLS_MODE_INSERT, XMLS_MODE_UPDATE, or XMLS_MODE_IGNORE * @return int current mode */ - function ExistingData( $mode = NULL ) { + function existingData( $mode = NULL ) { if( is_int( $mode ) ) { switch( $mode ) { case XMLS_MODE_UPDATE: @@ -1522,7 +1531,7 @@ class adoSchema { * * @see ParseSchema(), ExecuteSchema() */ - function ExecuteInline( $mode = NULL ) { + function executeInline( $mode = NULL ) { if( is_bool( $mode ) ) { $this->executeInline = $mode; } @@ -1543,7 +1552,7 @@ class adoSchema { * * @see addSQL(), ExecuteSchema() */ - function ContinueOnError( $mode = NULL ) { + function continueOnError( $mode = NULL ) { if( is_bool( $mode ) ) { $this->continueOnError = $mode; } @@ -1564,8 +1573,8 @@ class adoSchema { * @param bool $returnSchema Return schema rather than parsing. * @return array Array of SQL queries, ready to execute */ - function ParseSchema( $filename, $returnSchema = FALSE ) { - return $this->ParseSchemaString( $this->ConvertSchemaFile( $filename ), $returnSchema ); + function parseSchema( $filename, $returnSchema = FALSE ) { + return $this->parseSchemaString( $this->convertSchemaFile( $filename ), $returnSchema ); } /** @@ -1574,22 +1583,22 @@ class adoSchema { * Call this method to load the specified schema directly from a file (see * the DTD for the proper format) and generate the SQL necessary to create * the database described by the schema. Use this method when you are dealing - * with large schema files. Otherwise, ParseSchema() is faster. + * with large schema files. Otherwise, parseSchema() is faster. * This method does not automatically convert the schema to the latest axmls * schema version. You must convert the schema manually using either the - * ConvertSchemaFile() or ConvertSchemaString() method. - * @see ParseSchema() - * @see ConvertSchemaFile() - * @see ConvertSchemaString() + * convertSchemaFile() or convertSchemaString() method. + * @see parseSchema() + * @see convertSchemaFile() + * @see convertSchemaString() * * @param string $file Name of XML schema file. * @param bool $returnSchema Return schema rather than parsing. * @return array Array of SQL queries, ready to execute. * - * @deprecated Replaced by adoSchema::ParseSchema() and adoSchema::ParseSchemaString() - * @see ParseSchema(), ParseSchemaString() + * @deprecated Replaced by adoSchema::parseSchema() and adoSchema::parseSchemaString() + * @see parseSchema(), parseSchemaString() */ - function ParseSchemaFile( $filename, $returnSchema = FALSE ) { + function parseSchemaFile( $filename, $returnSchema = FALSE ) { // Open the file if( !($fp = fopen( $filename, 'r' )) ) { logMsg( 'Unable to open file' ); @@ -1597,7 +1606,7 @@ class adoSchema { } // do version detection here - if( $this->SchemaFileVersion( $filename ) != $this->schemaVersion ) { + if( $this->schemaFileVersion( $filename ) != $this->schemaVersion ) { logMsg( 'Invalid Schema Version' ); return FALSE; } @@ -1635,13 +1644,13 @@ class adoSchema { * * Call this method to parse a string containing an XML schema (see the DTD for the proper format) * and generate the SQL necessary to create the database described by the schema. - * @see ParseSchema() + * @see parseSchema() * * @param string $xmlstring XML schema string. * @param bool $returnSchema Return schema rather than parsing. * @return array Array of SQL queries, ready to execute. */ - function ParseSchemaString( $xmlstring, $returnSchema = FALSE ) { + function parseSchemaString( $xmlstring, $returnSchema = FALSE ) { if( !is_string( $xmlstring ) OR empty( $xmlstring ) ) { logMsg( 'Empty or Invalid Schema' ); return FALSE; @@ -1685,8 +1694,8 @@ class adoSchema { * @param bool $returnSchema Return schema rather than parsing. * @return array Array of SQL queries, ready to execute */ - function RemoveSchema( $filename, $returnSchema = FALSE ) { - return $this->RemoveSchemaString( $this->ConvertSchemaFile( $filename ), $returnSchema ); + function removeSchema( $filename, $returnSchema = FALSE ) { + return $this->removeSchemaString( $this->convertSchemaFile( $filename ), $returnSchema ); } /** @@ -1694,38 +1703,38 @@ class adoSchema { * * Call this method to parse a string containing an XML schema (see the DTD for the proper format) * and generate the SQL necessary to uninstall the database described by the schema. - * @see RemoveSchema() + * @see removeSchema() * * @param string $schema XML schema string. * @param bool $returnSchema Return schema rather than parsing. * @return array Array of SQL queries, ready to execute. */ - function RemoveSchemaString( $schema, $returnSchema = FALSE ) { + function removeSchemaString( $schema, $returnSchema = FALSE ) { // grab current version - if( !( $version = $this->SchemaStringVersion( $schema ) ) ) { + if( !( $version = $this->schemaStringVersion( $schema ) ) ) { return FALSE; } - return $this->ParseSchemaString( $this->TransformSchema( $schema, 'remove-' . $version), $returnSchema ); + return $this->parseSchemaString( $this->transformSchema( $schema, 'remove-' . $version), $returnSchema ); } /** * Applies the current XML schema to the database (post execution). * * Call this method to apply the current schema (generally created by calling - * ParseSchema() or ParseSchemaString() ) to the database (creating the tables, indexes, + * parseSchema() or parseSchemaString() ) to the database (creating the tables, indexes, * and executing other SQL specified in the schema) after parsing. - * @see ParseSchema(), ParseSchemaString(), ExecuteInline() + * @see parseSchema(), parseSchemaString(), executeInline() * * @param array $sqlArray Array of SQL statements that will be applied rather than * the current schema. * @param boolean $continueOnErr Continue to apply the schema even if an error occurs. * @returns integer 0 if failure, 1 if errors, 2 if successful. */ - function ExecuteSchema( $sqlArray = NULL, $continueOnErr = NULL ) { + function executeSchema( $sqlArray = NULL, $continueOnErr = NULL ) { if( !is_bool( $continueOnErr ) ) { - $continueOnErr = $this->ContinueOnError(); + $continueOnErr = $this->continueOnError(); } if( !isset( $sqlArray ) ) { @@ -1735,7 +1744,7 @@ class adoSchema { if( !is_array( $sqlArray ) ) { $this->success = 0; } else { - $this->success = $this->dict->ExecuteSQLArray( $sqlArray, $continueOnErr ); + $this->success = $this->dict->executeSQLArray( $sqlArray, $continueOnErr ); } return $this->success; @@ -1745,12 +1754,12 @@ class adoSchema { * Returns the current SQL array. * * Call this method to fetch the array of SQL queries resulting from - * ParseSchema() or ParseSchemaString(). + * parseSchema() or parseSchemaString(). * * @param string $format Format: HTML, TEXT, or NONE (PHP array) * @return array Array of SQL statements or FALSE if an error occurs */ - function PrintSQL( $format = 'NONE' ) { + function printSQL( $format = 'NONE' ) { $sqlArray = null; return $this->getSQL( $format, $sqlArray ); } @@ -1764,7 +1773,7 @@ class adoSchema { * @param string $filename Path and name where the file should be saved. * @return boolean TRUE if save is successful, else FALSE. */ - function SaveSQL( $filename = './schema.sql' ) { + function saveSQL( $filename = './schema.sql' ) { if( !isset( $sqlArray ) ) { $sqlArray = $this->sqlArray; @@ -1805,7 +1814,7 @@ class adoSchema { * * @access private */ - function _tag_open( &$parser, $tag, $attributes ) { + function _tag_open( $parser, $tag, $attributes ) { switch( strtoupper( $tag ) ) { case 'TABLE': if( !isset( $attributes['PLATFORM'] ) OR $this->supportedPlatform( $attributes['PLATFORM'] ) ) { @@ -1830,7 +1839,7 @@ class adoSchema { * * @access private */ - function _tag_cdata( &$parser, $cdata ) { + function _tag_cdata( $parser, $cdata ) { } /** @@ -1839,7 +1848,7 @@ class adoSchema { * @access private * @internal */ - function _tag_close( &$parser, $tag ) { + function _tag_close( $parser, $tag ) { } @@ -1852,17 +1861,17 @@ class adoSchema { * parameter is specified, the schema will be converted to the current DTD version. * If the newFile parameter is provided, the converted schema will be written to the specified * file. - * @see ConvertSchemaFile() + * @see convertSchemaFile() * * @param string $schema String containing XML schema that will be converted. * @param string $newVersion DTD version to convert to. * @param string $newFile File name of (converted) output file. * @return string Converted XML schema or FALSE if an error occurs. */ - function ConvertSchemaString( $schema, $newVersion = NULL, $newFile = NULL ) { + function convertSchemaString( $schema, $newVersion = NULL, $newFile = NULL ) { // grab current version - if( !( $version = $this->SchemaStringVersion( $schema ) ) ) { + if( !( $version = $this->schemaStringVersion( $schema ) ) ) { return FALSE; } @@ -1873,7 +1882,7 @@ class adoSchema { if( $version == $newVersion ) { $result = $schema; } else { - $result = $this->TransformSchema( $schema, 'convert-' . $version . '-' . $newVersion); + $result = $this->transformSchema( $schema, 'convert-' . $version . '-' . $newVersion); } if( is_string( $result ) AND is_string( $newFile ) AND ( $fp = fopen( $newFile, 'w' ) ) ) { @@ -1901,17 +1910,17 @@ class adoSchema { * parameter is specified, the schema will be converted to the current DTD version. * If the newFile parameter is provided, the converted schema will be written to the specified * file. - * @see ConvertSchemaString() + * @see convertSchemaString() * * @param string $filename Name of XML schema file that will be converted. * @param string $newVersion DTD version to convert to. * @param string $newFile File name of (converted) output file. * @return string Converted XML schema or FALSE if an error occurs. */ - function ConvertSchemaFile( $filename, $newVersion = NULL, $newFile = NULL ) { + function convertSchemaFile( $filename, $newVersion = NULL, $newFile = NULL ) { // grab current version - if( !( $version = $this->SchemaFileVersion( $filename ) ) ) { + if( !( $version = $this->schemaFileVersion( $filename ) ) ) { return FALSE; } @@ -1927,7 +1936,7 @@ class adoSchema { $result = substr( $result, 3 ); } } else { - $result = $this->TransformSchema( $filename, 'convert-' . $version . '-' . $newVersion, 'file' ); + $result = $this->transformSchema( $filename, 'convert-' . $version . '-' . $newVersion, 'file' ); } if( is_string( $result ) AND is_string( $newFile ) AND ( $fp = fopen( $newFile, 'w' ) ) ) { @@ -1938,7 +1947,7 @@ class adoSchema { return $result; } - function TransformSchema( $schema, $xsl, $schematype='string' ) + function transformSchema( $schema, $xsl, $schematype='string' ) { // Fail if XSLT extension is not available if( ! function_exists( 'xslt_create' ) ) { @@ -2049,7 +2058,7 @@ class adoSchema { * @param string $filename AXMLS schema file * @return string Schema version number or FALSE on error */ - function SchemaFileVersion( $filename ) { + function schemaFileVersion( $filename ) { // Open the file if( !($fp = fopen( $filename, 'r' )) ) { // die( 'Unable to open file' ); @@ -2075,7 +2084,7 @@ class adoSchema { * @param string $xmlstring XML schema string * @return string Schema version number or FALSE on error */ - function SchemaStringVersion( $xmlstring ) { + function schemaStringVersion( $xmlstring ) { if( !is_string( $xmlstring ) OR empty( $xmlstring ) ) { return FALSE; } @@ -2092,20 +2101,20 @@ class adoSchema { * * Call this method to create an XML schema string from an existing database. * If the data parameter is set to TRUE, AXMLS will include the data from the database - * in the schema. + * tables in the schema. * - * @param boolean $data Include data in schema dump - * @indent string indentation to use - * @prefix string extract only tables with given prefix - * @stripprefix strip prefix string when storing in XML schema + * @param boolean $data include data in schema dump + * @param string $indent indentation to use + * @param string $prefix extract only tables with given prefix + * @param boolean $stripprefix strip prefix string when storing in XML schema * @return string Generated XML schema */ - function ExtractSchema( $data = FALSE, $indent = ' ', $prefix = '' , $stripprefix=false) { - $old_mode = $this->db->SetFetchMode( ADODB_FETCH_NUM ); + function extractSchema( $data = FALSE, $indent = ' ', $prefix = '' , $stripprefix=false) { + $old_mode = $this->db->setFetchMode( ADODB_FETCH_NUM ); $schema = '<?xml version="1.0"?>' . "\n" . '<schema version="' . $this->schemaVersion . '">' . "\n"; - if( is_array( $tables = $this->db->MetaTables( 'TABLES' ,false ,($prefix) ? str_replace('_','\_',$prefix).'%' : '') ) ) { + if( is_array( $tables = $this->db->metaTables( 'TABLES' ,false ,($prefix) ? str_replace('_','\_',$prefix).'%' : '') ) ) { foreach( $tables as $table ) { $schema .= $indent . '<table name="' @@ -2113,9 +2122,9 @@ class adoSchema { . '">' . "\n"; // grab details from database - $rs = $this->db->Execute( 'SELECT * FROM ' . $table . ' WHERE -1' ); - $fields = $this->db->MetaColumns( $table ); - $indexes = $this->db->MetaIndexes( $table ); + $rs = $this->db->execute('SELECT * FROM ' . $table . ' WHERE 0=1'); + $fields = $this->db->metaColumns( $table ); + $indexes = $this->db->metaIndexes( $table ); if( is_array( $fields ) ) { foreach( $fields as $details ) { @@ -2147,7 +2156,7 @@ class adoSchema { // this stops the creation of 'R' columns, // AUTOINCREMENT is used to create auto columns $details->primary_key = 0; - $type = $rs->MetaType( $details ); + $type = $rs->metaType( $details ); $schema .= str_repeat( $indent, 2 ) . '<field name="' . htmlentities( $details->name ) . '" type="' . $type . '"' . $extra; @@ -2178,12 +2187,12 @@ class adoSchema { } if( $data ) { - $rs = $this->db->Execute( 'SELECT * FROM ' . $table ); + $rs = $this->db->execute( 'SELECT * FROM ' . $table ); if( is_object( $rs ) && !$rs->EOF ) { $schema .= str_repeat( $indent, 2 ) . "<data>\n"; - while( $row = $rs->FetchRow() ) { + while( $row = $rs->fetchRow() ) { foreach( $row as $key => $val ) { if ( $val != htmlentities( $val ) ) { $row[$key] = '<![CDATA[' . $val . ']]>'; @@ -2201,7 +2210,7 @@ class adoSchema { } } - $this->db->SetFetchMode( $old_mode ); + $this->db->setFetchMode( $old_mode ); $schema .= '</schema>'; return $schema; @@ -2217,7 +2226,7 @@ class adoSchema { * @param boolean $underscore If TRUE, automatically append an underscore character to the prefix. * @return boolean TRUE if successful, else FALSE */ - function SetPrefix( $prefix = '', $underscore = TRUE ) { + function setPrefix( $prefix = '', $underscore = TRUE ) { switch( TRUE ) { // clear prefix case empty( $prefix ): @@ -2376,9 +2385,7 @@ class adoSchema { * Call this method to clean up after an adoSchema object that is no longer in use. * @deprecated adoSchema now cleans up automatically. */ - function Destroy() { - ini_set("magic_quotes_runtime", $this->mgq ); - #set_magic_quotes_runtime( $this->mgq ); + function destroy() { } } diff --git a/libraries/adodb/adodb.inc.php b/libraries/adodb/adodb.inc.php index ed4617c17..f15158f94 100644 --- a/libraries/adodb/adodb.inc.php +++ b/libraries/adodb/adodb.inc.php @@ -1,37 +1,22 @@ <?php -/* - * Set tabs to 4 for best viewing. +/** + * ADOdb Library main include file. * - * Latest version is available at http://adodb.sourceforge.net + * This file is part of ADOdb, a Database Abstraction Layer library for PHP. * - * This is the main include file for ADOdb. - * Database specific drivers are stored in the adodb/drivers/adodb-*.inc.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 files are formatted so that doxygen can be used to generate documentation. - * Doxygen is a documentation generation tool and can be downloaded from http://doxygen.org/ - */ - -/** - \mainpage - - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - - Released under both BSD license and Lesser GPL library license. You can choose which license - you prefer. - - PHP's database access functions are not standardised. This creates a need for a database - class library to hide the differences between the different database API's (encapsulate - the differences) so we can easily switch databases. - - We currently support MySQL, Oracle, Microsoft SQL Server, Sybase, Sybase SQL Anywhere, DB2, - Informix, PostgreSQL, FrontBase, Interbase (Firebird and Borland variants), Foxpro, Access, - ADO, SAP DB, SQLite and ODBC. We have had successful reports of connecting to Progress and - other databases via ODBC. - - Latest Download at http://adodb.sourceforge.net/ - + * 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 */ if (!defined('_ADODB_LAYER')) { @@ -75,7 +60,6 @@ if (!defined('_ADODB_LAYER')) { $ADODB_CACHE_DIR, // directory to cache recordsets $ADODB_CACHE, $ADODB_CACHE_CLASS, - $ADODB_EXTENSION, // ADODB extension installed $ADODB_COMPAT_FETCH, // If $ADODB_COUNTRECS and this is true, $rs->fields is available on EOF $ADODB_FETCH_MODE, // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default... $ADODB_GETONE_EOF, @@ -85,35 +69,52 @@ if (!defined('_ADODB_LAYER')) { // GLOBAL SETUP //============================================================================================== - $ADODB_EXTENSION = defined('ADODB_EXTENSION'); - - // ******************************************************** - // Controls $ADODB_FORCE_TYPE mode. Default is ADODB_FORCE_VALUE (3). - // Used in GetUpdateSql and GetInsertSql functions. Thx to Niko, nuko#mbnet.fi - // - // 0 = ignore empty fields. All empty fields in array are ignored. - // 1 = force null. All empty, php null and string 'null' fields are changed to sql NULL values. - // 2 = force empty. All empty, php null and string 'null' fields are changed to sql empty '' or 0 values. - // 3 = force value. Value is left as it is. Php null and string 'null' are set to sql NULL values and empty fields '' are set to empty '' sql values. - + /********************************************************* + * Controls $ADODB_FORCE_TYPE mode. Default is ADODB_FORCE_VALUE (3). + * Used in GetUpdateSql and GetInsertSql functions. Thx to Niko, nuko#mbnet.fi + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:adodb_force_type + * + * 0 = ignore empty fields. All empty fields in array are ignored. + * 1 = force null. All empty, php null and string 'null' fields are + * changed to sql NULL values. + * 2 = force empty. All empty, php null and string 'null' fields are + * changed to sql empty '' or 0 values. + * 3 = force value. Value is left as it is. Php null and string 'null' + * are set to sql NULL values and empty fields '' are set to empty '' sql values. + * 4 = force value. Like 1 but numeric empty fields are set to zero. + */ define('ADODB_FORCE_IGNORE',0); define('ADODB_FORCE_NULL',1); define('ADODB_FORCE_EMPTY',2); define('ADODB_FORCE_VALUE',3); + define('ADODB_FORCE_NULL_AND_ZERO',4); // ******************************************************** - if (!$ADODB_EXTENSION || ADODB_EXTENSION < 4.0) { + /** + * Constants for returned values from the charMax and textMax methods. + * If not specifically defined in the driver, methods return the NOTSET value. + */ + define ('ADODB_STRINGMAX_NOTSET', -1); + define ('ADODB_STRINGMAX_NOLIMIT',-2); + + /* + * Defines the the default meta type returned + * when ADOdb encounters a type that it is not + * defined in the metaTypes. + */ + if (!defined('ADODB_DEFAULT_METATYPE')) + define ('ADODB_DEFAULT_METATYPE','N'); - define('ADODB_BAD_RS','<p>Bad $rs in %s. Connection or SQL invalid. Try using $connection->debug=true;</p>'); + define('ADODB_BAD_RS','<p>Bad $rs in %s. Connection or SQL invalid. Try using $connection->debug=true;</p>'); // allow [ ] @ ` " and . in table names - define('ADODB_TABLE_REGEX','([]0-9a-z_\:\"\`\.\@\[-]*)'); + define('ADODB_TABLE_REGEX','([]0-9a-z_\:\"\`\.\@\[-]*)'); // prefetching used by oracle - if (!defined('ADODB_PREFETCH_ROWS')) { - define('ADODB_PREFETCH_ROWS',10); - } + if (!defined('ADODB_PREFETCH_ROWS')) { + define('ADODB_PREFETCH_ROWS',10); + } /** @@ -128,10 +129,10 @@ if (!defined('_ADODB_LAYER')) { * - BOTH: array(0 => 456, 'id' => 456, 1 => 'john', 'name' => 'john') * - DEFAULT: driver-dependent */ - define('ADODB_FETCH_DEFAULT', 0); - define('ADODB_FETCH_NUM', 1); - define('ADODB_FETCH_ASSOC', 2); - define('ADODB_FETCH_BOTH', 3); + define('ADODB_FETCH_DEFAULT', 0); + define('ADODB_FETCH_NUM', 1); + define('ADODB_FETCH_ASSOC', 2); + define('ADODB_FETCH_BOTH', 3); /** * Associative array case constants @@ -148,53 +149,23 @@ if (!defined('_ADODB_LAYER')) { * NOTE: This functionality is not implemented everywhere, it currently * works only with: mssql, odbc, oci8 and ibase derived drivers */ - define('ADODB_ASSOC_CASE_LOWER', 0); - define('ADODB_ASSOC_CASE_UPPER', 1); - define('ADODB_ASSOC_CASE_NATIVE', 2); + define('ADODB_ASSOC_CASE_LOWER', 0); + define('ADODB_ASSOC_CASE_UPPER', 1); + define('ADODB_ASSOC_CASE_NATIVE', 2); - if (!defined('TIMESTAMP_FIRST_YEAR')) { - define('TIMESTAMP_FIRST_YEAR',100); - } - - /** - * AutoExecute constants - * (moved from adodb-pear.inc.php since they are only used in here) - */ - define('DB_AUTOQUERY_INSERT', 1); - define('DB_AUTOQUERY_UPDATE', 2); - - - // PHP's version scheme makes converting to numbers difficult - workaround - $_adodb_ver = (float) PHP_VERSION; - if ($_adodb_ver >= 5.2) { - define('ADODB_PHPVER',0x5200); - } else if ($_adodb_ver >= 5.0) { - define('ADODB_PHPVER',0x5000); - } else { - die("PHP5 or later required. You are running ".PHP_VERSION); - } - unset($_adodb_ver); + if (!defined('TIMESTAMP_FIRST_YEAR')) { + define('TIMESTAMP_FIRST_YEAR',100); } - /** - Accepts $src and $dest arrays, replacing string $data - */ - function ADODB_str_replace($src, $dest, $data) { - if (ADODB_PHPVER >= 0x4050) { - return str_replace($src,$dest,$data); - } + * AutoExecute constants + * (moved from adodb-pear.inc.php since they are only used in here) + */ + define('DB_AUTOQUERY_INSERT', 1); + define('DB_AUTOQUERY_UPDATE', 2); + - $s = reset($src); - $d = reset($dest); - while ($s !== false) { - $data = str_replace($s,$d,$data); - $s = next($src); - $d = next($dest); - } - return $data; - } function ADODB_Setup() { GLOBAL @@ -224,15 +195,10 @@ if (!defined('_ADODB_LAYER')) { } } - - // Initialize random number generator for randomizing cache flushes - // -- note Since PHP 4.2.0, the seed becomes optional and defaults to a random value if omitted. - srand(((double)microtime())*1000000); - /** * ADODB version as a string. */ - $ADODB_vers = 'v5.20.9 21-Dec-2016'; + $ADODB_vers = 'v5.21.2 2021-08-22'; /** * Determines whether recordset->RecordCount() is used. @@ -310,8 +276,8 @@ if (!defined('_ADODB_LAYER')) { //print "Errorno ($fn errno=$errno m=$errmsg) "; $thisConnection->_transOK = false; if ($thisConnection->_oldRaiseFn) { - $fn = $thisConnection->_oldRaiseFn; - $fn($dbms, $fn, $errno, $errmsg, $p1, $p2,$thisConnection); + $errfn = $thisConnection->_oldRaiseFn; + $errfn($dbms, $fn, $errno, $errmsg, $p1, $p2,$thisConnection); } } @@ -431,6 +397,7 @@ if (!defined('_ADODB_LAYER')) { var $databaseType = ''; /// RDBMS currently in use, eg. odbc, mysql, mssql var $database = ''; /// Name of database to be used. var $host = ''; /// The hostname of the database server + var $port = ''; /// The port of the database server var $user = ''; /// The username which is used to connect to the database server. var $password = ''; /// Password for the username. For security, we no longer store it. var $debug = false; /// if set to true will output sql statements @@ -446,6 +413,8 @@ if (!defined('_ADODB_LAYER')) { var $false = '0'; /// string that represents FALSE for a database var $replaceQuote = "\\'"; /// string to use to replace quotes var $nameQuote = '"'; /// string to use to quote identifiers and names + var $leftBracket = '['; /// left square bracked for t-sql styled column names + var $rightBracket = ']'; /// right square bracked for t-sql styled column names var $charSet=false; /// character set to use - only for interbase, postgres and oci8 var $metaDatabasesSQL = ''; var $metaTablesSQL = ''; @@ -464,7 +433,10 @@ if (!defined('_ADODB_LAYER')) { var $hasTransactions = true; /// has transactions //-- var $genID = 0; /// sequence id used by GenID(); - var $raiseErrorFn = false; /// error function to call + + /** @var bool|callable Error function to call */ + var $raiseErrorFn = false; + var $isoDates = false; /// accepts dates in ISO format var $cacheSecs = 3600; /// cache for 1 hour @@ -472,7 +444,7 @@ if (!defined('_ADODB_LAYER')) { var $memCache = false; /// should we use memCache instead of caching in files var $memCacheHost; /// memCache host var $memCachePort = 11211; /// memCache port - var $memCacheCompress = false; /// Use 'true' to store the item compressed (uses zlib) + var $memCacheCompress = false; /// Use 'true' to store the item compressed (uses zlib, not supported w/memcached library) var $sysDate = false; /// name of function that returns the current date var $sysTimeStamp = false; /// name of function that returns the current timestamp @@ -490,8 +462,12 @@ if (!defined('_ADODB_LAYER')) { var $autoRollback = false; // autoRollback on PConnect(). var $poorAffectedRows = false; // affectedRows not working or unreliable + /** @var bool|callable Execute function to call */ var $fnExecute = false; + + /** @var bool|callable Cache execution function to call */ var $fnCacheExecute = false; + var $blobEncodeType = false; // false=not required, 'I'=encode to integer, 'C'=encode to char var $rsPrefix = "ADORecordSet_"; @@ -508,7 +484,8 @@ if (!defined('_ADODB_LAYER')) { // var $_oldRaiseFn = false; var $_transOK = null; - var $_connectionID = false; /// The returned link identifier whenever a successful database connection is made. + /** @var resource Identifier for the native database connection */ + var $_connectionID = false; var $_errorMsg = false; /// A variable which was used to keep the returned last error message. The value will /// then returned by the errorMsg() function var $_errorCode = false; /// Last error code, not guaranteed to be used - only by oci8 @@ -521,32 +498,60 @@ if (!defined('_ADODB_LAYER')) { var $_logsql = false; var $_transmode = ''; // transaction mode - /* - * Additional parameters that may be passed to drivers in the connect string - * Driver must be coded to accept the parameters + /** + * Additional parameters that may be passed to drivers in the connect string. + * + * Data is stored as an array of arrays and not a simple associative array, + * because some drivers (e.g. mysql) allow multiple parameters with the same + * key to be set. + * @link https://github.com/ADOdb/ADOdb/issues/187 + * + * @see setConnectionParameter() + * + * @var array $connectionParameters Set of ParameterName => Value pairs */ protected $connectionParameters = array(); /** - * Adds a parameter to the connection string. - * - * These parameters are added to the connection string when connecting, - * if the driver is coded to use it. - * - * @param string $parameter The name of the parameter to set - * @param string $value The value of the parameter - * - * @return null - * - * @example, for mssqlnative driver ('CharacterSet','UTF-8') - */ - final public function setConnectionParameter($parameter,$value) + * Default Constructor. + * We define it even though it does not actually do anything. This avoids + * getting a PHP Fatal error: Cannot call constructor if a subclass tries + * to call its parent constructor. + */ + public function __construct() { + } - $this->connectionParameters[$parameter] = $value; - + /** + * Adds a parameter to the connection string. + * + * Parameters must be added before the connection is established; + * they are then passed on to the connect statement, which will. + * process them if the driver supports this feature. + * + * Example usage: + * - mssqlnative: setConnectionParameter('CharacterSet','UTF-8'); + * - mysqli: setConnectionParameter(MYSQLI_SET_CHARSET_NAME,'utf8mb4'); + * + * If used in a portable environment, parameters set in this manner should + * be predicated on the database provider, as unexpected results may occur + * if applied to the wrong database. + * + * @param string $parameter The name of the parameter to set + * @param string $value The value of the parameter + * + * @return bool True if success, false otherwise (e.g. parameter is not valid) + */ + public function setConnectionParameter($parameter, $value) { + $this->connectionParameters[] = array($parameter=>$value); + return true; } + /** + * ADOdb version. + * + * @return string + */ static function Version() { global $ADODB_vers; @@ -568,15 +573,20 @@ if (!defined('_ADODB_LAYER')) { } /** - Get server version info... - - @returns An array with 2 elements: $arr['string'] is the description string, - and $arr[version] is the version (also a string). - */ + * Get server version info. + * + * @return string[] An array with 2 elements: $arr['string'] is the description string, + * and $arr[version] is the version (also a string). + */ function ServerInfo() { return array('description' => '', 'version' => ''); } + /** + * Return true if connected to the database. + * + * @return bool + */ function IsConnected() { return !empty($this->_connectionID); } @@ -590,9 +600,13 @@ if (!defined('_ADODB_LAYER')) { } /** - * All error messages go through this bottleneck function. - * You can define your own handler by defining the function name in ADODB_OUTP. - */ + * All error messages go through this bottleneck function. + * + * You can define your own handler by defining the function name in ADODB_OUTP. + * + * @param string $msg Message to print + * @param bool $newline True to add a newline after printing $msg + */ static function outp($msg,$newline=true) { global $ADODB_FLUSH,$ADODB_OUTP; @@ -601,8 +615,7 @@ if (!defined('_ADODB_LAYER')) { $fn($msg,$newline); return; } else if (isset($ADODB_OUTP)) { - $fn = $ADODB_OUTP; - $fn($msg,$newline); + call_user_func($ADODB_OUTP,$msg,$newline); return; } @@ -623,6 +636,10 @@ if (!defined('_ADODB_LAYER')) { } + /** + * Return the database server's current date and time. + * @return int|false + */ function Time() { $rs = $this->_Execute("select $this->sysTimeStamp"); if ($rs && !$rs->EOF) { @@ -633,23 +650,43 @@ if (!defined('_ADODB_LAYER')) { } /** - * Connect to database + * Parses the hostname to extract the port. + * Overwrites $this->host and $this->port, only if a port is specified. + * The Hostname can be fully or partially qualified, + * ie: "db.mydomain.com:5432" or "ldaps://ldap.mydomain.com:636" + * Any specified scheme such as ldap:// or ldaps:// is maintained. + */ + protected function parseHostNameAndPort() { + $parsed_url = parse_url($this->host); + if (is_array($parsed_url) && isset($parsed_url['host']) && isset($parsed_url['port'])) { + if ( isset($parsed_url['scheme']) ) { + // If scheme is specified (ie: ldap:// or ldaps://, make sure we retain that. + $this->host = $parsed_url['scheme'] . "://" . $parsed_url['host']; + } else { + $this->host = $parsed_url['host']; + } + $this->port = $parsed_url['port']; + } + } + + /** + * Connect to database. * - * @param [argHostname] Host to connect to - * @param [argUsername] Userid to login - * @param [argPassword] Associated password - * @param [argDatabaseName] database - * @param [forceNew] force new connection + * @param string $argHostname Host to connect to + * @param string $argUsername Userid to login + * @param string $argPassword Associated password + * @param string $argDatabaseName Database name + * @param bool $forceNew Force new connection * - * @return true or false + * @return bool */ function Connect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "", $forceNew = false) { if ($argHostname != "") { $this->host = $argHostname; } - if ( strpos($this->host, ':') > 0 && isset($this->port) ) { - list($this->host, $this->port) = explode(":", $this->host, 2); - } + // Overwrites $this->host and $this->port if a port is specified. + $this->parseHostNameAndPort(); + if ($argUsername != "") { $this->user = $argUsername; } @@ -696,30 +733,31 @@ if (!defined('_ADODB_LAYER')) { return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabaseName); } - /** - * Always force a new connection to database - currently only works with oracle + * Always force a new connection to database. + * + * Currently this only works with Oracle. * - * @param [argHostname] Host to connect to - * @param [argUsername] Userid to login - * @param [argPassword] Associated password - * @param [argDatabaseName] database + * @param string $argHostname Host to connect to + * @param string $argUsername Userid to login + * @param string $argPassword Associated password + * @param string $argDatabaseName Database name * - * @return true or false + * @return bool */ function NConnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "") { return $this->Connect($argHostname, $argUsername, $argPassword, $argDatabaseName, true); } /** - * Establish persistent connect to database + * Establish persistent connection to database. * - * @param [argHostname] Host to connect to - * @param [argUsername] Userid to login - * @param [argPassword] Associated password - * @param [argDatabaseName] database + * @param string $argHostname Host to connect to + * @param string $argUsername Userid to login + * @param string $argPassword Associated password + * @param string $argDatabaseName Database name * - * @return return true or false + * @return bool */ function PConnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "") { @@ -730,9 +768,9 @@ if (!defined('_ADODB_LAYER')) { if ($argHostname != "") { $this->host = $argHostname; } - if ( strpos($this->host, ':') > 0 && isset($this->port) ) { - list($this->host, $this->port) = explode(":", $this->host, 2); - } + // Overwrites $this->host and $this->port if a port is specified. + $this->parseHostNameAndPort(); + if ($argUsername != "") { $this->user = $argUsername; } @@ -756,7 +794,7 @@ if (!defined('_ADODB_LAYER')) { $ret = false; } else { $err = "Missing extension for ".$this->dataProvider; - $ret = 0; + $ret = false; } if ($fn = $this->raiseErrorFn) { $fn($this->databaseType,'PCONNECT',$this->ErrorNo(),$err,$this->host,$this->database,$this); @@ -777,7 +815,11 @@ if (!defined('_ADODB_LAYER')) { ADOConnection::outp($msg); } - // create cache class. Code is backward compat with old memcache implementation + /** + * Create cache class. + * + * Code is backwards-compatible with old memcache implementation. + */ function _CreateCache() { global $ADODB_CACHE, $ADODB_CACHE_CLASS; @@ -793,8 +835,16 @@ if (!defined('_ADODB_LAYER')) { } } - // Format date column in sql string given an input format that understands Y M D - function SQLDate($fmt, $col=false) { + /** + * Format date column in sql string. + * + * See https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:sqldate + * for documentation on supported formats. + * + * @param string $fmt Format string + * @param string $col Date column; use system date if not specified. + */ + function SQLDate($fmt, $col = '') { if (!$col) { $col = $this->sysDate; } @@ -802,7 +852,8 @@ if (!defined('_ADODB_LAYER')) { } /** - * Should prepare the sql statement and return the stmt resource. + * Prepare an sql statement and return the statement resource. + * * For databases that do not support this, we return the $sql. To ensure * compatibility with databases that do not support prepare: * @@ -810,53 +861,47 @@ if (!defined('_ADODB_LAYER')) { * $db->Execute($stmt,array(1,'Jill')) or die('insert failed'); * $db->Execute($stmt,array(2,'Joe')) or die('insert failed'); * - * @param sql SQL to send to database - * - * @return return FALSE, or the prepared statement, or the original sql if - * if the database does not support prepare. + * @param string $sql SQL to send to database * + * @return mixed|false The prepared statement, or the original sql if the + * database does not support prepare. */ function Prepare($sql) { return $sql; } /** + * Prepare a Stored Procedure and return the statement resource. + * * Some databases, eg. mssql require a different function for preparing * stored procedures. So we cannot use Prepare(). * - * Should prepare the stored procedure and return the stmt resource. - * For databases that do not support this, we return the $sql. To ensure - * compatibility with databases that do not support prepare: - * - * @param sql SQL to send to database + * For databases that do not support this, we return the $sql. * - * @return return FALSE, or the prepared statement, or the original sql if - * if the database does not support prepare. + * @param string $sql SQL to send to database + * @param bool $param * + * @return mixed|false The prepared statement, or the original sql if the + * database does not support prepare. */ function PrepareSP($sql,$param=true) { return $this->Prepare($sql,$param); } /** - * PEAR DB Compat - */ - function Quote($s) { - return $this->qstr($s,false); - } - - /** - * Requested by "Karsten Dambekalns" <k.dambekalns@fishfarm.de> + * PEAR DB Compat - alias for qStr. + * @param $s + * @return string */ - function QMagic($s) { - return $this->qstr($s,get_magic_quotes_gpc()); + function Quote($s) { + return $this->qstr($s); } function q(&$s) { //if (!empty($this->qNull && $s == 'null') { // return $s; //} - $s = $this->qstr($s,false); + $s = $this->qstr($s); } /** @@ -878,17 +923,26 @@ if (!defined('_ADODB_LAYER')) { * Lock a row, will escalate and lock the table if row locking not supported * will normally free the lock at the end of the transaction * - * @param $table name of table to lock - * @param $where where clause to use, eg: "WHERE row=12". If left empty, will escalate to table lock + * @param string $table name of table to lock + * @param string $where where clause to use, eg: "WHERE row=12". If left empty, will escalate to table lock + * @param string $col */ function RowLock($table,$where,$col='1 as adodbignore') { return false; } + /** + * @param string $table + * @return true + */ function CommitLock($table) { return $this->CommitTrans(); } + /** + * @param string $table + * @return true + */ function RollbackLock($table) { return $this->RollbackTrans(); } @@ -899,8 +953,9 @@ if (!defined('_ADODB_LAYER')) { * The fetch modes for NUMERIC and ASSOC for PEAR DB and ADODB are identical * for easy porting :-) * - * @param mode The fetchmode ADODB_FETCH_ASSOC or ADODB_FETCH_NUM - * @returns The previous fetch mode + * @param int $mode The fetchmode ADODB_FETCH_ASSOC or ADODB_FETCH_NUM + * + * @return int Previous fetch mode */ function SetFetchMode($mode) { $old = $this->fetchMode; @@ -916,6 +971,11 @@ if (!defined('_ADODB_LAYER')) { /** * PEAR DB Compat - do not use internally. + * + * @param string $sql + * @param array|bool $inputarr + * + * @return ADORecordSet|bool */ function Query($sql, $inputarr=false) { $rs = $this->Execute($sql, $inputarr); @@ -927,8 +987,8 @@ if (!defined('_ADODB_LAYER')) { /** - * PEAR DB Compat - do not use internally - */ + * PEAR DB Compat - do not use internally + */ function LimitQuery($sql, $offset, $count, $params=false) { $rs = $this->SelectLimit($sql, $count, $offset, $params); if (!$rs && defined('ADODB_PEAR')) { @@ -939,22 +999,26 @@ if (!defined('_ADODB_LAYER')) { /** - * PEAR DB Compat - do not use internally - */ + * PEAR DB Compat - do not use internally + */ function Disconnect() { return $this->Close(); } /** - * Returns a placeholder for query parameters + * Returns a placeholder for query parameters. + * * e.g. $DB->Param('a') will return * - '?' for most databases * - ':a' for Oracle * - '$1', '$2', etc. for PostgreSQL - * @param string $name parameter's name, false to force a reset of the - * number to 1 (for databases that require positioned - * params such as PostgreSQL; note that ADOdb will - * automatically reset this when executing a query ) + * + * @param mixed $name parameter's name. + * For databases that require positioned params (e.g. PostgreSQL), + * a "falsy" value can be used to force resetting the placeholder + * count; using boolean 'false' will reset it without actually + * returning a placeholder. ADOdb will also automatically reset + * the count when executing a query. * @param string $type (unused) * @return string query parameter placeholder */ @@ -1102,11 +1166,14 @@ if (!defined('_ADODB_LAYER')) { /** * Execute SQL * - * @param sql SQL statement to execute, or possibly an array holding prepared statement ($sql[0] will hold sql text) - * @param [inputarr] holds the input data to bind to. Null elements will be set to null. - * @return RecordSet or false + * @param string $sql SQL statement to execute, or possibly an array + * holding prepared statement ($sql[0] will hold sql text) + * @param array|bool $inputarr holds the input data to bind to. + * Null elements will be set to null. + * + * @return ADORecordSet|bool */ - function Execute($sql,$inputarr=false) { + public function Execute($sql, $inputarr = false) { if ($this->fnExecute) { $fn = $this->fnExecute; $ret = $fn($this,$sql,$inputarr); @@ -1163,8 +1230,7 @@ if (!defined('_ADODB_LAYER')) { foreach($inputarr as $arr) { $sql = ''; $i = 0; - //Use each() instead of foreach to reduce memory usage -mikefedyk - while(list(, $v) = each($arr)) { + foreach ($arr as $v) { $sql .= $sqlarr[$i]; // from Ron Baldwin <ron.baldwin#sourceprose.com> // Only quote string types @@ -1238,13 +1304,14 @@ if (!defined('_ADODB_LAYER')) { if( is_string($sql) ) { // Strips keyword used to help generate SELECT COUNT(*) queries // from SQL if it exists. - $sql = ADODB_str_replace( '_ADODB_COUNT', '', $sql ); + // TODO: obsoleted by #715 - kept for backwards-compatibility + $sql = str_replace( '_ADODB_COUNT', '', $sql ); } if ($this->debug) { global $ADODB_INCLUDED_LIB; if (empty($ADODB_INCLUDED_LIB)) { - include(ADODB_DIR.'/adodb-lib.inc.php'); + include_once(ADODB_DIR.'/adodb-lib.inc.php'); } $this->_queryID = _adodb_debug_execute($this, $sql,$inputarr); } else { @@ -1275,8 +1342,17 @@ if (!defined('_ADODB_LAYER')) { return $rs; } + if ($this->dataProvider == 'pdo' && $this->databaseType != 'pdo') { + // PDO uses a slightly different naming convention for the + // recordset class if the database type is changed, so we must + // treat it specifically. The mysql driver leaves the + // databaseType as pdo + $rsclass = $this->rsPrefix . 'pdo_' . $this->databaseType; + } else { + $rsclass = $this->rsPrefix . $this->databaseType; + } + // return real recordset from select statement - $rsclass = $this->rsPrefix.$this->databaseType; $rs = new $rsclass($this->_queryID,$this->fetchMode); $rs->connection = $this; // Pablo suggestion $rs->Init(); @@ -1313,12 +1389,14 @@ if (!defined('_ADODB_LAYER')) { } /** - * Generates a sequence id and stores it in $this->genID; + * Generates a sequence id and stores it in $this->genID. + * * GenID is only available if $this->hasGenID = true; * - * @param seqname name of sequence to use - * @param startID if sequence does not exist, start at this ID - * @return 0 if not supported, otherwise a sequence id + * @param string $seqname Name of sequence to use + * @param int $startID If sequence does not exist, start at this ID + * + * @return int Sequence id, 0 if not supported */ function GenID($seqname='adodbseq',$startID=1) { if (!$this->hasGenID) { @@ -1353,16 +1431,22 @@ if (!defined('_ADODB_LAYER')) { } /** - * @param $table string name of the table, not needed by all databases (eg. mysql), default '' - * @param $column string name of the column, not needed by all databases (eg. mysql), default '' - * @return the last inserted ID. Not all databases support this. + * Returns the last inserted ID. + * + * Not all databases support this feature. Some do not require to specify + * table or column name (e.g. MySQL). + * + * @param string $table Table name, default '' + * @param string $column Column name, default '' + * + * @return int The last inserted ID. */ function Insert_ID($table='',$column='') { - if ($this->_logsql || $this->lastInsID) { + if ($this->_logsql && $this->lastInsID) { return $this->lastInsID; } if ($this->hasInsertID) { - return $this->_insertid($table,$column); + return $this->_insertID($table,$column); } if ($this->debug) { ADOConnection::outp( '<p>Insert_ID error</p>'); @@ -1371,12 +1455,37 @@ if (!defined('_ADODB_LAYER')) { return false; } + /** + * Enable or disable the Last Insert Id functionality. + * + * If the Driver supports it, this function allows setting {@see $hasInsertID}. + * + * @param bool $enable False to disable + */ + public function enableLastInsertID($enable = true) {} + + /** + * Return the id of the last row that has been inserted in a table. + * + * @param string $table + * @param string $column + * + * @return int|false + */ + protected function _insertID($table = '', $column = '') + { + return false; + } /** * Portable Insert ID. Pablo Roca <pabloroca#mvps.org> * - * @return the last inserted ID. All databases support this. But aware possible - * problems in multiuser environments. Heavy test this before deploying. + * @param string $table + * @param string $id + + * @return mixed The last inserted ID. All databases support this, but be + * aware of possible problems in multiuser environments. + * Heavily test this before deploying. */ function PO_Insert_ID($table="", $id="") { if ($this->hasInsertID){ @@ -1408,7 +1517,7 @@ if (!defined('_ADODB_LAYER')) { /** - * @return the last error message + * @return string the last error message */ function ErrorMsg() { if ($this->_errorMsg) { @@ -1420,7 +1529,7 @@ if (!defined('_ADODB_LAYER')) { /** - * @return the last error number. Normally 0 means no error. + * @return int the last error number. Normally 0 means no error. */ function ErrorNo() { return ($this->_errorMsg) ? -1 : 0; @@ -1471,13 +1580,15 @@ if (!defined('_ADODB_LAYER')) { /** * Choose a database to connect to. Many databases do not support this. * - * @param dbName is the name of the database to select - * @return true or false + * @param string $dbName the name of the database to select + * @return bool */ function SelectDB($dbName) {return false;} /** + * Select a limited number of rows. + * * Will select, getting rows from $offset (1-based), for $nrows. * This simulates the MySQL "select * from table limit $offset,$nrows" , and * the PostgreSQL "select * from table limit $nrows offset $offset". Note that @@ -1489,14 +1600,18 @@ if (!defined('_ADODB_LAYER')) { * Uses SELECT TOP for Microsoft databases (when $this->hasTop is set) * BUG: Currently SelectLimit fails with $sql with LIMIT or TOP clause already set * - * @param sql - * @param [offset] is the row to start calculations from (1-based) - * @param [nrows] is the number of rows to get - * @param [inputarr] array of bind variables - * @param [secs2cache] is a private parameter only used by jlim - * @return the recordset ($rs->databaseType == 'array') + * @param string $sql + * @param int $offset Row to start calculations from (1-based) + * @param int $nrows Number of rows to get + * @param array|bool $inputarr Array of bind variables + * @param int $secs2cache Private parameter only used by jlim + * + * @return ADORecordSet The recordset ($rs->databaseType == 'array') */ function SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) { + $nrows = (int)$nrows; + $offset = (int)$offset; + if ($this->hasTop && $nrows > 0) { // suggested by Reinhard Balling. Access requires top after distinct // Informix requires first before distinct - F Riosa @@ -1508,32 +1623,47 @@ if (!defined('_ADODB_LAYER')) { } if ($offset <= 0) { - // access includes ties in result - if ($isaccess) { - $sql = preg_replace( - '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop.' '.((integer)$nrows).' ',$sql); + // access includes ties in result + if ($isaccess) { + $sql = preg_replace( + '/(^\s*select\s+(distinctrow|distinct)?)/i', + '\\1 '.$this->hasTop.' '.$nrows.' ', + $sql + ); - if ($secs2cache != 0) { - $ret = $this->CacheExecute($secs2cache, $sql,$inputarr); - } else { - $ret = $this->Execute($sql,$inputarr); - } - return $ret; // PHP5 fix - } else if ($ismssql){ - $sql = preg_replace( - '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop.' '.((integer)$nrows).' ',$sql); + if ($secs2cache != 0) { + $ret = $this->CacheExecute($secs2cache, $sql,$inputarr); } else { - $sql = preg_replace( - '/(^\s*select\s)/i','\\1 '.$this->hasTop.' '.((integer)$nrows).' ',$sql); + $ret = $this->Execute($sql,$inputarr); } + return $ret; // PHP5 fix + } else if ($ismssql){ + $sql = preg_replace( + '/(^\s*select\s+(distinctrow|distinct)?)/i', + '\\1 '.$this->hasTop.' '.$nrows.' ', + $sql + ); + } else { + $sql = preg_replace( + '/(^\s*select\s)/i', + '\\1 '.$this->hasTop.' '.$nrows.' ', + $sql + ); + } } else { $nn = $nrows + $offset; if ($isaccess || $ismssql) { $sql = preg_replace( - '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop.' '.$nn.' ',$sql); + '/(^\s*select\s+(distinctrow|distinct)?)/i', + '\\1 '.$this->hasTop.' '.$nn.' ', + $sql + ); } else { $sql = preg_replace( - '/(^\s*select\s)/i','\\1 '.$this->hasTop.' '.$nn.' ',$sql); + '/(^\s*select\s)/i', + '\\1 '.$this->hasTop.' '.$nn.' ', + $sql + ); } } } @@ -1563,7 +1693,9 @@ if (!defined('_ADODB_LAYER')) { /** * Create serializable recordset. Breaks rs link to connection. * - * @param rs the recordset to serialize + * @param ADORecordSet $rs the recordset to serialize + * + * @return ADORecordSet_array|bool the new recordset */ function SerializableRS(&$rs) { $rs2 = $this->_rs2rs($rs); @@ -1574,18 +1706,21 @@ if (!defined('_ADODB_LAYER')) { } /** - * Convert database recordset to an array recordset - * input recordset's cursor should be at beginning, and - * old $rs will be closed. + * Convert a database recordset to an array recordset. + * + * Input recordset's cursor should be at beginning, and old $rs will be closed. * - * @param rs the recordset to copy - * @param [nrows] number of rows to retrieve (optional) - * @param [offset] offset by number of rows (optional) - * @return the new recordset + * @param ADORecordSet $rs the recordset to copy + * @param int $nrows number of rows to retrieve (optional) + * @param int $offset offset by number of rows (optional) + * @param bool $close + * + * @return ADORecordSet_array|ADORecordSet|bool the new recordset */ function &_rs2rs(&$rs,$nrows=-1,$offset=-1,$close=true) { if (! $rs) { - return false; + $ret = false; + return $ret; } $dbtype = $rs->databaseType; if (!$dbtype) { @@ -1620,23 +1755,58 @@ if (!defined('_ADODB_LAYER')) { } /* - * Return all rows. Compat with PEAR DB + * Return all rows. + * + * Compat with PEAR DB. + * + * @param string $sql SQL statement + * @param array|bool $inputarr Input bind array + * + * @return array|false */ function GetAll($sql, $inputarr=false) { - $arr = $this->GetArray($sql,$inputarr); - return $arr; + return $this->GetArray($sql,$inputarr); } - function GetAssoc($sql, $inputarr=false,$force_array = false, $first2cols = false) { + /** + * Execute statement and return rows in an array. + * + * The function executes a statement and returns all of the returned rows in + * an array, or false if the statement execution fails or if only 1 column + * is requested in the SQL statement. + * If no records match the provided SQL statement, an empty array is returned. + * + * @param string $sql SQL statement + * @param array|bool $inputarr input bind array + * @param bool $force_array + * @param bool $first2cols + * + * @return array|bool + */ + public function GetAssoc($sql, $inputarr = false, $force_array = false, $first2cols = false) { $rs = $this->Execute($sql, $inputarr); + if (!$rs) { + /* + * Execution failure + */ return false; } - $arr = $rs->GetAssoc($force_array,$first2cols); - return $arr; + return $rs->GetAssoc($force_array, $first2cols); } - function CacheGetAssoc($secs2cache, $sql=false, $inputarr=false,$force_array = false, $first2cols = false) { + /** + * Search for the results of an executed query in the cache. + * + * @param int $secs2cache + * @param string|bool $sql SQL statement + * @param array|bool $inputarr input bind array + * @param bool $force_array + * @param bool $first2cols + * + * @return false|array + */ + public function CacheGetAssoc($secs2cache, $sql = false, $inputarr = false,$force_array = false, $first2cols = false) { if (!is_numeric($secs2cache)) { $first2cols = $force_array; $force_array = $inputarr; @@ -1645,18 +1815,18 @@ if (!defined('_ADODB_LAYER')) { if (!$rs) { return false; } - $arr = $rs->GetAssoc($force_array,$first2cols); - return $arr; + return $rs->GetAssoc($force_array, $first2cols); } /** - * Return first element of first row of sql statement. Recordset is disposed - * for you. - * - * @param sql SQL statement - * @param [inputarr] input bind array - */ - function GetOne($sql,$inputarr=false) { + * Return first element of first row of sql statement. Recordset is disposed + * for you. + * + * @param string $sql SQL statement + * @param array|bool $inputarr input bind array + * @return mixed + */ + public function GetOne($sql, $inputarr=false) { global $ADODB_COUNTRECS,$ADODB_GETONE_EOF; $crecs = $ADODB_COUNTRECS; @@ -1710,6 +1880,17 @@ if (!defined('_ADODB_LAYER')) { return $ret; } + /** + * Executes a statement and returns each row's first column in an array. + * + * @param string $sql SQL statement + * @param array|bool $inputarr input bind array + * @param bool $trim enables space trimming of the returned value. + * This is only relevant if the returned string + * is coming from a CHAR type field. + * + * @return array|bool 1D array containning the first row of the query + */ function GetCol($sql, $inputarr = false, $trim = false) { $rs = $this->Execute($sql, $inputarr); @@ -1781,10 +1962,13 @@ if (!defined('_ADODB_LAYER')) { /** - * - * @param sql SQL statement - * @param [inputarr] input bind array - */ + * Executes a statement and returns a the entire recordset in an array. + * + * @param string $sql SQL statement + * @param array|bool $inputarr input bind array + * + * @return array|false + */ function GetArray($sql,$inputarr=false) { global $ADODB_COUNTRECS; @@ -1794,8 +1978,7 @@ if (!defined('_ADODB_LAYER')) { $ADODB_COUNTRECS = $savec; if (!$rs) if (defined('ADODB_PEAR')) { - $cls = ADODB_PEAR_Error(); - return $cls; + return ADODB_PEAR_Error(); } else { return false; } @@ -1805,8 +1988,7 @@ if (!defined('_ADODB_LAYER')) { } function CacheGetAll($secs2cache,$sql=false,$inputarr=false) { - $arr = $this->CacheGetArray($secs2cache,$sql,$inputarr); - return $arr; + return $this->CacheGetArray($secs2cache,$sql,$inputarr); } function CacheGetArray($secs2cache,$sql=false,$inputarr=false) { @@ -1819,8 +2001,7 @@ if (!defined('_ADODB_LAYER')) { if (!$rs) if (defined('ADODB_PEAR')) { - $cls = ADODB_PEAR_Error(); - return $cls; + return ADODB_PEAR_Error(); } else { return false; } @@ -1839,8 +2020,10 @@ if (!defined('_ADODB_LAYER')) { * Return one row of sql statement. Recordset is disposed for you. * Note that SelectLimit should not be called. * - * @param sql SQL statement - * @param [inputarr] input bind array + * @param string $sql SQL statement + * @param array|bool $inputarr input bind array + * + * @return array|false Array containing the first row of the query */ function GetRow($sql,$inputarr=false) { global $ADODB_COUNTRECS; @@ -1864,6 +2047,12 @@ if (!defined('_ADODB_LAYER')) { return false; } + /** + * @param int $secs2cache + * @param string|false $sql + * @param mixed[]|bool $inputarr + * @return mixed[]|bool + */ function CacheGetRow($secs2cache,$sql=false,$inputarr=false) { $rs = $this->CacheExecute($secs2cache,$sql,$inputarr); if ($rs) { @@ -1890,7 +2079,7 @@ if (!defined('_ADODB_LAYER')) { * $table table name * $fieldArray associative array of data (you must quote strings yourself). * $keyCol the primary key field name or if compound key, array of field names - * autoQuote set to true to use a hueristic to quote strings. Works with nulls and numbers + * autoQuote set to true to use a heuristic to quote strings. Works with nulls and numbers * but does not work with dates nor SQL functions. * has_autoinc the primary key is an auto-inc field, so skip in insert. * @@ -1902,7 +2091,7 @@ if (!defined('_ADODB_LAYER')) { function Replace($table, $fieldArray, $keyCol, $autoQuote=false, $has_autoinc=false) { global $ADODB_INCLUDED_LIB; if (empty($ADODB_INCLUDED_LIB)) { - include(ADODB_DIR.'/adodb-lib.inc.php'); + include_once(ADODB_DIR.'/adodb-lib.inc.php'); } return _adodb_replace($this, $table, $fieldArray, $keyCol, $autoQuote, $has_autoinc); @@ -1920,12 +2109,13 @@ if (!defined('_ADODB_LAYER')) { * * BUG: Currently CacheSelectLimit fails with $sql with LIMIT or TOP clause already set * - * @param [secs2cache] seconds to cache data, set to 0 to force query. This is optional - * @param sql - * @param [offset] is the row to start calculations from (1-based) - * @param [nrows] is the number of rows to get - * @param [inputarr] array of bind variables - * @return the recordset ($rs->databaseType == 'array') + * @param int $secs2cache Seconds to cache data, set to 0 to force query. This is optional + * @param string $sql + * @param int $offset Row to start calculations from (1-based) + * @param int $nrows Number of rows to get + * @param array $inputarr Array of bind variables + * + * @return ADORecordSet The recordset ($rs->databaseType == 'array') */ function CacheSelectLimit($secs2cache,$sql,$nrows=-1,$offset=-1,$inputarr=false) { if (!is_numeric($secs2cache)) { @@ -2008,11 +2198,12 @@ if (!defined('_ADODB_LAYER')) { /** * Execute SQL, caching recordsets. * - * @param [secs2cache] seconds to cache data, set to 0 to force query. - * This is an optional parameter. - * @param sql SQL statement to execute - * @param [inputarr] holds the input data to bind to - * @return RecordSet or false + * @param int $secs2cache Seconds to cache data, set to 0 to force query. + * This is an optional parameter. + * @param string|bool $sql SQL statement to execute + * @param array|bool $inputarr Holds the input data to bind + * + * @return ADORecordSet RecordSet or false */ function CacheExecute($secs2cache,$sql=false,$inputarr=false) { global $ADODB_CACHE; @@ -2047,11 +2238,8 @@ if (!defined('_ADODB_LAYER')) { } if (!$rs) { - // no cached rs found + // no cached rs found if ($this->debug) { - if (get_magic_quotes_runtime() && !$this->memCache) { - ADOConnection::outp("Please disable magic_quotes_runtime - it corrupts cache files :("); - } if ($this->debug !== -1) { ADOConnection::outp( " $md5file cache failure: $err (this is a notice and not an error)"); } @@ -2122,13 +2310,32 @@ if (!defined('_ADODB_LAYER')) { /* - Similar to PEAR DB's autoExecute(), except that - $mode can be 'INSERT' or 'UPDATE' or DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE - If $mode == 'UPDATE', then $where is compulsory as a safety measure. - $forceUpdate means that even if the data has not changed, perform update. + + $forceUpdate . */ - function AutoExecute($table, $fields_values, $mode = 'INSERT', $where = false, $forceUpdate = true, $magicq = false) { + /** + * Similar to PEAR DB's autoExecute(), except that $mode can be 'INSERT' + * or 'UPDATE' or DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE. + * If $mode == 'UPDATE', then $where is compulsory as a safety measure. + * + * @param $table + * @param $fields_values + * @param string $mode + * @param false $where + * @param bool $forceUpdate If true, perform update even if the data has not changed. + * @param bool $magic_quotes This param is not used since 5.21.0. + * It remains for backwards compatibility. + * + * @return bool + * + * @noinspection PhpUnusedParameterInspection + */ + function AutoExecute($table, $fields_values, $mode = 'INSERT', $where = false, $forceUpdate = true, $magic_quotes = false) { + if (empty($fields_values)) { + $this->outp_throw('AutoExecute: Empty fields array', 'AutoExecute'); + return false; + } if ($where === false && ($mode == 'UPDATE' || $mode == 2 /* DB_AUTOQUERY_UPDATE */) ) { $this->outp_throw('AutoExecute: Illegal mode=UPDATE with empty WHERE clause', 'AutoExecute'); return false; @@ -2149,11 +2356,11 @@ if (!defined('_ADODB_LAYER')) { switch($mode) { case 'UPDATE': case DB_AUTOQUERY_UPDATE: - $sql = $this->GetUpdateSQL($rs, $fields_values, $forceUpdate, $magicq); + $sql = $this->GetUpdateSQL($rs, $fields_values, $forceUpdate); break; case 'INSERT': case DB_AUTOQUERY_INSERT: - $sql = $this->GetInsertSQL($rs, $fields_values, $magicq); + $sql = $this->GetInsertSQL($rs, $fields_values); break; default: $this->outp_throw("AutoExecute: Unknown mode=$mode", 'AutoExecute'); @@ -2165,16 +2372,27 @@ if (!defined('_ADODB_LAYER')) { /** * Generates an Update Query based on an existing recordset. + * * $arrFields is an associative array of fields with the value * that should be assigned. * * Note: This function should only be used on a recordset - * that is run against a single table and sql should only - * be a simple select stmt with no groupby/orderby/limit + * that is run against a single table and sql should only + * be a simple select stmt with no groupby/orderby/limit + * @author "Jonathan Younger" <jyounger@unilab.com> + * + * @param $rs + * @param $arrFields + * @param bool $forceUpdate + * @param bool $magic_quotes This param is not used since 5.21.0. + * It remains for backwards compatibility. + * @param null $force + * + * @return false|string * - * "Jonathan Younger" <jyounger@unilab.com> + * @noinspection PhpUnusedParameterInspection */ - function GetUpdateSQL(&$rs, $arrFields,$forceUpdate=false,$magicq=false,$force=null) { + function GetUpdateSQL(&$rs, $arrFields, $forceUpdate=false, $magic_quotes=false, $force=null) { global $ADODB_INCLUDED_LIB; // ******************************************************** @@ -2187,29 +2405,40 @@ if (!defined('_ADODB_LAYER')) { // ******************************************************** if (empty($ADODB_INCLUDED_LIB)) { - include(ADODB_DIR.'/adodb-lib.inc.php'); + include_once(ADODB_DIR.'/adodb-lib.inc.php'); } - return _adodb_getupdatesql($this,$rs,$arrFields,$forceUpdate,$magicq,$force); + return _adodb_getupdatesql($this, $rs, $arrFields, $forceUpdate, $force); } /** * Generates an Insert Query based on an existing recordset. + * * $arrFields is an associative array of fields with the value * that should be assigned. * * Note: This function should only be used on a recordset * that is run against a single table. + * + * @param $rs + * @param $arrFields + * @param bool $magic_quotes This param is not used since 5.21.0. + * It remains for backwards compatibility. + * @param null $force + * + * @return false|string + * + * @noinspection PhpUnusedParameterInspection */ - function GetInsertSQL(&$rs, $arrFields,$magicq=false,$force=null) { + function GetInsertSQL(&$rs, $arrFields, $magic_quotes=false, $force=null) { global $ADODB_INCLUDED_LIB; if (!isset($force)) { global $ADODB_FORCE_TYPE; $force = $ADODB_FORCE_TYPE; } if (empty($ADODB_INCLUDED_LIB)) { - include(ADODB_DIR.'/adodb-lib.inc.php'); + include_once(ADODB_DIR.'/adodb-lib.inc.php'); } - return _adodb_getinsertsql($this,$rs,$arrFields,$magicq,$force); + return _adodb_getinsertsql($this, $rs, $arrFields, $force); } @@ -2262,11 +2491,26 @@ if (!defined('_ADODB_LAYER')) { return $blob; } - function GetCharSet() { + /** + * Retrieve the client connection's current character set. + * + * @return string|false The character set, or false if it can't be determined. + */ + function getCharSet() { return $this->charSet; } - function SetCharSet($charset) { + /** + * Sets the client-side character set. + * + * This is only supported for some databases. + * @see https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:setcharset + * + * @param string $charset The character set to switch to. + * + * @return bool True if the character set was changed successfully, false otherwise. + */ + function setCharSet($charset) { $this->charSet = $charset; return true; } @@ -2392,6 +2636,7 @@ if (!defined('_ADODB_LAYER')) { */ function Close() { $rez = $this->_close(); + $this->_queryID = false; $this->_connectionID = false; return $rez; } @@ -2399,7 +2644,7 @@ if (!defined('_ADODB_LAYER')) { /** * Begin a Transaction. Must be followed by CommitTrans() or RollbackTrans(). * - * @return true if succeeded or false if database does not support transactions + * @return bool true if succeeded or false if database does not support transactions */ function BeginTrans() { if ($this->debug) { @@ -2459,9 +2704,9 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 } /** - * If database does not support transactions, always return true as data always commited + * If database does not support transactions, always return true as data always committed * - * @param $ok set to false to rollback transaction, true to commit + * @param bool $ok set to false to rollback transaction, true to commit * * @return true/false. */ @@ -2473,7 +2718,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** * If database does not support transactions, rollbacks always fail, so return false * - * @return true/false. + * @return bool */ function RollbackTrans() { return false; @@ -2484,7 +2729,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 * return the databases that the driver can connect to. * Some databases will return an empty array. * - * @return an array of database names. + * @return array|bool an array of database names. */ function MetaDatabases() { global $ADODB_FETCH_MODE; @@ -2708,14 +2953,16 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 } /** + * Concatenate strings. + * * Different SQL databases used different methods to combine strings together. * This function provides a wrapper. * - * param s variable number of string parameters - * * Usage: $db->Concat($str1,$str2); * - * @return concatenated string + * @param string $s Variable number of string parameters + * + * @return string concatenated string */ function Concat() { $arr = func_get_args(); @@ -2726,9 +2973,9 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** * Converts a date "d" to a string that the database can understand. * - * @param d a date in Unix date time format. + * @param mixed $d a date in Unix date time format. * - * @return date string in database date format + * @return string date string in database date format */ function DBDate($d, $isfld=false) { if (empty($d) && $d !== 0) { @@ -2780,9 +3027,9 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** * Converts a timestamp "ts" to a string that the database can understand. * - * @param ts a timestamp in Unix date time format. + * @param int|object $ts A timestamp in Unix date time format. * - * @return timestamp string in database timestamp format + * @return string $timestamp string in database timestamp format */ function DBTimeStamp($ts,$isfld=false) { if (empty($ts) && $ts !== 0) { @@ -2813,9 +3060,9 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** * Also in ADORecordSet. - * @param $v is a date string in YYYY-MM-DD format + * @param mixed $v is a date string in YYYY-MM-DD format * - * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format + * @return int|false Date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format */ static function UnixDate($v) { if (is_object($v)) { @@ -2842,9 +3089,9 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** * Also in ADORecordSet. - * @param $v is a timestamp string in YYYY-MM-DD HH-NN-SS format + * @param string|object $v is a timestamp string in YYYY-MM-DD HH-NN-SS format * - * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format + * @return int|false Date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format */ static function UnixTimeStamp($v) { if (is_object($v)) { @@ -2869,14 +3116,15 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 } /** - * Also in ADORecordSet. - * * Format database date based on user defined format. * - * @param v is the character date in YYYY-MM-DD format, returned by database - * @param fmt is the format to apply to it, using date() + * Also in ADORecordSet. + * + * @param mixed $v Date in YYYY-MM-DD format, returned by database + * @param string $fmt Format to apply, using date() + * @param bool $gmt * - * @return a date formated as user desires + * @return string Formatted date */ function UserDate($v,$fmt='Y-m-d',$gmt=false) { $tt = $this->UnixDate($v); @@ -2895,11 +3143,13 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 } /** + * Format timestamp based on user defined format. * - * @param v is the character timestamp in YYYY-MM-DD hh:mm:ss format - * @param fmt is the format to apply to it, using date() + * @param mixed $v Date in YYYY-MM-DD hh:mm:ss format + * @param string $fmt Format to apply, using date() + * @param bool $gmt * - * @return a timestamp formated as user desires + * @return string Formatted timestamp */ function UserTimeStamp($v,$fmt='Y-m-d H:i:s',$gmt=false) { if (!isset($v)) { @@ -2920,92 +3170,80 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 return ($gmt) ? adodb_gmdate($fmt,$tt) : adodb_date($fmt,$tt); } + /** + * Alias for addQ() + * @param string $s + * @param bool [$magic_quotes] + * @return mixed + * + * @deprecated 5.21.0 + * @noinspection PhpUnusedParameterInspection + */ function escape($s,$magic_quotes=false) { - return $this->addq($s,$magic_quotes); + return $this->addQ($s); } /** - * Quotes a string, without prefixing nor appending quotes. - */ - function addq($s,$magic_quotes=false) { - if (!$magic_quotes) { - if ($this->replaceQuote[0] == '\\') { - // only since php 4.0.5 - $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s); - //$s = str_replace("\0","\\\0", str_replace('\\','\\\\',$s)); - } - return str_replace("'",$this->replaceQuote,$s); - } - - // undo magic quotes for " - $s = str_replace('\\"','"',$s); - - if ($this->replaceQuote == "\\'" || ini_get('magic_quotes_sybase')) { - // ' already quoted, no need to change anything - return $s; - } else { - // change \' to '' for sybase/mssql - $s = str_replace('\\\\','\\',$s); - return str_replace("\\'",$this->replaceQuote,$s); + * Quotes a string, without prefixing nor appending quotes. + * + * @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 + * + * @noinspection PhpUnusedParameterInspection + */ + function addQ($s, $magic_quotes=false) { + if ($this->replaceQuote[0] == '\\') { + $s = str_replace( + array('\\', "\0"), + array('\\\\', "\\\0"), + $s + ); } + return str_replace("'", $this->replaceQuote, $s); } /** - * Correctly quotes a string so that all strings are escaped. We prefix and append - * to the string single-quotes. - * An example is $db->qstr("Don't bother",magic_quotes_runtime()); + * Correctly quotes a string so that all strings are escaped. + * We prefix and append to the string single-quotes. + * An example is $db->qstr("Don't bother"); + * @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. * - * @param s the string to quote - * @param [magic_quotes] if $s is GET/POST var, set to get_magic_quotes_gpc(). - * This undoes the stupidity of magic quotes for GPC. + * @return string Quoted string to be sent back to database * - * @return quoted string to be sent back to database + * @noinspection PhpUnusedParameterInspection */ - function qstr($s,$magic_quotes=false) { - if (!$magic_quotes) { - if ($this->replaceQuote[0] == '\\'){ - // only since php 4.0.5 - $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s); - //$s = str_replace("\0","\\\0", str_replace('\\','\\\\',$s)); - } - return "'".str_replace("'",$this->replaceQuote,$s)."'"; - } - - // undo magic quotes for " - $s = str_replace('\\"','"',$s); - - if ($this->replaceQuote == "\\'" || ini_get('magic_quotes_sybase')) { - // ' already quoted, no need to change anything - return "'$s'"; - } else { - // change \' to '' for sybase/mssql - $s = str_replace('\\\\','\\',$s); - return "'".str_replace("\\'",$this->replaceQuote,$s)."'"; - } + function qStr($s, $magic_quotes=false) { + return "'" . $this->addQ($s) . "'"; } /** - * Will select the supplied $page number from a recordset, given that it is paginated in pages of - * $nrows rows per page. It also saves two boolean values saying if the given page is the first - * and/or last one of the recordset. Added by Iván Oliva to provide recordset pagination. - * - * See docs-adodb.htm#ex8 for an example of usage. - * - * @param sql - * @param nrows is the number of rows per page to get - * @param page is the page number to get (1-based) - * @param [inputarr] array of bind variables - * @param [secs2cache] is a private parameter only used by jlim - * @return the recordset ($rs->databaseType == 'array') - * - * NOTE: phpLens uses a different algorithm and does not use PageExecute(). - * - */ + * Will select the supplied $page number from a recordset, given that it is paginated in pages of + * $nrows rows per page. It also saves two boolean values saying if the given page is the first + * and/or last one of the recordset. Added by Iván Oliva to provide recordset pagination. + * + * See docs-adodb.htm#ex8 for an example of usage. + * NOTE: phpLens uses a different algorithm and does not use PageExecute(). + * + * @param string $sql + * @param int $nrows Number of rows per page to get + * @param int $page Page number to get (1-based) + * @param mixed[]|bool $inputarr Array of bind variables + * @param int $secs2cache Private parameter only used by jlim + * + * @return mixed the recordset ($rs->databaseType == 'array') + */ function PageExecute($sql, $nrows, $page, $inputarr=false, $secs2cache=0) { global $ADODB_INCLUDED_LIB; if (empty($ADODB_INCLUDED_LIB)) { - include(ADODB_DIR.'/adodb-lib.inc.php'); + include_once(ADODB_DIR.'/adodb-lib.inc.php'); } if ($this->pageExecuteCountRows) { $rs = _adodb_pageexecute_all_rows($this, $sql, $nrows, $page, $inputarr, $secs2cache); @@ -3021,12 +3259,12 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 * $nrows rows per page. It also saves two boolean values saying if the given page is the first * and/or last one of the recordset. Added by Iván Oliva to provide recordset pagination. * - * @param secs2cache seconds to cache data, set to 0 to force query - * @param sql - * @param nrows is the number of rows per page to get - * @param page is the page number to get (1-based) - * @param [inputarr] array of bind variables - * @return the recordset ($rs->databaseType == 'array') + * @param int $secs2cache seconds to cache data, set to 0 to force query + * @param string $sql + * @param int $nrows is the number of rows per page to get + * @param int $page is the page number to get (1-based) + * @param mixed[]|bool $inputarr array of bind variables + * @return mixed the recordset ($rs->databaseType == 'array') */ function CachePageExecute($secs2cache, $sql, $nrows, $page,$inputarr=false) { /*switch($this->dataProvider) { @@ -3035,8 +3273,134 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 break; default: $secs2cache = 0; break; }*/ - $rs = $this->PageExecute($sql,$nrows,$page,$inputarr,$secs2cache); - return $rs; + return $this->PageExecute($sql,$nrows,$page,$inputarr,$secs2cache); + } + + /** + * Returns the maximum size of a MetaType C field. If the method + * is not defined in the driver returns ADODB_STRINGMAX_NOTSET + * + * @return int + */ + function charMax() { + return ADODB_STRINGMAX_NOTSET; + } + + /** + * Returns the maximum size of a MetaType X field. If the method + * is not defined in the driver returns ADODB_STRINGMAX_NOTSET + * + * @return int + */ + function textMax() { + return ADODB_STRINGMAX_NOTSET; + } + + /** + * Returns a substring of a varchar type field + * + * Some databases have variations of the parameters, which is why + * we have an ADOdb function for it + * + * @param string $fld The field to sub-string + * @param int $start The start point + * @param int $length An optional length + * + * @return string The SQL text + */ + function substr($fld,$start,$length=0) { + $text = "{$this->substr}($fld,$start"; + if ($length > 0) + $text .= ",$length"; + $text .= ')'; + return $text; + } + + /* + * Formats the date into Month only format MM with leading zeroes + * + * @param string $fld The name of the date to format + * + * @return string The SQL text + */ + function month($fld) { + return $this->sqlDate('m',$fld); + } + + /* + * Formats the date into Day only format DD with leading zeroes + * + * @param string $fld The name of the date to format + * @return string The SQL text + */ + function day($fld) { + return $this->sqlDate('d',$fld); + } + + /* + * Formats the date into year only format YYYY + * + * @param string $fld The name of the date to format + * + * @return string The SQL text + */ + function year($fld) { + return $this->sqlDate('Y',$fld); + } + + /** + * Get the last error recorded by PHP and clear the message. + * + * By clearing the message, it becomes possible to detect whether a new error + * has occurred, even when it is the same error as before being repeated. + * + * @return mixed[]|null Array if an error has previously occurred. Null otherwise. + */ + protected function resetLastError() { + $error = error_get_last(); + + if (is_array($error)) { + $error['message'] = ''; + } + + return $error; + } + + /** + * Compare a previously stored error message with the last error recorded by PHP + * to determine whether a new error has occurred. + * + * @param mixed[]|null $old Optional. Previously stored return value of error_get_last(). + * + * @return string The error message if a new error has occurred + * or an empty string if no (new) errors have occurred.. + */ + protected function getChangedErrorMsg($old = null) { + $new = error_get_last(); + + if (is_null($new)) { + // No error has occurred yet at all. + return ''; + } + + if (is_null($old)) { + // First error recorded. + return $new['message']; + } + + $changed = false; + foreach($new as $key => $value) { + if ($new[$key] !== $old[$key]) { + $changed = true; + break; + } + } + + if ($changed === true) { + return $new['message']; + } + + return ''; } } // end class ADOConnection @@ -3101,6 +3465,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 var $databaseType = false; var $EOF = true; var $_numOfRows = 0; + /** @var bool|array */ var $fields = false; var $connection = false; @@ -3175,7 +3540,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 // DATE AND TIME FUNCTIONS //============================================================================================== if (!defined('ADODB_DATE_VERSION')) { - include(ADODB_DIR.'/adodb-time.inc.php'); + include_once(ADODB_DIR.'/adodb-time.inc.php'); } //============================================================================================== @@ -3233,6 +3598,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 * public variables */ var $dataProvider = "native"; + /** @var bool|array */ var $fields = false; /// holds the current row data var $blobSize = 100; /// any varchar/char field this size or greater is treated as a blob /// in other words, we use a text area for editing. @@ -3254,7 +3620,8 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 */ var $_numOfRows = -1; /** number of rows, or -1 */ var $_numOfFields = -1; /** number of fields in recordset */ - var $_queryID = -1; /** This variable keeps the result link identifier. */ + /** @var resource result link identifier */ + var $_queryID = -1; var $_currentRow = -1; /** This variable keeps the current row in the Recordset. */ var $_closed = false; /** has recordset been closed */ var $_inited = false; /** Init() should only be called once */ @@ -3268,10 +3635,16 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 var $_maxRecordCount = 0; var $datetime = false; + /** + * @var ADOFieldObject[] Field metadata cache + * @see fieldTypesArray() + */ + protected $fieldObjectsCache; + /** * Constructor * - * @param queryID this is the queryID returned by ADOConnection->_query() + * @param resource|int queryID this is the queryID returned by ADOConnection->_query() * */ function __construct($queryID) { @@ -3315,76 +3688,128 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** - * Generate a SELECT tag string from a recordset, and return the string. - * If the recordset has 2 cols, we treat the 1st col as the containing - * the text to display to the user, and 2nd col as the return value. Default - * strings are compared with the FIRST column. + * Generate a SELECT tag from a recordset, and return the HTML markup. * - * @param name name of SELECT tag - * @param [defstr] the value to hilite. Use an array for multiple hilites for listbox. - * @param [blank1stItem] true to leave the 1st item in list empty - * @param [multiple] true for listbox, false for popup - * @param [size] #rows to show for listbox. not used by popup - * @param [selectAttr] additional attributes to defined for SELECT tag. - * useful for holding javascript onChange='...' handlers. - & @param [compareFields0] when we have 2 cols in recordset, we compare the defstr with - * column 0 (1st col) if this is true. This is not documented. + * If the recordset has 2 columns, we treat the first one as the text to + * display to the user, and the second as the return value. Extra columns + * are discarded. * - * @return HTML + * @param string $name Name of SELECT tag + * @param string|array $defstr The value to highlight. Use an array for multiple highlight values. + * @param bool|string $blank1stItem True to create an empty item (default), False not to add one; + * 'string' to set its label and 'value:string' to assign a value to it. + * @param bool $multiple True for multi-select list + * @param int $size Number of rows to show (applies to multi-select box only) + * @param string $selectAttr Additional attributes to defined for SELECT tag, + * useful for holding javascript onChange='...' handlers, CSS class, etc. + * @param bool $compareFirstCol When true (default), $defstr is compared against the value (column 2), + * while false will compare against the description (column 1). * - * changes by glen.davies@cce.ac.nz to support multiple hilited items + * @return string HTML */ - function GetMenu($name,$defstr='',$blank1stItem=true,$multiple=false, - $size=0, $selectAttr='',$compareFields0=true) + function getMenu($name, $defstr = '', $blank1stItem = true, $multiple = false, + $size = 0, $selectAttr = '', $compareFirstCol = true) { global $ADODB_INCLUDED_LIB; if (empty($ADODB_INCLUDED_LIB)) { - include(ADODB_DIR.'/adodb-lib.inc.php'); + include_once(ADODB_DIR.'/adodb-lib.inc.php'); } - return _adodb_getmenu($this, $name,$defstr,$blank1stItem,$multiple, - $size, $selectAttr,$compareFields0); + return _adodb_getmenu($this, $name, $defstr, $blank1stItem, $multiple, + $size, $selectAttr, $compareFirstCol); } - - /** - * Generate a SELECT tag string from a recordset, and return the string. - * If the recordset has 2 cols, we treat the 1st col as the containing - * the text to display to the user, and 2nd col as the return value. Default - * strings are compared with the SECOND column. + * Generate a SELECT tag with groups from a recordset, and return the HTML markup. + * + * The recordset must have 3 columns and be ordered by the 3rd column. The + * first column contains the text to display to the user, the second is the + * return value and the third is the option group. Extra columns are discarded. + * Default strings are compared with the SECOND column. + * + * @param string $name Name of SELECT tag + * @param string|array $defstr The value to highlight. Use an array for multiple highlight values. + * @param bool|string $blank1stItem True to create an empty item (default), False not to add one; + * 'string' to set its label and 'value:string' to assign a value to it. + * @param bool $multiple True for multi-select list + * @param int $size Number of rows to show (applies to multi-select box only) + * @param string $selectAttr Additional attributes to defined for SELECT tag, + * useful for holding javascript onChange='...' handlers, CSS class, etc. + * @param bool $compareFirstCol When true (default), $defstr is compared against the value (column 2), + * while false will compare against the description (column 1). * + * @return string HTML */ - function GetMenu2($name,$defstr='',$blank1stItem=true,$multiple=false,$size=0, $selectAttr='') { - return $this->GetMenu($name,$defstr,$blank1stItem,$multiple, - $size, $selectAttr,false); - } - - /* - Grouped Menu - */ - function GetMenu3($name,$defstr='',$blank1stItem=true,$multiple=false, - $size=0, $selectAttr='') + function getMenuGrouped($name, $defstr = '', $blank1stItem = true, $multiple = false, + $size = 0, $selectAttr = '', $compareFirstCol = true) { global $ADODB_INCLUDED_LIB; if (empty($ADODB_INCLUDED_LIB)) { - include(ADODB_DIR.'/adodb-lib.inc.php'); + include_once(ADODB_DIR.'/adodb-lib.inc.php'); } - return _adodb_getmenu_gp($this, $name,$defstr,$blank1stItem,$multiple, + return _adodb_getmenu_gp($this, $name, $defstr, $blank1stItem, $multiple, + $size, $selectAttr, $compareFirstCol); + } + + /** + * Generate a SELECT tag from a recordset, and return the HTML markup. + * + * Same as GetMenu(), except that default strings are compared with the + * FIRST column (the description). + * + * @param string $name Name of SELECT tag + * @param string|array $defstr The value to highlight. Use an array for multiple highlight values. + * @param bool|string $blank1stItem True to create an empty item (default), False not to add one; + * 'string' to set its label and 'value:string' to assign a value to it. + * @param bool $multiple True for multi-select list + * @param int $size Number of rows to show (applies to multi-select box only) + * @param string $selectAttr Additional attributes to defined for SELECT tag, + * useful for holding javascript onChange='...' handlers, CSS class, etc. + * + * @return string HTML + * + * @deprecated 5.21.0 Use getMenu() with $compareFirstCol = false instead. + */ + function getMenu2($name, $defstr = '', $blank1stItem = true, $multiple = false, + $size = 0, $selectAttr = '') + { + return $this->getMenu($name, $defstr, $blank1stItem, $multiple, $size, $selectAttr,false); } + /** + * Generate a SELECT tag with groups from a recordset, and return the HTML markup. + * + * Same as GetMenuGrouped(), except that default strings are compared with the + * FIRST column (the description). + * + * @param string $name Name of SELECT tag + * @param string|array $defstr The value to highlight. Use an array for multiple highlight values. + * @param bool|string $blank1stItem True to create an empty item (default), False not to add one; + * 'string' to set its label and 'value:string' to assign a value to it. + * @param bool $multiple True for multi-select list + * @param int $size Number of rows to show (applies to multi-select box only) + * @param string $selectAttr Additional attributes to defined for SELECT tag, + * useful for holding javascript onChange='...' handlers, CSS class, etc. + * + * @return string HTML + * + * @deprecated 5.21.0 Use getMenuGrouped() with $compareFirstCol = false instead. + */ + function getMenu3($name, $defstr = '', $blank1stItem = true, $multiple = false, + $size = 0, $selectAttr = '') + { + return $this->getMenuGrouped($name, $defstr, $blank1stItem, $multiple, + $size, $selectAttr, false); + } + /** * return recordset as a 2-dimensional array. * - * @param [nRows] is the number of rows to return. -1 means every row. + * @param int $nRows Number of rows to return. -1 means every row. * - * @return an array indexed by the rows (0-based) from the recordset + * @return array indexed by the rows (0-based) from the recordset */ function GetArray($nRows = -1) { - global $ADODB_EXTENSION; if ($ADODB_EXTENSION) { - $results = adodb_getall($this,$nRows); - return $results; - } $results = array(); $cnt = 0; while (!$this->EOF && $nRows != $cnt) { @@ -3396,8 +3821,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 } function GetAll($nRows = -1) { - $arr = $this->GetArray($nRows); - return $arr; + return $this->GetArray($nRows); } /* @@ -3415,12 +3839,11 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 * @param offset is the row to start calculations from (1-based) * @param [nrows] is the number of rows to return * - * @return an array indexed by the rows (0-based) from the recordset + * @return array an array indexed by the rows (0-based) from the recordset */ function GetArrayLimit($nrows,$offset=-1) { if ($offset <= 0) { - $arr = $this->GetArray($nrows); - return $arr; + return $this->GetArray($nrows); } $this->Move($offset); @@ -3441,137 +3864,163 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 * * @param [nRows] is the number of rows to return. -1 means every row. * - * @return an array indexed by the rows (0-based) from the recordset + * @return array an array indexed by the rows (0-based) from the recordset */ function GetRows($nRows = -1) { - $arr = $this->GetArray($nRows); - return $arr; + return $this->GetArray($nRows); } /** - * return whole recordset as a 2-dimensional associative array if there are more than 2 columns. - * The first column is treated as the key and is not included in the array. - * If there is only 2 columns, it will return a 1 dimensional array of key-value pairs unless - * $force_array == true. + * return whole recordset as a 2-dimensional associative array if + * there are more than 2 columns. The first column is treated as the + * key and is not included in the array. If there is only 2 columns, + * it will return a 1 dimensional array of key-value pairs unless + * $force_array == true. This recordset method is currently part of + * the API, but may not be in later versions of ADOdb. By preference, use + * ADOconnnection::getAssoc() * - * @param [force_array] has only meaning if we have 2 data columns. If false, a 1 dimensional - * array is returned, otherwise a 2 dimensional array is returned. If this sounds confusing, - * read the source. + * @param bool $force_array (optional) Has only meaning if we have 2 data + * columns. If false, a 1 dimensional + * array is returned, otherwise a 2 dimensional + * array is returned. If this sounds confusing, + * read the source. * - * @param [first2cols] means if there are more than 2 cols, ignore the remaining cols and - * instead of returning array[col0] => array(remaining cols), return array[col0] => col1 + * @param bool $first2cols (optional) Means if there are more than + * 2 cols, ignore the remaining cols and + * instead of returning + * array[col0] => array(remaining cols), + * return array[col0] => col1 + * + * @return mixed[]|false * - * @return an associative array indexed by the first column of the array, - * or false if the data has less than 2 cols. */ - function GetAssoc($force_array = false, $first2cols = false) { - global $ADODB_EXTENSION; - - $cols = $this->_numOfFields; - if ($cols < 2) { - return false; - } + function getAssoc($force_array = false, $first2cols = false) + { + /* + * Insufficient rows to show data + */ + if ($this->_numOfFields < 2) + return; - // Empty recordset + /* + * Empty recordset + */ if (!$this->fields) { return array(); } - // Determine whether the array is associative or 0-based numeric - $numIndex = array_keys($this->fields) == range(0, count($this->fields) - 1); + /* + * The number of fields is half the actual returned in BOTH mode + */ + $numberOfFields = $this->_numOfFields; - $results = array(); + /* + * Get the fetch mode when the call was executed, this may be + * different than ADODB_FETCH_MODE + */ + $fetchMode = $this->connection->fetchMode; + if ($fetchMode == ADODB_FETCH_BOTH) { + /* + * If we are using BOTH, we present the data as if it + * was in ASSOC mode. This could be enhanced by adding + * a BOTH_ASSOC_MODE class property + * We build a template of numeric keys. you could improve the + * speed by caching this, indexed by number of keys + */ + $testKeys = array_fill(0,$numberOfFields,0); + } - if (!$first2cols && ($cols > 2 || $force_array)) { - if ($ADODB_EXTENSION) { - if ($numIndex) { - while (!$this->EOF) { - $results[trim($this->fields[0])] = array_slice($this->fields, 1); - adodb_movenext($this); - } - } else { - while (!$this->EOF) { - // Fix for array_slice re-numbering numeric associative keys - $keys = array_slice(array_keys($this->fields), 1); - $sliced_array = array(); + $showArrayMethod = 0; - foreach($keys as $key) { - $sliced_array[$key] = $this->fields[$key]; - } + if ($numberOfFields == 2) + /* + * Key is always value of first element + * Value is always value of second element + */ + $showArrayMethod = 1; - $results[trim(reset($this->fields))] = $sliced_array; - adodb_movenext($this); - } - } - } else { - if ($numIndex) { - while (!$this->EOF) { - $results[trim($this->fields[0])] = array_slice($this->fields, 1); - $this->MoveNext(); - } - } else { - while (!$this->EOF) { - // Fix for array_slice re-numbering numeric associative keys - $keys = array_slice(array_keys($this->fields), 1); - $sliced_array = array(); + if ($force_array) + $showArrayMethod = 0; - foreach($keys as $key) { - $sliced_array[$key] = $this->fields[$key]; - } + if ($first2cols) + $showArrayMethod = 1; - $results[trim(reset($this->fields))] = $sliced_array; - $this->MoveNext(); - } - } + $results = array(); + + while (!$this->EOF){ + + $myFields = $this->fields; + + if ($fetchMode == ADODB_FETCH_BOTH) { + /* + * extract the associative keys + */ + $myFields = array_diff_key($myFields,$testKeys); } - } else { - if ($ADODB_EXTENSION) { - // return scalar values - if ($numIndex) { - while (!$this->EOF) { - // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string - $results[trim(($this->fields[0]))] = $this->fields[1]; - adodb_movenext($this); - } - } else { - while (!$this->EOF) { - // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string - $v1 = trim(reset($this->fields)); - $v2 = ''.next($this->fields); - $results[$v1] = $v2; - adodb_movenext($this); - } - } - } else { - if ($numIndex) { - while (!$this->EOF) { - // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string - $results[trim(($this->fields[0]))] = $this->fields[1]; - $this->MoveNext(); - } - } else { - while (!$this->EOF) { - // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string - $v1 = trim(reset($this->fields)); - $v2 = ''.next($this->fields); - $results[$v1] = $v2; - $this->MoveNext(); - } + + /* + * key is value of first element, rest is data, + * The key is not case processed + */ + $key = array_shift($myFields); + + switch ($showArrayMethod) { + case 0: + + if ($fetchMode == ADODB_FETCH_ASSOC + || $fetchMode == ADODB_FETCH_BOTH) + { + /* + * The driver should have already handled the key + * casing, but in case it did not. We will check and force + * this in later versions of ADOdb + */ + if (ADODB_ASSOC_CASE == ADODB_ASSOC_CASE_UPPER) + $myFields = array_change_key_case($myFields,CASE_UPPER); + + elseif (ADODB_ASSOC_CASE == ADODB_ASSOC_CASE_LOWER) + $myFields = array_change_key_case($myFields,CASE_LOWER); + + /* + * We have already shifted the key off + * the front, so the rest is the value + */ + $results[$key] = $myFields; + } + else + /* + * I want the values in a numeric array, + * nicely re-indexed from zero + */ + $results[$key] = array_values($myFields); + break; + + case 1: + + /* + * Don't care how long the array is, + * I just want value of second column, and it doesn't + * matter whether the array is associative or numeric + */ + $results[$key] = array_shift($myFields); + break; } - } - $ref = $results; # workaround accelerator incompat with PHP 4.4 :( - return $ref; + $this->MoveNext(); + } + /* + * Done + */ + return $results; } - /** * - * @param v is the character timestamp in YYYY-MM-DD hh:mm:ss format - * @param fmt is the format to apply to it, using date() + * @param mixed $v is the character timestamp in YYYY-MM-DD hh:mm:ss format + * @param string [$fmt] is the format to apply to it, using date() * - * @return a timestamp formated as user desires + * @return string a timestamp formated as user desires */ function UserTimeStamp($v,$fmt='Y-m-d H:i:s') { if (is_numeric($v) && strlen($v)<14) { @@ -3590,10 +4039,10 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** - * @param v is the character date in YYYY-MM-DD format, returned by database - * @param fmt is the format to apply to it, using date() + * @param mixed $v is the character date in YYYY-MM-DD format, returned by database + * @param string $fmt is the format to apply to it, using date() * - * @return a date formated as user desires + * @return string a date formatted as user desires */ function UserDate($v,$fmt='Y-m-d') { $tt = $this->UnixDate($v); @@ -3610,9 +4059,9 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** - * @param $v is a date string in YYYY-MM-DD format + * @param mixed $v is a date string in YYYY-MM-DD format * - * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format + * @return string date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format */ static function UnixDate($v) { return ADOConnection::UnixDate($v); @@ -3620,9 +4069,9 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** - * @param $v is a timestamp string in YYYY-MM-DD HH-NN-SS format + * @param string|object $v is a timestamp string in YYYY-MM-DD HH-NN-SS format * - * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format + * @return mixed date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format */ static function UnixTimeStamp($v) { return ADOConnection::UnixTimeStamp($v); @@ -3638,26 +4087,30 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** - * PEAR DB compat, number of rows - */ + * PEAR DB compat, number of rows + * + * @return int + */ function NumRows() { return $this->_numOfRows; } /** - * PEAR DB compat, number of cols - */ + * PEAR DB compat, number of cols + * + * @return int + */ function NumCols() { return $this->_numOfFields; } /** - * Fetch a row, returning false if no more rows. - * This is PEAR DB compat mode. - * - * @return false or array containing the current record - */ + * Fetch a row, returning false if no more rows. + * This is PEAR DB compat mode. + * + * @return mixed[]|false false or array containing the current record + */ function FetchRow() { if ($this->EOF) { return false; @@ -3675,7 +4128,9 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 * Fetch a row, returning PEAR_Error if no more rows. * This is PEAR DB compat mode. * - * @return DB_OK or error object + * @param mixed[]|false $arr + * + * @return mixed DB_OK or error object */ function FetchInto(&$arr) { if ($this->EOF) { @@ -3690,7 +4145,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** * Move to the first row in the recordset. Many databases do NOT support this. * - * @return true or false + * @return bool true or false */ function MoveFirst() { if ($this->_currentRow == 0) { @@ -3703,7 +4158,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** * Move to the last row in the recordset. * - * @return true or false + * @return bool true or false */ function MoveLast() { if ($this->_numOfRows >= 0) { @@ -3725,7 +4180,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** * Move to next record in the recordset. * - * @return true if there still rows available, or false if there are no more rows (EOF). + * @return bool true if there still rows available, or false if there are no more rows (EOF). */ function MoveNext() { if (!$this->EOF) { @@ -3750,9 +4205,9 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 * Random access to a specific row in the recordset. Some databases do not support * access to previous rows in the databases (no scrolling backwards). * - * @param rowNumber is the row to move to (0-based) + * @param int $rowNumber is the row to move to (0-based) * - * @return true if there still rows available, or false if there are no more rows (EOF). + * @return bool true if there still rows available, or false if there are no more rows (EOF). */ function Move($rowNumber = 0) { $this->EOF = false; @@ -3784,18 +4239,11 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 if ($rowNumber < $this->_currentRow) { return false; } - global $ADODB_EXTENSION; - if ($ADODB_EXTENSION) { - while (!$this->EOF && $this->_currentRow < $rowNumber) { - adodb_movenext($this); - } - } else { - while (! $this->EOF && $this->_currentRow < $rowNumber) { - $this->_currentRow++; + while (! $this->EOF && $this->_currentRow < $rowNumber) { + $this->_currentRow++; - if (!$this->_fetch()) { - $this->EOF = true; - } + if (!$this->_fetch()) { + $this->EOF = true; } } return !($this->EOF); @@ -3811,9 +4259,9 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 * Get the value of a field in the current row by column name. * Will not work if ADODB_FETCH_MODE is set to ADODB_FETCH_NUM. * - * @param colname is the field to access + * @param string $colname is the field to access * - * @return the value of $colname column + * @return mixed the value of $colname column */ function Fields($colname) { return $this->fields[$colname]; @@ -3822,6 +4270,9 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** * Defines the function to use for table fields case conversion * depending on ADODB_ASSOC_CASE + * + * @param int [$case] + * * @return string strtolower/strtoupper or false if no conversion needed */ protected function AssocCaseConvertFunction($case = ADODB_ASSOC_CASE) { @@ -3839,7 +4290,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** * Builds the bind array associating keys to recordset fields * - * @param int $upper Case for the array keys, defaults to uppercase + * @param int [$upper] Case for the array keys, defaults to uppercase * (see ADODB_ASSOC_CASE_xxx constants) */ function GetAssocKeys($upper = ADODB_ASSOC_CASE) { @@ -3876,7 +4327,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 * Use associative array to get fields array for databases that do not support * associative arrays. Submitted by Paolo S. Asioli paolo.asioli#libero.it * - * @param int $upper Case for the array keys, defaults to uppercase + * @param int [$upper] Case for the array keys, defaults to uppercase * (see ADODB_ASSOC_CASE_xxx constants) */ function GetRowAssoc($upper = ADODB_ASSOC_CASE) { @@ -3899,7 +4350,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** * Clean up recordset * - * @return true or false + * @return bool */ function Close() { // free connection object - this seems to globally free the object @@ -3913,19 +4364,21 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 } /** - * synonyms RecordCount and RowCount + * Synonyms RecordCount and RowCount * - * @return the number of rows or -1 if this is not supported + * @return int Number of rows or -1 if this is not supported */ function RecordCount() { return $this->_numOfRows; } - /* - * If we are using PageExecute(), this will return the maximum possible rows - * that can be returned when paging a recordset. - */ + /** + * If we are using PageExecute(), this will return the maximum possible rows + * that can be returned when paging a recordset. + * + * @return int + */ function MaxRecordCount() { return ($this->_maxRecordCount) ? $this->_maxRecordCount : $this->RecordCount(); } @@ -3991,29 +4444,32 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 return $this->_numOfFields; } - /** - * Get the ADOFieldObject of a specific column. + * Get a Field's metadata from database. + * + * Must be defined by child class. * - * @param fieldoffset is the column position to access(0-based). + * @param int $fieldOffset * - * @return the ADOFieldObject for that column, or false. + * @return ADOFieldObject|false */ - function FetchField($fieldoffset = -1) { - // must be defined by child class - + function fetchField($fieldOffset) + { return false; } /** - * Get the ADOFieldObjects of all columns in an array. + * Get Field metadata for all the recordset's columns in an array. * + * @return ADOFieldObject[] */ - function FieldTypesArray() { - $arr = array(); - for ($i=0, $max=$this->_numOfFields; $i < $max; $i++) - $arr[] = $this->FetchField($i); - return $arr; + function fieldTypesArray() { + if (empty($this->fieldObjectsCache)) { + for ($i = 0; $i < $this->_numOfFields; $i++) { + $this->fieldObjectsCache[] = $this->fetchField($i); + } + } + return $this->fieldObjectsCache; } /** @@ -4023,8 +4479,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 * @return the object with the properties set to the fields of the current row */ function FetchObj() { - $o = $this->FetchObject(false); - return $o; + return $this->FetchObject(false); } /** @@ -4045,11 +4500,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 } } $i = 0; - if (PHP_VERSION >= 5) { - $o = clone($this->_obj); - } else { - $o = $this->_obj; - } + $o = clone($this->_obj); for ($i=0; $i <$this->_numOfFields; $i++) { $name = $this->_names[$i]; @@ -4074,8 +4525,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 * Fixed bug reported by tim@orotech.net */ function FetchNextObj() { - $o = $this->FetchNextObject(false); - return $o; + return $this->FetchNextObject(false); } @@ -4134,6 +4584,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 $len = $fieldobj->max_length; } + // changed in 2.32 to hashing instead of switch stmt for speed... static $typeMap = array( 'VARCHAR' => 'C', @@ -4240,9 +4691,10 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 "SQLBOOL" => 'L' ); + $tmap = false; $t = strtoupper($t); - $tmap = (isset($typeMap[$t])) ? $typeMap[$t] : 'N'; + $tmap = (isset($typeMap[$t])) ? $typeMap[$t] : ADODB_DEFAULT_METATYPE; switch ($tmap) { case 'C': // is the char field is too long, return as text field... @@ -4395,7 +4847,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 global $ADODB_INCLUDED_LIB; if (empty($ADODB_INCLUDED_LIB)) { - include(ADODB_DIR.'/adodb-lib.inc.php'); + include_once(ADODB_DIR.'/adodb-lib.inc.php'); } $hdr = true; @@ -4429,10 +4881,10 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 * * @param array is a 2-dimensional array holding the data. * The first row should hold the column names - * unless paramter $colnames is used. + * unless parameter $colnames is used. * @param typearr holds an array of types. These are the same types * used in MetaTypes (C,B,L,I,N). - * @param [colnames] array of column names. If set, then the first row of + * @param string[]|false [$colnames] array of column names. If set, then the first row of * $array should not hold the column names. */ function InitArray($array,$typearr,$colnames=false) { @@ -4450,10 +4902,10 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 /** * Setup the Array and datatype file objects * - * @param array is a 2-dimensional array holding the data. + * @param array $array 2-dimensional array holding the data * The first row should hold the column names - * unless paramter $colnames is used. - * @param fieldarr holds an array of ADOFieldObject's. + * unless parameter $colnames is used. + * @param array $fieldarr Array of ADOFieldObject's. */ function InitArrayFields(&$array,&$fieldarr) { $this->_array = $array; @@ -4464,12 +4916,15 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 $this->Init(); } + /** + * @param int [$nRows] + * @return array + */ function GetArray($nRows=-1) { if ($nRows == -1 && $this->_currentRow <= 0 && !$this->_skiprow1) { return $this->_array; } else { - $arr = ADORecordSet::GetArray($nRows); - return $arr; + return ADORecordSet::GetArray($nRows); } } @@ -4484,7 +4939,12 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 : sizeof($this->_types); } - /* Use associative array to get fields array */ + /** + * Use associative array to get fields array + * + * @param string $colname + * @return mixed + */ function Fields($colname) { $mode = isset($this->adodbFetchMode) ? $this->adodbFetchMode : $this->fetchMode; @@ -4504,6 +4964,11 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 return $this->fields[$this->bind[strtoupper($colname)]]; } + /** + * @param int [$fieldOffset] + * + * @return \ADOFieldObject + */ function FetchField($fieldOffset = -1) { if (isset($this->_fieldobjects)) { return $this->_fieldobjects[$fieldOffset]; @@ -4516,6 +4981,10 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 return $o; } + /** + * @param int $row + * @return bool + */ function _seek($row) { if (sizeof($this->_array) && 0 <= $row && $row < $this->_numOfRows) { $this->_currentRow = $row; @@ -4528,6 +4997,9 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 return false; } + /** + * @return bool + */ function MoveNext() { if (!$this->EOF) { $this->_currentRow++; @@ -4551,6 +5023,9 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 return false; } + /** + * @return bool + */ function _fetch() { $pos = $this->_currentRow; @@ -4598,9 +5073,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 $db = strtolower($dbType); switch ($db) { case 'ado': - if (PHP_VERSION >= 5) { - $db = 'ado5'; - } + $db = 'ado5'; $class = 'ado'; break; @@ -4611,15 +5084,30 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 case 'pgsql': case 'postgres': - $class = $db = 'postgres8'; + $class = $db = 'postgres9'; + break; + + case 'mysql': + // mysql driver deprecated since 5.5, removed in 7.0 + // automatically switch to mysqli + if(version_compare(PHP_VERSION, '7.0.0', '>=')) { + $db = 'mysqli'; + } + $class = $db; break; default: - $class = $db; break; + if (substr($db, 0, 4) === 'pdo_') { + ADOConnection::outp("Invalid database type: $db"); + return false; + } + + $class = $db; + break; } - $file = ADODB_DIR."/drivers/adodb-".$db.".inc.php"; - @include_once($file); + $file = "drivers/adodb-$db.inc.php"; + @include_once(ADODB_DIR . '/' . $file); $ADODB_LASTDB = $class; if (class_exists("ADODB_" . $class)) { return $class; @@ -4635,20 +5123,24 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 } /** - * synonym for ADONewConnection for people like me who cannot remember the correct name + * Synonym for ADONewConnection for people like me who cannot remember the correct name + * + * @param string [$db] + * + * @return ADOConnection|false */ function NewADOConnection($db='') { - $tmp = ADONewConnection($db); - return $tmp; + return ADONewConnection($db); } /** * Instantiate a new Connection class for a specific database driver. * - * @param [db] is the database Connection object to create. If undefined, + * @param string $db Database Connection object to create. If undefined, * use the last database driver that was loaded by ADOLoadCode(). * - * @return the freshly created instance of the Connection class. + * @return ADOConnection|false The freshly created instance of the Connection class + * or false in case of error. */ function ADONewConnection($db='') { global $ADODB_NEWCONNECTION, $ADODB_LASTDB; @@ -4656,6 +5148,13 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 if (!defined('ADODB_ASSOC_CASE')) { define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_NATIVE); } + + /* + * Are there special characters in the dsn password + * that disrupt parse_url + */ + $needsSpecialCharacterHandling = false; + $errorfn = (defined('ADODB_ERROR_HANDLER')) ? ADODB_ERROR_HANDLER : false; if (($at = strpos($db,'://')) !== FALSE) { $origdsn = $db; @@ -4677,8 +5176,27 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 $path = substr($path,0,$qmark); } $dsna['path'] = '/' . urlencode($path); - } else - $dsna = @parse_url($fakedsn); + } else { + /* + * Stop # character breaking parse_url + */ + $cFakedsn = str_replace('#','\035',$fakedsn); + if (strcmp($fakedsn,$cFakedsn) != 0) + { + /* + * There is a # in the string + */ + $needsSpecialCharacterHandling = true; + + /* + * This allows us to successfully parse the url + */ + $fakedsn = $cFakedsn; + + } + + $dsna = parse_url($fakedsn); + } if (!$dsna) { return false; @@ -4705,11 +5223,20 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 if (!$db) { return false; } + $dsna['host'] = isset($dsna['host']) ? rawurldecode($dsna['host']) : ''; $dsna['user'] = isset($dsna['user']) ? rawurldecode($dsna['user']) : ''; $dsna['pass'] = isset($dsna['pass']) ? rawurldecode($dsna['pass']) : ''; $dsna['path'] = isset($dsna['path']) ? rawurldecode(substr($dsna['path'],1)) : ''; # strip off initial / + if ($needsSpecialCharacterHandling) + { + /* + * Revert back to the original string + */ + $dsna = str_replace('\035','#',$dsna); + } + if (isset($dsna['query'])) { $opt1 = explode('&',$dsna['query']); foreach($opt1 as $k => $v) { @@ -4719,6 +5246,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 } else { $opt = array(); } + } /* * phptype: Database backend used in PHP (mysql, odbc etc.) @@ -4903,12 +5431,19 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 if (!class_exists($class)) { return false; } - $perf = new $class($conn); - return $perf; + return new $class($conn); } - function NewDataDictionary(&$conn,$drivername=false) { + /** + * Get a new Data Dictionary object for the connection. + * + * @param ADOConnection $conn + * @param string $drivername + * + * @return ADODB_DataDict|false + */ + function newDataDictionary(&$conn, $drivername='') { if (!$drivername) { $drivername = _adodb_getdriver($conn->dataProvider,$conn->databaseType); } @@ -4935,8 +5470,6 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 return $dict; } - - /* Perform a print_r, with pre tags for better formatting. */ @@ -4967,7 +5500,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 function adodb_backtrace($printOrArr=true,$levels=9999,$ishtml=null) { global $ADODB_INCLUDED_LIB; if (empty($ADODB_INCLUDED_LIB)) { - include(ADODB_DIR.'/adodb-lib.inc.php'); + include_once(ADODB_DIR.'/adodb-lib.inc.php'); } return _adodb_backtrace($printOrArr,$levels,0,$ishtml); } diff --git a/libraries/adodb/composer.json b/libraries/adodb/composer.json index 21bd25f92..807866b67 100644 --- a/libraries/adodb/composer.json +++ b/libraries/adodb/composer.json @@ -1,7 +1,7 @@ { "name" : "adodb/adodb-php", "description" : "ADOdb is a PHP database abstraction layer library", - "license" : [ "BSD-3-Clause", "LGPL-2.1" ], + "license" : [ "BSD-3-Clause", "LGPL-2.1-or-later" ], "authors" : [ { "name": "John Lim", @@ -20,14 +20,18 @@ "keywords" : [ "database", "abstraction", "layer", "library", "php" ], - "homepage": "http://adodb.org/", + "homepage": "https://adodb.org/", "support" : { "issues" : "https://github.com/ADOdb/ADOdb/issues", "source" : "https://github.com/ADOdb/ADOdb" }, "require" : { - "php" : ">=5.3.2" + "php" : "^5.5.9 || ^7.0 || ^8.0" + }, + + "require-dev" : { + "phpunit/phpunit": "^8.5" }, "autoload" : { diff --git a/libraries/adodb/contrib/toxmlrpc.inc.php b/libraries/adodb/contrib/toxmlrpc.inc.php deleted file mode 100644 index f769cc5fd..000000000 --- a/libraries/adodb/contrib/toxmlrpc.inc.php +++ /dev/null @@ -1,181 +0,0 @@ -<?php - /** - * Helper functions to convert between ADODB recordset objects and XMLRPC values. - * Uses John Lim's AdoDB and Edd Dumbill's phpxmlrpc libs - * - * @author Daniele Baroncelli - * @author Gaetano Giunta - * @copyright (c) 2003-2004 Giunta/Baroncelli. All rights reserved. - * - * @todo some more error checking here and there - * @todo document the xmlrpc-struct used to encode recordset info - * @todo verify if using xmlrpc_encode($rs->GetArray()) would work with: - * - ADODB_FETCH_BOTH - * - null values - */ - - /** - * Include the main libraries - */ - require_once('xmlrpc.inc'); - if (!defined('ADODB_DIR')) require_once('adodb.inc.php'); - - /** - * Builds an xmlrpc struct value out of an AdoDB recordset - */ - function rs2xmlrpcval(&$adodbrs) { - - $header = rs2xmlrpcval_header($adodbrs); - $body = rs2xmlrpcval_body($adodbrs); - - // put it all together and build final xmlrpc struct - $xmlrpcrs = new xmlrpcval ( array( - "header" => $header, - "body" => $body, - ), "struct"); - - return $xmlrpcrs; - - } - - /** - * Builds an xmlrpc struct value describing an AdoDB recordset - */ - function rs2xmlrpcval_header($adodbrs) - { - $numfields = $adodbrs->FieldCount(); - $numrecords = $adodbrs->RecordCount(); - - // build structure holding recordset information - $fieldstruct = array(); - for ($i = 0; $i < $numfields; $i++) { - $fld = $adodbrs->FetchField($i); - $fieldarray = array(); - if (isset($fld->name)) - $fieldarray["name"] = new xmlrpcval ($fld->name); - if (isset($fld->type)) - $fieldarray["type"] = new xmlrpcval ($fld->type); - if (isset($fld->max_length)) - $fieldarray["max_length"] = new xmlrpcval ($fld->max_length, "int"); - if (isset($fld->not_null)) - $fieldarray["not_null"] = new xmlrpcval ($fld->not_null, "boolean"); - if (isset($fld->has_default)) - $fieldarray["has_default"] = new xmlrpcval ($fld->has_default, "boolean"); - if (isset($fld->default_value)) - $fieldarray["default_value"] = new xmlrpcval ($fld->default_value); - $fieldstruct[$i] = new xmlrpcval ($fieldarray, "struct"); - } - $fieldcount = new xmlrpcval ($numfields, "int"); - $recordcount = new xmlrpcval ($numrecords, "int"); - $sql = new xmlrpcval ($adodbrs->sql); - $fieldinfo = new xmlrpcval ($fieldstruct, "array"); - - $header = new xmlrpcval ( array( - "fieldcount" => $fieldcount, - "recordcount" => $recordcount, - "sql" => $sql, - "fieldinfo" => $fieldinfo - ), "struct"); - - return $header; - } - - /** - * Builds an xmlrpc struct value out of an AdoDB recordset - * (data values only, no data definition) - */ - function rs2xmlrpcval_body($adodbrs) - { - $numfields = $adodbrs->FieldCount(); - - // build structure containing recordset data - $adodbrs->MoveFirst(); - $rows = array(); - while (!$adodbrs->EOF) { - $columns = array(); - // This should work on all cases of fetch mode: assoc, num, both or default - if ($adodbrs->fetchMode == 'ADODB_FETCH_BOTH' || count($adodbrs->fields) == 2 * $adodbrs->FieldCount()) - for ($i = 0; $i < $numfields; $i++) - if ($adodbrs->fields[$i] === null) - $columns[$i] = new xmlrpcval (''); - else - $columns[$i] = xmlrpc_encode ($adodbrs->fields[$i]); - else - foreach ($adodbrs->fields as $val) - if ($val === null) - $columns[] = new xmlrpcval (''); - else - $columns[] = xmlrpc_encode ($val); - - $rows[] = new xmlrpcval ($columns, "array"); - - $adodbrs->MoveNext(); - } - $body = new xmlrpcval ($rows, "array"); - - return $body; - } - - /** - * Returns an xmlrpc struct value as string out of an AdoDB recordset - */ - function rs2xmlrpcstring (&$adodbrs) { - $xmlrpc = rs2xmlrpcval ($adodbrs); - if ($xmlrpc) - return $xmlrpc->serialize(); - else - return null; - } - - /** - * Given a well-formed xmlrpc struct object returns an AdoDB object - * - * @todo add some error checking on the input value - */ - function xmlrpcval2rs (&$xmlrpcval) { - - $fields_array = array(); - $data_array = array(); - - // rebuild column information - $header = $xmlrpcval->structmem('header'); - - $numfields = $header->structmem('fieldcount'); - $numfields = $numfields->scalarval(); - $numrecords = $header->structmem('recordcount'); - $numrecords = $numrecords->scalarval(); - $sqlstring = $header->structmem('sql'); - $sqlstring = $sqlstring->scalarval(); - - $fieldinfo = $header->structmem('fieldinfo'); - for ($i = 0; $i < $numfields; $i++) { - $temp = $fieldinfo->arraymem($i); - $fld = new ADOFieldObject(); - while (list($key,$value) = $temp->structeach()) { - if ($key == "name") $fld->name = $value->scalarval(); - if ($key == "type") $fld->type = $value->scalarval(); - if ($key == "max_length") $fld->max_length = $value->scalarval(); - if ($key == "not_null") $fld->not_null = $value->scalarval(); - if ($key == "has_default") $fld->has_default = $value->scalarval(); - if ($key == "default_value") $fld->default_value = $value->scalarval(); - } // while - $fields_array[] = $fld; - } // for - - // fetch recordset information into php array - $body = $xmlrpcval->structmem('body'); - for ($i = 0; $i < $numrecords; $i++) { - $data_array[$i]= array(); - $xmlrpcrs_row = $body->arraymem($i); - for ($j = 0; $j < $numfields; $j++) { - $temp = $xmlrpcrs_row->arraymem($j); - $data_array[$i][$j] = $temp->scalarval(); - } // for j - } // for i - - // finally build in-memory recordset object and return it - $rs = new ADORecordSet_array(); - $rs->InitArrayFields($data_array,$fields_array); - return $rs; - - } diff --git a/libraries/adodb/cute_icons_for_site/adodb.gif b/libraries/adodb/cute_icons_for_site/adodb.gif deleted file mode 100644 index c5e8dfc6db2d41dfcdd1beaf338ad60bc8375587..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1091 zcmb7<{WIHl0DwOUc@N?x-e2-H64Owrwi9hvoYw2<meED5mh8wFs$NblGl%3#imJ4V zM7?z0lFmz_^LF#HR3uJX*{M3^EY_*0SyMWv=9;a4!k*usyXT3BIv+&mFo6eH0RIt~ zl5$V4-^O4vv|8<vBPIR)Ismw#q1A3~1w!Gl$z)<M>H%QrbkEDm9?<C(gM;&}t<y&1 z9+%q)0E<Y>CJ@p9h|bB8i9};DF}E-nu8&VKlPQ^+TA|VS1j3czU?Biulaoss8J!Ts zYim>Uczu?Z+_AA$2BXQzDHnj#?_luvIsX&rtvSLD_yg*D@BI@%nkK8u<)Ibft?jup znZYf(?&GWgZ>sABvVO@9()Sm}`b*{vZ=B*&F9lTrGZ^P;?EcTibFcm}m6R4^Fpw*e z7=|WYq*9@qwU9d&ix$<^iR-*c4Yed6YYz`+_m&oyx@O3`uDij^3}s<~b|H`<#Q<u2 z0*=E`CR9qb#@SwlveKw6Nm}h=9D3YKIlqh|{^VJS8C%AyZK3(OIi$*24fk47+LBiu zDHl;Yd)ieCHiB6tA;S_&@^O)eSZj7!KOaTV@(W1<7zaC&FgsN9TOZ3JB*ehxu;m0L zK1iEJg#rmm*ZtA7Eb-~|aY7^sf=!(_Wj;GLHCu8y$qerp{!-zf=lp{Bo258hppoeu ztD+O<UH}gr;!+ziwcvPquY7(qE(qk6BDs!TS+@-ZF46U5vS(}JXD!KMn<~$Q>x0Zy zM5&dzEm-tEQItP$xl*zQ1@sj=e1abg>0jztUh!k=?>ldPnd6aEsrB=JB)><;@~cOf ziOLmMa+SkLdEXON^ReiWo-F;14%!D3i;H{ufzKD*TyTdwEY-j|EBReup8T)JXC0b_ zH23V;2{)6hD(EfTEN!{@6v=r5CRRk4cxSdx=5w#k<cktEF~-SKE5W&%qmY3df<y-x zpTI@Gs^Y@ce{6u@EKH>7X<jSwVKQ=FC%Bcr+w=m59+f^%;u@)~NyWCYqzid#YtymJ zPl*EyNvKFl3G$4;S7;?$s?k@Yd?|P|mhq;o&^;l2JqG>7S2Y+G&phnomHi<*Sc+&S zwsGRNkSpfK{Xm9&J@{>iBx79Id6ynmPLW(WP;|BA+V5^iO5o4B?s7d3tSbzfC`wZ) zGMLi-J(g$a$UI2z?i2;Hqz%;<4-D;hrlVxiE*{ILz5RD-_t7Dm%{QGgd$F{q=;?<q zJA|uIhL#FEc}v=3$=Yleutv%9X2$h&=@gG24?|S&f9##H`EFY=?CY}Gd+mUC|AAw^ zt~6x1K*IJN*2!imvMrgkr*X9^0PcQmzf3cJxVQCc0-&hINpn<2Hk|5OhK|I4^r!J5 zA%gmP%8oCH$N33vmYq$7)?ceh<<uRGSAC{pW)H4|qso~@JF@|5>aJ$*2EiPh`WLqT B&Itej diff --git a/libraries/adodb/cute_icons_for_site/adodb2.gif b/libraries/adodb/cute_icons_for_site/adodb2.gif deleted file mode 100644 index f12ae2037ee14b11d8cc0f00a31ba088ef755119..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1458 zcma)%{Xf%r0Kh++S@STy8>OwtRIg)EqO#F-9)>lg*;Sk)BR4Xap**$p9Yd5hwrdr# zErn4eAxDke5jyLYh{~qsQf}Su)x*`f+SPw>@7Md+_Yd#T?I9FuJO^w54*)QkOh)6o zxw$!=&Y;me8yy`T8X6iHc&t`Wb#&ZsZPnD**DDl*a`~^7mA%qaX{DuI1qJOe4Cm#w zq^GO6+)Igx%BZL+7E2ZuCJ7G@4+tpt^)01Rk8j*qxNaTn>Y7g?<vBWL5eOMem!?4w z4}y|yY&aGcTnh^h0H2KpfCT^pfItAY0^t1#fdu~>(g&2eJ=h4`zZ74d0NUjL6OZmr z6b;p7+)4F9Xc~62A$olzyr=bg2$sD;N<PKvi#+s>!8vk+JL}smrf)*O2;46tt^r5! zxlA;_kd>7!WR}5ke4<q*^GJ3=aSSmtLu!?4C5fm4wn`=uNvx_XsxOtdhz^J@a}|P< zg2Uacn#{xeGooWG+hdAr(Iws4{iS93*MEpS-5AN2-s<cfVP49wEN(%!L=+ZB4#&YN zDd_5IohJWT%e8G<Q0<-Ml(hM~WeVL`K3}6BI11YgPlzcts~Oew3W?;za_^MKLsu^h zidK5ZsKxPSOKhB2m$o*xT^x~l?jNq+e(m=WTM|u7C+U&qCMyRo=^y^md5w}TA;%84 zH{P#jR^+Lv{it0_m%FncYU0VqA$Cv>Hmsw0>RR%BRqV*=W(;mEt2v59)1z&vp(kDY zI)#|tqaXIcAU;TUQ)p**MK{Zfv$eyor08@7`v(aapY;&}<J_1aLeA_fC=z1{zCzb@ z+M8q-Gr1=v@D8HX1vdd1<!gLkY#`*R?^3oyHrc^FoB|R9Oa#xkIX`tC2B>}o3R5xQ z!&^G#x6J2q!F&mBM7Bws(1)={1u>#9;9_qXcG}S7s?Z(HcGVUQMjX)RY7m$;buyX- z)75_!{~iL&LQehxF!b>whnCe-GhqTqY>qCLXB`1Mnrk-q1zLGv;&mzEQA}+f;Drj0 z1!IzDad#1r0P<o40C)}3GtnMZ*ELY)p)x8f8P)_?!lXd6!l0azRbVf%Pc9@2#ac8W z1v7JoutkTGtXHAe;uDbaOO{u$yo<Q#z`s`i$YwFM(ABeNYw`tG?j%%sdPO*b<(S#; zF9hl6wDa3sX5)(8))SrW&*JZ(s=~XcP)G3z+4|}lwi~KEXLAm%DC4|^y6(K?d_#Sh z6EQ`}ctZ&-t3+C=rH3-gp4WD$JeAGu=gx8^ySyq$S>sNPajoR{gr+tu*<vA+>^`lq zBpe)`ht8-POx$(`KbM4i6=JCdxbYQz6^|?;kd0={Rs?#}-n`l-v&j?^xAo@Yi*6-Z z;b9(<_>i;~;s4U5@jE$r;qYzZ)>JS>U36EbElaN}r=h0ih-MTxgO6pW*8TENaZJmg zldehIui0Xa4|PgqN8w4<y)+F$F#Kw4htK7MV?DkeZ^wh0)x7cDNq5^HFl907$v6kZ zJBTgXne{M48Vf&6Zh||eQbdlO_!tR);Bium2WsX>=T4M1<?kn*GwCI<l-N*L!)tBc z&pY2w=Pw%G>r<`5sdFN`{2OzpRv#2TjmrGAMPHt_?S}r$H~Aepajnz)S^9Wy(`5OI zePfG;lP$mHOevGXyA3^KhFo0Rh8n*GShkPyh!Z!{@%TdIwhu;{y~x4P<L5+qKAqI! z_qyWQOs^s7+qk#gliHeI{k_av)R%=}wRy&2Svaa;6<=OG@vk?QjB)ngWkS#6mUXGk z13_4f&{Kx?H431Ua@1G!KFerh!CpT(^vOkb1DY>%wpL(5>HYX~Mxh5K{y@~50*Cnp z)U$Z}2@d@>aoSi+8CBS19}jXcii4L31y*~+$j?~`eTNb+YZx$d5yQ;XXb1qm{{VnR Bbn*ZI diff --git a/libraries/adodb/datadict/datadict-access.inc.php b/libraries/adodb/datadict/datadict-access.inc.php index c14591543..7a7d4cbbd 100644 --- a/libraries/adodb/datadict/datadict-access.inc.php +++ b/libraries/adodb/datadict/datadict-access.inc.php @@ -1,16 +1,23 @@ <?php - /** - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4 for best viewing. - -*/ + * Data Dictionary for Access. + * + * 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(); diff --git a/libraries/adodb/datadict/datadict-db2.inc.php b/libraries/adodb/datadict/datadict-db2.inc.php index 7d201ff17..c5dda09fb 100644 --- a/libraries/adodb/datadict/datadict-db2.inc.php +++ b/libraries/adodb/datadict/datadict-db2.inc.php @@ -1,16 +1,24 @@ <?php - /** - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4 for best viewing. + * Data Dictionary for DB2. + * + * 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(); @@ -18,7 +26,12 @@ class ADODB2_db2 extends ADODB_DataDict { var $databaseType = 'db2'; var $seqField = false; + var $dropCol = 'ALTER TABLE %s DROP COLUMN %s'; + + public $blobAllowsDefaultValue = true; + public $blobAllowsNotNull = true; + function ActualType($meta) { switch($meta) { @@ -60,21 +73,66 @@ class ADODB2_db2 extends ADODB_DataDict { return $suffix; } - function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') + function alterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') { - if ($this->debug) ADOConnection::outp("AlterColumnSQL not supported"); - return array(); + $tabname = $this->TableName ($tabname); + $sql = array(); + list($lines,$pkey,$idxs) = $this->_GenFields($flds); + // genfields can return FALSE at times + if ($lines == null) $lines = array(); + $alter = 'ALTER TABLE ' . $tabname . $this->alterCol . ' '; + + $dataTypeWords = array('SET','DATA','TYPE'); + + foreach($lines as $v) + { + /* + * We must now post-process the line to insert the 'SET DATA TYPE' + * text into the alter statement + */ + $e = explode(' ',$v); + + array_splice($e,1,0,$dataTypeWords); + + $v = implode(' ',$e); + + $sql[] = $alter . $v; + } + if (is_array($idxs)) + { + foreach($idxs as $idx => $idxdef) { + $sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']); + $sql = array_merge($sql, $sql_idxs); + } + + } + return $sql; } - function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') + + function dropColumnSql($tabname, $flds, $tableflds='',$tableoptions='') { - if ($this->debug) ADOConnection::outp("DropColumnSQL not supported"); - return array(); - } + + + $tabname = $this->connection->getMetaCasedValue($tabname); + $flds = $this->connection->getMetaCasedValue($flds); + + if (ADODB_ASSOC_CASE == ADODB_ASSOC_CASE_NATIVE ) + { + /* + * METACASE_NATIVE + */ + $tabname = $this->connection->nameQuote . $tabname . $this->connection->nameQuote; + $flds = $this->connection->nameQuote . $flds . $this->connection->nameQuote; + } + $sql = sprintf($this->dropCol,$tabname,$flds); + return (array)$sql; + } + - function ChangeTableSQL($tablename, $flds, $tableoptions = false) + function changeTableSQL($tablename, $flds, $tableoptions = false, $dropOldFields=false) { /** @@ -86,17 +144,25 @@ class ADODB2_db2 extends ADODB_DataDict { $validTypes = array("CHAR","VARC"); $invalidTypes = array("BIGI","BLOB","CLOB","DATE", "DECI","DOUB", "INTE", "REAL","SMAL", "TIME"); // check table exists - $cols = $this->MetaColumns($tablename); + + + $cols = $this->metaColumns($tablename); if ( empty($cols)) { - return $this->CreateTableSQL($tablename, $flds, $tableoptions); + return $this->createTableSQL($tablename, $flds, $tableoptions); } // already exists, alter table instead list($lines,$pkey) = $this->_GenFields($flds); - $alter = 'ALTER TABLE ' . $this->TableName($tablename); + $alter = 'ALTER TABLE ' . $this->tableName($tablename); $sql = array(); foreach ( $lines as $id => $v ) { + /* + * If the metaCasing was NATIVE the col returned with nameQuotes + * around the field. We need to remove this for the metaColumn + * match + */ + $id = str_replace($this->connection->nameQuote,'',$id); if ( isset($cols[$id]) && is_object($cols[$id]) ) { /** If the first field of $v is the fieldname, and diff --git a/libraries/adodb/datadict/datadict-firebird.inc.php b/libraries/adodb/datadict/datadict-firebird.inc.php index f247c8dc0..0020a0ae0 100644 --- a/libraries/adodb/datadict/datadict-firebird.inc.php +++ b/libraries/adodb/datadict/datadict-firebird.inc.php @@ -1,33 +1,49 @@ <?php - /** - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4 for best viewing. - -*/ + * Data Dictionary for Firebird. + * + * 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(); class ADODB2_firebird extends ADODB_DataDict { var $databaseType = 'firebird'; var $seqField = false; - var $seqPrefix = 'gen_'; + var $seqPrefix = 's_'; var $blobSize = 40000; + var $renameColumn = 'ALTER TABLE %s ALTER %s TO %s'; + var $alterCol = ' ALTER'; + var $dropCol = ' DROP'; - function ActualType($meta) + function ActualType($meta) { switch($meta) { case 'C': return 'VARCHAR'; - case 'XL': return 'VARCHAR(32000)'; - case 'X': return 'VARCHAR(4000)'; + case 'XL': + case 'X': return 'BLOB SUB_TYPE TEXT'; - case 'C2': return 'VARCHAR'; // up to 32K - case 'X2': return 'VARCHAR(4000)'; + case 'C2': return 'VARCHAR(32765)'; // up to 32K + case 'X2': return 'VARCHAR(4096)'; + + case 'V': return 'CHAR'; + case 'C1': return 'CHAR(1)'; case 'B': return 'BLOB'; @@ -40,7 +56,7 @@ class ADODB2_firebird extends ADODB_DataDict { case 'I1': return 'SMALLINT'; case 'I2': return 'SMALLINT'; case 'I4': return 'INTEGER'; - case 'I8': return 'INTEGER'; + case 'I8': return 'BIGINT'; case 'F': return 'DOUBLE PRECISION'; case 'N': return 'DECIMAL'; @@ -49,7 +65,7 @@ class ADODB2_firebird extends ADODB_DataDict { } } - function NameQuote($name = NULL) + function NameQuote($name = NULL,$allowBrackets=false) { if (!is_string($name)) { return FALSE; @@ -90,9 +106,9 @@ class ADODB2_firebird extends ADODB_DataDict { { if (strpos($t,'.') !== false) { $tarr = explode('.',$t); - return 'DROP GENERATOR '.$tarr[0].'."gen_'.$tarr[1].'"'; + return 'DROP GENERATOR '.$tarr[0].'."s_'.$tarr[1].'"'; } - return 'DROP GENERATOR "GEN_'.$t; + return 'DROP GENERATOR s_'.$t; } @@ -103,11 +119,41 @@ class ADODB2_firebird extends ADODB_DataDict { if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault"; if ($fnotnull) $suffix .= ' NOT NULL'; if ($fautoinc) $this->seqField = $fname; + $fconstraint = preg_replace("/``/", "\"", $fconstraint); if ($fconstraint) $suffix .= ' '.$fconstraint; return $suffix; } + /** + Generate the SQL to create table. Returns an array of sql strings. + */ + function CreateTableSQL($tabname, $flds, $tableoptions=array()) + { + list($lines,$pkey,$idxs) = $this->_GenFields($flds, true); + // genfields can return FALSE at times + if ($lines == null) $lines = array(); + + $taboptions = $this->_Options($tableoptions); + $tabname = $this->TableName ($tabname); + $sql = $this->_TableSQL($tabname,$lines,$pkey,$taboptions); + + if ($this->autoIncrement && !isset($taboptions['DROP'])) + { $tsql = $this->_Triggers($tabname,$taboptions); + foreach($tsql as $s) $sql[] = $s; + } + + if (is_array($idxs)) { + foreach($idxs as $idx => $idxdef) { + $sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']); + $sql = array_merge($sql, $sql_idxs); + } + } + + return $sql; + } + + /* CREATE or replace TRIGGER jaddress_insert before insert on jaddress @@ -128,24 +174,60 @@ end; else $tab = $tab1; $seqField = $this->seqField; $seqname = $this->schema.'.'.$this->seqPrefix.$tab; - $trigname = $this->schema.'.trig_'.$this->seqPrefix.$tab; + $trigname = $this->schema.'.t_'.$this->seqPrefix.$tab; } else { $seqField = $this->seqField; $seqname = $this->seqPrefix.$tab1; - $trigname = 'trig_'.$seqname; + $trigname = 't_'.$seqname; } - if (isset($tableoptions['REPLACE'])) + + if (isset($tableoptions['DROP'])) + { $sql[] = "DROP GENERATOR $seqname"; + } + elseif (isset($tableoptions['REPLACE'])) { $sql[] = "DROP GENERATOR \"$seqname\""; $sql[] = "CREATE GENERATOR \"$seqname\""; $sql[] = "ALTER TRIGGER \"$trigname\" BEFORE INSERT OR UPDATE AS BEGIN IF ( NEW.$seqField IS NULL OR NEW.$seqField = 0 ) THEN NEW.$seqField = GEN_ID(\"$seqname\", 1); END"; } else - { $sql[] = "CREATE GENERATOR \"$seqname\""; - $sql[] = "CREATE TRIGGER \"$trigname\" FOR $tabname BEFORE INSERT OR UPDATE AS BEGIN IF ( NEW.$seqField IS NULL OR NEW.$seqField = 0 ) THEN NEW.$seqField = GEN_ID(\"$seqname\", 1); END"; + { $sql[] = "CREATE GENERATOR $seqname"; + $sql[] = "CREATE TRIGGER $trigname FOR $tabname BEFORE INSERT OR UPDATE AS BEGIN IF ( NEW.$seqField IS NULL OR NEW.$seqField = 0 ) THEN NEW.$seqField = GEN_ID($seqname, 1); END"; } $this->seqField = false; return $sql; } + /** + * Change the definition of one column + * + * As some DBM's can't do that on there own, you need to supply the complete definition of the new table, + * to allow, recreating the table and copying the content over to the new table + * @param string $tabname table-name + * @param string $flds column-name and type for the changed column + * @param string $tableflds='' complete definition of the new table, eg. for postgres, default '' + * @param array/string $tableoptions='' options for the new table see CreateTableSQL, default '' + * @return array with SQL strings + */ + function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') + { + $tabname = $this->TableName ($tabname); + $sql = array(); + list($lines,$pkey,$idxs) = $this->_GenFields($flds); + // genfields can return FALSE at times + if ($lines == null) $lines = array(); + $alter = 'ALTER TABLE ' . $tabname . $this->alterCol . ' '; + foreach($lines as $v) { + $sql[] = $alter . $v; + } + if (is_array($idxs)) { + foreach($idxs as $idx => $idxdef) { + $sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']); + $sql = array_merge($sql, $sql_idxs); + } + + } + return $sql; + } + } diff --git a/libraries/adodb/datadict/datadict-generic.inc.php b/libraries/adodb/datadict/datadict-generic.inc.php index e2e6909e7..c9c8dee87 100644 --- a/libraries/adodb/datadict/datadict-generic.inc.php +++ b/libraries/adodb/datadict/datadict-generic.inc.php @@ -1,16 +1,23 @@ <?php - /** - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4 for best viewing. - -*/ + * Generic Data Dictionary. + * + * 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(); diff --git a/libraries/adodb/datadict/datadict-ibase.inc.php b/libraries/adodb/datadict/datadict-ibase.inc.php index 495a722d6..5f58880ff 100644 --- a/libraries/adodb/datadict/datadict-ibase.inc.php +++ b/libraries/adodb/datadict/datadict-ibase.inc.php @@ -1,16 +1,23 @@ <?php - /** - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4 for best viewing. - -*/ + * Data Dictionary for Interbase. + * + * 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(); diff --git a/libraries/adodb/datadict/datadict-informix.inc.php b/libraries/adodb/datadict/datadict-informix.inc.php index 25726f499..acb5ba74c 100644 --- a/libraries/adodb/datadict/datadict-informix.inc.php +++ b/libraries/adodb/datadict/datadict-informix.inc.php @@ -1,16 +1,23 @@ <?php - /** - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4 for best viewing. - -*/ + * Data Dictionary for Informix. + * + * 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(); diff --git a/libraries/adodb/datadict/datadict-mssql.inc.php b/libraries/adodb/datadict/datadict-mssql.inc.php index 2c496dea6..1bcb27da1 100644 --- a/libraries/adodb/datadict/datadict-mssql.inc.php +++ b/libraries/adodb/datadict/datadict-mssql.inc.php @@ -1,16 +1,23 @@ <?php - /** - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4 for best viewing. - -*/ + * Data Dictionary for Microsoft SQL Server (mssql) + * + * 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 + */ /* In ADOdb, named quotes for MS SQL Server use ". From the MSSQL Docs: @@ -269,7 +276,7 @@ CREATE TABLE } - function _GetSize($ftype, $ty, $fsize, $fprec) + function _GetSize($ftype, $ty, $fsize, $fprec, $options=false) { switch ($ftype) { case 'INT': @@ -279,7 +286,7 @@ CREATE TABLE return $ftype; } if ($ty == 'T') return $ftype; - return parent::_GetSize($ftype, $ty, $fsize, $fprec); + return parent::_GetSize($ftype, $ty, $fsize, $fprec, $options); } } diff --git a/libraries/adodb/datadict/datadict-mssqlnative.inc.php b/libraries/adodb/datadict/datadict-mssqlnative.inc.php index 36d5fcad4..b53dcd97b 100644 --- a/libraries/adodb/datadict/datadict-mssqlnative.inc.php +++ b/libraries/adodb/datadict/datadict-mssqlnative.inc.php @@ -1,16 +1,25 @@ <?php - /** - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4 for best viewing. - -*/ + * Data Dictionary for Microsoft SQL Server native (mssqlnative) + + * FileDescription + * + * 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 + */ /* In ADOdb, named quotes for MS SQL Server use ". From the MSSQL Docs: @@ -45,7 +54,7 @@ if (!defined('ADODB_DIR')) die(); class ADODB2_mssqlnative extends ADODB_DataDict { var $databaseType = 'mssqlnative'; - var $dropIndex = 'DROP INDEX %1$s ON %2$s'; + var $dropIndex = /** @lang text */ 'DROP INDEX %1$s ON %2$s'; var $renameTable = "EXEC sp_rename '%s','%s'"; var $renameColumn = "EXEC sp_rename '%s.%s','%s'"; var $typeX = 'TEXT'; ## Alternatively, set it to VARCHAR(4000) @@ -53,12 +62,14 @@ class ADODB2_mssqlnative extends ADODB_DataDict { //var $alterCol = ' ALTER COLUMN '; + public $blobAllowsDefaultValue = true; + public $blobAllowsNotNull = true; + function MetaType($t,$len=-1,$fieldobj=false) { if (is_object($t)) { $fieldobj = $t; $t = $fieldobj->type; - $len = $fieldobj->max_length; } $_typeConversion = array( @@ -94,8 +105,11 @@ class ADODB2_mssqlnative extends ADODB_DataDict { -3 => 'X' ); - return $_typeConversion($t); + if (isset($_typeConversion[$t])) { + return $_typeConversion[$t]; + } + return ADODB_DEFAULT_METATYPE; } function ActualType($meta) @@ -126,7 +140,6 @@ class ADODB2_mssqlnative extends ADODB_DataDict { case 'F': return 'REAL'; case 'N': return 'NUMERIC'; default: - print "RETURN $meta"; return $meta; } } @@ -136,7 +149,7 @@ class ADODB2_mssqlnative extends ADODB_DataDict { { $tabname = $this->TableName ($tabname); $f = array(); - list($lines,$pkey) = $this->_GenFields($flds); + list($lines,) = $this->_GenFields($flds); $s = "ALTER TABLE $tabname $this->addCol"; foreach($lines as $v) { $f[] = "\n $v"; @@ -146,30 +159,29 @@ class ADODB2_mssqlnative extends ADODB_DataDict { return $sql; } - function DefaultConstraintname($tabname, $colname) + /** + * Get a column's default constraint. + * + * @param string $tabname + * @param string $colname + * @return string|null The Constraint's name, or null if there is none. + */ + function defaultConstraintName($tabname, $colname) { - $constraintname = false; - $rs = $this->connection->Execute( - "SELECT name FROM sys.default_constraints - WHERE object_name(parent_object_id) = '$tabname' - AND col_name(parent_object_id, parent_column_id) = '$colname'" - ); - if ( is_object($rs) ) { - $row = $rs->FetchRow(); - $constraintname = $row['name']; - } - return $constraintname; + $sql = "SELECT name FROM sys.default_constraints + WHERE object_name(parent_object_id) = ? + AND col_name(parent_object_id, parent_column_id) = ?"; + return $this->connection->getOne($sql, [$tabname, $colname]); } - + function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') { $tabname = $this->TableName ($tabname); $sql = array(); - list($lines,$pkey,$idxs) = $this->_GenFields($flds); + list($lines,,$idxs) = $this->_GenFields($flds); $alter = 'ALTER TABLE ' . $tabname . $this->alterCol . ' '; foreach($lines as $v) { - $not_null = false; if ($not_null = preg_match('/NOT NULL/i',$v)) { $v = preg_replace('/NOT NULL/i','',$v); } @@ -177,7 +189,7 @@ class ADODB2_mssqlnative extends ADODB_DataDict { list(,$colname,$default) = $matches; $v = preg_replace('/^' . preg_quote($colname) . '\s/', '', $v); $t = trim(str_replace('DEFAULT '.$default,'',$v)); - if ( $constraintname = $this->DefaultConstraintname($tabname,$colname) ) { + if ( $constraintname = $this->defaultConstraintName($tabname,$colname) ) { $sql[] = 'ALTER TABLE '.$tabname.' DROP CONSTRAINT '. $constraintname; } if ($not_null) { @@ -190,7 +202,7 @@ class ADODB2_mssqlnative extends ADODB_DataDict { . ' DEFAULT ' . $default . ' FOR ' . $colname; } else { $colname = strtok($v," "); - if ( $constraintname = $this->DefaultConstraintname($tabname,$colname) ) { + if ( $constraintname = $this->defaultConstraintName($tabname,$colname) ) { $sql[] = 'ALTER TABLE '.$tabname.' DROP CONSTRAINT '. $constraintname; } if ($not_null) { @@ -218,17 +230,19 @@ class ADODB2_mssqlnative extends ADODB_DataDict { * @param string $tableflds Throwaway value to make the function match the parent * @param string $tableoptions Throway value to make the function match the parent * - * @return string The SQL necessary to drop the column + * @return string[] The SQL necessary to drop the column */ function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') { $tabname = $this->TableName ($tabname); - if (!is_array($flds)) - $flds = explode(',',$flds); + if (!is_array($flds)) { + /** @noinspection PhpParamsInspection */ + $flds = explode(',', $flds); + } $f = array(); $s = 'ALTER TABLE ' . $tabname; foreach($flds as $v) { - if ( $constraintname = $this->DefaultConstraintname($tabname,$v) ) { + if ( $constraintname = $this->defaultConstraintName($tabname,$v) ) { $sql[] = 'ALTER TABLE ' . $tabname . ' DROP CONSTRAINT ' . $constraintname; } $f[] = ' DROP COLUMN ' . $this->NameQuote($v); @@ -239,6 +253,8 @@ class ADODB2_mssqlnative extends ADODB_DataDict { } // return string must begin with space + + /** @noinspection DuplicatedCode */ function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) { $suffix = ''; @@ -250,78 +266,7 @@ class ADODB2_mssqlnative extends ADODB_DataDict { return $suffix; } - /* -CREATE TABLE - [ database_name.[ owner ] . | owner. ] table_name - ( { < column_definition > - | column_name AS computed_column_expression - | < table_constraint > ::= [ CONSTRAINT constraint_name ] } - - | [ { PRIMARY KEY | UNIQUE } [ ,...n ] - ) - -[ ON { filegroup | DEFAULT } ] -[ TEXTIMAGE_ON { filegroup | DEFAULT } ] - -< column_definition > ::= { column_name data_type } - [ COLLATE < collation_name > ] - [ [ DEFAULT constant_expression ] - | [ IDENTITY [ ( seed , increment ) [ NOT FOR REPLICATION ] ] ] - ] - [ ROWGUIDCOL] - [ < column_constraint > ] [ ...n ] - -< column_constraint > ::= [ CONSTRAINT constraint_name ] - { [ NULL | NOT NULL ] - | [ { PRIMARY KEY | UNIQUE } - [ CLUSTERED | NONCLUSTERED ] - [ WITH FILLFACTOR = fillfactor ] - [ON {filegroup | DEFAULT} ] ] - ] - | [ [ FOREIGN KEY ] - REFERENCES ref_table [ ( ref_column ) ] - [ ON DELETE { CASCADE | NO ACTION } ] - [ ON UPDATE { CASCADE | NO ACTION } ] - [ NOT FOR REPLICATION ] - ] - | CHECK [ NOT FOR REPLICATION ] - ( logical_expression ) - } - -< table_constraint > ::= [ CONSTRAINT constraint_name ] - { [ { PRIMARY KEY | UNIQUE } - [ CLUSTERED | NONCLUSTERED ] - { ( column [ ASC | DESC ] [ ,...n ] ) } - [ WITH FILLFACTOR = fillfactor ] - [ ON { filegroup | DEFAULT } ] - ] - | FOREIGN KEY - [ ( column [ ,...n ] ) ] - REFERENCES ref_table [ ( ref_column [ ,...n ] ) ] - [ ON DELETE { CASCADE | NO ACTION } ] - [ ON UPDATE { CASCADE | NO ACTION } ] - [ NOT FOR REPLICATION ] - | CHECK [ NOT FOR REPLICATION ] - ( search_conditions ) - } - - - */ - - /* - CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name - ON { table | view } ( column [ ASC | DESC ] [ ,...n ] ) - [ WITH < index_option > [ ,...n] ] - [ ON filegroup ] - < index_option > :: = - { PAD_INDEX | - FILLFACTOR = fillfactor | - IGNORE_DUP_KEY | - DROP_EXISTING | - STATISTICS_NORECOMPUTE | - SORT_IN_TEMPDB - } -*/ + /** @noinspection DuplicatedCode */ function _IndexSQL($idxname, $tabname, $flds, $idxoptions) { $sql = array(); @@ -353,17 +298,18 @@ CREATE TABLE } - function _GetSize($ftype, $ty, $fsize, $fprec) + function _GetSize($ftype, $ty, $fsize, $fprec, $options=false) { switch ($ftype) { - case 'INT': - case 'SMALLINT': - case 'TINYINT': - case 'BIGINT': + case 'INT': + case 'SMALLINT': + case 'TINYINT': + case 'BIGINT': + return $ftype; + } + if ($ty == 'T') { return $ftype; } - if ($ty == 'T') return $ftype; - return parent::_GetSize($ftype, $ty, $fsize, $fprec); - + return parent::_GetSize($ftype, $ty, $fsize, $fprec, $options); } } diff --git a/libraries/adodb/datadict/datadict-mysql.inc.php b/libraries/adodb/datadict/datadict-mysql.inc.php index 00a43a2a1..a1ee950a6 100644 --- a/libraries/adodb/datadict/datadict-mysql.inc.php +++ b/libraries/adodb/datadict/datadict-mysql.inc.php @@ -1,16 +1,23 @@ <?php - /** - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4 for best viewing. - -*/ + * Data Dictionary for MySQL. + * + * 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(); @@ -24,8 +31,11 @@ class ADODB2_mysql extends ADODB_DataDict { var $dropIndex = 'DROP INDEX %s ON %s'; var $renameColumn = 'ALTER TABLE %s CHANGE COLUMN %s %s %s'; // needs column-definition! + public $blobAllowsNotNull = true; + function MetaType($t,$len=-1,$fieldobj=false) { + if (is_object($t)) { $fieldobj = $t; $t = $fieldobj->type; @@ -74,7 +84,7 @@ class ADODB2_mysql extends ADODB_DataDict { case 'SMALLINT': return $is_serial ? 'R' : 'I2'; case 'MEDIUMINT': return $is_serial ? 'R' : 'I4'; case 'BIGINT': return $is_serial ? 'R' : 'I8'; - default: return 'N'; + default: return ADODB_DEFAULT_METATYPE; } } diff --git a/libraries/adodb/datadict/datadict-oci8.inc.php b/libraries/adodb/datadict/datadict-oci8.inc.php index 57cf0af52..9a239095c 100644 --- a/libraries/adodb/datadict/datadict-oci8.inc.php +++ b/libraries/adodb/datadict/datadict-oci8.inc.php @@ -1,16 +1,23 @@ <?php - /** - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4 for best viewing. - -*/ + * Data Dictionary for Oracle (oci8) + * + * 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(); @@ -25,8 +32,18 @@ class ADODB2_oci8 extends ADODB_DataDict { var $alterCol = ' MODIFY '; var $typeX = 'VARCHAR(4000)'; var $typeXL = 'CLOB'; - - function MetaType($t, $len=-1, $fieldobj=false) + + /** + * Legacy compatibility for sequence names for emulated auto-increments. + * + * If set to true, creates sequences and triggers as TRIG_394545594 + * instead of TRIG_possibly_too_long_tablename + * + * @var bool $useCompactAutoIncrements + */ + public $useCompactAutoIncrements = false; + + function metaType($t, $len=-1, $fieldobj=false) { if (is_object($t)) { $fieldobj = $t; @@ -69,7 +86,7 @@ class ADODB2_oci8 extends ADODB_DataDict { return 'I'; default: - return 'N'; + return ADODB_DEFAULT_METATYPE; } } @@ -185,32 +202,52 @@ class ADODB2_oci8 extends ADODB_DataDict { return $suffix; } -/* -CREATE or replace TRIGGER jaddress_insert -before insert on jaddress -for each row -begin -select seqaddress.nextval into :new.A_ID from dual; -end; -*/ + /** + * Creates an insert trigger to emulate an auto-increment column + * in a table + * + * @param string $tabname The name of the table + * @param string[] $tableoptions Optional configuration items + * + * @return string[] The SQL statements to create the trigger + */ function _Triggers($tabname,$tableoptions) { + if (!$this->seqField) return array(); - if ($this->schema) { + if ($this->schema) + { $t = strpos($tabname,'.'); - if ($t !== false) $tab = substr($tabname,$t+1); - else $tab = $tabname; + if ($t !== false) + $tab = substr($tabname,$t+1); + else + $tab = $tabname; + + if ($this->connection->useCompactAutoIncrements) + $id = sprintf('%u',crc32(strtolower($tab))); + else + $id = $tab; + $seqname = $this->schema.'.'.$this->seqPrefix.$tab; $trigname = $this->schema.'.'.$this->trigPrefix.$this->seqPrefix.$tab; - } else { - $seqname = $this->seqPrefix.$tabname; - $trigname = $this->trigPrefix.$seqname; + + } + else + { + if ($this->connection->useCompactAutoIncrements) + $id = sprintf('%u',crc32(strtolower($tabname))); + else + $id = $tabname; + + $seqname = $this->seqPrefix.$id; + $trigname = $this->trigPrefix.$id; } if (strlen($seqname) > 30) { $seqname = $this->seqPrefix.uniqid(''); } // end if + if (strlen($trigname) > 30) { $trigname = $this->trigPrefix.uniqid(''); } // end if @@ -221,8 +258,8 @@ end; $seqIncr = ''; if (isset($tableoptions['SEQUENCE_INCREMENT'])){$seqIncr = ' INCREMENT BY '.$tableoptions['SEQUENCE_INCREMENT'];} $seqStart = ''; - if (isset($tableoptions['SEQUENCE_START'])){$seqIncr = ' START WITH '.$tableoptions['SEQUENCE_START'];} - $sql[] = "CREATE SEQUENCE $seqname $seqStart $seqIncr $seqCache"; + if (isset($tableoptions['SEQUENCE_START'])){$seqStart = ' START WITH '.$tableoptions['SEQUENCE_START'];} + $sql[] = "CREATE SEQUENCE $seqname MINVALUE 1 $seqStart $seqIncr $seqCache"; $sql[] = "CREATE OR REPLACE TRIGGER $trigname BEFORE insert ON $tabname FOR EACH ROW WHEN (NEW.$this->seqField IS NULL OR NEW.$this->seqField = 0) BEGIN select $seqname.nextval into :new.$this->seqField from dual; END;"; $this->seqField = false; diff --git a/libraries/adodb/datadict/datadict-postgres.inc.php b/libraries/adodb/datadict/datadict-postgres.inc.php index 99a564131..17627c44c 100644 --- a/libraries/adodb/datadict/datadict-postgres.inc.php +++ b/libraries/adodb/datadict/datadict-postgres.inc.php @@ -1,22 +1,29 @@ <?php - /** - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4 for best viewing. - -*/ + * Data Dictionary for PostgreSQL. + * + * 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(); -class ADODB2_postgres extends ADODB_DataDict { - +class ADODB2_postgres extends ADODB_DataDict +{ var $databaseType = 'postgres'; var $seqField = false; var $seqPrefix = 'SEQ_'; @@ -25,7 +32,10 @@ class ADODB2_postgres extends ADODB_DataDict { var $renameTable = 'ALTER TABLE %s RENAME TO %s'; // at least since 7.1 var $dropTable = 'DROP TABLE %s CASCADE'; - function MetaType($t,$len=-1,$fieldobj=false) + public $blobAllowsDefaultValue = true; + public $blobAllowsNotNull = true; + + function metaType($t, $len=-1, $fieldobj=false) { if (is_object($t)) { $fieldobj = $t; @@ -85,13 +95,13 @@ class ADODB2_postgres extends ADODB_DataDict { return 'F'; default: - return 'N'; + return ADODB_DEFAULT_METATYPE; } } - function ActualType($meta) + function actualType($meta) { - switch($meta) { + switch ($meta) { case 'C': return 'VARCHAR'; case 'XL': case 'X': return 'TEXT'; @@ -128,12 +138,12 @@ class ADODB2_postgres extends ADODB_DataDict { * @param string $flds column-names and types for the changed columns * @return array with SQL strings */ - function AddColumnSQL($tabname, $flds) + function addColumnSQL($tabname, $flds) { - $tabname = $this->TableName ($tabname); + $tabname = $this->tableName($tabname); $sql = array(); $not_null = false; - list($lines,$pkey) = $this->_GenFields($flds); + list($lines,$pkey) = $this->_genFields($flds); $alter = 'ALTER TABLE ' . $tabname . $this->addCol . ' '; foreach($lines as $v) { if (($not_null = preg_match('/NOT NULL/i',$v))) { @@ -156,41 +166,31 @@ class ADODB2_postgres extends ADODB_DataDict { } - function DropIndexSQL ($idxname, $tabname = NULL) + function dropIndexSQL($idxname, $tabname = NULL) { - return array(sprintf($this->dropIndex, $this->TableName($idxname), $this->TableName($tabname))); + return array(sprintf($this->dropIndex, $this->tableName($idxname), $this->tableName($tabname))); } /** * Change the definition of one column * - * Postgres can't do that on it's own, you need to supply the complete defintion of the new table, + * Postgres can't do that on it's own, you need to supply the complete definition of the new table, * to allow, recreating the table and copying the content over to the new table * @param string $tabname table-name * @param string $flds column-name and type for the changed column - * @param string $tableflds complete defintion of the new table, eg. for postgres, default '' + * @param string $tableflds complete definition of the new table, eg. for postgres, default '' * @param array/ $tableoptions options for the new table see CreateTableSQL, default '' * @return array with SQL strings */ - /* - function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') - { - if (!$tableflds) { - if ($this->debug) ADOConnection::outp("AlterColumnSQL needs a complete table-definiton for PostgreSQL"); - return array(); - } - return $this->_recreate_copy_table($tabname,False,$tableflds,$tableoptions); - }*/ - - function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') + function alterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='') { // Check if alter single column datatype available - works with 8.0+ $has_alter_column = 8.0 <= (float) @$this->serverInfo['version']; if ($has_alter_column) { - $tabname = $this->TableName($tabname); + $tabname = $this->tableName($tabname); $sql = array(); - list($lines,$pkey) = $this->_GenFields($flds); + list($lines,$pkey) = $this->_genFields($flds); $set_null = false; foreach($lines as $v) { $alter = 'ALTER TABLE ' . $tabname . $this->alterCol . ' '; @@ -200,7 +200,7 @@ class ADODB2_postgres extends ADODB_DataDict { // this next block doesn't work - there is no way that I can see to // explicitly ask a column to be null using $flds else if ($set_null = preg_match('/NULL/i',$v)) { - // if they didn't specify not null, see if they explicitely asked for null + // if they didn't specify not null, see if they explicitly asked for null // Lookbehind pattern covers the case 'fieldname NULL datatype DEFAULT NULL' // only the first NULL should be removed, not the one specifying // the default value @@ -208,13 +208,12 @@ class ADODB2_postgres extends ADODB_DataDict { } if (preg_match('/^([^ ]+) .*DEFAULT (\'[^\']+\'|\"[^\"]+\"|[^ ]+)/',$v,$matches)) { - $existing = $this->MetaColumns($tabname); + $existing = $this->metaColumns($tabname); list(,$colname,$default) = $matches; $alter .= $colname; if ($this->connection) { - $old_coltype = $this->connection->MetaType($existing[strtoupper($colname)]); - } - else { + $old_coltype = $this->connection->metaType($existing[strtoupper($colname)]); + } else { $old_coltype = $t; } $v = preg_replace('/^' . preg_quote($colname) . '\s/', '', $v); @@ -250,7 +249,7 @@ class ADODB2_postgres extends ADODB_DataDict { $sql[] = $alter . ' TYPE ' . $rest; } -# list($colname) = explode(' ',$v); + #list($colname) = explode(' ',$v); if ($not_null) { // this does not error out if the column is already not null $sql[] = $alter . ' SET NOT NULL'; @@ -268,31 +267,33 @@ class ADODB2_postgres extends ADODB_DataDict { if ($this->debug) ADOConnection::outp("AlterColumnSQL needs a complete table-definiton for PostgreSQL"); return array(); } - return $this->_recreate_copy_table($tabname,False,$tableflds,$tableoptions); + return $this->_recreate_copy_table($tabname, false, $tableflds,$tableoptions); } /** * Drop one column * - * Postgres < 7.3 can't do that on it's own, you need to supply the complete defintion of the new table, + * Postgres < 7.3 can't do that on it's own, you need to supply the complete definition of the new table, * to allow, recreating the table and copying the content over to the new table * @param string $tabname table-name * @param string $flds column-name and type for the changed column - * @param string $tableflds complete defintion of the new table, eg. for postgres, default '' + * @param string $tableflds complete definition of the new table, eg. for postgres, default '' * @param array/ $tableoptions options for the new table see CreateTableSQL, default '' * @return array with SQL strings */ - function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') + function dropColumnSQL($tabname, $flds, $tableflds='', $tableoptions='') { $has_drop_column = 7.3 <= (float) @$this->serverInfo['version']; if (!$has_drop_column && !$tableflds) { - if ($this->debug) ADOConnection::outp("DropColumnSQL needs complete table-definiton for PostgreSQL < 7.3"); - return array(); - } + if ($this->debug) { + ADOConnection::outp("dropColumnSQL needs complete table-definiton for PostgreSQL < 7.3"); + } + return array(); + } if ($has_drop_column) { - return ADODB_DataDict::DropColumnSQL($tabname, $flds); + return ADODB_DataDict::dropColumnSQL($tabname, $flds); } - return $this->_recreate_copy_table($tabname,$flds,$tableflds,$tableoptions); + return $this->_recreate_copy_table($tabname, $flds, $tableflds, $tableoptions); } /** @@ -303,68 +304,82 @@ class ADODB2_postgres extends ADODB_DataDict { * @internal * @param string $tabname table-name * @param string $dropflds column-names to drop - * @param string $tableflds complete defintion of the new table, eg. for postgres + * @param string $tableflds complete definition of the new table, eg. for postgres * @param array/string $tableoptions options for the new table see CreateTableSQL, default '' * @return array with SQL strings */ - function _recreate_copy_table($tabname,$dropflds,$tableflds,$tableoptions='') + function _recreate_copy_table($tabname, $dropflds, $tableflds, $tableoptions='') { if ($dropflds && !is_array($dropflds)) $dropflds = explode(',',$dropflds); $copyflds = array(); - foreach($this->MetaColumns($tabname) as $fld) { - if (!$dropflds || !in_array($fld->name,$dropflds)) { - // we need to explicit convert varchar to a number to be able to do an AlterColumn of a char column to a nummeric one - if (preg_match('/'.$fld->name.' (I|I2|I4|I8|N|F)/i',$tableflds,$matches) && - in_array($fld->type,array('varchar','char','text','bytea'))) { + foreach($this->metaColumns($tabname) as $fld) { + if (preg_match('/'.$fld->name.' (\w+)/i', $tableflds, $matches)) { + $new_type = strtoupper($matches[1]); + // AlterColumn of a char column to a nummeric one needs an explicit conversation + if (in_array($new_type, array('I', 'I2', 'I4', 'I8', 'N', 'F')) && + in_array($fld->type, array('varchar','char','text','bytea')) + ) { $copyflds[] = "to_number($fld->name,'S9999999999999D99')"; } else { - $copyflds[] = $fld->name; - } - // identify the sequence name and the fld its on - if ($fld->primary_key && $fld->has_default && - preg_match("/nextval\('([^']+)'::text\)/",$fld->default_value,$matches)) { - $seq_name = $matches[1]; - $seq_fld = $fld->name; + // other column-type changes needs explicit decode, encode for bytea or cast otherwise + $new_actual_type = $this->actualType($new_type); + if (strtoupper($fld->type) != $new_actual_type) { + if ($new_actual_type == 'BYTEA' && $fld->type == 'text') { + $copyflds[] = "DECODE($fld->name, 'escape')"; + } elseif ($fld->type == 'bytea' && $new_actual_type == 'TEXT') { + $copyflds[] = "ENCODE($fld->name, 'escape')"; + } else { + $copyflds[] = "CAST($fld->name AS $new_actual_type)"; + } + } } + } else { + $copyflds[] = $fld->name; + } + // identify the sequence name and the fld its on + if ($fld->primary_key && $fld->has_default && + preg_match("/nextval\('([^']+)'::(text|regclass)\)/", $fld->default_value, $matches)) { + $seq_name = $matches[1]; + $seq_fld = $fld->name; } } - $copyflds = implode(', ',$copyflds); + $copyflds = implode(', ', $copyflds); $tempname = $tabname.'_tmp'; $aSql[] = 'BEGIN'; // we use a transaction, to make sure not to loose the content of the table $aSql[] = "SELECT * INTO TEMPORARY TABLE $tempname FROM $tabname"; - $aSql = array_merge($aSql,$this->DropTableSQL($tabname)); - $aSql = array_merge($aSql,$this->CreateTableSQL($tabname,$tableflds,$tableoptions)); + $aSql = array_merge($aSql,$this->dropTableSQL($tabname)); + $aSql = array_merge($aSql,$this->createTableSQL($tabname, $tableflds, $tableoptions)); $aSql[] = "INSERT INTO $tabname SELECT $copyflds FROM $tempname"; if ($seq_name && $seq_fld) { // if we have a sequence we need to set it again $seq_name = $tabname.'_'.$seq_fld.'_seq'; // has to be the name of the new implicit sequence - $aSql[] = "SELECT setval('$seq_name',MAX($seq_fld)) FROM $tabname"; + $aSql[] = "SELECT setval('$seq_name', MAX($seq_fld)) FROM $tabname"; } $aSql[] = "DROP TABLE $tempname"; - // recreate the indexes, if they not contain one of the droped columns - foreach($this->MetaIndexes($tabname) as $idx_name => $idx_data) - { + // recreate the indexes, if they not contain one of the dropped columns + foreach($this->metaIndexes($tabname) as $idx_name => $idx_data) { if (substr($idx_name,-5) != '_pkey' && (!$dropflds || !count(array_intersect($dropflds,$idx_data['columns'])))) { - $aSql = array_merge($aSql,$this->CreateIndexSQL($idx_name,$tabname,$idx_data['columns'], - $idx_data['unique'] ? array('UNIQUE') : False)); + $aSql = array_merge($aSql,$this->createIndexSQL($idx_name, $tabname, $idx_data['columns'], + $idx_data['unique'] ? array('UNIQUE') : false)); } } $aSql[] = 'COMMIT'; return $aSql; } - function DropTableSQL($tabname) + function dropTableSQL($tabname) { - $sql = ADODB_DataDict::DropTableSQL($tabname); - - $drop_seq = $this->_DropAutoIncrement($tabname); - if ($drop_seq) $sql[] = $drop_seq; + $sql = ADODB_DataDict::dropTableSQL($tabname); + $drop_seq = $this->_dropAutoIncrement($tabname); + if ($drop_seq) { + $sql[] = $drop_seq; + } return $sql; } // return string must begin with space - function _CreateSuffix($fname, &$ftype, $fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) + function _createSuffix($fname, &$ftype, $fnotnull, $fdefault, $fautoinc, $fconstraint, $funsigned) { if ($fautoinc) { $ftype = 'SERIAL'; @@ -377,34 +392,34 @@ class ADODB2_postgres extends ADODB_DataDict { return $suffix; } - // search for a sequece for the given table (asumes the seqence-name contains the table-name!) + // search for a sequence for the given table (asumes the seqence-name contains the table-name!) // if yes return sql to drop it // this is still necessary if postgres < 7.3 or the SERIAL was created on an earlier version!!! - function _DropAutoIncrement($tabname) + function _dropAutoIncrement($tabname) { $tabname = $this->connection->quote('%'.$tabname.'%'); - $seq = $this->connection->GetOne("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relname LIKE $tabname AND relkind='S'"); + $seq = $this->connection->getOne("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relname LIKE $tabname AND relkind='S'"); - // check if a tables depends on the sequenz and it therefor cant and dont need to be droped separatly - if (!$seq || $this->connection->GetOne("SELECT relname FROM pg_class JOIN pg_depend ON pg_class.relfilenode=pg_depend.objid WHERE relname='$seq' AND relkind='S' AND deptype='i'")) { - return False; + // check if a tables depends on the sequence and it therefore can't and don't need to be dropped separately + if (!$seq || $this->connection->getOne("SELECT relname FROM pg_class JOIN pg_depend ON pg_class.relfilenode=pg_depend.objid WHERE relname='$seq' AND relkind='S' AND deptype='i'")) { + return false; } return "DROP SEQUENCE ".$seq; } - function RenameTableSQL($tabname,$newname) + function renameTableSQL($tabname, $newname) { if (!empty($this->schema)) { - $rename_from = $this->TableName($tabname); + $rename_from = $this->tableName($tabname); $schema_save = $this->schema; $this->schema = false; - $rename_to = $this->TableName($newname); + $rename_to = $this->tableName($newname); $this->schema = $schema_save; return array (sprintf($this->renameTable, $rename_from, $rename_to)); } - return array (sprintf($this->renameTable, $this->TableName($tabname),$this->TableName($newname))); + return array (sprintf($this->renameTable, $this->tableName($tabname), $this->tableName($newname))); } /* @@ -440,17 +455,18 @@ CREATE [ UNIQUE ] INDEX index_name ON table [ USING acc_method ] ( func_name( column [, ... ]) [ ops_name ] ) [ WHERE predicate ] */ - function _IndexSQL($idxname, $tabname, $flds, $idxoptions) + function _indexSQL($idxname, $tabname, $flds, $idxoptions) { $sql = array(); if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) { $sql[] = sprintf ($this->dropIndex, $idxname, $tabname); - if ( isset($idxoptions['DROP']) ) + if ( isset($idxoptions['DROP']) ) { return $sql; + } } - if ( empty ($flds) ) { + if (empty($flds)) { return $sql; } @@ -458,27 +474,92 @@ CREATE [ UNIQUE ] INDEX index_name ON table $s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname . ' '; - if (isset($idxoptions['HASH'])) + if (isset($idxoptions['HASH'])) { $s .= 'USING HASH '; - - if ( isset($idxoptions[$this->upperName]) ) + } + + if (isset($idxoptions[$this->upperName])) { $s .= $idxoptions[$this->upperName]; - - if ( is_array($flds) ) - $flds = implode(', ',$flds); + } + + if (is_array($flds)) { + $flds = implode(', ', $flds); + } $s .= '(' . $flds . ')'; $sql[] = $s; return $sql; } - function _GetSize($ftype, $ty, $fsize, $fprec) + function _getSize($ftype, $ty, $fsize, $fprec, $options=false) { if (strlen($fsize) && $ty != 'X' && $ty != 'B' && $ty != 'I' && strpos($ftype,'(') === false) { $ftype .= "(".$fsize; if (strlen($fprec)) $ftype .= ",".$fprec; $ftype .= ')'; } + + /* + * Handle additional options + */ + if (is_array($options)) { + foreach($options as $type=>$value) { + switch ($type) { + case 'ENUM': + $ftype .= '(' . $value . ')'; + break; + default: + } + } + } return $ftype; } -} + + function changeTableSQL($tablename, $flds, $tableoptions = false, $dropOldFlds=false) + { + global $ADODB_FETCH_MODE; + parent::changeTableSQL($tablename, $flds); + $save = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; + if ($this->connection->fetchMode !== false) { + $savem = $this->connection->setFetchMode(false); + } + + // check table exists + $save_handler = $this->connection->raiseErrorFn; + $this->connection->raiseErrorFn = ''; + $cols = $this->metaColumns($tablename); + $this->connection->raiseErrorFn = $save_handler; + + if (isset($savem)) { + $this->connection->setFetchMode($savem); + } + $ADODB_FETCH_MODE = $save; + + $sqlResult=array(); + if ( empty($cols)) { + $sqlResult=$this->createTableSQL($tablename, $flds, $tableoptions); + } else { + $sqlResultAdd = $this->addColumnSQL($tablename, $flds); + $sqlResultAlter = $this->alterColumnSQL($tablename, $flds, '', $tableoptions); + $sqlResult = array_merge((array)$sqlResultAdd, (array)$sqlResultAlter); + + if ($dropOldFlds) { + // already exists, alter table instead + list($lines,$pkey,$idxs) = $this->_genFields($flds); + // genfields can return FALSE at times + if ($lines == null) { + $lines = array(); + } + $alter = 'ALTER TABLE ' . $this->tableName($tablename); + foreach ( $cols as $id => $v ) { + if ( !isset($lines[$id]) ) { + $sqlResult[] = $alter . $this->dropCol . ' ' . $v->name; + } + } + } + + } + return $sqlResult; + } +} // end class diff --git a/libraries/adodb/datadict/datadict-sapdb.inc.php b/libraries/adodb/datadict/datadict-sapdb.inc.php index fbf931c73..20c16aa6c 100644 --- a/libraries/adodb/datadict/datadict-sapdb.inc.php +++ b/libraries/adodb/datadict/datadict-sapdb.inc.php @@ -1,17 +1,23 @@ <?php - /** - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4 for best viewing. - - Modified from datadict-generic.inc.php for sapdb by RalfBecker-AT-outdoor-training.de -*/ + * Data Dictionary for SAP DB. + * + * 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(); @@ -71,7 +77,7 @@ class ADODB2_sapdb extends ADODB_DataDict { 'FLOAT' => 'F', 'FIXED' => 'N', ); - $type = isset($maxdb_type2adodb[$t]) ? $maxdb_type2adodb[$t] : 'C'; + $type = isset($maxdb_type2adodb[$t]) ? $maxdb_type2adodb[$t] : ADODB_DEFAULT_METATYPE; // convert integer-types simulated with fixed back to integer if ($t == 'FIXED' && !$fieldobj->scale && ($len == 20 || $len == 3)) { diff --git a/libraries/adodb/datadict/datadict-sqlite.inc.php b/libraries/adodb/datadict/datadict-sqlite.inc.php index 86b1b0478..942927f8a 100644 --- a/libraries/adodb/datadict/datadict-sqlite.inc.php +++ b/libraries/adodb/datadict/datadict-sqlite.inc.php @@ -1,18 +1,23 @@ <?php - /** - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4 for best viewing. - - SQLite datadict Andrei Besleaga - -*/ + * Data Dictionary for SQLite. + * + * 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(); @@ -25,8 +30,9 @@ class ADODB2_sqlite extends ADODB_DataDict { var $dropIndex = 'DROP INDEX IF EXISTS %s'; var $renameTable = 'ALTER TABLE %s RENAME TO %s'; - - + public $blobAllowsDefaultValue = true; + public $blobAllowsNotNull = true; + function ActualType($meta) { switch(strtoupper($meta)) { @@ -58,7 +64,7 @@ class ADODB2_sqlite extends ADODB_DataDict { } // return string must begin with space - function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) + function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) { $suffix = ''; if ($funsigned) $suffix .= ' UNSIGNED'; diff --git a/libraries/adodb/datadict/datadict-sybase.inc.php b/libraries/adodb/datadict/datadict-sybase.inc.php index d4e5f0530..e565f8e21 100644 --- a/libraries/adodb/datadict/datadict-sybase.inc.php +++ b/libraries/adodb/datadict/datadict-sybase.inc.php @@ -1,16 +1,23 @@ <?php - /** - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4 for best viewing. - -*/ + * Data Dictionary for SyBase. + * + * 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(); diff --git a/libraries/adodb/docs/README.md b/libraries/adodb/docs/README.md index b0ec29417..aefdc884a 100644 --- a/libraries/adodb/docs/README.md +++ b/libraries/adodb/docs/README.md @@ -1,8 +1,8 @@ # ADOdb Documentation -ADOdb documentation is available in the following locations +ADOdb documentation is available in the following locations: -- [Online](http://adodb.org/) +- [Online](https://adodb.org/) - [Download](https://sourceforge.net/projects/adodb/files/Documentation/) for offline use ## Legacy documentation diff --git a/libraries/adodb/docs/changelog.md b/libraries/adodb/docs/changelog.md index 1e097e962..9ed825b0b 100644 --- a/libraries/adodb/docs/changelog.md +++ b/libraries/adodb/docs/changelog.md @@ -1,129 +1,750 @@ # ADOdb Changelog - v5.x +All notable changes to this project will be documented in this file. +As of version 5.20.1, its format is based on +[Keep a Changelog](https://keepachangelog.com/). + +This project adheres to the [Semantic Versioning](https://semver.org/) +specification, since version 5.20.0. + Older changelogs: [v4.x](changelog_v4.x.md), [v3.x](changelog_v3.x.md), [v2.x](changelog_v2.x.md). -## 5.20.9 - 21-Dec-2016 +-------------------------------------------------------------------------------- + +## [5.21.2] - 2021-08-22 + +### Fixed + +- Fix syntax error in toexport.inc.php + [#749](https://github.com/ADOdb/ADOdb/issues/749) +- pgsql: fix fetchField() parameter naming + [#752](https://github.com/ADOdb/ADOdb/issues/752) + + +## [5.21.1] - 2021-08-15 + +### Changed + +- Standardized source code file headers + [#728](https://github.com/ADOdb/ADOdb/issues/728) +- Code cleanup: PHPDoc, code style, whitespace, etc. + [#691](https://github.com/ADOdb/ADOdb/issues/691) + (and others) + +### Fixed + +- Caching in FieldTypesArray() causes problems + [#687](https://github.com/ADOdb/ADOdb/issues/687) +- setConnectionParameter() method should not be final + [#694](https://github.com/ADOdb/ADOdb/issues/694) +- Final private methods throw warning (PHP 8) + [#711](https://github.com/ADOdb/ADOdb/issues/711) +- Fix record count when executing SQL with subqueries + [#715](https://github.com/ADOdb/ADOdb/issues/715) +- Incorrect handling of $ADODB_QUOTE_FIELDNAMES = true + [#721](https://github.com/ADOdb/ADOdb/issues/721) +- db2: fix columns always returned in lowercase + [#719](https://github.com/ADOdb/ADOdb/issues/719) +- PDO: Bind parameters fail if sent in associative array + [#705](https://github.com/ADOdb/ADOdb/issues/705) +- mssql: _insertid() doesn't work anymore + [#692](https://github.com/ADOdb/ADOdb/issues/692) +- mssql: PHP warnings in dropColumnSQL() + [#696](https://github.com/ADOdb/ADOdb/issues/696) +- mssql: duplicate key in SQLDate convert formats + [#748](https://github.com/ADOdb/ADOdb/issues/748) +- mysql: affected_rows() returns number instead of false + [#604](https://github.com/ADOdb/ADOdb/issues/604) +- mysql: TypeError when calling get/setChangeSet on unset connection (PHP 8) + [#686](https://github.com/ADOdb/ADOdb/issues/686) +- mysql: TypeError when calling setConnectionParameter() with non-numeric value (PHP 8) + [#693](https://github.com/ADOdb/ADOdb/issues/693) +- pdo: Affected_Rows() throws Notice and returns 0 when rows affected + [#733](https://github.com/ADOdb/ADOdb/issues/733) +- pgsql: sub-selects require aliasing + [#736](https://github.com/ADOdb/ADOdb/issues/736) +- xml: Invalid SQL in extractSchema() + [#707](https://github.com/ADOdb/ADOdb/issues/707) + +### Removed + +- Use of _ADODB_COUNT as workaround for counting in complex queries + (introduced in [#88](https://github.com/ADOdb/ADOdb/issues/88)) + [#715](https://github.com/ADOdb/ADOdb/issues/715) + + + +## [5.21.0] - 2021-02-27 + +### Fixed + +- pgsql: param(0) returns invalid `$0` placeholder + [#682](https://github.com/ADOdb/ADOdb/issues/682) + + +## [5.21.0-rc.1] - 2021-02-02 + +Includes all fixes from 5.20.20. + +### Added + +- Explicit support for PHP 8 with Composer + +### Fixed + +- Replace adodb_str_replace() calls with str_replace() + [#646](https://github.com/ADOdb/ADOdb/issues/646) +- pgsql: override ADODB_DataDict::ChangeTableSQL() + [#634](https://github.com/ADOdb/ADOdb/issues/634) +- sqlite: fix metaIndexes does not return primary key correctly + [#656](https://github.com/ADOdb/ADOdb/issues/656) +- xmlschema: PHP8 compatibility + [#658](https://github.com/ADOdb/ADOdb/issues/658) + +### Removed + +- Support for PHP < 5.5.9 + [#654](https://github.com/ADOdb/ADOdb/issues/654) +- XML-RPC Interface + [#671](https://github.com/ADOdb/ADOdb/issues/671) +- Magic quotes related code + [#674](https://github.com/ADOdb/ADOdb/issues/674) + + +## [5.20.20] - 2021-01-31 + +### Fixed + +- Fix usage of get_magic_* functions + [#619](https://github.com/ADOdb/ADOdb/issues/619) + [#657](https://github.com/ADOdb/ADOdb/issues/657) +- Fix PHP warning in _rs2rs() function + [#679](https://github.com/ADOdb/ADOdb/issues/679) +- pdo: Fix Fatal error in _query() + [#666](https://github.com/ADOdb/ADOdb/issues/666) +- pdo: Fix undefined variable + [#678](https://github.com/ADOdb/ADOdb/issues/678) +- pgsql: Fix Fatal error in _close() method (PHP8) + [#666](https://github.com/ADOdb/ADOdb/issues/666) +- pgsql: fix deprecated function aliases (PHP8) + [#667](https://github.com/ADOdb/ADOdb/issues/667) +- text: fix Cannot pass parameter by reference + [#668](https://github.com/ADOdb/ADOdb/issues/668) + + +## [5.21.0-beta.1] - 2020-12-20 + +Includes all fixes from 5.20.19. + +### Added + +- adodb: New helper methods: day(), month(), year() + [#225](https://github.com/ADOdb/ADOdb/issues/225) +- adodb: add Occitan ([#285](https://github.com/ADOdb/ADOdb/issues/285)) + and Indonesian ([#293](https://github.com/ADOdb/ADOdb/issues/293)) translations. +- adodb: add control over BLOB data dictionary feature (NOT NULL, DEFAULT) + [#292](https://github.com/ADOdb/ADOdb/issues/292) + [#478](https://github.com/ADOdb/ADOdb/issues/478) +- mssql: support Windows authentication + [#353](https://github.com/ADOdb/ADOdb/issues/353) +- mysqli: support SSL connections + [#415](https://github.com/ADOdb/ADOdb/issues/415) +- pdo/dblib: new driver + [#496](https://github.com/ADOdb/ADOdb/issues/496) +- pdo/firebird: new driver + [#378](https://github.com/ADOdb/ADOdb/issues/378) +- loadbalancer: read/write splitting and load balancing across multiple connections, thanks to Mike Benoit + [#111](https://github.com/ADOdb/ADOdb/issues/111) + +### Changed + +- adodb: addColumnSQL datadict function now supports ENUM data types + [#26](https://github.com/ADOdb/ADOdb/issues/26) +- adodb: introduce user-defined default Metatype + [#165](https://github.com/ADOdb/ADOdb/issues/165) +- adodb: AutoExecute validates empty fields array + [#154](https://github.com/ADOdb/ADOdb/issues/154) +- adodb: Add new value defaulting mode for getInsertSQL() + [#214](https://github.com/ADOdb/ADOdb/issues/214) +- adodb: Added portable substring method + [#219](https://github.com/ADOdb/ADOdb/issues/219) +- adodb: Optimize FieldTypesArray with static variable + [#367](https://github.com/ADOdb/ADOdb/issues/367) +- adodb: Allow output handler to be callable + [#312](https://github.com/ADOdb/ADOdb/issues/312) +- adodb-time: Add 'W' (week of year) format support in adodb_date() + [#223](https://github.com/ADOdb/ADOdb/issues/223) +- db2: full driver rewrite + [#442](https://github.com/ADOdb/ADOdb/issues/442) +- firebird: updated driver, thanks to Lester Caine + [#201](https://github.com/ADOdb/ADOdb/issues/201) +- mssql: Add Convert on SQLDate Method + [#304](https://github.com/ADOdb/ADOdb/issues/304) +- mssql: support alternative port in connect + [#314](https://github.com/ADOdb/ADOdb/issues/314) +- mssql: MetaForeignKeys() not returning all FKs + [#486](https://github.com/ADOdb/ADOdb/issues/486) +- mssql: support for T-SQL-style square brackets + [#246](https://github.com/ADOdb/ADOdb/issues/246) +- mssqlnative: add support for 'l' (day of week) format in sqlDate() + [#232](https://github.com/ADOdb/ADOdb/issues/232) +- mssqlnative: support metaProcedures() method + [#578](https://github.com/ADOdb/ADOdb/issues/578) +- setConnectionParameter() now allows multiple parameters with the same key value + [#187](https://github.com/ADOdb/ADOdb/issues/187) +- mysqli: Insert_ID() did not return correct value after executing stored procedure + [#166](https://github.com/ADOdb/ADOdb/issues/166) +- mysqli: method failed if $associative set true + [#181](https://github.com/ADOdb/ADOdb/issues/181) +- oci8: provide option to create compact trigger/sequence names + [#565](https://github.com/ADOdb/ADOdb/issues/565) +- odbc/mssql: fix null strings concatenation issue with SQL server 2012 + [#148](https://github.com/ADOdb/ADOdb/issues/148) +- odbc/mssql: add missing Concat() method + [#402](https://github.com/ADOdb/ADOdb/issues/402) +- pdo: add setConnectionParameter support + [#247](https://github.com/ADOdb/ADOdb/issues/247) +- pdo: add meta extension points + [#475](https://github.com/ADOdb/ADOdb/issues/475) +- pdo/mysql: add genID() and createSequence() support + [#465](https://github.com/ADOdb/ADOdb/issues/465) +- pdo/pgsql: Add support for transactions + [#363](https://github.com/ADOdb/ADOdb/issues/363) +- pdo/sqlsrv: add SetTransactionMode() method + [#362](https://github.com/ADOdb/ADOdb/issues/362) +- pgsql: optimize version check + [#334](https://github.com/ADOdb/ADOdb/issues/334) +- pgsql: use postgres9 driver by default + [#474](https://github.com/ADOdb/ADOdb/issues/474) +- sqlite: Fix Metataypes mapping + [#177](https://github.com/ADOdb/ADOdb/issues/177) +- sqlite: driver did not support metaForeignKeys + [#179](https://github.com/ADOdb/ADOdb/issues/179) +- memcache: add support for memcached PECL library + [#322](https://github.com/ADOdb/ADOdb/issues/322) +- xml: support table 'opt' attribute with mysqli + [#267](https://github.com/ADOdb/ADOdb/issues/267) +- xml: add support for 'DESCR' tags for tables/fields + [#265](https://github.com/ADOdb/ADOdb/issues/265) + +### Deprecated + +- mysqli: Deprecate $optionFlags property in favor of standard setConnectionParameter() method + [#188](https://github.com/ADOdb/ADOdb/issues/188) +- proxy: the client driver and server.php script are deprecated + [#444](https://github.com/ADOdb/ADOdb/issues/444) + +### Removed + +- adodb: Remove references to obsolete ADOdb Extension + [#270](https://github.com/ADOdb/ADOdb/issues/270) +- adodb: Remove unneeded ADODB_str_replace function + [#582](https://github.com/ADOdb/ADOdb/issues/582) +- adodb: Remove useless PHP 4 and 5 version checks + [#583](https://github.com/ADOdb/ADOdb/issues/583) + [#584](https://github.com/ADOdb/ADOdb/issues/584) +- adodb: replace _array_change_key_case() by internal PHP function + [#587](https://github.com/ADOdb/ADOdb/issues/587) + +### Fixed + +- adodb: Remove useless constructors + [#171](https://github.com/ADOdb/ADOdb/issues/171) +- adodb: Define default constructor in ADOConnection base class + [#172](https://github.com/ADOdb/ADOdb/issues/172) +- adodb: Reimplement base methods charMax() and textMax() + [#183](https://github.com/ADOdb/ADOdb/issues/183) + [#220](https://github.com/ADOdb/ADOdb/issues/220) +- adodb: fix getAssoc() + [#189](https://github.com/ADOdb/ADOdb/issues/189) + [#198](https://github.com/ADOdb/ADOdb/issues/198) + [#204](https://github.com/ADOdb/ADOdb/issues/204) +- adodb: Improve array identification in ADOrecordset::getAssoc() + [#101](https://github.com/ADOdb/ADOdb/issues/101) +- adodb: MetaColumns() consistently returns Actual Type by default in all drivers + [#184](https://github.com/ADOdb/ADOdb/issues/184) + [#133](https://github.com/ADOdb/ADOdb/issues/133) +- adodb: getAssoc() should not change case of result set's outermost key + [#335](https://github.com/ADOdb/ADOdb/issues/335) +- adodb: getAssoc() fix fetch mode + [#350](https://github.com/ADOdb/ADOdb/issues/350) +- adodb: Replace each() with foreach (PHP 7.2 compatibility) + [#373](https://github.com/ADOdb/ADOdb/issues/373) +- adodb: fix ADORecordSet constructor signature + [#278](https://github.com/ADOdb/ADOdb/issues/278) +- adodb: support use of spaces and reserved keywords in replace function + [#390](https://github.com/ADOdb/ADOdb/issues/390) +- adodb: fix adodb_strip_order_by() to only remove the last order by statement + [#549](https://github.com/ADOdb/ADOdb/issues/549) +- adodb: fix field names quoting when setting value to null + [#572](https://github.com/ADOdb/ADOdb/issues/572) +- adodb: fix getAssoc returning key as value column with ADODB_FETCH_BOTH mode + [#600](https://github.com/ADOdb/ADOdb/issues/600) +- adodb-time: Fix 'Q' (quarter of year) format in adodb_date() + [#222](https://github.com/ADOdb/ADOdb/issues/222) +- active record: honor column and table name quoting + [#309](https://github.com/ADOdb/ADOdb/issues/309) +- db2: fix ChangeTableSQL() signature + [#338](https://github.com/ADOdb/ADOdb/issues/338) +- mssqlnative: Query not returning id + [#185](https://github.com/ADOdb/ADOdb/issues/185) +- mssqlnative: fix invalid return value for ErrorNo() + [#298](https://github.com/ADOdb/ADOdb/issues/298) +- mssqlnative: ensure that the bind array is numeric + [#336](https://github.com/ADOdb/ADOdb/issues/336) +- mssqlnative: fix crash with driver version 5.6 on queries returning no data + [#492](https://github.com/ADOdb/ADOdb/issues/492) +- mysql: prevent use of driver with PHP >= 7.0 + [#310](https://github.com/ADOdb/ADOdb/issues/310) +- mysqli: return fields as ADOFieldObject objects + [#175](https://github.com/ADOdb/ADOdb/issues/175) +- mysqli (perf): tables() method definition inconsistent with parent + [#435](https://github.com/ADOdb/ADOdb/issues/435) +- mysql: genId() not returning next sequence value + [#493](https://github.com/ADOdb/ADOdb/issues/493) +- oci8: fix syntax error preventing sequence creation + [#540](https://github.com/ADOdb/ADOdb/issues/540) +- oci8: remove use of curly braces in string offsets (deprecated in PHP 7.4) + [#570](https://github.com/ADOdb/ADOdb/issues/570) +- odbc: MetaColumns() can optionally be set to return MetaType for backwards compatibility + [#184](https://github.com/ADOdb/ADOdb/issues/184) +- pdo: allow loading of subclassed recordset + [#245](https://github.com/ADOdb/ADOdb/issues/245) +- pdo: fix PHP notice + [#248](https://github.com/ADOdb/ADOdb/issues/248) +- pdo: fix ADORecordSet class loading + [#250](https://github.com/ADOdb/ADOdb/issues/250) +- pdo/sqlsrv: fix fetchField() method + [#251](https://github.com/ADOdb/ADOdb/issues/251) + [#234](https://github.com/ADOdb/ADOdb/issues/234) +- pgsql: add CIDR data type to MetaType() + [#281](https://github.com/ADOdb/ADOdb/issues/281) +- pgsql: fix param number reset with param(false) + [#380](https://github.com/ADOdb/ADOdb/issues/380) +- pgsql: specialized casts for _recreate_copy_table() + [#207](https://github.com/ADOdb/ADOdb/issues/207) +- sqlite: _createSuffix is now compatible with parent + [#178](https://github.com/ADOdb/ADOdb/issues/178) +- sqlite: metaIndexes could not locate indexes on uppercase table name + [#176](https://github.com/ADOdb/ADOdb/issues/176) +- sqlite: metaIndexes() returns column as array instead of CSV + [#567](https://github.com/ADOdb/ADOdb/issues/567) +- session: string parameters for `assert` are deprecated in PHP 7.2 + [#438](https://github.com/ADOdb/ADOdb/issues/438) +- xml: fix invalid xmlschema03.dtd and descr tag in session schema XML + [#595](https://github.com/ADOdb/ADOdb/issues/595) + +### Security + +- adodb: prevent SQL injection in SelectLimit() + [#311](https://github.com/ADOdb/ADOdb/issues/311) +- session: add 'httponly' flag to cookie + [#190](https://github.com/ADOdb/ADOdb/issues/190) + + +## [5.20.19] - 2020-12-13 + +### Changed + +- PDO: support persistent connections + [#650](https://github.com/ADOdb/ADOdb/issues/650) +- mssql: connect to SQL Server database on a specified port + [#624](https://github.com/ADOdb/ADOdb/issues/624) + +### Fixed + +- DSN database connection with password containing a `#` fails + [#651](https://github.com/ADOdb/ADOdb/issues/651) +- Metacolumns returns wrong type for integer fields in MySQL 8 + [#642](https://github.com/ADOdb/ADOdb/issues/642) +- Uninitialized Variable access in mssqlnative ErrorNo() method + [#637](https://github.com/ADOdb/ADOdb/issues/637) + + +## [5.20.18] - 2020-06-28 + +### Fixed + +- mssql: Retrieve error messages early before connection closed + [#614](https://github.com/ADOdb/ADOdb/issues/614) + + +## [5.20.17] - 2020-03-31 + +### Fixed + +- core: fix PHP notice in ADOdb_Exception constructor when using transactions + [#601](https://github.com/ADOdb/ADOdb/issues/601) +- mssql: fix PHP notice due to uninitialized array with PHP 7.4 + [#608](https://github.com/ADOdb/ADOdb/issues/608) +- active record: Fix UpdateActiveTable failing with mixed case column names + [#610](https://github.com/ADOdb/ADOdb/issues/610) + + +## [5.20.16] - 2020-01-12 + +-### Fixed + + mssql: queries are not correctly closed + [#590](https://github.com/ADOdb/ADOdb/issues/590) + + +## [5.20.15] - 2019-11-24 + +### Fixed + +- core: remove unnecessary srand() calls + [#532](https://github.com/ADOdb/ADOdb/issues/532) +- core: Fix getMenu with ADODB_FETCH_BOTH + [#482](https://github.com/ADOdb/ADOdb/issues/482) +- core: code cleanup for getMenu and related functions + [#563](https://github.com/ADOdb/ADOdb/issues/563) +- pgsql: stop using obsolete pg_attrdef.adsrc column + [#562](https://github.com/ADOdb/ADOdb/issues/562) +- pdo/mysql: remove extraneous comma in $fmtTimeStamp + [#531](https://github.com/ADOdb/ADOdb/issues/531) +- active record: Use ADODB_ASSOC_CASE constant + [#536](https://github.com/ADOdb/ADOdb/issues/536) +- session: Remove session_module_name('user') calls (PHP 7.2 compatibility) + [#449](https://github.com/ADOdb/ADOdb/issues/449) +- PHP 7.4 compatibility: fix deprecated usage of join() + [#547](https://github.com/ADOdb/ADOdb/issues/547) + + +## [5.20.14] - 2019-01-06 + +### Fixed + +- core: Fix support for getMenu with ADODB_FETCH_ASSOC + [#460](https://github.com/ADOdb/ADOdb/issues/460) +- perf/mysql: fix tables() function incompatible with parent + [#435](https://github.com/ADOdb/ADOdb/issues/435) +- perf/mysql: fix error when logging slow queries + [#463](https://github.com/ADOdb/ADOdb/issues/463) + +### Security + +- security: Denial of service in adodb_date() + [#467](https://github.com/ADOdb/ADOdb/issues/467) + + +## [5.20.13] - 2018-08-06 + +### Fixed + +- core: Fix query execution failures with mismatched quotes + [#420](https://github.com/ADOdb/ADOdb/issues/420) +- ldap: Fix connections using URIs + [#340](https://github.com/ADOdb/ADOdb/issues/340) +- mssql: Fix Time field format, allowing autoExecute() to inserting time + [#432](https://github.com/ADOdb/ADOdb/issues/432) +- mssql: Fix Insert_ID returning null with table name in brackets + [#313](https://github.com/ADOdb/ADOdb/issues/313) +- mssql: Fix count wrapper + [#423](https://github.com/ADOdb/ADOdb/issues/423) +- oci8: Fix prepared statements failure + [#318](https://github.com/ADOdb/ADOdb/issues/318) +- oci8po: Fix incorrect query parameter replacements + [#370](https://github.com/ADOdb/ADOdb/issues/370) +- pdo: fix PHP notice due to uninitialized variable + [#437](https://github.com/ADOdb/ADOdb/issues/437) + + +## [5.20.12] - 2018-03-30 + +### Fixed + +- adodb: PHP 7.2 compatibility + - Replace each() with foreach + [#373](https://github.com/ADOdb/ADOdb/issues/373) + - Replace deprecated create_function() calls + [#404](https://github.com/ADOdb/ADOdb/issues/404) + - Replace $php_errormsg with error_get_last() + [#405](https://github.com/ADOdb/ADOdb/issues/405) +- adodb: Don't call `dl()` when the function is disabled + [#406](https://github.com/ADOdb/ADOdb/issues/406) +- adodb: Don't bother with magic quotes when not available + [#407](https://github.com/ADOdb/ADOdb/issues/407) +- adodb: fix potential SQL injection vector in SelectLimit() + [#190](https://github.com/ADOdb/ADOdb/issues/190) + [#311](https://github.com/ADOdb/ADOdb/issues/311) + [#401](https://github.com/ADOdb/ADOdb/issues/401) + + +## [5.20.11] - Withdrawn + +This release has been withdrawn as it introduced a regression on PHP 5.x. +Please use version 5.20.12 or later. + + +## [5.20.10] - 2018-03-08 -- mssql: fix syntax error in version matching regex #305 +### Fixed -## 5.20.8 - 17-Dec-2016 +- Fix year validation in adodb_validdate() + [#375](https://github.com/ADOdb/ADOdb/issues/375) +- Release db resource when closing connection + [#379](https://github.com/ADOdb/ADOdb/issues/379) +- Avoid full file path disclosure in ADOLoadCode() + [#389](https://github.com/ADOdb/ADOdb/issues/389) +- mssql: fix PHP warning in _adodb_getcount() + [#359](https://github.com/ADOdb/ADOdb/issues/359) +- mssql: string keys are not allowed in parameters arrays + [#316](https://github.com/ADOdb/ADOdb/issues/316) +- mysqli: fix PHP warning on DB connect + [#348](https://github.com/ADOdb/ADOdb/issues/348) +- pdo: fix auto-commit error in sqlsrv + [#347](https://github.com/ADOdb/ADOdb/issues/347) +- sybase: fix PHP Warning in _connect()/_pconnect + [#371](https://github.com/ADOdb/ADOdb/issues/371) -- mssql: support MSSQL Server 2016 and later #294 -- mssql: fix Find() returning no results. #298 -- mssql: fix Sequence name forced to 'adodbseq'. #295, #300 -- mssql: fix GenId() not returning next sequence value with SQL Server 2005/2008. #302 -- mssql: fix drop/alter column with existing default constraint. #290 -- mssql: fix PHP notice in MetaColumns(). #289 -- oci8po: fix inconsistent variable binding in SelectLimit() #288 -- oci8po: fix SelectLimit() with prepared statements #282 -## 5.20.7 - 20-Sep-2016 +## [5.20.9] - 2016-12-21 -- security: Fix SQL injection in PDO drivers qstr() method (CVE-2016-7405). #226 -- oci8po: prevent segfault on PHP 7. #259 -- pdo/mysql: Fix MetaTables() method. #275 +### Fixed -## 5.20.6 - 31-Aug-2016 +- mssql: fix syntax error in version matching regex + [#305](https://github.com/ADOdb/ADOdb/issues/305) -- security: Fix XSS vulnerability in old test script (CVE-2016-4855). #274 -- adodb: Exit with error/exception when the ADOdb Extension is loaded. #269 -- adodb: Fix truncated exception messages. #273 -## 5.20.5 - 10-Aug-2016 +## [5.20.8] - 2016-12-17 -- adodb: Fix fatal error when connecting with missing extension. #254 -- adodb: Fix _adodb_getcount(). #236 -- mssql: Destructor fails if recordset already closed. #268 -- mssql: Use SQL server native data types if available. #234 -- mysqli: Fix PHP notice in _close() method. #240 -- pdo: Let driver handle SelectDB() and SQLDate() calls. #242 -- xml: Fix PHP strict warning. #260 -- xml: remove calls to 'unset($this)' (PHP 7.1 compatibility). #257 +### Fixed -## 5.20.4 - 31-Mar-2016 +- mssql: support MSSQL Server 2016 and later + [#294](https://github.com/ADOdb/ADOdb/issues/294) +- mssql: fix Find() returning no results + [#298](https://github.com/ADOdb/ADOdb/issues/298) +- mssql: fix Sequence name forced to 'adodbseq' + [#295](https://github.com/ADOdb/ADOdb/issues/295), + [#300](https://github.com/ADOdb/ADOdb/issues/300) +- mssql: fix GenId() not returning next sequence value with SQL Server 2005/2008 + [#302](https://github.com/ADOdb/ADOdb/issues/302) +- mssql: fix drop/alter column with existing default constraint + [#290](https://github.com/ADOdb/ADOdb/issues/290) +- mssql: fix PHP notice in MetaColumns() + [#289](https://github.com/ADOdb/ADOdb/issues/289) +- oci8po: fix inconsistent variable binding in SelectLimit() + [#288](https://github.com/ADOdb/ADOdb/issues/288) +- oci8po: fix SelectLimit() with prepared statements + [#282](https://github.com/ADOdb/ADOdb/issues/282) -- adodb: Fix BulkBind() param count validation. #199 -- mysqli: fix PHP warning in recordset destructor. #217 -- mysqli: cast port number to int when connecting (PHP7 compatibility). #218 -## 5.20.3 - 01-Jan-2016 +## [5.20.7] - 2016-09-20 -- mssql: PHP warning when closing recordset from destructor not fixed in v5.20.2. #180 +### Fixed -## 5.20.2 - 27-Dec-2015 +- oci8po: prevent segfault on PHP 7 + [#259](https://github.com/ADOdb/ADOdb/issues/259) +- pdo/mysql: Fix MetaTables() method + [#275](https://github.com/ADOdb/ADOdb/issues/275) -- adodb: Remove a couple leftover PHP 4.x constructors (PHP7 compatibility). #139 -- db2ora: Remove deprecated preg_replace '/e' flag (PHP7 compatibility). #168 -- mysql: MoveNext() now respects ADODB_ASSOC_CASE. #167 -- mssql, mysql, informix: Avoid PHP warning when closing recordset from destructor. #170 +### Security -## 5.20.1 - 06-Dec-2015 +- security: Fix SQL injection in PDO drivers qstr() method (CVE-2016-7405) + [#226](https://github.com/ADOdb/ADOdb/issues/226) + + +## [5.20.6] - 2016-08-31 + +### Fixed + +- adodb: Exit with error/exception when the ADOdb Extension is loaded + [#269](https://github.com/ADOdb/ADOdb/issues/269) +- adodb: Fix truncated exception messages + [#273](https://github.com/ADOdb/ADOdb/issues/273) + +### Security + +- security: Fix XSS vulnerability in old test script (CVE-2016-4855) + [#274](https://github.com/ADOdb/ADOdb/issues/274) + +## [5.20.5] - 2016-08-10 + +### Fixed + +- adodb: Fix fatal error when connecting with missing extension + [#254](https://github.com/ADOdb/ADOdb/issues/254) +- adodb: Fix _adodb_getcount() + [#236](https://github.com/ADOdb/ADOdb/issues/236) +- mssql: Destructor fails if recordset already closed + [#268](https://github.com/ADOdb/ADOdb/issues/268) +- mssql: Use SQL server native data types if available + [#234](https://github.com/ADOdb/ADOdb/issues/234) +- mysqli: Fix PHP notice in _close() method + [#240](https://github.com/ADOdb/ADOdb/issues/240) +- pdo: Let driver handle SelectDB() and SQLDate() calls + [#242](https://github.com/ADOdb/ADOdb/issues/242) +- xml: Fix PHP strict warning + [#260](https://github.com/ADOdb/ADOdb/issues/260) +- xml: remove calls to 'unset($this)' (PHP 7.1 compatibility) + [#257](https://github.com/ADOdb/ADOdb/issues/257) + + +## [5.20.4] - 2016-03-31 + +### Fixed + +- adodb: Fix BulkBind() param count validation + [#199](https://github.com/ADOdb/ADOdb/issues/199) +- mysqli: fix PHP warning in recordset destructor + [#217](https://github.com/ADOdb/ADOdb/issues/217) +- mysqli: cast port number to int when connecting (PHP7 compatibility) + [#218](https://github.com/ADOdb/ADOdb/issues/218) + + +## [5.20.3] - 2016-01-01 + +### Fixed + +- mssql: PHP warning when closing recordset from destructor not fixed in v5.20.2 + [#180](https://github.com/ADOdb/ADOdb/issues/180) + + +## [5.20.2] - 2015-12-27 + +### Fixed + +- adodb: Remove a couple leftover PHP 4.x constructors (PHP7 compatibility) + [#139](https://github.com/ADOdb/ADOdb/issues/139) +- db2ora: Remove deprecated preg_replace '/e' flag (PHP7 compatibility) + [#168](https://github.com/ADOdb/ADOdb/issues/168) +- mysql: MoveNext() now respects ADODB_ASSOC_CASE + [#167](https://github.com/ADOdb/ADOdb/issues/167) +- mssql, mysql, informix: Avoid PHP warning when closing recordset from destructor + [#170](https://github.com/ADOdb/ADOdb/issues/170) + + +## [5.20.1] - 2015-12-06 + +### Fixed - adodb: Fix regression introduced in 5.20.0, causing a PHP Warning when - calling GetAssoc() on an empty recordset. See Github #162 -- ADOConnection::Version() now handles SemVer. See Github #164 - -## 5.20.0 - 28-Nov-2015 - -- adodb: Fix regression introduced in v5.19, causing queries to return empty rows. See Github #20, #93, #95 -- adodb: Fix regression introduced in v5.19 in GetAssoc() with ADODB_FETCH_ASSOC mode and '0' as data. See Github #102 -- adodb: AutoExecute correctly handles empty result set in case of updates. See Github #13 -- adodb: Fix regex in Version(). See Github #16 -- adodb: Align method signatures to definition in parent class ADODB_DataDict. See Github #31 -- adodb: Improve compatibility of ADORecordSet_empty, thanks to Sjan Evardsson. See Github #43 -- adodb: fix ADODB_Session::open() failing after successful ADONewConnection() call, thanks to Sjan Evardsson. See Github #44 -- adodb: Only include memcache library once for PHPUnit 4.x, thanks to Alan Farquharson. See Github #74 + calling GetAssoc() on an empty recordset + [#162](https://github.com/ADOdb/ADOdb/issues/162) +- ADOConnection::Version() now handles SemVer + [#164](https://github.com/ADOdb/ADOdb/issues/164) + + +## [5.20.0] - 2015-11-28 + +### Added + +- adodb: new setConnectionParameter() method, + previously implemented in mssqlnative driver only + [#158](https://github.com/ADOdb/ADOdb/issues/158). +- pdo: new sqlsrv driver, thanks to MarcelTO + [#81](https://github.com/ADOdb/ADOdb/issues/81) +- adodb: support for pagination with complex queries, thanks to Mike Benoit + [#88](https://github.com/ADOdb/ADOdb/issues/88) +- pdo/mysql: New methods to make the driver behave more like mysql/mysqli, thanks to Andy Theuninck + [#40](https://github.com/ADOdb/ADOdb/issues/40) + +### Changed + +- adodb: Define DB_AUTOQUERY_* constants in main include file + [#49](https://github.com/ADOdb/ADOdb/issues/49) +- adodb: Add mssql's DATETIME2 type to ADOConnection::MetaType(), thanks to MarcelTO + [#80](https://github.com/ADOdb/ADOdb/issues/80) +- adodb: Initialize charset in ADOConnection::SetCharSet + [#39](https://github.com/ADOdb/ADOdb/issues/39) +- adodb: Parse port out of hostname if specified in connection parameters, thanks to Andy Theuninck + [#63](https://github.com/ADOdb/ADOdb/issues/63) +- adodb: Improve compatibility of ADORecordSet_empty, thanks to Sjan Evardsson + [#43](https://github.com/ADOdb/ADOdb/issues/43) +- mssqlnative: Use ADOConnection::outp instead of error_log + [#12](https://github.com/ADOdb/ADOdb/issues/12) + +### Fixed + +- adodb: Fix regression introduced in v5.19, causing queries to return empty rows + [#20](https://github.com/ADOdb/ADOdb/issues/20) + [#93](https://github.com/ADOdb/ADOdb/issues/93) + [#95](https://github.com/ADOdb/ADOdb/issues/95) +- adodb: Fix regression introduced in v5.19 in GetAssoc() with ADODB_FETCH_ASSOC mode and '0' as data + [#102](https://github.com/ADOdb/ADOdb/issues/102) +- adodb: AutoExecute correctly handles empty result set in case of updates + [#13](https://github.com/ADOdb/ADOdb/issues/13) +- adodb: Fix regex in Version() + [#16](https://github.com/ADOdb/ADOdb/issues/16) +- adodb: Align method signatures to definition in parent class ADODB_DataDict + [#31](https://github.com/ADOdb/ADOdb/issues/31) +- adodb: fix ADODB_Session::open() failing after successful ADONewConnection() call, thanks to Sjan Evardsson + [#44](https://github.com/ADOdb/ADOdb/issues/44) +- adodb: Only include memcache library once for PHPUnit 4.x, thanks to Alan Farquharson + [#74](https://github.com/ADOdb/ADOdb/issues/74) - adodb: Move() returns false when given row is < 0, thanks to Mike Benoit. -- adodb: Add support for pagination with complex queries, thanks to Mike Benoit. See Github #88 -- adodb: Parse port out of hostname if specified in connection parameters, thanks to Andy Theuninck. See Github #63 -- adodb: Fix inability to set values from 0 to null (and vice versa) with Active Record, thanks to Louis Johnson. See Github #71 -- adodb: Fix PHP strict warning in ADODB_Active_Record::Reload(), thanks to BoÅ¡tjan ŽokÅ¡. See Github #75 -- adodb: Add mssql's DATETIME2 type to ADOConnection::MetaType(), thanks to MarcelTO. See Github #80 -- adodb: When flushing cache, initialize it if it is not set, thanks to Paul Haggart. See Github #57 -- adodb: Define DB_AUTOQUERY_* constants in main include file. See Github #49 +- adodb: Fix inability to set values from 0 to null (and vice versa) with Active Record, thanks to Louis Johnson + [#71](https://github.com/ADOdb/ADOdb/issues/71) +- adodb: Fix PHP strict warning in ADODB_Active_Record::Reload(), thanks to BoÅ¡tjan ŽokÅ¡ + [#75](https://github.com/ADOdb/ADOdb/issues/75) +- adodb: When flushing cache, initialize it if it is not set, thanks to Paul Haggart + [#57](https://github.com/ADOdb/ADOdb/issues/57) - adodb: Improve documentation of fetch mode and assoc case - adodb: Improve logic to build the assoc case bind array -- adodb: Strict-standards compliance for function names. See Github #18, #142 -- adodb: Remove old PHP 4.x constructors for compatibility with PHP 7. See Github #139 -- adodb: Initialize charset in ADOConnection::SetCharSet. See Github #39 -- adodb: Fix incorrect handling of input array in Execute(). See Github #146 -- adodb: Release Recordset when raising exception. See Github #143 -- adodb: Added new setConnectionParameter() method, currently implemented in mssqlnative driver only. See Github #158. -- adodb-lib: Optimize query pagination, thanks to Mike Benoit. See Github #110 -- memcache: use include_once() to avoid issues with PHPUnit. See http://phplens.com/lens/lensforum/msgs.php?id=19489 -- mssql_n: Allow use of prepared statements with driver. See Github #22 -- mssqlnative: Use ADOConnection::outp instead of error_log. See Github #12 -- mssqlnative: fix failure on Insert_ID() if the insert statement contains a semicolon in a value string, thanks to sketule. See Github #96 -- mssqlnative: Fix "invalid parameter was passed to sqlsrv_configure" error, thanks to Ray Morris. See Github #103 -- mssqlnative: Fix insert_ID() failing if server returns more than 1 row, thanks to gitjti. See Github #41 -- mysql: prevent race conditions when creating/dropping sequences, thanks to MikeB. See Github #28 +- adodb: Strict-standards compliance for function names + [#18](https://github.com/ADOdb/ADOdb/issues/18) + [#142](https://github.com/ADOdb/ADOdb/issues/142) +- adodb: Remove old PHP 4.x constructors for compatibility with PHP 7 + [#139](https://github.com/ADOdb/ADOdb/issues/139) +- adodb: Fix incorrect handling of input array in Execute() + [#146](https://github.com/ADOdb/ADOdb/issues/146) +- adodb: Release Recordset when raising exception + [#143](https://github.com/ADOdb/ADOdb/issues/143) +- adodb-lib: Optimize query pagination, thanks to Mike Benoit + [#110](https://github.com/ADOdb/ADOdb/issues/110) +- memcache: use include_once() to avoid issues with PHPUnit. See PHPLens Issue No: 19489 +- mssql_n: Allow use of prepared statements with driver + [#22](https://github.com/ADOdb/ADOdb/issues/22) +- mssqlnative: fix failure on Insert_ID() if the insert statement contains a semicolon in a value string, thanks to sketule + [#96](https://github.com/ADOdb/ADOdb/issues/96) +- mssqlnative: Fix "invalid parameter was passed to sqlsrv_configure" error, thanks to Ray Morris + [#103](https://github.com/ADOdb/ADOdb/issues/103) +- mssqlnative: Fix insert_ID() failing if server returns more than 1 row, thanks to gitjti + [#41](https://github.com/ADOdb/ADOdb/issues/41) +- mysql: prevent race conditions when creating/dropping sequences, thanks to MikeB + [#28](https://github.com/ADOdb/ADOdb/issues/28) - mysql: Fix adodb_strip_order_by() bug causing SQL error for subqueries with order/limit clause, thanks to MikeB. - mysql: workaround for HHVM behavior, thanks to Mike Benoit. -- mysqli: Fix qstr() when called without an active connection. See Github #11 -- oci8: Fix broken quoting of table name in AddColumnSQL and AlterColumnSQL, thanks to Andreas Fernandez. see Github #67 -- oci8: Allow oci8 driver to use lowercase field names in assoc mode. See Github #21 -- oci8po: Prevent replacement of '?' within strings, thanks to Mark Newnham. See Github #132 -- pdo: Added missing property (fixes PHP notices). see Github #56 -- pdo: Align method signatures with parent class, thanks to Andy Theuninck. see Github #62 -- pdo: new sqlsrv driver, thanks to MarcelTO. See Github #81 -- pdo/mysql: New methods to make the driver behave more like mysql/mysqli, thanks to Andy Theuninck. see Github #40 +- mysqli: Fix qstr() when called without an active connection + [#11](https://github.com/ADOdb/ADOdb/issues/11) +- oci8: Fix broken quoting of table name in AddColumnSQL and AlterColumnSQL, thanks to Andreas Fernandez + [#67](https://github.com/ADOdb/ADOdb/issues/67) +- oci8: Allow oci8 driver to use lowercase field names in assoc mode + [#21](https://github.com/ADOdb/ADOdb/issues/21) +- oci8po: Prevent replacement of '?' within strings, thanks to Mark Newnham + [#132](https://github.com/ADOdb/ADOdb/issues/132) +- pdo: Added missing property (fixes PHP notices) + [#56](https://github.com/ADOdb/ADOdb/issues/56) +- pdo: Align method signatures with parent class, thanks to Andy Theuninck + [#62](https://github.com/ADOdb/ADOdb/issues/62) - postgres: Stop using legacy function aliases -- postgres: Fix AlterColumnSQL when updating multiple columns, thanks to Jouni Ahto. See Github #72 -- postgres: Fix support for HHVM 3.6, thanks to Mike Benoit. See Github #87 -- postgres: Noblob optimization, thanks to Mike Benoit. See Github #112 -- postgres7: fix system warning in MetaColumns() with schema. See http://phplens.com/lens/lensforum/msgs.php?id=19481 +- postgres: Fix AlterColumnSQL when updating multiple columns, thanks to Jouni Ahto + [#72](https://github.com/ADOdb/ADOdb/issues/72) +- postgres: Fix support for HHVM 3.6, thanks to Mike Benoit + [#87](https://github.com/ADOdb/ADOdb/issues/87) +- postgres: Noblob optimization, thanks to Mike Benoit + [#112](https://github.com/ADOdb/ADOdb/issues/112) +- postgres7: fix system warning in MetaColumns() with schema. See PHPLens Issue No: 19481 - sqlite3: ServerInfo() now returns driver's version -- sqlite3: Fix wrong connection parameter in _connect(), thanks to diogotoscano. See Github #51 -- sqlite3: Fix FetchField, thanks to diogotoscano. See Github #53 -- sqlite3: Fix result-less SQL statements executed twice. See Github #99 -- sqlite3: use -1 for _numOfRows. See Github #151 -- xmlschema: Fix ExtractSchema() when given $prefix and $stripprefix parameters, thanks to peterdd. See Github #92 -- Convert languages files to UTF-8, thanks to Marc-Etienne Vargenau. See Github #32. - -## 5.19 - 23-Apr-2014 +- sqlite3: Fix wrong connection parameter in _connect(), thanks to diogotoscano + [#51](https://github.com/ADOdb/ADOdb/issues/51) +- sqlite3: Fix FetchField, thanks to diogotoscano + [#53](https://github.com/ADOdb/ADOdb/issues/53) +- sqlite3: Fix result-less SQL statements executed twice + [#99](https://github.com/ADOdb/ADOdb/issues/99) +- sqlite3: use -1 for _numOfRows + [#151](https://github.com/ADOdb/ADOdb/issues/151) +- xmlschema: Fix ExtractSchema() when given $prefix and $stripprefix parameters, thanks to peterdd + [#92](https://github.com/ADOdb/ADOdb/issues/92) +- Convert languages files to UTF-8, thanks to Marc-Etienne Vargenau + [#32](https://github.com/ADOdb/ADOdb/issues/32) + + +## 5.19 - 2014-04-23 **NOTE:** This release suffers from a [known issue with Associative Fetch Mode](https://github.com/ADOdb/ADOdb/issues/20) @@ -132,16 +753,16 @@ It causes recordsets to return empty strings (no data) when using some database The problem has been reported on MSSQL, Interbase and Foxpro, but possibly affects other database types as well; all drivers derived from the above are also impacted. -- adodb: GetRowAssoc will return null as required. See http://phplens.com/lens/lensforum/msgs.php?id=19289 -- adodb: Fix GetRowAssoc bug introduced in 5.17, causing function to return data from previous fetch for NULL fields. See http://phplens.com/lens/lensforum/msgs.php?id=17539 +- adodb: GetRowAssoc will return null as required. See PHPLens Issue No: 19289 +- adodb: Fix GetRowAssoc bug introduced in 5.17, causing function to return data from previous fetch for NULL fields. See PHPLens Issue No: 17539 - adodb: GetAssoc will return a zero-based array when 2nd column is null. See https://sourceforge.net/p/adodb/bugs/130/ - adodb: Execute no longer ignores single parameters evaluating to false. See https://sourceforge.net/p/adodb/patches/32/ -- adodb: Fix LIMIT 1 clause in subquery gets stripped off. See http://phplens.com/lens/lensforum/msgs.php?id=17813 +- adodb: Fix LIMIT 1 clause in subquery gets stripped off. See PHPLens Issue No: 17813 - adodb-lib: Fix columns quoting bug. See https://sourceforge.net/p/adodb/bugs/127/ - Added new ADODB_ASSOC_CASE_* constants. Thx to Damien Regad. - sessions: changed lob handling to detect all variations of oci8 driver. -- ads: clear fields before fetching. See http://phplens.com/lens/lensforum/msgs.php?id=17539 -- mssqlnative: fixed many FetchField compat issues. See http://phplens.com/lens/lensforum/msgs.php?id=18464. Also date format changed to remove timezone. +- ads: clear fields before fetching. See PHPLens Issue No: 17539 +- mssqlnative: fixed many FetchField compat issues. See PHPLens Issue No: 18464. Also date format changed to remove timezone. - mssqlnative: Numerous fixes and improvements by Mark Newnham - Driver supports SQL Server 2005, 2008 and 2012 - Bigint data types mapped to I8 instead of I @@ -149,37 +770,42 @@ other database types as well; all drivers derived from the above are also impact - On SQL Server 2012, makes use of new CREATE SEQUENCE statement - FetchField caches metadata at initialization to improve performance - etc. -- mssqlnative: Fix Insert ID on prepared statement, thanks to Mike Parks. See http://phplens.com/lens/lensforum/msgs.php?id=19079 +- mssqlnative: Fix Insert ID on prepared statement, thanks to Mike Parks. See PHPLens Issue No: 19079 - mssql: timestamp format changed to `Y-m-d\TH:i:s` (ISO 8601) to make them independent from DATEFORMAT setting, as recommended on [Microsoft TechNet](http://technet.microsoft.com/en-us/library/ms180878%28v=sql.105%29.aspx#StringLiteralDateandTimeFormats). -- mysql/mysqli: Fix ability for MetaTables to filter by table name, broken since 5.15. See http://phplens.com/lens/lensforum/msgs.php?id=19359 +- mysql/mysqli: Fix ability for MetaTables to filter by table name, broken since 5.15. See PHPLens Issue No: 19359 - odbc: Fixed MetaTables and MetaPrimaryKeys definitions in odbc driver to match adoconnection class. -- odbc: clear fields before fetching. See http://phplens.com/lens/lensforum/msgs.php?id=17539 +- odbc: clear fields before fetching. See PHPLens Issue No: 17539 - oci8: GetRowAssoc now works in ADODB_FETCH_ASSOC fetch mode - oci8: MetaType and MetaForeignKeys argument count are now strict-standards compliant - oci8: Added trailing `;` on trigger creation for sequence fields, prevents occurence of ORA-24344 - oci8quercus: new oci8 driver with support for quercus jdbc data types. -- pdo: Fixed concat recursion bug in 5.3. See http://phplens.com/lens/lensforum/msgs.php?id=19285 +- pdo: Fixed concat recursion bug in 5.3. See PHPLens Issue No: 19285 - pgsql: Default driver (postgres/pgsql) is now postgres8 - pgsql: Fix output of BLOB (bytea) columns with PostgreSQL >= 9.0 - pgsql: Fix handling of DEFAULT NULL columns in AlterColumnSQL - pgsql: Fix mapping of error message to ADOdb error codes - pgsql: Reset parameter number in Param() method when $name == false -- postgres8: New class/type with correct behavior for _insertid(). See Github #8 -- postgres9: Fixed assoc problem. See http://phplens.com/lens/lensforum/msgs.php?id=19296 -- sybase: Removed redundant sybase_connect() call in _connect(). See Github #3 -- sybase: Allow connection on custom port. See Github #9 -- sybase: Fix null values returned with ASSOC fetch mode. See Github #10 -- Added Composer support. See Github #7 - -## 5.18 - 3 Sep 2012 - -- datadict-postgres: Fixes bug in ALTER COL. See http://phplens.com/lens/lensforum/msgs.php?id=19202. +- postgres8: New class/type with correct behavior for _insertid() + [#8](https://github.com/ADOdb/ADOdb/issues/8) +- postgres9: Fixed assoc problem. See PHPLens Issue No: 19296 +- sybase: Removed redundant sybase_connect() call in _connect() + [#3](https://github.com/ADOdb/ADOdb/issues/3) +- sybase: Allow connection on custom port + [#9](https://github.com/ADOdb/ADOdb/issues/9) +- sybase: Fix null values returned with ASSOC fetch mode + [#10](https://github.com/ADOdb/ADOdb/issues/10) +- Added Composer support + [#7](https://github.com/ADOdb/ADOdb/issues/7) + +## 5.18 - 2012-09-03 + +- datadict-postgres: Fixes bug in ALTER COL. See PHPLens Issue No: 19202. - datadict-postgres: fixed bugs in MetaType() checking $fieldobj properties. - GetRowAssoc did not work with null values. Bug in 5.17. - postgres9: New driver to better support PostgreSQL 9. Thx Glenn Herteg and Cacti team. - sqlite3: Modified to support php 5.4. Thx Günter Weber [built.development#googlemail.com] -- adodb: When fetch mode is ADODB_FETCH_ASSOC, and we execute `$db->GetAssoc("select 'a','0'");` we get an error. Fixed. See http://phplens.com/lens/lensforum/msgs.php?id=19190 +- adodb: When fetch mode is ADODB_FETCH_ASSOC, and we execute `$db->GetAssoc("select 'a','0'");` we get an error. Fixed. See PHPLens Issue No: 19190 - adodb: Caching directory permissions now configurable using global variable $ADODB_CACHE_PERMS. Default value is 0771. - mysqli: SetCharSet() did not return true (success) or false (fail) correctly. Fixed. - mysqli: changed dataProvider to 'mysql' so that MetaError and other shared functions will work. @@ -187,7 +813,7 @@ other database types as well; all drivers derived from the above are also impact - mysql: FetchField(-1), turns it is is not possible to retrieve the max_length. Set to -1. - mysql-perf: Fixed "SHOW INNODB STATUS". Change to "SHOW ENGINE INNODB STATUS" -## 5.17 - 18 May 2012 +## 5.17 - 2012-05-18 - Active Record: Removed trailing whitespace from adodb-active-record.inc.php. - odbc: Added support for $database parameter in odbc Connect() function. E.g. $DB->Connect($dsn_without_db, $user, $pwd, $database). @@ -196,26 +822,26 @@ other database types as well; all drivers derived from the above are also impact - oci8: Changed to use newer oci API to support PHP 5.4. - adodb.inc.php: Changed GetRowAssoc to more generic code that will work in all scenarios. -## 5.16 - 26 March 2012 +## 5.16 - 2012-03-26 -- mysqli: extra mysqli_next_result() in close() removed. See http://phplens.com/lens/lensforum/msgs.php?id=19100 -- datadict-oci8: minor typo in create sequence trigger fixed. See http://phplens.com/lens/lensforum/msgs.php?id=18879. +- mysqli: extra mysqli_next_result() in close() removed. See PHPLens Issue No: 19100 +- datadict-oci8: minor typo in create sequence trigger fixed. See PHPLens Issue No: 18879. - security: safe date parsing changes. Does not impact security, these are code optimisations. Thx Saithis. - postgres, oci8, oci8po, db2oci: Param() function parameters inconsistent with base class. $type='C' missing. Fixed. -- active-record: locked bug fixed. http://phplens.com/lens/lensforum/msgs.php?phplens_forummsg=new&id=19073 -- mysql, mysqli and informix: added MetaProcedures. Metaprocedures allows to retrieve an array list of all procedures in database. http://phplens.com/lens/lensforum/msgs.php?id=18414 +- active-record: locked bug fixed. PHPLens Issue:19073 +- mysql, mysqli and informix: added MetaProcedures. Metaprocedures allows to retrieve an array list of all procedures in database. PHPLens Issue No: 18414 - Postgres7: added support for serial data type in MetaColumns(). -## 5.15 - 19 Jan 2012 +## 5.15 - 2012-01-19 - pdo: fix ErrorMsg() to detect errors correctly. Thx Jens. - mssqlnative: added another check for $this->fields array exists. -- mssqlnative: bugs in FetchField() fixed. See http://phplens.com/lens/lensforum/msgs.php?id=19024 +- mssqlnative: bugs in FetchField() fixed. See PHPLens Issue No: 19024 - DBDate and DBTimeStamp had sql injection bug. Fixed. Thx Saithis - mysql and mysqli: MetaTables() now identifies views and tables correctly. - Added function adodb_time() to adodb-time.inc.php. Generates current time in unsigned integer format. -## 5.14 - 8 Sep 2011 +## 5.14 - 2011-09-08 - mysqli: fix php compilation bug. - postgres: bind variables did not work properly. Fixed. @@ -224,27 +850,27 @@ other database types as well; all drivers derived from the above are also impact - ActiveRecord: 1 char length string never quoted. Fixed. - LDAP: Connection string ldap:// and ldaps:// did not work. Fixed. -## 5.13 - 15 Aug 2011 +## 5.13 - 2011-08-15 - Postgres: Fix in 5.12 was wrong. Uses pg_unescape_bytea() correctly now in _decode. - GetInsertSQL/GetUpdateSQL: Now $ADODB_QUOTE_FIELDNAMES allows you to define 'NATIVE', 'UPPER', 'LOWER'. If set to true, will default to 'UPPER'. - mysqli: added support for persistent connections 'p:'. - mssqlnative: ADODB_FETCH_BOTH did not work properly. Fixed. -- mssqlnative: return values for stored procedures where not returned! Fixed. See http://phplens.com/lens/lensforum/msgs.php?id=18919 -- mssqlnative: timestamp and fetchfield bugs fixed. http ://phplens.com/lens/lensforum/msgs.php?id=18453 +- mssqlnative: return values for stored procedures where not returned! Fixed. See PHPLens Issue No: 18919 +- mssqlnative: timestamp and fetchfield bugs fixed. PHPLens Issue: 18453 -## 5.12 - 30 June 2011 +## 5.12 - 2011-06-30 - Postgres: Added information_schema support for postgresql. - Postgres: Use pg_unescape_bytea() in _decode. -- Fix bulk binding with oci8. http://phplens.com/lens/lensforum/msgs.php?id=18786 +- Fix bulk binding with oci8. PHPLens Issue No: 18786 - oci8 perf: added wait evt monitoring. Also db cache advice now handles multiple buffer pools properly. - sessions2: Fixed setFetchMode problem. - sqlite: Some DSN connection settings were not parsed correctly. - mysqli: now GetOne obeys $ADODB_GETONE_EOF; -- memcache: compress option did not work. Fixed. See http://phplens.com/lens/lensforum/msgs.php?id=18899 +- memcache: compress option did not work. Fixed. See PHPLens Issue No: 18899 -## 5.11 - 5 May 2010 +## 5.11 - 2010-05-05 - mysql: Fixed GetOne() to return null if no records returned. - oci8 perf: added stats on sga, rman, memory usage, and flash in performance tab. @@ -259,21 +885,21 @@ other database types as well; all drivers derived from the above are also impact - ado5: Fixed ado5 exceptions to only display errors when $this->debug=true; - Added DSN support to sessions2.inc.php. - adodb-lib.inc.php. Fixed issue with _adodb_getcount() not using $secs2cache parameter. -- adodb active record. Fixed caching bug. See http://phplens.com/lens/lensforum/msgs.php?id=18288. +- adodb active record. Fixed caching bug. See PHPLens Issue No: 18288. - db2: fixed ServerInfo(). - adodb_date: Added support for format 'e' for TZ as in adodb_date('e') - Active Record: If you have a field which is a string field (with numbers in) and you add preceding 0's to it the adodb library does not pick up the fact that the field has changed because of the way php's == works (dodgily). The end result is that it never gets updated into the database - fix by Matthew Forrester (MediaEquals). [matthew.forrester#mediaequals.com] -- Fixes RowLock() and MetaIndexes() inconsistencies. See http://phplens.com/lens/lensforum/msgs.php?id=18236 -- Active record support for postgrseql boolean. See http://phplens.com/lens/lensforum/msgs.php?id=18246 -- By default, Execute 2D array is disabled for security reasons. Set $conn->bulkBind = true to enable. See http://phplens.com/lens/lensforum/msgs.php?id=18270. Note this breaks backward compat. -- MSSQL: fixes for 5.2 compat. http://phplens.com/lens/lensforum/msgs.php?id=18325 +- Fixes RowLock() and MetaIndexes() inconsistencies. See PHPLens Issue No: 18236 +- Active record support for postgrseql boolean. See PHPLens Issue No: 18246 +- By default, Execute 2D array is disabled for security reasons. Set $conn->bulkBind = true to enable. See PHPLens Issue No: 18270. Note this breaks backward compat. +- MSSQL: fixes for 5.2 compat. PHPLens Issue No: 18325 - Changed Version() to return a string instead of a float so it correctly returns 5.10 instead of 5.1. -## 5.10 - 10 Nov 2009 +## 5.10 - 2009-11-10 - Fixed memcache to properly support $rs->timeCreated. - adodb-ado.inc.php: Added BigInt support for PHP5. Will return float instead to support large numbers. Thx nasb#mail.goo.ne.jp. -- adodb-mysqli.inc.php: mysqli_multi_query is now turned off by default. To turn it on, use $conn->multiQuery = true; This is because of the risks of sql injection. See http://phplens.com/lens/lensforum/msgs.php?id=18144 +- adodb-mysqli.inc.php: mysqli_multi_query is now turned off by default. To turn it on, use $conn->multiQuery = true; This is because of the risks of sql injection. See PHPLens Issue No: 18144 - New db2oci driver for db2 9.7 when using PL/SQL mode. Allows oracle style :0, :1, :2 bind parameters which are remapped to ? ? ?. - adodb-db2.inc.php: fixed bugs in MetaTables. SYS owner field not checked properly. Also in $conn->Connect($dsn, null, null, $schema) and PConnect($dsn, null, null, $schema), we do a SET SCHEMA=$schema if successful connection. - adodb-mysqli.inc.php: Now $rs->Close() closes all pending next resultsets. Thx Clifton mesmackgod#gmail.com @@ -282,7 +908,7 @@ other database types as well; all drivers derived from the above are also impact - Removed usage of split (deprecated in php 5.3). Thx david#horizon-nigh.org. - Fixed RowLock() parameters to comply with PHP5 strict mode in multiple drivers. -## 5.09 - 25 June 2009 +## 5.09 - 2009-06-25 - Active Record: You can force column names to be quoted in INSERT and UPDATE statements, typically because you are using reserved words as column names by setting ADODB_Active_Record::$_quoteNames = true; - Added memcache and cachesecs to DSN. e.g. @@ -295,22 +921,22 @@ other database types as well; all drivers derived from the above are also impact - Fixed up MetaColumns and MetaPrimaryIndexes() for php 5.3 compat. Thx http://adodb.pastebin.com/m52082b16 - The postgresql driver's OffsetDate() apparently does not work with postgres 8.3. Fixed. - Added support for magic_quotes_sybase in qstr() and addq(). Thanks Eloy and Sam Moffat. -- The oci8 driver did not handle LOBs properly when binding. Fixed. See http://phplens.com/lens/lensforum/msgs.php?id=17991. +- The oci8 driver did not handle LOBs properly when binding. Fixed. See PHPLens Issue No: 17991. - Datadict: In order to support TIMESTAMP with subsecond accuracy, added to datadict the new TS type. Supported by mssql, postgresql and oci8 (oracle). Also changed oci8 $conn->sysTimeStamp to use 'SYSTIMESTAMP' instead of 'SYSDATE'. Should be backwards compat. - Added support for PHP 5.1+ DateTime objects in DBDate and DBTimeStamp. This means that dates and timestamps will be managed by DateTime objects if you are running PHP 5.1+. -- Added new property to postgres64 driver to support returning I if type is unique int called $db->uniqueIisR, defaulting to true. See http://phplens.com/lens/lensforum/msgs.php?id=17963 +- Added new property to postgres64 driver to support returning I if type is unique int called $db->uniqueIisR, defaulting to true. See PHPLens Issue No: 17963 - Added support for bindarray in adodb_GetActiveRecordsClass with SelectLimit in adodb-active-record.inc.php. - Transactions now allowed in ado_access driver. Thx to petar.petrov.georgiev#gmail.com. - Sessions2 garbage collection is now much more robust. We perform ORDER BY to prevent deadlock in adodb-sessions2.inc.php. - Fixed typo in pdo_sqlite driver. -## 5.08a - 17 Apr 2009 +## 5.08a - 2009-04-17 - Fixes wrong version number string. - Incorrect + in adodb-datadict.inc.php removed. - Fixes missing OffsetDate() function in pdo. Thx paul#mantisforge.org. -## 5.08 - 17 Apr 2009 +## 5.08 - 2009-04-17 - adodb-sybase.inc.php driver. Added $conn->charSet support. Thx Luis Henrique Mulinari (luis.mulinari#gmail.com) - adodb-ado5.inc.php. Fixed some bind param issues. Thx Jirka Novak. @@ -330,12 +956,12 @@ other database types as well; all drivers derived from the above are also impact - MetaForeignKeys for postgres7 driver changed from adodb_movenext to $rs->MoveNext (also in 4.99) - Added support for ldap and ldaps url format in ldap driver. E.g. ldap://host:port/dn?attributes?scope?filter?extensions -## 5.07 - 26 Dec 2008 +## 5.07 - 2008-12-26 - BeginTrans/CommitTrans/RollbackTrans return true/false correctly on success/failure now for mssql, odbc, oci8, mysqlt, mysqli, postgres, pdo. - Replace() now quotes all non-null values including numeric ones. - Postgresql qstr() now returns booleans as *true* and *false* without quotes. -- MetaForeignKeys in mysql and mysqli drivers had this problem: A table can have two foreign keys pointing to the same column in the same table. The original code will incorrectly report only the last column. Fixed. https://sourceforge.net/tracker/index.php?func=detail&aid=2287278&group_id=42718&atid=433976 +- MetaForeignKeys in mysql and mysqli drivers had this problem: A table can have two foreign keys pointing to the same column in the same table. The original code will incorrectly report only the last column. Fixed. https://sourceforge.net/p/adodb/bugs/100/ - Passing in full ado connection string in $argHostname with ado drivers was failing in adodb5 due to bug. Fixed. - Fixed memcachelib flushcache and flushall bugs. Also fixed possible timeCreated = 0 problem in readcache. (Also in adodb 4.992). Thanks AlexB_UK (alexbarnes#hotmail.com). - Fixed a notice in adodb-sessions2.inc.php, in _conn(). Thx bober m.derlukiewicz#rocktech.remove_me.pl; @@ -349,10 +975,10 @@ other database types as well; all drivers derived from the above are also impact - The rs2html function did not display hours in timestamps correctly. Now 24hr clock used. - Changed ereg* functions to use preg* functions as ereg* is deprecated in PHP 5.3. Modified sybase and postgresql drivers. -## 5.06 - 16 Oct 2008 +## 5.06 - 2008-10-16 - Added driver adodb-pdo_sqlite.inc.php. Thanks Diogo Toscano (diogo#scriptcase.net) for the code. -- Added support for [one-to-many relationships](docs-active-record.htm#onetomany) with BelongsTo() and HasMany() in adodb_active_record. +- Added support for [one-to-many relationships](https://adodb.org/dokuwiki/doku.php?id=v5:userguide:active_record#one_to_many_relations) with BelongsTo() and HasMany() in adodb_active_record. - Added BINARY type to mysql.inc.php (also in 4.991). - Added support for SelectLimit($sql,-1,100) in oci8. (also in 4.991). - New $conn->GetMedian($table, $field, $where='') to get median account no. (also in 4.991) @@ -377,12 +1003,12 @@ other database types as well; all drivers derived from the above are also impact - You can now change the return value of GetOne if no records are found using the global variable $ADODB_GETONE_EOF. The default is null. To change it back to the pre-4.99/5.00 behaviour of false, set $ADODB_GETONE_EOF = false; - In Postgresql 8.2/8.3 MetaForeignkeys did not work. Fixed William Kolodny William.Kolodny#gt-t.net -## 5.05 - 11 Jul 2008 +## 5.05 - 2008-07-11 Released together with [v4.990](changelog_v4.x.md#4990---11-jul-2008) -- Added support for multiple recordsets in mysqli , thanks to Geisel Sierote geisel#4up.com.br. See http://phplens.com/lens/lensforum/msgs.php?id=15917 -- Malcolm Cook added new Reload() function to Active Record. See http://phplens.com/lens/lensforum/msgs.php?id=17474 +- Added support for multiple recordsets in mysqli , thanks to Geisel Sierote geisel#4up.com.br. See PHPLens Issue No: 15917 +- Malcolm Cook added new Reload() function to Active Record. See PHPLens Issue No: 17474 - Thanks Zoltan Monori (monzol#fotoprizma.hu) for bug fixes in iterator, SelectLimit, GetRandRow, etc. - Under heavy loads, the performance monitor for oci8 disables Ixora views. - Fixed sybase driver SQLDate to use str_replace(). Also for adodb5, changed sybase driver UnixDate and UnixTimeStamp calls to static. @@ -420,7 +1046,7 @@ Released together with [v4.990](changelog_v4.x.md#4990---11-jul-2008) $db->CacheExecute($sql); ``` -## 5.04 - 13 Feb 2008 +## 5.04 - 2008-02-13 Released together with [v4.98](changelog_v4.x.md#498---13-feb-2008) @@ -428,14 +1054,14 @@ Released together with [v4.98](changelog_v4.x.md#498---13-feb-2008) - Added mysqli support to adodb_getcount(). - Removed MYSQLI_TYPE_CHAR from MetaType(). -## 5.03 - 22 Jan 2008 +## 5.03 - 2008-01-22 Released together with [v4.97](changelog_v4.x.md#497---22-jan-2008) - Active Record: $ADODB_ASSOC_CASE=1 did not work properly. Fixed. - Modified Fields() in recordset class to support display null fields in FetchNextObject(). -- In ADOdb5, active record implementation, we now support column names with spaces in them - we autoconvert the spaces to _ using __set(). Thx Daniel Cook. http://phplens.com/lens/lensforum/msgs.php?id=17200 -- Removed $arg3 from mysqli SelectLimit. See http://phplens.com/lens/lensforum/msgs.php?id=16243. Thx Zsolt Szeberenyi. +- In ADOdb5, active record implementation, we now support column names with spaces in them - we autoconvert the spaces to _ using __set(). Thx Daniel Cook. PHPLens Issue No: 17200 +- Removed $arg3 from mysqli SelectLimit. See PHPLens Issue No: 16243. Thx Zsolt Szeberenyi. - Changed oci8 FetchField, which returns the max_length of BLOB/CLOB/NCLOB as 4000 (incorrectly) to -1. - CacheExecute would sometimes return an error on Windows if it was unable to lock the cache file. This is harmless and has been changed to a warning that can be ignored. Also adodb_write_file() code revised. - ADOdb perf code changed to only log sql if execution time >= 0.05 seconds. New $ADODB_PERF_MIN variable holds min sql timing. Any SQL with timing value below this and is not causing an error is not logged. @@ -444,7 +1070,7 @@ Released together with [v4.97](changelog_v4.x.md#497---22-jan-2008) - Changed mssql driver Parameter() from SQLCHAR to SQLVARCHAR: case 'string': $type = SQLVARCHAR; break. - Problem with mssql driver in php5 (for adodb 5.03) because some functions are not static. Fixed. -## 5.02 - 24 Sept 2007 +## 5.02 - 2007-09-24 Released together with [v4.96](changelog_v4.x.md#496---24-sept-2007) @@ -472,7 +1098,7 @@ Released together with [v4.96](changelog_v4.x.md#496---24-sept-2007) - Added better support for MetaType() in mysqli when using an array recordset. - Changed parser for pgsql error messages in adodb-error.inc.php to case-insensitive regex. -## 5.01 - 17 May 2007 +## 5.01 - 2007-05-17 Released together with [v4.95](changelog_v4.x.md#495---17-may-2007) @@ -489,3 +1115,32 @@ Released together with [v4.95](changelog_v4.x.md#495---17-may-2007) - The $argHostname was wiped out in adodb-ado5.inc.php. Fixed. - Adodb5 version, added iterator support for adodb_recordset_empty. - Adodb5 version,more error checking code now will use exceptions if available. + + +[5.21.2]: https://github.com/adodb/adodb/compare/v5.21.1...v5.21.2 +[5.21.1]: https://github.com/adodb/adodb/compare/v5.21.0...v5.21.1 +[5.21.0]: https://github.com/adodb/adodb/compare/v5.21.0-rc.1...v5.21.0 +[5.21.0-rc.1]: https://github.com/adodb/adodb/compare/v5.21.0-beta.1...v5.21.0-rc.1 +[5.21.0-beta.1]: https://github.com/adodb/adodb/compare/v5.20.20...v5.21.0-beta.1 + +[5.20.20]: https://github.com/adodb/adodb/compare/v5.20.19...v5.20.20 +[5.20.19]: https://github.com/adodb/adodb/compare/v5.20.18...v5.20.19 +[5.20.18]: https://github.com/adodb/adodb/compare/v5.20.17...v5.20.18 +[5.20.17]: https://github.com/adodb/adodb/compare/v5.20.16...v5.20.17 +[5.20.16]: https://github.com/adodb/adodb/compare/v5.20.15...v5.20.16 +[5.20.15]: https://github.com/adodb/adodb/compare/v5.20.14...v5.20.15 +[5.20.14]: https://github.com/adodb/adodb/compare/v5.20.13...v5.20.14 +[5.20.13]: https://github.com/adodb/adodb/compare/v5.20.12...v5.20.13 +[5.20.12]: https://github.com/adodb/adodb/compare/v5.20.11...v5.20.12 +[5.20.11]: https://github.com/adodb/adodb/compare/v5.20.10...v5.20.11 +[5.20.10]: https://github.com/adodb/adodb/compare/v5.20.9...v5.20.10 +[5.20.9]: https://github.com/adodb/adodb/compare/v5.20.8...v5.20.9 +[5.20.8]: https://github.com/adodb/adodb/compare/v5.20.7...v5.20.8 +[5.20.7]: https://github.com/adodb/adodb/compare/v5.20.6...v5.20.7 +[5.20.6]: https://github.com/adodb/adodb/compare/v5.20.5...v5.20.6 +[5.20.5]: https://github.com/adodb/adodb/compare/v5.20.4...v5.20.5 +[5.20.4]: https://github.com/adodb/adodb/compare/v5.20.3...v5.20.4 +[5.20.3]: https://github.com/adodb/adodb/compare/v5.20.2...v5.20.3 +[5.20.2]: https://github.com/adodb/adodb/compare/v5.20.1...v5.20.2 +[5.20.1]: https://github.com/adodb/adodb/compare/v5.20.0...v5.20.1 +[5.20.0]: https://github.com/adodb/adodb/compare/v5.19...v5.20.0 diff --git a/libraries/adodb/docs/changelog_v2.x.md b/libraries/adodb/docs/changelog_v2.x.md index 000dcd5ad..af718b73c 100644 --- a/libraries/adodb/docs/changelog_v2.x.md +++ b/libraries/adodb/docs/changelog_v2.x.md @@ -31,7 +31,7 @@ $conn->Connect($dsn); - Now MetaType() can accept a field object as the first parameter. - New $arr = $db->ServerInfo( ) function. Returns $arr['description'] which is the string description, and $arr['version']. - PostgreSQL and MSSQL speedups for insert/updates. -- Implemented new SetFetchMode() that removes the need to use $ADODB_FETCH_MODE. Each connection has independant fetchMode. +- Implemented new SetFetchMode() that removes the need to use $ADODB_FETCH_MODE. Each connection has independent fetchMode. - ADODB_ASSOC_CASE now defaults to 2, use native defaults. This is because we would break backward compat for too many applications otherwise. - Patched encrypted sessions to use replace() - The qstr function supports quoting of nulls when escape character is \ @@ -209,7 +209,7 @@ $conn->Connect($dsn); - Properly implemented Prepare() in oci8 and ODBC. - Added Bind() support to oci8 to support Prepare(). - Improved error handler. Catches CacheExecute() and GenID() errors now. -- Now if you are running php from the command line, debugging messages do not output html formating. Not 100% complete, but getting there. +- Now if you are running php from the command line, debugging messages do not output html formatting. Not 100% complete, but getting there. ## 1.81 - 22 March 2002 @@ -234,7 +234,7 @@ $conn->Connect($dsn); - MetaDatabases() for postgres contributed by Phil pamelant#nerim.net - Mitchell T. Young (mitch#youngfamily.org) contributed informix driver. - Fixed rs2html() problem. I cannot reproduce, so probably a problem with pre PHP 4.1.0 versions, when supporting new ADODB_FETCH_MODEs. -- Mattia Rossi (mattia#technologist.com) contributed BlobDecode() and UpdateBlobFile() for postgresql using the postgres specific pg_lo_import()/pg_lo_open() - i don't use them but hopefully others will find this useful. See [this posting](http://phplens.com/lens/lensforum/msgs.php?id=1262) for an example of usage. +- Mattia Rossi (mattia#technologist.com) contributed BlobDecode() and UpdateBlobFile() for postgresql using the postgres specific pg_lo_import()/pg_lo_open() - i don't use them but hopefully others will find this useful. See [this posting](PHPLens Issue No: 1262) for an example of usage. - Added UpdateBlobFile() for uploading files to a database. - Made UpdateBlob() compatible with oci8po driver. - Added noNullStrings support to oci8 driver. Oracle changes all ' ' strings to nulls, so you need to set strings to ' ' to prevent the nullifying of strings. $conn->noNullStrings = true; will do this for you automatically. This is useful when you define a char column as NOT NULL. @@ -377,7 +377,7 @@ $conn->Connect($dsn); ## 1.10 - 19 May 2001 - Added caching. CacheExecute() and CacheSelectLimit(). -- Added csv driver. See [http://php.weblogs.com/ADODB_csv](http://php.weblogs.com/adodb_csv). +- Added csv driver. - Fixed SelectLimit(), SELECT TOP not working under certain circumstances. - Added better Frontbase support of MetaTypes() by Frank M. Kromann. @@ -471,7 +471,7 @@ $conn->Connect($dsn); ## 0.71 - 22 Nov 2000 -- Switched from using require_once to include/include_once for backward compatability with PHP 4.02 and earlier. +- Switched from using require_once to include/include_once for backward compatibility with PHP 4.02 and earlier. ## 0.70 - 15 Nov 2000 diff --git a/libraries/adodb/docs/changelog_v3.x.md b/libraries/adodb/docs/changelog_v3.x.md index ee2bded40..500c8669c 100644 --- a/libraries/adodb/docs/changelog_v3.x.md +++ b/libraries/adodb/docs/changelog_v3.x.md @@ -65,7 +65,7 @@ Older changelogs: - Added better debugging for Smart Transactions. - Postgres DBTimeStamp() was wrongly using TO_DATE. Changed to TO_TIMESTAMP. - ADODB_FETCH_CASE check pushed to ADONewConnection to allow people to define it after including adodb.inc.php. -- Added portugese (brazilian) to languages. Thx to "Levi Fukumori". +- Added portuguese (brazilian) to languages. Thx to "Levi Fukumori". - Removed arg3 parameter from Execute/SelectLimit/Cache* functions. - Execute() now accepts 2-d array as $inputarray. Also changed docs of fnExecute() to note change in sql query counting with 2-d arrays. - Added MONEY to MetaType in PostgreSQL. @@ -77,7 +77,7 @@ Older changelogs: - Fixed CacheFlush() bug - Thx to martin#gmx.de - Walt Boring contributed MetaForeignKeys for postgres7. - _fetch() called _BlobDecode() wrongly in interbase. Fixed. -- adodb_time bug fixed with dates after 2038 fixed by Jason Pell. http://phplens.com/lens/lensforum/msgs.php?id=6980 +- adodb_time bug fixed with dates after 2038 fixed by Jason Pell. PHPLens Issue No: 6980 ## 3.71 - 4 Aug 2003 @@ -85,7 +85,7 @@ Older changelogs: - Russian language file contributed by "Cyrill Malevanov" cyrill#malevanov.spb.ru. - Spanish language file contributed by "Horacio Degiorgi" horaciod#codigophp.com. - Error handling in oci8 bugfix - if there was an error in Execute(), then when calling ErrorNo() and/or ErrorMsg(), the 1st call would return the error, but the 2nd call would return no error. -- Error handling in odbc bugfix. ODBC would always return the last error, even if it happened 5 queries ago. Now we reset the errormsg to '' and errorno to 0 everytime before CacheExecute() and Execute(). +- Error handling in odbc bugfix. ODBC would always return the last error, even if it happened 5 queries ago. Now we reset the errormsg to '' and errorno to 0 every time before CacheExecute() and Execute(). ## 3.70 - 29 July 2003 @@ -239,4 +239,4 @@ Older changelogs: - Fixed adodb-pear.inc.php syntax error. - Improved _adodb_getcount() to use SELECT COUNT(*) FROM ($sql) for languages that accept it. - Fixed _adodb_getcount() caching error. -- Added sql to retrive table and column info for odbc_mssql. +- Added sql to retrieve table and column info for odbc_mssql. diff --git a/libraries/adodb/docs/changelog_v4+5.md b/libraries/adodb/docs/changelog_v4+5.md index c6a9c10de..c102ac6a7 100644 --- a/libraries/adodb/docs/changelog_v4+5.md +++ b/libraries/adodb/docs/changelog_v4+5.md @@ -1,7 +1,7 @@ ## 4.990/5.05 - 11 Jul 2008 -- Added support for multiple recordsets in mysqli Geisel Sierote <geisel#4up.com.br>. See http://phplens.com/lens/lensforum/msgs.php?id=15917 -- Malcolm Cook added new Reload() function to Active Record. See http://phplens.com/lens/lensforum/msgs.php?id=17474 +- Added support for multiple recordsets in mysqli Geisel Sierote <geisel#4up.com.br>. See PHPLens Issue No: 15917 +- Malcolm Cook added new Reload() function to Active Record. See PHPLens Issue No: 17474 - Thanks Zoltan Monori [monzol#fotoprizma.hu] for bug fixes in iterator, SelectLimit, GetRandRow, etc. - Under heavy loads, the performance monitor for oci8 disables Ixora views. - Fixed sybase driver SQLDate to use str_replace(). Also for adodb5, changed sybase driver UnixDate and UnixTimeStamp calls to static. @@ -49,8 +49,8 @@ $db->CacheExecute($sql); - Active Record: $ADODB_ASSOC_CASE=1 did not work properly. Fixed. - Modified Fields() in recordset class to support display null fields in FetchNextObject(). -- In ADOdb5, active record implementation, we now support column names with spaces in them - we autoconvert the spaces to _ using __set(). Thx Daniel Cook. http://phplens.com/lens/lensforum/msgs.php?id=17200 -- Removed $arg3 from mysqli SelectLimit. See http://phplens.com/lens/lensforum/msgs.php?id=16243. Thx Zsolt Szeberenyi. +- In ADOdb5, active record implementation, we now support column names with spaces in them - we autoconvert the spaces to _ using __set(). Thx Daniel Cook. PHPLens Issue No: 17200 +- Removed $arg3 from mysqli SelectLimit. See PHPLens Issue No: 16243. Thx Zsolt Szeberenyi. - Changed oci8 FetchField, which returns the max_length of BLOB/CLOB/NCLOB as 4000 (incorrectly) to -1. - CacheExecute would sometimes return an error on Windows if it was unable to lock the cache file. This is harmless and has been changed to a warning that can be ignored. Also adodb_write_file() code revised. - ADOdb perf code changed to only log sql if execution time >= 0.05 seconds. New $ADODB_PERF_MIN variable holds min sql timing. Any SQL with timing value below this and is not causing an error is not logged. diff --git a/libraries/adodb/docs/changelog_v4.x.md b/libraries/adodb/docs/changelog_v4.x.md index 84bdd8a70..8b0644402 100644 --- a/libraries/adodb/docs/changelog_v4.x.md +++ b/libraries/adodb/docs/changelog_v4.x.md @@ -8,8 +8,8 @@ Older changelogs: ## 4.990 - 11 Jul 2008 -- Added support for multiple recordsets in mysqli Geisel Sierote <geisel#4up.com.br>. See http://phplens.com/lens/lensforum/msgs.php?id=15917 -- Malcolm Cook added new Reload() function to Active Record. See http://phplens.com/lens/lensforum/msgs.php?id=17474 +- Added support for multiple recordsets in mysqli Geisel Sierote <geisel#4up.com.br>. See PHPLens Issue No: 15917 +- Malcolm Cook added new Reload() function to Active Record. See PHPLens Issue No: 17474 - Thanks Zoltan Monori [monzol#fotoprizma.hu] for bug fixes in iterator, SelectLimit, GetRandRow, etc. - Under heavy loads, the performance monitor for oci8 disables Ixora views. - Fixed sybase driver SQLDate to use str_replace(). Also for adodb5, changed sybase driver UnixDate and UnixTimeStamp calls to static. @@ -19,33 +19,33 @@ Older changelogs: - New ADODB_Cache_File class for file caching defined in adodb.inc.php. - Farsi language file contribution by Peyman Hooshmandi Raad (phooshmand#gmail.com) - New API for creating your custom caching class which is stored in $ADODB_CACHE: - ``` -include "/path/to/adodb.inc.php"; -$ADODB_CACHE_CLASS = 'MyCacheClass'; - -class MyCacheClass extends ADODB_Cache_File -{ - function writecache($filename, $contents,$debug=false){...} - function &readcache($filename, &$err, $secs2cache, $rsClass){ ...} - : -} - -$DB = NewADOConnection($driver); -$DB->Connect(...); ## MyCacheClass created here and stored in $ADODB_CACHE global variable. - -$data = $rs->CacheGetOne($sql); ## MyCacheClass is used here for caching... -``` + ``` + include "/path/to/adodb.inc.php"; + $ADODB_CACHE_CLASS = 'MyCacheClass'; + + class MyCacheClass extends ADODB_Cache_File + { + function writecache($filename, $contents,$debug=false){...} + function &readcache($filename, &$err, $secs2cache, $rsClass){ ...} + : + } + + $DB = NewADOConnection($driver); + $DB->Connect(...); ## MyCacheClass created here and stored in $ADODB_CACHE global variable. + + $data = $rs->CacheGetOne($sql); ## MyCacheClass is used here for caching... + ``` - Memcache supports multiple pooled hosts now. Only if none of the pooled servers can be contacted will a connect error be generated. Usage example below: - ``` -$db = NewADOConnection($driver); -$db->memCache = true; /// should we use memCache instead of caching in files -$db->memCacheHost = array($ip1, $ip2, $ip3); /// $db->memCacheHost = $ip1; still works -$db->memCachePort = 11211; /// this is default memCache port -$db->memCacheCompress = false; /// Use 'true' to store the item compressed (uses zlib) - -$db->Connect(...); -$db->CacheExecute($sql); -``` + ``` + $db = NewADOConnection($driver); + $db->memCache = true; /// should we use memCache instead of caching in files + $db->memCacheHost = array($ip1, $ip2, $ip3); /// $db->memCacheHost = $ip1; still works + $db->memCachePort = 11211; /// this is default memCache port + $db->memCacheCompress = false; /// Use 'true' to store the item compressed (uses zlib) + + $db->Connect(...); + $db->CacheExecute($sql); + ``` ## 4.98 - 13 Feb 2008 @@ -57,8 +57,8 @@ $db->CacheExecute($sql); - Active Record: $ADODB_ASSOC_CASE=1 did not work properly. Fixed. - Modified Fields() in recordset class to support display null fields in FetchNextObject(). -- In ADOdb5, active record implementation, we now support column names with spaces in them - we autoconvert the spaces to `_` using `__set()`. Thx Daniel Cook. http://phplens.com/lens/lensforum/msgs.php?id=17200 -- Removed $arg3 from mysqli SelectLimit. See http://phplens.com/lens/lensforum/msgs.php?id=16243. Thx Zsolt Szeberenyi. +- In ADOdb5, active record implementation, we now support column names with spaces in them - we autoconvert the spaces to `_` using `__set()`. Thx Daniel Cook. PHPLens Issue No: 17200 +- Removed $arg3 from mysqli SelectLimit. See PHPLens Issue No: 16243. Thx Zsolt Szeberenyi. - Changed oci8 FetchField, which returns the max_length of BLOB/CLOB/NCLOB as 4000 (incorrectly) to -1. - CacheExecute would sometimes return an error on Windows if it was unable to lock the cache file. This is harmless and has been changed to a warning that can be ignored. Also adodb_write_file() code revised. - ADOdb perf code changed to only log sql if execution time >= 0.05 seconds. New $ADODB_PERF_MIN variable holds min sql timing. Any SQL with timing value below this and is not causing an error is not logged. @@ -114,13 +114,13 @@ $db->CacheExecute($sql); - Active Record: $ADODB_ASSOC_CASE=2 did not work properly. Fixed. Thx gmane#auxbuss.com. - mysqli had bugs in BeginTrans() and EndTrans(). Fixed. - Improved error handling when no database is connected for oci8. Thx Andy Hassall. -- Names longer than 30 chars in oci8 datadict will be changed to random name. Thx Eugenio. http://phplens.com/lens/lensforum/msgs.php?id=16182 +- Names longer than 30 chars in oci8 datadict will be changed to random name. Thx Eugenio. PHPLens Issue No: 16182 - Added var $upperCase = 'ucase' to access and ado_access drivers. Thx Renato De Giovanni renato#cria.org.br -- Postgres64 driver, if preparing plan failed in _query, did not handle error properly. Fixed. See http://phplens.com/lens/lensforum/msgs.php?id=16131. -- Fixed GetActiveRecordsClass() reference bug. See http://phplens.com/lens/lensforum/msgs.php?id=16120 +- Postgres64 driver, if preparing plan failed in _query, did not handle error properly. Fixed. See PHPLens Issue No: 16131. +- Fixed GetActiveRecordsClass() reference bug. See PHPLens Issue No: 16120 - Added handling of nulls in adodb-ado_mssql.inc.php for qstr(). Thx to Felix Rabinovich. - Adodb-dict contributions by Gaetano - - Support for INDEX in data-dict. Example: idx_ev1. The ability to define indexes using the INDEX keyword was added in ADOdb 4.94. The following example features mutiple indexes, including a compound index idx_ev1. + - Support for INDEX in data-dict. Example: idx_ev1. The ability to define indexes using the INDEX keyword was added in ADOdb 4.94. The following example features multiple indexes, including a compound index idx_ev1. ``` event_id I(11) NOTNULL AUTOINCREMENT PRIMARY, @@ -139,7 +139,7 @@ $db->CacheExecute($sql); - makes any date defined as DEFAULT value for D and T columns work cross-database, not just the "sysdate" value (as long as it is specified using adodb standard format). See above example. - Fixed pdo's GetInsertID() support. Thx Ricky Su. - oci8 Prepare() now sets error messages if an error occurs. -- Added 'PT_BR' to SetDateLocale() -- brazilian portugese. +- Added 'PT_BR' to SetDateLocale() -- brazilian portuguese. - charset in oci8 was not set correctly on `*Connect()` - ADOConnection::Transpose() now appends as first column the field names. - Added $ADODB_QUOTE_FIELDNAMES. If set to true, will autoquote field names in AutoExecute(),GetInsertSQL(), GetUpdateSQL(). @@ -151,12 +151,12 @@ $db->CacheExecute($sql); - Added support for multiple database connections in performance monitoring code (adodb-perf.inc.php). Now all sql in multiple database connections can be saved into one database ($ADODB_LOG_CONN). - Added MetaIndexes() to odbc_mssql. -- Added connection property $db->null2null = 'null'. In autoexecute/getinsertsql/getupdatesql, this value will be converted to a null. Set this to a funny invalid value if you do not want null conversion. See http://phplens.com/lens/lensforum/msgs.php?id=15902. +- Added connection property $db->null2null = 'null'. In autoexecute/getinsertsql/getupdatesql, this value will be converted to a null. Set this to a funny invalid value if you do not want null conversion. See PHPLens Issue No: 15902. - Path disclosure problem in mysqli fixed. Thx Andy. - Fixed typo in session_schema2.xml. - Changed INT in oci8 to return correct precision in $fld->max_length, MetaColumns(). Thx Eloy Lafuente Plaza. -- Patched postgres64 _connect to handle serverinfo(). see http://phplens.com/lens/lensforum/msgs.php?id=15887. -- Added pdo fix for null columns. See http://phplens.com/lens/lensforum/msgs.php?id=15889 +- Patched postgres64 _connect to handle serverinfo(). see PHPLens Issue No: 15887. +- Added pdo fix for null columns. See PHPLens Issue No: 15889 - For stored procedures, missing connection id now passed into mssql_query(). Thx Ecsy (ecsy#freemail.hu). ## 4.92a - 30 Aug 2006 @@ -170,28 +170,28 @@ $db->CacheExecute($sql); - Added IgnoreErrors() to bypass default error handling. - The _adodb_getcount() function in adodb-lib.inc.php, some ORDER BY bug fixes. - For ibase and firebird, set $sysTimeStamp = "CURRENT_TIMESTAMP". -- Fixed postgres connection bug: http://phplens.com/lens/lensforum/msgs.php?id=11057. +- Fixed postgres connection bug: PHPLens Issue No: 11057. - Changed CacheSelectLimit() to flush cache when $secs2cache==-1 due to complaints from other users. - Added support for using memcached with CacheExecute/CacheSelectLimit. Requires memcache module PECL extension. Usage: ``` -$db = NewADOConnection($driver); -$db->memCache = true; /// should we use memCache instead of caching in files -$db->memCacheHost = "126.0.1.1"; /// memCache host -$db->memCachePort = 11211; /// this is default memCache port -$db->memCacheCompress = false; /// Use 'true' to store the item compressed (uses zlib) -$db->Connect(...); -$db->CacheExecute($sql); -``` + $db = NewADOConnection($driver); + $db->memCache = true; /// should we use memCache instead of caching in files + $db->memCacheHost = "126.0.1.1"; /// memCache host + $db->memCachePort = 11211; /// this is default memCache port + $db->memCacheCompress = false; /// Use 'true' to store the item compressed (uses zlib) + $db->Connect(...); + $db->CacheExecute($sql); + ``` - Implemented Transpose() for recordsets. Recordset must be retrieved using ADODB_FETCH_NUM. First column becomes the column name. ``` -$db = NewADOConnection('mysql'); -$db->Connect(...); -$db->SetFetchMode(ADODB_FETCH_NUM); -$rs = $db->Execute('select productname,productid,unitprice from products limit 10'); -$rs2 = $db->Transpose($rs); -rs2html($rs2); -``` + $db = NewADOConnection('mysql'); + $db->Connect(...); + $db->SetFetchMode(ADODB_FETCH_NUM); + $rs = $db->Execute('select productname,productid,unitprice from products limit 10'); + $rs2 = $db->Transpose($rs); + rs2html($rs2); + ``` ## 4.91 - 2 Aug 2006 @@ -201,9 +201,9 @@ rs2html($rs2); - Added to quotes to mysql and mysqli: "SHOW COLUMNS FROM \`%s\`"; - Removed accidental optgroup handling in GetMenu(). Fixed ibase _BlobDecode for php5 compat, and also mem alloc issues for small blobs, thx salvatori#interia.pl - Mysql driver OffsetDate() speedup, useful for adodb-sessions. -- Fix for GetAssoc() PHP5 compat. See http://phplens.com/lens/lensforum/msgs.php?id=15425 +- Fix for GetAssoc() PHP5 compat. See PHPLens Issue No: 15425 - Active Record - If inserting a record and the value of a primary key field is null, then we do not insert that field in as we assume it is an auto-increment field. Needed by mssql. -- Changed postgres7 MetaForeignKeys() see http://phplens.com/lens/lensforum/msgs.php?id=15531 +- Changed postgres7 MetaForeignKeys() see PHPLens Issue No: 15531 - DB2 will now return db2_conn_errormsg() when it is a connection error. ## 4.90 - 8 June 2006 @@ -214,7 +214,7 @@ rs2html($rs2); - Removed `$off = $fieldOffset - 1` line in db2 driver, FetchField(). Tx Larry Menard. - Added support for PHP5 objects as Execute() bind parameters using `__toString` (eg. Simple-XML). Thx Carl-Christian Salvesen. - Rounding in tohtml.inc.php did not work properly. Fixed. -- MetaIndexes in postgres fails when fields are deleted then added in again because the attnum has gaps in it. See http://sourceforge.net/tracker/index.php?func=detail&aid=1451245&group_id=42718&atid=433976. Fixed. +- MetaIndexes in postgres fails when fields are deleted then added in again because the attnum has gaps in it. See https://sourceforge.net/p/adodb/bugs/45/. Fixed. - MetaForeignkeys in mysql and mysqli did not work when fetchMode==ADODB_FETCH_ASSOC used. Fixed. - Reference error in AutoExecute() fixed. - Added macaddr postgres type to MetaType. Maps to 'C'. @@ -230,7 +230,7 @@ rs2html($rs2); - Fixed variable ref errors in adodb-ado5.inc.php in _query(). - Mysqli setcharset fix using method_exists(). - The adodb-perf.inc.php CreateLogTable() code now works for user-defined table names. -- Error in ibase_blob_open() fixed. See http://phplens.com/lens/lensforum/msgs.php?id=14997 +- Error in ibase_blob_open() fixed. See PHPLens Issue No: 14997 ## 4.80 - 8 Mar 2006 @@ -260,14 +260,14 @@ rs2html($rs2); - Fixed GetInsertSQL() to support oci8po. - Fixed qstr() issue with postgresql with \0 in strings. - Fixed some datadict driver loading issues in _adodb_getdriver(). -- Added register shutdown function session_write_close in adodb-session.inc.php for PHP 5 compat. See http://phplens.com/lens/lensforum/msgs.php?id=14200. +- Added register shutdown function session_write_close in adodb-session.inc.php for PHP 5 compat. See PHPLens Issue No: 14200. ## 4.70 - 6 Jan 2006 - Many fixes from Danila Ulyanov to ibase, oci8, postgres, mssql, odbc_oracle, odbtp, etc drivers. -- Changed usage of binary hint in adodb-session.inc.php for mysql. See http://phplens.com/lens/lensforum/msgs.php?id=14160 +- Changed usage of binary hint in adodb-session.inc.php for mysql. See PHPLens Issue No: 14160 - Fixed invalid variable reference problem in undomq(), adodb-perf.inc.php. -- Fixed http://phplens.com/lens/lensforum/msgs.php?id=14254 in adodb-perf.inc.php, `_DBParameter()` settings of fetchmode was wrong. +- Fixed PHPLens Issue No: 14254 in adodb-perf.inc.php, `_DBParameter()` settings of fetchmode was wrong. - Fixed security issues in server.php and tmssql.php discussed by Andreas Sandblad in a Secunia security advisory. Added `$ACCEPTIP = 127.0.0.1` and changed suggested root password to something more secure. - Changed pager to close recordset after RenderLayout(). @@ -349,20 +349,19 @@ rs2html($rs2); - Added 'w' (dow as 0-6 or 1-7) and 'l' (dow as string) for SQLDate for oci8, postgres and mysql. - Rolled back MetaType() changes for mysqli done in prev version. - Datadict change by chris, cblin#tennaxia.com data mappings from: - ``` -oci8: X->varchar(4000) XL->CLOB -mssql: X->XL->TEXT -mysql: X->XL->LONGTEXT -fbird: X->XL->varchar(4000) -``` + oci8: X->varchar(4000) XL->CLOB + mssql: X->XL->TEXT + mysql: X->XL->LONGTEXT + fbird: X->XL->varchar(4000) + ``` to: ``` -oci8: X->varchar(4000) XL->CLOB -mssql: X->VARCHAR(4000) XL->TEXT -mysql: X->TEXT XL->LONGTEXT -fbird: X->VARCHAR(4000) XL->VARCHAR(32000) -``` + oci8: X->varchar(4000) XL->CLOB + mssql: X->VARCHAR(4000) XL->TEXT + mysql: X->TEXT XL->LONGTEXT + fbird: X->VARCHAR(4000) XL->VARCHAR(32000) + ``` - Added $connection->disableBlobs to postgresql to improve performance when no bytea is used (2-5% improvement). - Removed all HTTP_* vars. - Added $rs->tableName to be set before calling AutoExecute(). @@ -446,7 +445,7 @@ fbird: X->VARCHAR(4000) XL->VARCHAR(32000) - MaxDB was padding the defaults of none-string types with spaces - MySql now correctly converts enum columns to varchar - Ralf also changed Postgresql datadict: - - you cant add NOT NULL columns in postgres in one go, they need to be added as NULL and then altered to NOT NULL + - you can't add NOT NULL columns in postgres in one go, they need to be added as NULL and then altered to NOT NULL - AlterColumnSQL could not change a varchar column with numbers into an integer column, postgres need an explicit conversation - a re-created sequence was not set to the correct value, if the name was the old name (no implicit sequence), now always the new name of the implicit sequence is used - Sergio Strampelli added extra $intoken check to Lens_ParseArgs() in datadict code. @@ -499,7 +498,7 @@ fbird: X->VARCHAR(4000) XL->VARCHAR(32000) - Fixed out of page bounds bug in _adodb_pageexecute_all_rows() Thx to "Sergio Strampelli" sergio#rir.it - Speedup of movenext for mysql and oci8 drivers. - Moved debugging code _adodb_debug_execute() to adodb-lib.inc.php. -- Fixed postgresql bytea detection bug. See http://phplens.com/lens/lensforum/msgs.php?id=9849. +- Fixed postgresql bytea detection bug. See PHPLens Issue No: 9849. - Fixed ibase datetimestamp typo in PHP5. Thx stefan. - Removed whitespace at end of odbtp drivers. - Added db2 metaprimarykeys fix. @@ -515,13 +514,13 @@ fbird: X->VARCHAR(4000) XL->VARCHAR(32000) - MetaTables() for mysql, $showschema parameter was not backward compatible with older versions of adodb. Fixed. - Changed mysql GetOne() to work with mysql 3.23 when using with non-select stmts (e.g. SHOW TABLES). - Changed TRIG_ prefix to a variable in datadict-oci8.inc.php. Thx to Luca.Gioppo#csi.it. -- New to adodb-time code. We allow you to define your own daylights savings function, adodb_daylight_sv for pre-1970 dates. If the function is defined (somewhere in an include), then you can correct for daylights savings. See http://phplens.com/phpeverywhere/node/view/16#daylightsavings for more info. +- New to adodb-time code. We allow you to define your own daylights savings function, adodb_daylight_sv for pre-1970 dates. If the function is defined (somewhere in an include), then you can correct for daylights savings. - New sqlitepo driver. This is because assoc mode does not work like other drivers in sqlite. Namely, when selecting (joining) multiple tables, in assoc mode the table names are included in the assoc keys in the "sqlite" driver. In "sqlitepo" driver, the table names are stripped from the returned column names. When this results in a conflict, the first field get preference. Contributed by Herman Kuiper herman#ozuzo.net - Added $forcenull parameter to GetInsertSQL/GetUpdateSQL. Idea by Marco Aurelio Silva. - More XHTML changes for GetMenu. By Jeremy Evans. - Fixes some ibase date issues. Thx to stefan bogdan. - Improvements to mysqli driver to support $ADODB_COUNTRECS. -- Fixed adodb-csvlib.inc.php problem when reading stream from socket. We need to poll stream continiously. +- Fixed adodb-csvlib.inc.php problem when reading stream from socket. We need to poll stream continuously. ## 4.23 - 16 June 2004 @@ -532,33 +531,29 @@ fbird: X->VARCHAR(4000) XL->VARCHAR(32000) - Added $gmt parameter (true/false) to UserDate and UserTimeStamp in connection class, to force conversion of input (in local time) to be converted to UTC/GMT. - Mssql datadict did not support INT types properly (no size param allowed). Added _GetSize() to datadict-mssql.inc.php. - For borland_ibase, BeginTrans(), changed: - ``` -$this->_transactionID = $this->_connectionID; -``` - + $this->_transactionID = $this->_connectionID; + ``` to - ``` -$this->_transactionID = ibase_trans($this->ibasetrans, $this->_connectionID); -``` + $this->_transactionID = ibase_trans($this->ibasetrans, $this->_connectionID); + ``` - Fixed typo in mysqi_field_seek(). Thx to Sh4dow (sh4dow#php.pl). - LogSQL did not work with Firebird/Interbase. Fixed. - Postgres: made errorno() handling more consistent. Thx to Michael Jahn, Michael.Jahn#mailbox.tu-dresden.de. - Added informix patch to better support metatables, metacolumns by "Cecilio Albero" c-albero#eos-i.com - Cyril Malevanov contributed patch to oci8 to support passing of LOB parameters: - ``` -$text = 'test test test'; -$sql = "declare rs clob; begin :rs := lobinout(:sa0); end;"; -$stmt = $conn -> PrepareSP($sql); -$conn -> InParameter($stmt,$text,'sa0', -1, OCI_B_CLOB); -$rs = ''; -$conn -> OutParameter($stmt,$rs,'rs', -1, OCI_B_CLOB); -$conn -> Execute($stmt); -echo "return = ".$rs."<br>";</pre> -``` + $text = 'test test test'; + $sql = "declare rs clob; begin :rs := lobinout(:sa0); end;"; + $stmt = $conn -> PrepareSP($sql); + $conn -> InParameter($stmt,$text,'sa0', -1, OCI_B_CLOB); + $rs = ''; + $conn -> OutParameter($stmt,$rs,'rs', -1, OCI_B_CLOB); + $conn -> Execute($stmt); + echo "return = ".$rs."<br>";</pre> + ``` As he says, the LOBs limitations are: - use OCINewDescriptor before binding @@ -655,7 +650,7 @@ echo "return = ".$rs."<br>";</pre> - CacheSelectLimit internal parameters to SelectLimit were wrong. Thx to Nio. - Modified adodb_pr() and adodb_backtrace() to support command-line usage (eg. no html). - Fixed some fr and it lang errors. Thx to Gaetano G. -- Added contrib directory, with adodb rs to xmlrpc convertor by Gaetano G. +- Added contrib directory, with adodb rs to xmlrpc converter by Gaetano G. - Fixed array recordset bugs when `_skiprow1` is true. Thx to Gaetano G. - Fixed pivot table code when count is false. diff --git a/libraries/adodb/drivers/adodb-access.inc.php b/libraries/adodb/drivers/adodb-access.inc.php index 3a5a8edc3..13461a35b 100644 --- a/libraries/adodb/drivers/adodb-access.inc.php +++ b/libraries/adodb/drivers/adodb-access.inc.php @@ -1,24 +1,34 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. See License.txt. - Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net +/** + * Microsoft Access driver. + * + * Requires ODBC. Works only on Microsoft Windows. + * + * 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 + */ - Microsoft Access data driver. Requires ODBC. Works only on MS Windows. -*/ if (!defined('_ADODB_ODBC_LAYER')) { if (!defined('ADODB_DIR')) die(); - include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); + include_once(ADODB_DIR."/drivers/adodb-odbc.inc.php"); } - if (!defined('_ADODB_ACCESS')) { - define('_ADODB_ACCESS',1); + +if (!defined('_ADODB_ACCESS')) { + define('_ADODB_ACCESS',1); class ADODB_access extends ADODB_odbc { var $databaseType = 'access'; @@ -31,14 +41,6 @@ class ADODB_access extends ADODB_odbc { var $hasTransactions = false; var $upperCase = 'ucase'; - function __construct() - { - global $ADODB_EXTENSION; - - $ADODB_EXTENSION = false; - parent::__construct(); - } - function Time() { return time(); @@ -62,8 +64,6 @@ class ADODB_access extends ADODB_odbc { $ADODB_FETCH_MODE = $savem; if (!$rs) return false; - $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; - $arr = $rs->GetArray(); //print_pre($arr); $arr2 = array(); @@ -80,9 +80,6 @@ class ADORecordSet_access extends ADORecordSet_odbc { var $databaseType = "access"; - function __construct($id,$mode=false) - { - return parent::__construct($id,$mode); - } -}// class +} // class + } diff --git a/libraries/adodb/drivers/adodb-ado.inc.php b/libraries/adodb/drivers/adodb-ado.inc.php index 449cdd005..67a032d72 100644 --- a/libraries/adodb/drivers/adodb-ado.inc.php +++ b/libraries/adodb/drivers/adodb-ado.inc.php @@ -1,17 +1,25 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. -Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Microsoft ADO data driver. Requires ADO. Works only on MS Windows. -*/ +/** + * Microsoft ADO driver. + * + * Requires ADO. Works only on MS Windows. + * + * 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(); @@ -52,9 +60,7 @@ class ADODB_ado extends ADOConnection { function _affectedrows() { - if (PHP_VERSION >= 5) return $this->_affectedRows; - - return $this->_affectedRows->value; + return $this->_affectedRows; } // you can also pass a connection string like this: @@ -81,7 +87,7 @@ class ADODB_ado extends ADOConnection { // not yet //if ($argDatabasename) $argHostname .= ";Initial Catalog=$argDatabasename"; - //use trusted conection for SQL if username not specified + //use trusted connection for SQL if username not specified if (!$argUsername) $argHostname .= ";Trusted_Connection=Yes"; } else if ($argProvider=='access') $argProvider = "Microsoft.Jet.OLEDB.4.0"; // Microsoft Jet Provider @@ -225,7 +231,7 @@ class ADODB_ado extends ADOConnection { // Map by http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthcreateparam.asp // Check issue http://bugs.php.net/bug.php?id=40664 !!! - while(list(, $val) = each($inputarr)) { + foreach ($inputarr as $val) { $type = gettype($val); $len=strlen($val); if ($type == 'boolean') @@ -350,7 +356,7 @@ class ADORecordSet_ado extends ADORecordSet { $mode = $ADODB_FETCH_MODE; } $this->fetchMode = $mode; - return parent::__construct($id,$mode); + parent::__construct($id); } @@ -538,7 +544,7 @@ class ADORecordSet_ado extends ADORecordSet { case 19://adUnsignedInt = 19, case 20://adUnsignedBigInt = 21, return 'I'; - default: return 'N'; + default: return ADODB_DEFAULT_METATYPE; } } diff --git a/libraries/adodb/drivers/adodb-ado5.inc.php b/libraries/adodb/drivers/adodb-ado5.inc.php index 21df32f16..f673d0929 100644 --- a/libraries/adodb/drivers/adodb-ado5.inc.php +++ b/libraries/adodb/drivers/adodb-ado5.inc.php @@ -1,17 +1,25 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. -Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Microsoft ADO data driver. Requires ADO. Works only on MS Windows. PHP5 compat version. -*/ +/** + * Microsoft ADO driver (PHP5 compat version). + * + * Requires ADO. Works only on MS Windows. + * + * 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(); @@ -52,9 +60,7 @@ class ADODB_ado extends ADOConnection { function _affectedrows() { - if (PHP_VERSION >= 5) return $this->_affectedRows; - - return $this->_affectedRows->value; + return $this->_affectedRows; } // you can also pass a connection string like this: @@ -97,7 +103,7 @@ class ADODB_ado extends ADOConnection { // not yet //if ($argDatabasename) $argHostname .= ";Initial Catalog=$argDatabasename"; - //use trusted conection for SQL if username not specified + //use trusted connection for SQL if username not specified if (!$argUsername) $argHostname .= ";Trusted_Connection=Yes"; } else if ($argProvider=='access') $argProvider = "Microsoft.Jet.OLEDB.4.0"; // Microsoft Jet Provider @@ -248,7 +254,7 @@ class ADODB_ado extends ADOConnection { $oCmd->CommandText = $sql; $oCmd->CommandType = 1; - while(list(, $val) = each($inputarr)) { + foreach ($inputarr as $val) { $type = gettype($val); $len=strlen($val); if ($type == 'boolean') @@ -384,7 +390,7 @@ class ADORecordSet_ado extends ADORecordSet { $mode = $ADODB_FETCH_MODE; } $this->fetchMode = $mode; - return parent::__construct($id,$mode); + parent::__construct($id); } @@ -579,7 +585,7 @@ class ADORecordSet_ado extends ADORecordSet { case 19://adUnsignedInt = 19, case 20://adUnsignedBigInt = 21, return 'I'; - default: return 'N'; + default: return ADODB_DEFAULT_METATYPE; } } diff --git a/libraries/adodb/drivers/adodb-ado_access.inc.php b/libraries/adodb/drivers/adodb-ado_access.inc.php index c167ce63a..ad7ab38c5 100644 --- a/libraries/adodb/drivers/adodb-ado_access.inc.php +++ b/libraries/adodb/drivers/adodb-ado_access.inc.php @@ -1,24 +1,31 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community -Released under both BSD license and Lesser GPL library license. -Whenever there is any discrepancy between the two licenses, -the BSD license will take precedence. See License.txt. -Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Microsoft Access ADO data driver. Requires ADO and ODBC. Works only on MS Windows. -*/ +/** + * Microsoft Access ADO driver. + * + * Requires ADO and ODBC. Works only on MS Windows. + * + * 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_ADO_LAYER')) { - if (PHP_VERSION >= 5) include(ADODB_DIR."/drivers/adodb-ado5.inc.php"); - else include(ADODB_DIR."/drivers/adodb-ado.inc.php"); + include_once(ADODB_DIR . "/drivers/adodb-ado5.inc.php"); } class ADODB_ado_access extends ADODB_ado { @@ -43,8 +50,4 @@ class ADORecordSet_ado_access extends ADORecordSet_ado { var $databaseType = "ado_access"; - function __construct($id,$mode=false) - { - return parent::__construct($id,$mode); - } } diff --git a/libraries/adodb/drivers/adodb-ado_mssql.inc.php b/libraries/adodb/drivers/adodb-ado_mssql.inc.php index 57eacc938..d0e9c1963 100644 --- a/libraries/adodb/drivers/adodb-ado_mssql.inc.php +++ b/libraries/adodb/drivers/adodb-ado_mssql.inc.php @@ -1,28 +1,31 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. -Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Microsoft SQL Server ADO data driver. Requires ADO and MSSQL client. - Works only on MS Windows. - - Warning: Some versions of PHP (esp PHP4) leak memory when ADO/COM is used. - Please check http://bugs.php.net/ for more info. -*/ +/** + * Microsoft SQL Server ADO driver. + * + * Requires ADO and MSSQL client. Works only on MS Windows. + * + * 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_ADO_LAYER')) { - if (PHP_VERSION >= 5) include(ADODB_DIR."/drivers/adodb-ado5.inc.php"); - else include(ADODB_DIR."/drivers/adodb-ado.inc.php"); + include_once(ADODB_DIR . "/drivers/adodb-ado5.inc.php"); } @@ -41,14 +44,14 @@ class ADODB_ado_mssql extends ADODB_ado { //var $_inTransaction = 1; // always open recordsets, so no transaction problems. - function _insertid() + protected function _insertID($table = '', $column = '') { - return $this->GetOne('select SCOPE_IDENTITY()'); + return $this->GetOne('select SCOPE_IDENTITY()'); } function _affectedrows() { - return $this->GetOne('select @@rowcount'); + return $this->GetOne('select @@rowcount'); } function SetTransactionMode( $transaction_mode ) @@ -62,40 +65,40 @@ class ADODB_ado_mssql extends ADODB_ado { $this->Execute("SET TRANSACTION ".$transaction_mode); } - function qstr($s,$magic_quotes=false) + function qStr($s, $magic_quotes=false) { - $s = ADOConnection::qstr($s, $magic_quotes); + $s = ADOConnection::qStr($s); return str_replace("\0", "\\\\000", $s); } function MetaColumns($table, $normalize=true) { - $table = strtoupper($table); - $arr= array(); - $dbc = $this->_connectionID; - - $osoptions = array(); - $osoptions[0] = null; - $osoptions[1] = null; - $osoptions[2] = $table; - $osoptions[3] = null; - - $adors=@$dbc->OpenSchema(4, $osoptions);//tables - - if ($adors){ - while (!$adors->EOF){ - $fld = new ADOFieldObject(); - $c = $adors->Fields(3); - $fld->name = $c->Value; - $fld->type = 'CHAR'; // cannot discover type in ADO! - $fld->max_length = -1; - $arr[strtoupper($fld->name)]=$fld; - - $adors->MoveNext(); - } - $adors->Close(); - } - $false = false; + $table = strtoupper($table); + $arr= array(); + $dbc = $this->_connectionID; + + $osoptions = array(); + $osoptions[0] = null; + $osoptions[1] = null; + $osoptions[2] = $table; + $osoptions[3] = null; + + $adors=@$dbc->OpenSchema(4, $osoptions);//tables + + if ($adors){ + while (!$adors->EOF){ + $fld = new ADOFieldObject(); + $c = $adors->Fields(3); + $fld->name = $c->Value; + $fld->type = 'CHAR'; // cannot discover type in ADO! + $fld->max_length = -1; + $arr[strtoupper($fld->name)]=$fld; + + $adors->MoveNext(); + } + $adors->Close(); + } + $false = false; return empty($arr) ? $false : $arr; } @@ -137,14 +140,10 @@ class ADODB_ado_mssql extends ADODB_ado { //return $this->GetOne("SELECT CONVERT(varchar(255), NEWID()) AS 'Char'"); } - } // end class +} // end class - class ADORecordSet_ado_mssql extends ADORecordSet_ado { +class ADORecordSet_ado_mssql extends ADORecordSet_ado { var $databaseType = 'ado_mssql'; - function __construct($id,$mode=false) - { - return parent::__construct($id,$mode); - } } diff --git a/libraries/adodb/drivers/adodb-ads.inc.php b/libraries/adodb/drivers/adodb-ads.inc.php index d59df663a..b9d4adb52 100644 --- a/libraries/adodb/drivers/adodb-ads.inc.php +++ b/libraries/adodb/drivers/adodb-ads.inc.php @@ -1,20 +1,29 @@ <?php -/* - (c) 2000-2014 John Lim (jlim#natsoft.com.my). All rights reserved. - Portions Copyright (c) 2007-2009, iAnywhere Solutions, Inc. - All rights reserved. All unpublished rights reserved. - - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - -Set tabs to 4 for best viewing. - - -NOTE: This driver requires the Advantage PHP client libraries, which - can be downloaded for free via: - http://devzone.advantagedatabase.com/dz/content.aspx?key=20 +/** + * ADOdb driver for ADS. + * + * NOTE: This driver requires the Advantage PHP client libraries, which + * can be downloaded for free via: + * @link http://devzone.advantagedatabase.com/dz/content.aspx?key=20 + * + * 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 + */ +/* DELPHI FOR PHP USERS: The following steps can be taken to utilize this driver from the CodeGear Delphi for PHP product: @@ -35,610 +44,632 @@ DELPHI FOR PHP USERS: Database object's DriverName property. */ + // security - hide paths -if (!defined('ADODB_DIR')) die(); +if (!defined('ADODB_DIR')) { + die(); +} - define("_ADODB_ADS_LAYER", 2 ); +define("_ADODB_ADS_LAYER", 2); /*-------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------*/ -class ADODB_ads extends ADOConnection { - var $databaseType = "ads"; - var $fmt = "'m-d-Y'"; - var $fmtTimeStamp = "'Y-m-d H:i:s'"; - var $concat_operator = ''; - var $replaceQuote = "''"; // string to use to replace quotes - var $dataProvider = "ads"; - var $hasAffectedRows = true; - var $binmode = ODBC_BINMODE_RETURN; - var $useFetchArray = false; // setting this to true will make array elements in FETCH_ASSOC mode case-sensitive - // breaking backward-compat - //var $longreadlen = 8000; // default number of chars to return for a Blob/Long field - var $_bindInputArray = false; - var $curmode = SQL_CUR_USE_DRIVER; // See sqlext.h, SQL_CUR_DEFAULT == SQL_CUR_USE_DRIVER == 2L - var $_genSeqSQL = "create table %s (id integer)"; - var $_autocommit = true; - var $_haserrorfunctions = true; - var $_has_stupid_odbc_fetch_api_change = true; - var $_lastAffectedRows = 0; - var $uCaseTables = true; // for meta* functions, uppercase table names - - - function __construct() - { - $this->_haserrorfunctions = ADODB_PHPVER >= 0x4050; - $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200; - } - - // returns true or false - function _connect($argDSN, $argUsername, $argPassword, $argDatabasename) - { - global $php_errormsg; - - if (!function_exists('ads_connect')) return null; - - if ($this->debug && $argDatabasename && $this->databaseType != 'vfp') { - ADOConnection::outp("For Advantage Connect(), $argDatabasename is not used. Place dsn in 1st parameter."); - } - if (isset($php_errormsg)) $php_errormsg = ''; - if ($this->curmode === false) $this->_connectionID = ads_connect($argDSN,$argUsername,$argPassword); - else $this->_connectionID = ads_connect($argDSN,$argUsername,$argPassword,$this->curmode); - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; - if (isset($this->connectStmt)) $this->Execute($this->connectStmt); - - return $this->_connectionID != false; - } - - // returns true or false - function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename) - { - global $php_errormsg; - - if (!function_exists('ads_connect')) return null; - - if (isset($php_errormsg)) $php_errormsg = ''; - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; - if ($this->debug && $argDatabasename) { - ADOConnection::outp("For PConnect(), $argDatabasename is not used. Place dsn in 1st parameter."); - } - // print "dsn=$argDSN u=$argUsername p=$argPassword<br>"; flush(); - if ($this->curmode === false) $this->_connectionID = ads_connect($argDSN,$argUsername,$argPassword); - else $this->_connectionID = ads_pconnect($argDSN,$argUsername,$argPassword,$this->curmode); - - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; - if ($this->_connectionID && $this->autoRollback) @ads_rollback($this->_connectionID); - if (isset($this->connectStmt)) $this->Execute($this->connectStmt); - - return $this->_connectionID != false; - } - - // returns the Server version and Description - function ServerInfo() - { - - if (!empty($this->host) && ADODB_PHPVER >= 0x4300) { - $stmt = $this->Prepare('EXECUTE PROCEDURE sp_mgGetInstallInfo()'); - $res = $this->Execute($stmt); - if(!$res) - print $this->ErrorMsg(); - else{ - $ret["version"]= $res->fields[3]; - $ret["description"]="Advantage Database Server"; - return $ret; - } - } - else { - return ADOConnection::ServerInfo(); - } - } - - - // returns true or false - function CreateSequence($seqname = 'adodbseq', $start = 1) - { - $res = $this->Execute("CREATE TABLE $seqname ( ID autoinc( 1 ) ) IN DATABASE"); - if(!$res){ - print $this->ErrorMsg(); - return false; - } - else - return true; - - } - - // returns true or false - function DropSequence($seqname = 'adodbseq') - { - $res = $this->Execute("DROP TABLE $seqname"); - if(!$res){ - print $this->ErrorMsg(); - return false; - } - else - return true; - } - - - // returns the generated ID or false - // checks if the table already exists, else creates the table and inserts a record into the table - // and gets the ID number of the last inserted record. - function GenID($seqname = 'adodbseq', $start = 1) - { - $go = $this->Execute("select * from $seqname"); - if (!$go){ - $res = $this->Execute("CREATE TABLE $seqname ( ID autoinc( 1 ) ) IN DATABASE"); - if(!res){ - print $this->ErrorMsg(); - return false; - } - } - $res = $this->Execute("INSERT INTO $seqname VALUES( DEFAULT )"); - if(!$res){ - print $this->ErrorMsg(); - return false; - } - else{ - $gen = $this->Execute("SELECT LastAutoInc( STATEMENT ) FROM system.iota"); - $ret = $gen->fields[0]; - return $ret; - } - - } - - - - - function ErrorMsg() - { - if ($this->_haserrorfunctions) { - if ($this->_errorMsg !== false) return $this->_errorMsg; - if (empty($this->_connectionID)) return @ads_errormsg(); - return @ads_errormsg($this->_connectionID); - } else return ADOConnection::ErrorMsg(); - } - - - function ErrorNo() - { - - if ($this->_haserrorfunctions) { - if ($this->_errorCode !== false) { - // bug in 4.0.6, error number can be corrupted string (should be 6 digits) - return (strlen($this->_errorCode)<=2) ? 0 : $this->_errorCode; - } - - if (empty($this->_connectionID)) $e = @ads_error(); - else $e = @ads_error($this->_connectionID); - - // bug in 4.0.6, error number can be corrupted string (should be 6 digits) - // so we check and patch - if (strlen($e)<=2) return 0; - return $e; - } else return ADOConnection::ErrorNo(); - } - - - - function BeginTrans() - { - if (!$this->hasTransactions) return false; - if ($this->transOff) return true; - $this->transCnt += 1; - $this->_autocommit = false; - return ads_autocommit($this->_connectionID,false); - } - - function CommitTrans($ok=true) - { - if ($this->transOff) return true; - if (!$ok) return $this->RollbackTrans(); - if ($this->transCnt) $this->transCnt -= 1; - $this->_autocommit = true; - $ret = ads_commit($this->_connectionID); - ads_autocommit($this->_connectionID,true); - return $ret; - } - - function RollbackTrans() - { - if ($this->transOff) return true; - if ($this->transCnt) $this->transCnt -= 1; - $this->_autocommit = true; - $ret = ads_rollback($this->_connectionID); - ads_autocommit($this->_connectionID,true); - return $ret; - } - - - // Returns tables,Views or both on succesfull execution. Returns - // tables by default on succesfull execustion. - function &MetaTables($ttype = false, $showSchema = false, $mask = false) - { - $recordSet1 = $this->Execute("select * from system.tables"); - if(!$recordSet1){ - print $this->ErrorMsg(); - return false; - } - $recordSet2 = $this->Execute("select * from system.views"); - if(!$recordSet2){ - print $this->ErrorMsg(); - return false; - } - $i=0; - while (!$recordSet1->EOF){ - $arr["$i"] = $recordSet1->fields[0]; - $recordSet1->MoveNext(); - $i=$i+1; - } - if($ttype=='FALSE'){ - while (!$recordSet2->EOF){ - $arr["$i"] = $recordSet2->fields[0]; - $recordSet2->MoveNext(); - $i=$i+1; - } - return $arr; - } - elseif($ttype=='VIEWS'){ - while (!$recordSet2->EOF){ - $arrV["$i"] = $recordSet2->fields[0]; - $recordSet2->MoveNext(); - $i=$i+1; - } - return $arrV; - } - else{ - return $arr; - } - - } - - function &MetaPrimaryKeys($table, $owner = false) - { - $recordSet = $this->Execute("select table_primary_key from system.tables where name='$table'"); - if(!$recordSet){ - print $this->ErrorMsg(); - return false; - } - $i=0; - while (!$recordSet->EOF){ - $arr["$i"] = $recordSet->fields[0]; - $recordSet->MoveNext(); - $i=$i+1; - } - return $arr; - } - -/* -See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcdatetime_data_type_changes.asp -/ SQL data type codes / -#define SQL_UNKNOWN_TYPE 0 -#define SQL_CHAR 1 -#define SQL_NUMERIC 2 -#define SQL_DECIMAL 3 -#define SQL_INTEGER 4 -#define SQL_SMALLINT 5 -#define SQL_FLOAT 6 -#define SQL_REAL 7 -#define SQL_DOUBLE 8 -#if (ODBCVER >= 0x0300) -#define SQL_DATETIME 9 -#endif -#define SQL_VARCHAR 12 - - -/ One-parameter shortcuts for date/time data types / -#if (ODBCVER >= 0x0300) -#define SQL_TYPE_DATE 91 -#define SQL_TYPE_TIME 92 -#define SQL_TYPE_TIMESTAMP 93 - -#define SQL_UNICODE (-95) -#define SQL_UNICODE_VARCHAR (-96) -#define SQL_UNICODE_LONGVARCHAR (-97) -*/ - function ODBCTypes($t) - { - switch ((integer)$t) { - case 1: - case 12: - case 0: - case -95: - case -96: - return 'C'; - case -97: - case -1: //text - return 'X'; - case -4: //image - return 'B'; - - case 9: - case 91: - return 'D'; - - case 10: - case 11: - case 92: - case 93: - return 'T'; - - case 4: - case 5: - case -6: - return 'I'; - - case -11: // uniqidentifier - return 'R'; - case -7: //bit - return 'L'; - - default: - return 'N'; - } - } - - function &MetaColumns($table, $normalize = true) - { - global $ADODB_FETCH_MODE; - - $false = false; - if ($this->uCaseTables) $table = strtoupper($table); - $schema = ''; - $this->_findschema($table,$schema); - - $savem = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - - /*if (false) { // after testing, confirmed that the following does not work becoz of a bug - $qid2 = ads_tables($this->_connectionID); - $rs = new ADORecordSet_ads($qid2); - $ADODB_FETCH_MODE = $savem; - if (!$rs) return false; - $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; - $rs->_fetch(); - - while (!$rs->EOF) { - if ($table == strtoupper($rs->fields[2])) { - $q = $rs->fields[0]; - $o = $rs->fields[1]; - break; - } - $rs->MoveNext(); - } - $rs->Close(); - - $qid = ads_columns($this->_connectionID,$q,$o,strtoupper($table),'%'); - } */ - - switch ($this->databaseType) { - case 'access': - case 'vfp': - $qid = ads_columns($this->_connectionID);#,'%','',strtoupper($table),'%'); - break; - - - case 'db2': - $colname = "%"; - $qid = ads_columns($this->_connectionID, "", $schema, $table, $colname); - break; - - default: - $qid = @ads_columns($this->_connectionID,'%','%',strtoupper($table),'%'); - if (empty($qid)) $qid = ads_columns($this->_connectionID); - break; - } - if (empty($qid)) return $false; - - $rs = new ADORecordSet_ads($qid); - $ADODB_FETCH_MODE = $savem; - - if (!$rs) return $false; - $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; - $rs->_fetch(); - - $retarr = array(); - - /* - $rs->fields indices - 0 TABLE_QUALIFIER - 1 TABLE_SCHEM - 2 TABLE_NAME - 3 COLUMN_NAME - 4 DATA_TYPE - 5 TYPE_NAME - 6 PRECISION - 7 LENGTH - 8 SCALE - 9 RADIX - 10 NULLABLE - 11 REMARKS - */ - while (!$rs->EOF) { - // adodb_pr($rs->fields); - if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) { - $fld = new ADOFieldObject(); - $fld->name = $rs->fields[3]; - $fld->type = $this->ODBCTypes($rs->fields[4]); - - // ref: http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraccgen/html/msdn_odk.asp - // access uses precision to store length for char/varchar - if ($fld->type == 'C' or $fld->type == 'X') { - if ($this->databaseType == 'access') - $fld->max_length = $rs->fields[6]; - else if ($rs->fields[4] <= -95) // UNICODE - $fld->max_length = $rs->fields[7]/2; - else - $fld->max_length = $rs->fields[7]; - } else - $fld->max_length = $rs->fields[7]; - $fld->not_null = !empty($rs->fields[10]); - $fld->scale = $rs->fields[8]; - $retarr[strtoupper($fld->name)] = $fld; - } else if (sizeof($retarr)>0) - break; - $rs->MoveNext(); - } - $rs->Close(); //-- crashes 4.03pl1 -- why? - - if (empty($retarr)) $retarr = false; - return $retarr; - } - - // Returns an array of columns names for a given table - function &MetaColumnNames($table, $numIndexes = false, $useattnum = false) - { - $recordSet = $this->Execute("select name from system.columns where parent='$table'"); - if(!$recordSet){ - print $this->ErrorMsg(); - return false; - } - else{ - $i=0; - while (!$recordSet->EOF){ - $arr["FIELD$i"] = $recordSet->fields[0]; - $recordSet->MoveNext(); - $i=$i+1; - } - return $arr; - } - } - - - function Prepare($sql) - { - if (! $this->_bindInputArray) return $sql; // no binding - $stmt = ads_prepare($this->_connectionID,$sql); - if (!$stmt) { - // we don't know whether odbc driver is parsing prepared stmts, so just return sql - return $sql; - } - return array($sql,$stmt,false); - } - - /* returns queryID or false */ - function _query($sql,$inputarr=false) - { - GLOBAL $php_errormsg; - if (isset($php_errormsg)) $php_errormsg = ''; - $this->_error = ''; - - if ($inputarr) { - if (is_array($sql)) { - $stmtid = $sql[1]; - } else { - $stmtid = ads_prepare($this->_connectionID,$sql); - - if ($stmtid == false) { - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; - return false; - } - } - - if (! ads_execute($stmtid,$inputarr)) { - //@ads_free_result($stmtid); - if ($this->_haserrorfunctions) { - $this->_errorMsg = ads_errormsg(); - $this->_errorCode = ads_error(); - } - return false; - } - - } else if (is_array($sql)) { - $stmtid = $sql[1]; - if (!ads_execute($stmtid)) { - //@ads_free_result($stmtid); - if ($this->_haserrorfunctions) { - $this->_errorMsg = ads_errormsg(); - $this->_errorCode = ads_error(); - } - return false; - } - } else - { - - $stmtid = ads_exec($this->_connectionID,$sql); - - } - - $this->_lastAffectedRows = 0; - - if ($stmtid) - { - - if (@ads_num_fields($stmtid) == 0) { - $this->_lastAffectedRows = ads_num_rows($stmtid); - $stmtid = true; - - } else { - - $this->_lastAffectedRows = 0; - ads_binmode($stmtid,$this->binmode); - ads_longreadlen($stmtid,$this->maxblobsize); - - } - - if ($this->_haserrorfunctions) - { - - $this->_errorMsg = ''; - $this->_errorCode = 0; - } - else - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; - } - else - { - if ($this->_haserrorfunctions) { - $this->_errorMsg = ads_errormsg(); - $this->_errorCode = ads_error(); - } else - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; - } - - return $stmtid; - - } - - /* - Insert a null into the blob field of the table first. - Then use UpdateBlob to store the blob. - - Usage: - - $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); - $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); - */ - function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') - { - $sql = "UPDATE $table SET $column=? WHERE $where"; - $stmtid = ads_prepare($this->_connectionID,$sql); - if ($stmtid == false){ - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; - return false; - } - if (! ads_execute($stmtid,array($val),array(SQL_BINARY) )){ - if ($this->_haserrorfunctions){ - $this->_errorMsg = ads_errormsg(); - $this->_errorCode = ads_error(); - } - return false; - } - return TRUE; - } - - // returns true or false - function _close() - { - $ret = @ads_close($this->_connectionID); - $this->_connectionID = false; - return $ret; - } - - function _affectedrows() - { - return $this->_lastAffectedRows; - } +class ADODB_ads extends ADOConnection +{ + var $databaseType = "ads"; + var $fmt = "'m-d-Y'"; + var $fmtTimeStamp = "'Y-m-d H:i:s'"; + var $concat_operator = ''; + var $replaceQuote = "''"; // string to use to replace quotes + var $dataProvider = "ads"; + var $hasAffectedRows = true; + var $binmode = ODBC_BINMODE_RETURN; + var $useFetchArray = false; // setting this to true will make array elements in FETCH_ASSOC mode case-sensitive + // breaking backward-compat + //var $longreadlen = 8000; // default number of chars to return for a Blob/Long field + var $_bindInputArray = false; + var $curmode = SQL_CUR_USE_DRIVER; // See sqlext.h, SQL_CUR_DEFAULT == SQL_CUR_USE_DRIVER == 2L + var $_genSeqSQL = "create table %s (id integer)"; + var $_autocommit = true; + var $_lastAffectedRows = 0; + var $uCaseTables = true; // for meta* functions, uppercase table names + + function __construct() + { + } + + // returns true or false + function _connect($argDSN, $argUsername, $argPassword, $argDatabasename) + { + if (!function_exists('ads_connect')) { + return null; + } + + if ($this->debug && $argDatabasename && $this->databaseType != 'vfp') { + ADOConnection::outp("For Advantage Connect(), $argDatabasename is not used. Place dsn in 1st parameter."); + } + $last_php_error = $this->resetLastError(); + if ($this->curmode === false) { + $this->_connectionID = ads_connect($argDSN, $argUsername, $argPassword); + } else { + $this->_connectionID = ads_connect($argDSN, $argUsername, $argPassword, $this->curmode); + } + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); + if (isset($this->connectStmt)) { + $this->Execute($this->connectStmt); + } + + return $this->_connectionID != false; + } + + // returns true or false + function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename) + { + if (!function_exists('ads_connect')) { + return null; + } + + $last_php_error = $this->resetLastError(); + $this->_errorMsg = ''; + if ($this->debug && $argDatabasename) { + ADOConnection::outp("For PConnect(), $argDatabasename is not used. Place dsn in 1st parameter."); + } + // print "dsn=$argDSN u=$argUsername p=$argPassword<br>"; flush(); + if ($this->curmode === false) { + $this->_connectionID = ads_connect($argDSN, $argUsername, $argPassword); + } else { + $this->_connectionID = ads_pconnect($argDSN, $argUsername, $argPassword, $this->curmode); + } + + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); + if ($this->_connectionID && $this->autoRollback) { + @ads_rollback($this->_connectionID); + } + if (isset($this->connectStmt)) { + $this->Execute($this->connectStmt); + } + + return $this->_connectionID != false; + } + + // returns the Server version and Description + function ServerInfo() + { + + if (!empty($this->host)) { + $stmt = $this->Prepare('EXECUTE PROCEDURE sp_mgGetInstallInfo()'); + $res = $this->Execute($stmt); + if (!$res) { + print $this->ErrorMsg(); + } else { + $ret["version"] = $res->fields[3]; + $ret["description"] = "Advantage Database Server"; + return $ret; + } + } else { + return ADOConnection::ServerInfo(); + } + } + + + // returns true or false + function CreateSequence($seqname = 'adodbseq', $start = 1) + { + $res = $this->Execute("CREATE TABLE $seqname ( ID autoinc( 1 ) ) IN DATABASE"); + if (!$res) { + print $this->ErrorMsg(); + return false; + } else { + return true; + } + + } + + // returns true or false + function DropSequence($seqname = 'adodbseq') + { + $res = $this->Execute("DROP TABLE $seqname"); + if (!$res) { + print $this->ErrorMsg(); + return false; + } else { + return true; + } + } + + + // returns the generated ID or false + // checks if the table already exists, else creates the table and inserts a record into the table + // and gets the ID number of the last inserted record. + function GenID($seqname = 'adodbseq', $start = 1) + { + $go = $this->Execute("select * from $seqname"); + if (!$go) { + $res = $this->Execute("CREATE TABLE $seqname ( ID autoinc( 1 ) ) IN DATABASE"); + if (!$res) { + print $this->ErrorMsg(); + return false; + } + } + $res = $this->Execute("INSERT INTO $seqname VALUES( DEFAULT )"); + if (!$res) { + print $this->ErrorMsg(); + return false; + } else { + $gen = $this->Execute("SELECT LastAutoInc( STATEMENT ) FROM system.iota"); + $ret = $gen->fields[0]; + return $ret; + } + + } + + + function ErrorMsg() + { + if ($this->_errorMsg !== false) { + return $this->_errorMsg; + } + if (empty($this->_connectionID)) { + return @ads_errormsg(); + } + return @ads_errormsg($this->_connectionID); + } + + + function ErrorNo() + { + if ($this->_errorCode !== false) { + // bug in 4.0.6, error number can be corrupted string (should be 6 digits) + return (strlen($this->_errorCode) <= 2) ? 0 : $this->_errorCode; + } + + if (empty($this->_connectionID)) { + $e = @ads_error(); + } else { + $e = @ads_error($this->_connectionID); + } + + // bug in 4.0.6, error number can be corrupted string (should be 6 digits) + // so we check and patch + if (strlen($e) <= 2) { + return 0; + } + return $e; + } + + + function BeginTrans() + { + if (!$this->hasTransactions) { + return false; + } + if ($this->transOff) { + return true; + } + $this->transCnt += 1; + $this->_autocommit = false; + return ads_autocommit($this->_connectionID, false); + } + + function CommitTrans($ok = true) + { + if ($this->transOff) { + return true; + } + if (!$ok) { + return $this->RollbackTrans(); + } + if ($this->transCnt) { + $this->transCnt -= 1; + } + $this->_autocommit = true; + $ret = ads_commit($this->_connectionID); + ads_autocommit($this->_connectionID, true); + return $ret; + } + + function RollbackTrans() + { + if ($this->transOff) { + return true; + } + if ($this->transCnt) { + $this->transCnt -= 1; + } + $this->_autocommit = true; + $ret = ads_rollback($this->_connectionID); + ads_autocommit($this->_connectionID, true); + return $ret; + } + + + // Returns tables,Views or both on successful execution. Returns + // tables by default on successful execution. + function &MetaTables($ttype = false, $showSchema = false, $mask = false) + { + $recordSet1 = $this->Execute("select * from system.tables"); + if (!$recordSet1) { + print $this->ErrorMsg(); + return false; + } + $recordSet2 = $this->Execute("select * from system.views"); + if (!$recordSet2) { + print $this->ErrorMsg(); + return false; + } + $i = 0; + while (!$recordSet1->EOF) { + $arr["$i"] = $recordSet1->fields[0]; + $recordSet1->MoveNext(); + $i = $i + 1; + } + if ($ttype == 'FALSE') { + while (!$recordSet2->EOF) { + $arr["$i"] = $recordSet2->fields[0]; + $recordSet2->MoveNext(); + $i = $i + 1; + } + return $arr; + } elseif ($ttype == 'VIEWS') { + while (!$recordSet2->EOF) { + $arrV["$i"] = $recordSet2->fields[0]; + $recordSet2->MoveNext(); + $i = $i + 1; + } + return $arrV; + } else { + return $arr; + } + + } + + function &MetaPrimaryKeys($table, $owner = false) + { + $recordSet = $this->Execute("select table_primary_key from system.tables where name='$table'"); + if (!$recordSet) { + print $this->ErrorMsg(); + return false; + } + $i = 0; + while (!$recordSet->EOF) { + $arr["$i"] = $recordSet->fields[0]; + $recordSet->MoveNext(); + $i = $i + 1; + } + return $arr; + } + + /* + See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcdatetime_data_type_changes.asp + / SQL data type codes / + #define SQL_UNKNOWN_TYPE 0 + #define SQL_CHAR 1 + #define SQL_NUMERIC 2 + #define SQL_DECIMAL 3 + #define SQL_INTEGER 4 + #define SQL_SMALLINT 5 + #define SQL_FLOAT 6 + #define SQL_REAL 7 + #define SQL_DOUBLE 8 + #if (ODBCVER >= 0x0300) + #define SQL_DATETIME 9 + #endif + #define SQL_VARCHAR 12 + + + / One-parameter shortcuts for date/time data types / + #if (ODBCVER >= 0x0300) + #define SQL_TYPE_DATE 91 + #define SQL_TYPE_TIME 92 + #define SQL_TYPE_TIMESTAMP 93 + + #define SQL_UNICODE (-95) + #define SQL_UNICODE_VARCHAR (-96) + #define SQL_UNICODE_LONGVARCHAR (-97) + */ + function ODBCTypes($t) + { + switch ((integer)$t) { + case 1: + case 12: + case 0: + case -95: + case -96: + return 'C'; + case -97: + case -1: //text + return 'X'; + case -4: //image + return 'B'; + + case 9: + case 91: + return 'D'; + + case 10: + case 11: + case 92: + case 93: + return 'T'; + + case 4: + case 5: + case -6: + return 'I'; + + case -11: // uniqidentifier + return 'R'; + case -7: //bit + return 'L'; + + default: + return 'N'; + } + } + + function &MetaColumns($table, $normalize = true) + { + global $ADODB_FETCH_MODE; + + $false = false; + if ($this->uCaseTables) { + $table = strtoupper($table); + } + $schema = ''; + $this->_findschema($table, $schema); + + $savem = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + + /*if (false) { // after testing, confirmed that the following does not work because of a bug + $qid2 = ads_tables($this->_connectionID); + $rs = new ADORecordSet_ads($qid2); + $ADODB_FETCH_MODE = $savem; + if (!$rs) return false; + $rs->_fetch(); + + while (!$rs->EOF) { + if ($table == strtoupper($rs->fields[2])) { + $q = $rs->fields[0]; + $o = $rs->fields[1]; + break; + } + $rs->MoveNext(); + } + $rs->Close(); + + $qid = ads_columns($this->_connectionID,$q,$o,strtoupper($table),'%'); + } */ + + switch ($this->databaseType) { + case 'access': + case 'vfp': + $qid = ads_columns($this->_connectionID);#,'%','',strtoupper($table),'%'); + break; + + + case 'db2': + $colname = "%"; + $qid = ads_columns($this->_connectionID, "", $schema, $table, $colname); + break; + + default: + $qid = @ads_columns($this->_connectionID, '%', '%', strtoupper($table), '%'); + if (empty($qid)) { + $qid = ads_columns($this->_connectionID); + } + break; + } + if (empty($qid)) { + return $false; + } + + $rs = new ADORecordSet_ads($qid); + $ADODB_FETCH_MODE = $savem; + + if (!$rs) { + return $false; + } + $rs->_fetch(); + + $retarr = array(); + + /* + $rs->fields indices + 0 TABLE_QUALIFIER + 1 TABLE_SCHEM + 2 TABLE_NAME + 3 COLUMN_NAME + 4 DATA_TYPE + 5 TYPE_NAME + 6 PRECISION + 7 LENGTH + 8 SCALE + 9 RADIX + 10 NULLABLE + 11 REMARKS + */ + while (!$rs->EOF) { + // adodb_pr($rs->fields); + if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) { + $fld = new ADOFieldObject(); + $fld->name = $rs->fields[3]; + $fld->type = $this->ODBCTypes($rs->fields[4]); + + // ref: http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraccgen/html/msdn_odk.asp + // access uses precision to store length for char/varchar + if ($fld->type == 'C' or $fld->type == 'X') { + if ($this->databaseType == 'access') { + $fld->max_length = $rs->fields[6]; + } else { + if ($rs->fields[4] <= -95) // UNICODE + { + $fld->max_length = $rs->fields[7] / 2; + } else { + $fld->max_length = $rs->fields[7]; + } + } + } else { + $fld->max_length = $rs->fields[7]; + } + $fld->not_null = !empty($rs->fields[10]); + $fld->scale = $rs->fields[8]; + $retarr[strtoupper($fld->name)] = $fld; + } else { + if (sizeof($retarr) > 0) { + break; + } + } + $rs->MoveNext(); + } + $rs->Close(); //-- crashes 4.03pl1 -- why? + + if (empty($retarr)) { + $retarr = false; + } + return $retarr; + } + + // Returns an array of columns names for a given table + function &MetaColumnNames($table, $numIndexes = false, $useattnum = false) + { + $recordSet = $this->Execute("select name from system.columns where parent='$table'"); + if (!$recordSet) { + print $this->ErrorMsg(); + return false; + } else { + $i = 0; + while (!$recordSet->EOF) { + $arr["FIELD$i"] = $recordSet->fields[0]; + $recordSet->MoveNext(); + $i = $i + 1; + } + return $arr; + } + } + + + function Prepare($sql) + { + if (!$this->_bindInputArray) { + return $sql; + } // no binding + $stmt = ads_prepare($this->_connectionID, $sql); + if (!$stmt) { + // we don't know whether odbc driver is parsing prepared stmts, so just return sql + return $sql; + } + return array($sql, $stmt, false); + } + + /* returns queryID or false */ + function _query($sql, $inputarr = false) + { + $last_php_error = $this->resetLastError(); + $this->_errorMsg = ''; + + if ($inputarr) { + if (is_array($sql)) { + $stmtid = $sql[1]; + } else { + $stmtid = ads_prepare($this->_connectionID, $sql); + + if ($stmtid == false) { + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); + return false; + } + } + + if (!ads_execute($stmtid, $inputarr)) { + //@ads_free_result($stmtid); + $this->_errorMsg = ads_errormsg(); + $this->_errorCode = ads_error(); + return false; + } + + } else { + if (is_array($sql)) { + $stmtid = $sql[1]; + if (!ads_execute($stmtid)) { + //@ads_free_result($stmtid); + $this->_errorMsg = ads_errormsg(); + $this->_errorCode = ads_error(); + return false; + } + } else { + + $stmtid = ads_exec($this->_connectionID, $sql); + + } + } + + $this->_lastAffectedRows = 0; + + if ($stmtid) { + + if (@ads_num_fields($stmtid) == 0) { + $this->_lastAffectedRows = ads_num_rows($stmtid); + $stmtid = true; + + } else { + + $this->_lastAffectedRows = 0; + ads_binmode($stmtid, $this->binmode); + ads_longreadlen($stmtid, $this->maxblobsize); + + } + + $this->_errorMsg = ''; + $this->_errorCode = 0; + } else { + $this->_errorMsg = ads_errormsg(); + $this->_errorCode = ads_error(); + } + + return $stmtid; + + } + + /* + Insert a null into the blob field of the table first. + Then use UpdateBlob to store the blob. + + Usage: + + $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); + $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); + */ + function UpdateBlob($table, $column, $val, $where, $blobtype = 'BLOB') + { + $last_php_error = $this->resetLastError(); + $sql = "UPDATE $table SET $column=? WHERE $where"; + $stmtid = ads_prepare($this->_connectionID, $sql); + if ($stmtid == false) { + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); + return false; + } + if (!ads_execute($stmtid, array($val), array(SQL_BINARY))) { + $this->_errorMsg = ads_errormsg(); + $this->_errorCode = ads_error(); + return false; + } + return true; + } + + // returns true or false + function _close() + { + $ret = @ads_close($this->_connectionID); + $this->_connectionID = false; + return $ret; + } + + function _affectedrows() + { + return $this->_lastAffectedRows; + } } @@ -646,139 +677,142 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/od Class Name: Recordset --------------------------------------------------------------------------------------*/ -class ADORecordSet_ads extends ADORecordSet { - - var $bind = false; - var $databaseType = "ads"; - var $dataProvider = "ads"; - var $useFetchArray; - var $_has_stupid_odbc_fetch_api_change; - - function __construct($id,$mode=false) - { - if ($mode === false) { - global $ADODB_FETCH_MODE; - $mode = $ADODB_FETCH_MODE; - } - $this->fetchMode = $mode; - - $this->_queryID = $id; - - // the following is required for mysql odbc driver in 4.3.1 -- why? - $this->EOF = false; - $this->_currentRow = -1; - //parent::__construct($id); - } - - - // returns the field object - function &FetchField($fieldOffset = -1) - { - - $off=$fieldOffset+1; // offsets begin at 1 - - $o= new ADOFieldObject(); - $o->name = @ads_field_name($this->_queryID,$off); - $o->type = @ads_field_type($this->_queryID,$off); - $o->max_length = @ads_field_len($this->_queryID,$off); - if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name); - else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name); - return $o; - } - - /* Use associative array to get fields array */ - function Fields($colname) - { - if ($this->fetchMode & ADODB_FETCH_ASSOC) 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 _initrs() - { - global $ADODB_COUNTRECS; - $this->_numOfRows = ($ADODB_COUNTRECS) ? @ads_num_rows($this->_queryID) : -1; - $this->_numOfFields = @ads_num_fields($this->_queryID); - // some silly drivers such as db2 as/400 and intersystems cache return _numOfRows = 0 - if ($this->_numOfRows == 0) $this->_numOfRows = -1; - //$this->useFetchArray = $this->connection->useFetchArray; - $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200; - } - - function _seek($row) - { - return false; - } - - // speed up SelectLimit() by switching to ADODB_FETCH_NUM as ADODB_FETCH_ASSOC is emulated - function &GetArrayLimit($nrows,$offset=-1) - { - if ($offset <= 0) { - $rs =& $this->GetArray($nrows); - return $rs; - } - $savem = $this->fetchMode; - $this->fetchMode = ADODB_FETCH_NUM; - $this->Move($offset); - $this->fetchMode = $savem; - - if ($this->fetchMode & ADODB_FETCH_ASSOC) { - $this->fields =& $this->GetRowAssoc(); - } - - $results = array(); - $cnt = 0; - while (!$this->EOF && $nrows != $cnt) { - $results[$cnt++] = $this->fields; - $this->MoveNext(); - } - - return $results; - } - - - function MoveNext() - { - if ($this->_numOfRows != 0 && !$this->EOF) { - $this->_currentRow++; - if( $this->_fetch() ) { - return true; - } - } - $this->fields = false; - $this->EOF = true; - return false; - } - - function _fetch() - { - $this->fields = false; - if ($this->_has_stupid_odbc_fetch_api_change) - $rez = @ads_fetch_into($this->_queryID,$this->fields); - else { - $row = 0; - $rez = @ads_fetch_into($this->_queryID,$row,$this->fields); - } - if ($rez) { - if ($this->fetchMode & ADODB_FETCH_ASSOC) { - $this->fields =& $this->GetRowAssoc(); - } - return true; - } - return false; - } - - function _close() - { - return @ads_free_result($this->_queryID); - } +class ADORecordSet_ads extends ADORecordSet +{ + + var $bind = false; + var $databaseType = "ads"; + var $dataProvider = "ads"; + var $useFetchArray; + + function __construct($id, $mode = false) + { + if ($mode === false) { + global $ADODB_FETCH_MODE; + $mode = $ADODB_FETCH_MODE; + } + $this->fetchMode = $mode; + + $this->_queryID = $id; + + // the following is required for mysql odbc driver in 4.3.1 -- why? + $this->EOF = false; + $this->_currentRow = -1; + //parent::__construct($id); + } + + + // returns the field object + function &FetchField($fieldOffset = -1) + { + + $off = $fieldOffset + 1; // offsets begin at 1 + + $o = new ADOFieldObject(); + $o->name = @ads_field_name($this->_queryID, $off); + $o->type = @ads_field_type($this->_queryID, $off); + $o->max_length = @ads_field_len($this->_queryID, $off); + if (ADODB_ASSOC_CASE == 0) { + $o->name = strtolower($o->name); + } else { + if (ADODB_ASSOC_CASE == 1) { + $o->name = strtoupper($o->name); + } + } + return $o; + } + + /* Use associative array to get fields array */ + function Fields($colname) + { + if ($this->fetchMode & ADODB_FETCH_ASSOC) { + 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 _initrs() + { + global $ADODB_COUNTRECS; + $this->_numOfRows = ($ADODB_COUNTRECS) ? @ads_num_rows($this->_queryID) : -1; + $this->_numOfFields = @ads_num_fields($this->_queryID); + // some silly drivers such as db2 as/400 and intersystems cache return _numOfRows = 0 + if ($this->_numOfRows == 0) { + $this->_numOfRows = -1; + } + //$this->useFetchArray = $this->connection->useFetchArray; + } + + function _seek($row) + { + return false; + } + + // speed up SelectLimit() by switching to ADODB_FETCH_NUM as ADODB_FETCH_ASSOC is emulated + function &GetArrayLimit($nrows, $offset = -1) + { + if ($offset <= 0) { + $rs =& $this->GetArray($nrows); + return $rs; + } + $savem = $this->fetchMode; + $this->fetchMode = ADODB_FETCH_NUM; + $this->Move($offset); + $this->fetchMode = $savem; + + if ($this->fetchMode & ADODB_FETCH_ASSOC) { + $this->fields =& $this->GetRowAssoc(); + } + + $results = array(); + $cnt = 0; + while (!$this->EOF && $nrows != $cnt) { + $results[$cnt++] = $this->fields; + $this->MoveNext(); + } + + return $results; + } + + + function MoveNext() + { + if ($this->_numOfRows != 0 && !$this->EOF) { + $this->_currentRow++; + if ($this->_fetch()) { + return true; + } + } + $this->fields = false; + $this->EOF = true; + return false; + } + + function _fetch() + { + $this->fields = false; + $rez = @ads_fetch_into($this->_queryID, $this->fields); + if ($rez) { + if ($this->fetchMode & ADODB_FETCH_ASSOC) { + $this->fields =& $this->GetRowAssoc(); + } + return true; + } + return false; + } + + function _close() + { + return @ads_free_result($this->_queryID); + } } diff --git a/libraries/adodb/drivers/adodb-borland_ibase.inc.php b/libraries/adodb/drivers/adodb-borland_ibase.inc.php index d3de2caa1..da2c76186 100644 --- a/libraries/adodb/drivers/adodb-borland_ibase.inc.php +++ b/libraries/adodb/drivers/adodb-borland_ibase.inc.php @@ -1,18 +1,25 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. -Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Support Borland Interbase 6.5 and later - -*/ +/** + * Borland Interbase driver. + * + * Support Borland Interbase 6.5 and later + * + * 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(); @@ -53,6 +60,8 @@ class ADODB_borland_ibase extends ADODB_ibase { // SELECT FIRST 5 SKIP 2 col1, col2 FROM TABLE function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) { + $nrows = (int) $nrows; + $offset = (int) $offset; if ($nrows > 0) { if ($offset <= 0) $str = " ROWS $nrows "; else { @@ -80,8 +89,4 @@ class ADORecordSet_borland_ibase extends ADORecordSet_ibase { var $databaseType = "borland_ibase"; - function __construct($id,$mode=false) - { - parent::__construct($id,$mode); - } } diff --git a/libraries/adodb/drivers/adodb-csv.inc.php b/libraries/adodb/drivers/adodb-csv.inc.php index fd47784de..8a59626e1 100644 --- a/libraries/adodb/drivers/adodb-csv.inc.php +++ b/libraries/adodb/drivers/adodb-csv.inc.php @@ -1,21 +1,30 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4. - - Currently unsupported: MetaDatabases, MetaTables and MetaColumns, and also inputarr in Execute. - Native types have been converted to MetaTypes. - Transactions not supported yet. - - Limitation of url length. For IIS, see MaxClientRequestBuffer registry value. - - http://support.microsoft.com/default.aspx?scid=kb;en-us;260694 -*/ +/** + * FileDescription + * + * Currently unsupported: MetaDatabases, MetaTables and MetaColumns, + * and also inputarr in Execute. + * Native types have been converted to MetaTypes. + * Transactions not supported yet. + * + * Limitation of url length. For IIS, see MaxClientRequestBuffer registry value. + * + * 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(); @@ -38,18 +47,14 @@ class ADODB_csv extends ADOConnection { var $hasTransactions = false; var $_errorNo = false; - function __construct() + protected function _insertID($table = '', $column = '') { - } - - function _insertid() - { - return $this->_insertid; + return $this->_insertid; } function _affectedrows() { - return $this->_affectedrows; + return $this->_affectedrows; } function MetaDatabases() @@ -83,8 +88,10 @@ class ADODB_csv extends ADOConnection { // parameters use PostgreSQL convention, not MySQL function SelectLimit($sql, $nrows = -1, $offset = -1, $inputarr = false, $secs2cache = 0) { - global $ADODB_FETCH_MODE; + global $ADODB_FETCH_MODE; + $nrows = (int) $nrows; + $offset = (int) $offset; $url = $this->_url.'?sql='.urlencode($sql)."&nrows=$nrows&fetch=". (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE). "&offset=$offset"; @@ -176,7 +183,7 @@ class ADODB_csv extends ADOConnection { /* Returns: the last error message from previous database operation */ function ErrorMsg() { - return $this->_errorMsg; + return $this->_errorMsg; } /* Returns: the last error number from previous database operation */ @@ -193,10 +200,6 @@ class ADODB_csv extends ADOConnection { } // class class ADORecordset_csv extends ADORecordset { - function __construct($id,$mode=false) - { - parent::__construct($id,$mode); - } function _close() { diff --git a/libraries/adodb/drivers/adodb-db2.inc.php b/libraries/adodb/drivers/adodb-db2.inc.php index e7b9dbdd7..8f616fa6f 100644 --- a/libraries/adodb/drivers/adodb-db2.inc.php +++ b/libraries/adodb/drivers/adodb-db2.inc.php @@ -1,32 +1,40 @@ <?php /** - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - - This is a version of the ADODB driver for DB2. It uses the 'ibm_db2' PECL extension - for PHP (http://pecl.php.net/package/ibm_db2), which in turn requires DB2 V8.2.2 or - higher. - - Originally tested with PHP 5.1.1 and Apache 2.0.55 on Windows XP SP2. - More recently tested with PHP 5.1.2 and Apache 2.0.55 on Windows XP SP2. - - This file was ported from "adodb-odbc.inc.php" by Larry Menard, "larry.menard#rogers.com". - I ripped out what I believed to be a lot of redundant or obsolete code, but there are - probably still some remnants of the ODBC support in this file; I'm relying on reviewers - of this code to point out any other things that can be removed. -*/ + * IBM DB2 Native Client driver. + * + * Originally DB2 drivers were dependent on an ODBC driver, and some installations + * may still use that. To use an ODBC driver connection, use the odbc_db2 + * ADOdb driver. For Linux, you need the 'ibm_db2' PECL extension for PHP, + * For Windows, you need to locate an appropriate version of the php_ibm_db2.dll, + * as well as the IBM data server client software. + * This is basically a full rewrite of the original driver, for information + * about all the changes, see the update information on the ADOdb website + * for version 5.21.0. + * + * @link http://pecl.php.net/package/ibm_db2 PECL Extension For DB2 + * + * 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 Mark Newnham + */ // security - hide paths if (!defined('ADODB_DIR')) die(); - define("_ADODB_DB2_LAYER", 2 ); - -/*-------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------*/ - - - +define("_ADODB_DB2_LAYER", 2 ); class ADODB_db2 extends ADOConnection { @@ -45,108 +53,375 @@ class ADODB_db2 extends ADOConnection { var $binmode = DB2_BINARY; - var $useFetchArray = false; // setting this to true will make array elements in FETCH_ASSOC mode case-sensitive - // breaking backward-compat - var $_bindInputArray = false; + /* + * setting this to true will make array elements in FETCH_ASSOC + * mode case-sensitive breaking backward-compat + */ + var $useFetchArray = false; + var $_bindInputArray = true; var $_genIDSQL = "VALUES NEXTVAL FOR %s"; - var $_genSeqSQL = "CREATE SEQUENCE %s START WITH %s NO MAXVALUE NO CYCLE"; + var $_genSeqSQL = " + CREATE SEQUENCE %s START WITH %s + NO MAXVALUE NO CYCLE INCREMENT BY 1 NO CACHE + "; var $_dropSeqSQL = "DROP SEQUENCE %s"; var $_autocommit = true; - var $_haserrorfunctions = true; var $_lastAffectedRows = 0; - var $uCaseTables = true; // for meta* functions, uppercase table names var $hasInsertID = true; + var $hasGenID = true; + + /* + * Character used to wrap column and table names for escaping special + * characters in column and table names as well as forcing upper and + * lower case + */ + public $nameQuote = '"'; + /* + * Executed after successful connection + */ + public $connectStmt = ''; + + /* + * Holds the current database name + */ + private $databaseName = ''; + + /* + * Holds information about the stored procedure request + * currently being built + */ + private $storedProcedureParameters = false; + + + function __construct() {} - function _insertid() - { - return ADOConnection::GetOne('VALUES IDENTITY_VAL_LOCAL()'); - } + protected function _insertID($table = '', $column = '') + { + return ADOConnection::GetOne('VALUES IDENTITY_VAL_LOCAL()'); + } - function __construct() + public function _connect($argDSN, $argUsername, $argPassword, $argDatabasename) { - $this->_haserrorfunctions = ADODB_PHPVER >= 0x4050; + return $this->doDB2Connect($argDSN, $argUsername, $argPassword, $argDatabasename); } - // returns true or false - function _connect($argDSN, $argUsername, $argPassword, $argDatabasename) + public function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename) + { + return $this->doDB2Connect($argDSN, $argUsername, $argPassword, $argDatabasename,true); + } + + private function doDB2Connect($argDSN, $argUsername, $argPassword, $argDatabasename, $persistent=false) { global $php_errormsg; if (!function_exists('db2_connect')) { - ADOConnection::outp("Warning: The old ODBC based DB2 driver has been renamed 'odbc_db2'. This ADOdb driver calls PHP's native db2 extension which is not installed."); + ADOConnection::outp("DB2 extension not installed."); return null; } - // This needs to be set before the connect(). - // Replaces the odbc_binmode() call that was in Execute() + + $connectionParameters = $this->unpackParameters($argDSN, + $argUsername, + $argPassword, + $argDatabasename); + + if ($connectionParameters == null) + { + /* + * Error thrown + */ + return null; + } + + $argDSN = $connectionParameters['dsn']; + $argUsername = $connectionParameters['uid']; + $argPassword = $connectionParameters['pwd']; + $argDatabasename = $connectionParameters['database']; + $useCataloguedConnection = $connectionParameters['catalogue']; + + if ($this->debug){ + if ($useCataloguedConnection){ + $connectMessage = "Catalogued connection using parameters: "; + $connectMessage .= "DB=$argDatabasename / "; + $connectMessage .= "UID=$argUsername / "; + $connectMessage .= "PWD=$argPassword"; + } + else + { + $connectMessage = "Uncatalogued connection using DSN: $argDSN"; + } + ADOConnection::outp($connectMessage); + } + /* + * This needs to be set before the connect(). + */ ini_set('ibm_db2.binmode', $this->binmode); - if ($argDatabasename && empty($argDSN)) { + if ($persistent) + $db2Function = 'db2_pconnect'; + else + $db2Function = 'db2_connect'; - if (stripos($argDatabasename,'UID=') && stripos($argDatabasename,'PWD=')) $this->_connectionID = db2_connect($argDatabasename,null,null); - else $this->_connectionID = db2_connect($argDatabasename,$argUsername,$argPassword); - } else { - if ($argDatabasename) $schema = $argDatabasename; - if (stripos($argDSN,'UID=') && stripos($argDSN,'PWD=')) $this->_connectionID = db2_connect($argDSN,null,null); - else $this->_connectionID = db2_connect($argDSN,$argUsername,$argPassword); + /* + * We need to flatten out the connectionParameters + */ + + $db2Options = array(); + if ($this->connectionParameters) + { + foreach($this->connectionParameters as $p) + foreach($p as $k=>$v) + $db2Options[$k] = $v; } - if (isset($php_errormsg)) $php_errormsg = ''; - // For db2_connect(), there is an optional 4th arg. If present, it must be - // an array of valid options. So far, we don't use them. + if ($useCataloguedConnection) + $this->_connectionID = $db2Function($argDatabasename, + $argUsername, + $argPassword, + $db2Options); + else + $this->_connectionID = $db2Function($argDSN, + null, + null, + $db2Options); + + $php_errormsg = ''; $this->_errorMsg = @db2_conn_errormsg(); - if (isset($this->connectStmt)) $this->Execute($this->connectStmt); - if ($this->_connectionID && isset($schema)) $this->Execute("SET SCHEMA=$schema"); + if ($this->_connectionID && $this->connectStmt) + $this->execute($this->connectStmt); + return $this->_connectionID != false; + } - // returns true or false - function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename) + /** + * Validates and preprocesses the passed parameters for consistency + * + * @param string $argDSN Either DSN or database + * @param string $argUsername User name or null + * @param string $argPassword Password or null + * @param string $argDatabasename Either DSN or database + * + * @return mixed array if correct, null if not + */ + private function unpackParameters($argDSN, $argUsername, $argPassword, $argDatabasename) { + global $php_errormsg; - if (!function_exists('db2_connect')) return null; + $connectionParameters = array('dsn'=>'', + 'uid'=>'', + 'pwd'=>'', + 'database'=>'', + 'catalogue'=>true + ); - // This needs to be set before the connect(). - // Replaces the odbc_binmode() call that was in Execute() - ini_set('ibm_db2.binmode', $this->binmode); + /* + * Uou can either connect to a catalogued connection + * with a database name e.g. 'SAMPLE' + * or an uncatalogued connection with a DSN like connection + * DATABASE=database;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=username;PWD=password; + */ + + if (!$argDSN && !$argDatabasename) + { + $errorMessage = 'Supply either catalogued or uncatalogued connection parameters'; + $this->_errorMsg = $errorMessage; + if ($this->debug) + ADOConnection::outp($errorMessage); + return null; + } - if (isset($php_errormsg)) $php_errormsg = ''; - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; + $useCataloguedConnection = true; + $schemaName = ''; + + if ($argDSN && $argDatabasename) + { + /* + * If a catalogued connection if provided, + * as well as user and password + * that will take priority + */ + if ($argUsername && $argPassword && !$this->isDsn($argDatabasename)) + { + if ($this->debug){ + $errorMessage = 'Warning: Because you provided user,'; + $errorMessage.= 'password and database, DSN connection '; + $errorMessage.= 'parameters were discarded'; + ADOConnection::outp($errorMessage); - if ($argDatabasename && empty($argDSN)) { + } + $argDSN = ''; + } + else if ($this->isDsn($argDSN) && $this->isDsn($argDatabasename)) + { + $errorMessage = 'Supply uncatalogued connection parameters '; + $errorMessage.= 'in either the database or DSN arguments, '; + $errorMessage.= 'but not both'; + $php_errormsg = $errorMessage; + if ($this->debug) + ADOConnection::outp($errorMessage); + return null; + } + } - if (stripos($argDatabasename,'UID=') && stripos($argDatabasename,'PWD=')) $this->_connectionID = db2_pconnect($argDatabasename,null,null); - else $this->_connectionID = db2_pconnect($argDatabasename,$argUsername,$argPassword); - } else { - if ($argDatabasename) $schema = $argDatabasename; - if (stripos($argDSN,'UID=') && stripos($argDSN,'PWD=')) $this->_connectionID = db2_pconnect($argDSN,null,null); - else $this->_connectionID = db2_pconnect($argDSN,$argUsername,$argPassword); + if (!$this->isDsn($argDSN) && $this->isDsn($argDatabasename)) + { + /* + * Switch them around for next test + */ + $temp = $argDSN; + $argDsn = $argDatabasename; + $argDatabasenME = $temp; } - if (isset($php_errormsg)) $php_errormsg = ''; - $this->_errorMsg = @db2_conn_errormsg(); - if ($this->_connectionID && $this->autoRollback) @db2_rollback($this->_connectionID); - if (isset($this->connectStmt)) $this->Execute($this->connectStmt); + if ($this->isDsn($argDSN)) + { + + if (!preg_match('/uid=/i',$argDSN) + || !preg_match('/pwd=/i',$argDSN)) + { + $errorMessage = 'For uncatalogued connections, provide '; + $errorMessage.= 'both UID and PWD in the connection string'; + $php_errormsg = $errorMessage; + if ($this->debug) + ADOConnection::outp($errorMessage); + return null; + } + + if (preg_match('/database=/i',$argDSN)) + { + if ($argDatabasename) + { + $argDatabasename = ''; + if ($this->debug) + { + $errorMessage = 'Warning: Because you provided '; + $errorMessage.= 'database information in the DSN '; + $errorMessage.= 'parameters, the supplied database '; + $errorMessage.= 'name was discarded'; + ADOConnection::outp($errorMessage); + } + } + $useCataloguedConnection = false; + + } + elseif ($argDatabasename) + { + $this->databaseName = $argDatabasename; + $argDSN .= ';database=' . $argDatabasename; + $argDatabasename = ''; + $useCataloguedConnection = false; + + } + else + { + $errorMessage = 'Uncatalogued connection parameters '; + $errorMessage.= 'must contain a database= argument'; + $php_errormsg = $errorMessage; + if ($this->debug) + ADOConnection::outp($errorMessage); + return null; + } + } + + if ($argDSN && !$argDatabasename && $useCataloguedConnection) + { + $argDatabasename = $argDSN; + $argDSN = ''; + } + + + if ($useCataloguedConnection + && (!$argDatabasename + || !$argUsername + || !$argPassword)) + { + + $errorMessage = 'For catalogued connections, provide '; + $errorMessage.= 'database, username and password'; + $this->_errorMsg = $errorMessage; + if ($this->debug) + ADOConnection::outp($errorMessage); + return null; + + } + + if ($argDatabasename) + $this->databaseName = $argDatabasename; + elseif (!$this->databaseName) + $this->databaseName = $this->getDatabasenameFromDsn($argDSN); + + + $connectionParameters = array('dsn'=>$argDSN, + 'uid'=>$argUsername, + 'pwd'=>$argPassword, + 'database'=>$argDatabasename, + 'catalogue'=>$useCataloguedConnection + ); + + return $connectionParameters; - if ($this->_connectionID && isset($schema)) $this->Execute("SET SCHEMA=$schema"); - return $this->_connectionID != false; } - // format and return date string in database timestamp format - function DBTimeStamp($ts, $isfld = false) + /** + * Does the provided string look like a DSN + * + * @param string $dsnString + * + * @return bool + */ + private function isDsn($dsnString){ + $dsnArray = preg_split('/[;=]+/',$dsnString); + if (count($dsnArray) > 2) + return true; + return false; + } + + + /** + * Gets the database name from the DSN + * + * @param string $dsnString + * + * @return string + */ + private function getDatabasenameFromDsn($dsnString){ + + $dsnArray = preg_split('/[;=]+/',$dsnString); + $dbIndex = array_search('database',$dsnArray); + + return $dsnArray[$dbIndex + 1]; + } + + + /** + * format and return date string in database timestamp format + * + * @param mixed $ts either a string or a unixtime + * @param bool $isField discarded + * + * @return string + */ + function dbTimeStamp($ts,$isField=false) { if (empty($ts) && $ts !== 0) return 'null'; - if (is_string($ts)) $ts = ADORecordSet::UnixTimeStamp($ts); + if (is_string($ts)) $ts = ADORecordSet::unixTimeStamp($ts); return 'TO_DATE('.adodb_date($this->fmtTimeStamp,$ts).",'YYYY-MM-DD HH24:MI:SS')"; } - // Format date column in sql string given an input format that understands Y M D - function SQLDate($fmt, $col=false) + /** + * Format date column in sql string given an input format that understands Y M D + * + * @param string $fmt + * @param bool $col + * + * @return string + */ + function sqlDate($fmt, $col=false) { - // use right() and replace() ? if (!$col) $col = $this->sysDate; /* use TO_CHAR() if $fmt is TO_CHAR() allowed fmt */ @@ -210,10 +485,12 @@ class ADODB_db2 extends ADOConnection { } - function ServerInfo() + function serverInfo() { - $row = $this->GetRow("SELECT service_level, fixpack_num FROM TABLE(sysproc.env_get_inst_info()) - as INSTANCEINFO"); + $sql = "SELECT service_level, fixpack_num + FROM TABLE(sysproc.env_get_inst_info()) + AS INSTANCEINFO"; + $row = $this->GetRow($sql); if ($row) { @@ -221,107 +498,119 @@ class ADODB_db2 extends ADOConnection { $info['fixpack'] = $row[1]; $info['description'] = ''; } else { - return ADOConnection::ServerInfo(); + return ADOConnection::serverInfo(); } return $info; } - function CreateSequence($seqname='adodbseq',$start=1) + function createSequence($seqname='adodbseq',$start=1) { - if (empty($this->_genSeqSQL)) return false; - $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname,$start)); - if (!$ok) return false; + if (empty($this->_genSeqSQL)) + return false; + + $ok = $this->execute(sprintf($this->_genSeqSQL,$seqname,$start)); + if (!$ok) + return false; return true; } - function DropSequence($seqname = 'adodbseq') + function dropSequence($seqname='adodbseq') { if (empty($this->_dropSeqSQL)) return false; - return $this->Execute(sprintf($this->_dropSeqSQL,$seqname)); + return $this->execute(sprintf($this->_dropSeqSQL,$seqname)); } - function SelectLimit($sql, $nrows = -1, $offset = -1, $inputArr = false, $secs2cache = 0) + function selectLimit($sql,$nrows=-1,$offset=-1,$inputArr=false,$secs2cache=0) { $nrows = (integer) $nrows; - if ($offset <= 0) { - // could also use " OPTIMIZE FOR $nrows ROWS " - if ($nrows >= 0) $sql .= " FETCH FIRST $nrows ROWS ONLY "; - $rs = $this->Execute($sql,$inputArr); - } else { + + if ($offset <= 0) + { + if ($nrows >= 0) + $sql .= " FETCH FIRST $nrows ROWS ONLY "; + + $rs = $this->execute($sql,$inputArr); + + } + else + { if ($offset > 0 && $nrows < 0); - else { + + else + { $nrows += $offset; $sql .= " FETCH FIRST $nrows ROWS ONLY "; } - $rs = ADOConnection::SelectLimit($sql,-1,$offset,$inputArr); + + /* + * DB2 has no native support for mid table offset + */ + $rs = ADOConnection::selectLimit($sql,$nrows,$offset,$inputArr); + } return $rs; } - /* - This algorithm is not very efficient, but works even if table locking - is not available. - Will return false if unable to generate an ID after $MAXLOOPS attempts. - */ - function GenID($seq='adodbseq',$start=1) + function errorMsg() { - // if you have to modify the parameter below, your database is overloaded, - // or you need to implement generation of id's yourself! - $num = $this->GetOne("VALUES NEXTVAL FOR $seq"); - return $num; - } + if ($this->_errorMsg !== false) + return $this->_errorMsg; + if (empty($this->_connectionID)) + return @db2_conn_errormsg(); - function ErrorMsg() - { - if ($this->_haserrorfunctions) { - if ($this->_errorMsg !== false) return $this->_errorMsg; - if (empty($this->_connectionID)) return @db2_conn_errormsg(); - return @db2_conn_errormsg($this->_connectionID); - } else return ADOConnection::ErrorMsg(); + return @db2_conn_errormsg($this->_connectionID); } - function ErrorNo() + function errorNo() { - if ($this->_haserrorfunctions) { - if ($this->_errorCode !== false) { - // bug in 4.0.6, error number can be corrupted string (should be 6 digits) - return (strlen($this->_errorCode)<=2) ? 0 : $this->_errorCode; - } + if ($this->_errorCode !== false) + return $this->_errorCode; + - if (empty($this->_connectionID)) $e = @db2_conn_error(); - else $e = @db2_conn_error($this->_connectionID); + if (empty($this->_connectionID)) + $e = @db2_conn_error(); - // bug in 4.0.6, error number can be corrupted string (should be 6 digits) - // so we check and patch - if (strlen($e)<=2) return 0; - return $e; - } else return ADOConnection::ErrorNo(); + else + $e = @db2_conn_error($this->_connectionID); + + return $e; } - function BeginTrans() + function beginTrans() { - if (!$this->hasTransactions) return false; - if ($this->transOff) return true; + if (!$this->hasTransactions) + return false; + if ($this->transOff) + return true; + $this->transCnt += 1; + $this->_autocommit = false; + return db2_autocommit($this->_connectionID,false); } function CommitTrans($ok=true) { - if ($this->transOff) return true; - if (!$ok) return $this->RollbackTrans(); - if ($this->transCnt) $this->transCnt -= 1; + if ($this->transOff) + return true; + + if (!$ok) + return $this->RollbackTrans(); + + if ($this->transCnt) + $this->transCnt -= 1; + $this->_autocommit = true; - $ret = db2_commit($this->_connectionID); - db2_autocommit($this->_connectionID,true); + $ret = @db2_commit($this->_connectionID); + @db2_autocommit($this->_connectionID,true); return $ret; } @@ -330,124 +619,401 @@ class ADODB_db2 extends ADOConnection { if ($this->transOff) return true; if ($this->transCnt) $this->transCnt -= 1; $this->_autocommit = true; - $ret = db2_rollback($this->_connectionID); - db2_autocommit($this->_connectionID,true); + $ret = @db2_rollback($this->_connectionID); + @db2_autocommit($this->_connectionID,true); return $ret; } - function MetaPrimaryKeys($table, $owner = false) + /** + * Return a list of Primary Keys for a specified table + * + * We don't use db2_statistics as the function does not seem to play + * well with mixed case table names + * + * @param string $table + * @param bool $primary (optional) only return primary keys + * @param bool $owner (optional) not used in this driver + * + * @return string[] Array of indexes + */ + public function metaPrimaryKeys($table,$owner=false) { - global $ADODB_FETCH_MODE; - if ($this->uCaseTables) $table = strtoupper($table); + $primaryKeys = array(); + + global $ADODB_FETCH_MODE; + $schema = ''; $this->_findschema($table,$schema); - $savem = $ADODB_FETCH_MODE; + $table = $this->getTableCasedValue($table); + + $savem = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $qid = @db2_primarykeys($this->_connectionID,'',$schema,$table); + $this->setFetchMode(ADODB_FETCH_NUM); - if (!$qid) { - $ADODB_FETCH_MODE = $savem; - return false; - } - $rs = new ADORecordSet_db2($qid); + + $sql = "SELECT * + FROM syscat.indexes + WHERE tabname='$table'"; + + $rows = $this->getAll($sql); + + $this->setFetchMode($savem); $ADODB_FETCH_MODE = $savem; - if (!$rs) return false; + if (empty($rows)) + return false; - $arr = $rs->GetArray(); - $rs->Close(); - $arr2 = array(); - for ($i=0; $i < sizeof($arr); $i++) { - if ($arr[$i][3]) $arr2[] = $arr[$i][3]; + foreach ($rows as $r) + { + if ($r[7] != 'P') + continue; + + $cols = explode('+',$r[6]); + foreach ($cols as $colIndex=>$col) + { + if ($colIndex == 0) + continue; + $columnName = $this->getMetaCasedValue($col); + $primaryKeys[] = $columnName; + } + break; } - return $arr2; + return $primaryKeys; } - function MetaForeignKeys($table, $owner = FALSE, $upper = FALSE, $asociative = FALSE ) + /** + * returns assoc array where keys are tables, and values are foreign keys + * + * @param string $table + * @param string $owner [optional][discarded] + * @param bool $upper [optional][discarded] + * @param bool $associative[optional][discarded] + * + * @return mixed[] Array of foreign key information + */ + public function metaForeignKeys($table, $owner = FALSE, $upper = FALSE, $asociative = FALSE ) { - global $ADODB_FETCH_MODE; - if ($this->uCaseTables) $table = strtoupper($table); + global $ADODB_FETCH_MODE; + $schema = ''; $this->_findschema($table,$schema); $savem = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $qid = @db2_foreign_keys($this->_connectionID,'',$schema,$table); - if (!$qid) { - $ADODB_FETCH_MODE = $savem; + + $this->setFetchMode(ADODB_FETCH_NUM); + + $sql = "SELECT SUBSTR(tabname,1,20) table_name, + SUBSTR(constname,1,20) fk_name, + SUBSTR(REFTABNAME,1,12) parent_table, + SUBSTR(refkeyname,1,20) pk_orig_table, + fk_colnames + FROM syscat.references + WHERE tabname = '$table'"; + + $results = $this->getAll($sql); + + $ADODB_FETCH_MODE = $savem; + $this->setFetchMode($savem); + + if (empty($results)) return false; + + $foreignKeys = array(); + + foreach ($results as $r) + { + $parentTable = trim($this->getMetaCasedValue($r[2])); + $keyName = trim($this->getMetaCasedValue($r[1])); + $foreignKeys[$parentTable] = $keyName; } + + return $foreignKeys; + } + + /** + * Returns a list of tables + * + * @param string $ttype (optional) + * @param string $schema (optional) + * @param string $mask (optional) + * + * @return array + */ + public function metaTables($ttype=false,$schema=false,$mask=false) + { + + global $ADODB_FETCH_MODE; + + $savem = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + + /* + * Values for TABLE_TYPE + * --------------------------- + * ALIAS, HIERARCHY TABLE, INOPERATIVE VIEW, NICKNAME, + * MATERIALIZED QUERY TABLE, SYSTEM TABLE, TABLE, + * TYPED TABLE, TYPED VIEW, and VIEW + * + * If $ttype passed as '', match 'TABLE' and 'VIEW' + * If $ttype passed as 'T' it is assumed to be 'TABLE' + * if $ttype passed as 'V' it is assumed to be 'VIEW' + */ + $ttype = strtoupper($ttype); + if ($ttype) { + /* + * @todo We could do valid type checking or array type + */ + if ($ttype == 'V') + $ttype = 'VIEW'; + if ($ttype == 'T') + $ttype = 'TABLE'; + } + + if (!$schema) + $schema = '%'; + + if (!$mask) + $mask = '%'; + + $qid = @db2_tables($this->_connectionID,NULL,$schema,$mask,$ttype); + $rs = new ADORecordSet_db2($qid); $ADODB_FETCH_MODE = $savem; + + if (!$rs) + return false; + + $arr = $rs->getArray(); + + $rs->Close(); + + $tableList = array(); + /* - $rs->fields indices - 0 PKTABLE_CAT - 1 PKTABLE_SCHEM - 2 PKTABLE_NAME - 3 PKCOLUMN_NAME - 4 FKTABLE_CAT - 5 FKTABLE_SCHEM - 6 FKTABLE_NAME - 7 FKCOLUMN_NAME + * Array items + * --------------------------------- + * 0 TABLE_CAT The catalog that contains the table. + * The value is NULL if this table does not have catalogs. + * 1 TABLE_SCHEM Name of the schema that contains the table. + * 2 TABLE_NAME Name of the table. + * 3 TABLE_TYPE Table type identifier for the table. + * 4 REMARKS Description of the table. */ - if (!$rs) return false; - $foreign_keys = array(); - while (!$rs->EOF) { - if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) { - if (!is_array($foreign_keys[$rs->fields[5].'.'.$rs->fields[6]])) - $foreign_keys[$rs->fields[5].'.'.$rs->fields[6]] = array(); - $foreign_keys[$rs->fields[5].'.'.$rs->fields[6]][$rs->fields[7]] = $rs->fields[3]; + for ($i=0; $i < sizeof($arr); $i++) + { + + $tableRow = $arr[$i]; + $tableName = $tableRow[2]; + $tableType = $tableRow[3]; + + if (!$tableName) + continue; + + if ($ttype == '' && (strcmp($tableType,'TABLE') <> 0 && strcmp($tableType,'VIEW') <> 0)) + continue; + + /* + * Set metacasing if required + */ + $tableName = $this->getMetaCasedValue($tableName); + + /* + * If we requested a schema, we prepend the schema + name to the table name + */ + if (strcmp($schema,'%') <> 0) + $tableName = $schema . '.' . $tableName; + + $tableList[] = $tableName; + + } + return $tableList; + } + + /** + * Return a list of indexes for a specified table + * + * We don't use db2_statistics as the function does not seem to play + * well with mixed case table names + * + * @param string $table + * @param bool $primary (optional) only return primary keys + * @param bool $owner (optional) not used in this driver + * + * @return string[] Array of indexes + */ + public function metaIndexes($table, $primary = false, $owner = false) { + + global $ADODB_FETCH_MODE; + + /* Array( + * [name_of_index] => Array( + * [unique] => true or false + * [columns] => Array( + * [0] => firstcol + * [1] => nextcol + * [2] => etc........ + * ) + * ) + * ) + */ + $indices = array(); + $primaryKeyName = ''; + + $table = $this->getTableCasedValue($table); + + + $savem = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + $this->setFetchMode(ADODB_FETCH_NUM); + + $sql = "SELECT * + FROM syscat.indexes + WHERE tabname='$table'"; + + $rows = $this->getAll($sql); + + $this->setFetchMode($savem); + $ADODB_FETCH_MODE = $savem; + + if (empty($rows)) + return false; + + foreach ($rows as $r) + { + + $primaryIndex = $r[7] == 'P'?1:0; + if (!$primary) + /* + * Primary key not requested, ignore that one + */ + if ($r[7] == 'P') + continue; + + $indexName = $this->getMetaCasedValue($r[1]); + if (!isset($indices[$indexName])) + { + $unique = ($r[7] == 'U')?1:0; + $indices[$indexName] = array('unique'=>$unique, + 'primary'=>$primaryIndex, + 'columns'=>array() + ); } - $rs->MoveNext(); + $cols = explode('+',$r[6]); + foreach ($cols as $colIndex=>$col) + { + if ($colIndex == 0) + continue; + $columnName = $this->getMetaCasedValue($col); + $indices[$indexName]['columns'][] = $columnName; + } + } - $rs->Close(); - return $foreign_key; + return $indices; + } + /** + * List procedures or functions in an array. + * + * We interrogate syscat.routines instead of calling the PHP + * function procedures because ADOdb requires the type of procedure + * this is not available in the php function + * + * @param string $procedureNamePattern (optional) + * @param string $catalog (optional) + * @param string $schemaPattern (optional) - function MetaTables($ttype = false, $schema = false, $mask = false) - { - global $ADODB_FETCH_MODE; + * @return array of procedures on current database. + * + */ + public function metaProcedures($procedureNamePattern = null, $catalog = null, $schemaPattern = null) { - $savem = $ADODB_FETCH_MODE; + + global $ADODB_FETCH_MODE; + + $metaProcedures = array(); + $procedureSQL = ''; + $catalogSQL = ''; + $schemaSQL = ''; + + $savem = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $qid = db2_tables($this->_connectionID); - $rs = new ADORecordSet_db2($qid); + if ($procedureNamePattern) + $procedureSQL = "AND ROUTINENAME LIKE " . strtoupper($this->qstr($procedureNamePattern)); + + if ($catalog) + $catalogSQL = "AND OWNER=" . strtoupper($this->qstr($catalog)); + + if ($schemaPattern) + $schemaSQL = "AND ROUTINESCHEMA LIKE {$this->qstr($schemaPattern)}"; + + + $fields = " + ROUTINENAME, + CASE ROUTINETYPE + WHEN 'P' THEN 'PROCEDURE' + WHEN 'F' THEN 'FUNCTION' + ELSE 'METHOD' + END AS ROUTINETYPE_NAME, + ROUTINESCHEMA, + REMARKS"; + + $SQL = "SELECT $fields + FROM syscat.routines + WHERE OWNER IS NOT NULL + $procedureSQL + $catalogSQL + $schemaSQL + ORDER BY ROUTINENAME + "; + + $result = $this->execute($SQL); $ADODB_FETCH_MODE = $savem; - if (!$rs) { - $false = false; - return $false; - } - $arr = $rs->GetArray(); - $rs->Close(); - $arr2 = array(); + if (!$result) + return false; - if ($ttype) { - $isview = strncmp($ttype,'V',1) === 0; - } - for ($i=0; $i < sizeof($arr); $i++) { - if (!$arr[$i][2]) continue; - $type = $arr[$i][3]; - $owner = $arr[$i][1]; - $schemaval = ($schema) ? $arr[$i][1].'.' : ''; - if ($ttype) { - if ($isview) { - if (strncmp($type,'V',1) === 0) $arr2[] = $schemaval.$arr[$i][2]; - } else if (strncmp($owner,'SYS',3) !== 0) $arr2[] = $schemaval.$arr[$i][2]; - } else if (strncmp($owner,'SYS',3) !== 0) $arr2[] = $schemaval.$arr[$i][2]; + while ($r = $result->fetchRow()){ + $procedureName = $this->getMetaCasedValue($r[0]); + $schemaName = $this->getMetaCasedValue($r[2]); + $metaProcedures[$procedureName] = array('type'=> $r[1], + 'catalog' => '', + 'schema' => $schemaName, + 'remarks' => $r[3] + ); } - return $arr2; + + return $metaProcedures; + } + /** + * Lists databases. Because instances are independent, we only know about + * the current database name + * + * @return string[] + */ + public function metaDatabases(){ + + $dbName = $this->getMetaCasedValue($this->databaseName); + + return (array)$dbName; + + } + + + + /* See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/db2/htm/db2datetime_data_type_changes.asp / SQL data type codes / @@ -516,26 +1082,32 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/db2/htm/db2 } } - function MetaColumns($table, $normalize=true) + public function metaColumns($table, $normalize=true) { - global $ADODB_FETCH_MODE; - - $false = false; - if ($this->uCaseTables) $table = strtoupper($table); - $schema = ''; - $this->_findschema($table,$schema); + global $ADODB_FETCH_MODE; $savem = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $colname = "%"; - $qid = db2_columns($this->_connectionID, "", $schema, $table, $colname); - if (empty($qid)) return $false; + $schema = '%'; + $this->_findschema($table,$schema); + $table = $this->getTableCasedValue($table); + $colname = "%"; + $qid = db2_columns($this->_connectionID, null, $schema, $table, $colname); + if (empty($qid)) + { + if ($this->debug) + { + $errorMessage = @db2_conn_errormsg($this->_connectionID); + ADOConnection::outp($errorMessage); + } + return false; + } $rs = new ADORecordSet_db2($qid); - $ADODB_FETCH_MODE = $savem; - if (!$rs) return $false; + if (!$rs) + return false; + $rs->_fetch(); $retarr = array(); @@ -554,15 +1126,25 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/db2/htm/db2 9 RADIX 10 NULLABLE 11 REMARKS + 12 Column Default + 13 SQL Data Type + 14 SQL DateTime SubType + 15 Max length in Octets + 16 Ordinal Position + 17 Is NULLABLE */ - while (!$rs->EOF) { - if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) { - $fld = new ADOFieldObject(); + while (!$rs->EOF) + { + if ($rs->fields[2] == $table) + { + + $fld = new ADOFieldObject(); $fld->name = $rs->fields[3]; $fld->type = $this->DB2Types($rs->fields[4]); // ref: http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraccgen/html/msdn_odk.asp // access uses precision to store length for char/varchar + if ($fld->type == 'C' or $fld->type == 'X') { if ($rs->fields[4] <= -95) // UNICODE $fld->max_length = $rs->fields[7]/2; @@ -570,24 +1152,42 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/db2/htm/db2 $fld->max_length = $rs->fields[7]; } else $fld->max_length = $rs->fields[7]; - $fld->not_null = !empty($rs->fields[10]); - $fld->scale = $rs->fields[8]; - $fld->primary_key = false; - $retarr[strtoupper($fld->name)] = $fld; - } else if (sizeof($retarr)>0) + + $fld->not_null = !empty($rs->fields[10]); + $fld->scale = $rs->fields[8]; + $fld->primary_key = false; + + //$columnName = $this->getMetaCasedValue($fld->name); + $columnName = strtoupper($fld->name); + $retarr[$columnName] = $fld; + + } + else if (sizeof($retarr)>0) break; + $rs->MoveNext(); + } + $rs->Close(); - if (empty($retarr)) $retarr = false; + if (empty($retarr)) + $retarr = false; + + /* + * Now we find out if the column is part of a primary key + */ - $qid = db2_primary_keys($this->_connectionID, "", $schema, $table); - if (empty($qid)) return $false; + $qid = @db2_primary_keys($this->_connectionID, "", $schema, $table); + if (empty($qid)) + return false; $rs = new ADORecordSet_db2($qid); - $ADODB_FETCH_MODE = $savem; - if (!$rs) return $retarr; + if (!$rs) + { + $ADODB_FETCH_MODE = $savem; + return $retarr; + } $rs->_fetch(); /* @@ -600,23 +1200,371 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/db2/htm/db2 5 PK_NAME */ while (!$rs->EOF) { - if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) { + if (strtoupper(trim($rs->fields[2])) == $table + && (!$schema || strtoupper($rs->fields[1]) == $schema)) + { $retarr[strtoupper($rs->fields[3])]->primary_key = true; - } else if (sizeof($retarr)>0) + } + else if (sizeof($retarr)>0) break; + $rs->MoveNext(); } $rs->Close(); - if (empty($retarr)) $retarr = false; + $ADODB_FETCH_MODE = $savem; + + if (empty($retarr)) + return false; + + /* + * If the fetch mode is numeric, return as numeric array + */ + if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) + $retarr = array_values($retarr); + return $retarr; } + /** + * In this version if prepareSp, we just check to make sure + * that the name of the stored procedure is correct + * If true, we returns an array + * else false + * + * @param string $procedureName + * @param mixed $parameters (not used in db2 connections) + * @return mixed[] + */ + function prepareSp($procedureName,$parameters=false) { + + global $ADODB_FETCH_MODE; + + $this->storedProcedureParameters = array('name'=>'', + 'resource'=>false, + 'in'=>array(), + 'out'=>array(), + 'index'=>array(), + 'parameters'=>array(), + 'keyvalue' => array()); + + //$procedureName = strtoupper($procedureName); + //$procedureName = $this->getTableCasedValue($procedureName); + + $savem = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + + $qid = db2_procedures($this->_connectionID, NULL , '%' , $procedureName ); + + $ADODB_FETCH_MODE = $savem; + + if (!$qid) + { + if ($this->debug) + ADOConnection::outp(sprintf('No Procedure of name %s available',$procedureName)); + return false; + } + + + + $this->storedProcedureParameters['name'] = $procedureName; + /* + * Now we know we have a valid procedure name, lets see if it requires + * parameters + */ + $savem = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + + $qid = db2_procedure_columns($this->_connectionID, NULL , '%' , $procedureName , NULL ); + + $ADODB_FETCH_MODE = $savem; + + if (!$qid) + { + if ($this->debug) + ADOConnection::outp(sprintf('No columns of name %s available',$procedureName)); + return false; + } + $rs = new ADORecordSet_db2($qid); + if (!$rs) + return false; + + $preparedStatement = 'CALL %s(%s)'; + $parameterMarkers = array(); + while (!$rs->EOF) + { + $parameterName = $rs->fields[3]; + if ($parameterName == '') + { + $rs->moveNext(); + continue; + } + $parameterType = $rs->fields[4]; + $ordinalPosition = $rs->fields[17]; + switch($parameterType) + { + case DB2_PARAM_IN: + case DB2_PARAM_INOUT: + $this->storedProcedureParameters['in'][$parameterName] = ''; + break; + case DB2_PARAM_INOUT: + case DB2_PARAM_OUT: + $this->storedProcedureParameters['out'][$parameterName] = ''; + break; + } + $this->storedProcedureParameters['index'][$parameterName] = $ordinalPosition; + $this->storedProcedureParameters['parameters'][$ordinalPosition] = $rs->fields; + $rs->moveNext(); + + } + $parameterCount = count($this->storedProcedureParameters['index']); + $parameterMarkers = array_fill(0,$parameterCount,'?'); + + /* + * We now know how many parameters to bind to the stored procedure + */ + $parameterList = implode(',',$parameterMarkers); + + $sql = sprintf($preparedStatement,$procedureName,$parameterList); + + $spResource = @db2_prepare($this->_connectionID,$sql); + + if (!$spResource) + { + $errorMessage = @db2_conn_errormsg($this->_connectionID); + $this->_errorMsg = $errorMessage; + + if ($this->debug) + ADOConnection::outp($errorMessage); + + return false; + } + + $this->storedProcedureParameters['resource'] = $spResource; + + if ($this->debug) + { + + ADOConnection::outp('The following parameters will be used in the SP call'); + ADOConnection::outp(print_r($this->storedProcedureParameters)); + } + /* + * We now have a stored parameter resource + * to bind to. The spResource and sql that is returned are + * not usable, its for dummy compatibility. Everything + * will be handled by the storedProcedureParameters + * array + */ + return array($sql,$spResource); + + } + + private function storedProcedureParameter(&$stmt, + &$var, + $name, + $isOutput=false, + $maxLen=4000, + $type=false) + { + + + $name = strtoupper($name); + + /* + * Must exist in the list of parameter names for the type + */ + if ($isOutput + && !isset( $this->storedProcedureParameters['out'][$name])) + { + $errorMessage = sprintf('%s is not a valid OUT parameter name',$name); + + $this->_errorMsg = $errorMessage; + if ($this->debug) + ADOConnection::outp($errorMessage); + return false; + } + + if (!$isOutput + && !isset( $this->storedProcedureParameters['in'][$name])) + { + $errorMessage = sprintf('%s is not a valid IN parameter name',$name); + + $this->_errorMsg = $errorMessage; + if ($this->debug) + ADOConnection::outp($errorMessage); + return false; + } + + /* + * We will use these values to bind to when we execute + * the query + */ + $this->storedProcedureParameters['keyvalue'][$name] = &$var; + + return true; + + } + + /** + * Executes a prepared stored procedure. + * + * The function uses the previously accumulated information and + * resources in the $storedProcedureParameters array + * + * @return mixed The statement id if successful, or false + */ + private function executeStoredProcedure() + { + + /* + * Get the previously built resource + */ + $stmtid = $this->storedProcedureParameters['resource']; + + /* + * Bind our variables to the DB2 procedure + */ + foreach ($this->storedProcedureParameters['keyvalue'] as $spName=>$spValue){ + + /* + * Get the ordinal position, required for binding + */ + $ordinalPosition = $this->storedProcedureParameters['index'][$spName]; + + /* + * Get the db2 column dictionary for the parameter + */ + $columnDictionary = $this->storedProcedureParameters['parameters'][$ordinalPosition]; + $parameterType = $columnDictionary[4]; + $dataType = $columnDictionary[5]; + $precision = $columnDictionary[10]; + $scale = $columnDictionary[9]; + + $ok = @db2_bind_param ($this->storedProcedureParameters['resource'], + $ordinalPosition , + $spName, + $parameterType, + $dataType, + $precision, + $scale + ); + + if (!$ok) + { + $this->_errorMsg = @db2_stmt_errormsg(); + $this->_errorCode = @db2_stmt_error(); + + if ($this->debug) + ADOConnection::outp($this->_errorMsg); + return false; + } + + if ($this->debug) + ADOConnection::outp("Correctly Bound parameter $spName to procedure"); + + /* + * Build a variable in the current environment that matches + * the parameter name + */ + ${$spName} = $spValue; + + } + + /* + * All bound, execute + */ + + if (!@db2_execute($stmtid)) + { + $this->_errorMsg = @db2_stmt_errormsg(); + $this->_errorCode = @db2_stmt_error(); + + if ($this->debug) + ADOConnection::outp($this->_errorMsg); + return false; + } + + /* + * We now take the changed parameters back into the + * stored procedures array where we can query them later + * Remember that $spValue was passed in by reference, so we + * can access the value in the variable that was originally + * passed to inParameter or outParameter + */ + foreach ($this->storedProcedureParameters['keyvalue'] as $spName=>$spValue) + { + /* + * We make it available to the environment + */ + $spValue = ${$spName}; + $this->storedProcedureParameters['keyvalue'][$spName] = $spValue; + } + + return $stmtid; + } + + /** + * + * Accepts an input or output parameter to bind to either a stored + * or prepared statements. For DB2, this should not be called as an + * API. always wrap with inParameter and outParameter + * + * @param mixed[] $stmt Statement returned by Prepare() or PrepareSP(). + * @param mixed $var PHP variable to bind to. Can set to null (for isNull support). + * @param string $name Name of stored procedure variable name to bind to. + * @param int $isOutput optional) Indicates direction of parameter + * 0/false=IN 1=OUT 2= IN/OUT + * This is ignored for Stored Procedures + * @param int $maxLen (optional)Holds an maximum length of the variable. + * This is ignored for Stored Procedures + * @param int $type (optional) The data type of $var. + * This is ignored for Stored Procedures + * + * @return bool Success of the operation + */ + public function parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=4000, $type=false) + { + + /* + * If the $stmt is the name of a stored procedure we are + * setting up, we will process it one way, otherwise + * we assume we are setting up a prepared statement + */ + if (is_array($stmt)) + { + if ($this->debug) + ADOConnection::outp("Adding parameter to stored procedure"); + if ($stmt[1] == $this->storedProcedureParameters['resource']) + return $this->storedProcedureParameter($stmt[1], + $var, + $name, + $isOutput, + $maxLen, + $type); + + } + + /* + * We are going to add a parameter to a prepared statement + */ + if ($this->debug) + ADOConnection::outp("Adding parameter to prepared statement"); + } + - function Prepare($sql) + /** + * Prepares a prepared SQL statement, not used for stored procedures + * + * @param string $sql + * + * @return mixed + */ + function prepare($sql) { + if (! $this->_bindInputArray) return $sql; // no binding - $stmt = db2_prepare($this->_connectionID,$sql); + + $stmt = @db2_prepare($this->_connectionID,$sql); if (!$stmt) { // we don't know whether db2 driver is parsing prepared stmts, so just return sql return $sql; @@ -624,65 +1572,154 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/db2/htm/db2 return array($sql,$stmt,false); } - /* returns queryID or false */ - function _query($sql,$inputarr=false) + /** + * Executes a query + * + * @param mixed $sql + * @param mixed $inputarr An optional array of parameters + * + * @return mixed either the queryID or false + */ + function _query(&$sql,$inputarr=false) { - GLOBAL $php_errormsg; - if (isset($php_errormsg)) $php_errormsg = ''; + + GLOBAL $php_errormsg; + + if (isset($php_errormsg)) + $php_errormsg = ''; $this->_error = ''; - if ($inputarr) { - if (is_array($sql)) { + $db2Options = array(); + /* + * Use DB2 Internal case handling for best speed + */ + switch(ADODB_ASSOC_CASE) + { + case ADODB_ASSOC_CASE_UPPER: + $db2Options = array('db2_attr_case'=>DB2_CASE_UPPER); + $setOption = @db2_set_option($this->_connectionID,$db2Options,1); + break; + + case ADODB_ASSOC_CASE_LOWER: + $db2Options = array('db2_attr_case'=>DB2_CASE_LOWER); + $setOption = @db2_set_option($this->_connectionID,$db2Options,1); + break; + + default: + $db2Options = array('db2_attr_case'=>DB2_CASE_NATURAL); + $setOption = @db2_set_option($this->_connectionID,$db2Options,1); + } + + if ($inputarr) + { + if (is_array($sql)) + { $stmtid = $sql[1]; - } else { - $stmtid = db2_prepare($this->_connectionID,$sql); + } + else + { + $stmtid = @db2_prepare($this->_connectionID,$sql); - if ($stmtid == false) { + if ($stmtid == false) + { $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; return false; } } - if (! db2_execute($stmtid,$inputarr)) { - if ($this->_haserrorfunctions) { - $this->_errorMsg = db2_stmt_errormsg(); - $this->_errorCode = db2_stmt_error(); - } + if (! @db2_execute($stmtid,$inputarr)) + { + $this->_errorMsg = @db2_stmt_errormsg(); + $this->_errorCode = @db2_stmt_error(); + if ($this->debug) + ADOConnection::outp($this->_errorMsg); return false; } - } else if (is_array($sql)) { - $stmtid = $sql[1]; - if (!db2_execute($stmtid)) { - if ($this->_haserrorfunctions) { - $this->_errorMsg = db2_stmt_errormsg(); - $this->_errorCode = db2_stmt_error(); + } + else if (is_array($sql)) + { + + /* + * Either a prepared statement or a stored procedure + */ + + if (is_array($this->storedProcedureParameters) + && is_resource($this->storedProcedureParameters['resource'] + )) + /* + * This is all handled in the separate method for + * readability + */ + return $this->executeStoredProcedure(); + + /* + * First, we prepare the statement + */ + $stmtid = @db2_prepare($this->_connectionID,$sql[0]); + if (!$stmtid){ + $this->_errorMsg = @db2_stmt_errormsg(); + $this->_errorCode = @db2_stmt_error(); + if ($this->debug) + ADOConnection::outp("Prepare failed: " . $this->_errorMsg); + + return false; + } + /* + * We next bind some input parameters + */ + $ordinal = 1; + foreach ($sql[1] as $psVar=>$psVal){ + ${$psVar} = $psVal; + $ok = @db2_bind_param($stmtid, $ordinal, $psVar, DB2_PARAM_IN); + if (!$ok) + { + $this->_errorMsg = @db2_stmt_errormsg(); + $this->_errorCode = @db2_stmt_error(); + if ($this->debug) + ADOConnection::outp("Bind failed: " . $this->_errorMsg); + return false; } + } + + if (!@db2_execute($stmtid)) + { + $this->_errorMsg = @db2_stmt_errormsg(); + $this->_errorCode = @db2_stmt_error(); + if ($this->debug) + ADOConnection::outp($this->_errorMsg); return false; } - } else - $stmtid = @db2_exec($this->_connectionID,$sql); + return $stmtid; + } + else + { + + $stmtid = @db2_exec($this->_connectionID,$sql); + } $this->_lastAffectedRows = 0; - if ($stmtid) { - if (@db2_num_fields($stmtid) == 0) { + if ($stmtid) + { + if (@db2_num_fields($stmtid) == 0) + { $this->_lastAffectedRows = db2_num_rows($stmtid); $stmtid = true; - } else { + } + else + { $this->_lastAffectedRows = 0; } - if ($this->_haserrorfunctions) { - $this->_errorMsg = ''; - $this->_errorCode = 0; - } else - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; - } else { - if ($this->_haserrorfunctions) { - $this->_errorMsg = db2_stmt_errormsg(); - $this->_errorCode = db2_stmt_error(); - } else - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; + $this->_errorMsg = ''; + $this->_errorCode = 0; + + } + else + { + + $this->_errorMsg = @db2_stmt_errormsg(); + $this->_errorCode = @db2_stmt_error(); } return $stmtid; @@ -694,12 +1731,12 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/db2/htm/db2 Usage: - $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); + $conn->execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); */ - function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') + function updateBlob($table,$column,$val,$where,$blobtype='BLOB') { - return $this->Execute("UPDATE $table SET $column=? WHERE $where",array($val)) != false; + return $this->execute("UPDATE $table SET $column=? WHERE $where",array($val)) != false; } // returns true or false @@ -715,6 +1752,87 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/db2/htm/db2 return $this->_lastAffectedRows; } + /** + * Gets a meta cased parameter + * + * Receives an input variable to be processed per the metaCasing + * rule, and returns the same value, processed + * + * @param string $value + * + * @return string + */ + final public function getMetaCasedValue($value) + { + global $ADODB_ASSOC_CASE; + + switch($ADODB_ASSOC_CASE) + { + case ADODB_ASSOC_CASE_LOWER: + $value = strtolower($value); + break; + case ADODB_ASSOC_CASE_UPPER: + $value = strtoupper($value); + break; + } + return $value; + } + + + const TABLECASE_LOWER = 0; + const TABLECASE_UPPER = 1; + const TABLECASE_DEFAULT = 2; + + /** + * Controls the casing of the table provided to the meta functions + */ + private $tableCase = 2; + + /** + * Sets the table case parameter + * + * @param int $caseOption + * @return null + */ + final public function setTableCasing($caseOption) + { + $this->tableCase = $caseOption; + } + + /** + * Gets the table casing parameter + * + * @return int $caseOption + */ + final public function getTableCasing() + { + return $this->tableCase; + } + + /** + * Gets a table cased parameter + * + * Receives an input variable to be processed per the tableCasing + * rule, and returns the same value, processed + * + * @param string $value + * + * @return string + */ + final public function getTableCasedValue($value) + { + switch($this->tableCase) + { + case self::TABLECASE_LOWER: + $value = strtolower($value); + break; + case self::TABLECASE_UPPER: + $value = strtoupper($value); + break; + } + return $value; + } + } /*-------------------------------------------------------------------------------------- @@ -741,21 +1859,30 @@ class ADORecordSet_db2 extends ADORecordSet { // returns the field object - function FetchField($offset = -1) - { - $o= new ADOFieldObject(); - $o->name = @db2_field_name($this->_queryID,$offset); - $o->type = @db2_field_type($this->_queryID,$offset); - $o->max_length = db2_field_width($this->_queryID,$offset); - if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name); - else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name); + function fetchField($offset = 0) + { + $o = new ADOFieldObject(); + $o->name = @db2_field_name($this->_queryID,$offset); + $o->type = @db2_field_type($this->_queryID,$offset); + $o->max_length = @db2_field_width($this->_queryID,$offset); + + /* + if (ADODB_ASSOC_CASE == 0) + $o->name = strtolower($o->name); + else if (ADODB_ASSOC_CASE == 1) + $o->name = strtoupper($o->name); + */ return $o; } /* Use associative array to get fields array */ - function Fields($colname) + function fields($colname) { - if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname]; + + if ($this->fetchMode & ADODB_FETCH_ASSOC) { + return $this->fields[$colname]; + } + if (!$this->bind) { $this->bind = array(); for ($i=0; $i < $this->_numOfFields; $i++) { @@ -770,11 +1897,15 @@ class ADORecordSet_db2 extends ADORecordSet { function _initrs() { - global $ADODB_COUNTRECS; + global $ADODB_COUNTRECS; $this->_numOfRows = ($ADODB_COUNTRECS) ? @db2_num_rows($this->_queryID) : -1; + $this->_numOfFields = @db2_num_fields($this->_queryID); + // some silly drivers such as db2 as/400 and intersystems cache return _numOfRows = 0 - if ($this->_numOfRows == 0) $this->_numOfRows = -1; + + if ($this->_numOfRows == 0) + $this->_numOfRows = -1; } function _seek($row) @@ -782,21 +1913,15 @@ class ADORecordSet_db2 extends ADORecordSet { return false; } - // speed up SelectLimit() by switching to ADODB_FETCH_NUM as ADODB_FETCH_ASSOC is emulated - function GetArrayLimit($nrows,$offset=-1) + function getArrayLimit($nrows,$offset=0) { if ($offset <= 0) { $rs = $this->GetArray($nrows); return $rs; } - $savem = $this->fetchMode; - $this->fetchMode = ADODB_FETCH_NUM; + $this->Move($offset); - $this->fetchMode = $savem; - if ($this->fetchMode & ADODB_FETCH_ASSOC) { - $this->fields = $this->GetRowAssoc(); - } $results = array(); $cnt = 0; @@ -808,42 +1933,77 @@ class ADORecordSet_db2 extends ADORecordSet { return $results; } - - function MoveNext() + function moveNext() { - if ($this->_numOfRows != 0 && !$this->EOF) { - $this->_currentRow++; + if ($this->EOF || $this->_numOfRows == 0) + return false; + + $this->_currentRow++; + + $this->processCoreFetch(); + return $this->processMoveRecord(); + + } + private function processCoreFetch() + { + switch ($this->fetchMode){ + case ADODB_FETCH_ASSOC: + + /* + * Associative array + */ + $this->fields = @db2_fetch_assoc($this->_queryID); + break; + + case ADODB_FETCH_BOTH: + /* + * Fetch both numeric and Associative array + */ + $this->fields = @db2_fetch_both($this->_queryID); + break; + default: + /* + * Numeric array + */ $this->fields = @db2_fetch_array($this->_queryID); - if ($this->fields) { - if ($this->fetchMode & ADODB_FETCH_ASSOC) { - $this->fields = $this->GetRowAssoc(); - } - return true; - } + break; } - $this->fields = false; - $this->EOF = true; - return false; } - function _fetch() + private function processMoveRecord() { + if (!$this->fields){ + $this->EOF = true; + return false; + } - $this->fields = db2_fetch_array($this->_queryID); - if ($this->fields) { - if ($this->fetchMode & ADODB_FETCH_ASSOC) { - $this->fields = $this->GetRowAssoc(); - } + return true; + } + + function _fetch() + { + $this->processCoreFetch(); + if ($this->fields) return true; - } + $this->fields = false; return false; } function _close() { - return @db2_free_result($this->_queryID); + $ok = @db2_free_result($this->_queryID); + if (!$ok) + { + $this->_errorMsg = @db2_stmt_errormsg($this->_queryId); + $this->_errorCode = @db2_stmt_error(); + + if ($this->debug) + ADOConnection::outp($this->_errorMsg); + return false; + } + } } diff --git a/libraries/adodb/drivers/adodb-db2oci.inc.php b/libraries/adodb/drivers/adodb-db2oci.inc.php index 91d61af14..eea63d94c 100644 --- a/libraries/adodb/drivers/adodb-db2oci.inc.php +++ b/libraries/adodb/drivers/adodb-db2oci.inc.php @@ -1,63 +1,43 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. -Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Microsoft Visual FoxPro data driver. Requires ODBC. Works only on MS Windows. -*/ +/** + * IBM DB2 / Oracle compatibility driver. + * + * This driver re-maps ibm :0 bind variables to oracle compatible ? variables. + * + * @deprecated + * + * 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(ADODB_DIR."/drivers/adodb-db2.inc.php"); +include_once(ADODB_DIR."/drivers/adodb-db2.inc.php"); if (!defined('ADODB_DB2OCI')){ define('ADODB_DB2OCI',1); -/* -// regex code for smart remapping of :0, :1 bind vars to ? ? -function _colontrack($p) -{ -global $_COLONARR,$_COLONSZ; - $v = (integer) substr($p,1); - if ($v > $_COLONSZ) return $p; - $_COLONARR[] = $v; - return '?'; -} - -// smart remapping of :0, :1 bind vars to ? ? -function _colonscope($sql,$arr) -{ -global $_COLONARR,$_COLONSZ; - - $_COLONARR = array(); - $_COLONSZ = sizeof($arr); - - $sql2 = preg_replace("/(:[0-9]+)/e","_colontrack('\\1')",$sql); - - if (empty($_COLONARR)) return array($sql,$arr); - - foreach($_COLONARR as $k => $v) { - $arr2[] = $arr[$v]; - } - - return array($sql2,$arr2); -} -*/ - -/* - Smart remapping of :0, :1 bind vars to ? ? - - Handles colons in comments -- and / * * / and in quoted strings. -*/ - +/** + * Smart remapping of :0, :1 bind vars to ? ? + * Handles colons in comments -- and / * * / and in quoted strings. + * @param string $sql SQL statement + * @param array $arr parameters + * @return array + */ function _colonparser($sql,$arr) { $lensql = strlen($sql); @@ -217,10 +197,6 @@ class ADORecordSet_db2oci extends ADORecordSet_db2 { var $databaseType = "db2oci"; - function __construct($id,$mode=false) - { - return parent::__construct($id,$mode); - } } } //define diff --git a/libraries/adodb/drivers/adodb-db2ora.inc.php b/libraries/adodb/drivers/adodb-db2ora.inc.php index 1261689db..d343a8ae1 100644 --- a/libraries/adodb/drivers/adodb-db2ora.inc.php +++ b/libraries/adodb/drivers/adodb-db2ora.inc.php @@ -1,21 +1,32 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. -Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Microsoft Visual FoxPro data driver. Requires ODBC. Works only on MS Windows. -*/ +/** + * IBM DB2 / Oracle compatibility driver. + * + * This driver provides undocumented bind variable mapping from ibm to oracle. + * The functionality appears to overlap the db2_oci driver. + * + * @deprecated + * + * 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(ADODB_DIR."/drivers/adodb-db2.inc.php"); +include_once(ADODB_DIR."/drivers/adodb-db2.inc.php"); if (!defined('ADODB_DB2OCI')){ @@ -77,10 +88,6 @@ class ADORecordSet_db2oci extends ADORecordSet_odbc { var $databaseType = "db2oci"; - function __construct($id,$mode=false) - { - return parent::__construct($id,$mode); - } } } //define diff --git a/libraries/adodb/drivers/adodb-fbsql.inc.php b/libraries/adodb/drivers/adodb-fbsql.inc.php index 9a2440cfa..0fb895a1d 100644 --- a/libraries/adodb/drivers/adodb-fbsql.inc.php +++ b/libraries/adodb/drivers/adodb-fbsql.inc.php @@ -1,14 +1,24 @@ <?php -/* - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Contribution by Frank M. Kromann <frank@frontbase.com>. - Set tabs to 8. -*/ +/** + * Frontbase 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 + * @author Frank M. Kromann <frank@frontbase.com> + */ // security - hide paths if (!defined('ADODB_DIR')) die(); @@ -25,11 +35,7 @@ class ADODB_fbsql extends ADOConnection { var $fmtTimeStamp = "'Y-m-d H:i:s'"; var $hasLimit = false; - function __construct() - { - } - - function _insertid() + protected function _insertID($table = '', $column = '') { return fbsql_insert_id($this->_connectionID); } @@ -177,7 +183,7 @@ class ADORecordSet_fbsql extends ADORecordSet{ default: $this->fetchMode = FBSQL_BOTH; break; } - return parent::__construct($queryID); + parent::__construct($queryID); } function _initrs() @@ -259,7 +265,7 @@ class ADORecordSet_fbsql extends ADORecordSet{ if (!empty($fieldobj->primary_key)) return 'R'; else return 'I'; - default: return 'N'; + default: return ADODB_DEFAULT_METATYPE; } } diff --git a/libraries/adodb/drivers/adodb-firebird.inc.php b/libraries/adodb/drivers/adodb-firebird.inc.php index 415f66f21..2fafbe4fc 100644 --- a/libraries/adodb/drivers/adodb-firebird.inc.php +++ b/libraries/adodb/drivers/adodb-firebird.inc.php @@ -1,27 +1,130 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. -Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - -*/ +/** + * Firebird driver. + * + * Requires firebird client. Works on Windows and Unix. + * + * 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-ibase.inc.php"); - -class ADODB_firebird extends ADODB_ibase { +class ADODB_firebird extends ADOConnection { var $databaseType = "firebird"; + var $dataProvider = "firebird"; + var $replaceQuote = "''"; // string to use to replace quotes + var $fbird_datefmt = '%Y-%m-%d'; // For hours,mins,secs change to '%Y-%m-%d %H:%M:%S'; + var $fmtDate = "'Y-m-d'"; + var $fbird_timestampfmt = "%Y-%m-%d %H:%M:%S"; + var $fbird_timefmt = "%H:%M:%S"; + var $fmtTimeStamp = "'Y-m-d, H:i:s'"; + var $concat_operator='||'; + var $_transactionID; + var $metaTablesSQL = "select lower(rdb\$relation_name) from rdb\$relations where rdb\$relation_name not like 'RDB\$%'"; + //OPN STUFF start + var $metaColumnsSQL = "select lower(a.rdb\$field_name), a.rdb\$null_flag, a.rdb\$default_source, b.rdb\$field_length, b.rdb\$field_scale, b.rdb\$field_sub_type, b.rdb\$field_precision, b.rdb\$field_type from rdb\$relation_fields a, rdb\$fields b where a.rdb\$field_source = b.rdb\$field_name and a.rdb\$relation_name = '%s' order by a.rdb\$field_position asc"; + //OPN STUFF end + var $ibasetrans; + var $hasGenID = true; + var $_bindInputArray = true; + var $buffers = 0; var $dialect = 3; - + var $sysDate = "cast('TODAY' as timestamp)"; var $sysTimeStamp = "CURRENT_TIMESTAMP"; //"cast('NOW' as timestamp)"; + var $ansiOuter = true; + var $hasAffectedRows = true; + var $poorAffectedRows = false; + var $blobEncodeType = 'C'; + var $role = false; + var $nameQuote = ''; /// string to use to quote identifiers and names + + function __construct() + { + // Ignore IBASE_DEFAULT we want a more practical transaction! + // if (defined('IBASE_DEFAULT')) $this->ibasetrans = IBASE_DEFAULT; + // else + $this->ibasetrans = IBASE_WAIT | IBASE_REC_VERSION | IBASE_COMMITTED; + } + + + // returns true or false + function _connect($argHostname, $argUsername, $argPassword, $argDatabasename,$persist=false) + { + if (!function_exists('fbird_pconnect')) return null; + if ($argDatabasename) $argHostname .= ':'.$argDatabasename; + $fn = ($persist) ? 'fbird_pconnect':'fbird_connect'; + if ($this->role) + $this->_connectionID = $fn($argHostname,$argUsername,$argPassword, + $this->charSet,$this->buffers,$this->dialect,$this->role); + else + $this->_connectionID = $fn($argHostname,$argUsername,$argPassword, + $this->charSet,$this->buffers,$this->dialect); + + if ($this->dialect != 1) { // http://www.ibphoenix.com/ibp_60_del_id_ds.html + $this->replaceQuote = "''"; + } + if ($this->_connectionID === false) { + $this->_handleerror(); + return false; + } + + // PHP5 change. + if (function_exists('fbird_timefmt')) { + fbird_timefmt($this->fbird_datefmt,fbird_DATE ); + if ($this->dialect == 1) { + fbird_timefmt($this->fbird_datefmt,fbird_TIMESTAMP ); + } else { + fbird_timefmt($this->fbird_timestampfmt,fbird_TIMESTAMP ); + } + fbird_timefmt($this->fbird_timefmt,fbird_TIME ); + + } else { + ini_set("ibase.timestampformat", $this->fbird_timestampfmt); + ini_set("ibase.dateformat", $this->fbird_datefmt); + ini_set("ibase.timeformat", $this->fbird_timefmt); + } + return true; + } + + // returns true or false + function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) + { + return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename,true); + } + + + function MetaPrimaryKeys($table,$owner_notused=false,$internalKey=false) + { + if ($internalKey) { + return array('RDB$DB_KEY'); + } + + $table = strtoupper($table); + + $sql = 'SELECT S.RDB$FIELD_NAME AFIELDNAME + FROM RDB$INDICES I JOIN RDB$INDEX_SEGMENTS S ON I.RDB$INDEX_NAME=S.RDB$INDEX_NAME + WHERE I.RDB$RELATION_NAME=\''.$table.'\' and I.RDB$INDEX_NAME like \'RDB$PRIMARY%\' + ORDER BY I.RDB$INDEX_NAME,S.RDB$FIELD_POSITION'; + + $a = $this->GetCol($sql,false,true); + if ($a && sizeof($a)>0) return $a; + return false; + } function ServerInfo() { @@ -38,10 +141,597 @@ class ADODB_firebird extends ADODB_ibase { return $arr; } + function BeginTrans() + { + if ($this->transOff) return true; + $this->transCnt += 1; + $this->autoCommit = false; + $this->_transactionID = fbird_trans( $this->ibasetrans, $this->_connectionID ); + return $this->_transactionID; + } + + function CommitTrans($ok=true) + { + if (!$ok) { + return $this->RollbackTrans(); + } + if ($this->transOff) { + return true; + } + if ($this->transCnt) { + $this->transCnt -= 1; + } + $ret = false; + $this->autoCommit = true; + if ($this->_transactionID) { + //print ' commit '; + $ret = fbird_commit($this->_transactionID); + } + $this->_transactionID = false; + return $ret; + } + + function _affectedrows() + { + return fbird_affected_rows( $this->_transactionID ? $this->_transactionID : $this->_connectionID ); + } + + // there are some compat problems with ADODB_COUNTRECS=false and $this->_logsql currently. + // it appears that ibase extension cannot support multiple concurrent queryid's + function _Execute($sql,$inputarr=false) { + global $ADODB_COUNTRECS; + + if ($this->_logsql) { + $savecrecs = $ADODB_COUNTRECS; + $ADODB_COUNTRECS = true; // force countrecs + $ret =& ADOConnection::_Execute($sql,$inputarr); + $ADODB_COUNTRECS = $savecrecs; + } else { + $ret = ADOConnection::_Execute($sql,$inputarr); + } + return $ret; + } + + function RollbackTrans() + { + if ($this->transOff) return true; + if ($this->transCnt) $this->transCnt -= 1; + $ret = false; + $this->autoCommit = true; + if ($this->_transactionID) { + $ret = fbird_rollback($this->_transactionID); + } + $this->_transactionID = false; + + 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); + } + $table = strtoupper($table); + $sql = "SELECT * FROM RDB\$INDICES WHERE RDB\$RELATION_NAME = '".$table."'"; + if (!$primary) { + $sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$%'"; + } else { + $sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$FOREIGN%'"; + } + // get index details + $rs = $this->Execute($sql); + if (!is_object($rs)) { + // restore fetchmode + if (isset($savem)) { + $this->SetFetchMode($savem); + } + $ADODB_FETCH_MODE = $save; + return $false; + } + + $indexes = array(); + while ($row = $rs->FetchRow()) { + $index = $row[0]; + if (!isset($indexes[$index])) { + if (is_null($row[3])) { + $row[3] = 0; + } + $indexes[$index] = array( + 'unique' => ($row[3] == 1), + 'columns' => array() + ); + } + $sql = "SELECT * FROM RDB\$INDEX_SEGMENTS WHERE RDB\$INDEX_NAME = '".$index."' ORDER BY RDB\$FIELD_POSITION ASC"; + $rs1 = $this->Execute($sql); + while ($row1 = $rs1->FetchRow()) { + $indexes[$index]['columns'][$row1[2]] = $row1[1]; + } + } + // restore fetchmode + if (isset($savem)) { + $this->SetFetchMode($savem); + } + $ADODB_FETCH_MODE = $save; + + return $indexes; + } + + + // See http://community.borland.com/article/0,1410,25844,00.html + function RowLock($tables,$where,$col=false) + { + if ($this->autoCommit) { + $this->BeginTrans(); + } + $this->Execute("UPDATE $table SET $col=$col WHERE $where "); // is this correct - jlim? + return 1; + } + + + function CreateSequence($seqname = 'adodbseq', $startID = 1) + { + $ok = $this->Execute(("CREATE GENERATOR $seqname" )); + if (!$ok) return false; + return $this->Execute("SET GENERATOR $seqname TO ".($startID-1)); + } + + function DropSequence($seqname = 'adodbseq') + { + $seqname = strtoupper($seqname); + return $this->Execute("DROP GENERATOR $seqname"); + } + + function GenID($seqname='adodbseq',$startID=1) + { + $getnext = ("SELECT Gen_ID($seqname,1) FROM RDB\$DATABASE"); + $rs = @$this->Execute($getnext); + if (!$rs) { + $this->Execute(("CREATE GENERATOR $seqname" )); + $this->Execute("SET GENERATOR $seqname TO ".($startID-1).';'); + $rs = $this->Execute($getnext); + } + if ($rs && !$rs->EOF) { + $this->genID = (integer) reset($rs->fields); + } + else { + $this->genID = 0; // false + } + + if ($rs) { + $rs->Close(); + } + + return $this->genID; + } + + function SelectDB($dbName) + { + return false; + } + + function _handleerror() + { + $this->_errorMsg = fbird_errmsg(); + } + + function ErrorNo() + { + if (preg_match('/error code = ([\-0-9]*)/i', $this->_errorMsg,$arr)) return (integer) $arr[1]; + else return 0; + } + + function ErrorMsg() + { + return $this->_errorMsg; + } + + function Prepare($sql) + { + $stmt = fbird_prepare($this->_connectionID,$sql); + if (!$stmt) return false; + return array($sql,$stmt); + } + + // returns query ID if successful, otherwise false + // there have been reports of problems with nested queries - the code is probably not re-entrant? + function _query($sql,$iarr=false) + { + if ( !$this->isConnected() ) return false; + if (!$this->autoCommit && $this->_transactionID) { + $conn = $this->_transactionID; + $docommit = false; + } else { + $conn = $this->_connectionID; + $docommit = true; + } + if (is_array($sql)) { + $fn = 'fbird_execute'; + $sql = $sql[1]; + if (is_array($iarr)) { + if ( !isset($iarr[0]) ) + $iarr[0] = ''; // PHP5 compat hack + $fnarr = array_merge( array($sql) , $iarr); + $ret = call_user_func_array($fn,$fnarr); + } + else { + $ret = $fn($sql); + } + } else { + $fn = 'fbird_query'; + if (is_array($iarr)) + { + if (sizeof($iarr) == 0) + $iarr[0] = ''; // PHP5 compat hack + $fnarr = array_merge( array($conn,$sql) , $iarr); + $ret = call_user_func_array($fn,$fnarr); + } + else { + $ret = $fn($conn, $sql); + } + } + if ($docommit && $ret === true) { + fbird_commit($this->_connectionID); + } + + $this->_handleerror(); + return $ret; + } + + // returns true or false + function _close() + { + if (!$this->autoCommit) { + @fbird_rollback($this->_connectionID); + } + return @fbird_close($this->_connectionID); + } + + //OPN STUFF start + function _ConvertFieldType(&$fld, $ftype, $flen, $fscale, $fsubtype, $fprecision, $dialect3) + { + $fscale = abs($fscale); + $fld->max_length = $flen; + $fld->scale = null; + switch($ftype){ + case 7: + case 8: + if ($dialect3) { + switch($fsubtype){ + case 0: + $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); + break; + case 1: + $fld->type = 'numeric'; + $fld->max_length = $fprecision; + $fld->scale = $fscale; + break; + case 2: + $fld->type = 'decimal'; + $fld->max_length = $fprecision; + $fld->scale = $fscale; + break; + } // switch + } else { + if ($fscale !=0) { + $fld->type = 'decimal'; + $fld->scale = $fscale; + $fld->max_length = ($ftype == 7 ? 4 : 9); + } else { + $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); + } + } + break; + case 16: + if ($dialect3) { + switch($fsubtype){ + case 0: + $fld->type = 'decimal'; + $fld->max_length = 18; + $fld->scale = 0; + break; + case 1: + $fld->type = 'numeric'; + $fld->max_length = $fprecision; + $fld->scale = $fscale; + break; + case 2: + $fld->type = 'decimal'; + $fld->max_length = $fprecision; + $fld->scale = $fscale; + break; + } // switch + } + break; + case 10: + $fld->type = 'float'; + break; + case 14: + $fld->type = 'char'; + break; + case 27: + if ($fscale !=0) { + $fld->type = 'decimal'; + $fld->max_length = 15; + $fld->scale = 5; + } else { + $fld->type = 'double'; + } + break; + case 35: + if ($dialect3) { + $fld->type = 'timestamp'; + } else { + $fld->type = 'date'; + } + break; + case 12: + $fld->type = 'date'; + break; + case 13: + $fld->type = 'time'; + break; + case 37: + $fld->type = 'varchar'; + break; + case 40: + $fld->type = 'cstring'; + break; + case 261: + $fld->type = 'blob'; + $fld->max_length = -1; + break; + } // switch + } + //OPN STUFF end + + // returns array of ADOFieldObjects for current table + function MetaColumns($table, $normalize=true) + { + global $ADODB_FETCH_MODE; + + $save = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + + $rs = $this->Execute(sprintf($this->metaColumnsSQL,strtoupper($table))); + + $ADODB_FETCH_MODE = $save; + $false = false; + if ($rs === false) { + return $false; + } + + $retarr = array(); + //OPN STUFF start + $dialect3 = ($this->dialect==3 ? true : false); + //OPN STUFF end + while (!$rs->EOF) { //print_r($rs->fields); + $fld = new ADOFieldObject(); + $fld->name = trim($rs->fields[0]); + //OPN STUFF start + $this->_ConvertFieldType($fld, $rs->fields[7], $rs->fields[3], $rs->fields[4], $rs->fields[5], $rs->fields[6], $dialect3); + if (isset($rs->fields[1]) && $rs->fields[1]) { + $fld->not_null = true; + } + if (isset($rs->fields[2])) { + + $fld->has_default = true; + $d = substr($rs->fields[2],strlen('default ')); + switch ($fld->type) + { + case 'smallint': + case 'integer': $fld->default_value = (int) $d; break; + case 'char': + case 'blob': + case 'text': + case 'varchar': $fld->default_value = (string) substr($d,1,strlen($d)-2); break; + case 'double': + case 'float': $fld->default_value = (float) $d; break; + default: $fld->default_value = $d; break; + } + // case 35:$tt = 'TIMESTAMP'; break; + } + if ((isset($rs->fields[5])) && ($fld->type == 'blob')) { + $fld->sub_type = $rs->fields[5]; + } else { + $fld->sub_type = null; + } + //OPN STUFF end + if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld; + else $retarr[strtoupper($fld->name)] = $fld; + + $rs->MoveNext(); + } + $rs->Close(); + if ( empty($retarr)) return $false; + else return $retarr; + } + + function BlobEncode( $blob ) + { + $blobid = fbird_blob_create( $this->_connectionID); + fbird_blob_add( $blobid, $blob ); + return fbird_blob_close( $blobid ); + } + + // since we auto-decode all blob's since 2.42, + // BlobDecode should not do any transforms + function BlobDecode($blob) + { + return $blob; + } + + // old blobdecode function + // still used to auto-decode all blob's + function _BlobDecode_old( $blob ) + { + $blobid = fbird_blob_open($this->_connectionID, $blob ); + $realblob = fbird_blob_get( $blobid,$this->maxblobsize); // 2nd param is max size of blob -- Kevin Boillet <kevinboillet@yahoo.fr> + while($string = fbird_blob_get($blobid, 8192)){ + $realblob .= $string; + } + fbird_blob_close( $blobid ); + + return( $realblob ); + } + + function _BlobDecode( $blob ) + { + $blob_data = fbird_blob_info($this->_connectionID, $blob ); + $blobid = fbird_blob_open($this->_connectionID, $blob ); + + if( $blob_data[0] > $this->maxblobsize ) { + $realblob = fbird_blob_get($blobid, $this->maxblobsize); + + while($string = fbird_blob_get($blobid, 8192)) { + $realblob .= $string; + } + } else { + $realblob = fbird_blob_get($blobid, $blob_data[0]); + } + + fbird_blob_close( $blobid ); + return( $realblob ); + } + + function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB') + { + $fd = fopen($path,'rb'); + if ($fd === false) return false; + $blob_id = fbird_blob_create($this->_connectionID); + + /* fill with data */ + + while ($val = fread($fd,32768)){ + fbird_blob_add($blob_id, $val); + } + + /* close and get $blob_id_str for inserting into table */ + $blob_id_str = fbird_blob_close($blob_id); + + fclose($fd); + return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; + } + + /* + Insert a null into the blob field of the table first. + Then use UpdateBlob to store the blob. + + Usage: + + $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); + $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); + */ + function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') + { + $blob_id = fbird_blob_create($this->_connectionID); + + // fbird_blob_add($blob_id, $val); + + // replacement that solves the problem by which only the first modulus 64K / + // of $val are stored at the blob field //////////////////////////////////// + // Thx Abel Berenstein aberenstein#afip.gov.ar + $len = strlen($val); + $chunk_size = 32768; + $tail_size = $len % $chunk_size; + $n_chunks = ($len - $tail_size) / $chunk_size; + + for ($n = 0; $n < $n_chunks; $n++) { + $start = $n * $chunk_size; + $data = substr($val, $start, $chunk_size); + fbird_blob_add($blob_id, $data); + } + + if ($tail_size) { + $start = $n_chunks * $chunk_size; + $data = substr($val, $start, $tail_size); + fbird_blob_add($blob_id, $data); + } + // end replacement ///////////////////////////////////////////////////////// + + $blob_id_str = fbird_blob_close($blob_id); + + return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; + + } + + + function OldUpdateBlob($table,$column,$val,$where,$blobtype='BLOB') + { + $blob_id = fbird_blob_create($this->_connectionID); + fbird_blob_add($blob_id, $val); + $blob_id_str = fbird_blob_close($blob_id); + return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; + } + + // Format date column in sql string given an input format that understands Y M D + // Only since Interbase 6.0 - uses EXTRACT + // problem - does not zero-fill the day and month yet + function SQLDate($fmt, $col=false) + { + if (!$col) $col = $this->sysDate; + $s = ''; + + $len = strlen($fmt); + for ($i=0; $i < $len; $i++) { + if ($s) $s .= '||'; + $ch = $fmt[$i]; + switch($ch) { + case 'Y': + case 'y': + $s .= "extract(year from $col)"; + break; + case 'M': + case 'm': + $s .= "extract(month from $col)"; + break; + case 'W': + case 'w': + // The more accurate way of doing this is with a stored procedure + // See http://wiki.firebirdsql.org/wiki/index.php?page=DATE+Handling+Functions for details + $s .= "((extract(yearday from $col) - extract(weekday from $col - 1) + 7) / 7)"; + break; + case 'Q': + case 'q': + $s .= "cast(((extract(month from $col)+2) / 3) as integer)"; + break; + case 'D': + case 'd': + $s .= "(extract(day from $col))"; + break; + case 'H': + case 'h': + $s .= "(extract(hour from $col))"; + break; + case 'I': + case 'i': + $s .= "(extract(minute from $col))"; + break; + case 'S': + case 's': + $s .= "CAST((extract(second from $col)) AS INTEGER)"; + break; + + default: + if ($ch == '\\') { + $i++; + $ch = substr($fmt,$i,1); + } + $s .= $this->qstr($ch); + break; + } + } + return $s; + } + // Note that Interbase 6.5 uses this ROWS instead - don't you love forking wars! // SELECT col1, col2 FROM table ROWS 5 -- get 5 rows // SELECT col1, col2 FROM TABLE ORDER BY col1 ROWS 3 TO 7 -- first 5 skip 2 - function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false, $secs=0) + function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false, $secs=0) { $nrows = (integer) $nrows; $offset = (integer) $offset; @@ -58,16 +748,173 @@ class ADODB_firebird extends ADODB_ibase { return $rs; } +} -}; - +/*-------------------------------------------------------------------------------------- + Class Name: Recordset +--------------------------------------------------------------------------------------*/ -class ADORecordSet_firebird extends ADORecordSet_ibase { +class ADORecordset_firebird extends ADORecordSet +{ var $databaseType = "firebird"; + var $bind=false; + var $_cacheType; function __construct($id,$mode=false) { - parent::__construct($id,$mode); + global $ADODB_FETCH_MODE; + + $this->fetchMode = ($mode === false) ? $ADODB_FETCH_MODE : $mode; + parent::__construct($id); + } + + /** + * Get column information in the Recordset object. + * fetchField() can be used in order to obtain information about fields in + * a certain query result. If the field offset isn't specified, the next + * field that wasn't yet retrieved by fetchField() is retrieved. + * @return object containing field information. + */ + function FetchField($fieldOffset = -1) + { + $fld = new ADOFieldObject; + $ibf = fbird_field_info($this->_queryID,$fieldOffset); + + $name = empty($ibf['alias']) ? $ibf['name'] : $ibf['alias']; + + switch (ADODB_ASSOC_CASE) { + case ADODB_ASSOC_CASE_UPPER: + $fld->name = strtoupper($name); + break; + case ADODB_ASSOC_CASE_LOWER: + $fld->name = strtolower($name); + break; + case ADODB_ASSOC_CASE_NATIVE: + default: + $fld->name = $name; + break; + } + + $fld->type = $ibf['type']; + $fld->max_length = $ibf['length']; + + /* This needs to be populated from the metadata */ + $fld->not_null = false; + $fld->has_default = false; + $fld->default_value = 'null'; + return $fld; + } + + function _initrs() + { + $this->_numOfRows = -1; + $this->_numOfFields = @fbird_num_fields($this->_queryID); + + // cache types for blob decode check + for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { + $f1 = $this->FetchField($i); + $this->_cacheType[] = $f1->type; + } + } + + function _seek($row) + { + return false; + } + + function _fetch() + { + $f = @fbird_fetch_row($this->_queryID); + if ($f === false) { + $this->fields = false; + return false; + } + // OPN stuff start - optimized + // fix missing nulls and decode blobs automatically + + global $ADODB_ANSI_PADDING_OFF; + //$ADODB_ANSI_PADDING_OFF=1; + $rtrim = !empty($ADODB_ANSI_PADDING_OFF); + + for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { + if ($this->_cacheType[$i]=="BLOB") { + if (isset($f[$i])) { + $f[$i] = $this->connection->_BlobDecode($f[$i]); + } else { + $f[$i] = null; + } + } else { + if (!isset($f[$i])) { + $f[$i] = null; + } else if ($rtrim && is_string($f[$i])) { + $f[$i] = rtrim($f[$i]); + } + } + } + // OPN stuff end + + $this->fields = $f; + if ($this->fetchMode == ADODB_FETCH_ASSOC) { + $this->fields = $this->GetRowAssoc(); + } else if ($this->fetchMode == ADODB_FETCH_BOTH) { + $this->fields = array_merge($this->fields,$this->GetRowAssoc()); + } + return true; + } + + /* Use associative array to get fields array */ + function Fields($colname) + { + if ($this->fetchMode & ADODB_FETCH_ASSOC) 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 _close() + { + return @fbird_free_result($this->_queryID); + } + + function MetaType($t,$len=-1,$fieldobj=false) + { + if (is_object($t)) { + $fieldobj = $t; + $t = $fieldobj->type; + $len = $fieldobj->max_length; + } + switch (strtoupper($t)) { + case 'CHAR': + return 'C'; + + case 'TEXT': + case 'VARCHAR': + case 'VARYING': + if ($len <= $this->blobSize) return 'C'; + return 'X'; + case 'BLOB': + return 'B'; + + case 'TIMESTAMP': + case 'DATE': return 'D'; + case 'TIME': return 'T'; + //case 'T': return 'T'; + + //case 'L': return 'L'; + case 'INT': + case 'SHORT': + case 'INTEGER': return 'I'; + default: return ADODB_DEFAULT_METATYPE; + } + } + } diff --git a/libraries/adodb/drivers/adodb-ibase.inc.php b/libraries/adodb/drivers/adodb-ibase.inc.php index c4f0cbdb6..69de30dcc 100644 --- a/libraries/adodb/drivers/adodb-ibase.inc.php +++ b/libraries/adodb/drivers/adodb-ibase.inc.php @@ -1,29 +1,25 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Latest version is available at http://adodb.sourceforge.net - - Interbase data driver. Requires interbase client. Works on Windows and Unix. - - 3 Jan 2002 -- suggestions by Hans-Peter Oeri <kampfcaspar75@oeri.ch> - changed transaction handling and added experimental blob stuff - - Docs to interbase at the website - http://www.synectics.co.za/php3/tutorial/IB_PHP3_API.html - - To use gen_id(), see - http://www.volny.cz/iprenosil/interbase/ip_ib_code.htm#_code_creategen - - $rs = $conn->Execute('select gen_id(adodb,1) from rdb$database'); - $id = $rs->fields[0]; - $conn->Execute("insert into table (id, col1,...) values ($id, $val1,...)"); -*/ +/** + * Interbase driver. + * + * Requires interbase client. Works on Windows and Unix. + * + * 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(); @@ -350,46 +346,26 @@ class ADODB_ibase extends ADOConnection { $fn = 'ibase_execute'; $sql = $sql[1]; if (is_array($iarr)) { - if (ADODB_PHPVER >= 0x4050) { // actually 4.0.4 - if ( !isset($iarr[0]) ) $iarr[0] = ''; // PHP5 compat hack - $fnarr = array_merge( array($sql) , $iarr); - $ret = call_user_func_array($fn,$fnarr); - } else { - switch(sizeof($iarr)) { - case 1: $ret = $fn($sql,$iarr[0]); break; - case 2: $ret = $fn($sql,$iarr[0],$iarr[1]); break; - case 3: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2]); break; - case 4: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3]); break; - case 5: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4]); break; - case 6: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5]); break; - case 7: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6]); break; - default: ADOConnection::outp( "Too many parameters to ibase query $sql"); - case 8: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6],$iarr[7]); break; - } - } - } else $ret = $fn($sql); + if ( !isset($iarr[0]) ) + $iarr[0] = ''; // PHP5 compat hack + $fnarr = array_merge( array($sql) , $iarr); + $ret = call_user_func_array($fn,$fnarr); + } + else { + $ret = $fn($sql); + } } else { $fn = 'ibase_query'; if (is_array($iarr)) { - if (ADODB_PHPVER >= 0x4050) { // actually 4.0.4 - if (sizeof($iarr) == 0) $iarr[0] = ''; // PHP5 compat hack - $fnarr = array_merge( array($conn,$sql) , $iarr); - $ret = call_user_func_array($fn,$fnarr); - } else { - switch(sizeof($iarr)) { - case 1: $ret = $fn($conn,$sql,$iarr[0]); break; - case 2: $ret = $fn($conn,$sql,$iarr[0],$iarr[1]); break; - case 3: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2]); break; - case 4: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3]); break; - case 5: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4]); break; - case 6: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5]); break; - case 7: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6]); break; - default: ADOConnection::outp( "Too many parameters to ibase query $sql"); - case 8: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6],$iarr[7]); break; - } - } - } else $ret = $fn($conn,$sql); + if (sizeof($iarr) == 0) + $iarr[0] = ''; // PHP5 compat hack + $fnarr = array_merge( array($conn,$sql) , $iarr); + $ret = call_user_func_array($fn,$fnarr); + } + else { + $ret = $fn($conn, $sql); + } } if ($docommit && $ret === true) { ibase_commit($this->_connectionID); @@ -601,14 +577,8 @@ class ADODB_ibase extends ADOConnection { function _BlobDecode( $blob ) { - if (ADODB_PHPVER >= 0x5000) { - $blob_data = ibase_blob_info($this->_connectionID, $blob ); - $blobid = ibase_blob_open($this->_connectionID, $blob ); - } else { - - $blob_data = ibase_blob_info( $blob ); - $blobid = ibase_blob_open( $blob ); - } + $blob_data = ibase_blob_info($this->_connectionID, $blob ); + $blobid = ibase_blob_open($this->_connectionID, $blob ); if( $blob_data[0] > $this->maxblobsize ) { @@ -911,7 +881,7 @@ class ADORecordset_ibase extends ADORecordSet case 'INT': case 'SHORT': case 'INTEGER': return 'I'; - default: return 'N'; + default: return ADODB_DEFAULT_METATYPE; } } diff --git a/libraries/adodb/drivers/adodb-informix.inc.php b/libraries/adodb/drivers/adodb-informix.inc.php index 801451ea5..8e99137cb 100644 --- a/libraries/adodb/drivers/adodb-informix.inc.php +++ b/libraries/adodb/drivers/adodb-informix.inc.php @@ -1,19 +1,27 @@ <?php /** -* @version v5.20.9 21-Dec-2016 -* @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -* @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community -* Released under both BSD license and Lesser GPL library license. -* Whenever there is any discrepancy between the two licenses, -* the BSD license will take precedence. -* -* Set tabs to 4 for best viewing. -* -* Latest version is available at http://php.weblogs.com -* -* Informix 9 driver that supports SELECT FIRST -* -*/ + * Informix 9 driver. + * + * Supports SELECT FIRST. + * + * @deprecated + * + * 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(); @@ -33,9 +41,4 @@ class ADODB_informix extends ADODB_informix72 { class ADORecordset_informix extends ADORecordset_informix72 { var $databaseType = "informix"; - - function __construct($id,$mode=false) - { - parent::__construct($id,$mode); - } } diff --git a/libraries/adodb/drivers/adodb-informix72.inc.php b/libraries/adodb/drivers/adodb-informix72.inc.php index 58f233a1f..a9c43e231 100644 --- a/libraries/adodb/drivers/adodb-informix72.inc.php +++ b/libraries/adodb/drivers/adodb-informix72.inc.php @@ -1,20 +1,27 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim. All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Informix port by Mitchell T. Young (mitch@youngfamily.org) - - Further mods by "Samuel CARRIERE" <samuel_carriere@hotmail.com> - -*/ +/** + * Informix driver. + * + * @deprecated + * + * 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 Mitchell T. Young <mitch@youngfamily.org> + * @author Samuel Carriere <samuel_carriere@hotmail.com> + */ // security - hide paths if (!defined('ADODB_DIR')) die(); @@ -83,7 +90,7 @@ class ADODB_informix72 extends ADOConnection { - function _insertid() + protected function _insertID($table = '', $column = '') { $sqlca =ifx_getsqlca($this->lastQuery); return @$sqlca["sqlerrd1"]; @@ -403,7 +410,7 @@ class ADORecordset_informix72 extends ADORecordSet { $mode = $ADODB_FETCH_MODE; } $this->fetchMode = $mode; - return parent::__construct($id); + parent::__construct($id); } @@ -501,7 +508,7 @@ class ADORecordset_informix72 extends ADORecordSet { } /** !Eos -* Auxiliar function to Parse coltype,collength. Used by Metacolumns +* Auxiliary function to Parse coltype,collength. Used by Metacolumns * return: array ($mtype,$length,$precision,$nullable) (similar to ifx_fieldpropierties) */ function ifx_props($coltype,$collength){ diff --git a/libraries/adodb/drivers/adodb-ldap.inc.php b/libraries/adodb/drivers/adodb-ldap.inc.php index 633705e09..323b35856 100644 --- a/libraries/adodb/drivers/adodb-ldap.inc.php +++ b/libraries/adodb/drivers/adodb-ldap.inc.php @@ -1,20 +1,26 @@ <?php -/* - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 8. - - Revision 1: (02/25/2005) Updated codebase to include the _inject_bind_options function. This allows - users to access the options in the ldap_set_option function appropriately. Most importantly - LDAP Version 3 is now supported. See the examples for more information. Also fixed some minor - bugs that surfaced when PHP error levels were set high. - - Joshua Eldridge (joshuae74#hotmail.com) -*/ +/** + * 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(); @@ -45,10 +51,6 @@ class ADODB_ldap extends ADOConnection { # error on binding, eg. "Binding: invalid credentials" var $_bind_errmsg = "Binding: %s"; - function __construct() - { - } - // returns true or false function _connect( $host, $username, $password, $ldapbase) @@ -331,7 +333,7 @@ class ADORecordSet_ldap extends ADORecordSet{ /* Return whole recordset as a multi-dimensional associative array */ - function GetAssoc($force_array = false, $first2cols = false) + function GetAssoc($force_array = false, $first2cols = false, $fetchMode = -1) { $records = $this->_numOfRows; $results = array(); diff --git a/libraries/adodb/drivers/adodb-mssql.inc.php b/libraries/adodb/drivers/adodb-mssql.inc.php index 068dffce0..3de3f8d33 100644 --- a/libraries/adodb/drivers/adodb-mssql.inc.php +++ b/libraries/adodb/drivers/adodb-mssql.inc.php @@ -1,21 +1,25 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. -Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Native mssql driver. Requires mssql client. Works on Windows. - To configure for Unix, see - http://phpbuilder.com/columns/alberto20000919.php3 - -*/ - +/** + * Native MSSQL driver. + * + * Requires mssql client. Works on Windows. + * + * 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(); @@ -39,39 +43,7 @@ if (!defined('ADODB_DIR')) die(); //---------------------------------------------------------------- -// has datetime converstion to YYYY-MM-DD format, and also mssql_fetch_assoc -if (ADODB_PHPVER >= 0x4300) { -// docs say 4.2.0, but testing shows only since 4.3.0 does it work! - ini_set('mssql.datetimeconvert',0); -} else { -global $ADODB_mssql_mths; // array, months must be upper-case - - - $ADODB_mssql_date_order = 'mdy'; - $ADODB_mssql_mths = array( - 'JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6, - 'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12); -} - -//--------------------------------------------------------------------------- -// Call this to autoset $ADODB_mssql_date_order at the beginning of your code, -// just after you connect to the database. Supports mdy and dmy only. -// Not required for PHP 4.2.0 and above. -function AutoDetect_MSSQL_Date_Order($conn) -{ -global $ADODB_mssql_date_order; - $adate = $conn->GetOne('select getdate()'); - if ($adate) { - $anum = (int) $adate; - if ($anum > 0) { - if ($anum > 31) { - //ADOConnection::outp( "MSSQL: YYYY-MM-DD date format not supported currently"); - } else - $ADODB_mssql_date_order = 'dmy'; - } else - $ADODB_mssql_date_order = 'mdy'; - } -} +ini_set('mssql.datetimeconvert',0); class ADODB_mssql extends ADOConnection { var $databaseType = "mssql"; @@ -94,7 +66,6 @@ class ADODB_mssql extends ADOConnection { var $hasGenID = true; var $sysDate = 'convert(datetime,convert(char,GetDate(),102),102)'; var $sysTimeStamp = 'GetDate()'; - var $_has_mssql_init; var $maxParameterLen = 4000; var $arrayClass = 'ADORecordSet_array_mssql'; var $uniqueSort = true; @@ -107,11 +78,6 @@ class ADODB_mssql extends ADOConnection { var $_bindInputArray = true; var $forceNewConnect = false; - function __construct() - { - $this->_has_mssql_init = (strnatcmp(PHP_VERSION,'4.1.0')>=0); - } - function ServerInfo() { global $ADODB_FETCH_MODE; @@ -148,16 +114,16 @@ class ADODB_mssql extends ADOConnection { return " ISNULL($field, $ifNull) "; // if MS SQL Server } - function _insertid() + protected function _insertID($table = '', $column = '') { // SCOPE_IDENTITY() // Returns the last IDENTITY value inserted into an IDENTITY column in // the same scope. A scope is a module -- a stored procedure, trigger, // function, or batch. Thus, two statements are in the same scope if // they are in the same stored procedure, function, or batch. - if ($this->lastInsID !== false) { - return $this->lastInsID; // InsID from sp_executesql call - } else { + if ($this->lastInsID !== false) { + return $this->lastInsID; // InsID from sp_executesql call + } else { return $this->GetOne($this->identitySQL); } } @@ -165,37 +131,22 @@ class ADODB_mssql extends ADOConnection { /** - * Correctly quotes a string so that all strings are escaped. We prefix and append - * to the string single-quotes. - * An example is $db->qstr("Don't bother",magic_quotes_runtime()); - * - * @param s the string to quote - * @param [magic_quotes] if $s is GET/POST var, set to get_magic_quotes_gpc(). - * This undoes the stupidity of magic quotes for GPC. - * - * @return quoted string to be sent back to database - */ - function qstr($s,$magic_quotes=false) + * Correctly quotes a string so that all strings are escaped. + * We prefix and append to the string single-quotes. + * An example is $db->qstr("Don't bother"); + * + * @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 to be sent back to database + * + * @noinspection PhpUnusedParameterInspection + */ + function qStr($s, $magic_quotes=false) { - if (!$magic_quotes) { - return "'".str_replace("'",$this->replaceQuote,$s)."'"; - } - - // undo magic quotes for " unless sybase is on - $sybase = ini_get('magic_quotes_sybase'); - if (!$sybase) { - $s = str_replace('\\"','"',$s); - if ($this->replaceQuote == "\\'") // ' already quoted, no need to change anything - return "'$s'"; - else {// change \' to '' for sybase/mssql - $s = str_replace('\\\\','\\',$s); - return "'".str_replace("\\'",$this->replaceQuote,$s)."'"; - } - } else { - return "'".$s."'"; - } + return "'" . str_replace("'", $this->replaceQuote, $s) . "'"; } -// moodle change end - see readme_moodle.txt function _affectedrows() { @@ -245,6 +196,8 @@ class ADODB_mssql extends ADOConnection { function SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) { + $nrows = (int) $nrows; + $offset = (int) $offset; if ($nrows > 0 && $offset <= 0) { $sql = preg_replace( '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop." $nrows ",$sql); @@ -307,7 +260,9 @@ class ADODB_mssql extends ADOConnection { case 'A': $s .= "substring(convert(char(19),$col,0),18,2)"; break; - + case 'l': + $s .= "datename(dw,$col)"; + break; default: if ($ch == '\\') { $i++; @@ -325,8 +280,8 @@ class ADODB_mssql extends ADOConnection { { if ($this->transOff) return true; $this->transCnt += 1; - $ok = $this->Execute('BEGIN TRAN'); - return $ok; + $ok = $this->Execute('BEGIN TRAN'); + return $ok; } function CommitTrans($ok=true) @@ -449,29 +404,29 @@ class ADODB_mssql extends ADOConnection { global $ADODB_FETCH_MODE; $save = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - if ($this->fetchMode !== FALSE) { - $savem = $this->SetFetchMode(FALSE); - } + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + if ($this->fetchMode !== FALSE) { + $savem = $this->SetFetchMode(FALSE); + } - $rs = $this->Execute($sql); - if (isset($savem)) { - $this->SetFetchMode($savem); - } - $ADODB_FETCH_MODE = $save; + $rs = $this->Execute($sql); + if (isset($savem)) { + $this->SetFetchMode($savem); + } + $ADODB_FETCH_MODE = $save; - if (!is_object($rs)) { - return FALSE; - } + if (!is_object($rs)) { + return FALSE; + } $indexes = array(); while ($row = $rs->FetchRow()) { if ($primary && !$row[5]) continue; - $indexes[$row[0]]['unique'] = $row[6]; - $indexes[$row[0]]['columns'][] = $row[1]; - } - return $indexes; + $indexes[$row[0]]['unique'] = $row[6]; + $indexes[$row[0]]['columns'][] = $row[1]; + } + return $indexes; } function MetaForeignKeys($table, $owner=false, $upper=false) @@ -486,7 +441,7 @@ class ADODB_mssql extends ADOConnection { "select object_name(constid) as constraint_name, col_name(fkeyid, fkey) as column_name, object_name(rkeyid) as referenced_table_name, - col_name(rkeyid, rkey) as referenced_column_name + col_name(rkeyid, rkey) as referenced_column_name from sysforeignkeys where upper(object_name(fkeyid)) = $table order by constraint_name, referenced_table_name, keyno"; @@ -507,7 +462,11 @@ order by constraint_name, referenced_table_name, keyno"; foreach($arr as $k => $v) { foreach($v as $a => $b) { if ($upper) $a = strtoupper($a); - $arr2[$a] = $b; + if (is_array($arr2[$a])) { // a previous foreign key was define for this reference table, we merge the new one + $arr2[$a] = array_merge($arr2[$a], $b); + } else { + $arr2[$a] = $b; + } } } return $arr2; @@ -517,22 +476,24 @@ order by constraint_name, referenced_table_name, keyno"; function MetaDatabases() { if(@mssql_select_db("master")) { - $qry=$this->metaDatabasesSQL; - if($rs=@mssql_query($qry,$this->_connectionID)){ - $tmpAr=$ar=array(); - while($tmpAr=@mssql_fetch_row($rs)) - $ar[]=$tmpAr[0]; - @mssql_select_db($this->database); - if(sizeof($ar)) - return($ar); - else - return(false); - } else { - @mssql_select_db($this->database); - return(false); - } - } - return(false); + $qry = $this->metaDatabasesSQL; + if($rs = @mssql_query($qry,$this->_connectionID)) { + $tmpAr = $ar = array(); + while($tmpAr = @mssql_fetch_row($rs)) { + $ar[]=$tmpAr[0]; + } + @mssql_select_db($this->database); + if(sizeof($ar)) { + return($ar); + } else { + return(false); + } + } else { + @mssql_select_db($this->database); + return(false); + } + } + return(false); } // "Stein-Aksel Basma" <basma@accelero.no> @@ -605,14 +566,18 @@ order by constraint_name, referenced_table_name, keyno"; if (!$id) return false; $arr = mssql_fetch_array($id); @mssql_free_result($id); - if (is_array($arr)) return $arr[0]; - else return -1; + if (is_array($arr)) { + return $arr[0]; + } else { + return -1; + } } // returns true or false, newconnect supported since php 5.1.0. function _connect($argHostname, $argUsername, $argPassword, $argDatabasename,$newconnect=false) { if (!function_exists('mssql_pconnect')) return null; + if (!empty($this->port)) $argHostname .= ":".$this->port; $this->_connectionID = mssql_connect($argHostname,$argUsername,$argPassword,$newconnect); if ($this->_connectionID === false) return false; if ($argDatabasename) return $this->SelectDB($argDatabasename); @@ -624,6 +589,7 @@ order by constraint_name, referenced_table_name, keyno"; function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) { if (!function_exists('mssql_pconnect')) return null; + if (!empty($this->port)) $argHostname .= ":".$this->port; $this->_connectionID = mssql_pconnect($argHostname,$argUsername,$argPassword); if ($this->_connectionID === false) return false; @@ -637,9 +603,9 @@ order by constraint_name, referenced_table_name, keyno"; } function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename) - { + { return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename, true); - } + } function Prepare($sql) { @@ -654,38 +620,39 @@ order by constraint_name, referenced_table_name, keyno"; function PrepareSP($sql,$param=true) { - if (!$this->_has_mssql_init) { - ADOConnection::outp( "PrepareSP: mssql_init only available since PHP 4.1.0"); - return $sql; - } $stmt = mssql_init($sql,$this->_connectionID); if (!$stmt) return $sql; return array($sql,$stmt); } // returns concatenated string - // MSSQL requires integers to be cast as strings - // automatically cast every datatype to VARCHAR(255) - // @author David Rogers (introspectshun) - function Concat() - { - $s = ""; - $arr = func_get_args(); - - // Split single record on commas, if possible - if (sizeof($arr) == 1) { - foreach ($arr as $arg) { - $args = explode(',', $arg); - } - $arr = $args; - } - - array_walk($arr, create_function('&$v', '$v = "CAST(" . $v . " AS VARCHAR(255))";')); - $s = implode('+',$arr); - if (sizeof($arr) > 0) return "$s"; + // MSSQL requires integers to be cast as strings + // automatically cast every datatype to VARCHAR(255) + // @author David Rogers (introspectshun) + function Concat() + { + $s = ""; + $arr = func_get_args(); + + // Split single record on commas, if possible + if (sizeof($arr) == 1) { + foreach ($arr as $arg) { + $args = explode(',', $arg); + } + $arr = $args; + } + + array_walk( + $arr, + function(&$value, $key) { + $value = "CAST(" . $value . " AS VARCHAR(255))"; + } + ); + $s = implode('+',$arr); + if (sizeof($arr) > 0) return "$s"; return ''; - } + } /* Usage: @@ -707,11 +674,6 @@ order by constraint_name, referenced_table_name, keyno"; */ function Parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=4000, $type=false) { - if (!$this->_has_mssql_init) { - ADOConnection::outp( "Parameter: mssql_bind only available since PHP 4.1.0"); - return false; - } - $isNull = is_null($var); // php 4.0.4 and above... if ($type === false) @@ -721,7 +683,7 @@ order by constraint_name, referenced_table_name, keyno"; case 'double': $type = SQLFLT8; break; case 'integer': $type = SQLINT4; break; case 'boolean': $type = SQLINT1; break; # SQLBIT not supported in 4.1.0 - } + } if ($this->debug) { $prefix = ($isOutput) ? 'Out' : 'In'; @@ -729,7 +691,7 @@ order by constraint_name, referenced_table_name, keyno"; ADOConnection::outp( "{$prefix}Parameter(\$stmt, \$php_var='$var', \$name='$name', \$maxLen=$maxLen, \$type=$ztype);"); } /* - See http://phplens.com/lens/lensforum/msgs.php?id=7231 + See PHPLens Issue No: 7231 RETVAL is HARD CODED into php_mssql extension: The return value (a long integer value) is treated like a special OUTPUT parameter, @@ -773,11 +735,11 @@ order by constraint_name, referenced_table_name, keyno"; # bind input params with sp_executesql: # see http://www.quest-pipelines.com/newsletter-v3/0402_F.htm # works only with sql server 7 and newer - $getIdentity = false; - if (!is_array($sql) && preg_match('/^\\s*insert/i', $sql)) { - $getIdentity = true; - $sql .= (preg_match('/;\\s*$/i', $sql) ? ' ' : '; ') . $this->identitySQL; - } + $getIdentity = false; + if (!is_array($sql) && preg_match('/^\\s*insert/i', $sql)) { + $getIdentity = true; + $sql .= (preg_match('/;\\s*$/i', $sql) ? ' ' : '; ') . $this->identitySQL; + } if (!is_array($sql)) $sql = $this->Prepare($sql); $params = ''; $decl = ''; @@ -798,7 +760,16 @@ order by constraint_name, referenced_table_name, keyno"; $decl .= "@P$i NVARCHAR($len)"; } - $params .= "@P$i=N". (strncmp($v,"'",1)==0? $v : $this->qstr($v)); + if(substr($v,0,1) == "'" && substr($v,-1,1) == "'") + /* + * String is already fully quoted + */ + $inputVar = $v; + else + $inputVar = $db->this($v); + + $params .= "@P$i=N" . $inputVar; + } else if (is_integer($v)) { $decl .= "@P$i INT"; $params .= "@P$i=".$v; @@ -817,20 +788,20 @@ order by constraint_name, referenced_table_name, keyno"; $decl = $this->qstr($decl); if ($this->debug) ADOConnection::outp("<font size=-1>sp_executesql N{$sql[1]},N$decl,$params</font>"); $rez = mssql_query("sp_executesql N{$sql[1]},N$decl,$params", $this->_connectionID); - if ($getIdentity) { - $arr = @mssql_fetch_row($rez); - $this->lastInsID = isset($arr[0]) ? $arr[0] : false; - @mssql_data_seek($rez, 0); - } + if ($getIdentity) { + $arr = @mssql_fetch_row($rez); + $this->lastInsID = isset($arr[0]) ? $arr[0] : false; + @mssql_data_seek($rez, 0); + } } else if (is_array($sql)) { # PrepareSP() $rez = mssql_execute($sql[1]); - $this->lastInsID = false; + $this->lastInsID = false; } else { $rez = mssql_query($sql,$this->_connectionID); - $this->lastInsID = false; + $this->lastInsID = false; } return $rez; } @@ -838,33 +809,54 @@ order by constraint_name, referenced_table_name, keyno"; // returns true or false function _close() { - if ($this->transCnt) $this->RollbackTrans(); - $rez = @mssql_close($this->_connectionID); + if ($this->transCnt) { + $this->RollbackTrans(); + } + if($this->_connectionID) { + $rez = mssql_close($this->_connectionID); + } $this->_connectionID = false; return $rez; } - // mssql uses a default date like Dec 30 2000 12:00AM - static function UnixDate($v) - { - return ADORecordSet_array_mssql::UnixDate($v); - } - static function UnixTimeStamp($v) + + /** + * Returns a substring of a varchar type field + * + * The SQL server version varies because the length is mandatory, so + * we append a reasonable string length + * + * @param string $fld The field to sub-string + * @param int $start The start point + * @param int $length An optional length + * + * @return The SQL text + */ + function substr($fld,$start,$length=0) { - return ADORecordSet_array_mssql::UnixTimeStamp($v); + if ($length == 0) + /* + * The length available to varchar is 2GB, but that makes no + * sense in a substring, so I'm going to arbitrarily limit + * the length to 1K, but you could change it if you want + */ + $length = 1024; + + $text = "SUBSTRING($fld,$start,$length)"; + return $text; } } /*-------------------------------------------------------------------------------------- - Class Name: Recordset + Class Name: Recordset --------------------------------------------------------------------------------------*/ class ADORecordset_mssql extends ADORecordSet { var $databaseType = "mssql"; var $canSeek = true; - var $hasFetchAssoc; // see http://phplens.com/lens/lensforum/msgs.php?id=6083 + var $hasFetchAssoc; // see PHPLens Issue No: 6083 // _mths works only in non-localised system function __construct($id,$mode=false) @@ -878,7 +870,7 @@ class ADORecordset_mssql extends ADORecordSet { } $this->fetchMode = $mode; - return parent::__construct($id,$mode); + return parent::__construct($id); } @@ -914,7 +906,7 @@ class ADORecordset_mssql extends ADORecordSet { } } - return $this->fields[$this->bind[strtoupper($colname)]]; + return $this->fields[$this->bind[strtoupper($colname)]]; } /* Returns: an object containing field information. @@ -954,7 +946,7 @@ class ADORecordset_mssql extends ADORecordSet { } else { if ($this->hasFetchAssoc) {// only for PHP 4.2.0 or later - $this->fields = @mssql_fetch_assoc($this->_queryID); + $this->fields = @mssql_fetch_assoc($this->_queryID); } else { $flds = @mssql_fetch_array($this->_queryID); if (is_array($flds)) { @@ -1011,9 +1003,9 @@ class ADORecordset_mssql extends ADORecordSet { $this->fields = @mssql_fetch_assoc($this->_queryID); else { $this->fields = @mssql_fetch_array($this->_queryID); - if (@is_array($$this->fields)) { + if (@is_array($this->fields)) { $fassoc = array(); - foreach($$this->fields as $k => $v) { + foreach($this->fields as $k => $v) { if (is_integer($k)) continue; $fassoc[$k] = $v; } @@ -1059,108 +1051,43 @@ class ADORecordset_mssql extends ADORecordSet { return true; } - // mssql uses a default date like Dec 30 2000 12:00AM - static function UnixDate($v) + /** + * Returns the maximum size of a MetaType C field. Because of the + * database design, SQL Server places no limits on the size of data inserted + * Although the actual limit is 2^31-1 bytes. + * + * @return int + */ + function charMax() { - return ADORecordSet_array_mssql::UnixDate($v); + return ADODB_STRINGMAX_NOLIMIT; } - static function UnixTimeStamp($v) + /** + * Returns the maximum size of a MetaType X field. Because of the + * database design, SQL Server places no limits on the size of data inserted + * Although the actual limit is 2^31-1 bytes. + * + * @return int + */ + function textMax() { - return ADORecordSet_array_mssql::UnixTimeStamp($v); + return ADODB_STRINGMAX_NOLIMIT; } } -class ADORecordSet_array_mssql extends ADORecordSet_array { - function __construct($id=-1,$mode=false) - { - parent::__construct($id,$mode); - } - - // mssql uses a default date like Dec 30 2000 12:00AM - static function UnixDate($v) - { - - if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) return parent::UnixDate($v); - - global $ADODB_mssql_mths,$ADODB_mssql_date_order; - - //Dec 30 2000 12:00AM - if ($ADODB_mssql_date_order == 'dmy') { - if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4})|" ,$v, $rr)) { - return parent::UnixDate($v); - } - if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; - - $theday = $rr[1]; - $themth = substr(strtoupper($rr[2]),0,3); - } else { - if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4})|" ,$v, $rr)) { - return parent::UnixDate($v); - } - if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; - - $theday = $rr[2]; - $themth = substr(strtoupper($rr[1]),0,3); - } - $themth = $ADODB_mssql_mths[$themth]; - if ($themth <= 0) return false; - // h-m-s-MM-DD-YY - return mktime(0,0,0,$themth,$theday,$rr[3]); - } - - static function UnixTimeStamp($v) - { - - if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) return parent::UnixTimeStamp($v); - - global $ADODB_mssql_mths,$ADODB_mssql_date_order; - - //Dec 30 2000 12:00AM - if ($ADODB_mssql_date_order == 'dmy') { - if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|" - ,$v, $rr)) return parent::UnixTimeStamp($v); - if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; - - $theday = $rr[1]; - $themth = substr(strtoupper($rr[2]),0,3); - } else { - if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|" - ,$v, $rr)) return parent::UnixTimeStamp($v); - if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; - - $theday = $rr[2]; - $themth = substr(strtoupper($rr[1]),0,3); - } - - $themth = $ADODB_mssql_mths[$themth]; - if ($themth <= 0) return false; - - switch (strtoupper($rr[6])) { - case 'P': - if ($rr[4]<12) $rr[4] += 12; - break; - case 'A': - if ($rr[4]==12) $rr[4] = 0; - break; - default: - break; - } - // h-m-s-MM-DD-YY - return mktime($rr[4],$rr[5],0,$themth,$theday,$rr[3]); - } -} +class ADORecordSet_array_mssql extends ADORecordSet_array {} /* Code Example 1: -select object_name(constid) as constraint_name, - object_name(fkeyid) as table_name, - col_name(fkeyid, fkey) as column_name, +select object_name(constid) as constraint_name, + object_name(fkeyid) as table_name, + col_name(fkeyid, fkey) as column_name, object_name(rkeyid) as referenced_table_name, - col_name(rkeyid, rkey) as referenced_column_name + col_name(rkeyid, rkey) as referenced_column_name from sysforeignkeys where object_name(fkeyid) = x order by constraint_name, table_name, referenced_table_name, keyno diff --git a/libraries/adodb/drivers/adodb-mssql_n.inc.php b/libraries/adodb/drivers/adodb-mssql_n.inc.php index 2bbac5b28..236c1546a 100644 --- a/libraries/adodb/drivers/adodb-mssql_n.inc.php +++ b/libraries/adodb/drivers/adodb-mssql_n.inc.php @@ -1,46 +1,27 @@ <?php - -/// $Id $ - -/////////////////////////////////////////////////////////////////////////// -// // -// NOTICE OF COPYRIGHT // -// // -// ADOdb - Database Abstraction Library for PHP // -// http://adodb.sourceforge.net/ // -// // -// Copyright (c) 2000-2014 John Lim (jlim\@natsoft.com.my) // -// All rights reserved. // -// Released under both BSD license and LGPL library license. // -// Whenever there is any discrepancy between the two licenses, // -// the BSD license will take precedence // -// // -// Moodle - Modular Object-Oriented Dynamic Learning Environment // -// http://moodle.com // -// // -// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com // -// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details: // -// // -// http://www.gnu.org/copyleft/gpl.html // -// // -/////////////////////////////////////////////////////////////////////////// - /** -* MSSQL Driver with auto-prepended "N" for correct unicode storage -* of SQL literal strings. Intended to be used with MSSQL drivers that -* are sending UCS-2 data to MSSQL (FreeTDS and ODBTP) in order to get -* true cross-db compatibility from the application point of view. -*/ + * MSSQL Driver with auto-prepended "N" for correct unicode storage of SQL literal strings. + * + * Intended to be used with MSSQL drivers that are sending UCS-2 data to MSSQL + * (FreeTDS and ODBTP) in order to get true cross-db compatibility from the + * application point of view. + * + * 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(); @@ -59,18 +40,18 @@ class ADODB_mssql_n extends ADODB_mssql { return ADODB_mssql::_query($sql,$inputarr); } - /** + /** * This function will intercept all the literals used in the SQL, prepending the "N" char to them * in order to allow mssql to store properly data sent in the correct UCS-2 encoding (by freeTDS * and ODBTP) keeping SQL compatibility at ADOdb level (instead of hacking every project to add * the "N" notation when working against MSSQL. * - * The orginal note indicated that this hack should only be used if ALL the char-based columns + * The original note indicated that this hack should only be used if ALL the char-based columns * in your DB are of type nchar, nvarchar and ntext, but testing seems to indicate that SQL server * doesn't seem to care if the statement is used against char etc fields. * * @todo This function should raise an ADOdb error if one of the transformations fail - * + * * @param mixed $inboundData Either a string containing an SQL statement * or an array with resources from prepared statements * @@ -79,22 +60,22 @@ class ADODB_mssql_n extends ADODB_mssql { function _appendN($inboundData) { $inboundIsArray = false; - + if (is_array($inboundData)) { $inboundIsArray = true; $inboundArray = $inboundData; } else $inboundArray = (array)$inboundData; - + /* * All changes will be placed here */ $outboundArray = $inboundArray; - + foreach($inboundArray as $inboundKey=>$inboundValue) { - + if (is_resource($inboundValue)) { /* @@ -105,7 +86,7 @@ class ADODB_mssql_n extends ADODB_mssql { continue; } - + if (strpos($inboundValue, SINGLEQUOTE) === false) { /* @@ -120,11 +101,11 @@ class ADODB_mssql_n extends ADODB_mssql { * Check we haven't an odd number of single quotes (this can cause problems below * and should be considered one wrong SQL). Exit with debug info. */ - if ((substr_count($inboundValue, SINGLEQUOTE) & 1)) + if ((substr_count($inboundValue, SINGLEQUOTE) & 1)) { if ($this->debug) ADOConnection::outp("{$this->databaseType} internal transformation: not converted. Wrong number of quotes (odd)"); - + break; } @@ -135,9 +116,9 @@ class ADODB_mssql_n extends ADODB_mssql { $regexp = '/(\\\\' . SINGLEQUOTE . '[^' . SINGLEQUOTE . '])/'; if (preg_match($regexp, $inboundValue)) { - if ($this->debug) + if ($this->debug) ADOConnection::outp("{$this->databaseType} internal transformation: not converted. Found bad use of backslash + single quote"); - + break; } @@ -147,16 +128,16 @@ class ADODB_mssql_n extends ADODB_mssql { $pairs = array(); $regexp = '/(' . SINGLEQUOTE . SINGLEQUOTE . ')/'; preg_match_all($regexp, $inboundValue, $list_of_pairs); - + if ($list_of_pairs) { foreach (array_unique($list_of_pairs[0]) as $key=>$value) $pairs['<@#@#@PAIR-'.$key.'@#@#@>'] = $value; - - + + if (!empty($pairs)) $inboundValue = str_replace($pairs, array_keys($pairs), $inboundValue); - + } /* @@ -165,13 +146,13 @@ class ADODB_mssql_n extends ADODB_mssql { $literals = array(); $regexp = '/(N?' . SINGLEQUOTE . '.*?' . SINGLEQUOTE . ')/is'; preg_match_all($regexp, $inboundValue, $list_of_literals); - + if ($list_of_literals) { foreach (array_unique($list_of_literals[0]) as $key=>$value) $literals['<#@#@#LITERAL-'.$key.'#@#@#>'] = $value; - - + + if (!empty($literals)) $inboundValue = str_replace($literals, array_keys($literals), $inboundValue); } @@ -184,11 +165,11 @@ class ADODB_mssql_n extends ADODB_mssql { foreach ($literals as $key=>$value) { if (!is_numeric(trim($value, SINGLEQUOTE))) /* - * Non numeric string, prepend our dear N, whilst + * Non numeric string, prepend our dear N, whilst * Trimming potentially existing previous "N" */ - $literals[$key] = 'N' . trim($value, 'N'); - + $literals[$key] = 'N' . trim($value, 'N'); + } } @@ -197,7 +178,7 @@ class ADODB_mssql_n extends ADODB_mssql { */ if (!empty($literals)) $inboundValue = str_replace(array_keys($literals), $literals, $inboundValue); - + /* * Any pairs followed by N' must be switched to N' followed by those pairs @@ -210,40 +191,36 @@ class ADODB_mssql_n extends ADODB_mssql { */ if (!empty($pairs)) $inboundValue = str_replace(array_keys($pairs), $pairs, $inboundValue); - + /* * Print transformation if debug = on */ if (strcmp($inboundValue,$inboundArray[$inboundKey]) <> 0 && $this->debug) ADOConnection::outp("{$this->databaseType} internal transformation: {$inboundArray[$inboundKey]} to {$inboundValue}"); - + if (strcmp($inboundValue,$inboundArray[$inboundKey]) <> 0) /* * Place the transformed value into the outbound array */ $outboundArray[$inboundKey] = $inboundValue; } - + /* * Any transformations are in the $outboundArray */ if ($inboundIsArray) return $outboundArray; - + /* * We passed a string in originally */ return $outboundArray[0]; - + } } class ADORecordset_mssql_n extends ADORecordset_mssql { var $databaseType = "mssql_n"; - function __construct($id,$mode=false) - { - parent::__construct($id,$mode); - } } diff --git a/libraries/adodb/drivers/adodb-mssqlnative.inc.php b/libraries/adodb/drivers/adodb-mssqlnative.inc.php index 23eb2c03d..36dc54339 100644 --- a/libraries/adodb/drivers/adodb-mssqlnative.inc.php +++ b/libraries/adodb/drivers/adodb-mssqlnative.inc.php @@ -1,24 +1,26 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. -Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Native mssql driver. Requires mssql client. Works on Windows. - http://www.microsoft.com/sql/technologies/php/default.mspx - To configure for Unix, see - http://phpbuilder.com/columns/alberto20000919.php3 - - $stream = sqlsrv_get_field($stmt, $index, SQLSRV_SQLTYPE_STREAM(SQLSRV_ENC_BINARY)); - stream_filter_append($stream, "convert.iconv.ucs-2/utf-8"); // Voila, UTF-8 can be read directly from $stream - -*/ +/** + * Native MSSQL driver. + * + * Requires mssql client. Works on Windows. + * https://docs.microsoft.com/sql/connect/php + * + * 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(); @@ -43,49 +45,19 @@ if (!function_exists('sqlsrv_log_set_subsystems')) { } } - -//---------------------------------------------------------------- -// MSSQL returns dates with the format Oct 13 2002 or 13 Oct 2002 -// and this causes tons of problems because localized versions of -// MSSQL will return the dates in dmy or mdy order; and also the -// month strings depends on what language has been configured. The -// following two variables allow you to control the localization -// settings - Ugh. -// -// MORE LOCALIZATION INFO -// ---------------------- -// To configure datetime, look for and modify sqlcommn.loc, -// typically found in c:\mssql\install -// Also read : -// http://support.microsoft.com/default.aspx?scid=kb;EN-US;q220918 -// Alternatively use: -// CONVERT(char(12),datecol,120) -// -// Also if your month is showing as month-1, -// e.g. Jan 13, 2002 is showing as 13/0/2002, then see -// http://phplens.com/lens/lensforum/msgs.php?id=7048&x=1 -// it's a localisation problem. -//---------------------------------------------------------------- - - -// has datetime converstion to YYYY-MM-DD format, and also mssql_fetch_assoc -if (ADODB_PHPVER >= 0x4300) { -// docs say 4.2.0, but testing shows only since 4.3.0 does it work! - ini_set('mssql.datetimeconvert',0); -} else { - global $ADODB_mssql_mths; // array, months must be upper-case - $ADODB_mssql_date_order = 'mdy'; - $ADODB_mssql_mths = array( - 'JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6, - 'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12); -} - class ADODB_mssqlnative extends ADOConnection { var $databaseType = "mssqlnative"; var $dataProvider = "mssqlnative"; var $replaceQuote = "''"; // string to use to replace quotes var $fmtDate = "'Y-m-d'"; var $fmtTimeStamp = "'Y-m-d\TH:i:s'"; + /** + * Enabling InsertID capability will cause execution of an extra query + * {@see $identitySQL} after each INSERT statement. To improve performance + * when inserting a large number of records, you should switch this off by + * calling {@see enableLastInsertID enableLastInsertID(false)}. + * @var bool $hasInsertID + */ var $hasInsertID = true; var $substr = "substring"; var $length = 'len'; @@ -124,8 +96,10 @@ class ADODB_mssqlnative extends ADOConnection { var $uniqueOrderBy = true; var $_bindInputArray = true; var $_dropSeqSQL = "drop table %s"; - var $connectionInfo = array(); + + var $connectionInfo = array('ReturnDatesAsStrings'=>true); var $cachedSchemaFlush = false; + var $sequences = false; var $mssql_version = ''; @@ -163,7 +137,7 @@ class ADODB_mssqlnative extends ADOConnection { } function ServerInfo() { - global $ADODB_FETCH_MODE; + global $ADODB_FETCH_MODE; static $arr = false; if (is_array($arr)) return $arr; @@ -187,14 +161,23 @@ class ADODB_mssqlnative extends ADOConnection { return " ISNULL($field, $ifNull) "; // if MS SQL Server } - function _insertid() + public function enableLastInsertID($enable = true) { + $this->hasInsertID = $enable; + $this->lastInsID = false; + } + + /** + * Get the last value inserted into an IDENTITY column. + * + * The value will actually be set in {@see _query()} when executing an + * INSERT statement, but only if the connection's $hasInsertId property + * is true; this can be set with {@see enableLastInsertId()}. + * + * @inheritDoc + */ + protected function _insertID($table = '', $column = '') { - // SCOPE_IDENTITY() - // Returns the last IDENTITY value inserted into an IDENTITY column in - // the same scope. A scope is a module -- a stored procedure, trigger, - // function, or batch. Thus, two statements are in the same scope if - // they are in the same stored procedure, function, or batch. - return $this->lastInsertID; + return $this->lastInsID; } function _affectedrows() @@ -204,8 +187,6 @@ class ADODB_mssqlnative extends ADOConnection { } function GenID($seq='adodbseq',$start=1) { - if (!$this->mssql_version) - $this->ServerVersion(); switch($this->mssql_version){ case 9: case 10: @@ -219,9 +200,6 @@ class ADODB_mssqlnative extends ADOConnection { function CreateSequence($seq='adodbseq',$start=1) { - if (!$this->mssql_version) - $this->ServerVersion(); - switch($this->mssql_version){ case 9: case 10: @@ -231,7 +209,6 @@ class ADODB_mssqlnative extends ADOConnection { return $this->CreateSequence2012($seq, $start); break; } - } /** @@ -321,9 +298,26 @@ class ADODB_mssqlnative extends ADOConnection { // 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; + if (!$col) { + $col = $this->sysTimeStamp; + } $s = ''; + $ConvertableFmt=array( + "m/d/Y"=>101, "m/d/y"=>101 // US + ,"Y.m.d"=>102, "y.m.d"=>102 // ANSI + ,"d/m/Y"=>103, "d/m/y"=>103 // French /english + ,"d.m.Y"=>104, "d.m.y"=>104 // German + ,"d-m-Y"=>105, "d-m-y"=>105 // Italian + ,"m-d-Y"=>110, "m-d-y"=>110 // US Dash + ,"Y/m/d"=>111, "y/m/d"=>111 // Japan + ,"Ymd"=>112, "ymd"=>112 // ISO + ,"H:i:s"=>108 // Time + ); + if (key_exists($fmt,$ConvertableFmt)) { + return "convert (varchar ,$col," . $ConvertableFmt[$fmt] . ")"; + } + $len = strlen($fmt); for ($i=0; $i < $len; $i++) { if ($s) $s .= '+'; @@ -365,7 +359,9 @@ class ADODB_mssqlnative extends ADOConnection { case 'A': $s .= "substring(convert(char(19),$col,0),18,2)"; break; - + case 'l': + $s .= "datename(dw,$col)"; + break; default: if ($ch == '\\') { $i++; @@ -397,6 +393,7 @@ class ADODB_mssqlnative extends ADOConnection { sqlsrv_commit($this->_connectionID); return true; } + function RollbackTrans() { if ($this->transOff) return true; @@ -458,8 +455,6 @@ class ADODB_mssqlnative extends ADOConnection { $this->_errorMsg .= "Error Code: ".$arrError[ 'code']."\n"; $this->_errorMsg .= "Message: ".$arrError[ 'message']."\n"; } - } else { - $this->_errorMsg = "No errors found"; } return $this->_errorMsg; } @@ -467,30 +462,75 @@ class ADODB_mssqlnative extends ADOConnection { function ErrorNo() { $err = sqlsrv_errors(SQLSRV_ERR_ALL); - if($err[0]) return $err[0]['code']; - else return 0; + if ($err && $err[0]) + return $err[0]['code']; + else + return 0; } // returns true or false function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) { - if (!function_exists('sqlsrv_connect')) return null; - $connectionInfo = $this->connectionInfo; - $connectionInfo["Database"]=$argDatabasename; - $connectionInfo["UID"]=$argUsername; - $connectionInfo["PWD"]=$argPassword; - - foreach ($this->connectionParameters as $parameter=>$value) - $connectionInfo[$parameter] = $value; - - if ($this->debug) ADOConnection::outp("<hr>connecting... hostname: $argHostname params: ".var_export($connectionInfo,true)); - //if ($this->debug) ADOConnection::outp("<hr>_connectionID before: ".serialize($this->_connectionID)); - if(!($this->_connectionID = sqlsrv_connect($argHostname,$connectionInfo))) { - if ($this->debug) ADOConnection::outp( "<hr><b>errors</b>: ".print_r( sqlsrv_errors(), true)); + if (!function_exists('sqlsrv_connect')) + { + if ($this->debug) + ADOConnection::outp('Microsoft SQL Server native driver (mssqlnative) not installed'); + return null; + } + + if (!empty($this->port)) + /* + * Port uses a comma + */ + $argHostname .= ",".$this->port; + + $connectionInfo = $this->connectionInfo; + $connectionInfo["Database"] = $argDatabasename; + if ((string)$argUsername != '' || (string)$argPassword != '') + { + /* + * If they pass either a userid or password, we assume + * SQL Server authentication + */ + $connectionInfo["UID"] = $argUsername; + $connectionInfo["PWD"] = $argPassword; + + if ($this->debug) + ADOConnection::outp('userid or password supplied, attempting connection with SQL Server Authentication'); + + } + else + { + /* + * If they don't pass either value, we won't add them to the + * connection parameters. This will then force an attempt + * to use windows authentication + */ + if ($this->debug) + + ADOConnection::outp('No userid or password supplied, attempting connection with Windows Authentication'); + } + + + /* + * Now merge in the passed connection parameters setting + */ + foreach ($this->connectionParameters as $options) + { + foreach($options as $parameter=>$value) + $connectionInfo[$parameter] = $value; + } + + if ($this->debug) ADOConnection::outp("connecting to host: $argHostname params: ".var_export($connectionInfo,true)); + if(!($this->_connectionID = @sqlsrv_connect($argHostname,$connectionInfo))) + { + if ($this->debug) + ADOConnection::outp( 'Connection Failed: '.print_r( sqlsrv_errors(), true)); return false; } - //if ($this->debug) ADOConnection::outp(" _connectionID after: ".serialize($this->_connectionID)); - //if ($this->debug) ADOConnection::outp("<hr>defined functions: <pre>".var_export(get_defined_functions(),true)."</pre>"); + + $this->ServerVersion(); + return true; } @@ -501,13 +541,10 @@ class ADODB_mssqlnative extends ADOConnection { return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename); } + function Prepare($sql) { return $sql; // prepare does not work properly with bind parameters as bind parameters are managed by sqlsrv_prepare! - - $stmt = sqlsrv_prepare( $this->_connectionID, $sql); - if (!$stmt) return $sql; - return array($sql,$stmt); } // returns concatenated string @@ -527,7 +564,12 @@ class ADODB_mssqlnative extends ADOConnection { $arr = $args; } - array_walk($arr, create_function('&$v', '$v = "CAST(" . $v . " AS VARCHAR(255))";')); + array_walk( + $arr, + function(&$value, $key) { + $value = "CAST(" . $value . " AS VARCHAR(255))"; + } + ); $s = implode('+',$arr); if (sizeof($arr) > 0) return "$s"; @@ -557,34 +599,67 @@ class ADODB_mssqlnative extends ADOConnection { return $this->Execute($sql) != false; } - // returns query ID if successful, otherwise false - function _query($sql,$inputarr=false) + /** + * Execute a query. + * + * If executing an INSERT statement and $hasInsertId is true, will set + * $lastInsId. + * + * @param string $sql + * @param array $inputarr + * @return resource|false Query Id if successful, otherwise false + */ + function _query($sql, $inputarr = false) { $this->_errorMsg = false; - if (is_array($sql)) $sql = $sql[1]; + if (is_array($sql)) { + $sql = $sql[1]; + } - $insert = false; - // handle native driver flaw for retrieving the last insert ID - if(preg_match('/^\W*insert[\s\w()",.]+values\s*\((?:[^;\']|\'\'|(?:(?:\'\')*\'[^\']+\'(?:\'\')*))*;?$/i', $sql)) { - $insert = true; - $sql .= '; '.$this->identitySQL; // select scope_identity() + // Handle native driver flaw for retrieving the last insert ID + if ($this->hasInsertID) { + // Check if it's an INSERT statement + $retrieveLastInsertID = preg_match( + '/^\W*insert[\s\w()[\]",.]+values\s*\((?:[^;\']|\'\'|(?:(?:\'\')*\'[^\']+\'(?:\'\')*))*;?$/i', + $sql + ); + if ($retrieveLastInsertID) { + // Append the identity SQL, so it is executed in the same + // scope as the insert query. + $sql .= '; ' . $this->identitySQL; + } + } else { + $retrieveLastInsertID = false; } - if($inputarr) { + + if ($inputarr) { + // Ensure that the input array is indexed numerically, as required + // by sqlsrv_query(). If param() was used to create portable binds + // then the array might be associative. + $inputarr = array_values($inputarr); $rez = sqlsrv_query($this->_connectionID, $sql, $inputarr); } else { - $rez = sqlsrv_query($this->_connectionID,$sql); + $rez = sqlsrv_query($this->_connectionID, $sql); } - if ($this->debug) ADOConnection::outp("<hr>running query: ".var_export($sql,true)."<hr>input array: ".var_export($inputarr,true)."<hr>result: ".var_export($rez,true)); + if ($this->debug) { + ADOConnection::outp("<hr>running query: " . var_export($sql, true) + . "<hr>input array: " . var_export($inputarr, true) + . "<hr>result: " . var_export($rez, true) + ); + } - if(!$rez) { + $this->lastInsID = false; + if (!$rez) { $rez = false; - } else if ($insert) { - // retrieve the last insert ID (where applicable) - while ( sqlsrv_next_result($rez) ) { + } elseif ($retrieveLastInsertID) { + // Get the inserted id from the last result + // Note: loop is required as server may return more than one row, + // e.g. if triggers are involved (see #41) + while (sqlsrv_next_result($rez)) { sqlsrv_fetch($rez); - $this->lastInsertID = sqlsrv_get_field($rez, 0); + $this->lastInsID = sqlsrv_get_field($rez, 0, SQLSRV_PHPTYPE_INT); } } return $rez; @@ -593,22 +668,16 @@ class ADODB_mssqlnative extends ADOConnection { // returns true or false function _close() { - if ($this->transCnt) $this->RollbackTrans(); - $rez = @sqlsrv_close($this->_connectionID); + if ($this->transCnt) { + $this->RollbackTrans(); + } + if($this->_connectionID) { + $rez = sqlsrv_close($this->_connectionID); + } $this->_connectionID = false; return $rez; } - // mssql uses a default date like Dec 30 2000 12:00AM - static function UnixDate($v) - { - return ADORecordSet_array_mssqlnative::UnixDate($v); - } - - static function UnixTimeStamp($v) - { - return ADORecordSet_array_mssqlnative::UnixTimeStamp($v); - } function MetaIndexes($table,$primary=false, $owner = false) { @@ -667,7 +736,7 @@ class ADODB_mssqlnative extends ADOConnection { where upper(object_name(fkeyid)) = $table order by constraint_name, referenced_table_name, keyno"; - $constraints =& $this->GetArray($sql); + $constraints = $this->GetArray($sql); $ADODB_FETCH_MODE = $save; @@ -683,7 +752,11 @@ class ADODB_mssqlnative extends ADOConnection { foreach($arr as $k => $v) { foreach($v as $a => $b) { if ($upper) $a = strtoupper($a); - $arr2[$a] = $b; + if (is_array($arr2[$a])) { // a previous foreign key was define for this reference table, we merge the new one + $arr2[$a] = array_merge($arr2[$a], $b); + } else { + $arr2[$a] = $b; + } } } return $arr2; @@ -693,7 +766,7 @@ class ADODB_mssqlnative extends ADOConnection { function MetaDatabases() { $this->SelectDB("master"); - $rs =& $this->Execute($this->metaDatabasesSQL); + $rs = $this->Execute($this->metaDatabasesSQL); $rows = $rs->GetRows(); $ret = array(); for($i=0;$i<count($rows);$i++) { @@ -749,7 +822,9 @@ class ADODB_mssqlnative extends ADOConnection { } function MetaColumns($table, $upper=true, $schema=false){ - # start adg + /* + * A simple caching mechanism, to be replaced in ADOdb V6 + */ static $cached_columns = array(); if ($this->cachedSchemaFlush) $cached_columns = array(); @@ -757,10 +832,7 @@ class ADODB_mssqlnative extends ADOConnection { if (array_key_exists($table,$cached_columns)){ return $cached_columns[$table]; } - # end adg - if (!$this->mssql_version) - $this->ServerVersion(); $this->_findschema($table,$schema); if ($schema) { @@ -794,7 +866,7 @@ class ADODB_mssqlnative extends ADOConnection { $fld->type = $rs->fields[1]; $fld->max_length = $rs->fields[2]; $fld->precision = $rs->fields[3]; - $fld->scale = $rs->fields[4]; + $fld->scale = $rs->fields[4]; $fld->not_null =!$rs->fields[5]; $fld->has_default = $rs->fields[6]; $fld->xtype = $rs->fields[7]; @@ -805,7 +877,7 @@ class ADODB_mssqlnative extends ADOConnection { $fld->type = $rs->fields['type']; $fld->max_length = $rs->fields['length']; $fld->precision = $rs->fields['precision']; - $fld->scale = $rs->fields['scale']; + $fld->scale = $rs->fields['scale']; $fld->not_null =!$rs->fields['nullable']; $fld->has_default = $rs->fields['default_value']; $fld->xtype = $rs->fields['xtype']; @@ -822,16 +894,125 @@ class ADODB_mssqlnative extends ADOConnection { } $rs->Close(); - # start adg $cached_columns[$table] = $retarr; - # end adg + return $retarr; } + /** + * Returns a substring of a varchar type field + * + * The SQL server version varies because the length is mandatory, so + * we append a reasonable string length + * + * @param string $fld The field to sub-string + * @param int $start The start point + * @param int $length An optional length + * + * @return The SQL text + */ + function substr($fld,$start,$length=0) + { + if ($length == 0) + /* + * The length available to varchar is 2GB, but that makes no + * sense in a substring, so I'm going to arbitrarily limit + * the length to 1K, but you could change it if you want + */ + $length = 1024; + + $text = "SUBSTRING($fld,$start,$length)"; + return $text; + } + + /** + * Returns the maximum size of a MetaType C field. Because of the + * database design, SQL Server places no limits on the size of data inserted + * Although the actual limit is 2^31-1 bytes. + * + * @return int + */ + function charMax() + { + return ADODB_STRINGMAX_NOLIMIT; + } + + /** + * Returns the maximum size of a MetaType X field. Because of the + * database design, SQL Server places no limits on the size of data inserted + * Although the actual limit is 2^31-1 bytes. + * + * @return int + */ + function textMax() + { + return ADODB_STRINGMAX_NOLIMIT; + } + /** + * Lists procedures, functions and methods in an array. + * + * @param string $procedureNamePattern (optional) + * @param string $catalog (optional) + * @param string $schemaPattern (optional) + + * @return array of stored objects in current database. + * + */ + public function metaProcedures($procedureNamePattern = null, $catalog = null, $schemaPattern = null) + { + $metaProcedures = array(); + $procedureSQL = ''; + $catalogSQL = ''; + $schemaSQL = ''; + + if ($procedureNamePattern) + $procedureSQL = "AND ROUTINE_NAME LIKE " . strtoupper($this->qstr($procedureNamePattern)); + + if ($catalog) + $catalogSQL = "AND SPECIFIC_SCHEMA=" . strtoupper($this->qstr($catalog)); + + if ($schemaPattern) + $schemaSQL = "AND ROUTINE_SCHEMA LIKE {$this->qstr($schemaPattern)}"; + + $fields = " ROUTINE_NAME,ROUTINE_TYPE,ROUTINE_SCHEMA,ROUTINE_CATALOG"; + + $SQL = "SELECT $fields + FROM {$this->database}.information_schema.routines + WHERE 1=1 + $procedureSQL + $catalogSQL + $schemaSQL + ORDER BY ROUTINE_NAME + "; + + $result = $this->execute($SQL); + + if (!$result) + return false; + while ($r = $result->fetchRow()){ + if (!isset($r[0])) + /* + * Convert to numeric + */ + $r = array_values($r); + + $procedureName = $r[0]; + $schemaName = $r[2]; + $routineCatalog= $r[3]; + $metaProcedures[$procedureName] = array('type'=> $r[1], + 'catalog' => $routineCatalog, + 'schema' => $schemaName, + 'remarks' => '', + ); + } + + return $metaProcedures; + } + } /*-------------------------------------------------------------------------------------- - Class Name: Recordset + Class Name: Recordset --------------------------------------------------------------------------------------*/ class ADORecordset_mssqlnative extends ADORecordSet { @@ -841,6 +1022,62 @@ class ADORecordset_mssqlnative extends ADORecordSet { var $fieldOffset = 0; // _mths works only in non-localised system + /** + * @var bool True if we have retrieved the fields metadata + */ + private $fieldObjectsRetrieved = false; + + /* + * Cross-reference the objects by name for easy access + */ + private $fieldObjectsIndex = array(); + + /* + * Cross references the dateTime objects for faster decoding + */ + private $dateTimeObjects = array(); + + /* + * flags that we have dateTimeObjects to handle + */ + private $hasDateTimeObjects = false; + + /* + * This is cross reference between how the types are stored + * in SQL Server and their english-language description + * -154 is a time field, see #432 + */ + private $_typeConversion = array( + -155 => 'datetimeoffset', + -154 => 'char', + -152 => 'xml', + -151 => 'udt', + -11 => 'uniqueidentifier', + -10 => 'ntext', + -9 => 'nvarchar', + -8 => 'nchar', + -7 => 'bit', + -6 => 'tinyint', + -5 => 'bigint', + -4 => 'image', + -3 => 'varbinary', + -2 => 'timestamp', + -1 => 'text', + 1 => 'char', + 2 => 'numeric', + 3 => 'decimal', + 4 => 'int', + 5 => 'smallint', + 6 => 'float', + 7 => 'real', + 12 => 'varchar', + 91 => 'date', + 93 => 'datetime' + ); + + + + function __construct($id,$mode=false) { if ($mode === false) { @@ -849,29 +1086,15 @@ class ADORecordset_mssqlnative extends ADORecordSet { } $this->fetchMode = $mode; - return parent::__construct($id,$mode); + parent::__construct($id); } function _initrs() { - global $ADODB_COUNTRECS; - # KMN # if ($this->connection->debug) ADOConnection::outp("(before) ADODB_COUNTRECS: {$ADODB_COUNTRECS} _numOfRows: {$this->_numOfRows} _numOfFields: {$this->_numOfFields}"); - /*$retRowsAff = sqlsrv_rows_affected($this->_queryID);//"If you need to determine the number of rows a query will return before retrieving the actual results, appending a SELECT COUNT ... query would let you get that information, and then a call to next_result would move you to the "real" results." - ADOConnection::outp("rowsaff: ".serialize($retRowsAff)); - $this->_numOfRows = ($ADODB_COUNTRECS)? $retRowsAff:-1;*/ $this->_numOfRows = -1;//not supported - $fieldmeta = sqlsrv_field_metadata($this->_queryID); - $this->_numOfFields = ($fieldmeta)? count($fieldmeta):-1; - # KMN # if ($this->connection->debug) ADOConnection::outp("(after) _numOfRows: {$this->_numOfRows} _numOfFields: {$this->_numOfFields}"); - /* - * Copy the oracle method and cache the metadata at init time - */ - if ($this->_numOfFields>0) { - $this->_fieldobjs = array(); - $max = $this->_numOfFields; - for ($i=0;$i<$max; $i++) $this->_fieldobjs[] = $this->_FetchField($i); - } + // Cache the metadata right now + $this->_fetchField(); } @@ -891,7 +1114,14 @@ class ADORecordset_mssqlnative extends ADORecordSet { /* Use associative array to get fields array */ function Fields($colname) { - if ($this->fetchMode != ADODB_FETCH_NUM) return $this->fields[$colname]; + if (!is_array($this->fields)) + /* + * Too early + */ + return; + if ($this->fetchMode != ADODB_FETCH_NUM) + return $this->fields[$colname]; + if (!$this->bind) { $this->bind = array(); for ($i=0; $i < $this->_numOfFields; $i++) { @@ -903,79 +1133,63 @@ class ADORecordset_mssqlnative extends ADORecordSet { return $this->fields[$this->bind[strtoupper($colname)]]; } - /* Returns: an object containing field information. - Get column information in the Recordset object. fetchField() can be used in order to obtain information about - fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by - fetchField() is retrieved. - Designed By jcortinap#jc.com.mx + /** + * Returns: an object containing field information. + * + * Get column information in the Recordset object. fetchField() + * can be used in order to obtain information about fields in a + * certain query result. If the field offset isn't specified, + * the next field that wasn't yet retrieved by fetchField() + * is retrieved. + * + * @param int $fieldOffset (optional default=-1 for all + * @return mixed an ADOFieldObject, or array of objects */ - function _FetchField($fieldOffset = -1) + private function _fetchField($fieldOffset = -1) { - $_typeConversion = array( - -155 => 'datetimeoffset', - -154 => 'time', - -152 => 'xml', - -151 => 'udt', - -11 => 'uniqueidentifier', - -10 => 'ntext', - -9 => 'nvarchar', - -8 => 'nchar', - -7 => 'bit', - -6 => 'tinyint', - -5 => 'bigint', - -4 => 'image', - -3 => 'varbinary', - -2 => 'timestamp', - -1 => 'text', - 1 => 'char', - 2 => 'numeric', - 3 => 'decimal', - 4 => 'int', - 5 => 'smallint', - 6 => 'float', - 7 => 'real', - 12 => 'varchar', - 91 => 'date', - 93 => 'datetime' - ); + if ($this->fieldObjectsRetrieved) { + if ($this->fieldObjectsCache) { + // Already got the information + if ($fieldOffset == -1) { + return $this->fieldObjectsCache; + } else { + return $this->fieldObjectsCache[$fieldOffset]; + } + } else { + // No metadata available + return false; + } + } - $fa = @sqlsrv_field_metadata($this->_queryID); - if ($fieldOffset != -1) { - $fa = $fa[$fieldOffset]; + $this->fieldObjectsRetrieved = true; + /* + * Retrieve all metadata in one go. This is always returned as a + * numeric array. + */ + $fieldMetaData = sqlsrv_field_metadata($this->_queryID); + + if (!$fieldMetaData) { + // Not a statement that gives us metaData + return false; } - $false = false; - if (empty($fa)) { - $f = false;//PHP Notice: Only variable references should be returned by reference + + $this->_numOfFields = count($fieldMetaData); + foreach ($fieldMetaData as $key=>$value) { + $fld = new ADOFieldObject; + // Caution - keys are case-sensitive, must respect casing of values + $fld->name = $value['Name']; + $fld->max_length = $value['Size']; + $fld->column_source = $value['Name']; + $fld->type = $this->_typeConversion[$value['Type']]; + + $this->fieldObjectsCache[$key] = $fld; + $this->fieldObjectsIndex[$fld->name] = $key; } - else - { - // Convert to an object - $fa = array_change_key_case($fa, CASE_LOWER); - $fb = array(); - if ($fieldOffset != -1) - { - $fb = array( - 'name' => $fa['name'], - 'max_length' => $fa['size'], - 'column_source' => $fa['name'], - 'type' => $_typeConversion[$fa['type']] - ); - } - else - { - foreach ($fa as $key => $value) - { - $fb[] = array( - 'name' => $value['name'], - 'max_length' => $value['size'], - 'column_source' => $value['name'], - 'type' => $_typeConversion[$value['type']] - ); - } - } - $f = (object) $fb; + if ($fieldOffset == -1) { + return $this->fieldObjectsCache; } - return $f; + + return $this->fieldObjectsCache[$fieldOffset]; } /* @@ -983,12 +1197,16 @@ class ADORecordset_mssqlnative extends ADORecordSet { * into the _fieldobjs array once, to save multiple calls to the * sqlsrv_field_metadata function * + * @param int $fieldOffset (optional) + * + * @return adoFieldObject + * * @author KM Newnham * @date 02/20/2013 */ - function FetchField($fieldOffset = -1) + function fetchField($fieldOffset = -1) { - return $this->_fieldobjs[$fieldOffset]; + return $this->fieldObjectsCache[$fieldOffset]; } function _seek($row) @@ -999,178 +1217,73 @@ class ADORecordset_mssqlnative extends ADORecordSet { // speedup function MoveNext() { - //# KMN # if ($this->connection->debug) ADOConnection::outp("movenext()"); - //# KMN # if ($this->connection->debug) ADOConnection::outp("eof (beginning): ".$this->EOF); - if ($this->EOF) return false; + if ($this->EOF) + return false; $this->_currentRow++; - // # KMN # if ($this->connection->debug) ADOConnection::outp("_currentRow: ".$this->_currentRow); - if ($this->_fetch()) return true; + if ($this->_fetch()) + return true; $this->EOF = true; - //# KMN # if ($this->connection->debug) ADOConnection::outp("eof (end): ".$this->EOF); return false; } - - // INSERT UPDATE DELETE returns false even if no error occurs in 4.0.4 - // also the date format has been changed from YYYY-mm-dd to dd MMM YYYY in 4.0.4. Idiot! function _fetch($ignore_fields=false) { - # KMN # if ($this->connection->debug) ADOConnection::outp("_fetch()"); if ($this->fetchMode & ADODB_FETCH_ASSOC) { - if ($this->fetchMode & ADODB_FETCH_NUM) { - //# KMN # if ($this->connection->debug) ADOConnection::outp("fetch mode: both"); + if ($this->fetchMode & ADODB_FETCH_NUM) $this->fields = @sqlsrv_fetch_array($this->_queryID,SQLSRV_FETCH_BOTH); - } else { - //# KMN # if ($this->connection->debug) ADOConnection::outp("fetch mode: assoc"); + else $this->fields = @sqlsrv_fetch_array($this->_queryID,SQLSRV_FETCH_ASSOC); - } - if (is_array($this->fields)) { - if (ADODB_ASSOC_CASE == 0) { - foreach($this->fields as $k=>$v) { - $this->fields[strtolower($k)] = $v; - } - } else if (ADODB_ASSOC_CASE == 1) { - foreach($this->fields as $k=>$v) { - $this->fields[strtoupper($k)] = $v; - } - } - } - } else { - //# KMN # if ($this->connection->debug) ADOConnection::outp("fetch mode: num"); - $this->fields = @sqlsrv_fetch_array($this->_queryID,SQLSRV_FETCH_NUMERIC); - } - if(is_array($this->fields) && array_key_exists(1,$this->fields) && !array_key_exists(0,$this->fields)) {//fix fetch numeric keys since they're not 0 based - $arrFixed = array(); - foreach($this->fields as $key=>$value) { - if(is_numeric($key)) { - $arrFixed[$key-1] = $value; - } else { - $arrFixed[$key] = $value; - } - } - //if($this->connection->debug) ADOConnection::outp("<hr>fixing non 0 based return array, old: ".print_r($this->fields,true)." new: ".print_r($arrFixed,true)); - $this->fields = $arrFixed; - } - if(is_array($this->fields)) { - foreach($this->fields as $key=>$value) { - if (is_object($value) && method_exists($value, 'format')) {//is DateTime object - $this->fields[$key] = $value->format("Y-m-d\TH:i:s\Z"); - } + if (is_array($this->fields)) + { + + if (ADODB_ASSOC_CASE == ADODB_ASSOC_CASE_LOWER) + $this->fields = array_change_key_case($this->fields,CASE_LOWER); + else if (ADODB_ASSOC_CASE == ADODB_ASSOC_CASE_UPPER) + $this->fields = array_change_key_case($this->fields,CASE_UPPER); + } } - if($this->fields === null) $this->fields = false; - # KMN # if ($this->connection->debug) ADOConnection::outp("<hr>after _fetch, fields: <pre>".print_r($this->fields,true)." backtrace: ".adodb_backtrace(false)); + else + $this->fields = @sqlsrv_fetch_array($this->_queryID,SQLSRV_FETCH_NUMERIC); + + if (!$this->fields) + return false; + return $this->fields; } - /* close() only needs to be called if you are worried about using too much memory while your script - is running. All associated result memory for the specified result identifier will automatically be freed. */ + /** + * close() only needs to be called if you are worried about using too much + * memory while your script is running. All associated result memory for + * the specified result identifier will automatically be freed. + * + * @return bool tru if we succeeded in closing down + */ function _close() { - if(is_object($this->_queryID)) { + /* + * If we are closing down a failed query, collect any + * error messages. This is a hack fix to the "close too early" + * problem so this might go away later + */ + $this->connection->errorMsg(); + if(is_resource($this->_queryID)) { $rez = sqlsrv_free_stmt($this->_queryID); $this->_queryID = false; return $rez; } - return true; - } - // mssql uses a default date like Dec 30 2000 12:00AM - static function UnixDate($v) - { - return ADORecordSet_array_mssqlnative::UnixDate($v); + return true; } - static function UnixTimeStamp($v) - { - return ADORecordSet_array_mssqlnative::UnixTimeStamp($v); - } } -class ADORecordSet_array_mssqlnative extends ADORecordSet_array { - function __construct($id=-1,$mode=false) - { - parent::__construct($id,$mode); - } - - // mssql uses a default date like Dec 30 2000 12:00AM - static function UnixDate($v) - { - - if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) return parent::UnixDate($v); - - global $ADODB_mssql_mths,$ADODB_mssql_date_order; - - //Dec 30 2000 12:00AM - if ($ADODB_mssql_date_order == 'dmy') { - if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4})|" ,$v, $rr)) { - return parent::UnixDate($v); - } - if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; - - $theday = $rr[1]; - $themth = substr(strtoupper($rr[2]),0,3); - } else { - if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4})|" ,$v, $rr)) { - return parent::UnixDate($v); - } - if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; - - $theday = $rr[2]; - $themth = substr(strtoupper($rr[1]),0,3); - } - $themth = $ADODB_mssql_mths[$themth]; - if ($themth <= 0) return false; - // h-m-s-MM-DD-YY - return adodb_mktime(0,0,0,$themth,$theday,$rr[3]); - } - - static function UnixTimeStamp($v) - { - - if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) return parent::UnixTimeStamp($v); - - global $ADODB_mssql_mths,$ADODB_mssql_date_order; - - //Dec 30 2000 12:00AM - if ($ADODB_mssql_date_order == 'dmy') { - if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|" - ,$v, $rr)) return parent::UnixTimeStamp($v); - if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; - - $theday = $rr[1]; - $themth = substr(strtoupper($rr[2]),0,3); - } else { - if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|" - ,$v, $rr)) return parent::UnixTimeStamp($v); - if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; - - $theday = $rr[2]; - $themth = substr(strtoupper($rr[1]),0,3); - } - - $themth = $ADODB_mssql_mths[$themth]; - if ($themth <= 0) return false; - - switch (strtoupper($rr[6])) { - case 'P': - if ($rr[4]<12) $rr[4] += 12; - break; - case 'A': - if ($rr[4]==12) $rr[4] = 0; - break; - default: - break; - } - // h-m-s-MM-DD-YY - return adodb_mktime($rr[4],$rr[5],0,$themth,$theday,$rr[3]); - } -} +class ADORecordSet_array_mssqlnative extends ADORecordSet_array {} /* Code Example 1: diff --git a/libraries/adodb/drivers/adodb-mssqlpo.inc.php b/libraries/adodb/drivers/adodb-mssqlpo.inc.php index cd6a2850a..f2d2f6fbd 100644 --- a/libraries/adodb/drivers/adodb-mssqlpo.inc.php +++ b/libraries/adodb/drivers/adodb-mssqlpo.inc.php @@ -1,29 +1,27 @@ <?php /** -* @version v5.20.9 21-Dec-2016 -* @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -* @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community -* Released under both BSD license and Lesser GPL library license. -* Whenever there is any discrepancy between the two licenses, -* the BSD license will take precedence. -* -* Set tabs to 4 for best viewing. -* -* Latest version is available at http://php.weblogs.com -* -* Portable MSSQL Driver that supports || instead of + -* -*/ + * Portable MSSQL Driver that supports || instead of +. + * + * 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(); - -/* - The big difference between mssqlpo and it's parent mssql is that mssqlpo supports - the more standard || string concatenation operator. -*/ - include_once(ADODB_DIR.'/drivers/adodb-mssql.inc.php'); class ADODB_mssqlpo extends ADODB_mssql { @@ -32,10 +30,6 @@ class ADODB_mssqlpo extends ADODB_mssql { function PrepareSP($sql, $param = true) { - if (!$this->_has_mssql_init) { - ADOConnection::outp( "PrepareSP: mssql_init only available since PHP 4.1.0"); - return $sql; - } if (is_string($sql)) $sql = str_replace('||','+',$sql); $stmt = mssql_init($sql,$this->_connectionID); if (!$stmt) return $sql; @@ -51,8 +45,4 @@ class ADODB_mssqlpo extends ADODB_mssql { class ADORecordset_mssqlpo extends ADORecordset_mssql { var $databaseType = "mssqlpo"; - function __construct($id,$mode=false) - { - parent::__construct($id,$mode); - } } diff --git a/libraries/adodb/drivers/adodb-mysql.inc.php b/libraries/adodb/drivers/adodb-mysql.inc.php index 2d999c6bc..f07c081b5 100644 --- a/libraries/adodb/drivers/adodb-mysql.inc.php +++ b/libraries/adodb/drivers/adodb-mysql.inc.php @@ -1,22 +1,30 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 8. - - This driver only supports the original non-transactional MySQL driver. It - is deprected 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 - - Requires mysql client. Works on Windows and Unix. - - 28 Feb 2001: MetaColumns bug fix - suggested by Freek Dijkstra (phpeverywhere@macfreek.com) -*/ +/** + * 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(); @@ -51,23 +59,41 @@ class ADODB_mysql extends ADOConnection { var $nameQuote = '`'; /// string to use to quote identifiers and names var $compat323 = false; // true if compat with mysql 3.23 - function __construct() - { - if (defined('ADODB_EXTENSION')) $this->rsPrefix .= 'ext_'; + /** + * 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 + } + } } - - // SetCharSet - switch the client encoding - function SetCharSet($charset_name) + function setCharSet($charset) { if (!function_exists('mysql_set_charset')) { return false; } - if ($this->charSet !== $charset_name) { - $ok = @mysql_set_charset($charset_name,$this->_connectionID); + if ($this->charSet !== $charset) { + $ok = @mysql_set_charset($charset,$this->_connectionID); if ($ok) { - $this->charSet = $charset_name; + $this->charSet = $charset; return true; } return false; @@ -75,19 +101,19 @@ class ADODB_mysql extends ADOConnection { return true; } - function ServerInfo() + function serverInfo() { $arr['description'] = ADOConnection::GetOne("select version()"); $arr['version'] = ADOConnection::_findvers($arr['description']); return $arr; } - function IfNull( $field, $ifNull ) + function ifNull( $field, $ifNull ) { return " IFNULL($field, $ifNull) "; // if MySQL } - function MetaProcedures($NamePattern = false, $catalog = null, $schemaPattern = null) + function metaProcedures($NamePattern = false, $catalog = null, $schemaPattern = null) { // save old fetch mode global $ADODB_FETCH_MODE; @@ -153,7 +179,7 @@ class ADODB_mysql extends ADOConnection { * * @return array list of tables */ - function MetaTables($ttype=false,$showSchema=false,$mask=false) + function metaTables($ttype=false,$showSchema=false,$mask=false) { $save = $this->metaTablesSQL; if ($showSchema && is_string($showSchema)) { @@ -173,7 +199,7 @@ class ADODB_mysql extends ADOConnection { } - function MetaIndexes ($table, $primary = FALSE, $owner=false) + function metaIndexes ($table, $primary = FALSE, $owner=false) { // save old fetch mode global $ADODB_FETCH_MODE; @@ -226,34 +252,41 @@ class ADODB_mysql extends ADOConnection { } - // if magic quotes disabled, use mysql_real_escape_string() - function qstr($s,$magic_quotes=false) + /** + * 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 (!$magic_quotes) { + if (is_null($s)) { + return 'NULL'; + } - if (ADODB_PHPVER >= 0x4300) { - if (is_resource($this->_connectionID)) - return "'".mysql_real_escape_string($s,$this->_connectionID)."'"; - } - if ($this->replaceQuote[0] == '\\'){ - $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s); - } - return "'".str_replace("'",$this->replaceQuote,$s)."'"; + if (is_resource($this->_connectionID)) { + return "'" . mysql_real_escape_string($s, $this->_connectionID) . "'"; } - // undo magic quotes for " - $s = str_replace('\\"','"',$s); - return "'$s'"; + if ($this->replaceQuote[0] == '\\') { + $s = str_replace(array('\\', "\0"), array('\\\\', "\\\0"), $s); + } + return "'" . str_replace("'", $this->replaceQuote, $s) . "'"; } - function _insertid() + protected function _insertID($table = '', $column = '') { return ADOConnection::GetOne('SELECT LAST_INSERT_ID()'); //return mysql_insert_id($this->_connectionID); } - function GetOne($sql,$inputarr=false) + function getOne($sql,$inputarr=false) { global $ADODB_GETONE_EOF; if ($this->compat323 == false && strncasecmp($sql,'sele',4) == 0) { @@ -269,7 +302,7 @@ class ADODB_mysql extends ADOConnection { return false; } - function BeginTrans() + function beginTrans() { if ($this->debug) ADOConnection::outp("Transactions not supported in 'mysql' driver. Use 'mysqlt' or 'mysqli' driver"); } @@ -287,7 +320,7 @@ class ADODB_mysql extends ADOConnection { var $_genSeq2SQL = "insert into %s values (%s)"; var $_dropSeqSQL = "drop table if exists %s"; - function CreateSequence($seqname='adodbseq',$startID=1) + function createSequence($seqname='adodbseq',$startID=1) { if (empty($this->_genSeqSQL)) return false; $u = strtoupper($seqname); @@ -298,7 +331,7 @@ class ADODB_mysql extends ADOConnection { } - function GenID($seqname='adodbseq',$startID=1) + function genID($seqname='adodbseq',$startID=1) { // post-nuke sets hasGenID to false if (!$this->hasGenID) return false; @@ -327,7 +360,7 @@ class ADODB_mysql extends ADOConnection { return $this->genID; } - function MetaDatabases() + function metaDatabases() { $qid = mysql_list_dbs($this->_connectionID); $arr = array(); @@ -343,7 +376,7 @@ class ADODB_mysql extends ADOConnection { // Format date column in sql string given an input format that understands Y M D - function SQLDate($fmt, $col=false) + function sqlDate($fmt, $col=false) { if (!$col) $col = $this->sysTimeStamp; $s = 'DATE_FORMAT('.$col.",'"; @@ -431,7 +464,7 @@ class ADODB_mysql extends ADOConnection { // returns concatenated string // much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator - function Concat() + function concat() { $s = ""; $arr = func_get_args(); @@ -442,7 +475,7 @@ class ADODB_mysql extends ADOConnection { else return ''; } - function OffsetDate($dayFraction,$date=false) + function offsetDate($dayFraction,$date=false) { if (!$date) $date = $this->sysDate; @@ -455,19 +488,23 @@ class ADODB_mysql extends ADOConnection { // returns true or false function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) { - if (!empty($this->port)) $argHostname .= ":".$this->port; + if (!empty($this->port)) + $argHostname .= ":".$this->port; - if (ADODB_PHPVER >= 0x4300) - $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword, - $this->forceNewConnect,$this->clientFlags); - else if (ADODB_PHPVER >= 0x4200) - $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword, - $this->forceNewConnect); - else - $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword); + $this->_connectionID = + mysql_connect($argHostname, + $argUsername, + $argPassword, + $this->forceNewConnect, + $this->clientFlags + ); + + + if ($this->_connectionID === false) + return false; + if ($argDatabasename) + return $this->SelectDB($argDatabasename); - if ($this->_connectionID === false) return false; - if ($argDatabasename) return $this->SelectDB($argDatabasename); return true; } @@ -476,13 +513,18 @@ class ADODB_mysql extends ADOConnection { { if (!empty($this->port)) $argHostname .= ":".$this->port; - if (ADODB_PHPVER >= 0x4300) - $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword,$this->clientFlags); - else - $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword); - if ($this->_connectionID === false) return false; - if ($this->autoRollback) $this->RollbackTrans(); - if ($argDatabasename) return $this->SelectDB($argDatabasename); + $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; } @@ -492,7 +534,7 @@ class ADODB_mysql extends ADOConnection { return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename); } - function MetaColumns($table, $normalize=true) + function metaColumns($table, $normalize=true) { $this->_findschema($table,$schema); if ($schema) { @@ -572,7 +614,7 @@ class ADODB_mysql extends ADOConnection { } // returns true or false - function SelectDB($dbName) + function selectDB($dbName) { $this->database = $dbName; $this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions @@ -583,10 +625,12 @@ class ADODB_mysql extends ADOConnection { } // parameters use PostgreSQL convention, not MySQL - function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0) + 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 http://phplens.com/lens/lensforum/msgs.php?id=9220 + // jason judge, see PHPLens Issue No: 9220 if ($nrows < 0) $nrows = '18446744073709551615'; if ($secs) @@ -611,7 +655,7 @@ class ADODB_mysql extends ADOConnection { } /* Returns: the last error message from previous database operation */ - function ErrorMsg() + function errorMsg() { if ($this->_logsql) return $this->_errorMsg; @@ -621,7 +665,7 @@ class ADODB_mysql extends ADOConnection { } /* Returns: the last error number from previous database operation */ - function ErrorNo() + function errorNo() { if ($this->_logsql) return $this->_errorCode; if (empty($this->_connectionID)) return @mysql_errno(); @@ -641,7 +685,7 @@ class ADODB_mysql extends ADOConnection { /* * Maximum size of C field */ - function CharMax() + function charMax() { return 255; } @@ -649,13 +693,13 @@ class ADODB_mysql extends ADOConnection { /* * Maximum size of X field */ - function TextMax() + function textMax() { return 4294967295; } // "Innox - Juan Carlos Gonzalez" <jgonzalez#innox.com.mx> - function MetaForeignKeys( $table, $owner = FALSE, $upper = FALSE, $associative = FALSE ) + function metaForeignKeys( $table, $owner = FALSE, $upper = FALSE, $associative = FALSE ) { global $ADODB_FETCH_MODE; if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC || $this->fetchMode == ADODB_FETCH_ASSOC) $associative = true; @@ -684,7 +728,7 @@ class ADODB_mysql extends ADOConnection { $ref_table = strtoupper($ref_table); } - // see https://sourceforge.net/tracker/index.php?func=detail&aid=2287278&group_id=42718&atid=433976 + // see https://sourceforge.net/p/adodb/bugs/100/ if (!isset($foreign_keys[$ref_table])) { $foreign_keys[$ref_table] = array(); } @@ -741,7 +785,7 @@ class ADORecordSet_mysql extends ADORecordSet{ $this->_numOfFields = @mysql_num_fields($this->_queryID); } - function FetchField($fieldOffset = -1) + function fetchField($fieldOffset = -1) { if ($fieldOffset != -1) { $o = @mysql_fetch_field($this->_queryID, $fieldOffset); @@ -759,7 +803,7 @@ class ADORecordSet_mysql extends ADORecordSet{ return $o; } - function GetRowAssoc($upper = ADODB_ASSOC_CASE) + function getRowAssoc($upper = ADODB_ASSOC_CASE) { if ($this->fetchMode == MYSQL_ASSOC && $upper == ADODB_ASSOC_CASE_LOWER) { $row = $this->fields; @@ -771,7 +815,7 @@ class ADORecordSet_mysql extends ADORecordSet{ } /* Use associative array to get fields array */ - function Fields($colname) + function fields($colname) { // added @ by "Michael William Miller" <mille562@pilot.msu.edu> if ($this->fetchMode != MYSQL_NUM) return @$this->fields[$colname]; @@ -792,10 +836,8 @@ class ADORecordSet_mysql extends ADORecordSet{ return @mysql_data_seek($this->_queryID,$row); } - function MoveNext() + function moveNext() { - //return adodb_movenext($this); - //if (defined('ADODB_EXTENSION')) return adodb_movenext($this); if (@$this->fields = mysql_fetch_array($this->_queryID,$this->fetchMode)) { $this->_updatefields(); $this->_currentRow += 1; @@ -820,7 +862,7 @@ class ADORecordSet_mysql extends ADORecordSet{ $this->_queryID = false; } - function MetaType($t,$len=-1,$fieldobj=false) + function metaType($t,$len=-1,$fieldobj=false) { if (is_object($t)) { $fieldobj = $t; @@ -870,19 +912,18 @@ class ADORecordSet_mysql extends ADORecordSet{ if (!empty($fieldobj->primary_key)) return 'R'; else return 'I'; - default: return 'N'; + default: return ADODB_DEFAULT_METATYPE; } } } +/** + * Class ADORecordSet_ext_mysql + */ class ADORecordSet_ext_mysql extends ADORecordSet_mysql { - function __construct($queryID,$mode=false) - { - parent::__construct($queryID,$mode); - } - function MoveNext() + function moveNext() { return @adodb_movenext($this); } diff --git a/libraries/adodb/drivers/adodb-mysqli.inc.php b/libraries/adodb/drivers/adodb-mysqli.inc.php index c53eeeed4..352810cc0 100644 --- a/libraries/adodb/drivers/adodb-mysqli.inc.php +++ b/libraries/adodb/drivers/adodb-mysqli.inc.php @@ -1,37 +1,44 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 8. - - This is the preferred driver for MySQL connections, and supports both transactional - and non-transactional table types. You can use this as a drop-in replacement for both - the mysql and mysqlt drivers. As of ADOdb Version 5.20.0, all other native MySQL drivers - are deprecated - - Requires mysql client. Works on Windows and Unix. - -21 October 2003: MySQLi extension implementation by Arjen de Rijke (a.de.rijke@xs4all.nl) -Based on adodb 3.40 -*/ +/** + * MySQL improved driver (mysqli) + * + * This is the preferred driver for MySQL connections. It supports both + * transactional and non-transactional table types. You can use this as a + * drop-in replacement for both the mysql and mysqlt drivers. + * As of ADOdb Version 5.20.0, all other native MySQL drivers are deprecated. + * + * 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_MYSQLI_LAYER")) { - define("_ADODB_MYSQLI_LAYER", 1 ); +if (!defined('ADODB_DIR')) { + die(); +} - // PHP5 compat... - if (! defined("MYSQLI_BINARY_FLAG")) define("MYSQLI_BINARY_FLAG", 128); - if (!defined('MYSQLI_READ_DEFAULT_GROUP')) define('MYSQLI_READ_DEFAULT_GROUP',1); +if (!defined("_ADODB_MYSQLI_LAYER")) { + define("_ADODB_MYSQLI_LAYER", 1); - // disable adodb extension - currently incompatible. - global $ADODB_EXTENSION; $ADODB_EXTENSION = false; +// PHP5 compat... +if (! defined("MYSQLI_BINARY_FLAG")) define("MYSQLI_BINARY_FLAG", 128); +if (!defined('MYSQLI_READ_DEFAULT_GROUP')) define('MYSQLI_READ_DEFAULT_GROUP',1); +/** + * Class ADODB_mysqli + */ class ADODB_mysqli extends ADOConnection { var $databaseType = 'mysqli'; var $dataProvider = 'mysql'; @@ -62,31 +69,84 @@ class ADODB_mysqli extends ADOConnection { var $optionFlags = array(array(MYSQLI_READ_DEFAULT_GROUP,0)); var $arrayClass = 'ADORecordSet_array_mysqli'; var $multiQuery = false; + var $ssl_key = null; + var $ssl_cert = null; + var $ssl_ca = null; + var $ssl_capath = null; + var $ssl_cipher = null; - function __construct() - { - // if(!extension_loaded("mysqli")) - //trigger_error("You must have the mysqli extension installed.", E_USER_ERROR); - } + /** + * Tells the insert_id method how to obtain the last value, depending on whether + * we are using a stored procedure or not + */ + private $usePreparedStatement = false; + private $useLastInsertStatement = false; + + /** + * @var bool True if the last executed statement is a SELECT {@see _query()} + */ + private $isSelectStatement = false; - function SetTransactionMode( $transaction_mode ) + /** + * Sets the isolation level of a transaction. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:settransactionmode + * + * @param string $transaction_mode The transaction mode to set. + * + * @return void + */ + function SetTransactionMode($transaction_mode) { $this->_transmode = $transaction_mode; if (empty($transaction_mode)) { - $this->Execute('SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ'); + $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); + $this->execute("SET SESSION TRANSACTION ".$transaction_mode); } - // returns true or false - // To add: parameter int $port, - // parameter string $socket - function _connect($argHostname = NULL, - $argUsername = NULL, - $argPassword = NULL, - $argDatabasename = NULL, $persist=false) + /** + * Adds a parameter to the connection string. + * + * Parameter must be one of the the constants listed in mysqli_options(). + * @see https://www.php.net/manual/en/mysqli.options.php + * + * @param int $parameter The parameter to set + * @param string $value The value of the parameter + * + * @example, for mssqlnative driver ('CharacterSet','UTF-8') + * @return bool + */ + public function setConnectionParameter($parameter, $value) { + if(!is_numeric($parameter)) { + $this->outp_throw("Invalid connection parameter '$parameter'", __METHOD__); + return false; + } + $this->connectionParameters[$parameter] = $value; + return true; + } + + /** + * Connect to a database. + * + * @todo add: parameter int $port, parameter string $socket + * + * @param string|null $argHostname (Optional) The host to connect to. + * @param string|null $argUsername (Optional) The username to connect as. + * @param string|null $argPassword (Optional) The password to connect with. + * @param string|null $argDatabasename (Optional) The name of the database to start in when connected. + * @param bool $persist (Optional) Whether or not to use a persistent connection. + * + * @return bool|null True if connected successfully, false if connection failed, or null if the mysqli extension + * isn't currently loaded. + */ + function _connect($argHostname = null, + $argUsername = null, + $argPassword = null, + $argDatabasename = null, + $persist = false) { if(!extension_loaded("mysqli")) { return null; @@ -96,7 +156,7 @@ class ADODB_mysqli extends ADOConnection { if (is_null($this->_connectionID)) { // mysqli_init only fails if insufficient memory if ($this->debug) { - ADOConnection::outp("mysqli_init() failed : " . $this->ErrorMsg()); + ADOConnection::outp("mysqli_init() failed : " . $this->errorMsg()); } return false; } @@ -105,15 +165,34 @@ class ADODB_mysqli extends ADOConnection { read connection options from the standard mysql configuration file /etc/my.cnf - "Bastien Duclaux" <bduclaux#yahoo.com> */ + $this->optionFlags = array(); foreach($this->optionFlags as $arr) { mysqli_options($this->_connectionID,$arr[0],$arr[1]); } - //http ://php.net/manual/en/mysqli.persistconns.php - if ($persist && PHP_VERSION > 5.2 && strncmp($argHostname,'p:',2) != 0) $argHostname = 'p:'.$argHostname; + // Now merge in the standard connection parameters setting + foreach ($this->connectionParameters as $parameter => $value) { + // Make sure parameter is numeric before calling mysqli_options() + // that to avoid Warning (or TypeError exception on PHP 8). + if (!is_numeric($parameter) + || !mysqli_options($this->_connectionID, $parameter, $value) + ) { + $this->outp_throw("Invalid connection parameter '$parameter'", __METHOD__); + } + } + + //https://php.net/manual/en/mysqli.persistconns.php + if ($persist && strncmp($argHostname,'p:',2) != 0) { + $argHostname = 'p:' . $argHostname; + } + + // SSL Connections for MySQLI + if ($this->ssl_key || $this->ssl_cert || $this->ssl_ca || $this->ssl_capath || $this->ssl_cipher) { + mysqli_ssl_set($this->_connectionID, $this->ssl_key, $this->ssl_cert, $this->ssl_ca, $this->ssl_capath, $this->ssl_cipher); + } #if (!empty($this->port)) $argHostname .= ":".$this->port; - $ok = mysqli_real_connect($this->_connectionID, + $ok = @mysqli_real_connect($this->_connectionID, $argHostname, $argUsername, $argPassword, @@ -124,155 +203,255 @@ class ADODB_mysqli extends ADOConnection { $this->clientFlags); if ($ok) { - if ($argDatabasename) return $this->SelectDB($argDatabasename); + if ($argDatabasename) return $this->selectDB($argDatabasename); return true; } else { if ($this->debug) { - ADOConnection::outp("Could't connect : " . $this->ErrorMsg()); + ADOConnection::outp("Could not connect : " . $this->errorMsg()); } $this->_connectionID = null; return false; } } - // returns true or false - // How to force a persistent connection + /** + * Connect to a database with a persistent connection. + * + * @param string|null $argHostname The host to connect to. + * @param string|null $argUsername The username to connect as. + * @param string|null $argPassword The password to connect with. + * @param string|null $argDatabasename The name of the database to start in when connected. + * + * @return bool|null True if connected successfully, false if connection failed, or null if the mysqli extension + * isn't currently loaded. + */ function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) { return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename, true); } - // When is this used? Close old connection first? - // In _connect(), check $this->forceNewConnect? + /** + * Connect to a database, whilst setting $this->forceNewConnect to true. + * + * When is this used? Close old connection first? + * In _connect(), check $this->forceNewConnect? + * + * @param string|null $argHostname The host to connect to. + * @param string|null $argUsername The username to connect as. + * @param string|null $argPassword The password to connect with. + * @param string|null $argDatabasename The name of the database to start in when connected. + * + * @return bool|null True if connected successfully, false if connection failed, or null if the mysqli extension + * isn't currently loaded. + */ function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename) { $this->forceNewConnect = true; return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename); } - function IfNull( $field, $ifNull ) + /** + * Replaces a null value with a specified replacement. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:ifnull + * + * @param mixed $field The field in the table to check. + * @param mixed $ifNull The value to replace the null value with if it is found. + * + * @return string + */ + function IfNull($field, $ifNull) { - return " IFNULL($field, $ifNull) "; // if MySQL + return " IFNULL($field, $ifNull) "; } - // do not use $ADODB_COUNTRECS - function GetOne($sql,$inputarr=false) + /** + * Retrieves the first column of the first matching row of an executed SQL statement. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:getone + * + * @param string $sql The SQL to execute. + * @param bool|array $inputarr (Optional) An array containing any required SQL parameters, or false if none needed. + * + * @return bool|array|null + */ + function GetOne($sql, $inputarr = false) { global $ADODB_GETONE_EOF; $ret = false; - $rs = $this->Execute($sql,$inputarr); + $rs = $this->execute($sql,$inputarr); if ($rs) { if ($rs->EOF) $ret = $ADODB_GETONE_EOF; else $ret = reset($rs->fields); - $rs->Close(); + $rs->close(); } return $ret; } + /** + * Get information about the current MySQL server. + * + * @return array + */ function ServerInfo() { - $arr['description'] = $this->GetOne("select version()"); + $arr['description'] = $this->getOne("select version()"); $arr['version'] = ADOConnection::_findvers($arr['description']); return $arr; } - + /** + * Begins a granular transaction. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:begintrans + * + * @return bool Always returns true. + */ function BeginTrans() { if ($this->transOff) return true; $this->transCnt += 1; - //$this->Execute('SET AUTOCOMMIT=0'); + //$this->execute('SET AUTOCOMMIT=0'); mysqli_autocommit($this->_connectionID, false); - $this->Execute('BEGIN'); + $this->execute('BEGIN'); return true; } - function CommitTrans($ok=true) + /** + * Commits a granular transaction. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:committrans + * + * @param bool $ok (Optional) If false, will rollback the transaction instead. + * + * @return bool Always returns true. + */ + function CommitTrans($ok = true) { if ($this->transOff) return true; - if (!$ok) return $this->RollbackTrans(); + if (!$ok) return $this->rollbackTrans(); if ($this->transCnt) $this->transCnt -= 1; - $this->lastInsID = $this->_insertid(); - $this->Execute('COMMIT'); + $this->execute('COMMIT'); - //$this->Execute('SET AUTOCOMMIT=1'); + //$this->execute('SET AUTOCOMMIT=1'); mysqli_autocommit($this->_connectionID, true); return true; } + /** + * Rollback a smart transaction. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:rollbacktrans + * + * @return bool Always returns true. + */ function RollbackTrans() { if ($this->transOff) return true; if ($this->transCnt) $this->transCnt -= 1; - $this->Execute('ROLLBACK'); - //$this->Execute('SET AUTOCOMMIT=1'); + $this->execute('ROLLBACK'); + //$this->execute('SET AUTOCOMMIT=1'); mysqli_autocommit($this->_connectionID, true); return true; } - function RowLock($tables,$where='',$col='1 as adodbignore') + /** + * Lock a table row for a duration of a transaction. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:rowlock + * + * @param string $tables The table(s) to lock rows for. + * @param string $where (Optional) The WHERE clause to use to determine which rows to lock. + * @param string $col (Optional) The columns to select. + * + * @return bool True if the locking SQL statement executed successfully, otherwise false. + */ + function RowLock($tables, $where = '', $col = '1 as adodbignore') { - if ($this->transCnt==0) $this->BeginTrans(); + if ($this->transCnt==0) $this->beginTrans(); if ($where) $where = ' where '.$where; - $rs = $this->Execute("select $col from $tables $where for update"); + $rs = $this->execute("select $col from $tables $where for update"); return !empty($rs); } /** - * Quotes a string to be sent to the database - * When there is no active connection, - * @param string $s The string to quote - * @param boolean $magic_quotes If false, use mysqli_real_escape_string() - * if you are quoting a string extracted from a POST/GET variable, - * then pass get_magic_quotes_gpc() as the second parameter. This will - * ensure that the variable is not quoted twice, once by qstr() and - * once by the magic_quotes_gpc. - * Eg. $s = $db->qstr(_GET['name'],get_magic_quotes_gpc()); + * Appropriately quotes strings with ' characters for insertion into the database. + * + * Relies on mysqli_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) + function qStr($s, $magic_quotes=false) { - if (is_null($s)) return 'NULL'; - if (!$magic_quotes) { - // mysqli_real_escape_string() throws a warning when the given - // connection is invalid - if (PHP_VERSION >= 5 && $this->_connectionID) { - return "'" . mysqli_real_escape_string($this->_connectionID, $s) . "'"; - } + if (is_null($s)) { + return 'NULL'; + } - if ($this->replaceQuote[0] == '\\') { - $s = adodb_str_replace(array('\\',"\0"), array('\\\\',"\\\0") ,$s); - } - return "'" . str_replace("'", $this->replaceQuote, $s) . "'"; + // mysqli_real_escape_string() throws a warning when the given + // connection is invalid + if ($this->_connectionID) { + return "'" . mysqli_real_escape_string($this->_connectionID, $s) . "'"; + } + + if ($this->replaceQuote[0] == '\\') { + $s = str_replace(array('\\', "\0"), array('\\\\', "\\\0") ,$s); } - // undo magic quotes for " - $s = str_replace('\\"','"',$s); - return "'$s'"; + return "'" . str_replace("'", $this->replaceQuote, $s) . "'"; } - function _insertid() + /** + * Return the AUTO_INCREMENT id of the last row that has been inserted or updated in a table. + * + * @inheritDoc + */ + protected function _insertID($table = '', $column = '') { - $result = @mysqli_insert_id($this->_connectionID); + // mysqli_insert_id does not return the last_insert_id if called after + // execution of a stored procedure so we execute this instead. + if ($this->useLastInsertStatement) + $result = ADOConnection::getOne('SELECT LAST_INSERT_ID()'); + else + $result = @mysqli_insert_id($this->_connectionID); + if ($result == -1) { - if ($this->debug) ADOConnection::outp("mysqli_insert_id() failed : " . $this->ErrorMsg()); + if ($this->debug) + ADOConnection::outp("mysqli_insert_id() failed : " . $this->errorMsg()); } + // reset prepared statement flags + $this->usePreparedStatement = false; + $this->useLastInsertStatement = false; return $result; } - // Only works for INSERT, UPDATE and DELETE query's + /** + * Returns how many rows were effected by the most recently executed SQL statement. + * Only works for INSERT, UPDATE and DELETE queries. + * + * @return int The number of rows affected. + */ function _affectedrows() { + if ($this->isSelectStatement) { + // Affected rows works fine against selects, returning + // the rowcount, but ADOdb does not do that. + return false; + } + $result = @mysqli_affected_rows($this->_connectionID); if ($result == -1) { - if ($this->debug) ADOConnection::outp("mysqli_affected_rows() failed : " . $this->ErrorMsg()); + if ($this->debug) ADOConnection::outp("mysqli_affected_rows() failed : " . $this->errorMsg()); } return $result; } - // 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)"; @@ -280,60 +459,96 @@ class ADODB_mysqli extends ADOConnection { var $_genSeq2SQL = "insert into %s values (%s)"; var $_dropSeqSQL = "drop table if exists %s"; - function CreateSequence($seqname='adodbseq',$startID=1) + /** + * Creates a sequence in the database. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:createsequence + * + * @param string $seqname The sequence name. + * @param int $startID The start id. + * + * @return ADORecordSet|bool A record set if executed successfully, otherwise false. + */ + function CreateSequence($seqname = 'adodbseq', $startID = 1) { if (empty($this->_genSeqSQL)) return false; - $u = strtoupper($seqname); - $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname)); + $ok = $this->execute(sprintf($this->_genSeqSQL,$seqname)); if (!$ok) return false; - return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1)); + return $this->execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1)); } - function GenID($seqname='adodbseq',$startID=1) + /** + * A portable method of creating sequence numbers. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:genid + * + * @param string $seqname (Optional) The name of the sequence to use. + * @param int $startID (Optional) The point to start at in the sequence. + * + * @return bool|int|string + */ + function GenID($seqname = 'adodbseq', $startID = 1) { // post-nuke sets hasGenID to false if (!$this->hasGenID) return false; $getnext = sprintf($this->_genIDSQL,$seqname); $holdtransOK = $this->_transOK; // save the current status - $rs = @$this->Execute($getnext); + $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); + $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 = mysqli_insert_id($this->_connectionID); - $rs->Close(); + if ($this->genID == 0) { + $getnext = "select LAST_INSERT_ID() from " . $seqname; + $rs = $this->execute($getnext); + $this->genID = (int)$rs->fields[0]; + } + $rs->close(); } else $this->genID = 0; return $this->genID; } + /** + * Return a list of all visible databases except the 'mysql' database. + * + * @return array|false An array of database names, or false if the query failed. + */ function MetaDatabases() { $query = "SHOW DATABASES"; - $ret = $this->Execute($query); + $ret = $this->execute($query); if ($ret && is_object($ret)){ $arr = array(); while (!$ret->EOF){ - $db = $ret->Fields('Database'); + $db = $ret->fields('Database'); if ($db != 'mysql') $arr[] = $db; - $ret->MoveNext(); + $ret->moveNext(); } return $arr; } return $ret; } - - function MetaIndexes ($table, $primary = FALSE, $owner = false) + /** + * 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; @@ -342,15 +557,15 @@ class ADODB_mysqli extends ADOConnection { $save = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; if ($this->fetchMode !== FALSE) { - $savem = $this->SetFetchMode(FALSE); + $savem = $this->setFetchMode(FALSE); } // get index details - $rs = $this->Execute(sprintf('SHOW INDEXES FROM %s',$table)); + $rs = $this->execute(sprintf('SHOW INDEXES FROM %s',$table)); // restore fetchmode if (isset($savem)) { - $this->SetFetchMode($savem); + $this->setFetchMode($savem); } $ADODB_FETCH_MODE = $save; @@ -361,7 +576,7 @@ class ADODB_mysqli extends ADOConnection { $indexes = array (); // parse index data into array - while ($row = $rs->FetchRow()) { + while ($row = $rs->fetchRow()) { if ($primary == FALSE AND $row[2] == 'PRIMARY') { continue; } @@ -385,9 +600,17 @@ class ADODB_mysqli extends ADOConnection { return $indexes; } - - // Format date column in sql string given an input format that understands Y M D - function SQLDate($fmt, $col=false) + /** + * Returns a portably-formatted date string from a timestamp database column. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:sqldate + * + * @param string $fmt The date format to use. + * @param string|bool $col (Optional) The table column to date format, or if false, use NOW(). + * + * @return bool|string The SQL DATE_FORMAT() string, or false if the provided date format was empty. + */ + function SQLDate($fmt, $col = false) { if (!$col) $col = $this->sysTimeStamp; $s = 'DATE_FORMAT('.$col.",'"; @@ -464,11 +687,15 @@ class ADODB_mysqli extends ADOConnection { return $s; } - // returns concatenated string - // much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator + /** + * Returns a database-specific concatenation of strings. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:concat + * + * @return string + */ function Concat() { - $s = ""; $arr = func_get_args(); // suggestion by andrew005@mnogo.ru @@ -477,8 +704,17 @@ class ADODB_mysqli extends ADOConnection { else return ''; } - // dayFraction is a day in floating point - function OffsetDate($dayFraction,$date=false) + /** + * Creates a portable date offset field, for use in SQL statements. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:offsetdate + * + * @param float $dayFraction A day in floating point + * @param string|bool $date (Optional) The date to offset. If false, uses CURDATE() + * + * @return string + */ + function OffsetDate($dayFraction, $date = false) { if (!$date) $date = $this->sysDate; @@ -488,17 +724,25 @@ class ADODB_mysqli extends ADOConnection { // return "from_unixtime(unix_timestamp($date)+$fraction)"; } + /** + * Returns information about stored procedures and stored functions. + * + * @param string|bool $NamePattern (Optional) Only look for procedures/functions with a name matching this pattern. + * @param null $catalog (Optional) Unused. + * @param null $schemaPattern (Optional) Unused. + * + * @return array + */ 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); + $savem = $this->setFetchMode(FALSE); } $procedures = array (); @@ -509,11 +753,11 @@ class ADODB_mysqli extends ADOConnection { if ($NamePattern) { $likepattern = " LIKE '".$NamePattern."'"; } - $rs = $this->Execute('SHOW PROCEDURE STATUS'.$likepattern); + $rs = $this->execute('SHOW PROCEDURE STATUS'.$likepattern); if (is_object($rs)) { // parse index data into array - while ($row = $rs->FetchRow()) { + while ($row = $rs->fetchRow()) { $procedures[$row[1]] = array( 'type' => 'PROCEDURE', 'catalog' => '', @@ -523,10 +767,10 @@ class ADODB_mysqli extends ADOConnection { } } - $rs = $this->Execute('SHOW FUNCTION STATUS'.$likepattern); + $rs = $this->execute('SHOW FUNCTION STATUS'.$likepattern); if (is_object($rs)) { // parse index data into array - while ($row = $rs->FetchRow()) { + while ($row = $rs->fetchRow()) { $procedures[$row[1]] = array( 'type' => 'FUNCTION', 'catalog' => '', @@ -538,7 +782,7 @@ class ADODB_mysqli extends ADOConnection { // restore fetchmode if (isset($savem)) { - $this->SetFetchMode($savem); + $this->setFetchMode($savem); } $ADODB_FETCH_MODE = $save; @@ -548,13 +792,13 @@ class ADODB_mysqli extends ADOConnection { /** * 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 + * @param string|bool $ttype (Optional) Table type = 'TABLE', 'VIEW' or false=both (default) + * @param string|bool $showSchema (Optional) schema name, false = current schema (default) + * @param string|bool $mask (Optional) filters the table by name * * @return array list of tables */ - function MetaTables($ttype=false,$showSchema=false,$mask=false) + function MetaTables($ttype = false, $showSchema = false, $mask = false) { $save = $this->metaTablesSQL; if ($showSchema && is_string($showSchema)) { @@ -567,26 +811,43 @@ class ADODB_mysqli extends ADOConnection { $mask = $this->qstr($mask); $this->metaTablesSQL .= " AND table_name LIKE $mask"; } - $ret = ADOConnection::MetaTables($ttype,$showSchema); + $ret = ADOConnection::metaTables($ttype,$showSchema); $this->metaTablesSQL = $save; return $ret; } - // "Innox - Juan Carlos Gonzalez" <jgonzalez#innox.com.mx> - function MetaForeignKeys( $table, $owner = FALSE, $upper = FALSE, $associative = FALSE ) + /** + * Return information about a table's foreign keys. + * + * @param string $table The name of the table to get the foreign keys for. + * @param string|bool $owner (Optional) The database the table belongs to, or false to assume the current db. + * @param string|bool $upper (Optional) Force uppercase table name on returned array keys. + * @param bool $associative (Optional) Whether to return an associate or numeric array. + * + * @return array|bool An array of foreign keys, or false no foreign keys could be found. + */ + function MetaForeignKeys($table, $owner = false, $upper = false, $associative = false) { - global $ADODB_FETCH_MODE; - if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC || $this->fetchMode == ADODB_FETCH_ASSOC) $associative = true; + global $ADODB_FETCH_MODE; + + if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC + || $this->fetchMode == ADODB_FETCH_ASSOC) + $associative = true; + + $savem = $ADODB_FETCH_MODE; + $this->setFetchMode(ADODB_FETCH_ASSOC); 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]; + + $this->setFetchMode($savem); + + $create_sql = isset($a_create_table["Create Table"]) ? $a_create_table["Create Table"] : $a_create_table["Create View"]; $matches = array(); @@ -602,7 +863,7 @@ class ADODB_mysqli extends ADOConnection { $ref_table = strtoupper($ref_table); } - // see https://sourceforge.net/tracker/index.php?func=detail&aid=2287278&group_id=42718&atid=433976 + // see https://sourceforge.net/p/adodb/bugs/100/ if (!isset($foreign_keys[$ref_table])) { $foreign_keys[$ref_table] = array(); } @@ -619,7 +880,15 @@ class ADODB_mysqli extends ADOConnection { return $foreign_keys; } - function MetaColumns($table, $normalize=true) + /** + * Return an array of information about a table's columns. + * + * @param string $table The name of the table to get the column info for. + * @param bool $normalize (Optional) Unused. + * + * @return ADOFieldObject[]|bool An array of info for each column, or false if it could not determine the info. + */ + function MetaColumns($table, $normalize = true) { $false = false; if (!$this->metaColumnsSQL) @@ -630,6 +899,19 @@ class ADODB_mysqli extends ADOConnection { $ADODB_FETCH_MODE = ADODB_FETCH_NUM; if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); + /* + * Return assoc array where key is column name, value is column type + * [1] => int unsigned + */ + + $SQL = "SELECT column_name, column_type + FROM information_schema.columns + WHERE table_schema='{$this->databaseName}' + AND table_name='$table'"; + + $schemaArray = $this->getAssoc($SQL); + $schemaArray = array_change_key_case($schemaArray,CASE_LOWER); + $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table)); if (isset($savem)) $this->SetFetchMode($savem); $ADODB_FETCH_MODE = $save; @@ -642,6 +924,12 @@ class ADODB_mysqli extends ADOConnection { $fld->name = $rs->fields[0]; $type = $rs->fields[1]; + /* + * Type from information_schema returns + * the same format in V8 mysql as V5 + */ + $type = $schemaArray[strtolower($fld->name)]; + // split type into type(length): $fld->scale = null; if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) { @@ -661,6 +949,7 @@ class ADODB_mysqli extends ADOConnection { $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); @@ -683,14 +972,22 @@ class ADODB_mysqli extends ADOConnection { } else { $retarr[strtoupper($fld->name)] = $fld; } - $rs->MoveNext(); + $rs->moveNext(); } - $rs->Close(); + $rs->close(); return $retarr; } - // returns true or false + /** + * Select which database to connect to. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:selectdb + * + * @param string $dbName The name of the database to select. + * + * @return bool True if the database was selected successfully, otherwise false. + */ function SelectDB($dbName) { // $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID); @@ -700,48 +997,86 @@ class ADODB_mysqli extends ADOConnection { if ($this->_connectionID) { $result = @mysqli_select_db($this->_connectionID, $dbName); if (!$result) { - ADOConnection::outp("Select of database " . $dbName . " failed. " . $this->ErrorMsg()); + ADOConnection::outp("Select of database " . $dbName . " failed. " . $this->errorMsg()); } return $result; } return false; } - // parameters use PostgreSQL convention, not MySQL + /** + * Executes a provided SQL statement and returns a handle to the result, with the ability to supply a starting + * offset and record count. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:selectlimit + * + * @param string $sql The SQL to execute. + * @param int $nrows (Optional) The limit for the number of records you want returned. By default, all results. + * @param int $offset (Optional) The offset to use when selecting the results. By default, no offset. + * @param array|bool $inputarr (Optional) Any parameter values required by the SQL statement, or false if none. + * @param int $secs (Optional) If greater than 0, perform a cached execute. By default, normal execution. + * + * @return ADORecordSet|false The query results, or false if the query failed to execute. + */ function SelectLimit($sql, - $nrows = -1, - $offset = -1, - $inputarr = false, - $secs = 0) + $nrows = -1, + $offset = -1, + $inputarr = false, + $secs = 0) { + $nrows = (int) $nrows; + $offset = (int) $offset; $offsetStr = ($offset >= 0) ? "$offset," : ''; if ($nrows < 0) $nrows = '18446744073709551615'; if ($secs) - $rs = $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows" , $inputarr ); + $rs = $this->cacheExecute($secs, $sql . " LIMIT $offsetStr$nrows" , $inputarr ); else - $rs = $this->Execute($sql . " LIMIT $offsetStr$nrows" , $inputarr ); + $rs = $this->execute($sql . " LIMIT $offsetStr$nrows" , $inputarr ); return $rs; } - + /** + * Prepares an SQL statement and returns a handle to use. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:prepare + * @todo update this function to handle prepared statements correctly + * + * @param string $sql The SQL to prepare. + * + * @return string The original SQL that was provided. + */ function Prepare($sql) { + /* + * Flag the insert_id method to use the correct retrieval method + */ + $this->usePreparedStatement = true; + + /* + * Prepared statements are not yet handled correctly + */ return $sql; $stmt = $this->_connectionID->prepare($sql); if (!$stmt) { - echo $this->ErrorMsg(); + echo $this->errorMsg(); return $sql; } return array($sql,$stmt); } - - // returns queryID or false + /** + * Return the query id. + * + * @param string|array $sql + * @param array $inputarr + * + * @return bool|mysqli_result + */ function _query($sql, $inputarr) { - global $ADODB_COUNTRECS; + global $ADODB_COUNTRECS; // Move to the next recordset, or return false if there is none. In a stored proc // call, mysqli_next_result returns true for the last "recordset", but mysqli_store_result // returns false. I think this is because the last "recordset" is actually just the @@ -762,21 +1097,36 @@ class ADODB_mysqli extends ADOConnection { else $a .= 'd'; } + /* + * set prepared statement flags + */ + if ($this->usePreparedStatement) + $this->useLastInsertStatement = true; + $fnarr = array_merge( array($stmt,$a) , $inputarr); - $ret = call_user_func_array('mysqli_stmt_bind_param',$fnarr); + call_user_func_array('mysqli_stmt_bind_param',$fnarr); $ret = mysqli_stmt_execute($stmt); return $ret; } + else + { + /* + * reset prepared statement flags, in case we set them + * previously and didn't use them + */ + $this->usePreparedStatement = false; + $this->useLastInsertStatement = false; + } /* if (!$mysql_res = mysqli_query($this->_connectionID, $sql, ($ADODB_COUNTRECS) ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT)) { - if ($this->debug) ADOConnection::outp("Query: " . $sql . " failed. " . $this->ErrorMsg()); + if ($this->debug) ADOConnection::outp("Query: " . $sql . " failed. " . $this->errorMsg()); return false; } return $mysql_res; */ - + if ($this->multiQuery) { $rs = mysqli_multi_query($this->_connectionID, $sql.';'); if ($rs) { @@ -785,18 +1135,26 @@ class ADODB_mysqli extends ADOConnection { } } else { $rs = mysqli_query($this->_connectionID, $sql, $ADODB_COUNTRECS ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT); - - if ($rs) return $rs; + if ($rs) { + $this->isSelectStatement = is_object($rs); + return $rs; + } } if($this->debug) - ADOConnection::outp("Query: " . $sql . " failed. " . $this->ErrorMsg()); + ADOConnection::outp("Query: " . $sql . " failed. " . $this->errorMsg()); return false; } - /* Returns: the last error message from previous database operation */ + /** + * Returns a database specific error message. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:errormsg + * + * @return string The last error message. + */ function ErrorMsg() { if (empty($this->_connectionID)) @@ -806,7 +1164,11 @@ class ADODB_mysqli extends ADOConnection { return $this->_errorMsg; } - /* Returns: the last error number from previous database operation */ + /** + * Returns the last error number from previous database operation. + * + * @return int The last error number. + */ function ErrorNo() { if (empty($this->_connectionID)) @@ -815,72 +1177,73 @@ class ADODB_mysqli extends ADOConnection { return @mysqli_errno($this->_connectionID); } - // returns true or false + /** + * Close the database connection. + * + * @return void + */ function _close() { - @mysqli_close($this->_connectionID); + if($this->_connectionID) { + mysqli_close($this->_connectionID); + } $this->_connectionID = false; } - /* - * Maximum size of C field - */ + /** + * Returns the largest length of data that can be inserted into a character field. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:charmax + * + * @return int + */ function CharMax() { return 255; } - /* - * Maximum size of X field - */ + /** + * Returns the largest length of data that can be inserted into a text field. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:textmax + * + * @return int + */ function TextMax() { return 4294967295; } - - // this is a set of functions for managing client encoding - very important if the encodings - // of your database and your output target (i.e. HTML) don't match - // for instance, you may have UTF8 database and server it on-site as latin1 etc. - // GetCharSet - get the name of the character set the client is using now - // Under Windows, the functions should work with MySQL 4.1.11 and above, the set of charsets supported - // depends on compile flags of mysql distribution - - function GetCharSet() + function getCharSet() { - //we will use ADO's builtin property charSet - if (!method_exists($this->_connectionID,'character_set_name')) - return false; - - $this->charSet = @$this->_connectionID->character_set_name(); - if (!$this->charSet) { + if (!$this->_connectionID || !method_exists($this->_connectionID,'character_set_name')) { return false; - } else { - return $this->charSet; } + + $this->charSet = $this->_connectionID->character_set_name(); + return $this->charSet ?: false; } - // SetCharSet - switch the client encoding - function SetCharSet($charset_name) + function setCharSet($charset) { - if (!method_exists($this->_connectionID,'set_charset')) { + if (!$this->_connectionID || !method_exists($this->_connectionID,'set_charset')) { return false; } - if ($this->charSet !== $charset_name) { - $if = @$this->_connectionID->set_charset($charset_name); - return ($if === true & $this->GetCharSet() == $charset_name); - } else { - return true; + if ($this->charSet !== $charset) { + if (!$this->_connectionID->set_charset($charset)) { + return false; + } + $this->getCharSet(); } + return true; } } -/*-------------------------------------------------------------------------------------- - Class Name: Recordset ---------------------------------------------------------------------------------------*/ - +/** + * Class ADORecordSet_mysqli + */ class ADORecordSet_mysqli extends ADORecordSet{ var $databaseType = "mysqli"; @@ -938,6 +1301,15 @@ class ADORecordSet_mysqli extends ADORecordSet{ 131072 = MYSQLI_BINCMP_FLAG */ + /** + * Returns raw, database specific information about a field. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:recordset:fetchfield + * + * @param int $fieldOffset (Optional) The field number to get information for. + * + * @return ADOFieldObject|bool + */ function FetchField($fieldOffset = -1) { $fieldnr = $fieldOffset; @@ -959,19 +1331,43 @@ class ADORecordSet_mysqli extends ADORecordSet{ // $o->blob = $o->flags & MYSQLI_BLOB_FLAG; /* not returned by MetaColumns */ $o->unsigned = $o->flags & MYSQLI_UNSIGNED_FLAG; - return $o; + /* + * Trivial method to cast class to ADOfieldObject + */ + $a = new ADOFieldObject; + foreach (get_object_vars($o) as $key => $name) + $a->$key = $name; + return $a; } + /** + * Reads a row in associative mode if the recordset fetch mode is numeric. + * Using this function when the fetch mode is set to ADODB_FETCH_ASSOC may produce unpredictable results. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:getrowassoc + * + * @param int $upper Indicates whether the keys of the recordset should be upper case or lower case. + * + * @return array|bool + */ function GetRowAssoc($upper = ADODB_ASSOC_CASE) { if ($this->fetchMode == MYSQLI_ASSOC && $upper == ADODB_ASSOC_CASE_LOWER) { return $this->fields; } - $row = ADORecordSet::GetRowAssoc($upper); + $row = ADORecordSet::getRowAssoc($upper); return $row; } - /* Use associative array to get fields array */ + /** + * Returns a single field in a single row of the current recordset. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:recordset:fields + * + * @param string $colname The name of the field to retrieve. + * + * @return mixed + */ function Fields($colname) { if ($this->fetchMode != MYSQLI_NUM) { @@ -981,13 +1377,20 @@ class ADORecordSet_mysqli extends ADORecordSet{ if (!$this->bind) { $this->bind = array(); for ($i = 0; $i < $this->_numOfFields; $i++) { - $o = $this->FetchField($i); + $o = $this->fetchField($i); $this->bind[strtoupper($o->name)] = $i; } } return $this->fields[$this->bind[strtoupper($colname)]]; } + /** + * Adjusts the result pointer to an arbitrary row in the result. + * + * @param int $row The row to seek to. + * + * @return bool False if the recordset contains no rows, otherwise true. + */ function _seek($row) { if ($this->_numOfRows == 0 || $row < 0) { @@ -999,10 +1402,16 @@ class ADORecordSet_mysqli extends ADORecordSet{ return true; } - + /** + * In databases that allow accessing of recordsets, retrieves the next set. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:recordset:nextrecordset + * + * @return bool + */ function NextRecordSet() { - global $ADODB_COUNTRECS; + global $ADODB_COUNTRECS; mysqli_free_result($this->_queryID); $this->_queryID = -1; @@ -1010,25 +1419,32 @@ class ADORecordSet_mysqli extends ADORecordSet{ // call, mysqli_next_result returns true for the last "recordset", but mysqli_store_result // returns false. I think this is because the last "recordset" is actually just the // return value of the stored proc (ie the number of rows affected). - if(!mysqli_next_result($this->connection->_connectionID)) { - return false; + if (!mysqli_next_result($this->connection->_connectionID)) { + return false; } + // CD: There is no $this->_connectionID variable, at least in the ADO version I'm using - $this->_queryID = ($ADODB_COUNTRECS) ? @mysqli_store_result( $this->connection->_connectionID ) - : @mysqli_use_result( $this->connection->_connectionID ); - if(!$this->_queryID) { + $this->_queryID = ($ADODB_COUNTRECS) ? @mysqli_store_result($this->connection->_connectionID) + : @mysqli_use_result($this->connection->_connectionID); + + if (!$this->_queryID) { return false; } - $this->_inited = false; - $this->bind = false; + + $this->_inited = false; + $this->bind = false; $this->_currentRow = -1; - $this->Init(); + $this->init(); return true; } - // 10% speedup to move MoveNext to child class - // This is the only implementation that works now (23-10-2003). - // Other functions return no or the wrong results. + /** + * Moves the cursor to the next record of the recordset from the current position. + * + * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:movenext + * + * @return bool False if there are no more records to move on to, otherwise true. + */ function MoveNext() { if ($this->EOF) return false; @@ -1043,6 +1459,11 @@ class ADORecordSet_mysqli extends ADORecordSet{ return false; } + /** + * Attempt to fetch a result row using the current fetch mode and return whether or not this was successful. + * + * @return bool True if row was fetched successfully, otherwise false. + */ function _fetch() { $this->fields = mysqli_fetch_array($this->_queryID,$this->fetchMode); @@ -1050,18 +1471,23 @@ class ADORecordSet_mysqli extends ADORecordSet{ return is_array($this->fields); } + /** + * Frees the memory associated with a result. + * + * @return void + */ function _close() { - //if results are attached to this pointer from Stored Proceedure calls, the next standard query will die 2014 - //only a problem with persistant connections + //if results are attached to this pointer from Stored Procedure calls, the next standard query will die 2014 + //only a problem with persistent connections - if(isset($this->connection->_connectionID) && $this->connection->_connectionID) { - while(mysqli_more_results($this->connection->_connectionID)){ + if (isset($this->connection->_connectionID) && $this->connection->_connectionID) { + while (mysqli_more_results($this->connection->_connectionID)) { mysqli_next_result($this->connection->_connectionID); } } - if($this->_queryID instanceof mysqli_result) { + if ($this->_queryID instanceof mysqli_result) { mysqli_free_result($this->_queryID); } $this->_queryID = false; @@ -1096,6 +1522,15 @@ class ADORecordSet_mysqli extends ADORecordSet{ 255 = MYSQLI_TYPE_GEOMETRY */ + /** + * Get the MetaType character for a given field type. + * + * @param string|object $t The type to get the MetaType character for. + * @param int $len (Optional) Redundant. Will always be set to -1. + * @param bool|object $fieldobj (Optional) + * + * @return string The MetaType + */ function MetaType($t, $len = -1, $fieldobj = false) { if (is_object($t)) { @@ -1104,99 +1539,107 @@ class ADORecordSet_mysqli extends ADORecordSet{ $len = $fieldobj->max_length; } - $len = -1; // mysql max_length is not accurate switch (strtoupper($t)) { - case 'STRING': - case 'CHAR': - case 'VARCHAR': - case 'TINYBLOB': - case 'TINYTEXT': - case 'ENUM': - case 'SET': - - case MYSQLI_TYPE_TINY_BLOB : - #case MYSQLI_TYPE_CHAR : - case MYSQLI_TYPE_STRING : - case MYSQLI_TYPE_ENUM : - case MYSQLI_TYPE_SET : - case 253 : - 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 MYSQLI_TYPE_BLOB : - case MYSQLI_TYPE_LONG_BLOB : - case MYSQLI_TYPE_MEDIUM_BLOB : - return !empty($fieldobj->binary) ? 'B' : 'X'; - - case 'YEAR': - case 'DATE': - case MYSQLI_TYPE_DATE : - case MYSQLI_TYPE_YEAR : - return 'D'; - - case 'TIME': - case 'DATETIME': - case 'TIMESTAMP': - - case MYSQLI_TYPE_DATETIME : - case MYSQLI_TYPE_NEWDATE : - case MYSQLI_TYPE_TIME : - case MYSQLI_TYPE_TIMESTAMP : - return 'T'; - - case 'INT': - case 'INTEGER': - case 'BIGINT': - case 'TINYINT': - case 'MEDIUMINT': - case 'SMALLINT': - - case MYSQLI_TYPE_INT24 : - case MYSQLI_TYPE_LONG : - case MYSQLI_TYPE_LONGLONG : - case MYSQLI_TYPE_SHORT : - case MYSQLI_TYPE_TINY : - if (!empty($fieldobj->primary_key)) return 'R'; - return 'I'; - - // Added floating-point types - // Maybe not necessery. - case 'FLOAT': - case 'DOUBLE': -// case 'DOUBLE PRECISION': - case 'DECIMAL': - case 'DEC': - case 'FIXED': - default: - //if (!is_numeric($t)) echo "<p>--- Error in type matching $t -----</p>"; - return 'N'; + case 'STRING': + case 'CHAR': + case 'VARCHAR': + case 'TINYBLOB': + case 'TINYTEXT': + case 'ENUM': + case 'SET': + + case MYSQLI_TYPE_TINY_BLOB : +// case MYSQLI_TYPE_CHAR : + case MYSQLI_TYPE_STRING : + case MYSQLI_TYPE_ENUM : + case MYSQLI_TYPE_SET : + case 253 : + 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 MYSQLI_TYPE_BLOB : + case MYSQLI_TYPE_LONG_BLOB : + case MYSQLI_TYPE_MEDIUM_BLOB : + return !empty($fieldobj->binary) ? 'B' : 'X'; + + case 'YEAR': + case 'DATE': + case MYSQLI_TYPE_DATE : + case MYSQLI_TYPE_YEAR : + return 'D'; + + case 'TIME': + case 'DATETIME': + case 'TIMESTAMP': + + case MYSQLI_TYPE_DATETIME : + case MYSQLI_TYPE_NEWDATE : + case MYSQLI_TYPE_TIME : + case MYSQLI_TYPE_TIMESTAMP : + return 'T'; + + case 'INT': + case 'INTEGER': + case 'BIGINT': + case 'TINYINT': + case 'MEDIUMINT': + case 'SMALLINT': + + case MYSQLI_TYPE_INT24 : + case MYSQLI_TYPE_LONG : + case MYSQLI_TYPE_LONGLONG : + case MYSQLI_TYPE_SHORT : + case MYSQLI_TYPE_TINY : + if (!empty($fieldobj->primary_key)) { + return 'R'; + } + return 'I'; + + // Added floating-point types + // Maybe not necessary. + case 'FLOAT': + case 'DOUBLE': +// case 'DOUBLE PRECISION': + case 'DECIMAL': + case 'DEC': + case 'FIXED': + default: + //if (!is_numeric($t)) echo "<p>--- Error in type matching $t -----</p>"; + return 'N'; } - } // function + } } // rs class -} - -class ADORecordSet_array_mysqli extends ADORecordSet_array { - - function __construct($id=-1,$mode=false) - { - parent::__construct($id,$mode); - } - +/** + * Class ADORecordSet_array_mysqli + */ +class ADORecordSet_array_mysqli extends ADORecordSet_array +{ + /** + * Get the MetaType character for a given field type. + * + * @param string|object $t The type to get the MetaType character for. + * @param int $len (Optional) Redundant. Will always be set to -1. + * @param bool|object $fieldobj (Optional) + * + * @return string The MetaType + */ function MetaType($t, $len = -1, $fieldobj = false) { if (is_object($t)) { @@ -1205,90 +1648,89 @@ class ADORecordSet_array_mysqli extends ADORecordSet_array { $len = $fieldobj->max_length; } - $len = -1; // mysql max_length is not accurate switch (strtoupper($t)) { - case 'STRING': - case 'CHAR': - case 'VARCHAR': - case 'TINYBLOB': - case 'TINYTEXT': - case 'ENUM': - case 'SET': - - case MYSQLI_TYPE_TINY_BLOB : - #case MYSQLI_TYPE_CHAR : - case MYSQLI_TYPE_STRING : - case MYSQLI_TYPE_ENUM : - case MYSQLI_TYPE_SET : - case 253 : - 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 MYSQLI_TYPE_BLOB : - case MYSQLI_TYPE_LONG_BLOB : - case MYSQLI_TYPE_MEDIUM_BLOB : - - return !empty($fieldobj->binary) ? 'B' : 'X'; - case 'YEAR': - case 'DATE': - case MYSQLI_TYPE_DATE : - case MYSQLI_TYPE_YEAR : - - return 'D'; - - case 'TIME': - case 'DATETIME': - case 'TIMESTAMP': - - case MYSQLI_TYPE_DATETIME : - case MYSQLI_TYPE_NEWDATE : - case MYSQLI_TYPE_TIME : - case MYSQLI_TYPE_TIMESTAMP : - - return 'T'; - - case 'INT': - case 'INTEGER': - case 'BIGINT': - case 'TINYINT': - case 'MEDIUMINT': - case 'SMALLINT': - - case MYSQLI_TYPE_INT24 : - case MYSQLI_TYPE_LONG : - case MYSQLI_TYPE_LONGLONG : - case MYSQLI_TYPE_SHORT : - case MYSQLI_TYPE_TINY : - - if (!empty($fieldobj->primary_key)) return 'R'; - - return 'I'; - - - // Added floating-point types - // Maybe not necessery. - case 'FLOAT': - case 'DOUBLE': -// case 'DOUBLE PRECISION': - case 'DECIMAL': - case 'DEC': - case 'FIXED': - default: - //if (!is_numeric($t)) echo "<p>--- Error in type matching $t -----</p>"; - return 'N'; - } - } // function + case 'STRING': + case 'CHAR': + case 'VARCHAR': + case 'TINYBLOB': + case 'TINYTEXT': + case 'ENUM': + case 'SET': + + case MYSQLI_TYPE_TINY_BLOB : +// case MYSQLI_TYPE_CHAR : + case MYSQLI_TYPE_STRING : + case MYSQLI_TYPE_ENUM : + case MYSQLI_TYPE_SET : + case 253 : + 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 MYSQLI_TYPE_BLOB : + case MYSQLI_TYPE_LONG_BLOB : + case MYSQLI_TYPE_MEDIUM_BLOB : + return !empty($fieldobj->binary) ? 'B' : 'X'; + + case 'YEAR': + case 'DATE': + case MYSQLI_TYPE_DATE : + case MYSQLI_TYPE_YEAR : + return 'D'; + + case 'TIME': + case 'DATETIME': + case 'TIMESTAMP': + + case MYSQLI_TYPE_DATETIME : + case MYSQLI_TYPE_NEWDATE : + case MYSQLI_TYPE_TIME : + case MYSQLI_TYPE_TIMESTAMP : + return 'T'; + + case 'INT': + case 'INTEGER': + case 'BIGINT': + case 'TINYINT': + case 'MEDIUMINT': + case 'SMALLINT': + + case MYSQLI_TYPE_INT24 : + case MYSQLI_TYPE_LONG : + case MYSQLI_TYPE_LONGLONG : + case MYSQLI_TYPE_SHORT : + case MYSQLI_TYPE_TINY : + if (!empty($fieldobj->primary_key)) { + return 'R'; + } + return 'I'; + + // Added floating-point types + // Maybe not necessary. + case 'FLOAT': + case 'DOUBLE': +// case 'DOUBLE PRECISION': + case 'DECIMAL': + case 'DEC': + case 'FIXED': + default: + //if (!is_numeric($t)) echo "<p>--- Error in type matching $t -----</p>"; + return 'N'; + } + } } + +} // if defined _ADODB_MYSQLI_LAYER diff --git a/libraries/adodb/drivers/adodb-mysqlpo.inc.php b/libraries/adodb/drivers/adodb-mysqlpo.inc.php index 26b354aee..8aa7779ad 100644 --- a/libraries/adodb/drivers/adodb-mysqlpo.inc.php +++ b/libraries/adodb/drivers/adodb-mysqlpo.inc.php @@ -1,24 +1,30 @@ <?php - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 8. - - MySQL code that supports transactions. For MySQL 3.23 or later. - Code from James Poon <jpoon88@yahoo.com> - - This driver 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. - - Requires mysql client. Works on Windows and Unix. -*/ +/** + * 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(); @@ -32,11 +38,6 @@ class ADODB_mysqlt extends ADODB_mysql { var $hasTransactions = true; var $autoRollback = true; // apparently mysql does not autorollback properly - function __construct() - { - global $ADODB_EXTENSION; if ($ADODB_EXTENSION) $this->rsPrefix .= 'ext_'; - } - function BeginTrans() { if ($this->transOff) return true; @@ -116,11 +117,6 @@ class ADORecordSet_mysqlt extends ADORecordSet_mysql{ class ADORecordSet_ext_mysqlt extends ADORecordSet_mysqlt { - function __construct($queryID,$mode=false) - { - parent::__construct($queryID,$mode); - } - function MoveNext() { return adodb_movenext($this); diff --git a/libraries/adodb/drivers/adodb-mysqlt.inc.php b/libraries/adodb/drivers/adodb-mysqlt.inc.php index 79c937600..cccd93f8d 100644 --- a/libraries/adodb/drivers/adodb-mysqlt.inc.php +++ b/libraries/adodb/drivers/adodb-mysqlt.inc.php @@ -1,21 +1,30 @@ <?php - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 8. - - This driver only supports the original MySQL driver in transactional mode. It - is deprected 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 - - Requires mysql client. Works on Windows and Unix. -*/ +/** + * 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(); @@ -29,11 +38,6 @@ class ADODB_mysqlt extends ADODB_mysql { var $hasTransactions = true; var $autoRollback = true; // apparently mysql does not autorollback properly - function __construct() - { - global $ADODB_EXTENSION; if ($ADODB_EXTENSION) $this->rsPrefix .= 'ext_'; - } - /* set transaction mode SET [GLOBAL | SESSION] TRANSACTION ISOLATION LEVEL diff --git a/libraries/adodb/drivers/adodb-netezza.inc.php b/libraries/adodb/drivers/adodb-netezza.inc.php index af3a1a11d..dc7c58e42 100644 --- a/libraries/adodb/drivers/adodb-netezza.inc.php +++ b/libraries/adodb/drivers/adodb-netezza.inc.php @@ -1,21 +1,35 @@ <?php -/* - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - - First cut at the Netezza Driver by Josh Eldridge joshuae74#hotmail.com - Based on the previous postgres drivers. - http://www.netezza.com/ - Major Additions/Changes: - MetaDatabasesSQL, MetaTablesSQL, MetaColumnsSQL - Note: You have to have admin privileges to access the system tables - Removed non-working keys code (Netezza has no concept of keys) - Fixed the way data types and lengths are returned in MetaColumns() - as well as added the default lengths for certain types - Updated public variables for Netezza - Still need to remove blob functions, as Netezza doesn't suppport blob -*/ +/** + * Netezza Driver + * + * @link https://www.ibm.com/products/netezza + * Based on the previous postgres drivers. Major Additions/Changes: + * - MetaDatabasesSQL, MetaTablesSQL, MetaColumnsSQL + * Note: You have to have admin privileges to access the system tables + * - Removed non-working keys code (Netezza has no concept of keys) + * - Fixed the way data types and lengths are returned in MetaColumns() + * as well as added the default lengths for certain types + * - Updated public variables for Netezza + * TODO: Still need to remove blob functions, as Netezza doesn't support blob + * + * 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 Josh Eldridge <joshuae74@hotmail.com> + */ + // security - hide paths if (!defined('ADODB_DIR')) die(); @@ -50,11 +64,6 @@ class ADODB_netezza extends ADODB_postgres64 { // http://bugs.php.net/bug.php?id=25404 - function __construct() - { - - } - function MetaColumns($table,$upper=true) { @@ -141,11 +150,6 @@ class ADORecordSet_netezza extends ADORecordSet_postgres64 var $databaseType = "netezza"; var $canSeek = true; - function __construct($queryID,$mode=false) - { - parent::__construct($queryID,$mode); - } - // _initrs modified to disable blob handling function _initrs() { diff --git a/libraries/adodb/drivers/adodb-oci8.inc.php b/libraries/adodb/drivers/adodb-oci8.inc.php index 928d1b843..e541b6b6a 100644 --- a/libraries/adodb/drivers/adodb-oci8.inc.php +++ b/libraries/adodb/drivers/adodb-oci8.inc.php @@ -1,20 +1,25 @@ <?php -/* - - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim. All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Latest version is available at http://adodb.sourceforge.net - - Code contributed by George Fourlanos <fou@infomap.gr> - - 13 Nov 2000 jlim - removed all ora_* references. -*/ +/** + * FileDescription + * + * 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 John Lim + * @author George Fourlanos <fou@infomap.gr> + */ // security - hide paths if (!defined('ADODB_DIR')) die(); @@ -89,7 +94,6 @@ END; var $connectSID = false; var $_bind = false; var $_nestedSQL = true; - var $_hasOciFetchStatement = false; var $_getarray = false; // currently not working var $leftOuter = ''; // oracle wierdness, $col = $value (+) for LEFT OUTER, $col (+)= $value for RIGHT OUTER var $session_sharing_force_blob = false; // alter session on updateblob if set to true @@ -103,13 +107,20 @@ END; // var $ansiOuter = true; // if oracle9 - function __construct() - { - $this->_hasOciFetchStatement = ADODB_PHPVER >= 0x4200; - if (defined('ADODB_EXTENSION')) { - $this->rsPrefix .= 'ext_'; - } - } + /* + * Legacy compatibility for sequence names for emulated auto-increments + */ + public $useCompactAutoIncrements = false; + + /* + * Defines the schema name for emulated auto-increment columns + */ + public $schema = false; + + /* + * Defines the prefix for emulated auto-increment columns + */ + public $seqPrefix = 'SEQ_'; /* function MetaColumns($table, $normalize=true) added by smondino@users.sourceforge.net*/ function MetaColumns($table, $normalize=true) @@ -308,6 +319,42 @@ END; return " NVL($field, $ifNull) "; // if Oracle } + protected function _insertID($table = '', $column = '') + { + + if (!$this->seqField) + return false; + + if ($this->schema) + { + $t = strpos($table,'.'); + if ($t !== false) + $tab = substr($table,$t+1); + else + $tab = $table; + + if ($this->useCompactAutoIncrements) + $tab = sprintf('%u',crc32(strtolower($tab))); + + $seqname = $this->schema.'.'.$this->seqPrefix.$tab; + } + else + { + if ($this->useCompactAutoIncrements) + $table = sprintf('%u',crc32(strtolower($table))); + + $seqname = $this->seqPrefix.$table; + } + + if (strlen($seqname) > 30) + /* + * We cannot successfully identify the sequence + */ + return false; + + return $this->getOne("SELECT $seqname.currval FROM dual"); + } + // format and return date string in database date format function DBDate($d,$isfld=false) { @@ -709,6 +756,8 @@ END; */ function SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) { + $nrows = (int) $nrows; + $offset = (int) $offset; // Since the methods used to limit the number of returned rows rely // on modifying the provided SQL query, we can't work with prepared // statements so we just extract the SQL string. @@ -945,7 +994,7 @@ END; $element0 = reset($inputarr); $array2d = $this->bulkBind && is_array($element0) && !is_object(reset($element0)); - # see http://phplens.com/lens/lensforum/msgs.php?id=18786 + # see PHPLens Issue No: 18786 if ($array2d || !$this->_bindInputArray) { # is_object check because oci8 descriptors can be passed in @@ -1495,37 +1544,27 @@ SELECT /*+ RULE */ distinct b.column_name } /** - * Quotes a string. - * An example is $db->qstr("Don't bother",magic_quotes_runtime()); + * Correctly quotes a string so that all strings are escaped. + * We prefix and append to the string single-quotes. + * An example is $db->qstr("Don't bother"); * - * @param string $s the string to quote - * @param bool $magic_quotes if $s is GET/POST var, set to get_magic_quotes_gpc(). - * This undoes the stupidity of magic quotes for GPC. + * @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 to be sent back to database + * @return string Quoted string to be sent back to database + * + * @noinspection PhpUnusedParameterInspection */ - function qstr($s,$magic_quotes=false) + function qStr($s, $magic_quotes=false) { - //$nofixquotes=false; - - if ($this->noNullStrings && strlen($s)==0) { + if ($this->noNullStrings && strlen($s) == 0) { $s = ' '; } - if (!$magic_quotes) { - if ($this->replaceQuote[0] == '\\'){ - $s = str_replace('\\','\\\\',$s); - } - return "'".str_replace("'",$this->replaceQuote,$s)."'"; - } - - // undo magic quotes for " unless sybase is on - if (!ini_get('magic_quotes_sybase')) { - $s = str_replace('\\"','"',$s); - $s = str_replace('\\\\','\\',$s); - return "'".str_replace("\\'",$this->replaceQuote,$s)."'"; - } else { - return "'".$s."'"; + if ($this->replaceQuote[0] == '\\'){ + $s = str_replace('\\','\\\\',$s); } + return "'" . str_replace("'", $this->replaceQuote, $s) . "'"; } } @@ -1564,6 +1603,12 @@ class ADORecordset_oci8 extends ADORecordSet { $this->_queryID = $queryID; } + /** + * Overrides the core destructor method as that causes problems here + * + * @return void + */ + function __destruct() {} function Init() { @@ -1583,7 +1628,7 @@ class ADORecordset_oci8 extends ADORecordSet { /* // based on idea by Gaetano Giunta to detect unusual oracle errors - // see http://phplens.com/lens/lensforum/msgs.php?id=6771 + // see PHPLens Issue No: 6771 $err = oci_error($this->_queryID); if ($err && $this->connection->debug) { ADOConnection::outp($err); @@ -1743,7 +1788,8 @@ class ADORecordset_oci8 extends ADORecordSet { oci_free_cursor($this->_refcursor); $this->_refcursor = false; } - @oci_free_statement($this->_queryID); + if (is_resource($this->_queryID)) + @oci_free_statement($this->_queryID); $this->_queryID = false; } @@ -1800,16 +1846,12 @@ class ADORecordset_oci8 extends ADORecordSet { return 'I'; default: - return 'N'; + return ADODB_DEFAULT_METATYPE; } } } class ADORecordSet_ext_oci8 extends ADORecordSet_oci8 { - function __construct($queryID,$mode=false) - { - parent::__construct($queryID, $mode); - } function MoveNext() { diff --git a/libraries/adodb/drivers/adodb-oci805.inc.php b/libraries/adodb/drivers/adodb-oci805.inc.php index 112e9eccd..01958282c 100644 --- a/libraries/adodb/drivers/adodb-oci805.inc.php +++ b/libraries/adodb/drivers/adodb-oci805.inc.php @@ -1,18 +1,27 @@ <?php /** - * @version v5.20.9 21-Dec-2016 - * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - * @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - * Released under both BSD license and Lesser GPL library license. - * Whenever there is any discrepancy between the two licenses, - * the BSD license will take precedence. + * Oracle 8.0.5 (oci8) driver * - * Set tabs to 4 for best viewing. + * @deprecated * - * Latest version is available at http://php.weblogs.com + * Optimizes selectLimit() performance with FIRST_ROWS hint. * - * Oracle 8.0.5 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(); @@ -48,8 +57,4 @@ class ADODB_oci805 extends ADODB_oci8 { class ADORecordset_oci805 extends ADORecordset_oci8 { var $databaseType = "oci805"; - function __construct($id,$mode=false) - { - parent::__construct($id,$mode); - } } diff --git a/libraries/adodb/drivers/adodb-oci8po.inc.php b/libraries/adodb/drivers/adodb-oci8po.inc.php index 6b939b0a0..50630cad6 100644 --- a/libraries/adodb/drivers/adodb-oci8po.inc.php +++ b/libraries/adodb/drivers/adodb-oci8po.inc.php @@ -1,23 +1,28 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim. All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Latest version is available at http://adodb.sourceforge.net - - Portable version of oci8 driver, to make it more similar to other database drivers. - The main differences are - - 1. that the OCI_ASSOC names are in lowercase instead of uppercase. - 2. bind variables are mapped using ? instead of :<bindvar> - - Should some emulation of RecordCount() be implemented? - -*/ +/** + * Portable version of Oracle oci8 driver + * + * This file is part of ADOdb, a Database Abstraction Layer library for PHP. + * + * Portable version of oci8 driver, to make it more similar to other database + * drivers. The main differences are + * 1. that the OCI_ASSOC names are in lowercase instead of uppercase. + * 2. bind variables are mapped using ? instead of :<bindvar> + * + * @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(); @@ -30,12 +35,6 @@ class ADODB_oci8po extends ADODB_oci8 { var $metaColumnsSQL = "select lower(cname),coltype,width, SCALE, PRECISION, NULLS, DEFAULTVAL from col where tname='%s' order by colno"; //changed by smondino@users.sourceforge. net var $metaTablesSQL = "select lower(table_name),table_type from cat where table_type in ('TABLE','VIEW')"; - function __construct() - { - $this->_hasOCIFetchStatement = ADODB_PHPVER >= 0x4200; - # oci8po does not support adodb extension: adodb_movenext() - } - function Param($name,$type='C') { return '?'; @@ -81,29 +80,89 @@ class ADODB_oci8po extends ADODB_oci8 { $arr['bind'.$i++] = $v; } } else { - // Need to identify if the ? is inside a quoted string, and if - // so not use it as a bind variable - preg_match_all('/".*\??"|\'.*\?.*?\'/', $sql, $matches); - foreach($matches[0] as $qmMatch){ - $qmReplace = str_replace('?', '-QUESTIONMARK-', $qmMatch); - $sql = str_replace($qmMatch, $qmReplace, $sql); - } - - // Replace parameters if any were found - $sqlarr = explode('?',$sql); - if(count($sqlarr) > 1) { - $sql = $sqlarr[0]; - - foreach ($inputarr as $k => $v) { - $sql .= ":$k" . $sqlarr[++$i]; - } - } - - $sql = str_replace('-QUESTIONMARK-', '?', $sql); + $sql = $this->extractBinds($sql,$inputarr); } } return ADODB_oci8::_query($sql,$inputarr); } + + /** + * Replaces compatibility bind markers with oracle ones and returns a + * valid sql statement + * + * This replaces a regexp based section of code that has been subject + * to numerous tweaks, as more extreme test cases have appeared. This + * is now done this like this to help maintainability and avoid the + * need to rely on regexp experienced maintainers + * + * @param string $sql The sql statement + * @param string[] $inputarr The bind array + * + * @return string The modified statement + */ + private function extractBinds($sql,$inputarr) + { + $inString = false; + $escaped = 0; + $sqlLength = strlen($sql) - 1; + $newSql = ''; + $bindCount = 0; + + /* + * inputarr is the passed in bind list, which is associative, but + * we only want the keys here + */ + $inputKeys = array_keys($inputarr); + + + for ($i=0;$i<=$sqlLength;$i++) + { + /* + * find the next character of the string + */ + $c = $sql[$i]; + + if ($c == "'" && !$inString && $escaped==0) + /* + * Found the start of a string inside the statement + */ + $inString = true; + elseif ($c == "\\" && $escaped==0) + /* + * The next character will be escaped + */ + $escaped = 1; + elseif ($c == "'" && $inString && $escaped==0) + /* + * We found the end of the string + */ + $inString = false; + + if ($escaped == 2) + $escaped = 0; + + if ($escaped==0 && !$inString && $c == '?') + /* + * We found a bind symbol, replace it with the oracle equivalent + */ + $newSql .= ':' . $inputKeys[$bindCount++]; + else + /* + * Add the current character the pile + */ + $newSql .= $c; + + if ($escaped == 1) + /* + * We have just found an escape character, make sure we ignore the + * next one that comes along, it might be a ' character + */ + $escaped = 2; + } + + return $newSql; + + } } /*-------------------------------------------------------------------------------------- @@ -114,11 +173,6 @@ class ADORecordset_oci8po extends ADORecordset_oci8 { var $databaseType = 'oci8po'; - function __construct($queryID,$mode=false) - { - parent::__construct($queryID,$mode); - } - function Fields($colname) { if ($this->fetchMode & OCI_ASSOC) return $this->fields[$colname]; diff --git a/libraries/adodb/drivers/adodb-oci8quercus.inc.php b/libraries/adodb/drivers/adodb-oci8quercus.inc.php index 1940e802e..f9312c9d7 100644 --- a/libraries/adodb/drivers/adodb-oci8quercus.inc.php +++ b/libraries/adodb/drivers/adodb-oci8quercus.inc.php @@ -1,23 +1,23 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim. All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Latest version is available at http://adodb.sourceforge.net - - Portable version of oci8 driver, to make it more similar to other database drivers. - The main differences are - - 1. that the OCI_ASSOC names are in lowercase instead of uppercase. - 2. bind variables are mapped using ? instead of :<bindvar> - - Should some emulation of RecordCount() be implemented? - -*/ +/** + * Oracle "quercus" 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(); @@ -28,10 +28,6 @@ class ADODB_oci8quercus extends ADODB_oci8 { var $databaseType = 'oci8quercus'; var $dataProvider = 'oci8'; - function __construct() - { - } - } /*-------------------------------------------------------------------------------------- @@ -42,11 +38,6 @@ class ADORecordset_oci8quercus extends ADORecordset_oci8 { var $databaseType = 'oci8quercus'; - function __construct($queryID,$mode=false) - { - parent::__construct($queryID,$mode); - } - function _FetchField($fieldOffset = -1) { global $QUERCUS; diff --git a/libraries/adodb/drivers/adodb-odbc.inc.php b/libraries/adodb/drivers/adodb-odbc.inc.php index efaa5bb1a..a9705e2d8 100644 --- a/libraries/adodb/drivers/adodb-odbc.inc.php +++ b/libraries/adodb/drivers/adodb-odbc.inc.php @@ -1,22 +1,41 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. -Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net +/** + * Base ODBC 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 + */ - Requires ODBC. Works on Windows and Unix. -*/ // security - hide paths if (!defined('ADODB_DIR')) die(); define("_ADODB_ODBC_LAYER", 2 ); +/* + * These constants are used to set define MetaColumns() method's behavior. + * - METACOLUMNS_RETURNS_ACTUAL makes the driver return the actual type, + * like all other drivers do (default) + * - METACOLUMNS_RETURNS_META is provided for legacy compatibility (makes + * driver behave as it did prior to v5.21) + * + * @see $metaColumnsReturnType + */ +DEFINE('METACOLUMNS_RETURNS_ACTUAL', 0); +DEFINE('METACOLUMNS_RETURNS_META', 1); + /*-------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------*/ @@ -36,22 +55,19 @@ class ADODB_odbc extends ADOConnection { var $curmode = SQL_CUR_USE_DRIVER; // See sqlext.h, SQL_CUR_DEFAULT == SQL_CUR_USE_DRIVER == 2L var $_genSeqSQL = "create table %s (id integer)"; var $_autocommit = true; - var $_haserrorfunctions = true; - var $_has_stupid_odbc_fetch_api_change = true; var $_lastAffectedRows = 0; var $uCaseTables = true; // for meta* functions, uppercase table names + + /* + * Tells the metaColumns feature whether to return actual or meta type + */ + public $metaColumnsReturnType = METACOLUMNS_RETURNS_ACTUAL; - function __construct() - { - $this->_haserrorfunctions = ADODB_PHPVER >= 0x4050; - $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200; - } + function __construct() {} // returns true or false function _connect($argDSN, $argUsername, $argPassword, $argDatabasename) { - global $php_errormsg; - if (!function_exists('odbc_connect')) return null; if (!empty($argDatabasename) && stristr($argDSN, 'Database=') === false) { @@ -61,10 +77,10 @@ class ADODB_odbc extends ADOConnection { $argDSN .= 'Database='.$argDatabasename; } - if (isset($php_errormsg)) $php_errormsg = ''; + $last_php_error = $this->resetLastError(); if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword); else $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,$this->curmode); - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); if (isset($this->connectStmt)) $this->Execute($this->connectStmt); return $this->_connectionID != false; @@ -73,12 +89,10 @@ class ADODB_odbc extends ADOConnection { // returns true or false function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename) { - global $php_errormsg; - if (!function_exists('odbc_connect')) return null; - if (isset($php_errormsg)) $php_errormsg = ''; - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; + $last_php_error = $this->resetLastError(); + $this->_errorMsg = ''; if ($this->debug && $argDatabasename) { ADOConnection::outp("For odbc PConnect(), $argDatabasename is not used. Place dsn in 1st parameter."); } @@ -86,7 +100,7 @@ class ADODB_odbc extends ADOConnection { if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword); else $this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,$this->curmode); - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); if ($this->_connectionID && $this->autoRollback) @odbc_rollback($this->_connectionID); if (isset($this->connectStmt)) $this->Execute($this->connectStmt); @@ -97,7 +111,7 @@ class ADODB_odbc extends ADOConnection { function ServerInfo() { - if (!empty($this->host) && ADODB_PHPVER >= 0x4300) { + if (!empty($this->host)) { $dsn = strtoupper($this->host); $first = true; $found = false; @@ -184,30 +198,25 @@ class ADODB_odbc extends ADOConnection { function ErrorMsg() { - if ($this->_haserrorfunctions) { - if ($this->_errorMsg !== false) return $this->_errorMsg; - if (empty($this->_connectionID)) return @odbc_errormsg(); - return @odbc_errormsg($this->_connectionID); - } else return ADOConnection::ErrorMsg(); + if ($this->_errorMsg !== false) return $this->_errorMsg; + if (empty($this->_connectionID)) return @odbc_errormsg(); + return @odbc_errormsg($this->_connectionID); } function ErrorNo() { + if ($this->_errorCode !== false) { + // bug in 4.0.6, error number can be corrupted string (should be 6 digits) + return (strlen($this->_errorCode)<=2) ? 0 : $this->_errorCode; + } - if ($this->_haserrorfunctions) { - if ($this->_errorCode !== false) { - // bug in 4.0.6, error number can be corrupted string (should be 6 digits) - return (strlen($this->_errorCode)<=2) ? 0 : $this->_errorCode; - } - - if (empty($this->_connectionID)) $e = @odbc_error(); - else $e = @odbc_error($this->_connectionID); + if (empty($this->_connectionID)) $e = @odbc_error(); + else $e = @odbc_error($this->_connectionID); - // bug in 4.0.6, error number can be corrupted string (should be 6 digits) - // so we check and patch - if (strlen($e)<=2) return 0; - return $e; - } else return ADOConnection::ErrorNo(); + // bug in 4.0.6, error number can be corrupted string (should be 6 digits) + // so we check and patch + if (strlen($e)<=2) return 0; + return $e; } @@ -262,7 +271,6 @@ class ADODB_odbc extends ADOConnection { $ADODB_FETCH_MODE = $savem; if (!$rs) return false; - $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; $arr = $rs->GetArray(); $rs->Close(); @@ -291,7 +299,6 @@ class ADODB_odbc extends ADOConnection { $false = false; return $false; } - $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; $arr = $rs->GetArray(); //print_r($arr); @@ -394,12 +401,11 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/od $savem = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - /*if (false) { // after testing, confirmed that the following does not work becoz of a bug + /*if (false) { // after testing, confirmed that the following does not work because of a bug $qid2 = odbc_tables($this->_connectionID); $rs = new ADORecordSet_odbc($qid2); $ADODB_FETCH_MODE = $savem; if (!$rs) return false; - $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; $rs->_fetch(); while (!$rs->EOF) { @@ -438,7 +444,6 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/od $ADODB_FETCH_MODE = $savem; if (!$rs) return $false; - $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; $rs->_fetch(); $retarr = array(); @@ -463,7 +468,16 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/od if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) { $fld = new ADOFieldObject(); $fld->name = $rs->fields[3]; - $fld->type = $this->ODBCTypes($rs->fields[4]); + if ($this->metaColumnsReturnType == METACOLUMNS_RETURNS_META) + /* + * This is the broken, original value + */ + $fld->type = $this->ODBCTypes($rs->fields[4]); + else + /* + * This is the correct new value + */ + $fld->type = $rs->fields[4]; // ref: http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraccgen/html/msdn_odk.asp // access uses precision to store length for char/varchar @@ -503,9 +517,8 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/od /* returns queryID or false */ function _query($sql,$inputarr=false) { - GLOBAL $php_errormsg; - if (isset($php_errormsg)) $php_errormsg = ''; - $this->_error = ''; + $last_php_error = $this->resetLastError(); + $this->_errorMsg = ''; if ($inputarr) { if (is_array($sql)) { @@ -514,17 +527,15 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/od $stmtid = odbc_prepare($this->_connectionID,$sql); if ($stmtid == false) { - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); return false; } } if (! odbc_execute($stmtid,$inputarr)) { //@odbc_free_result($stmtid); - if ($this->_haserrorfunctions) { - $this->_errorMsg = odbc_errormsg(); - $this->_errorCode = odbc_error(); - } + $this->_errorMsg = odbc_errormsg(); + $this->_errorCode = odbc_error(); return false; } @@ -532,10 +543,8 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/od $stmtid = $sql[1]; if (!odbc_execute($stmtid)) { //@odbc_free_result($stmtid); - if ($this->_haserrorfunctions) { - $this->_errorMsg = odbc_errormsg(); - $this->_errorCode = odbc_error(); - } + $this->_errorMsg = odbc_errormsg(); + $this->_errorCode = odbc_error(); return false; } } else @@ -552,17 +561,11 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/od odbc_longreadlen($stmtid,$this->maxblobsize); } - if ($this->_haserrorfunctions) { - $this->_errorMsg = ''; - $this->_errorCode = 0; - } else - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; + $this->_errorMsg = ''; + $this->_errorCode = 0; } else { - if ($this->_haserrorfunctions) { - $this->_errorMsg = odbc_errormsg(); - $this->_errorCode = odbc_error(); - } else - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; + $this->_errorMsg = odbc_errormsg(); + $this->_errorCode = odbc_error(); } return $stmtid; } @@ -606,7 +609,6 @@ class ADORecordSet_odbc extends ADORecordSet { var $databaseType = "odbc"; var $dataProvider = "odbc"; var $useFetchArray; - var $_has_stupid_odbc_fetch_api_change; function __construct($id,$mode=false) { @@ -664,7 +666,6 @@ class ADORecordSet_odbc extends ADORecordSet { // some silly drivers such as db2 as/400 and intersystems cache return _numOfRows = 0 if ($this->_numOfRows == 0) $this->_numOfRows = -1; //$this->useFetchArray = $this->connection->useFetchArray; - $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200; } function _seek($row) @@ -715,12 +716,7 @@ class ADORecordSet_odbc extends ADORecordSet { function _fetch() { $this->fields = false; - if ($this->_has_stupid_odbc_fetch_api_change) - $rez = @odbc_fetch_into($this->_queryID,$this->fields); - else { - $row = 0; - $rez = @odbc_fetch_into($this->_queryID,$row,$this->fields); - } + $rez = @odbc_fetch_into($this->_queryID,$this->fields); if ($rez) { if ($this->fetchMode & ADODB_FETCH_ASSOC) { $this->fields = $this->GetRowAssoc(); diff --git a/libraries/adodb/drivers/adodb-odbc_db2.inc.php b/libraries/adodb/drivers/adodb-odbc_db2.inc.php index fa6d8b849..8f0e60cb1 100644 --- a/libraries/adodb/drivers/adodb-odbc_db2.inc.php +++ b/libraries/adodb/drivers/adodb-odbc_db2.inc.php @@ -1,98 +1,29 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. -Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - DB2 data driver. Requires ODBC. - -From phpdb list: - -Hi Andrew, - -thanks a lot for your help. Today we discovered what -our real problem was: - -After "playing" a little bit with the php-scripts that try -to connect to the IBM DB2, we set the optional parameter -Cursortype when calling odbc_pconnect(....). - -And the exciting thing: When we set the cursor type -to SQL_CUR_USE_ODBC Cursor Type, then -the whole query speed up from 1 till 10 seconds -to 0.2 till 0.3 seconds for 100 records. Amazing!!! - -Therfore, PHP is just almost fast as calling the DB2 -from Servlets using JDBC (don't take too much care -about the speed at whole: the database was on a -completely other location, so the whole connection -was made over a slow network connection). - -I hope this helps when other encounter the same -problem when trying to connect to DB2 from -PHP. - -Kind regards, -Christian Szardenings - -2 Oct 2001 -Mark Newnham has discovered that the SQL_CUR_USE_ODBC is not supported by -IBM's DB2 ODBC driver, so this must be a 3rd party ODBC driver. - -From the IBM CLI Reference: - -SQL_ATTR_ODBC_CURSORS (DB2 CLI v5) -This connection attribute is defined by ODBC, but is not supported by DB2 -CLI. Any attempt to set or get this attribute will result in an SQLSTATE of -HYC00 (Driver not capable). - -A 32-bit option specifying how the Driver Manager uses the ODBC cursor -library. - -So I guess this means the message [above] was related to using a 3rd party -odbc driver. - -Setting SQL_CUR_USE_ODBC -======================== -To set SQL_CUR_USE_ODBC for drivers that require it, do this: - -$db = NewADOConnection('odbc_db2'); -$db->curMode = SQL_CUR_USE_ODBC; -$db->Connect($dsn, $userid, $pwd); - - - -USING CLI INTERFACE -=================== - -I have had reports that the $host and $database params have to be reversed in -Connect() when using the CLI interface. From Halmai Csongor csongor.halmai#nexum.hu: - -> The symptom is that if I change the database engine from postgres or any other to DB2 then the following -> connection command becomes wrong despite being described this version to be correct in the docs. -> -> $connection_object->Connect( $DATABASE_HOST, $DATABASE_AUTH_USER_NAME, $DATABASE_AUTH_PASSWORD, $DATABASE_NAME ) -> -> In case of DB2 I had to swap the first and last arguments in order to connect properly. - - -System Error 5 -============== -IF you get a System Error 5 when trying to Connect/Load, it could be a permission problem. Give the user connecting -to DB2 full rights to the DB2 SQLLIB directory, and place the user in the DBUSERS group. -*/ +/** + * DB2 driver via ODBC + * + * 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_ODBC_LAYER')) { - include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); + include_once(ADODB_DIR."/drivers/adodb-odbc.inc.php"); } if (!defined('ADODB_ODBC_DB2')){ define('ADODB_ODBC_DB2',1); @@ -131,7 +62,7 @@ class ADODB_ODBC_DB2 extends ADODB_odbc { return array('description'=>'DB2 ODBC driver', 'version'=>$vers); } - function _insertid() + protected function _insertID($table = '', $column = '') { return $this->GetOne($this->identitySQL); } @@ -157,7 +88,6 @@ class ADODB_ODBC_DB2 extends ADODB_odbc { $false = false; return $false; } - $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; $arr = $rs->GetArray(); //print_r($arr); @@ -306,11 +236,6 @@ class ADORecordSet_odbc_db2 extends ADORecordSet_odbc { var $databaseType = "db2"; - function __construct($id,$mode=false) - { - parent::__construct($id,$mode); - } - function MetaType($t,$len=-1,$fieldobj=false) { if (is_object($t)) { @@ -361,7 +286,7 @@ class ADORecordSet_odbc_db2 extends ADORecordSet_odbc { case 'I': return 'I'; - default: return 'N'; + default: return ADODB_DEFAULT_METATYPE; } } } diff --git a/libraries/adodb/drivers/adodb-odbc_mssql.inc.php b/libraries/adodb/drivers/adodb-odbc_mssql.inc.php index aa6431680..37185aac3 100644 --- a/libraries/adodb/drivers/adodb-odbc_mssql.inc.php +++ b/libraries/adodb/drivers/adodb-odbc_mssql.inc.php @@ -1,24 +1,29 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. -Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - MSSQL support via ODBC. Requires ODBC. Works on Windows and Unix. - For Unix configuration, see http://phpbuilder.com/columns/alberto20000919.php3 -*/ +/** + * MSSQL driver via ODBC + * + * 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_ODBC_LAYER')) { - include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); + include_once(ADODB_DIR."/drivers/adodb-odbc.inc.php"); } @@ -47,12 +52,6 @@ class ADODB_odbc_mssql extends ADODB_odbc { var $connectStmt = 'SET CONCAT_NULL_YIELDS_NULL OFF'; # When SET CONCAT_NULL_YIELDS_NULL is ON, # concatenating a null value with a string yields a NULL result - function __construct() - { - parent::__construct(); - //$this->curmode = SQL_CUR_USE_ODBC; - } - // crashes php... function ServerInfo() { @@ -72,7 +71,7 @@ class ADODB_odbc_mssql extends ADODB_odbc { return " ISNULL($field, $ifNull) "; // if MS SQL Server } - function _insertid() + protected function _insertID($table = '', $column = '') { // SCOPE_IDENTITY() // Returns the last IDENTITY value inserted into an IDENTITY column in @@ -280,6 +279,8 @@ order by constraint_name, referenced_table_name, keyno"; function SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) { + $nrows = (int) $nrows; + $offset = (int) $offset; if ($nrows > 0 && $offset <= 0) { $sql = preg_replace( '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop." $nrows ",$sql); @@ -350,14 +351,89 @@ order by constraint_name, referenced_table_name, keyno"; return $s; } + /** + * Returns a substring of a varchar type field + * + * The SQL server version varies because the length is mandatory, so + * we append a reasonable string length + * + * @param string $fld The field to sub-string + * @param int $start The start point + * @param int $length An optional length + * + * @return The SQL text + */ + function substr($fld,$start,$length=0) + { + if ($length == 0) + /* + * The length available to varchar is 2GB, but that makes no + * sense in a substring, so I'm going to arbitrarily limit + * the length to 1K, but you could change it if you want + */ + $length = 1024; + + $text = "SUBSTRING($fld,$start,$length)"; + return $text; + } + + /** + * Returns the maximum size of a MetaType C field. Because of the + * database design, SQL Server places no limits on the size of data inserted + * Although the actual limit is 2^31-1 bytes. + * + * @return int + */ + function charMax() + { + return ADODB_STRINGMAX_NOLIMIT; + } + + /** + * Returns the maximum size of a MetaType X field. Because of the + * database design, SQL Server places no limits on the size of data inserted + * Although the actual limit is 2^31-1 bytes. + * + * @return int + */ + function textMax() + { + return ADODB_STRINGMAX_NOLIMIT; + } + + // returns concatenated string + // MSSQL requires integers to be cast as strings + // automatically cast every datatype to VARCHAR(255) + // @author David Rogers (introspectshun) + function Concat() + { + $s = ""; + $arr = func_get_args(); + + // Split single record on commas, if possible + if (sizeof($arr) == 1) { + foreach ($arr as $arg) { + $args = explode(',', $arg); + } + $arr = $args; + } + + array_walk( + $arr, + function(&$value, $key) { + $value = "CAST(" . $value . " AS VARCHAR(255))"; + } + ); + $s = implode('+',$arr); + if (sizeof($arr) > 0) return "$s"; + + return ''; + } + } class ADORecordSet_odbc_mssql extends ADORecordSet_odbc { var $databaseType = 'odbc_mssql'; - function __construct($id,$mode=false) - { - return parent::__construct($id,$mode); - } } diff --git a/libraries/adodb/drivers/adodb-odbc_mssql2012.inc.php b/libraries/adodb/drivers/adodb-odbc_mssql2012.inc.php new file mode 100644 index 000000000..79fa32516 --- /dev/null +++ b/libraries/adodb/drivers/adodb-odbc_mssql2012.inc.php @@ -0,0 +1,37 @@ +<?php +/** + * Microsoft SQL Server 2012 driver via ODBC + * + * 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 + */ + +if (!defined('ADODB_DIR')) + die(); + +include_once(ADODB_DIR."/drivers/adodb-odbc_mssql.inc.php"); + +class ADODB_odbc_mssql2012 extends ADODB_odbc_mssql +{ + /* + * Makes behavior similar to prior versions of SQL Server + */ + var $connectStmt = 'SET CONCAT_NULL_YIELDS_NULL ON'; +} + +class ADORecordSet_odbc_mssql2012 extends ADORecordSet_odbc_mssql +{ +} \ No newline at end of file diff --git a/libraries/adodb/drivers/adodb-odbc_oracle.inc.php b/libraries/adodb/drivers/adodb-odbc_oracle.inc.php index dfa851c0a..d8461e1a9 100644 --- a/libraries/adodb/drivers/adodb-odbc_oracle.inc.php +++ b/libraries/adodb/drivers/adodb-odbc_oracle.inc.php @@ -1,22 +1,29 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. -Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Oracle support via ODBC. Requires ODBC. Works on Windows. -*/ +/** + * Oracle driver via ODBC + * + * 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_ODBC_LAYER')) { - include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); + include_once(ADODB_DIR."/drivers/adodb-odbc.inc.php"); } @@ -76,11 +83,9 @@ class ADODB_odbc_oracle extends ADODB_odbc { // returns true or false function _connect($argDSN, $argUsername, $argPassword, $argDatabasename) { - global $php_errormsg; - - $php_errormsg = ''; + $last_php_error = $this->resetLastError(); $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,SQL_CUR_USE_ODBC ); - $this->_errorMsg = $php_errormsg; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); $this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'"); //if ($this->_connectionID) odbc_autocommit($this->_connectionID,true); @@ -89,10 +94,9 @@ class ADODB_odbc_oracle extends ADODB_odbc { // returns true or false function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename) { - global $php_errormsg; - $php_errormsg = ''; + $last_php_error = $this->resetLastError(); $this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,SQL_CUR_USE_ODBC ); - $this->_errorMsg = $php_errormsg; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); $this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'"); //if ($this->_connectionID) odbc_autocommit($this->_connectionID,true); @@ -104,8 +108,4 @@ class ADORecordSet_odbc_oracle extends ADORecordSet_odbc { var $databaseType = 'odbc_oracle'; - function __construct($id,$mode=false) - { - return parent::__construct($id,$mode); - } } diff --git a/libraries/adodb/drivers/adodb-odbtp.inc.php b/libraries/adodb/drivers/adodb-odbtp.inc.php index ec374a5db..bd167a1c8 100644 --- a/libraries/adodb/drivers/adodb-odbtp.inc.php +++ b/libraries/adodb/drivers/adodb-odbtp.inc.php @@ -1,15 +1,26 @@ <?php -/* - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. See License.txt. - Set tabs to 4 for best viewing. - Latest version is available at http://adodb.sourceforge.net -*/ -// Code contributed by "stefan bogdan" <sbogdan#rsb.ro> +/** + * ODBTP driver + * + * @deprecated will be removed in ADOdb version 6 + * + * 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 stefan bogdan <sbogdan@rsb.ro> + */ // security - hide paths if (!defined('ADODB_DIR')) die(); @@ -35,10 +46,6 @@ class ADODB_odbtp extends ADOConnection{ var $_canPrepareSP = false; var $_dontPoolDBC = true; - function __construct() - { - } - function ServerInfo() { return array('description' => @odbtp_get_attr( ODB_ATTR_DBMSNAME, $this->_connectionID), @@ -80,7 +87,7 @@ class ADODB_odbtp extends ADOConnection{ } */ - function _insertid() + protected function _insertID($table = '', $column = '') { // SCOPE_IDENTITY() // Returns the last IDENTITY value inserted into an IDENTITY column in @@ -609,9 +616,8 @@ class ADODB_odbtp extends ADOConnection{ function _query($sql,$inputarr=false) { - global $php_errormsg; - - $this->_errorMsg = false; + $last_php_error = $this->resetLastError(); + $this->_errorMsg = false; $this->_errorCode = false; if ($inputarr) { @@ -620,7 +626,7 @@ class ADODB_odbtp extends ADOConnection{ } else { $stmtid = @odbtp_prepare($sql,$this->_connectionID); if ($stmtid == false) { - $this->_errorMsg = $php_errormsg; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); return false; } } @@ -793,48 +799,28 @@ class ADORecordSet_odbtp_mssql extends ADORecordSet_odbtp { var $databaseType = 'odbtp_mssql'; - function __construct($id,$mode=false) - { - return parent::__construct($id,$mode); - } } class ADORecordSet_odbtp_access extends ADORecordSet_odbtp { var $databaseType = 'odbtp_access'; - function __construct($id,$mode=false) - { - return parent::__construct($id,$mode); - } } class ADORecordSet_odbtp_vfp extends ADORecordSet_odbtp { var $databaseType = 'odbtp_vfp'; - function __construct($id,$mode=false) - { - return parent::__construct($id,$mode); - } } class ADORecordSet_odbtp_oci8 extends ADORecordSet_odbtp { var $databaseType = 'odbtp_oci8'; - function __construct($id,$mode=false) - { - return parent::__construct($id,$mode); - } } class ADORecordSet_odbtp_sybase extends ADORecordSet_odbtp { var $databaseType = 'odbtp_sybase'; - function __construct($id,$mode=false) - { - return parent::__construct($id,$mode); - } } diff --git a/libraries/adodb/drivers/adodb-odbtp_unicode.inc.php b/libraries/adodb/drivers/adodb-odbtp_unicode.inc.php index 5ca03e717..190c3ab5e 100644 --- a/libraries/adodb/drivers/adodb-odbtp_unicode.inc.php +++ b/libraries/adodb/drivers/adodb-odbtp_unicode.inc.php @@ -1,32 +1,38 @@ <?php -/* - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. See License.txt. - Set tabs to 4 for best viewing. - Latest version is available at http://adodb.sourceforge.net -*/ - -// Code contributed by "Robert Twitty" <rtwitty#neutron.ushmm.org> +/** + * ODBTP Unicode driver. + * + * @deprecated will be removed in ADOdb version 6 + * + * Because the ODBTP server sends and reads UNICODE text data using UTF-8 + * encoding, the following HTML meta tag must be included within the HTML + * head section of every HTML form and script page: + * <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> + * Also, all SQL query strings must be submitted as UTF-8 encoded text. + * + * 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 Robert Twitty <rtwitty@neutron.ushmm.org> + */ // security - hide paths if (!defined('ADODB_DIR')) die(); -/* - Because the ODBTP server sends and reads UNICODE text data using UTF-8 - encoding, the following HTML meta tag must be included within the HTML - head section of every HTML form and script page: - - <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> - - Also, all SQL query strings must be submitted as UTF-8 encoded text. -*/ - if (!defined('_ADODB_ODBTP_LAYER')) { - include(ADODB_DIR."/drivers/adodb-odbtp.inc.php"); + include_once(ADODB_DIR."/drivers/adodb-odbtp.inc.php"); } class ADODB_odbtp_unicode extends ADODB_odbtp { diff --git a/libraries/adodb/drivers/adodb-oracle.inc.php b/libraries/adodb/drivers/adodb-oracle.inc.php index ca737d668..1a2735b14 100644 --- a/libraries/adodb/drivers/adodb-oracle.inc.php +++ b/libraries/adodb/drivers/adodb-oracle.inc.php @@ -1,18 +1,25 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Latest version is available at http://adodb.sourceforge.net - - Oracle data driver. Requires Oracle client. Works on Windows and Unix and Oracle 7. - - If you are using Oracle 8 or later, use the oci8 driver which is much better and more reliable. -*/ +/** + * Oracle data driver + * + * @deprecated Use oci8 driver instead + * + * 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(); @@ -29,10 +36,6 @@ class ADODB_oracle extends ADOConnection { var $sysTimeStamp = 'SYSDATE'; var $connectSID = true; - function __construct() - { - } - // format and return date string in database date format function DBDate($d, $isfld = false) { diff --git a/libraries/adodb/drivers/adodb-pdo.inc.php b/libraries/adodb/drivers/adodb-pdo.inc.php index b7b5577fa..0933bf144 100644 --- a/libraries/adodb/drivers/adodb-pdo.inc.php +++ b/libraries/adodb/drivers/adodb-pdo.inc.php @@ -1,23 +1,23 @@ <?php /** - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Requires ODBC. Works on Windows and Unix. - - Problems: - Where is float/decimal type in pdo_param_type - LOB handling for CLOB/BLOB differs significantly -*/ + * 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(); @@ -77,7 +77,6 @@ class ADODB_pdo extends ADOConnection { var $_genSeqSQL = "create table %s (id integer)"; var $_dropSeqSQL; var $_autocommit = true; - var $_haserrorfunctions = true; var $_lastAffectedRows = 0; var $_errormsg = false; @@ -87,9 +86,12 @@ class ADODB_pdo extends ADOConnection { var $stmt = false; var $_driver; - function __construct() - { - } + /* + * Describe parameters passed directly to the PDO driver + * + * @example $db->pdoOptions = [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]; + */ + public $pdoParameters = array(); function _UpdatePDO() { @@ -102,6 +104,7 @@ class ADODB_pdo extends ADOConnection { $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; @@ -144,12 +147,22 @@ class ADODB_pdo extends ADOConnection { 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->_connectionID = new \PDO($argDSN, $argUsername, $argPassword, $this->pdoParameters); } catch (Exception $e) { $this->_connectionID = false; $this->_errorno = -1; @@ -175,6 +188,16 @@ class ADODB_pdo extends ADOConnection { //$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) { @@ -184,6 +207,8 @@ class ADODB_pdo extends ADOConnection { case 'pgsql': case 'sqlite': case 'sqlsrv': + case 'firebird': + case 'dblib': include_once(ADODB_DIR.'/drivers/adodb-pdo_'.$this->dsnType.'.inc.php'); break; } @@ -210,10 +235,7 @@ class ADODB_pdo extends ADOConnection { return call_user_func_array(array($this->_driver, 'Concat'), $args); } - if (PHP_VERSION >= 5.3) { - return call_user_func_array('parent::Concat', $args); - } - return call_user_func_array(array($this,'parent::Concat'), $args); + return call_user_func_array('parent::Concat', $args); } // returns true or false @@ -251,6 +273,64 @@ class ADODB_pdo extends ADOConnection { return $this->_driver->MetaColumns($table,$normalize); } + public function metaIndexes($table,$normalize=true) + { + if (method_exists($this->_driver,'metaIndexes')) + return $this->_driver->metaIndexes($table,$normalize); + } + + /** + * 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 for a specified table. + * + * @param string $table + * @param bool $owner (optional) not used in this driver + * @param bool $upper + * @param bool $associative + * + * @return string[] where keys are tables, and values are foreign keys + */ + public function metaForeignKeys($table, $owner=false, $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]; @@ -335,19 +415,30 @@ class ADODB_pdo extends ADOConnection { return $err; } + /** + * @param bool $auto_commit + * @return void + */ + function SetAutoCommit($auto_commit) + { + if(method_exists($this->_driver, 'SetAutoCommit')) { + $this->_driver->SetAutoCommit($auto_commit); + } + } + function SetTransactionMode($transaction_mode) { if(method_exists($this->_driver, 'SetTransactionMode')) { return $this->_driver->SetTransactionMode($transaction_mode); } - return parent::SetTransactionMode($seqname); + return parent::SetTransactionMode($transaction_mode); } - function BeginTrans() + function beginTrans() { - if(method_exists($this->_driver, 'BeginTrans')) { - return $this->_driver->BeginTrans(); + if(method_exists($this->_driver, 'beginTrans')) { + return $this->_driver->beginTrans(); } if (!$this->hasTransactions) { @@ -358,15 +449,16 @@ class ADODB_pdo extends ADOConnection { } $this->transCnt += 1; $this->_autocommit = false; - $this->_connectionID->setAttribute(PDO::ATTR_AUTOCOMMIT,false); + $this->SetAutoCommit(false); return $this->_connectionID->beginTransaction(); } - function CommitTrans($ok=true) + function commitTrans($ok=true) { - if(method_exists($this->_driver, 'CommitTrans')) { - return $this->_driver->CommitTrans($ok); + + if(method_exists($this->_driver, 'commitTrans')) { + return $this->_driver->commitTrans($ok); } if (!$this->hasTransactions) { @@ -376,7 +468,7 @@ class ADODB_pdo extends ADOConnection { return true; } if (!$ok) { - return $this->RollbackTrans(); + return $this->rollbackTrans(); } if ($this->transCnt) { $this->transCnt -= 1; @@ -384,7 +476,7 @@ class ADODB_pdo extends ADOConnection { $this->_autocommit = true; $ret = $this->_connectionID->commit(); - $this->_connectionID->setAttribute(PDO::ATTR_AUTOCOMMIT,true); + $this->SetAutoCommit(true); return $ret; } @@ -406,7 +498,7 @@ class ADODB_pdo extends ADOConnection { $this->_autocommit = true; $ret = $this->_connectionID->rollback(); - $this->_connectionID->setAttribute(PDO::ATTR_AUTOCOMMIT,true); + $this->SetAutoCommit(true); return $ret; } @@ -430,10 +522,10 @@ class ADODB_pdo extends ADOConnection { return $obj; } - function CreateSequence($seqname='adodbseq',$startID=1) + public function createSequence($seqname='adodbseq',$startID=1) { - if(method_exists($this->_driver, 'CreateSequence')) { - return $this->_driver->CreateSequence($seqname, $startID); + if(method_exists($this->_driver, 'createSequence')) { + return $this->_driver->createSequence($seqname, $startID); } return parent::CreateSequence($seqname, $startID); @@ -461,16 +553,22 @@ class ADODB_pdo extends ADOConnection { /* returns queryID or false */ function _query($sql,$inputarr=false) { + $ok = false; if (is_array($sql)) { $stmt = $sql[1]; } else { $stmt = $this->_connectionID->prepare($sql); } - #adodb_backtrace(); - #var_dump($this->_bindInputArray); + if ($stmt) { - $this->_driver->debug = $this->debug; + 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 { @@ -514,32 +612,30 @@ class ADODB_pdo extends ADOConnection { return ($this->_stmt) ? $this->_stmt->rowCount() : 0; } - function _insertid() + 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. Otherwise, replace "'" by the value of $replaceQuote (same - * behavior as mysqli driver) - * @param string $s The string to quote - * @param boolean $magic_quotes If false, use PDO::quote(). + * 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) + function qStr($s, $magic_quotes = false) { - if (!$magic_quotes) { - if ($this->_connectionID) { - return $this->_connectionID->quote($s); - } - return "'" . str_replace("'", $this->replaceQuote, $s) . "'"; + if ($this->_connectionID) { + return $this->_connectionID->quote($s); } - - // undo magic quotes for " - $s = str_replace('\\"', '"', $s); - return "'$s'"; + return "'" . str_replace("'", $this->replaceQuote, $s) . "'"; } } @@ -734,22 +830,22 @@ class ADORecordSet_pdo extends ADORecordSet { } //adodb_pr($arr); $o->name = $arr['name']; - if (isset($arr['sqlsrv:decl_type']) && $arr['sqlsrv:decl_type'] <> "null") + 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") + elseif (isset($arr['native_type']) && $arr['native_type'] <> "null") { $o->type = $arr['native_type']; } - else + else { $o->type = adodb_pdo_type($arr['pdo_type']); } - + $o->max_length = $arr['len']; $o->precision = $arr['precision']; @@ -801,3 +897,5 @@ class ADORecordSet_pdo extends ADORecordSet { } } + +class ADORecordSet_array_pdo extends ADORecordSet_array {} diff --git a/libraries/adodb/drivers/adodb-pdo_dblib.inc.php b/libraries/adodb/drivers/adodb-pdo_dblib.inc.php new file mode 100644 index 000000000..aae561bf5 --- /dev/null +++ b/libraries/adodb/drivers/adodb-pdo_dblib.inc.php @@ -0,0 +1,190 @@ +<?php +/** + * ADOdb PDO dblib 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 2019 Damien Regad, Mark Newnham and the ADOdb community + */ + +class ADODB_pdo_dblib extends ADODB_pdo +{ + var $hasTop = 'top'; + var $sysDate = 'convert(datetime,convert(char,GetDate(),102),102)'; + var $sysTimeStamp = 'GetDate()'; + var $metaDatabasesSQL = "select name from sysdatabases where name <> 'master'"; + var $metaTablesSQL="select name,case when type='U' then 'T' else 'V' end from sysobjects where (type='U' or type='V') and (name not in ('sysallocations','syscolumns','syscomments','sysdepends','sysfilegroups','sysfiles','sysfiles1','sysforeignkeys','sysfulltextcatalogs','sysindexes','sysindexkeys','sysmembers','sysobjects','syspermissions','sysprotects','sysreferences','systypes','sysusers','sysalternates','sysconstraints','syssegments','REFERENTIAL_CONSTRAINTS','CHECK_CONSTRAINTS','CONSTRAINT_TABLE_USAGE','CONSTRAINT_COLUMN_USAGE','VIEWS','VIEW_TABLE_USAGE','VIEW_COLUMN_USAGE','SCHEMATA','TABLES','TABLE_CONSTRAINTS','TABLE_PRIVILEGES','COLUMNS','COLUMN_DOMAIN_USAGE','COLUMN_PRIVILEGES','DOMAINS','DOMAIN_CONSTRAINTS','KEY_COLUMN_USAGE','dtproperties'))"; + + var $metaColumnsSQL = "SELECT c.NAME, OBJECT_NAME(c.id) as tbl_name, c.length, c.isnullable, c.status, ( CASE WHEN c.xusertype=61 THEN 0 ELSE c.xprec END), ( CASE WHEN c.xusertype=61 THEN 0 ELSE c.xscale END), ISNULL(i.is_primary_key, 0) as primary_key FROM syscolumns c INNER JOIN systypes t ON t.xusertype=c.xusertype INNER JOIN sysobjects o ON o.id=c.id LEFT JOIN sys.index_columns ic ON ic.object_id = c.id AND c.colid = ic.column_id LEFT JOIN sys.indexes i ON i.object_id = ic.object_id AND i.index_id = ic.index_id WHERE c.id = OBJECT_ID('%s') ORDER by c.colid"; + + function _init(ADODB_pdo $parentDriver) + { + $parentDriver->hasTransactions = true; + $parentDriver->_bindInputArray = true; + $parentDriver->hasInsertID = true; + $parentDriver->fmtTimeStamp = "'Y-m-d H:i:s'"; + $parentDriver->fmtDate = "'Y-m-d'"; + } + + function BeginTrans() + { + $returnval = parent::BeginTrans(); + return $returnval; + } + + 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]; + $fld->type = $rs->fields[1]; + $fld->primary_key = $rs->fields[7]; + + $fld->not_null = (!$rs->fields[3]); + $fld->auto_increment = ($rs->fields[4] == 128); // sys.syscolumns status field. 0x80 = 128 ref: http://msdn.microsoft.com/en-us/library/ms186816.aspx + + if (isset($rs->fields[5]) && $rs->fields[5]) { + if ($rs->fields[5]>0) $fld->max_length = $rs->fields[5]; + $fld->scale = $rs->fields[6]; + if ($fld->scale>0) $fld->max_length += 1; + } else + $fld->max_length = $rs->fields[2]; + + if ($save == ADODB_FETCH_NUM) { + $retarr[] = $fld; + } else { + $retarr[strtoupper($fld->name)] = $fld; + } + $rs->MoveNext(); + } + + $rs->Close(); + return $retarr; + } + + function MetaTables($ttype=false,$showSchema=false,$mask=false) + { + if ($mask) { + $save = $this->metaTablesSQL; + $mask = $this->qstr(($mask)); + $this->metaTablesSQL .= " AND name like $mask"; + } + $ret = ADOConnection::MetaTables($ttype,$showSchema); + + if ($mask) { + $this->metaTablesSQL = $save; + } + return $ret; + } + + function SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) + { + if ($nrows > 0 && $offset <= 0) { + $sql = preg_replace( + '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop." $nrows ",$sql); + + if ($secs2cache) + $rs = $this->CacheExecute($secs2cache, $sql, $inputarr); + else + $rs = $this->Execute($sql,$inputarr); + } else + $rs = ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); + + return $rs; + } + + function _query($sql,$inputarr=false) + { + $this->_connectionID->setAttribute(\PDO::ATTR_EMULATE_PREPARES , true); + if (is_array($sql)) { + $stmt = $sql[1]; + } else { + $stmt = $this->_connectionID->prepare($sql); + } + + if ($stmt) { + $this->_driver->debug = $this->debug; + if ($inputarr) { + foreach ($inputarr as $key => $value) { + if(gettype($key) == 'integer') { + $key += 1; + } + $stmt->bindValue($key, $value, $this->GetPDODataType($value)); + } + } + } + + $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; + } + + private function GetPDODataType($var) + { + if(gettype($var) == 'integer') { + return PDO::PARAM_INT ; + } + return PDO::PARAM_STR; + } + + function ServerInfo() + { + return ADOConnection::ServerInfo(); + } +} diff --git a/libraries/adodb/drivers/adodb-pdo_firebird.inc.php b/libraries/adodb/drivers/adodb-pdo_firebird.inc.php new file mode 100644 index 000000000..0ee5e02b6 --- /dev/null +++ b/libraries/adodb/drivers/adodb-pdo_firebird.inc.php @@ -0,0 +1,452 @@ +<?php +/** + * PDO Firebird driver + * + * This version has only been tested on Firebird 3.0 and PHP 7 + * + * 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 2019 Damien Regad, Mark Newnham and the ADOdb community + */ + +/** + * Class ADODB_pdo_firebird + */ +class ADODB_pdo_firebird extends ADODB_pdo +{ + public $dialect = 3; + public $metaTablesSQL = "select lower(rdb\$relation_name) from rdb\$relations where rdb\$relation_name not like 'RDB\$%'"; + public $metaColumnsSQL = "select lower(a.rdb\$field_name), a.rdb\$null_flag, a.rdb\$default_source, b.rdb\$field_length, b.rdb\$field_scale, b.rdb\$field_sub_type, b.rdb\$field_precision, b.rdb\$field_type from rdb\$relation_fields a, rdb\$fields b where a.rdb\$field_source = b.rdb\$field_name and a.rdb\$relation_name = '%s' order by a.rdb\$field_position asc"; + + var $arrayClass = 'ADORecordSet_array_pdo_firebird'; + + function _init($parentDriver) + { + $this->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; + } + + /** + * Gets the version iformation from the server + * + * @return string[] + */ + public function serverInfo() + { + $arr['dialect'] = $this->dialect; + switch ($arr['dialect']) { + case '': + case '1': + $s = 'Firebird Dialect 1'; + break; + case '2': + $s = 'Firebird Dialect 2'; + break; + default: + case '3': + $s = 'Firebird Dialect 3'; + break; + } + $arr['version'] = ADOConnection::_findvers($s); + $arr['description'] = $s; + return $arr; + } + + /** + * Returns the tables in the database. + * + * @param mixed $ttype + * @param bool $showSchema + * @param mixed $mask + * + * @return string[] + */ + public function metaTables($ttype = false, $showSchema = false, $mask = false) + { + $ret = ADOConnection::MetaTables($ttype, $showSchema); + + return $ret; + } + + public function metaColumns($table, $normalize = true) + { + global $ADODB_FETCH_MODE; + + $save = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + + $rs = $this->Execute(sprintf($this->metaColumnsSQL, strtoupper($table))); + + $ADODB_FETCH_MODE = $save; + + if ($rs === false) { + return false; + } + + $retarr = array(); + $dialect3 = $this->dialect == 3; + while (!$rs->EOF) { //print_r($rs->fields); + $fld = new ADOFieldObject(); + $fld->name = trim($rs->fields[0]); + $this->_ConvertFieldType($fld, $rs->fields[7], $rs->fields[3], $rs->fields[4], $rs->fields[5], + $rs->fields[6], $dialect3); + if (isset($rs->fields[1]) && $rs->fields[1]) { + $fld->not_null = true; + } + if (isset($rs->fields[2])) { + + $fld->has_default = true; + $d = substr($rs->fields[2], strlen('default ')); + switch ($fld->type) { + case 'smallint': + case 'integer': + $fld->default_value = (int)$d; + break; + case 'char': + case 'blob': + case 'text': + case 'varchar': + $fld->default_value = (string)substr($d, 1, strlen($d) - 2); + break; + case 'double': + case 'float': + $fld->default_value = (float)$d; + break; + default: + $fld->default_value = $d; + break; + } + } + if ((isset($rs->fields[5])) && ($fld->type == 'blob')) { + $fld->sub_type = $rs->fields[5]; + } else { + $fld->sub_type = null; + } + if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) { + $retarr[] = $fld; + } else { + $retarr[strtoupper($fld->name)] = $fld; + } + + $rs->MoveNext(); + } + $rs->Close(); + if (empty($retarr)) { + return false; + } else { + return $retarr; + } + } + + public function metaIndexes($table, $primary = false, $owner = false) + { + // save old fetch mode + global $ADODB_FETCH_MODE; + $save = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + if ($this->fetchMode !== false) { + $savem = $this->SetFetchMode(false); + } + $table = strtoupper($table); + $sql = "SELECT * FROM RDB\$INDICES WHERE RDB\$RELATION_NAME = '" . $table . "'"; + if (!$primary) { + $sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$%'"; + } else { + $sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$FOREIGN%'"; + } + + // get index details + $rs = $this->Execute($sql); + if (!is_object($rs)) { + // restore fetchmode + if (isset($savem)) { + $this->SetFetchMode($savem); + } + $ADODB_FETCH_MODE = $save; + return false; + } + + $indexes = array(); + while ($row = $rs->FetchRow()) { + $index = $row[0]; + if (!isset($indexes[$index])) { + if (is_null($row[3])) { + $row[3] = 0; + } + $indexes[$index] = array( + 'unique' => ($row[3] == 1), + 'columns' => array() + ); + } + $sql = "SELECT * FROM RDB\$INDEX_SEGMENTS WHERE RDB\$INDEX_NAME = '" . $index . "' ORDER BY RDB\$FIELD_POSITION ASC"; + $rs1 = $this->Execute($sql); + while ($row1 = $rs1->FetchRow()) { + $indexes[$index]['columns'][$row1[2]] = $row1[1]; + } + } + // restore fetchmode + if (isset($savem)) { + $this->SetFetchMode($savem); + } + $ADODB_FETCH_MODE = $save; + + return $indexes; + } + + public function metaPrimaryKeys($table, $owner_notused = false, $internalKey = false) + { + if ($internalKey) { + return array('RDB$DB_KEY'); + } + + $table = strtoupper($table); + + $sql = 'SELECT S.RDB$FIELD_NAME AFIELDNAME + FROM RDB$INDICES I JOIN RDB$INDEX_SEGMENTS S ON I.RDB$INDEX_NAME=S.RDB$INDEX_NAME + WHERE I.RDB$RELATION_NAME=\'' . $table . '\' and I.RDB$INDEX_NAME like \'RDB$PRIMARY%\' + ORDER BY I.RDB$INDEX_NAME,S.RDB$FIELD_POSITION'; + + $a = $this->GetCol($sql, false, true); + if ($a && sizeof($a) > 0) { + return $a; + } + return false; + } + + public function createSequence($seqname = 'adodbseq', $startID = 1) + { + $ok = $this->execute("CREATE SEQUENCE $seqname"); + if (!$ok) { + return false; + } + + return $this->execute("ALTER SEQUENCE $seqname RESTART WITH " . ($startID - 1)); + } + + public function dropSequence($seqname = 'adodbseq') + { + $seqname = strtoupper($seqname); + return $this->Execute("DROP SEQUENCE $seqname"); + } + + + public function _affectedrows() + { + return fbird_affected_rows($this->_transactionID ? $this->_transactionID : $this->_connectionID); + } + + public function genId($seqname = 'adodbseq', $startID = 1) + { + $getnext = ("SELECT Gen_ID($seqname,1) FROM RDB\$DATABASE"); + $rs = @$this->execute($getnext); + if (!$rs) { + $this->execute(("CREATE SEQUENCE $seqname")); + $this->execute("ALTER SEQUENCE $seqname RESTART WITH " . ($startID - 1) . ';'); + $rs = $this->execute($getnext); + } + if ($rs && !$rs->EOF) { + $this->genID = (integer)reset($rs->fields); + } else { + $this->genID = 0; // false + } + + if ($rs) { + $rs->Close(); + } + + return $this->genID; + } + + public function selectLimit($sql, $nrows = -1, $offset = -1, $inputarr = false, $secs = 0) + { + $nrows = (integer)$nrows; + $offset = (integer)$offset; + $str = 'SELECT '; + if ($nrows >= 0) { + $str .= "FIRST $nrows "; + } + $str .= ($offset >= 0) ? "SKIP $offset " : ''; + + $sql = preg_replace('/^[ \t]*select/i', $str, $sql); + if ($secs) { + $rs = $this->cacheExecute($secs, $sql, $inputarr); + } else { + $rs = $this->execute($sql, $inputarr); + } + + return $rs; + } + + /** + * Sets the appropriate type into the $fld variable + * + * @param ADOFieldObject $fld By reference + * @param int $ftype + * @param int $flen + * @param int $fscale + * @param int $fsubtype + * @param int $fprecision + * @param bool $dialect3 + */ + private function _convertFieldType(&$fld, $ftype, $flen, $fscale, $fsubtype, $fprecision, $dialect3) + { + $fscale = abs($fscale); + $fld->max_length = $flen; + $fld->scale = null; + switch ($ftype) { + case 7: + case 8: + if ($dialect3) { + switch ($fsubtype) { + case 0: + $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); + break; + case 1: + $fld->type = 'numeric'; + $fld->max_length = $fprecision; + $fld->scale = $fscale; + break; + case 2: + $fld->type = 'decimal'; + $fld->max_length = $fprecision; + $fld->scale = $fscale; + break; + } // switch + } else { + if ($fscale != 0) { + $fld->type = 'decimal'; + $fld->scale = $fscale; + $fld->max_length = ($ftype == 7 ? 4 : 9); + } else { + $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); + } + } + break; + case 16: + if ($dialect3) { + switch ($fsubtype) { + case 0: + $fld->type = 'decimal'; + $fld->max_length = 18; + $fld->scale = 0; + break; + case 1: + $fld->type = 'numeric'; + $fld->max_length = $fprecision; + $fld->scale = $fscale; + break; + case 2: + $fld->type = 'decimal'; + $fld->max_length = $fprecision; + $fld->scale = $fscale; + break; + } // switch + } + break; + case 10: + $fld->type = 'float'; + break; + case 14: + $fld->type = 'char'; + break; + case 27: + if ($fscale != 0) { + $fld->type = 'decimal'; + $fld->max_length = 15; + $fld->scale = 5; + } else { + $fld->type = 'double'; + } + break; + case 35: + if ($dialect3) { + $fld->type = 'timestamp'; + } else { + $fld->type = 'date'; + } + break; + case 12: + $fld->type = 'date'; + break; + case 13: + $fld->type = 'time'; + break; + case 37: + $fld->type = 'varchar'; + break; + case 40: + $fld->type = 'cstring'; + break; + case 261: + $fld->type = 'blob'; + $fld->max_length = -1; + break; + } // switch + } +} + +/** + * Class ADORecordSet_pdo_firebird + */ +class ADORecordSet_pdo_firebird extends ADORecordSet_pdo +{ + + public $databaseType = "pdo_firebird"; + + /** + * returns the field object + * + * @param int $fieldOffset Optional field offset + * + * @return object The ADOFieldObject describing the field + */ + public function fetchField($fieldOffset = 0) + { + } +} + +/** + * Class ADORecordSet_array_pdo_firebird + */ +class ADORecordSet_array_pdo_firebird extends ADORecordSet_array_pdo +{ + public $databaseType = "pdo_firebird"; + public $canSeek = true; + + /** + * returns the field object + * + * @param int $fieldOffset Optional field offset + * + * @return object The ADOFieldObject describing the field + */ + public function fetchField($fieldOffset = 0) + { + + $fld = new ADOFieldObject; + $fld->name = $fieldOffset; + $fld->type = 'C'; + $fld->max_length = 0; + + // This needs to be populated from the metadata + $fld->not_null = false; + $fld->has_default = false; + $fld->default_value = 'null'; + + return $fld; + } +} diff --git a/libraries/adodb/drivers/adodb-pdo_mssql.inc.php b/libraries/adodb/drivers/adodb-pdo_mssql.inc.php index 219cf1312..ef63b654a 100644 --- a/libraries/adodb/drivers/adodb-pdo_mssql.inc.php +++ b/libraries/adodb/drivers/adodb-pdo_mssql.inc.php @@ -1,16 +1,23 @@ <?php - - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 8. - -*/ +/** + * PDO MSSQL 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_mssql extends ADODB_pdo { diff --git a/libraries/adodb/drivers/adodb-pdo_mysql.inc.php b/libraries/adodb/drivers/adodb-pdo_mysql.inc.php index 36d97b6ec..c8812453f 100644 --- a/libraries/adodb/drivers/adodb-pdo_mysql.inc.php +++ b/libraries/adodb/drivers/adodb-pdo_mysql.inc.php @@ -1,14 +1,23 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 8. - -*/ +/** + * 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 { @@ -21,9 +30,12 @@ class ADODB_pdo_mysql extends ADODB_pdo { var $sysDate = 'CURDATE()'; var $sysTimeStamp = 'NOW()'; var $hasGenID = true; - var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);"; + 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 $fmtTimeStamp = "'Y-m-d H:i:s'"; var $nameQuote = '`'; function _init($parentDriver) @@ -45,6 +57,67 @@ class ADODB_pdo_mysql extends ADODB_pdo { 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() { @@ -85,6 +158,15 @@ class ADODB_pdo_mysql extends ADODB_pdo { 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; @@ -192,8 +274,10 @@ class ADODB_pdo_mysql extends ADODB_pdo { // 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 http://phplens.com/lens/lensforum/msgs.php?id=9220 + // jason judge, see PHPLens Issue No: 9220 if ($nrows < 0) { $nrows = '18446744073709551615'; } @@ -299,4 +383,41 @@ class ADODB_pdo_mysql extends ADODB_pdo { } 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)); + } } diff --git a/libraries/adodb/drivers/adodb-pdo_oci.inc.php b/libraries/adodb/drivers/adodb-pdo_oci.inc.php index 0bca35e3c..9a05ee6a9 100644 --- a/libraries/adodb/drivers/adodb-pdo_oci.inc.php +++ b/libraries/adodb/drivers/adodb-pdo_oci.inc.php @@ -1,16 +1,23 @@ <?php - - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 8. - -*/ +/** + * PDO Oracle (oci) 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_oci extends ADODB_pdo_base { @@ -90,4 +97,13 @@ class ADODB_pdo_oci extends ADODB_pdo_base { else return $retarr; } + + /** + * @param bool $auto_commit + * @return void + */ + function SetAutoCommit($auto_commit) + { + $this->_connectionID->setAttribute(PDO::ATTR_AUTOCOMMIT, $auto_commit); + } } diff --git a/libraries/adodb/drivers/adodb-pdo_pgsql.inc.php b/libraries/adodb/drivers/adodb-pdo_pgsql.inc.php index 9afe4b0e4..0212d4fda 100644 --- a/libraries/adodb/drivers/adodb-pdo_pgsql.inc.php +++ b/libraries/adodb/drivers/adodb-pdo_pgsql.inc.php @@ -1,15 +1,23 @@ <?php - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 8. - -*/ +/** + * 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"; @@ -73,12 +81,14 @@ WHERE relkind in ('r','v') AND (c.relname='%s' or c.relname = lower('%s')) function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) { - $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); + $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; } @@ -227,4 +237,64 @@ select viewname,'V' from pg_views where viewname like $mask"; } + 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); + } } diff --git a/libraries/adodb/drivers/adodb-pdo_sqlite.inc.php b/libraries/adodb/drivers/adodb-pdo_sqlite.inc.php index d42c5191c..b62ca35ed 100644 --- a/libraries/adodb/drivers/adodb-pdo_sqlite.inc.php +++ b/libraries/adodb/drivers/adodb-pdo_sqlite.inc.php @@ -1,19 +1,25 @@ <?php - -/* - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. See License.txt. - Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Thanks Diogo Toscano (diogo#scriptcase.net) for the code. - And also Sid Dunayer [sdunayer#interserv.com] for extensive fixes. -*/ +/** + * PDO SQLite 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 + * @author Diogo Toscano <diogo@scriptcase.net> + * @author Sid Dunayer <sdunayer@interserv.com> + */ class ADODB_pdo_sqlite extends ADODB_pdo { var $metaTablesSQL = "SELECT name FROM sqlite_master WHERE type='table'"; @@ -54,13 +60,15 @@ class ADODB_pdo_sqlite extends ADODB_pdo { 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); + if ($secs2cache) + $rs = $parent->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr); + else + $rs = $parent->Execute($sql."$limitStr$offsetStr",$inputarr); return $rs; } diff --git a/libraries/adodb/drivers/adodb-pdo_sqlsrv.inc.php b/libraries/adodb/drivers/adodb-pdo_sqlsrv.inc.php index 869e8e181..ed73f3a24 100644 --- a/libraries/adodb/drivers/adodb-pdo_sqlsrv.inc.php +++ b/libraries/adodb/drivers/adodb-pdo_sqlsrv.inc.php @@ -1,14 +1,31 @@ <?php - /** - * Provided by Ned Andre to support sqlsrv library + * PDO sqlsrv 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 + * @author Ned Andre */ + class ADODB_pdo_sqlsrv extends ADODB_pdo { - var $hasTop = 'top'; var $sysDate = 'convert(datetime,convert(char,GetDate(),102),102)'; var $sysTimeStamp = 'GetDate()'; + var $arrayClass = 'ADORecordSet_array_pdo_sqlsrv'; function _init(ADODB_pdo $parentDriver) { @@ -45,5 +62,120 @@ class ADODB_pdo_sqlsrv extends ADODB_pdo { return ADOConnection::ServerInfo(); } +} + +class ADORecordSet_pdo_sqlsrv extends ADORecordSet_pdo +{ + + public $databaseType = "pdo_sqlsrv"; + + /** + * returns the field object + * + * @param int $fieldOffset Optional field offset + * + * @return object The ADOFieldObject describing the field + */ + public function fetchField($fieldOffset = 0) + { + + // Default behavior allows passing in of -1 offset, which crashes the method + if ($fieldOffset == -1) { + $fieldOffset++; + } + + $o = new ADOFieldObject(); + $arr = @$this->_queryID->getColumnMeta($fieldOffset); + + if (!$arr) { + $o->name = 'bad getColumnMeta()'; + $o->max_length = -1; + $o->type = 'VARCHAR'; + $o->precision = 0; + return $o; + } + $o->name = $arr['name']; + if (isset($arr['sqlsrv:decl_type']) && $arr['sqlsrv:decl_type'] <> "null") { + // Use the SQL Server driver specific value + $o->type = $arr['sqlsrv:decl_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; + } +} + +class ADORecordSet_array_pdo_sqlsrv extends ADORecordSet_array_pdo +{ + + /** + * returns the field object + * + * Note that this is a direct copy of the ADORecordSet_pdo_sqlsrv method + * + * @param int $fieldOffset Optional field offset + * + * @return object The ADOfieldobject describing the field + */ + public function fetchField($fieldOffset = 0) + { + // Default behavior allows passing in of -1 offset, which crashes the method + if ($fieldOffset == -1) { + $fieldOffset++; + } + $o = new ADOFieldObject(); + $arr = @$this->_queryID->getColumnMeta($fieldOffset); + + if (!$arr) { + $o->name = 'bad getColumnMeta()'; + $o->max_length = -1; + $o->type = 'VARCHAR'; + $o->precision = 0; + return $o; + } + $o->name = $arr['name']; + if (isset($arr['sqlsrv:decl_type']) && $arr['sqlsrv:decl_type'] <> "null") { + // Use the SQL Server driver specific value + $o->type = $arr['sqlsrv:decl_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 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); + } } diff --git a/libraries/adodb/drivers/adodb-postgres.inc.php b/libraries/adodb/drivers/adodb-postgres.inc.php index 3c866b72f..070ac1c7c 100644 --- a/libraries/adodb/drivers/adodb-postgres.inc.php +++ b/libraries/adodb/drivers/adodb-postgres.inc.php @@ -1,14 +1,25 @@ <?php -/* - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4. - - NOTE: Since 3.31, this file is no longer used, and the "postgres" driver is - remapped to "postgres7". Maintaining multiple postgres drivers is no easy - job, so hopefully this will ensure greater consistency and fewer bugs. -*/ +/** + * 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 + */ diff --git a/libraries/adodb/drivers/adodb-postgres64.inc.php b/libraries/adodb/drivers/adodb-postgres64.inc.php index 5fd271109..9128467be 100644 --- a/libraries/adodb/drivers/adodb-postgres64.inc.php +++ b/libraries/adodb/drivers/adodb-postgres64.inc.php @@ -1,48 +1,23 @@ <?php -/* - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 8. - - Original version derived from Alberto Cerezal (acerezalp@dbnet.es) - DBNet Informatica & Comunicaciones. - 08 Nov 2000 jlim - Minor corrections, removing mysql stuff - 09 Nov 2000 jlim - added insertid support suggested by "Christopher Kings-Lynne" <chriskl@familyhealth.com.au> - jlim - changed concat operator to || and data types to MetaType to match documented pgsql types - see http://www.postgresql.org/devel-corner/docs/postgres/datatype.htm - 22 Nov 2000 jlim - added changes to FetchField() and MetaTables() contributed by "raser" <raser@mail.zen.com.tw> - 27 Nov 2000 jlim - added changes to _connect/_pconnect from ideas by "Lennie" <leen@wirehub.nl> - 15 Dec 2000 jlim - added changes suggested by Additional code changes by "Eric G. Werk" egw@netguide.dk. - 31 Jan 2002 jlim - finally installed postgresql. testing - 01 Mar 2001 jlim - Freek Dijkstra changes, also support for text type - - See http://www.varlena.com/varlena/GeneralBits/47.php - - -- What indexes are on my table? - select * from pg_indexes where tablename = 'tablename'; - - -- What triggers are on my table? - select c.relname as "Table", t.tgname as "Trigger Name", - t.tgconstrname as "Constraint Name", t.tgenabled as "Enabled", - t.tgisconstraint as "Is Constraint", cc.relname as "Referenced Table", - p.proname as "Function Name" - from pg_trigger t, pg_class c, pg_class cc, pg_proc p - where t.tgfoid = p.oid and t.tgrelid = c.oid - and t.tgconstrrelid = cc.oid - and c.relname = 'tablename'; - - -- What constraints are on my table? - select r.relname as "Table", c.conname as "Constraint Name", - contype as "Constraint Type", conkey as "Key Columns", - confkey as "Foreign Columns", consrc as "Source" - from pg_class r, pg_constraint c - where r.oid = c.conrelid - and relname = 'tablename'; - -*/ +/** + * ADOdb PostgreSQL 6.4 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(); @@ -114,6 +89,7 @@ class ADODB_postgres64 extends ADOConnection{ var $_bindInputArray = false; // requires postgresql 7.3+ and ability to modify database var $disableBlobs = false; // set to true to disable blob checking, resulting in 2-5% improvement in performance. + /** @var int $_pnum Number of the last assigned query parameter {@see param()} */ var $_pnum = 0; // The last (fmtTimeStamp is not entirely correct: @@ -124,19 +100,40 @@ class ADODB_postgres64 extends ADOConnection{ // to know what the concequences are. The other values are correct (wheren't in 0.94) // -- Freek Dijkstra - function __construct() + /** + * Retrieve Server information. + * In addition to server version and description, the function also returns + * the client version. + * @param bool $detailed If true, retrieve detailed version string (executes + * a SQL query) in addition to the version number + * @return array|bool Server info or false if version could not be retrieved + * e.g. if there is no active connection + */ + function ServerInfo($detailed = true) { - // changes the metaColumnsSQL, adds columns: attnum[6] - } + if (empty($this->version['version'])) { + // We don't have a connection, so we can't retrieve server info + if (!$this->_connectionID) { + return false; + } - function ServerInfo() - { - if (isset($this->version)) return $this->version; + $version = pg_version($this->_connectionID); + $this->version = array( + // If PHP has been compiled with PostgreSQL 7.3 or lower, then + // server version is not set so we use pg_parameter_status() + // which includes logic to obtain values server_version + 'version' => isset($version['server']) + ? $version['server'] + : pg_parameter_status($this->_connectionID, 'server_version'), + 'client' => $version['client'], + 'description' => null, + ); + } + if ($detailed && $this->version['description'] === null) { + $this->version['description'] = $this->GetOne('select version()'); + } - $arr['description'] = $this->GetOne("select version()"); - $arr['version'] = ADOConnection::_findvers($arr['description']); - $this->version = $arr; - return $arr; + return $this->version; } function IfNull( $field, $ifNull ) @@ -161,11 +158,13 @@ class ADODB_postgres64 extends ADOConnection{ * Using a OID as a unique identifier is not generally wise. * Unless you are very careful, you might end up with a tuple having * a different OID if a database must be reloaded. + * + * @inheritDoc */ - function _insertid($table,$column) + protected function _insertID($table = '', $column = '') { if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') return false; - $oid = pg_getlastoid($this->_resultid); + $oid = pg_last_oid($this->_resultid); // to really return the id, we need the table and column-name, else we can only return the oid != id return empty($table) || empty($column) ? $oid : $this->GetOne("SELECT $column FROM $table WHERE oid=".(int)$oid); } @@ -243,31 +242,32 @@ class ADODB_postgres64 extends ADOConnection{ } - // if magic quotes disabled, use pg_escape_string() - function qstr($s,$magic_quotes=false) + /** + * Quotes a string to be sent to the database. + * + * Relies on pg_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_bool($s)) return $s ? 'true' : 'false'; - - if (!$magic_quotes) { - if (ADODB_PHPVER >= 0x5200 && $this->_connectionID) { - return "'".pg_escape_string($this->_connectionID,$s)."'"; - } - if (ADODB_PHPVER >= 0x4200) { - return "'".pg_escape_string($s)."'"; - } - if ($this->replaceQuote[0] == '\\'){ - $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\\000"),$s); - } - return "'".str_replace("'",$this->replaceQuote,$s)."'"; + if (is_bool($s)) { + return $s ? 'true' : 'false'; } - // undo magic quotes for " - $s = str_replace('\\"','"',$s); - return "'$s'"; + if ($this->_connectionID) { + return "'" . pg_escape_string($this->_connectionID, $s) . "'"; + } else { + return "'" . pg_escape_string($s) . "'"; + } } - // Format date column in sql string given an input format that understands Y M D function SQLDate($fmt, $col=false) { @@ -393,7 +393,7 @@ class ADODB_postgres64 extends ADOConnection{ } /* - Hueristic - not guaranteed to work. + Heuristic - not guaranteed to work. */ function GuessOID($oid) { @@ -425,29 +425,25 @@ class ADODB_postgres64 extends ADOConnection{ } if (!$maxsize) $maxsize = $this->maxblobsize; $realblob = @pg_lo_read($fd,$maxsize); - @pg_loclose($fd); + @pg_lo_close($fd); if ($hastrans) pg_query($this->_connectionID,'commit'); return $realblob; } - /* - See http://www.postgresql.org/idocs/index.php?datatype-binary.html - - NOTE: SQL string literals (input strings) must be preceded with two backslashes - due to the fact that they must pass through two parsers in the PostgreSQL - backend. - */ + /** + * Encode binary value prior to DB storage. + * + * See https://www.postgresql.org/docs/current/static/datatype-binary.html + * + * NOTE: SQL string literals (input strings) must be preceded with two + * backslashes due to the fact that they must pass through two parsers in + * the PostgreSQL backend. + * + * @param string $blob + */ function BlobEncode($blob) { - if (ADODB_PHPVER >= 0x5200) return pg_escape_bytea($this->_connectionID, $blob); - if (ADODB_PHPVER >= 0x4200) return pg_escape_bytea($blob); - - /*92=backslash, 0=null, 39=single-quote*/ - $badch = array(chr(92),chr(0),chr(39)); # \ null ' - $fixch = array('\\\\134','\\\\000','\\\\047'); - return adodb_str_replace($badch,$fixch,$blob); - - // note that there is a pg_escape_bytea function only for php 4.2.0 or later + return pg_escape_bytea($this->_connectionID, $blob); } // assumes bytea for blob, and varchar for clob @@ -492,7 +488,7 @@ class ADODB_postgres64 extends ADOConnection{ // for schema support, pass in the $table param "$schema.$tabname". // converts field names to lowercase, $upper is ignored - // see http://phplens.com/lens/lensforum/msgs.php?id=14018 for more info + // see PHPLens Issue No: 14018 for more info function MetaColumns($table,$normalize=true) { global $ADODB_FETCH_MODE; @@ -606,15 +602,18 @@ class ADODB_postgres64 extends ADOConnection{ } - function Param($name,$type='C') + function param($name, $type='C') { - if ($name) { - $this->_pnum += 1; - } else { - // Reset param num if $name is false - $this->_pnum = 1; + if (!$name) { + // Reset parameter number if $name is falsy + $this->_pnum = 0; + if ($name === false) { + // and don't return placeholder if false (see #380) + return ''; + } } - return '$'.$this->_pnum; + + return '$' . ++$this->_pnum; } function MetaIndexes ($table, $primary = FALSE, $owner = false) @@ -666,8 +665,8 @@ class ADODB_postgres64 extends ADOConnection{ } $col_names = $this->MetaColumnNames($table,true,true); - //3rd param is use attnum, - // see http://sourceforge.net/tracker/index.php?func=detail&aid=1451245&group_id=42718&atid=433976 + // 3rd param is use attnum, + // see https://sourceforge.net/p/adodb/bugs/45/ $indexes = array(); while ($row = $rs->FetchRow()) { $columns = array(); @@ -729,9 +728,9 @@ class ADODB_postgres64 extends ADOConnection{ if ($this->_connectionID === false) return false; $this->Execute("set datestyle='ISO'"); - $info = $this->ServerInfo(); - $this->pgVersion = (float) substr($info['version'],0,3); - if ($this->pgVersion >= 7.1) { // good till version 999 + $info = $this->ServerInfo(false); + + if (version_compare($info['version'], '7.1', '>=')) { $this->_nestedSQL = true; } @@ -739,7 +738,10 @@ class ADODB_postgres64 extends ADOConnection{ # PHP does not handle 'hex' properly ('x74657374' is returned as 't657374') # https://bugs.php.net/bug.php?id=59831 states this is in fact not a bug, # so we manually set bytea_output - if ( !empty($this->connection->noBlobs) && version_compare($info['version'], '9.0', '>=')) { + if (!empty($this->connection->noBlobs) + && version_compare($info['version'], '9.0', '>=') + && version_compare($info['client'], '9.2', '<') + ) { $this->Execute('set bytea_output=escape'); } @@ -848,20 +850,23 @@ class ADODB_postgres64 extends ADOConnection{ /* Returns: the last error message from previous database operation */ function ErrorMsg() { - if ($this->_errorMsg !== false) return $this->_errorMsg; - if (ADODB_PHPVER >= 0x4300) { - if (!empty($this->_resultid)) { - $this->_errorMsg = @pg_result_error($this->_resultid); - if ($this->_errorMsg) return $this->_errorMsg; + if ($this->_errorMsg !== false) { + return $this->_errorMsg; + } + + if (!empty($this->_resultid)) { + $this->_errorMsg = @pg_result_error($this->_resultid); + if ($this->_errorMsg) { + return $this->_errorMsg; } + } - if (!empty($this->_connectionID)) { - $this->_errorMsg = @pg_last_error($this->_connectionID); - } else $this->_errorMsg = $this->_errconnect(); + if (!empty($this->_connectionID)) { + $this->_errorMsg = @pg_last_error($this->_connectionID); } else { - if (empty($this->_connectionID)) $this->_errconnect(); - else $this->_errorMsg = @pg_errormessage($this->_connectionID); + $this->_errorMsg = $this->_errconnect(); } + return $this->_errorMsg; } @@ -946,10 +951,9 @@ class ADORecordSet_postgres64 extends ADORecordSet{ return $row; } - - function _initrs() + function _initRS() { - global $ADODB_COUNTRECS; + global $ADODB_COUNTRECS; $qid = $this->_queryID; $this->_numOfRows = ($ADODB_COUNTRECS)? @pg_num_rows($qid):-1; $this->_numOfFields = @pg_num_fields($qid); @@ -964,10 +968,11 @@ class ADORecordSet_postgres64 extends ADORecordSet{ } } - /* Use associative array to get fields array */ - function Fields($colname) + function fields($colname) { - if ($this->fetchMode != PGSQL_NUM) return @$this->fields[$colname]; + if ($this->fetchMode != PGSQL_NUM) { + return @$this->fields[$colname]; + } if (!$this->bind) { $this->bind = array(); @@ -979,14 +984,14 @@ class ADORecordSet_postgres64 extends ADORecordSet{ return $this->fields[$this->bind[strtoupper($colname)]]; } - function FetchField($off = 0) + function fetchField($fieldOffset = 0) { // offsets begin at 0 - $o= new ADOFieldObject(); - $o->name = @pg_field_name($this->_queryID,$off); - $o->type = @pg_field_type($this->_queryID,$off); - $o->max_length = @pg_fieldsize($this->_queryID,$off); + $o = new ADOFieldObject(); + $o->name = @pg_field_name($this->_queryID, $fieldOffset); + $o->type = @pg_field_type($this->_queryID, $fieldOffset); + $o->max_length = @pg_field_size($this->_queryID, $fieldOffset); return $o; } @@ -998,7 +1003,7 @@ class ADORecordSet_postgres64 extends ADORecordSet{ function _decode($blob) { if ($blob === NULL) return NULL; -// eval('$realblob="'.adodb_str_replace(array('"','$'),array('\"','\$'),$blob).'";'); +// eval('$realblob="'.str_replace(array('"','$'),array('\"','\$'),$blob).'";'); return pg_unescape_bytea($blob); } @@ -1049,7 +1054,12 @@ class ADORecordSet_postgres64 extends ADORecordSet{ function _close() { - return @pg_free_result($this->_queryID); + if (!is_resource($this->_queryID) + || get_resource_type($this->_queryID) != 'pgsql result' + ) { + return true; + } + return pg_free_result($this->_queryID); } function MetaType($t,$len=-1,$fieldobj=false) @@ -1068,6 +1078,7 @@ class ADORecordSet_postgres64 extends ADORecordSet{ case 'NAME': case 'BPCHAR': case '_VARCHAR': + case 'CIDR': case 'INET': case 'MACADDR': if ($len <= $this->blobSize) return 'C'; @@ -1111,7 +1122,7 @@ class ADORecordSet_postgres64 extends ADORecordSet{ return 'R'; default: - return 'N'; + return ADODB_DEFAULT_METATYPE; } } diff --git a/libraries/adodb/drivers/adodb-postgres7.inc.php b/libraries/adodb/drivers/adodb-postgres7.inc.php index ebdf2acfb..59174f678 100644 --- a/libraries/adodb/drivers/adodb-postgres7.inc.php +++ b/libraries/adodb/drivers/adodb-postgres7.inc.php @@ -1,17 +1,23 @@ <?php -/* - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4. - - Postgres7 support. - 28 Feb 2001: Currently indicate that we support LIMIT - 01 Dec 2001: dannym added support for default values -*/ +/** + * 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(); @@ -101,7 +107,7 @@ class ADODB_postgres7 extends ADODB_postgres64 { if (ADODB_ASSOC_CASE !== ADODB_ASSOC_CASE_NATIVE) { $this->rsPrefix .= 'assoc_'; } - $this->_bindInputArray = PHP_VERSION >= 5.1; + $this->_bindInputArray = true; } @@ -109,6 +115,8 @@ class ADODB_postgres7 extends ADODB_postgres64 { // 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) @@ -267,34 +275,47 @@ class ADODB_postgres7 extends ADODB_postgres64 { return $rez; } - // this is a set of functions for managing client encoding - very important if the encodings - // of your database and your output target (i.e. HTML) don't match - //for instance, you may have UNICODE database and server it on-site as WIN1251 etc. - // GetCharSet - get the name of the character set the client is using now - // the functions should work with Postgres 7.0 and above, the set of charsets supported - // depends on compile flags of postgres distribution - if no charsets were compiled into the server - // it will return 'SQL_ANSI' always - function GetCharSet() + /** + * 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() { - //we will use ADO's builtin property charSet - $this->charSet = @pg_client_encoding($this->_connectionID); - if (!$this->charSet) { + if (!$this->_connectionID) { return false; - } else { - return $this->charSet; } + $this->charSet = pg_client_encoding($this->_connectionID); + return $this->charSet ?: false; } - // SetCharSet - switch the client encoding - function SetCharSet($charset_name) + /** + * 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) { - $this->GetCharSet(); - if ($this->charSet !== $charset_name) { - $if = pg_set_client_encoding($this->_connectionID, $charset_name); - if ($if == "0" & $this->GetCharSet() == $charset_name) { - return true; - } else return false; - } else return true; + if ($this->charSet !== $charset) { + if (!$this->_connectionID || pg_set_client_encoding($this->_connectionID, $charset) != 0) { + return false; + } + $this->getCharSet(); + } + return true; } } @@ -307,12 +328,6 @@ class ADORecordSet_postgres7 extends ADORecordSet_postgres64{ var $databaseType = "postgres7"; - - function __construct($queryID, $mode=false) - { - parent::__construct($queryID, $mode); - } - // 10% speedup to move MoveNext to child class function MoveNext() { @@ -339,11 +354,6 @@ class ADORecordSet_assoc_postgres7 extends ADORecordSet_postgres64{ var $databaseType = "postgres7"; - function __construct($queryID, $mode=false) - { - parent::__construct($queryID, $mode); - } - function _fetch() { if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0) { diff --git a/libraries/adodb/drivers/adodb-postgres8.inc.php b/libraries/adodb/drivers/adodb-postgres8.inc.php index 54b14abbc..37c2aae14 100644 --- a/libraries/adodb/drivers/adodb-postgres8.inc.php +++ b/libraries/adodb/drivers/adodb-postgres8.inc.php @@ -1,15 +1,23 @@ <?php -/* - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4. - - Postgres8 support. -*/ +/** + * 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(); @@ -20,6 +28,12 @@ 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 @@ -31,7 +45,7 @@ class ADODB_postgres8 extends ADODB_postgres7 * @return int last inserted ID for given table/column, or the most recently * returned one if $table or $column are empty */ - function _insertid($table, $column) + protected function _insertID($table = '', $column = '') { return empty($table) || empty($column) ? $this->GetOne("SELECT lastval()") diff --git a/libraries/adodb/drivers/adodb-postgres9.inc.php b/libraries/adodb/drivers/adodb-postgres9.inc.php index fb589188e..fb9c6785e 100644 --- a/libraries/adodb/drivers/adodb-postgres9.inc.php +++ b/libraries/adodb/drivers/adodb-postgres9.inc.php @@ -1,15 +1,23 @@ <?php -/* - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4. - - Postgres9 support. -*/ +/** + * 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(); diff --git a/libraries/adodb/drivers/adodb-proxy.inc.php b/libraries/adodb/drivers/adodb-proxy.inc.php index 4004fa78c..3be13179a 100644 --- a/libraries/adodb/drivers/adodb-proxy.inc.php +++ b/libraries/adodb/drivers/adodb-proxy.inc.php @@ -1,33 +1,40 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4. - - Synonym for csv driver. -*/ +/** + * ADOdb Proxy Server driver + * + * @deprecated + * + * 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_PROXY_LAYER")) { - define("_ADODB_PROXY_LAYER", 1 ); - include(ADODB_DIR."/drivers/adodb-csv.inc.php"); + define("_ADODB_PROXY_LAYER", 1 ); + include_once(ADODB_DIR."/drivers/adodb-csv.inc.php"); + +class ADODB_proxy extends ADODB_csv { + var $databaseType = 'proxy'; + var $databaseProvider = 'csv'; +} - class ADODB_proxy extends ADODB_csv { - var $databaseType = 'proxy'; - var $databaseProvider = 'csv'; - } - class ADORecordset_proxy extends ADORecordset_csv { +class ADORecordset_proxy extends ADORecordset_csv { var $databaseType = "proxy"; +} - function __construct($id,$mode=false) - { - parent::__construct($id,$mode); - } - }; } // define diff --git a/libraries/adodb/drivers/adodb-sapdb.inc.php b/libraries/adodb/drivers/adodb-sapdb.inc.php index a11e7e068..34eb4a559 100644 --- a/libraries/adodb/drivers/adodb-sapdb.inc.php +++ b/libraries/adodb/drivers/adodb-sapdb.inc.php @@ -1,24 +1,29 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. -Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - SAPDB data driver. Requires ODBC. - -*/ +/** + * SAPDB data 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(); if (!defined('_ADODB_ODBC_LAYER')) { - include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); + include_once(ADODB_DIR."/drivers/adodb-odbc.inc.php"); } if (!defined('ADODB_SAPDB')){ define('ADODB_SAPDB',1); @@ -33,12 +38,6 @@ class ADODB_SAPDB extends ADODB_odbc { var $hasInsertId = true; var $_bindInputArray = true; - function __construct() - { - //if (strncmp(PHP_OS,'WIN',3) === 0) $this->curmode = SQL_CUR_USE_ODBC; - parent::__construct(); - } - function ServerInfo() { $info = ADODB_odbc::ServerInfo(); @@ -55,7 +54,7 @@ class ADODB_SAPDB extends ADODB_odbc { return $this->GetCol("SELECT columnname FROM COLUMNS WHERE tablename=$table AND mode='KEY' ORDER BY pos"); } - function MetaIndexes ($table, $primary = FALSE, $owner = false) + function MetaIndexes ($table, $primary = FALSE, $owner = false) { $table = $this->Quote(strtoupper($table)); @@ -65,43 +64,43 @@ class ADODB_SAPDB extends ADODB_odbc { global $ADODB_FETCH_MODE; $save = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - if ($this->fetchMode !== FALSE) { - $savem = $this->SetFetchMode(FALSE); - } + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + if ($this->fetchMode !== FALSE) { + $savem = $this->SetFetchMode(FALSE); + } - $rs = $this->Execute($sql); - if (isset($savem)) { - $this->SetFetchMode($savem); - } - $ADODB_FETCH_MODE = $save; + $rs = $this->Execute($sql); + if (isset($savem)) { + $this->SetFetchMode($savem); + } + $ADODB_FETCH_MODE = $save; - if (!is_object($rs)) { - return FALSE; - } + if (!is_object($rs)) { + return FALSE; + } $indexes = array(); while ($row = $rs->FetchRow()) { - $indexes[$row[0]]['unique'] = $row[1] == 'UNIQUE'; - $indexes[$row[0]]['columns'][] = $row[2]; - } + $indexes[$row[0]]['unique'] = $row[1] == 'UNIQUE'; + $indexes[$row[0]]['columns'][] = $row[2]; + } if ($primary) { $indexes['SYSPRIMARYKEYINDEX'] = array( 'unique' => True, // by definition 'columns' => $this->GetCol("SELECT columnname FROM COLUMNS WHERE tablename=$table AND mode='KEY' ORDER BY pos"), ); } - return $indexes; + return $indexes; } function MetaColumns ($table, $normalize = true) { global $ADODB_FETCH_MODE; $save = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - if ($this->fetchMode !== FALSE) { - $savem = $this->SetFetchMode(FALSE); - } + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + if ($this->fetchMode !== FALSE) { + $savem = $this->SetFetchMode(FALSE); + } $table = $this->Quote(strtoupper($table)); $retarr = array(); @@ -134,10 +133,10 @@ class ADODB_SAPDB extends ADODB_odbc { } $retarr[$fld->name] = $fld; } - if (isset($savem)) { - $this->SetFetchMode($savem); - } - $ADODB_FETCH_MODE = $save; + if (isset($savem)) { + $this->SetFetchMode($savem); + } + $ADODB_FETCH_MODE = $save; return $retarr; } @@ -150,7 +149,7 @@ class ADODB_SAPDB extends ADODB_odbc { } // unlike it seems, this depends on the db-session and works in a multiuser environment - function _insertid($table,$column) + protected function _insertID($table = '', $column = '') { return empty($table) ? False : $this->GetOne("SELECT $table.CURRVAL FROM DUAL"); } @@ -158,13 +157,13 @@ class ADODB_SAPDB extends ADODB_odbc { /* SelectLimit implementation problems: - The following will return random 10 rows as order by performed after "WHERE rowno<10" - which is not ideal... + The following will return random 10 rows as order by performed after "WHERE rowno<10" + which is not ideal... - select * from table where rowno < 10 order by 1 + select * from table where rowno < 10 order by 1 - This means that we have to use the adoconnection base class SelectLimit when - there is an "order by". + This means that we have to use the adoconnection base class SelectLimit when + there is an "order by". See http://listserv.sap.com/pipermail/sapdb.general/2002-January/010405.html */ @@ -172,14 +171,10 @@ class ADODB_SAPDB extends ADODB_odbc { }; -class ADORecordSet_sapdb extends ADORecordSet_odbc { +class ADORecordSet_sapdb extends ADORecordSet_odbc { var $databaseType = "sapdb"; - function __construct($id,$mode=false) - { - parent::__construct($id,$mode); - } } } //define diff --git a/libraries/adodb/drivers/adodb-sqlanywhere.inc.php b/libraries/adodb/drivers/adodb-sqlanywhere.inc.php index 03a9da2a0..88897af92 100644 --- a/libraries/adodb/drivers/adodb-sqlanywhere.inc.php +++ b/libraries/adodb/drivers/adodb-sqlanywhere.inc.php @@ -1,66 +1,44 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community -reserved. - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. -Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - 21.02.2002 - Wade Johnson wade@wadejohnson.de - Extended ODBC class for Sybase SQLAnywhere. - 1) Added support to retrieve the last row insert ID on tables with - primary key column using autoincrement function. - - 2) Added blob support. Usage: - a) create blob variable on db server: - - $dbconn->create_blobvar($blobVarName); - - b) load blob var from file. $filename must be complete path - - $dbcon->load_blobvar_from_file($blobVarName, $filename); - - c) Use the $blobVarName in SQL insert or update statement in the values - clause: - - $recordSet = $dbconn->Execute('INSERT INTO tabname (idcol, blobcol) ' - . - 'VALUES (\'test\', ' . $blobVarName . ')'); - - instead of loading blob from a file, you can also load from - an unformatted (raw) blob variable: - $dbcon->load_blobvar_from_var($blobVarName, $varName); - - d) drop blob variable on db server to free up resources: - $dbconn->drop_blobvar($blobVarName); - - Sybase_SQLAnywhere data driver. Requires ODBC. - -*/ +/** + * SAP SQL Anywhere driver (previously Sybase SQL Anywhere) + * + * 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_ODBC_LAYER')) { - include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); + include_once(ADODB_DIR."/drivers/adodb-odbc.inc.php"); } if (!defined('ADODB_SYBASE_SQLANYWHERE')){ define('ADODB_SYBASE_SQLANYWHERE',1); - class ADODB_sqlanywhere extends ADODB_odbc { - var $databaseType = "sqlanywhere"; - var $hasInsertID = true; + class ADODB_sqlanywhere extends ADODB_odbc + { + var $databaseType = "sqlanywhere"; + var $hasInsertID = true; - function _insertid() { - return $this->GetOne('select @@identity'); - } + protected function _insertID($table = '', $column = '') + { + return $this->GetOne('select @@identity'); + } function create_blobvar($blobVarName) { $this->Execute("create variable $blobVarName long binary"); @@ -153,11 +131,6 @@ if (!defined('ADODB_SYBASE_SQLANYWHERE')){ var $databaseType = "sqlanywhere"; - function __construct($id,$mode=false) - { - parent::__construct($id,$mode); - } - }; //class diff --git a/libraries/adodb/drivers/adodb-sqlite.inc.php b/libraries/adodb/drivers/adodb-sqlite.inc.php index 5cc6b9ea3..0711f1dde 100644 --- a/libraries/adodb/drivers/adodb-sqlite.inc.php +++ b/libraries/adodb/drivers/adodb-sqlite.inc.php @@ -1,27 +1,34 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Latest version is available at http://adodb.sourceforge.net - - SQLite info: http://www.hwaci.com/sw/sqlite/ - - Install Instructions: - ==================== - 1. Place this in adodb/drivers - 2. Rename the file, remove the .txt prefix. -*/ +/** + * SQLite driver + * + * @link https://www.sqlite.org/ + * + * @deprecated Use SQLite3 driver instead + * + * 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(); class ADODB_sqlite extends ADOConnection { var $databaseType = "sqlite"; + var $dataProvider = "sqlite"; var $replaceQuote = "''"; // string to use to replace quotes var $concat_operator='||'; var $_errorNo = 0; @@ -33,10 +40,6 @@ class ADODB_sqlite extends ADOConnection { var $sysTimeStamp = "adodb_date('Y-m-d H:i:s')"; var $fmtTimeStamp = "'Y-m-d H:i:s'"; - function __construct() - { - } - function ServerInfo() { $arr['version'] = sqlite_libversion(); @@ -135,7 +138,7 @@ class ADODB_sqlite extends ADOConnection { $parentDriver->hasInsertID = true; } - function _insertid() + protected function _insertID($table = '', $column = '') { return sqlite_last_insert_rowid($this->_connectionID); } @@ -226,6 +229,8 @@ class ADODB_sqlite extends ADOConnection { 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" : ($offset >= 0 ? ' LIMIT 999999999' : ''); if ($secs2cache) { @@ -353,6 +358,63 @@ class ADODB_sqlite extends ADOConnection { return $indexes; } + /** + * Returns the maximum size of a MetaType C field. Because of the + * database design, sqlite places no limits on the size of data inserted + * + * @return int + */ + function charMax() + { + return ADODB_STRINGMAX_NOLIMIT; + } + + /** + * Returns the maximum size of a MetaType X field. Because of the + * database design, sqlite places no limits on the size of data inserted + * + * @return int + */ + function textMax() + { + return ADODB_STRINGMAX_NOLIMIT; + } + + /* + * Converts a date to a month only field and pads it to 2 characters + * + * @param str $fld The name of the field to process + * @return str The SQL Statement + */ + function month($fld) + { + $x = "strftime('%m',$fld)"; + + return $x; + } + + /* + * Converts a date to a day only field and pads it to 2 characters + * + * @param str $fld The name of the field to process + * @return str The SQL Statement + */ + function day($fld) { + $x = "strftime('%d',$fld)"; + return $x; + } + + /* + * Converts a date to a year only field + * + * @param str $fld The name of the field to process + * @return str The SQL Statement + */ + function year($fld) { + $x = "strftime('%Y',$fld)"; + + return $x; + } } /*-------------------------------------------------------------------------------------- diff --git a/libraries/adodb/drivers/adodb-sqlite3.inc.php b/libraries/adodb/drivers/adodb-sqlite3.inc.php index 7600c3a96..548727d8b 100644 --- a/libraries/adodb/drivers/adodb-sqlite3.inc.php +++ b/libraries/adodb/drivers/adodb-sqlite3.inc.php @@ -1,27 +1,32 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Latest version is available at http://adodb.sourceforge.net - - SQLite info: http://www.hwaci.com/sw/sqlite/ - - Install Instructions: - ==================== - 1. Place this in adodb/drivers - 2. Rename the file, remove the .txt prefix. -*/ +/** + * SQLite3 driver + * + * @link https://www.sqlite.org/ + * + * 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(); class ADODB_sqlite3 extends ADOConnection { var $databaseType = "sqlite3"; + var $dataProvider = "sqlite"; var $replaceQuote = "''"; // string to use to replace quotes var $concat_operator='||'; var $_errorNo = 0; @@ -33,10 +38,6 @@ class ADODB_sqlite3 extends ADOConnection { var $sysTimeStamp = "adodb_date('Y-m-d H:i:s')"; var $fmtTimeStamp = "'Y-m-d H:i:s'"; - function __construct() - { - } - function ServerInfo() { $version = SQLite3::version(); @@ -82,6 +83,73 @@ class ADODB_sqlite3 extends ADOConnection { return !empty($ret); } + function metaType($t,$len=-1,$fieldobj=false) + { + + if (is_object($t)) + { + $fieldobj = $t; + $t = $fieldobj->type; + $len = $fieldobj->max_length; + } + + $t = strtoupper($t); + + /* + * We are using the Sqlite affinity method here + * @link https://www.sqlite.org/datatype3.html + */ + $affinity = array( + 'INT'=>'INTEGER', + 'INTEGER'=>'INTEGER', + 'TINYINT'=>'INTEGER', + 'SMALLINT'=>'INTEGER', + 'MEDIUMINT'=>'INTEGER', + 'BIGINT'=>'INTEGER', + 'UNSIGNED BIG INT'=>'INTEGER', + 'INT2'=>'INTEGER', + 'INT8'=>'INTEGER', + + 'CHARACTER'=>'TEXT', + 'VARCHAR'=>'TEXT', + 'VARYING CHARACTER'=>'TEXT', + 'NCHAR'=>'TEXT', + 'NATIVE CHARACTER'=>'TEXT', + 'NVARCHAR'=>'TEXT', + 'TEXT'=>'TEXT', + 'CLOB'=>'TEXT', + + 'BLOB'=>'BLOB', + + 'REAL'=>'REAL', + 'DOUBLE'=>'REAL', + 'DOUBLE PRECISION'=>'REAL', + 'FLOAT'=>'REAL', + + 'NUMERIC'=>'NUMERIC', + 'DECIMAL'=>'NUMERIC', + 'BOOLEAN'=>'NUMERIC', + 'DATE'=>'NUMERIC', + 'DATETIME'=>'NUMERIC' + ); + + if (!isset($affinity[$t])) + return ADODB_DEFAULT_METATYPE; + + $subt = $affinity[$t]; + /* + * Now that we have subclassed the provided data down + * the sqlite 'affinity', we convert to ADOdb metatype + */ + + $subclass = array('INTEGER'=>'I', + 'TEXT'=>'X', + 'BLOB'=>'B', + 'REAL'=>'N', + 'NUMERIC'=>'N'); + + return $subclass[$subt]; + } // mark newnham function MetaColumns($table, $normalize=true) { @@ -129,13 +197,67 @@ class ADODB_sqlite3 extends ADOConnection { return $arr; } + function metaForeignKeys( $table, $owner = FALSE, $upper = FALSE, $associative = FALSE ) + { + global $ADODB_FETCH_MODE; + if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC + || $this->fetchMode == ADODB_FETCH_ASSOC) + $associative = true; + + /* + * Read sqlite master to find foreign keys + */ + $sql = "SELECT sql + FROM ( + SELECT sql sql, type type, tbl_name tbl_name, name name + FROM sqlite_master + ) + WHERE type != 'meta' + AND sql NOTNULL + AND LOWER(name) ='" . strtolower($table) . "'"; + + $tableSql = $this->getOne($sql); + + $fkeyList = array(); + $ylist = preg_split("/,+/",$tableSql); + foreach ($ylist as $y) + { + if (!preg_match('/FOREIGN/',$y)) + continue; + + $matches = false; + preg_match_all('/\((.+?)\)/i',$y,$matches); + $tmatches = false; + preg_match_all('/REFERENCES (.+?)\(/i',$y,$tmatches); + + if ($associative) + { + if (!isset($fkeyList[$tmatches[1][0]])) + $fkeyList[$tmatches[1][0]] = array(); + $fkeyList[$tmatches[1][0]][$matches[1][0]] = $matches[1][1]; + } + else + $fkeyList[$tmatches[1][0]][] = $matches[1][0] . '=' . $matches[1][1]; + } + + if ($associative) + { + if ($upper) + $fkeyList = array_change_key_case($fkeyList,CASE_UPPER); + else + $fkeyList = array_change_key_case($fkeyList,CASE_LOWER); + } + return $fkeyList; + } + + function _init($parentDriver) { $parentDriver->hasTransactions = false; $parentDriver->hasInsertID = true; } - function _insertid() + protected function _insertID($table = '', $column = '') { return $this->_connectionID->lastInsertRowID(); } @@ -160,11 +282,22 @@ class ADODB_sqlite3 extends ADOConnection { function SQLDate($fmt, $col=false) { + /* + * In order to map the values correctly, we must ensure the proper + * casing for certain fields + * Y must be UC, because y is a 2 digit year + * d must be LC, because D is 3 char day + * A must be UC because a is non-portable am + * Q must be UC because q means nothing + */ + $fromChars = array('y','D','a','q'); + $toChars = array('Y','d','A','Q'); + $fmt = str_replace($fromChars,$toChars,$fmt); + $fmt = $this->qstr($fmt); return ($col) ? "adodb_date2($fmt,$col)" : "adodb_date($fmt)"; } - function _createFunctions() { $this->_connectionID->createFunction('adodb_date', 'adodb_date', 1); @@ -209,6 +342,8 @@ class ADODB_sqlite3 extends ADOConnection { 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" : ($offset >= 0 ? ' LIMIT 999999999' : ''); if ($secs2cache) { @@ -287,7 +422,7 @@ class ADODB_sqlite3 extends ADOConnection { return $this->_connectionID->close(); } - function MetaIndexes($table, $primary = FALSE, $owner = false) + function metaIndexes($table, $primary = FALSE, $owner = false) { $false = false; // save old fetch mode @@ -297,8 +432,36 @@ class ADODB_sqlite3 extends ADOConnection { if ($this->fetchMode !== FALSE) { $savem = $this->SetFetchMode(FALSE); } - $SQL=sprintf("SELECT name,sql FROM sqlite_master WHERE type='index' AND tbl_name='%s'", strtolower($table)); - $rs = $this->Execute($SQL); + + $pragmaData = array(); + + /* + * If we want the primary key, we must extract + * it from the table statement, and the pragma + */ + if ($primary) + { + $sql = sprintf('PRAGMA table_info([%s]);', + strtolower($table) + ); + $pragmaData = $this->getAll($sql); + } + + /* + * Exclude the empty entry for the primary index + */ + $sqlite = "SELECT name,sql + FROM sqlite_master + WHERE type='index' + AND sql IS NOT NULL + AND LOWER(tbl_name)='%s'"; + + $SQL = sprintf($sqlite, + strtolower($table) + ); + + $rs = $this->execute($SQL); + if (!is_object($rs)) { if (isset($savem)) { $this->SetFetchMode($savem); @@ -308,10 +471,10 @@ class ADODB_sqlite3 extends ADOConnection { } $indexes = array (); - while ($row = $rs->FetchRow()) { - if ($primary && preg_match("/primary/i",$row[1]) == 0) { - continue; - } + + while ($row = $rs->FetchRow()) + { + if (!isset($indexes[$row[0]])) { $indexes[$row[0]] = array( 'unique' => preg_match("/unique/i",$row[1]), @@ -319,23 +482,122 @@ class ADODB_sqlite3 extends ADOConnection { ); } /** - * There must be a more elegant way of doing this, - * the index elements appear in the SQL statement + * The index elements appear in the SQL statement * in cols[1] between parentheses * e.g CREATE UNIQUE INDEX ware_0 ON warehouse (org,warehouse) */ - $cols = explode("(",$row[1]); - $cols = explode(")",$cols[1]); - array_pop($cols); - $indexes[$row[0]]['columns'] = $cols; + preg_match_all('/\((.*)\)/',$row[1],$indexExpression); + $indexes[$row[0]]['columns'] = array_map('trim',explode(',',$indexExpression[1][0])); } + if (isset($savem)) { $this->SetFetchMode($savem); $ADODB_FETCH_MODE = $save; } + + /* + * If we want primary, add it here + */ + if ($primary){ + + /* + * Check the previously retrieved pragma to search + * with a closure + */ + + $pkIndexData = array('unique'=>1,'columns'=>array()); + + $pkCallBack = function ($value, $key) use (&$pkIndexData) { + + /* + * As we iterate the elements check for pk index and sort + */ + if ($value[5] > 0) + { + $pkIndexData['columns'][$value[5]] = strtolower($value[1]); + ksort($pkIndexData['columns']); + } + }; + + array_walk($pragmaData,$pkCallBack); + + /* + * If we found no columns, there is no + * primary index + */ + if (count($pkIndexData['columns']) > 0) + $indexes['PRIMARY'] = $pkIndexData; + } + return $indexes; } + /** + * Returns the maximum size of a MetaType C field. Because of the + * database design, sqlite places no limits on the size of data inserted + * + * @return int + */ + function charMax() + { + return ADODB_STRINGMAX_NOLIMIT; + } + + /** + * Returns the maximum size of a MetaType X field. Because of the + * database design, sqlite places no limits on the size of data inserted + * + * @return int + */ + function textMax() + { + return ADODB_STRINGMAX_NOLIMIT; + } + + /** + * Converts a date to a month only field and pads it to 2 characters + * + * This uses the more efficient strftime native function to process + * + * @param str $fld The name of the field to process + * + * @return str The SQL Statement + */ + function month($fld) + { + $x = "strftime('%m',$fld)"; + return $x; + } + + /** + * Converts a date to a day only field and pads it to 2 characters + * + * This uses the more efficient strftime native function to process + * + * @param str $fld The name of the field to process + * + * @return str The SQL Statement + */ + function day($fld) { + $x = "strftime('%d',$fld)"; + return $x; + } + + /** + * Converts a date to a year only field + * + * This uses the more efficient strftime native function to process + * + * @param str $fld The name of the field to process + * + * @return str The SQL Statement + */ + function year($fld) + { + $x = "strftime('%Y',$fld)"; + return $x; + } + } /*-------------------------------------------------------------------------------------- diff --git a/libraries/adodb/drivers/adodb-sqlitepo.inc.php b/libraries/adodb/drivers/adodb-sqlitepo.inc.php index b167e8c8b..cb69ff9e9 100644 --- a/libraries/adodb/drivers/adodb-sqlitepo.inc.php +++ b/libraries/adodb/drivers/adodb-sqlitepo.inc.php @@ -1,23 +1,31 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Portable version of sqlite driver, to make it more similar to other database drivers. - The main differences are - - 1. When selecting (joining) multiple tables, in assoc mode the table - names are included in the assoc keys in the "sqlite" driver. - - In "sqlitepo" driver, the table names are stripped from the returned column names. - When this results in a conflict, the first field get preference. - - Contributed by Herman Kuiper herman#ozuzo.net -*/ +/** + * SQLite Portable driver. + * + * Make it more similar to other database drivers. The main differences are + * - When selecting (joining) multiple tables, in assoc mode the table + * names are included in the assoc keys in the "sqlite" driver. + * In "sqlitepo" driver, the table names are stripped from the returned + * column names. When this results in a conflict, the first field gets + * preference. + * + * 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 Herman Kuiper <herman@ozuzo.net> + */ if (!defined('ADODB_DIR')) die(); @@ -35,11 +43,6 @@ class ADORecordset_sqlitepo extends ADORecordset_sqlite { var $databaseType = 'sqlitepo'; - function __construct($queryID,$mode=false) - { - parent::__construct($queryID,$mode); - } - // Modified to strip table names from returned fields function _fetch($ignore_fields=false) { diff --git a/libraries/adodb/drivers/adodb-sybase.inc.php b/libraries/adodb/drivers/adodb-sybase.inc.php index 6ba392d35..b8db07479 100644 --- a/libraries/adodb/drivers/adodb-sybase.inc.php +++ b/libraries/adodb/drivers/adodb-sybase.inc.php @@ -1,21 +1,24 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim. All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Sybase driver contributed by Toni (toni.tunkkari@finebyte.com) - - - MSSQL date patch applied. - - Date patch by Toni 15 Feb 2002 -*/ +/** + * Sybase 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 + * @author Toni Tunkkari <toni.tunkkari@finebyte.com> + */ // security - hide paths if (!defined('ADODB_DIR')) die(); @@ -44,15 +47,15 @@ class ADODB_sybase extends ADOConnection { var $port; - function __construct() - { - } - - // might require begintrans -- committrans - function _insertid() + /** + * might require begintrans -- committrans + * @inheritDoc + */ + protected function _insertID($table = '', $column = '') { return $this->GetOne('select @@identity'); } + // might require begintrans -- committrans function _affectedrows() { @@ -117,8 +120,10 @@ class ADODB_sybase extends ADOConnection { if ($this->_logsql) return $this->_errorMsg; if (function_exists('sybase_get_last_message')) $this->_errorMsg = sybase_get_last_message(); - else - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : 'SYBASE error messages not supported on this platform'; + else { + $this->_errorMsg = 'SYBASE error messages not supported on this platform'; + } + return $this->_errorMsg; } @@ -133,9 +138,9 @@ class ADODB_sybase extends ADOConnection { } if ($this->charSet) { - $this->_connectionID = sybase_connect($argHostname,$argUsername,$argPassword, $this->charSet); + $this->_connectionID = @sybase_connect($argHostname,$argUsername,$argPassword, $this->charSet); } else { - $this->_connectionID = sybase_connect($argHostname,$argUsername,$argPassword); + $this->_connectionID = @sybase_connect($argHostname,$argUsername,$argPassword); } if ($this->_connectionID === false) return false; @@ -154,9 +159,9 @@ class ADODB_sybase extends ADOConnection { } if ($this->charSet) { - $this->_connectionID = sybase_pconnect($argHostname,$argUsername,$argPassword, $this->charSet); + $this->_connectionID = @sybase_pconnect($argHostname,$argUsername,$argPassword, $this->charSet); } else { - $this->_connectionID = sybase_pconnect($argHostname,$argUsername,$argPassword); + $this->_connectionID = @sybase_pconnect($argHostname,$argUsername,$argPassword); } if ($this->_connectionID === false) return false; @@ -169,7 +174,7 @@ class ADODB_sybase extends ADOConnection { { global $ADODB_COUNTRECS; - if ($ADODB_COUNTRECS == false && ADODB_PHPVER >= 0x4300) + if ($ADODB_COUNTRECS == false) return sybase_unbuffered_query($sql,$this->_connectionID); else return sybase_query($sql,$this->_connectionID); @@ -318,7 +323,7 @@ class ADORecordset_sybase extends ADORecordSet { } if (!$mode) $this->fetchMode = ADODB_FETCH_ASSOC; else $this->fetchMode = $mode; - parent::__construct($id,$mode); + parent::__construct($id); } /* Returns: an object containing field information. @@ -391,12 +396,8 @@ class ADORecordset_sybase extends ADORecordSet { } class ADORecordSet_array_sybase extends ADORecordSet_array { - function __construct($id=-1) - { - parent::__construct($id); - } - // sybase/mssql uses a default date like Dec 30 2000 12:00AM + // sybase/mssql uses a default date like Dec 30 2000 12:00AM static function UnixDate($v) { global $ADODB_sybase_mths; diff --git a/libraries/adodb/drivers/adodb-sybase_ase.inc.php b/libraries/adodb/drivers/adodb-sybase_ase.inc.php index 669dd22ff..d301ba996 100644 --- a/libraries/adodb/drivers/adodb-sybase_ase.inc.php +++ b/libraries/adodb/drivers/adodb-sybase_ase.inc.php @@ -1,17 +1,24 @@ <?php -/* - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Set tabs to 4. - - Contributed by Interakt Online. Thx Cristian MARIN cristic#interaktonline.com -*/ - +/** + * SAP Adaptive Server Enterprise driver (formerly Sybase ASE) + * + * 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 Cristian Marin, Interakt Online <cristic@interaktonline.com> + */ require_once ADODB_DIR."/drivers/adodb-sybase.inc.php"; @@ -22,10 +29,6 @@ class ADODB_sybase_ase extends ADODB_sybase { var $metaColumnsSQL = "SELECT syscolumns.name AS field_name, systypes.name AS type, systypes.length AS width FROM sysobjects, syscolumns, systypes WHERE sysobjects.name='%s' AND syscolumns.id = sysobjects.id AND systypes.type=syscolumns.type"; var $metaDatabasesSQL ="SELECT a.name FROM master.dbo.sysdatabases a, master.dbo.syslogins b WHERE a.suid = b.suid and a.name like '%' and a.name != 'tempdb' and a.status3 != 256 order by 1"; - function __construct() - { - } - // split the Views, Tables and procedures. function MetaTables($ttype=false,$showSchema=false,$mask=false) { @@ -111,10 +114,5 @@ class ADODB_sybase_ase extends ADODB_sybase { } class adorecordset_sybase_ase extends ADORecordset_sybase { -var $databaseType = "sybase_ase"; -function __construct($id,$mode=false) - { - parent::__construct($id,$mode); - } - + var $databaseType = "sybase_ase"; } diff --git a/libraries/adodb/drivers/adodb-text.inc.php b/libraries/adodb/drivers/adodb-text.inc.php new file mode 100644 index 000000000..77ad06a0b --- /dev/null +++ b/libraries/adodb/drivers/adodb-text.inc.php @@ -0,0 +1,341 @@ +<?php +/** + * ADOdb Plain Text driver + * + * @deprecated + * + * 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_TEXT_LAYER")) { + define("_ADODB_TEXT_LAYER", 1 ); + +// for sorting in _query() +function adodb_cmp($a, $b) { + if ($a[0] == $b[0]) return 0; + return ($a[0] < $b[0]) ? -1 : 1; +} +// for sorting in _query() +function adodb_cmpr($a, $b) { + if ($a[0] == $b[0]) return 0; + return ($a[0] > $b[0]) ? -1 : 1; +} +class ADODB_text extends ADOConnection { + var $databaseType = 'text'; + + var $_origarray; // original data + var $_types; + var $_proberows = 8; + var $_colnames; + var $_skiprow1=false; + var $readOnly = true; + var $hasTransactions = false; + + var $_rezarray; + var $_reznames; + var $_reztypes; + + function RSRecordCount() + { + if (!empty($this->_rezarray)) return sizeof($this->_rezarray); + + return sizeof($this->_origarray); + } + + function _affectedrows() + { + return false; + } + + // returns true or false + function PConnect(&$array, $types = false, $colnames = false) + { + return $this->Connect($array, $types, $colnames); + } + // returns true or false + function Connect(&$array, $types = false, $colnames = false) + { + if (is_string($array) and $array === 'iluvphplens') return 'me2'; + + if (!$array) { + $this->_origarray = false; + return true; + } + $row = $array[0]; + $cols = sizeof($row); + + + if ($colnames) $this->_colnames = $colnames; + else { + $this->_colnames = $array[0]; + $this->_skiprow1 = true; + } + if (!$types) { + // probe and guess the type + $types = array(); + $firstrow = true; + if ($this->_proberows > sizeof($array)) $max = sizeof($array); + else $max = $this->_proberows; + for ($j=($this->_skiprow1)?1:0;$j < $max; $j++) { + $row = $array[$j]; + if (!$row) break; + $i = -1; + foreach($row as $v) { + $i += 1; + //print " ($i ".$types[$i]. "$v) "; + $v = trim($v); + if (!preg_match('/^[+-]{0,1}[0-9\.]+$/',$v)) { + $types[$i] = 'C'; // once C, always C + continue; + } + if (isset($types[$i]) && $types[$i]=='C') continue; + if ($firstrow) { + // If empty string, we presume is character + // test for integer for 1st row only + // after that it is up to testing other rows to prove + // that it is not an integer + if (strlen($v) == 0) $types[0] = 'C'; + if (strpos($v,'.') !== false) $types[0] = 'N'; + else $types[$i] = 'I'; + continue; + } + + if (strpos($v,'.') !== false) $types[$i] = 'N'; + + } + $firstrow = false; + } + } + //print_r($types); + $this->_origarray = $array; + $this->_types = $types; + return true; + } + + + + // returns queryID or false + // We presume that the select statement is on the same table (what else?), + // with the only difference being the order by. + //You can filter by using $eval and each clause is stored in $arr .eg. $arr[1] == 'name' + // also supports SELECT [DISTINCT] COL FROM ... -- only 1 col supported + function _query($sql,$input_arr,$eval=false) + { + if ($this->_origarray === false) return false; + + $eval = $this->evalAll; + $usql = strtoupper(trim($sql)); + $usql = preg_replace("/[\t\n\r]/",' ',$usql); + $usql = preg_replace('/ *BY/i',' BY',strtoupper($usql)); + + $eregword ='([A-Z_0-9]*)'; + //print "<BR> $sql $eval "; + if ($eval) { + $i = 0; + foreach($this->_colnames as $n) { + $n = strtoupper(trim($n)); + $eval = str_replace("\$$n","\$arr[$i]",$eval); + + $i += 1; + } + + $i = 0; + $eval = "\$rez=($eval);"; + //print "<p>Eval string = $eval </p>"; + $where_arr = array(); + + reset($this->_origarray); + foreach ($this->_origarray as $arr) { + + if ($i == 0 && $this->_skiprow1) + $where_arr[] = $arr; + else { + eval($eval); + //print " $i: result=$rez arr[0]={$arr[0]} arr[1]={$arr[1]} <BR>\n "; + if ($rez) $where_arr[] = $arr; + } + $i += 1; + } + $this->_rezarray = $where_arr; + }else + $where_arr = $this->_origarray; + + // THIS PROJECTION CODE ONLY WORKS FOR 1 COLUMN, + // OTHERWISE IT RETURNS ALL COLUMNS + if (substr($usql,0,7) == 'SELECT ') { + $at = strpos($usql,' FROM '); + $sel = trim(substr($usql,7,$at-7)); + + $distinct = false; + if (substr($sel,0,8) == 'DISTINCT') { + $distinct = true; + $sel = trim(substr($sel,8,$at)); + } + + // $sel holds the selection clause, comma delimited + // currently we only project if one column is involved + // this is to support popups in PHPLens + if (strpos(',',$sel)===false) { + $colarr = array(); + + preg_match("/$eregword/",$sel,$colarr); + $col = $colarr[1]; + $i = 0; + $n = ''; + reset($this->_colnames); + foreach ($this->_colnames as $n) { + + if ($col == strtoupper(trim($n))) break; + $i += 1; + } + + if ($n && $col) { + $distarr = array(); + $projarray = array(); + $projtypes = array($this->_types[$i]); + $projnames = array($n); + + foreach ($where_arr as $a) { + if ($i == 0 && $this->_skiprow1) { + $projarray[] = array($n); + continue; + } + + if ($distinct) { + $v = strtoupper($a[$i]); + if (! $distarr[$v]) { + $projarray[] = array($a[$i]); + $distarr[$v] = 1; + } + } else + $projarray[] = array($a[$i]); + + } //foreach + //print_r($projarray); + } + } // check 1 column in projection + } // is SELECT + + if (empty($projarray)) { + $projtypes = $this->_types; + $projarray = $where_arr; + $projnames = $this->_colnames; + } + $this->_rezarray = $projarray; + $this->_reztypes = $projtypes; + $this->_reznames = $projnames; + + + $pos = strpos($usql,' ORDER BY '); + if ($pos === false) return $this; + $orderby = trim(substr($usql,$pos+10)); + + preg_match("/$eregword/",$orderby,$arr); + if (sizeof($arr) < 2) return $this; // actually invalid sql + $col = $arr[1]; + $at = (integer) $col; + if ($at == 0) { + $i = 0; + reset($projnames); + foreach ($projnames as $n) { + if (strtoupper(trim($n)) == $col) { + $at = $i+1; + break; + } + $i += 1; + } + } + + if ($at <= 0 || $at > sizeof($projarray[0])) return $this; // cannot find sort column + $at -= 1; + + // generate sort array consisting of (sortval1, row index1) (sortval2, row index2)... + $sorta = array(); + $t = $projtypes[$at]; + $num = ($t == 'I' || $t == 'N'); + for ($i=($this->_skiprow1)?1:0, $max = sizeof($projarray); $i < $max; $i++) { + $row = $projarray[$i]; + $val = ($num)?(float)$row[$at]:$row[$at]; + $sorta[]=array($val,$i); + } + + // check for desc sort + $orderby = substr($orderby,strlen($col)+1); + $arr = array(); + preg_match('/([A-Z_0-9]*)/i',$orderby,$arr); + + if (trim($arr[1]) == 'DESC') $sortf = 'adodb_cmpr'; + else $sortf = 'adodb_cmp'; + + // hasta la sorta babe + usort($sorta, $sortf); + + // rearrange original array + $arr2 = array(); + if ($this->_skiprow1) $arr2[] = $projarray[0]; + foreach($sorta as $v) { + $arr2[] = $projarray[$v[1]]; + } + + $this->_rezarray = $arr2; + return $this; + } + + /* Returns: the last error message from previous database operation */ + function ErrorMsg() + { + return ''; + } + + /* Returns: the last error number from previous database operation */ + function ErrorNo() + { + return 0; + } + + // returns true or false + function _close() + { + } + + +} + +/*-------------------------------------------------------------------------------------- + Class Name: Recordset +--------------------------------------------------------------------------------------*/ + + +class ADORecordSet_text extends ADORecordSet_array +{ + + var $databaseType = "text"; + + function __construct( $conn,$mode=false) + { + parent::__construct(); + $this->InitArray($conn->_rezarray,$conn->_reztypes,$conn->_reznames); + $conn->_rezarray = false; + } + +} // class ADORecordSet_text + + +} // defined diff --git a/libraries/adodb/drivers/adodb-vfp.inc.php b/libraries/adodb/drivers/adodb-vfp.inc.php index 840c9c109..bb4351683 100644 --- a/libraries/adodb/drivers/adodb-vfp.inc.php +++ b/libraries/adodb/drivers/adodb-vfp.inc.php @@ -1,23 +1,31 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. -Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Microsoft Visual FoxPro data driver. Requires ODBC. Works only on MS Windows. -*/ +/** + * Microsoft Visual FoxPro driver + * + * @deprecated + * + * 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_ODBC_LAYER')) { - include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); + include_once(ADODB_DIR."/drivers/adodb-odbc.inc.php"); } if (!defined('ADODB_VFP')){ define('ADODB_VFP',1); @@ -69,11 +77,6 @@ class ADORecordSet_vfp extends ADORecordSet_odbc { var $databaseType = "vfp"; - function __construct($id,$mode=false) - { - return parent::__construct($id,$mode); - } - function MetaType($t, $len = -1, $fieldobj = false) { if (is_object($t)) { @@ -95,7 +98,7 @@ class ADORecordSet_vfp extends ADORecordSet_odbc { case 'I': return 'I'; - default: return 'N'; + default: return ADODB_DEFAULT_METATYPE; } } } diff --git a/libraries/adodb/lang/adodb-ar.inc.php b/libraries/adodb/lang/adodb-ar.inc.php index 0b8f12ff8..920c99432 100644 --- a/libraries/adodb/lang/adodb-ar.inc.php +++ b/libraries/adodb/lang/adodb-ar.inc.php @@ -1,5 +1,25 @@ <?php -// by "El-Shamaa, Khaled" <k.el-shamaa#cgiar.org> +/** + * Arabic language strings. + * + * 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 El-Shamaa, Khaled <k.el-shamaa@cgiar.org> + */ + $ADODB_LANG_ARRAY = array ( 'LANG' => 'ar', DB_ERROR => 'خطأ غير Ù…Øدد', diff --git a/libraries/adodb/lang/adodb-bg.inc.php b/libraries/adodb/lang/adodb-bg.inc.php index 07069b421..bbfd92f28 100644 --- a/libraries/adodb/lang/adodb-bg.inc.php +++ b/libraries/adodb/lang/adodb-bg.inc.php @@ -1,8 +1,24 @@ <?php -/* - Bulgarian language, v1.0, 25.03.2004, encoding by UTF-8 charset - contributed by Valentin Sheiretsky <valio#valio.eu.org> -*/ +/** + * Bulgarian language strings. + * + * 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 Valentin Sheiretsky <valio@valio.eu.org> + */ $ADODB_LANG_ARRAY = array ( 'LANG' => 'bg', diff --git a/libraries/adodb/lang/adodb-ca.inc.php b/libraries/adodb/lang/adodb-ca.inc.php index adbafac98..4b046884f 100644 --- a/libraries/adodb/lang/adodb-ca.inc.php +++ b/libraries/adodb/lang/adodb-ca.inc.php @@ -1,6 +1,25 @@ <?php -// Catalan language -// contributed by "Josep Lladonosa" jlladono#pie.xtec.es +/** + * Catalan language strings. + * + * 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 Josep Lladonosa <jlladono@pie.xtec.es> + */ + $ADODB_LANG_ARRAY = array ( 'LANG' => 'ca', DB_ERROR => 'error desconegut', diff --git a/libraries/adodb/lang/adodb-cn.inc.php b/libraries/adodb/lang/adodb-cn.inc.php index 9c9734130..512ffb82e 100644 --- a/libraries/adodb/lang/adodb-cn.inc.php +++ b/libraries/adodb/lang/adodb-cn.inc.php @@ -1,6 +1,25 @@ <?php -// Chinese language file contributed by "Cuiyan (cysoft)" cysoft#php.net. -// Simplified Chinese +/** + * Simplified Chinese language strings. + * + * 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 Cuiyan (cysoft) <cysoft@php.net> + */ + $ADODB_LANG_ARRAY = array ( 'LANG' => 'cn', DB_ERROR => '未知错误', diff --git a/libraries/adodb/lang/adodb-cz.inc.php b/libraries/adodb/lang/adodb-cz.inc.php index d79d7142f..eb2fb2e3a 100644 --- a/libraries/adodb/lang/adodb-cz.inc.php +++ b/libraries/adodb/lang/adodb-cz.inc.php @@ -1,7 +1,24 @@ <?php - -# Czech language -# v1.0, 19.06.2003 Kamil Jakubovic <jake@host.sk> +/** + * Czech language strings. + * + * 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 Kamil Jakubovic <jake@host.sk> + */ $ADODB_LANG_ARRAY = array ( 'LANG' => 'cz', diff --git a/libraries/adodb/lang/adodb-da.inc.php b/libraries/adodb/lang/adodb-da.inc.php index 14e720b85..e4c655be9 100644 --- a/libraries/adodb/lang/adodb-da.inc.php +++ b/libraries/adodb/lang/adodb-da.inc.php @@ -1,5 +1,25 @@ <?php -// Arne Eckmann bananstat#users.sourceforge.net +/** + * Danish language strings. + * + * 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 Arne Eckmann <bananstat@users.sourceforge.net> + */ + $ADODB_LANG_ARRAY = array ( 'LANG' => 'da', DB_ERROR => 'ukendt fejl', diff --git a/libraries/adodb/lang/adodb-de.inc.php b/libraries/adodb/lang/adodb-de.inc.php index dca4ffefe..a02dd7295 100644 --- a/libraries/adodb/lang/adodb-de.inc.php +++ b/libraries/adodb/lang/adodb-de.inc.php @@ -1,32 +1,52 @@ <?php -// contributed by "Heinz Hombergs" <opn@hhombergs.de> +/** + * German language strings. + * + * 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 Heinz Hombergs <opn@hhombergs.de> + */ + $ADODB_LANG_ARRAY = array ( - 'LANG' => 'de', - DB_ERROR => 'Unbekannter Fehler', - DB_ERROR_ALREADY_EXISTS => 'existiert bereits', - DB_ERROR_CANNOT_CREATE => 'kann nicht erstellen', - DB_ERROR_CANNOT_DELETE => 'kann nicht löschen', - DB_ERROR_CANNOT_DROP => 'Tabelle oder Index konnte nicht gelöscht werden', - DB_ERROR_CONSTRAINT => 'Constraint Verletzung', - DB_ERROR_DIVZERO => 'Division durch Null', - DB_ERROR_INVALID => 'ungültig', - DB_ERROR_INVALID_DATE => 'ungültiges Datum oder Zeit', - DB_ERROR_INVALID_NUMBER => 'ungültige Zahl', - DB_ERROR_MISMATCH => 'Unverträglichkeit', - DB_ERROR_NODBSELECTED => 'keine Dantebank ausgewählt', - DB_ERROR_NOSUCHFIELD => 'Feld nicht vorhanden', - DB_ERROR_NOSUCHTABLE => 'Tabelle nicht vorhanden', - DB_ERROR_NOT_CAPABLE => 'Funktion nicht installiert', - DB_ERROR_NOT_FOUND => 'nicht gefunden', - DB_ERROR_NOT_LOCKED => 'nicht gesperrt', - DB_ERROR_SYNTAX => 'Syntaxfehler', - DB_ERROR_UNSUPPORTED => 'nicht Unterstützt', - DB_ERROR_VALUE_COUNT_ON_ROW => 'Anzahl der zurückgelieferten Felder entspricht nicht der Anzahl der Felder in der Abfrage', - DB_ERROR_INVALID_DSN => 'ungültiger DSN', - DB_ERROR_CONNECT_FAILED => 'Verbindung konnte nicht hergestellt werden', - 0 => 'kein Fehler', // DB_OK - DB_ERROR_NEED_MORE_DATA => 'Nicht genügend Daten geliefert', - DB_ERROR_EXTENSION_NOT_FOUND=> 'erweiterung nicht gefunden', - DB_ERROR_NOSUCHDB => 'keine Datenbank', - DB_ERROR_ACCESS_VIOLATION => 'ungenügende Rechte' + 'LANG' => 'de', + DB_ERROR => 'unbekannter Fehler', + DB_ERROR_ALREADY_EXISTS => 'existiert bereits', + DB_ERROR_CANNOT_CREATE => 'kann nicht erstellen', + DB_ERROR_CANNOT_DELETE => 'kann nicht löschen', + DB_ERROR_CANNOT_DROP => 'Tabelle oder Index konnte nicht gelöscht werden', + DB_ERROR_CONSTRAINT => 'Randbedingung verletzt', + DB_ERROR_DIVZERO => 'Division durch Null', + DB_ERROR_INVALID => 'ungültig', + DB_ERROR_INVALID_DATE => 'ungültiges Datum oder Zeit', + DB_ERROR_INVALID_NUMBER => 'ungültige Zahl', + DB_ERROR_MISMATCH => 'Unverträglichkeit', + DB_ERROR_NODBSELECTED => 'Keine Datenbank ausgewählt', + DB_ERROR_NOSUCHFIELD => 'Feld nicht vorhanden', + DB_ERROR_NOSUCHTABLE => 'Tabelle nicht vorhanden', + DB_ERROR_NOT_CAPABLE => 'Funktion nicht installiert', + DB_ERROR_NOT_FOUND => 'nicht gefunden', + DB_ERROR_NOT_LOCKED => 'nicht gesperrt', + DB_ERROR_SYNTAX => 'Syntaxfehler', + DB_ERROR_UNSUPPORTED => 'nicht unterstützt', + DB_ERROR_VALUE_COUNT_ON_ROW => 'Anzahl der zurückgelieferten Felder entspricht nicht der Anzahl der Felder in der Abfrage', + DB_ERROR_INVALID_DSN => 'ungültiger DSN', + DB_ERROR_CONNECT_FAILED => 'Verbindung konnte nicht hergestellt werden', + 0 => 'kein Fehler', // DB_OK + DB_ERROR_NEED_MORE_DATA => 'Nicht genügend Daten geliefert', + DB_ERROR_EXTENSION_NOT_FOUND=> 'Erweiterung nicht gefunden', + DB_ERROR_NOSUCHDB => 'keine Datenbank', + DB_ERROR_ACCESS_VIOLATION => 'ungenügende Rechte' ); diff --git a/libraries/adodb/lang/adodb-en.inc.php b/libraries/adodb/lang/adodb-en.inc.php index 05828554c..74c4ea021 100644 --- a/libraries/adodb/lang/adodb-en.inc.php +++ b/libraries/adodb/lang/adodb-en.inc.php @@ -1,4 +1,23 @@ <?php +/** + * English language strings. + * + * 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 + */ $ADODB_LANG_ARRAY = array ( 'LANG' => 'en', diff --git a/libraries/adodb/lang/adodb-eo.inc.php b/libraries/adodb/lang/adodb-eo.inc.php index baa589c1c..107a3b37f 100644 --- a/libraries/adodb/lang/adodb-eo.inc.php +++ b/libraries/adodb/lang/adodb-eo.inc.php @@ -1,6 +1,24 @@ <?php -// Vivu Esperanto ĉiam! -// Traduko fare de Antono Vasiljev (anders[#]brainactive.org) +/** + * Esperanto language strings. + * + * 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 Antono Vasiljev <anders@brainactive.org> + */ $ADODB_LANG_ARRAY = array ( 'LANG' => 'eo', diff --git a/libraries/adodb/lang/adodb-es.inc.php b/libraries/adodb/lang/adodb-es.inc.php index a80a64415..bcb0cceac 100644 --- a/libraries/adodb/lang/adodb-es.inc.php +++ b/libraries/adodb/lang/adodb-es.inc.php @@ -1,5 +1,25 @@ <?php -// contributed by "Horacio Degiorgi" <horaciod@codigophp.com> +/** + * Spanish language strings. + * + * 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 Horacio Degiorgi <horaciod@codigophp.com> + */ + $ADODB_LANG_ARRAY = array ( 'LANG' => 'es', DB_ERROR => 'error desconocido', diff --git a/libraries/adodb/lang/adodb-fa.inc.php b/libraries/adodb/lang/adodb-fa.inc.php index 7fa46183e..84f17bd85 100644 --- a/libraries/adodb/lang/adodb-fa.inc.php +++ b/libraries/adodb/lang/adodb-fa.inc.php @@ -1,6 +1,24 @@ <?php - -/* Farsi - by "Peyman Hooshmandi Raad" <phooshmand#gmail.com> */ +/** + * Farsi language strings. + * + * 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 Peyman Hooshmandi Raad" <phooshmand@gmail.com> + */ $ADODB_LANG_ARRAY = array ( 'LANG' => 'fa', diff --git a/libraries/adodb/lang/adodb-fr.inc.php b/libraries/adodb/lang/adodb-fr.inc.php index 620196b43..b010d1e59 100644 --- a/libraries/adodb/lang/adodb-fr.inc.php +++ b/libraries/adodb/lang/adodb-fr.inc.php @@ -1,4 +1,23 @@ <?php +/** + * French language strings. + * + * 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 + */ $ADODB_LANG_ARRAY = array ( 'LANG' => 'fr', diff --git a/libraries/adodb/lang/adodb-hu.inc.php b/libraries/adodb/lang/adodb-hu.inc.php index 49357ce22..5a73827b3 100644 --- a/libraries/adodb/lang/adodb-hu.inc.php +++ b/libraries/adodb/lang/adodb-hu.inc.php @@ -1,6 +1,25 @@ <?php -# Hungarian language, encoding by ISO 8859-2 charset (Iso Latin-2) -# Halászvári Gábor <g.halaszvari#portmax.hu> +/** + * Hungarian language strings. + * + * 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 Halászvári Gábor <g.halaszvari@portmax.hu> + */ + $ADODB_LANG_ARRAY = array ( 'LANG' => 'hu', DB_ERROR => 'ismeretlen hiba', diff --git a/libraries/adodb/lang/adodb-id.inc.php b/libraries/adodb/lang/adodb-id.inc.php new file mode 100644 index 000000000..abd38eee3 --- /dev/null +++ b/libraries/adodb/lang/adodb-id.inc.php @@ -0,0 +1,55 @@ +<?php +/** + * Indonesian language strings. + * + * 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 Bambang Riswanto <bamz3r@gmail.com> + */ + +$ADODB_LANG_ARRAY = array ( + 'LANG' => 'id', + DB_ERROR => 'kesalahan tidak diketahui', + DB_ERROR_ALREADY_EXISTS => 'sudah ada', + DB_ERROR_CANNOT_CREATE => 'tak dapat membuat', + DB_ERROR_CANNOT_DELETE => 'tak dapat menghapus', + DB_ERROR_CANNOT_DROP => 'tak dapat menghapus', + DB_ERROR_CONSTRAINT => 'pelanggaran kendala', + DB_ERROR_DIVZERO => 'pembagian dengan 0', + DB_ERROR_INVALID => 'tidak sah', + DB_ERROR_INVALID_DATE => 'tanggal atau waktu tidak valid', + DB_ERROR_INVALID_NUMBER => 'nomor tidak sah', + DB_ERROR_MISMATCH => 'tak cocok', + DB_ERROR_NODBSELECTED => 'tak ada database dipilih', + DB_ERROR_NOSUCHFIELD => 'kolom tak ditemukan', + DB_ERROR_NOSUCHTABLE => 'tabel tak ditemukan', + DB_ERROR_NOT_CAPABLE => 'kemampuan DB tak memadai', + DB_ERROR_NOT_FOUND => 'tidak ditemukan', + DB_ERROR_NOT_LOCKED => 'tidak terkunci', + DB_ERROR_SYNTAX => 'kesalahan sintak', + DB_ERROR_UNSUPPORTED => 'tak didukung', + DB_ERROR_VALUE_COUNT_ON_ROW => 'menghitung isi pada baris', + DB_ERROR_INVALID_DSN => 'DSN tidak sah', + DB_ERROR_CONNECT_FAILED => 'koneksi gagal', + 0 => 'tak ada kesalahan', // DB_OK + DB_ERROR_NEED_MORE_DATA => 'data yang dimasukan tidak memadai', + DB_ERROR_EXTENSION_NOT_FOUND=> 'ekstensi tak ditemukan', + DB_ERROR_NOSUCHDB => 'database tak ditemukan', + DB_ERROR_ACCESS_VIOLATION => 'izin tidak memadai', + DB_ERROR_DEADLOCK => 'kebuntuan terdeteksi', + DB_ERROR_STATEMENT_TIMEOUT => 'perintah kehabisan waktu', + DB_ERROR_SERIALIZATION_FAILURE => 'tak dapat melanjutkan akses' +); diff --git a/libraries/adodb/lang/adodb-it.inc.php b/libraries/adodb/lang/adodb-it.inc.php index 80524e1d3..a6516308d 100644 --- a/libraries/adodb/lang/adodb-it.inc.php +++ b/libraries/adodb/lang/adodb-it.inc.php @@ -1,6 +1,25 @@ <?php -// Italian language file contributed by Tiraboschi Massimiliano aka TiMax -// www.maxdev.com timax@maxdev.com +/** + * Italian language strings. + * + * 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 Tiraboschi Massimiliano <timax@maxdev.com> + */ + $ADODB_LANG_ARRAY = array ( 'LANG' => 'it', DB_ERROR => 'errore sconosciuto', diff --git a/libraries/adodb/lang/adodb-nl.inc.php b/libraries/adodb/lang/adodb-nl.inc.php index 43e3ee694..8a898193f 100644 --- a/libraries/adodb/lang/adodb-nl.inc.php +++ b/libraries/adodb/lang/adodb-nl.inc.php @@ -1,5 +1,25 @@ <?php -// Translated by Pim Koeman (pim#wittenborg-university.com) +/** + * Dutch language strings. + * + * 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 Pim Koeman <pim@wittenborg-university.com> + */ + $ADODB_LANG_ARRAY = array ( 'LANG' => 'nl', DB_ERROR => 'onbekende fout', diff --git a/libraries/adodb/lang/adodb-oc.inc.php b/libraries/adodb/lang/adodb-oc.inc.php new file mode 100644 index 000000000..3481e79a1 --- /dev/null +++ b/libraries/adodb/lang/adodb-oc.inc.php @@ -0,0 +1,51 @@ +<?php +/** + * Occitan language strings. + * + * 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 + */ + +$ADODB_LANG_ARRAY = array ( + 'LANG' => 'oc', + DB_ERROR => 'error desconeguda', + DB_ERROR_ALREADY_EXISTS => 'existÃs ja', + DB_ERROR_CANNOT_CREATE => 'creacion impossibla', + DB_ERROR_CANNOT_DELETE => 'escafament impossible', + DB_ERROR_CANNOT_DROP => 'supression impossibla', + DB_ERROR_CONSTRAINT => 'violacion de constrenta', + DB_ERROR_DIVZERO => 'division per zèro', + DB_ERROR_INVALID => 'invalid', + DB_ERROR_INVALID_DATE => 'data o ora invalida', + DB_ERROR_INVALID_NUMBER => 'nombre invalid', + DB_ERROR_MISMATCH => 'error de concordà ncia', + DB_ERROR_NODBSELECTED => 'pas de basa de donadas de seleccionada', + DB_ERROR_NOSUCHFIELD => 'nom de colomna invalid', + DB_ERROR_NOSUCHTABLE => 'taula o vista inexistenta', + DB_ERROR_NOT_CAPABLE => 'foncion opcionala pas installada', + DB_ERROR_NOT_FOUND => 'pas trobat', + DB_ERROR_NOT_LOCKED => 'pas verrolhat', + DB_ERROR_SYNTAX => 'error de sintaxi', + DB_ERROR_UNSUPPORTED => 'pas suportat', + DB_ERROR_VALUE_COUNT_ON_ROW => 'valor inserida tròp granda per colomna', + DB_ERROR_INVALID_DSN => 'DSN invalid', + DB_ERROR_CONNECT_FAILED => 'fracà s a la connexion', + 0 => "pas d'error", // DB_OK + DB_ERROR_NEED_MORE_DATA => 'donadas provesidas insufisentas', + DB_ERROR_EXTENSION_NOT_FOUND=> 'extension pas trobada', + DB_ERROR_NOSUCHDB => 'basa de donadas desconeguda', + DB_ERROR_ACCESS_VIOLATION => 'dreits insufisents' +); diff --git a/libraries/adodb/lang/adodb-pl.inc.php b/libraries/adodb/lang/adodb-pl.inc.php index ffa10e33e..f855153eb 100644 --- a/libraries/adodb/lang/adodb-pl.inc.php +++ b/libraries/adodb/lang/adodb-pl.inc.php @@ -1,6 +1,24 @@ <?php - -// Contributed by Grzegorz Pacan <gp#dione.cc> +/** + * Polish language strings. + * + * 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 Grzegorz Pacan <gp@dione.cc> + */ $ADODB_LANG_ARRAY = array ( 'LANG' => 'pl', diff --git a/libraries/adodb/lang/adodb-pt-br.inc.php b/libraries/adodb/lang/adodb-pt-br.inc.php index 9c687b060..b6c0d1c95 100644 --- a/libraries/adodb/lang/adodb-pt-br.inc.php +++ b/libraries/adodb/lang/adodb-pt-br.inc.php @@ -1,6 +1,25 @@ <?php -// contributed by "Levi Fukumori" levi _AT_ fukumori _DOT_ com _DOT_ br -// portugese (brazilian) +/** + * Portuguese (Brazilian) language strings. + * + * 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 Levi Fukumori <levi@fukumori.com.br> + */ + $ADODB_LANG_ARRAY = array ( 'LANG' => 'pt-br', DB_ERROR => 'erro desconhecido', diff --git a/libraries/adodb/lang/adodb-ro.inc.php b/libraries/adodb/lang/adodb-ro.inc.php index b6ddd3132..011c01636 100644 --- a/libraries/adodb/lang/adodb-ro.inc.php +++ b/libraries/adodb/lang/adodb-ro.inc.php @@ -1,6 +1,24 @@ <?php - -/* Romanian - by "bogdan stefan" <sbogdan#rsb.ro> */ +/** + * Romanian language strings. + * + * 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 Bogdan Stefan <sbogdan@rsb.ro> + */ $ADODB_LANG_ARRAY = array ( 'LANG' => 'ro', diff --git a/libraries/adodb/lang/adodb-ru.inc.php b/libraries/adodb/lang/adodb-ru.inc.php index 67d80f2cc..a311784a5 100644 --- a/libraries/adodb/lang/adodb-ru.inc.php +++ b/libraries/adodb/lang/adodb-ru.inc.php @@ -1,6 +1,24 @@ <?php - -// Russian language file contributed by "Cyrill Malevanov" cyrill#malevanov.spb.ru. +/** + * Russian language strings. + * + * 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 Cyrill Malevanov <cyrill@malevanov.spb.ru> + */ $ADODB_LANG_ARRAY = array ( 'LANG' => 'ru', diff --git a/libraries/adodb/lang/adodb-sv.inc.php b/libraries/adodb/lang/adodb-sv.inc.php index d3be6b0e7..72e243011 100644 --- a/libraries/adodb/lang/adodb-sv.inc.php +++ b/libraries/adodb/lang/adodb-sv.inc.php @@ -1,5 +1,25 @@ <?php -// Christian Tiberg" christian@commsoft.nu +/** + * Swedish language strings. + * + * 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 Christian Tiberg <christian@commsoft.nu> + */ + $ADODB_LANG_ARRAY = array ( 'LANG' => 'en', DB_ERROR => 'Okänt fel', diff --git a/libraries/adodb/lang/adodb-th.inc.php b/libraries/adodb/lang/adodb-th.inc.php index a0685645d..354acca1e 100644 --- a/libraries/adodb/lang/adodb-th.inc.php +++ b/libraries/adodb/lang/adodb-th.inc.php @@ -1,5 +1,25 @@ <?php -// by Trirat Petchsingh <rosskouk#gmail.com> +/** + * Thai language strings. + * + * 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 Trirat Petchsingh <rosskouk@gmail.com> + */ + $ADODB_LANG_ARRAY = array ( 'LANG' => 'th', DB_ERROR => 'error ไม่รู้สาเหตุ', diff --git a/libraries/adodb/lang/adodb-uk.inc.php b/libraries/adodb/lang/adodb-uk.inc.php index 2ace5bc49..e54a96708 100644 --- a/libraries/adodb/lang/adodb-uk.inc.php +++ b/libraries/adodb/lang/adodb-uk.inc.php @@ -1,6 +1,24 @@ <?php - -// Ukrainian language file contributed by Alex Rootoff rootoff{AT}pisem.net. +/** + * Ukrainian language strings. + * + * 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 Alex Rootoff <rootoff@pisem.net> + */ $ADODB_LANG_ARRAY = array ( 'LANG' => 'uk', diff --git a/libraries/adodb/pear/Auth/Container/ADOdb.php b/libraries/adodb/pear/Auth/Container/ADOdb.php index 26c3a23e1..807da9d7b 100644 --- a/libraries/adodb/pear/Auth/Container/ADOdb.php +++ b/libraries/adodb/pear/Auth/Container/ADOdb.php @@ -1,36 +1,36 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. See License.txt. - Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Original Authors: Martin Jansen <mj#php.net> - Richard Tango-Lowy <richtl#arscognita.com> -*/ - -require_once 'Auth/Container.php'; -require_once 'adodb.inc.php'; -require_once 'adodb-pear.inc.php'; -require_once 'adodb-errorpear.inc.php'; - /** * Storage driver for fetching login data from a database using ADOdb-PHP. * - * This storage driver can use all databases which are supported - * by the ADBdb DB abstraction layer to fetch login data. - * See http://php.weblogs.com/adodb for information on ADOdb. + * This storage driver can use all databases which are supported by the ADBdb + * abstraction layer to fetch login data. * NOTE: The ADOdb directory MUST be in your PHP include_path! * - * @author Richard Tango-Lowy <richtl@arscognita.com> - * @package Auth - * @version $Revision: 1.3 $ + * 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 Martin Jansen <mj@php.net> + * @author Richard Tango-Lowy <richtl@arscognita.com> */ + +require_once 'Auth/Container.php'; +require_once 'adodb.inc.php'; +require_once 'adodb-pear.inc.php'; +require_once 'adodb-errorpear.inc.php'; + + class Auth_Container_ADOdb extends Auth_Container { @@ -58,7 +58,7 @@ class Auth_Container_ADOdb extends Auth_Container /** * Constructor of the container class * - * Initate connection to the database via PEAR::ADOdb + * Initiate connection to the database via PEAR::ADOdb * * @param string Connection data or DB object * @return object Returns an error object if something went wrong @@ -199,7 +199,7 @@ class Auth_Container_ADOdb extends Auth_Container /* Include additional fields if they exist */ if(!empty($this->options['db_fields'])){ if(is_array($this->options['db_fields'])){ - $this->options['db_fields'] = join($this->options['db_fields'], ', '); + $this->options['db_fields'] = join(', ', $this->options['db_fields']); } $this->options['db_fields'] = ', '.$this->options['db_fields']; } @@ -262,7 +262,7 @@ class Auth_Container_ADOdb extends Auth_Container continue; } // Use reference to the auth object if exists - // This is because the auth session variable can change so a static call to setAuthData does not make sence + // This is because the auth session variable can change so a static call to setAuthData does not make sense if(is_object($this->_auth_obj)){ $this->_auth_obj->setAuthData($key, $value); } else { diff --git a/libraries/adodb/pear/auth_adodb_example.php b/libraries/adodb/pear/auth_adodb_example.php index 3b7cf5e85..77af93955 100644 --- a/libraries/adodb/pear/auth_adodb_example.php +++ b/libraries/adodb/pear/auth_adodb_example.php @@ -1,5 +1,26 @@ <?php -// NOTE: The ADOdb and PEAR directories MUST be in your PHP include_path! +/** + * PEAR Auth example + * + * NOTE: The ADOdb and PEAR directories MUST be in your PHP include_path! + * + * 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 + */ +// require_once "Auth/Auth.php"; function loginFunction() { diff --git a/libraries/adodb/perf/perf-db2.inc.php b/libraries/adodb/perf/perf-db2.inc.php index 143fc3d55..fc05219d8 100644 --- a/libraries/adodb/perf/perf-db2.inc.php +++ b/libraries/adodb/perf/perf-db2.inc.php @@ -1,18 +1,23 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. See License.txt. - Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Library for basic performance monitoring and tuning - -*/ +/** + * Library for basic performance monitoring and tuning + * + * 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(); diff --git a/libraries/adodb/perf/perf-informix.inc.php b/libraries/adodb/perf/perf-informix.inc.php index e5cfb25d9..88802bcc5 100644 --- a/libraries/adodb/perf/perf-informix.inc.php +++ b/libraries/adodb/perf/perf-informix.inc.php @@ -1,18 +1,23 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. See License.txt. - Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Library for basic performance monitoring and tuning - -*/ +/** + * Library for basic performance monitoring and tuning + * + * 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(); @@ -23,7 +28,7 @@ if (!defined('ADODB_DIR')) die(); // class perf_informix extends adodb_perf{ - // Maximum size on varchar upto 9.30 255 chars + // Maximum size on varchar up to 9.30 255 chars // better truncate varchar to 255 than char(4000) ? var $createTableSQL = "CREATE TABLE adodb_logsql ( created datetime year to second NOT NULL, diff --git a/libraries/adodb/perf/perf-mssql.inc.php b/libraries/adodb/perf/perf-mssql.inc.php index cd8a6641f..5d8320326 100644 --- a/libraries/adodb/perf/perf-mssql.inc.php +++ b/libraries/adodb/perf/perf-mssql.inc.php @@ -1,19 +1,23 @@ <?php - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. See License.txt. - Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Library for basic performance monitoring and tuning - -*/ +/** + * Library for basic performance monitoring and tuning + * + * 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(); diff --git a/libraries/adodb/perf/perf-mssqlnative.inc.php b/libraries/adodb/perf/perf-mssqlnative.inc.php index b27788821..c2c90fc75 100644 --- a/libraries/adodb/perf/perf-mssqlnative.inc.php +++ b/libraries/adodb/perf/perf-mssqlnative.inc.php @@ -1,19 +1,23 @@ <?php - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. See License.txt. - Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Library for basic performance monitoring and tuning - -*/ +/** + * Library for basic performance monitoring and tuning + * + * 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(); diff --git a/libraries/adodb/perf/perf-mysql.inc.php b/libraries/adodb/perf/perf-mysql.inc.php index adccbdc92..dae44229d 100644 --- a/libraries/adodb/perf/perf-mysql.inc.php +++ b/libraries/adodb/perf/perf-mysql.inc.php @@ -1,18 +1,23 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. See License.txt. - Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Library for basic performance monitoring and tuning - -*/ +/** + * Library for basic performance monitoring and tuning + * + * 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(); @@ -118,7 +123,13 @@ class perf_mysql extends adodb_perf{ return $s; } - function Tables() + /** + * Returns a list of table statuses. + * + * @param string $orderby Unused (compatibility with parent method) + * @return string A formatted set of recordsets + */ + function tables($orderby='1') { if (!$this->tablesSQL) return false; @@ -302,11 +313,9 @@ class perf_mysql extends adodb_perf{ case ADODB_OPT_LOW : $sql = $this->optimizeTableLow; break; case ADODB_OPT_HIGH : $sql = $this->optimizeTableHigh; break; default : - { - // May dont use __FUNCTION__ constant for BC (__FUNCTION__ Added in PHP 4.3.0) + // May don't use __FUNCTION__ constant for BC (__FUNCTION__ Added in PHP 4.3.0) ADOConnection::outp( sprintf( "<p>%s: '%s' using of undefined mode '%s'</p>", __CLASS__, __FUNCTION__, $mode)); return false; - } } $sql = sprintf( $sql, $table); diff --git a/libraries/adodb/perf/perf-oci8.inc.php b/libraries/adodb/perf/perf-oci8.inc.php index 69df104fa..c11b261fd 100644 --- a/libraries/adodb/perf/perf-oci8.inc.php +++ b/libraries/adodb/perf/perf-oci8.inc.php @@ -1,18 +1,23 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. See License.txt. - Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Library for basic performance monitoring and tuning - -*/ +/** + * Library for basic performance monitoring and tuning + * + * 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(); diff --git a/libraries/adodb/perf/perf-postgres.inc.php b/libraries/adodb/perf/perf-postgres.inc.php index bd0ccb1b5..315c17f5c 100644 --- a/libraries/adodb/perf/perf-postgres.inc.php +++ b/libraries/adodb/perf/perf-postgres.inc.php @@ -1,19 +1,23 @@ <?php - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. See License.txt. - Set tabs to 4 for best viewing. - - Latest version is available at http://adodb.sourceforge.net - - Library for basic performance monitoring and tuning - -*/ +/** + * Library for basic performance monitoring and tuning + * + * 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(); @@ -113,10 +117,8 @@ class perf_postgres extends adodb_perf{ case ADODB_OPT_LOW : $sql = $this->optimizeTableLow; break; case ADODB_OPT_HIGH: $sql = $this->optimizeTableHigh; break; default : - { ADOConnection::outp(sprintf("<p>%s: '%s' using of undefined mode '%s'</p>", __CLASS__, 'optimizeTable', $mode)); return false; - } } $sql = sprintf($sql, $table); diff --git a/libraries/adodb/phpdoc b/libraries/adodb/phpdoc new file mode 100644 index 000000000..d4cb73a91 --- /dev/null +++ b/libraries/adodb/phpdoc @@ -0,0 +1,20 @@ +<?php +/** + * FileDescription + * + * 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 + */ diff --git a/libraries/adodb/pivottable.inc.php b/libraries/adodb/pivottable.inc.php index dd7d5d88a..14d8eebe5 100644 --- a/libraries/adodb/pivottable.inc.php +++ b/libraries/adodb/pivottable.inc.php @@ -1,15 +1,23 @@ <?php /** - * @version v5.20.9 21-Dec-2016 - * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - * @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - * Released under both BSD license and Lesser GPL library license. - * Whenever there is any discrepancy between the two licenses, - * the BSD license will take precedence. + * PivotTable. * - * Set tabs to 4 for best viewing. + * 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 + */ /* * Concept from daniel.lucazeau@ajornet.com. @@ -29,8 +37,7 @@ * * @returns Sql generated */ - - function PivotTableSQL(&$db,$tables,$rowfields,$colfield, $where=false, +function PivotTableSQL(&$db,$tables,$rowfields,$colfield, $where=false, $aggfield = false,$sumlabel='Sum ',$aggfn ='SUM', $showcount = true) { if ($aggfield) $hidecnt = true; diff --git a/libraries/adodb/rsfilter.inc.php b/libraries/adodb/rsfilter.inc.php index 4b609b98b..34c5311cf 100644 --- a/libraries/adodb/rsfilter.inc.php +++ b/libraries/adodb/rsfilter.inc.php @@ -1,18 +1,23 @@ <?php /** - * @version v5.20.9 21-Dec-2016 - * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - * @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - * Released under both BSD license and Lesser GPL library license. - * Whenever there is any discrepancy between the two licenses, - * the BSD license will take precedence. + * RecordSet Filter. * - * Set tabs to 4 for best viewing. + * This file is part of ADOdb, a Database Abstraction Layer library for PHP. * - * Latest version is available at http://php.weblogs.com + * @package ADOdb + * @link https://adodb.org Project's web site and documentation + * @link https://github.com/ADOdb/ADOdb Source code and issue tracker * - * Requires PHP4.01pl2 or later because it uses include_once -*/ + * 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 + */ /* Filter all fields and all rows in a recordset and returns the diff --git a/libraries/adodb/server.php b/libraries/adodb/server.php index c61287e73..76e757fd9 100644 --- a/libraries/adodb/server.php +++ b/libraries/adodb/server.php @@ -1,15 +1,31 @@ <?php - /** - * @version v5.20.9 21-Dec-2016 - * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - * @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - * Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. + * ADOdb Proxy Server. + * + * @deprecated 5.21.0 + * + * Security warning - use with extreme caution ! + * Depending on how it is setup, this feature can potentially expose the + * database to attacks, particularly if used with a privileged user account. + * + * 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 */ -/* Documentation on usage is at http://php.weblogs.com/adodb_csv +/* Documentation on usage is at https://adodb.org/dokuwiki/doku.php?id=v5:proxy:proxy_index * * Legal query string parameters: * @@ -20,7 +36,7 @@ * * example: * - * http://localhost/php/server.php?select+*+from+table&nrows=10&offset=2 + * http://localhost/php/server.php?sql=select+*+from+table&nrows=10&offset=2 */ @@ -33,7 +49,7 @@ $ACCEPTIP = '127.0.0.1'; /* * Connection parameters */ -$driver = 'mysql'; +$driver = 'mysqli'; $host = 'localhost'; // DSN for odbc $uid = 'root'; $pwd = 'garbase-it-is'; @@ -51,19 +67,6 @@ function err($s) die('**** '.$s.' '); } -// undo stupid magic quotes -function undomq(&$m) -{ - if (get_magic_quotes_gpc()) { - // undo the damage - $m = str_replace('\\\\','\\',$m); - $m = str_replace('\"','"',$m); - $m = str_replace('\\\'','\'',$m); - - } - return $m; -} - ///////////////////////////////////////// DEFINITIONS @@ -80,8 +83,8 @@ if (empty($_REQUEST['sql'])) err('No SQL'); $conn = ADONewConnection($driver); -if (!$conn->Connect($host,$uid,$pwd,$database)) err($conn->ErrorNo(). $sep . $conn->ErrorMsg()); -$sql = undomq($_REQUEST['sql']); +if (!$conn->connect($host,$uid,$pwd,$database)) err($conn->errorNo(). $sep . $conn->errorMsg()); +$sql = $_REQUEST['sql']; if (isset($_REQUEST['fetch'])) $ADODB_FETCH_MODE = $_REQUEST['fetch']; @@ -89,12 +92,12 @@ if (isset($_REQUEST['fetch'])) if (isset($_REQUEST['nrows'])) { $nrows = $_REQUEST['nrows']; $offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : -1; - $rs = $conn->SelectLimit($sql,$nrows,$offset); + $rs = $conn->selectLimit($sql,$nrows,$offset); } else - $rs = $conn->Execute($sql); + $rs = $conn->execute($sql); if ($rs){ //$rs->timeToLive = 1; echo _rs2serialize($rs,$conn,$sql); - $rs->Close(); + $rs->close(); } else - err($conn->ErrorNo(). $sep .$conn->ErrorMsg()); + err($conn->errorNo(). $sep .$conn->errorMsg()); diff --git a/libraries/adodb/session/adodb-compress-bzip2.php b/libraries/adodb/session/adodb-compress-bzip2.php index 4e6ab501a..17ad99fb7 100644 --- a/libraries/adodb/session/adodb-compress-bzip2.php +++ b/libraries/adodb/session/adodb-compress-bzip2.php @@ -1,24 +1,32 @@ <?php - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Contributed by Ross Smith (adodb@netebb.com). - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4 for best viewing. - -*/ +/** + * ADOdb Session Management + * + * 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 Ross Smith <adodb@netebb.com> + */ if (!function_exists('bzcompress')) { trigger_error('bzip2 functions are not available', E_USER_ERROR); return 0; } -/* -*/ +/** + */ class ADODB_Compress_Bzip2 { /** */ @@ -41,8 +49,8 @@ class ADODB_Compress_Bzip2 { /** */ function setBlockSize($block_size) { - assert('$block_size >= 1'); - assert('$block_size <= 9'); + assert($block_size >= 1); + assert($block_size <= 9); $this->_block_size = (int) $block_size; } @@ -55,8 +63,8 @@ class ADODB_Compress_Bzip2 { /** */ function setWorkLevel($work_level) { - assert('$work_level >= 0'); - assert('$work_level <= 250'); + assert($work_level >= 0); + assert($work_level <= 250); $this->_work_level = (int) $work_level; } @@ -69,7 +77,7 @@ class ADODB_Compress_Bzip2 { /** */ function setMinLength($min_length) { - assert('$min_length >= 0'); + assert($min_length >= 0); $this->_min_length = (int) $min_length; } diff --git a/libraries/adodb/session/adodb-compress-gzip.php b/libraries/adodb/session/adodb-compress-gzip.php index 53bb0530a..bbaf6c637 100644 --- a/libraries/adodb/session/adodb-compress-gzip.php +++ b/libraries/adodb/session/adodb-compress-gzip.php @@ -1,17 +1,23 @@ <?php - - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Contributed by Ross Smith (adodb@netebb.com). - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4 for best viewing. - -*/ +/** + * ADOdb Session Management + * + * 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 + */ if (!function_exists('gzcompress')) { trigger_error('gzip functions are not available', E_USER_ERROR); @@ -38,8 +44,8 @@ class ADODB_Compress_Gzip { /** */ function setLevel($level) { - assert('$level >= 0'); - assert('$level <= 9'); + assert($level >= 0); + assert($level <= 9); $this->_level = (int) $level; } @@ -52,7 +58,7 @@ class ADODB_Compress_Gzip { /** */ function setMinLength($min_length) { - assert('$min_length >= 0'); + assert($min_length >= 0); $this->_min_length = (int) $min_length; } diff --git a/libraries/adodb/session/adodb-cryptsession.php b/libraries/adodb/session/adodb-cryptsession.php index 763cb50e8..088053217 100644 --- a/libraries/adodb/session/adodb-cryptsession.php +++ b/libraries/adodb/session/adodb-cryptsession.php @@ -1,22 +1,25 @@ <?php - - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Contributed by Ross Smith (adodb@netebb.com). - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4 for best viewing. -*/ - -/* - -This file is provided for backwards compatibility purposes - -*/ +/** + * ADOdb Session Management + * + * @deprecated This file is provided for backwards compatibility purposes + * + * 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 + */ if (!defined('ADODB_SESSION')) { require_once dirname(__FILE__) . '/adodb-session.php'; diff --git a/libraries/adodb/session/adodb-cryptsession2.php b/libraries/adodb/session/adodb-cryptsession2.php index b2ef54dd9..f3e95a132 100644 --- a/libraries/adodb/session/adodb-cryptsession2.php +++ b/libraries/adodb/session/adodb-cryptsession2.php @@ -1,22 +1,25 @@ <?php - - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Contributed by Ross Smith (adodb@netebb.com). - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4 for best viewing. -*/ - -/* - -This file is provided for backwards compatibility purposes - -*/ +/** + * ADOdb Session Management + * + * @deprecated This file is provided for backwards compatibility purposes + * + * 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 + */ if (!defined('ADODB_SESSION')) { require_once dirname(__FILE__) . '/adodb-session2.php'; diff --git a/libraries/adodb/session/adodb-encrypt-mcrypt.php b/libraries/adodb/session/adodb-encrypt-mcrypt.php index fc99fbc29..bec9ff2c7 100644 --- a/libraries/adodb/session/adodb-encrypt-mcrypt.php +++ b/libraries/adodb/session/adodb-encrypt-mcrypt.php @@ -1,17 +1,23 @@ <?php - - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Contributed by Ross Smith (adodb@netebb.com). - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4 for best viewing. - -*/ +/** + * ADOdb Session Management + * + * 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 + */ if (!function_exists('mcrypt_encrypt')) { trigger_error('Mcrypt functions are not available', E_USER_ERROR); diff --git a/libraries/adodb/session/adodb-encrypt-md5.php b/libraries/adodb/session/adodb-encrypt-md5.php index f5b2da616..7ae9b56eb 100644 --- a/libraries/adodb/session/adodb-encrypt-md5.php +++ b/libraries/adodb/session/adodb-encrypt-md5.php @@ -1,16 +1,23 @@ <?php - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Contributed by Ross Smith (adodb@netebb.com). - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4 for best viewing. - -*/ +/** + * ADOdb Session Management + * + * 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_SESSION')) die(); diff --git a/libraries/adodb/session/adodb-encrypt-secret.php b/libraries/adodb/session/adodb-encrypt-secret.php index 96ae85494..2c29f7a08 100644 --- a/libraries/adodb/session/adodb-encrypt-secret.php +++ b/libraries/adodb/session/adodb-encrypt-secret.php @@ -1,16 +1,23 @@ <?php - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Contributed by Ross Smith (adodb@netebb.com). - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4 for best viewing. - -*/ +/** + * ADOdb Session Management + * + * 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 + */ @define('HORDE_BASE', dirname(dirname(dirname(__FILE__))) . '/horde'); @@ -22,14 +29,6 @@ if (!is_dir(HORDE_BASE)) { include_once HORDE_BASE . '/lib/Horde.php'; include_once HORDE_BASE . '/lib/Secret.php'; -/** - -NOTE: On Windows 2000 SP4 with PHP 4.3.1, MCrypt 2.4.x, and Apache 1.3.28, -the session didn't work properly. - -This may be resolved with 4.3.3. - - */ class ADODB_Encrypt_Secret { /** */ diff --git a/libraries/adodb/session/adodb-encrypt-sha1.php b/libraries/adodb/session/adodb-encrypt-sha1.php index 70655153f..0aa38c837 100644 --- a/libraries/adodb/session/adodb-encrypt-sha1.php +++ b/libraries/adodb/session/adodb-encrypt-sha1.php @@ -1,13 +1,27 @@ <?php +/** + * ADOdb Session Management + * + * 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 + */ if (!defined('ADODB_SESSION')) die(); include_once ADODB_SESSION . '/crypt.inc.php'; - -/** - - */ - class ADODB_Encrypt_SHA1 { function write($data, $key) diff --git a/libraries/adodb/session/adodb-sess.txt b/libraries/adodb/session/adodb-sess.txt index c6c768586..1e9a8aace 100644 --- a/libraries/adodb/session/adodb-sess.txt +++ b/libraries/adodb/session/adodb-sess.txt @@ -58,10 +58,10 @@ Originally, the user had to call adodb_sess_open(). Postgres SAP -* filter(): Used to support multiple, simulataneous encryption/compression +* filter(): Used to support multiple, simultaneous encryption/compression schemes. -* Debug support is improved thru _rsdump() function, which is called after +* Debug support is improved through _rsdump() function, which is called after every database call. ------------ @@ -120,7 +120,7 @@ next release of ADODB. If so, I will modify the current documentation to detail the new functionality. To that end, what file(s) contain the documentation? Please -send them to me if they are not publically available. +send them to me if they are not publicly available. Also, if there is *anything* in the code that you like to see changed, let me know. diff --git a/libraries/adodb/session/adodb-session-clob.php b/libraries/adodb/session/adodb-session-clob.php index a6906f601..8c5e9fb39 100644 --- a/libraries/adodb/session/adodb-session-clob.php +++ b/libraries/adodb/session/adodb-session-clob.php @@ -1,22 +1,25 @@ <?php - - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Contributed by Ross Smith (adodb@netebb.com). - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4 for best viewing. -*/ - -/* - -This file is provided for backwards compatibility purposes - -*/ +/** + * ADOdb Session Management + * + * @deprecated This file is provided for backwards compatibility purposes + * + * 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 + */ if (!defined('ADODB_SESSION')) { require_once dirname(__FILE__) . '/adodb-session.php'; diff --git a/libraries/adodb/session/adodb-session-clob2.php b/libraries/adodb/session/adodb-session-clob2.php index 2cb1cab67..babfa4206 100644 --- a/libraries/adodb/session/adodb-session-clob2.php +++ b/libraries/adodb/session/adodb-session-clob2.php @@ -1,22 +1,26 @@ <?php - - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Contributed by Ross Smith (adodb@netebb.com). - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4 for best viewing. -*/ - -/* - -This file is provided for backwards compatibility purposes - -*/ +/** + * ADOdb Session Management + * + * @deprecated This file is provided for backwards compatibility purposes + * + * 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 Ross Smith <adodb@netebb.com> + */ if (!defined('ADODB_SESSION')) { require_once dirname(__FILE__) . '/adodb-session2.php'; diff --git a/libraries/adodb/session/adodb-session.php b/libraries/adodb/session/adodb-session.php index aa2ea1e84..9e716232c 100644 --- a/libraries/adodb/session/adodb-session.php +++ b/libraries/adodb/session/adodb-session.php @@ -1,16 +1,24 @@ <?php - - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Contributed by Ross Smith (adodb@netebb.com). - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4 for best viewing. -*/ +/** + * ADOdb Session Management + * + * 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 Ross Smith <adodb@netebb.com> + */ /* You may want to rename the 'data' field to 'session_data' as @@ -37,7 +45,7 @@ define('ADODB_SESSION', dirname(__FILE__)); /* - Unserialize session data manually. See http://phplens.com/lens/lensforum/msgs.php?id=9821 + Unserialize session data manually. See PHPLens Issue No: 9821 From Kerr Schere, to unserialize session data stored via ADOdb. 1. Pull the session data from the db and loop through it. @@ -56,7 +64,7 @@ function adodb_unserialize( $serialized_string ) } /* - Thanks Joe Li. See http://phplens.com/lens/lensforum/msgs.php?id=11487&x=1 + Thanks Joe Li. See PHPLens Issue No: 11487&x=1 Since adodb 4.61. */ function adodb_session_regenerate_id() @@ -70,7 +78,7 @@ function adodb_session_regenerate_id() } else { session_id(md5(uniqid(rand(), true))); $ck = session_get_cookie_params(); - setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); + setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure'], $ck['httponly']); //@session_start(); } $new_id = session_id(); @@ -80,7 +88,7 @@ function adodb_session_regenerate_id() if (!$ok) { session_id($old_id); if (empty($ck)) $ck = session_get_cookie_params(); - setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); + setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure'], $ck['httponly']); return false; } @@ -89,7 +97,7 @@ function adodb_session_regenerate_id() /* Generate database table for session data - @see http://phplens.com/lens/lensforum/msgs.php?id=12280 + @see PHPLens Issue No: 12280 @return 0 if failure, 1 if errors, 2 if successful. @author Markus Staab http://www.public-4u.de */ @@ -442,7 +450,6 @@ class ADODB_Session { /*! */ function _init() { - session_module_name('user'); session_set_save_handler( array('ADODB_Session', 'open'), array('ADODB_Session', 'close'), @@ -600,7 +607,7 @@ class ADODB_Session { $sql = "SELECT $data FROM $table WHERE sesskey = $binary $qkey AND expiry >= " . time(); /* Lock code does not work as it needs to hold transaction within whole page, and we don't know if - developer has commited elsewhere... :( + developer has committed elsewhere... :( */ #if (ADODB_Session::Lock()) # $rs = $conn->RowLock($table, "$binary sesskey = $qkey AND expiry >= " . time(), $data); @@ -922,12 +929,12 @@ ADODB_Session::_init(); if (empty($ADODB_SESSION_READONLY)) register_shutdown_function('session_write_close'); -// for backwards compatability only +// for backwards compatibility only function adodb_sess_open($save_path, $session_name, $persist = true) { return ADODB_Session::open($save_path, $session_name, $persist); } -// for backwards compatability only +// for backwards compatibility only function adodb_sess_gc($t) { return ADODB_Session::gc($t); diff --git a/libraries/adodb/session/adodb-session2.php b/libraries/adodb/session/adodb-session2.php index adeefc621..bf64b4166 100644 --- a/libraries/adodb/session/adodb-session2.php +++ b/libraries/adodb/session/adodb-session2.php @@ -1,61 +1,23 @@ <?php - - -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Contributed by Ross Smith (adodb@netebb.com). - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4 for best viewing. - - -*/ - -/* - -CREATE Table SCripts - -Oracle -====== - -CREATE TABLE SESSIONS2 -( - SESSKEY VARCHAR2(48 BYTE) NOT NULL, - EXPIRY DATE NOT NULL, - EXPIREREF VARCHAR2(200 BYTE), - CREATED DATE NOT NULL, - MODIFIED DATE NOT NULL, - SESSDATA CLOB, - PRIMARY KEY(SESSKEY) -); - - -CREATE INDEX SESS2_EXPIRY ON SESSIONS2(EXPIRY); -CREATE UNIQUE INDEX SESS2_PK ON SESSIONS2(SESSKEY); -CREATE INDEX SESS2_EXP_REF ON SESSIONS2(EXPIREREF); - - - - MySQL - ===== - -CREATE TABLE sessions2( - sesskey VARCHAR( 64 ) NOT NULL DEFAULT '', - expiry TIMESTAMP NOT NULL , - expireref VARCHAR( 250 ) DEFAULT '', - created TIMESTAMP NOT NULL , - modified TIMESTAMP NOT NULL , - sessdata LONGTEXT DEFAULT '', - PRIMARY KEY ( sesskey ) , - INDEX sess2_expiry( expiry ), - INDEX sess2_expireref( expireref ) -) - - -*/ +/** + * ADOdb Session Management + * + * 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 + */ if (!defined('_ADODB_LAYER')) { require realpath(dirname(__FILE__) . '/../adodb.inc.php'); @@ -67,7 +29,7 @@ define('ADODB_SESSION', dirname(__FILE__)); define('ADODB_SESSION2', ADODB_SESSION); /* - Unserialize session data manually. See http://phplens.com/lens/lensforum/msgs.php?id=9821 + Unserialize session data manually. See PHPLens Issue No: 9821 From Kerr Schere, to unserialize session data stored via ADOdb. 1. Pull the session data from the db and loop through it. @@ -86,7 +48,7 @@ function adodb_unserialize( $serialized_string ) } /* - Thanks Joe Li. See http://phplens.com/lens/lensforum/msgs.php?id=11487&x=1 + Thanks Joe Li. See PHPLens Issue No: 11487&x=1 Since adodb 4.61. */ function adodb_session_regenerate_id() @@ -100,7 +62,7 @@ function adodb_session_regenerate_id() } else { session_id(md5(uniqid(rand(), true))); $ck = session_get_cookie_params(); - setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); + setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure'], $ck['httponly']); //@session_start(); } $new_id = session_id(); @@ -110,7 +72,7 @@ function adodb_session_regenerate_id() if (!$ok) { session_id($old_id); if (empty($ck)) $ck = session_get_cookie_params(); - setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); + setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure'], $ck['httponly']); return false; } @@ -119,7 +81,7 @@ function adodb_session_regenerate_id() /* Generate database table for session data - @see http://phplens.com/lens/lensforum/msgs.php?id=12280 + @see PHPLens Issue No: 12280 @return 0 if failure, 1 if errors, 2 if successful. @author Markus Staab http://www.public-4u.de */ @@ -158,7 +120,7 @@ class ADODB_Session { */ static function driver($driver = null) { - static $_driver = 'mysql'; + static $_driver = 'mysqli'; static $set = false; if (!is_null($driver)) { @@ -464,7 +426,6 @@ class ADODB_Session { /*! */ static function _init() { - session_module_name('user'); session_set_save_handler( array('ADODB_Session', 'open'), array('ADODB_Session', 'close'), @@ -564,29 +525,44 @@ class ADODB_Session { # assert('$database'); # assert('$driver'); # assert('$host'); - - $conn = ADONewConnection($driver); - - if ($debug) { - $conn->debug = true; - ADOConnection::outp( " driver=$driver user=$user db=$database "); - } - - if (empty($conn->_connectionID)) { // not dsn + if (strpos($driver, 'pdo_') === 0){ + $conn = ADONewConnection('pdo'); + $driver = str_replace('pdo_', '', $driver); + $dsn = $driver.':'.'hostname='.$host.';dbname='.$database.';'; if ($persist) { switch($persist) { default: - case 'P': $ok = $conn->PConnect($host, $user, $password, $database); break; - case 'C': $ok = $conn->Connect($host, $user, $password, $database); break; - case 'N': $ok = $conn->NConnect($host, $user, $password, $database); break; + case 'P': $ok = $conn->PConnect($dsn,$user,$password); break; + case 'C': $ok = $conn->Connect($dsn,$user,$password); break; + case 'N': $ok = $conn->NConnect($dsn,$user,$password); break; } } else { - $ok = $conn->Connect($host, $user, $password, $database); + $ok = $conn->Connect($dsn,$user,$password); + } + }else{ + $conn = ADONewConnection($driver); + if ($debug) { + $conn->debug = true; + ADOConnection::outp( " driver=$driver user=$user db=$database "); + } + + if (empty($conn->_connectionID)) { // not dsn + if ($persist) { + switch($persist) { + default: + case 'P': $ok = $conn->PConnect($host, $user, $password, $database); break; + case 'C': $ok = $conn->Connect($host, $user, $password, $database); break; + case 'N': $ok = $conn->NConnect($host, $user, $password, $database); break; + } + } else { + $ok = $conn->Connect($host, $user, $password, $database); + } + } else { + $ok = true; // $conn->_connectionID is set after call to ADONewConnection } - } else { - $ok = true; // $conn->_connectionID is set after call to ADONewConnection } + if ($ok) $GLOBALS['ADODB_SESS_CONN'] = $conn; else ADOConnection::outp('<p>Session: connection failed</p>', false); @@ -629,7 +605,7 @@ class ADODB_Session { $sql = "SELECT $ADODB_SESSION_SELECT_FIELDS FROM $table WHERE sesskey = $binary ".$conn->Param(0)." AND expiry >= " . $conn->sysTimeStamp; /* Lock code does not work as it needs to hold transaction within whole page, and we don't know if - developer has commited elsewhere... :( + developer has committed elsewhere... :( */ #if (ADODB_Session::Lock()) # $rs = $conn->RowLock($table, "$binary sesskey = $qkey AND expiry >= " . time(), sessdata); @@ -807,7 +783,7 @@ class ADODB_Session { //assert('$table'); $qkey = $conn->quote($key); - $binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : ''; + $binary = $conn->dataProvider === 'mysql' || $conn->dataProvider === 'pdo' ? '/*! BINARY */' : ''; if ($expire_notify) { reset($expire_notify); @@ -927,12 +903,12 @@ ADODB_Session::_init(); if (empty($ADODB_SESSION_READONLY)) register_shutdown_function('session_write_close'); -// for backwards compatability only +// for backwards compatibility only function adodb_sess_open($save_path, $session_name, $persist = true) { return ADODB_Session::open($save_path, $session_name, $persist); } -// for backwards compatability only +// for backwards compatibility only function adodb_sess_gc($t) { return ADODB_Session::gc($t); diff --git a/libraries/adodb/session/crypt.inc.php b/libraries/adodb/session/crypt.inc.php index 1468cb1ae..82121e397 100644 --- a/libraries/adodb/session/crypt.inc.php +++ b/libraries/adodb/session/crypt.inc.php @@ -1,5 +1,25 @@ <?php -// Session Encryption by Ari Kuorikoski <ari.kuorikoski@finebyte.com> +/** + * ADOdb Session Management + * + * 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 Ari Kuorikoski <ari.kuorikoski@finebyte.com> + */ + class MD5Crypt{ function keyED($txt,$encrypt_key) { @@ -16,7 +36,6 @@ class MD5Crypt{ function Encrypt($txt,$key) { - srand((double)microtime()*1000000); $encrypt_key = md5(rand(0,32000)); $ctr=0; $tmp = ""; @@ -45,7 +64,6 @@ class MD5Crypt{ function RandPass() { $randomPassword = ""; - srand((double)microtime()*1000000); for($i=0;$i<8;$i++) { $randnumber = rand(48,120); @@ -83,7 +101,6 @@ class SHA1Crypt{ function Encrypt($txt,$key) { - srand((double)microtime()*1000000); $encrypt_key = sha1(rand(0,32000)); $ctr=0; $tmp = ""; @@ -133,8 +150,6 @@ class SHA1Crypt{ function RandPass() { $randomPassword = ""; - srand((double)microtime()*1000000); - for($i=0;$i<8;$i++) { diff --git a/libraries/adodb/session/old/adodb-cryptsession.php b/libraries/adodb/session/old/adodb-cryptsession.php index ca0d79305..6616de3d3 100644 --- a/libraries/adodb/session/old/adodb-cryptsession.php +++ b/libraries/adodb/session/old/adodb-cryptsession.php @@ -1,22 +1,29 @@ <?php +/** + * ADOdb Session Management + * + * This file provides PHP4 session management using the ADODB database + * wrapper library. + * + * @deprecated + * + * 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 + */ /* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Made table name configurable - by David Johnson djohnson@inpro.net - Encryption by Ari Kuorikoski <ari.kuorikoski@finebyte.com> - - Set tabs to 4 for best viewing. - - Latest version of ADODB is available at http://php.weblogs.com/adodb - ====================================================================== - - This file provides PHP4 session management using the ADODB database -wrapper library. - Example ======= @@ -197,7 +204,7 @@ $Crypt = new MD5Crypt; ADOConnection::outp( ' -- Session Replace: '.$ADODB_SESS_CONN->ErrorMsg().'</p>',false); } else { - // bug in access driver (could be odbc?) means that info is not commited + // bug in access driver (could be odbc?) means that info is not committed // properly unless select statement executed in Win2000 if ($ADODB_SESS_CONN->databaseType == 'access') $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'"); @@ -302,7 +309,6 @@ function adodb_sess_gc($maxlifetime) { return true; } -session_module_name('user'); session_set_save_handler( "adodb_sess_open", "adodb_sess_close", diff --git a/libraries/adodb/session/old/adodb-session-clob.php b/libraries/adodb/session/old/adodb-session-clob.php index 3361ea595..864fdfd73 100644 --- a/libraries/adodb/session/old/adodb-session-clob.php +++ b/libraries/adodb/session/old/adodb-session-clob.php @@ -1,19 +1,29 @@ <?php +/** + * ADOdb Session Management + * + * This file provides PHP4 session management using the ADODB database + * wrapper library. + * + * @deprecated + * + * 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 + */ /* - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4 for best viewing. - - Latest version of ADODB is available at http://php.weblogs.com/adodb - ====================================================================== - - This file provides PHP4 session management using the ADODB database - wrapper library, using Oracle CLOB's to store data. Contributed by achim.gosse@ddd.de. - Example ======= @@ -318,7 +328,7 @@ function adodb_sess_write($key, $val) ADOConnection::outp( ' -- Session Replace: '.nl2br($err).'</p>',false); } else { - // bug in access driver (could be odbc?) means that info is not commited + // bug in access driver (could be odbc?) means that info is not committed // properly unless select statement executed in Win2000 if ($ADODB_SESS_CONN->databaseType == 'access') $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'"); @@ -426,7 +436,6 @@ function adodb_sess_gc($maxlifetime) return true; } -session_module_name('user'); session_set_save_handler( "adodb_sess_open", "adodb_sess_close", diff --git a/libraries/adodb/session/old/adodb-session.php b/libraries/adodb/session/old/adodb-session.php index 5764339ec..5fd43abc0 100644 --- a/libraries/adodb/session/old/adodb-session.php +++ b/libraries/adodb/session/old/adodb-session.php @@ -1,19 +1,30 @@ <?php -/* -@version v5.20.9 21-Dec-2016 -@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. -@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - Set tabs to 4 for best viewing. - - Latest version of ADODB is available at http://php.weblogs.com/adodb - ====================================================================== - - This file provides PHP4 session management using the ADODB database -wrapper library. +/** + * ADOdb Session Management + * + * This file provides PHP4 session management using the ADODB database + * wrapper library. + * + * @deprecated + * + * 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 + */ +/* Example ======= @@ -110,7 +121,7 @@ if (!defined('ADODB_SESSION')) { define('ADODB_SESSION_SYNCH_SECS',60); /* - Thanks Joe Li. See http://phplens.com/lens/lensforum/msgs.php?id=11487&x=1 + Thanks Joe Li. See PHPLens Issue No: 11487&x=1 */ function adodb_session_regenerate_id() { @@ -307,7 +318,7 @@ function adodb_sess_write($key, $val) ADOConnection::outp( ' -- Session Replace: '.$ADODB_SESS_CONN->ErrorMsg().'</p>',false); } else { - // bug in access driver (could be odbc?) means that info is not commited + // bug in access driver (could be odbc?) means that info is not committed // properly unless select statement executed in Win2000 if ($ADODB_SESS_CONN->databaseType == 'access') $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'"); @@ -417,7 +428,6 @@ function adodb_sess_gc($maxlifetime) return true; } -session_module_name('user'); session_set_save_handler( "adodb_sess_open", "adodb_sess_close", diff --git a/libraries/adodb/session/old/crypt.inc.php b/libraries/adodb/session/old/crypt.inc.php index 9c347db06..089e24a0a 100644 --- a/libraries/adodb/session/old/crypt.inc.php +++ b/libraries/adodb/session/old/crypt.inc.php @@ -1,5 +1,27 @@ <?php -// Session Encryption by Ari Kuorikoski <ari.kuorikoski@finebyte.com> +/** + * ADOdb Session Management + * + * @deprecated + * + * 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 Ari Kuorikoski <ari.kuorikoski@finebyte.com> + */ + class MD5Crypt{ function keyED($txt,$encrypt_key) { @@ -16,7 +38,6 @@ class MD5Crypt{ function Encrypt($txt,$key) { - srand((double)microtime()*1000000); $encrypt_key = md5(rand(0,32000)); $ctr=0; $tmp = ""; @@ -45,7 +66,6 @@ class MD5Crypt{ function RandPass() { $randomPassword = ""; - srand((double)microtime()*1000000); for($i=0;$i<8;$i++) { $randnumber = rand(48,120); diff --git a/libraries/adodb/session/session_schema.xml b/libraries/adodb/session/session_schema.xml index 27e47bfee..c1f75316d 100644 --- a/libraries/adodb/session/session_schema.xml +++ b/libraries/adodb/session/session_schema.xml @@ -1,7 +1,7 @@ <?xml version="1.0"?> <schema version="0.2"> <table name="sessions"> - <desc>table for ADOdb session-management</desc> + <descr>table for ADOdb session-management</descr> <field name="SESSKEY" type="C" size="32"> <descr>session key</descr> diff --git a/libraries/adodb/session/session_schema2.xml b/libraries/adodb/session/session_schema2.xml index f0d3ec94a..89cb4f283 100644 --- a/libraries/adodb/session/session_schema2.xml +++ b/libraries/adodb/session/session_schema2.xml @@ -1,7 +1,7 @@ <?xml version="1.0"?> <schema version="0.3"> <table name="sessions2"> - <desc>table for ADOdb session-management</desc> + <descr>table for ADOdb session-management</descr> <field name="SESSKEY" type="C" size="64"> <descr>session key</descr> diff --git a/libraries/adodb/toexport.inc.php b/libraries/adodb/toexport.inc.php index 94c394b8e..66bbf5424 100644 --- a/libraries/adodb/toexport.inc.php +++ b/libraries/adodb/toexport.inc.php @@ -1,14 +1,6 @@ <?php - /** - * @version v5.20.9 21-Dec-2016 - * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - * @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - * Released under both BSD license and Lesser GPL library license. - * Whenever there is any discrepancy between the two licenses, - * the BSD license will take precedence. - * - * Code to export recordsets in several formats: + * Export recordsets in several formats. * * AS VARIABLE * $s = rs2csv($rs); # comma-separated values @@ -21,6 +13,22 @@ * * TO STDOUT * rs2csvout($rs); + * + * 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 */ // returns a recordset as a csv string @@ -77,7 +85,7 @@ function _adodb_export(&$rs,$sep,$sepreplace,$fp=false,$addtitles=true,$quote = reset($fieldTypes); $i = 0; $elements = array(); - while(list(,$o) = each($fieldTypes)) { + foreach ($fieldTypes as $o) { $v = ($o) ? $o->name : 'Field'.($i++); if ($escquote) $v = str_replace($quote,$escquotequote,$v); diff --git a/libraries/adodb/tohtml.inc.php b/libraries/adodb/tohtml.inc.php index d39ed2919..e92c8b44a 100644 --- a/libraries/adodb/tohtml.inc.php +++ b/libraries/adodb/tohtml.inc.php @@ -1,14 +1,29 @@ <?php -/* - @version v5.20.9 21-Dec-2016 - @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. - @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, - the BSD license will take precedence. - - Some pretty-printing by Chris Oxenreider <oxenreid@state.net> -*/ +/** + * RecordSet to HTML Table + * + * Convert a recordset to a html table. Multiple tables are generated + * if the number of rows is > $gSQLBlockRows. This is because + * web browsers normally require the whole table to be downloaded + * before it can be rendered, so we break the output into several + * smaller, faster rendering tables. + * + * 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 + */ // specific code for tohtml GLOBAL $gSQLMaxRows,$gSQLBlockRows,$ADODB_ROUND; @@ -17,14 +32,6 @@ $ADODB_ROUND=4; // rounding $gSQLMaxRows = 1000; // max no of rows to download $gSQLBlockRows=20; // max no of rows per table block -// RecordSet to HTML Table -//------------------------------------------------------------ -// Convert a recordset to a html table. Multiple tables are generated -// if the number of rows is > $gSQLBlockRows. This is because -// web browsers normally require the whole table to be downloaded -// before it can be rendered, so we break the output into several -// smaller faster rendering tables. -// // $rs: the recordset // $ztabhtml: the table tag attributes (optional) // $zheaderarray: contains the replacement strings for the headers (optional) diff --git a/libraries/adodb/xmlschema03.dtd b/libraries/adodb/xmlschema03.dtd index 97850bc7f..351ea44b1 100644 --- a/libraries/adodb/xmlschema03.dtd +++ b/libraries/adodb/xmlschema03.dtd @@ -1,17 +1,22 @@ -<?xml version="1.0"?> -<!DOCTYPE adodb_schema [ <!ELEMENT schema (table*, sql*)> <!ATTLIST schema version CDATA #REQUIRED> <!ELEMENT table (descr?, (field+|DROP), constraint*, opt*, index*, data*)> -<!ATTLIST table name CDATA #REQUIRED platform CDATA #IMPLIED version CDATA #IMPLIED> +<!ATTLIST table + name CDATA #REQUIRED + platform CDATA #IMPLIED + version CDATA #IMPLIED> <!ELEMENT field (descr?, (NOTNULL|KEY|PRIMARY)?, (AUTO|AUTOINCREMENT)?, (DEFAULT|DEFDATE|DEFTIMESTAMP)?, NOQUOTE?, UNSIGNED?, constraint*, opt*)> -<!ATTLIST field name CDATA #REQUIRED type (C|C2|X|X2|B|D|T|L|I|F|N) #REQUIRED size CDATA #IMPLIED opts CDATA #IMPLIED> +<!ATTLIST + field name CDATA #REQUIRED + type (C|C2|X|X2|XL|B|D|T|L|I|I1|I2|I4|I8|F|N) #REQUIRED + size CDATA #IMPLIED + opts CDATA #IMPLIED> <!ELEMENT data (descr?, row+)> <!ATTLIST data platform CDATA #IMPLIED> <!ELEMENT row (f+)> -<!ELEMENT f (#CDATA)> +<!ELEMENT f (#PCDATA)> <!ATTLIST f name CDATA #IMPLIED> -<!ELEMENT descr (#CDATA)> +<!ELEMENT descr (#PCDATA)> <!ELEMENT NOTNULL EMPTY> <!ELEMENT KEY EMPTY> <!ELEMENT PRIMARY EMPTY> @@ -24,20 +29,25 @@ <!ELEMENT NOQUOTE EMPTY> <!ELEMENT UNSIGNED EMPTY> <!ELEMENT DROP EMPTY> -<!ELEMENT constraint (#CDATA)> +<!ELEMENT constraint (#PCDATA)> <!ATTLIST constraint platform CDATA #IMPLIED> -<!ELEMENT opt (#CDATA)> +<!ELEMENT opt (#PCDATA)> <!ATTLIST opt platform CDATA #IMPLIED> <!ELEMENT index ((col+|DROP), CLUSTERED?, BITMAP?, UNIQUE?, FULLTEXT?, HASH?, descr?)> -<!ATTLIST index name CDATA #REQUIRED platform CDATA #IMPLIED> -<!ELEMENT col (#CDATA)> +<!ATTLIST index + name CDATA #REQUIRED + platform CDATA #IMPLIED> +<!ELEMENT col (#PCDATA)> <!ELEMENT CLUSTERED EMPTY> <!ELEMENT BITMAP EMPTY> <!ELEMENT UNIQUE EMPTY> <!ELEMENT FULLTEXT EMPTY> <!ELEMENT HASH EMPTY> <!ELEMENT sql (query+, descr?)> -<!ATTLIST sql name CDATA #IMPLIED platform CDATA #IMPLIED, key CDATA, prefixmethod (AUTO|MANUAL|NONE)> -<!ELEMENT query (#CDATA)> +<!ATTLIST sql + name CDATA #IMPLIED + platform CDATA #IMPLIED + key CDATA #IMPLIED + prefixmethod (AUTO|MANUAL|NONE) #IMPLIED> +<!ELEMENT query (#PCDATA)> <!ATTLIST query platform CDATA #IMPLIED> -]> \ No newline at end of file -- GitLab