home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / adodb-csv.inc.php < prev    next >
Encoding:
PHP Script  |  2004-03-20  |  4.7 KB  |  200 lines

  1. <?php
  2. /*
  3. V4.21 20 Mar 2004  (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
  4.   Released under both BSD license and Lesser GPL library license. 
  5.   Whenever there is any discrepancy between the two licenses, 
  6.   the BSD license will take precedence.
  7.   Set tabs to 4.
  8.   
  9.   Currently unsupported: MetaDatabases, MetaTables and MetaColumns, and also inputarr in Execute.
  10.   Native types have been converted to MetaTypes.
  11.   Transactions not supported yet.
  12. */ 
  13.  
  14. if (! defined("_ADODB_CSV_LAYER")) {
  15.  define("_ADODB_CSV_LAYER", 1 );
  16.  
  17. include_once(ADODB_DIR.'/adodb-csvlib.inc.php');
  18.  
  19. class ADODB_csv extends ADOConnection {
  20.     var $databaseType = 'csv';
  21.     var $databaseProvider = 'csv';
  22.     var $hasInsertID = true;
  23.     var $hasAffectedRows = true;    
  24.     var $fmtTimeStamp = "'Y-m-d H:i:s'";
  25.     var $_affectedrows=0;
  26.     var $_insertid=0;
  27.     var $_url;
  28.     var $replaceQuote = "''"; // string to use to replace quotes
  29.     var $hasTransactions = false;
  30.     var $_errorNo = false;
  31.     
  32.     function ADODB_csv() 
  33.     {        
  34.     }
  35.     
  36.     function _insertid()
  37.     {
  38.             return $this->_insertid;
  39.     }
  40.     
  41.     function _affectedrows()
  42.     {
  43.             return $this->_affectedrows;
  44.     }
  45.   
  46.       function &MetaDatabases()
  47.     {
  48.         return false;
  49.     }
  50.  
  51.     
  52.     // returns true or false
  53.     function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
  54.     {
  55.         if (strtolower(substr($argHostname,0,7)) !== 'http://') return false;
  56.         $this->_url = $argHostname;
  57.         return true;    
  58.     }
  59.     
  60.     // returns true or false
  61.     function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
  62.     {
  63.         if (strtolower(substr($argHostname,0,7)) !== 'http://') return false;
  64.         $this->_url = $argHostname;
  65.         return true;
  66.     }
  67.     
  68.      function &MetaColumns($table) 
  69.     {
  70.         return false;
  71.     }
  72.         
  73.         
  74.     // parameters use PostgreSQL convention, not MySQL
  75.     function &SelectLimit($sql,$nrows=-1,$offset=-1)
  76.     {
  77.     global $ADODB_FETCH_MODE;
  78.     
  79.         $url = $this->_url.'?sql='.urlencode($sql)."&nrows=$nrows&fetch=".
  80.             (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE).
  81.             "&offset=$offset";
  82.         $err = false;
  83.         $rs = csv2rs($url,$err,false);
  84.         
  85.         if ($this->debug) print "$url<br><i>$err</i><br>";
  86.  
  87.         $at = strpos($err,'::::');
  88.         if ($at === false) {
  89.             $this->_errorMsg = $err;
  90.             $this->_errorNo = (integer)$err;
  91.         } else {
  92.             $this->_errorMsg = substr($err,$at+4,1024);
  93.             $this->_errorNo = -9999;
  94.         }
  95.         if ($this->_errorNo) 
  96.             if ($fn = $this->raiseErrorFn) {
  97.                 $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,'');
  98.             }
  99.             
  100.         if (is_object($rs)) {    
  101.         
  102.             $rs->databaseType='csv';        
  103.             $rs->fetchMode = ($this->fetchMode !== false) ?  $this->fetchMode : $ADODB_FETCH_MODE;
  104.             $rs->connection = &$this;
  105.         }
  106.         return $rs;
  107.     }
  108.     
  109.     // returns queryID or false
  110.     function &_Execute($sql,$inputarr=false)
  111.     {
  112.     global $ADODB_FETCH_MODE;
  113.     
  114.         if (!$this->_bindInputArray && $inputarr) {
  115.             $sqlarr = explode('?',$sql);
  116.             $sql = '';
  117.             $i = 0;
  118.             foreach($inputarr as $v) {
  119.  
  120.                 $sql .= $sqlarr[$i];
  121.                 if (gettype($v) == 'string')
  122.                     $sql .= $this->qstr($v);
  123.                 else if ($v === null)
  124.                     $sql .= 'NULL';
  125.                 else
  126.                     $sql .= $v;
  127.                 $i += 1;
  128.     
  129.             }
  130.             $sql .= $sqlarr[$i];
  131.             if ($i+1 != sizeof($sqlarr))    
  132.                 print "Input Array does not match ?: ".htmlspecialchars($sql);
  133.             $inputarr = false;
  134.         }
  135.         
  136.         $url =  $this->_url.'?sql='.urlencode($sql)."&fetch=".
  137.             (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE);
  138.         $err = false;
  139.         
  140.         
  141.         $rs = csv2rs($url,$err,false);
  142.         if ($this->debug) print urldecode($url)."<br><i>$err</i><br>";
  143.         $at = strpos($err,'::::');
  144.         if ($at === false) {        
  145.             $this->_errorMsg = $err;
  146.             $this->_errorNo = (integer)$err;
  147.         } else {
  148.             $this->_errorMsg = substr($err,$at+4,1024);
  149.             $this->_errorNo = -9999;
  150.         }
  151.         
  152.         if ($this->_errorNo) 
  153.             if ($fn = $this->raiseErrorFn) {
  154.                 $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr);
  155.             }
  156.         if (is_object($rs)) {
  157.             $rs->fetchMode = ($this->fetchMode !== false) ?  $this->fetchMode : $ADODB_FETCH_MODE;
  158.             
  159.             $this->_affectedrows = $rs->affectedrows;
  160.             $this->_insertid = $rs->insertid;
  161.             $rs->databaseType='csv';
  162.             $rs->connection = &$this;
  163.         }
  164.         return $rs;
  165.     }
  166.  
  167.     /*    Returns: the last error message from previous database operation    */    
  168.     function ErrorMsg() 
  169.     {
  170.             return $this->_errorMsg;
  171.     }
  172.     
  173.     /*    Returns: the last error number from previous database operation    */    
  174.     function ErrorNo() 
  175.     {
  176.         return $this->_errorNo;
  177.     }
  178.     
  179.     // returns true or false
  180.     function _close()
  181.     {
  182.         return true;
  183.     }
  184. } // class
  185.  
  186. class ADORecordset_csv extends ADORecordset {
  187.     function ADORecordset_csv($id,$mode=false)
  188.     {
  189.         $this->ADORecordset($id,$mode);
  190.     }
  191.     
  192.     function _close()
  193.     {
  194.         return true;
  195.     }
  196. }
  197.  
  198. } // define
  199.     
  200. ?>