Skip to content

Commit

Permalink
Upgraded to ADOdb 4.5.1. Contains a lot of small fixes and speed-ups.
Browse files Browse the repository at this point in the history
  • Loading branch information
moodler committed Aug 7, 2004
1 parent f5f346a commit fab7e07
Show file tree
Hide file tree
Showing 90 changed files with 1,550 additions and 827 deletions.
54 changes: 53 additions & 1 deletion lib/adodb/adodb-csvlib.inc.php
Expand Up @@ -7,7 +7,7 @@
$ADODB_INCLUDED_CSV = 1;

/*
V4.50 6 July 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.51 29 July 2004 (c) 2000-2004 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.
Expand Down Expand Up @@ -249,4 +249,56 @@ function &csv2rs($url,&$err,$timeout=0)
$rs->InitArrayFields($arr,$flds);
return $rs;
}


/**
* Save a file $filename and its $contents (normally for caching) with file locking
*/
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
# modified the file exclusively.
# What a stupid need - having to simulate locking.
# Risks:
# 1. $tempfile name is not unique -- very very low
# 2. unlink($filename) fails -- ok, rename will fail
# 3. adodb reads stale file because unlink fails -- ok, $rs timeout occurs
# 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);
// 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;
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'));
}
return $ok;
}
if (!($fd = fopen($filename, 'a'))) return false;
if (flock($fd, LOCK_EX) && ftruncate($fd, 0)) {
$ok = fwrite( $fd, $contents );
fclose($fd);
chmod($filename,0644);
}else {
fclose($fd);
if ($debug)ADOConnection::outp( " Failed acquiring lock for $filename<br>\n");
$ok = false;
}

return $ok;
}
?>
2 changes: 1 addition & 1 deletion lib/adodb/adodb-datadict.inc.php
@@ -1,7 +1,7 @@
<?php

/**
V4.50 6 July 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.51 29 July 2004 (c) 2000-2004 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.
Expand Down
2 changes: 1 addition & 1 deletion lib/adodb/adodb-errorhandler.inc.php
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.50 6 July 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
* @version V4.51 29 July 2004 (c) 2000-2004 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.
Expand Down
2 changes: 1 addition & 1 deletion lib/adodb/adodb-exceptions.inc.php
@@ -1,7 +1,7 @@
<?php

/**
* @version V4.50 6 July 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
* @version V4.51 29 July 2004 (c) 2000-2004 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.
Expand Down
17 changes: 8 additions & 9 deletions lib/adodb/adodb-iterator.inc.php
@@ -1,7 +1,7 @@
<?php

/*
V4.50 6 July 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.51 29 July 2004 (c) 2000-2004 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.
Expand Down Expand Up @@ -58,14 +58,7 @@ function __call($func, $params)
{
return call_user_func_array(array($this->rs, $func), $params);
}

function __toString()
{
if (isset($rs->databaseType)) $s = ' for '.$rs->databaseType;
else $s = '';

return 'ADODB Iterator'.$s;
}


function hasMore()
{
Expand All @@ -79,6 +72,12 @@ class ADODB_BASE_RS implements IteratorAggregate {
function getIterator() {
return new ADODB_Iterator($this);
}

function __toString()
{
include_once(ADODB_DIR.'/toexport.inc.php');
return _adodb_export($this,',',',',false,true);
}
}

?>

0 comments on commit fab7e07

Please sign in to comment.