diff options
Diffstat (limited to 'libraries/adodb/adodb-csvlib.inc.php')
| -rw-r--r-- | libraries/adodb/adodb-csvlib.inc.php | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/libraries/adodb/adodb-csvlib.inc.php b/libraries/adodb/adodb-csvlib.inc.php index 1e34d39e..1f7543f9 100644 --- a/libraries/adodb/adodb-csvlib.inc.php +++ b/libraries/adodb/adodb-csvlib.inc.php @@ -8,7 +8,7 @@ $ADODB_INCLUDED_CSV = 1; /* - V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. + V5.09 25 June 2009 (c) 2000-2009 John Lim (jlim#natsoft.com). 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. @@ -54,7 +54,7 @@ $ADODB_INCLUDED_CSV = 1; $line = "====1,$tt,$sql\n"; if ($rs->databaseType == 'array') { - $rows =& $rs->_array; + $rows = $rs->_array; } else { $rows = array(); while (!$rs->EOF) { @@ -64,7 +64,7 @@ $ADODB_INCLUDED_CSV = 1; } for($i=0; $i < $max; $i++) { - $o =& $rs->FetchField($i); + $o = $rs->FetchField($i); $flds[] = $o; } @@ -90,7 +90,7 @@ $ADODB_INCLUDED_CSV = 1; * 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; @@ -261,6 +261,7 @@ $ADODB_INCLUDED_CSV = 1; /** * 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) { @@ -280,27 +281,31 @@ $ADODB_INCLUDED_CSV = 1; $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"); |
