Skip to content
Snippets Groups Projects
Commit 9ab4fc9d authored by Satish's avatar Satish
Browse files

Adodb library updated to 5.20

parent 0422271e
No related branches found
No related tags found
No related merge requests found
Showing
with 5571 additions and 2216 deletions
This diff is collapsed.
ADOdb Library for PHP5
======================
[![Join chat on Gitter](https://img.shields.io/gitter/room/form-data/form-data.svg)](https://gitter.im/adodb/adodb?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Download ADOdb](https://img.shields.io/sourceforge/dm/adodb.svg)](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;
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).
Introduction
============
PHP's database access functions are not standardized. This creates a
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,
Sybase SQL Anywhere, generic ODBC and Microsoft's ADO.
We hope more people will contribute drivers to support other databases.
Installation
============
Unpack all the files into a directory accessible by your web server.
To test, try modifying some of the tutorial examples.
Make sure you customize the connection settings correctly.
You can debug using:
``` php
<?php
include('adodb/adodb.inc.php');
$db = ADONewConnection($driver); # eg. 'mysql' or 'oci8'
$db->debug = true;
$db->Connect($server, $user, $password, $database);
$rs = $db->Execute('select * from some_small_table');
print "<pre>";
print_r($rs->GetRows());
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/).
- [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).
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.
Files
=====
- `adodb.inc.php` is the library's main file. You only need to include this file.
- `adodb-*.inc.php` are the database specific driver code.
- `adodb-session.php` is the PHP4 session handling code.
- `test.php` contains a list of test commands to exercise the class library.
- `testdatabases.inc.php` contains the list of databases to apply the tests on.
- `Benchmark.php` is a simple benchmark to test the throughput of a SELECT
statement for databases described in testdatabases.inc.php. The benchmark
tables are created in test.php.
Support
=======
To discuss with the ADOdb development team and users, connect to our
[Gitter chatroom](https://gitter.im/adodb/adodb) using your Github credentials.
Please report bugs, issues and feature requests on Github:
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
only be used as reference.
This diff is collapsed.
This diff is collapsed.
......@@ -6,19 +6,21 @@ if (!defined('ADODB_DIR')) die();
global $ADODB_INCLUDED_CSV;
$ADODB_INCLUDED_CSV = 1;
/*
/*
V4.90 8 June 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). 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. See License.txt.
@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.
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
==============
......@@ -34,63 +36,64 @@ $ADODB_INCLUDED_CSV = 1;
function _rs2serialize(&$rs,$conn=false,$sql='')
{
$max = ($rs) ? $rs->FieldCount() : 0;
if ($sql) $sql = urlencode($sql);
// metadata setup
if ($max <= 0 || $rs->dataProvider == 'empty') { // is insert/update/delete
if (is_object($conn)) {
$sql .= ','.$conn->Affected_Rows();
$sql .= ','.$conn->Insert_ID();
} else
$sql .= ',,';
$text = "====-1,0,$sql\n";
return $text;
}
$tt = ($rs->timeCreated) ? $rs->timeCreated : time();
## changed format from ====0 to ====1
$line = "====1,$tt,$sql\n";
if ($rs->databaseType == 'array') {
$rows =& $rs->_array;
$rows = $rs->_array;
} else {
$rows = array();
while (!$rs->EOF) {
while (!$rs->EOF) {
$rows[] = $rs->fields;
$rs->MoveNext();
}
}
}
for($i=0; $i < $max; $i++) {
$o =& $rs->FetchField($i);
$o = $rs->FetchField($i);
$flds[] = $o;
}
$savefetch = isset($rs->adodbFetchMode) ? $rs->adodbFetchMode : $rs->fetchMode;
$class = $rs->connection->arrayClass;
$rs2 = new $class();
$rs2->timeCreated = $rs->timeCreated; # memcache fix
$rs2->sql = $rs->sql;
$rs2->oldProvider = $rs->dataProvider;
$rs2->oldProvider = $rs->dataProvider;
$rs2->InitArrayFields($rows,$flds);
$rs2->fetchMode = $savefetch;
return $line.serialize($rs2);
}
/**
* Open CSV file and convert it into Data.
* Open CSV file and convert it into Data.
*
* @param url file/ftp/http url
* @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
* error occurred in sql INSERT/UPDATE/DELETE,
* error occurred in sql INSERT/UPDATE/DELETE,
* empty recordset is returned
*/
function &csv2rs($url,&$err,$timeout=0, $rsclass='ADORecordSet_array')
function csv2rs($url,&$err,$timeout=0, $rsclass='ADORecordSet_array')
{
$false = false;
$err = false;
......@@ -102,7 +105,7 @@ $ADODB_INCLUDED_CSV = 1;
@flock($fp, LOCK_SH);
$arr = array();
$ttl = 0;
if ($meta = fgetcsv($fp, 32000, ",")) {
// check if error message
if (strncmp($meta[0],'****',4) === 0) {
......@@ -112,10 +115,10 @@ $ADODB_INCLUDED_CSV = 1;
}
// check for meta data
// $meta[0] is -1 means return an empty recordset
// $meta[1] contains a time
// $meta[1] contains a time
if (strncmp($meta[0], '====',4) === 0) {
if ($meta[0] == "====-1") {
if (sizeof($meta) < 5) {
$err = "Corrupt first line for format -1";
......@@ -123,12 +126,12 @@ $ADODB_INCLUDED_CSV = 1;
return $false;
}
fclose($fp);
if ($timeout > 0) {
$err = " Illegal Timeout $timeout ";
return $false;
}
$rs = new $rsclass($val=true);
$rs->fields = array();
$rs->timeCreated = $meta[1];
......@@ -136,9 +139,9 @@ $ADODB_INCLUDED_CSV = 1;
$rs->_numOfFields = 0;
$rs->sql = urldecode($meta[2]);
$rs->affectedrows = (integer)$meta[3];
$rs->insertid = $meta[4];
$rs->insertid = $meta[4];
return $rs;
}
}
# Under high volume loads, we want only 1 thread/process to _write_file
# so that we don't have 50 processes queueing to write the same data.
# We use probabilistic timeout, ahead of time.
......@@ -148,7 +151,7 @@ $ADODB_INCLUDED_CSV = 1;
# -1 sec after timeout give processes 1/4 chance of timing out
# +0 sec after timeout, give processes 100% chance of timing out
if (sizeof($meta) > 1) {
if($timeout >0){
if($timeout >0){
$tdiff = (integer)( $meta[1]+$timeout - time());
if ($tdiff <= 2) {
switch($tdiff) {
......@@ -160,7 +163,7 @@ $ADODB_INCLUDED_CSV = 1;
return $false;
}
break;
case 2:
case 2:
if ((rand() & 15) == 0) {
fclose($fp);
$err = "Timeout 2";
......@@ -174,12 +177,12 @@ $ADODB_INCLUDED_CSV = 1;
return $false;
}
break;
default:
default:
fclose($fp);
$err = "Timeout 0";
return $false;
} // switch
} // if check flush cache
}// (timeout>0)
$ttl = $meta[1];
......@@ -189,7 +192,7 @@ $ADODB_INCLUDED_CSV = 1;
if ($meta[0] === '====1') {
// slurp in the data
$MAXSIZE = 128000;
$text = fread($fp,$MAXSIZE);
if (strlen($text)) {
while ($txt = fread($fp,$MAXSIZE)) {
......@@ -205,7 +208,7 @@ $ADODB_INCLUDED_CSV = 1;
}
return $rs;
}
$meta = false;
$meta = fgetcsv($fp, 32000, ",");
if (!$meta) {
......@@ -235,15 +238,15 @@ $ADODB_INCLUDED_CSV = 1;
$err = "Recordset had unexpected EOF 2";
return $false;
}
// slurp in the data
$MAXSIZE = 128000;
$text = '';
while ($txt = fread($fp,$MAXSIZE)) {
$text .= $txt;
}
fclose($fp);
@$arr = unserialize($text);
//var_dump($arr);
......@@ -257,17 +260,18 @@ $ADODB_INCLUDED_CSV = 1;
$rs->InitArrayFields($arr,$flds);
return $rs;
}
/**
* Save a file $filename and its $contents (normally for caching) with file locking
* Returns true if ok, false if fopen/fwrite error, 0 if rename error (eg. file is locked)
*/
function adodb_write_file($filename, $contents,$debug=false)
{
{
# http://www.php.net/bugs.php?id=9203 Bug that flock fails on Windows
# So to simulate locking, we assume that rename is an atomic operation.
# First we delete $filename, then we create a $tempfile write to it and
# rename to the desired $filename. If the rename works, then we successfully
# First we delete $filename, then we create a $tempfile write to it and
# rename to the desired $filename. If the rename works, then we successfully
# modified the file exclusively.
# What a stupid need - having to simulate locking.
# Risks:
......@@ -277,36 +281,39 @@ $ADODB_INCLUDED_CSV = 1;
# 4. another process creates $filename between unlink() and rename() -- ok, rename() fails and cache updated
if (strncmp(PHP_OS,'WIN',3) === 0) {
// skip the decimal place
$mtime = substr(str_replace(' ','_',microtime()),2);
$mtime = substr(str_replace(' ','_',microtime()),2);
// getmypid() actually returns 0 on Win98 - never mind!
$tmpname = $filename.uniqid($mtime).getmypid();
if (!($fd = @fopen($tmpname,'a'))) return false;
$ok = ftruncate($fd,0);
if (!fwrite($fd,$contents)) $ok = false;
if (!($fd = @fopen($tmpname,'w'))) return false;
if (fwrite($fd,$contents)) $ok = true;
else $ok = false;
fclose($fd);
chmod($tmpname,0644);
// the tricky moment
@unlink($filename);
if (!@rename($tmpname,$filename)) {
unlink($tmpname);
$ok = false;
}
if (!$ok) {
if ($debug) ADOConnection::outp( " Rename $tmpname ".($ok? 'ok' : 'failed'));
if ($ok) {
@chmod($tmpname,0644);
// the tricky moment
@unlink($filename);
if (!@rename($tmpname,$filename)) {
@unlink($tmpname);
$ok = 0;
}
if (!$ok) {
if ($debug) ADOConnection::outp( " Rename $tmpname ".($ok? 'ok' : 'failed'));
}
}
return $ok;
}
if (!($fd = @fopen($filename, 'a'))) return false;
if (flock($fd, LOCK_EX) && ftruncate($fd, 0)) {
$ok = fwrite( $fd, $contents );
if (fwrite( $fd, $contents )) $ok = true;
else $ok = false;
fclose($fd);
chmod($filename,0644);
@chmod($filename,0644);
}else {
fclose($fd);
if ($debug)ADOConnection::outp( " Failed acquiring lock for $filename<br>\n");
$ok = false;
}
return $ok;
}
?>
\ No newline at end of file
This diff is collapsed.
<?php
/**
* @version V4.90 8 June 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). 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.
/**
* @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.
*
*
* The following code is adapted from the PEAR DB error handling code.
* Portions (c)1997-2002 The PHP Group.
*/
......@@ -41,6 +43,9 @@ if (!defined("DB_ERROR_SYNTAX")) {
define("DB_ERROR_EXTENSION_NOT_FOUND",-25);
define("DB_ERROR_NOSUCHDB", -25);
define("DB_ERROR_ACCESS_VIOLATION", -26);
define("DB_ERROR_DEADLOCK", -27);
define("DB_ERROR_STATEMENT_TIMEOUT", -28);
define("DB_ERROR_SERIALIZATION_FAILURE", -29);
}
function adodb_errormsg($value)
......@@ -59,27 +64,27 @@ function adodb_error($provider,$dbType,$errno)
{
//var_dump($errno);
if (is_numeric($errno) && $errno == 0) return 0;
switch($provider) {
switch($provider) {
case 'mysql': $map = adodb_error_mysql(); break;
case 'oracle':
case 'oci8': $map = adodb_error_oci8(); break;
case 'ibase': $map = adodb_error_ibase(); break;
case 'odbc': $map = adodb_error_odbc(); break;
case 'mssql':
case 'sybase': $map = adodb_error_mssql(); break;
case 'informix': $map = adodb_error_ifx(); break;
case 'postgres': return adodb_error_pg($errno); break;
case 'sqlite': return $map = adodb_error_sqlite(); break;
default:
return DB_ERROR;
}
}
//print_r($map);
//var_dump($errno);
if (isset($map[$errno])) return $map[$errno];
......@@ -91,27 +96,30 @@ function adodb_error($provider,$dbType,$errno)
function adodb_error_pg($errormsg)
{
if (is_numeric($errormsg)) return (integer) $errormsg;
static $error_regexps = array(
'/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/' => DB_ERROR_NOSUCHTABLE,
'/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/' => DB_ERROR_ALREADY_EXISTS,
'/divide by zero$/' => DB_ERROR_DIVZERO,
'/pg_atoi: error in .*: can\'t parse /' => DB_ERROR_INVALID_NUMBER,
'/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => DB_ERROR_NOSUCHFIELD,
'/parser: parse error at or near \"/' => DB_ERROR_SYNTAX,
'/referential integrity violation/' => DB_ERROR_CONSTRAINT,
'/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key violates unique constraint/'
=> DB_ERROR_ALREADY_EXISTS
);
// Postgres has no lock-wait timeout. The best we could do would be to set a statement timeout.
static $error_regexps = array(
'(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$' => DB_ERROR_NOSUCHTABLE,
'Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key.*violates unique constraint' => DB_ERROR_ALREADY_EXISTS,
'database ".+" does not exist$' => DB_ERROR_NOSUCHDB,
'(divide|division) by zero$' => DB_ERROR_DIVZERO,
'pg_atoi: error in .*: can\'t parse ' => DB_ERROR_INVALID_NUMBER,
'ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']' => DB_ERROR_NOSUCHFIELD,
'(parser: parse|syntax) error at or near \"' => DB_ERROR_SYNTAX,
'referential integrity violation' => DB_ERROR_CONSTRAINT,
'deadlock detected$' => DB_ERROR_DEADLOCK,
'canceling statement due to statement timeout$' => DB_ERROR_STATEMENT_TIMEOUT,
'could not serialize access due to' => DB_ERROR_SERIALIZATION_FAILURE
);
reset($error_regexps);
while (list($regexp,$code) = each($error_regexps)) {
if (preg_match($regexp, $errormsg)) {
return $code;
}
}
// Fall back to DB_ERROR if there was no mapping.
return DB_ERROR;
while (list($regexp,$code) = each($error_regexps)) {
if (preg_match("/$regexp/mi", $errormsg)) {
return $code;
}
}
// Fall back to DB_ERROR if there was no mapping.
return DB_ERROR;
}
function adodb_error_odbc()
{
static $MAP = array(
......@@ -169,7 +177,7 @@ static $MAP = array(
-923 => DB_ERROR_CONNECT_FAILED,
-924 => DB_ERROR_CONNECT_FAILED
);
return $MAP;
}
......@@ -187,7 +195,7 @@ static $MAP = array(
'-1210' => DB_ERROR_INVALID_DATE,
'-1212' => DB_ERROR_INVALID_DATE
);
return $MAP;
}
......@@ -206,7 +214,7 @@ static $MAP = array(
2291 => DB_ERROR_CONSTRAINT,
2449 => DB_ERROR_CONSTRAINT
);
return $MAP;
}
......@@ -216,7 +224,7 @@ static $MAP = array(
208 => DB_ERROR_NOSUCHTABLE,
2601 => DB_ERROR_ALREADY_EXISTS
);
return $MAP;
}
......@@ -225,7 +233,7 @@ function adodb_error_sqlite()
static $MAP = array(
1 => DB_ERROR_SYNTAX
);
return $MAP;
}
......@@ -252,7 +260,6 @@ static $MAP = array(
2002 => DB_ERROR_CONNECT_FAILED,
2005 => DB_ERROR_CONNECT_FAILED
);
return $MAP;
}
?>
\ No newline at end of file
<?php
/**
* @version V4.90 8 June 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
* @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.
......@@ -13,7 +15,7 @@
// added Claudio Bustos clbustos#entelchile.net
if (!defined('ADODB_ERROR_HANDLER_TYPE')) define('ADODB_ERROR_HANDLER_TYPE',E_USER_ERROR);
if (!defined('ADODB_ERROR_HANDLER_TYPE')) define('ADODB_ERROR_HANDLER_TYPE',E_USER_ERROR);
if (!defined('ADODB_ERROR_HANDLER')) define('ADODB_ERROR_HANDLER','ADODB_Error_Handler');
......@@ -74,6 +76,5 @@ function ADODB_Error_Handler($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnec
//print "<p>$s</p>";
trigger_error($s,ADODB_ERROR_HANDLER_TYPE);
trigger_error($s,ADODB_ERROR_HANDLER_TYPE);
}
?>
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php
/*
V4.90 8 June 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
@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 {
}
?>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment