Documentation TYPO3 par Ameos

adodb-sqlanywhere.inc.php

00001 <?php
00002 /* 
00003 version V4.80 8 Mar 2006 (c) 2000-2006  John Lim (jlim@natsoft.com.my).  All rights
00004 reserved.
00005   Released under both BSD license and Lesser GPL library license. 
00006   Whenever there is any discrepancy between the two licenses, 
00007   the BSD license will take precedence. 
00008 Set tabs to 4 for best viewing.
00009 
00010   Latest version is available at http://adodb.sourceforge.net
00011 
00012   21.02.2002 - Wade Johnson wade@wadejohnson.de
00013                            Extended ODBC class for Sybase SQLAnywhere.
00014    1) Added support to retrieve the last row insert ID on tables with
00015           primary key column using autoincrement function.
00016 
00017    2) Added blob support.  Usage:
00018                  a) create blob variable on db server:
00019 
00020                 $dbconn->create_blobvar($blobVarName);
00021 
00022           b) load blob var from file.  $filename must be complete path
00023 
00024           $dbcon->load_blobvar_from_file($blobVarName, $filename);
00025 
00026           c) Use the $blobVarName in SQL insert or update statement in the values
00027           clause:
00028 
00029                 $recordSet = $dbconn->Execute('INSERT INTO tabname (idcol, blobcol) '
00030                 .
00031            'VALUES (\'test\', ' . $blobVarName . ')');
00032 
00033          instead of loading blob from a file, you can also load from 
00034           an unformatted (raw) blob variable:
00035           $dbcon->load_blobvar_from_var($blobVarName, $varName);
00036 
00037           d) drop blob variable on db server to free up resources:
00038           $dbconn->drop_blobvar($blobVarName);
00039 
00040   Sybase_SQLAnywhere data driver. Requires ODBC.
00041 
00042 */
00043 
00044 // security - hide paths
00045 if (!defined('ADODB_DIR')) die();
00046 
00047 if (!defined('_ADODB_ODBC_LAYER')) {
00048  include(ADODB_DIR."/drivers/adodb-odbc.inc.php");
00049 }
00050 
00051 if (!defined('ADODB_SYBASE_SQLANYWHERE')){
00052 
00053  define('ADODB_SYBASE_SQLANYWHERE',1);
00054 
00055  class ADODB_sqlanywhere extends ADODB_odbc {
00056         var $databaseType = "sqlanywhere";      
00057         var $hasInsertID = true;
00058         
00059         function ADODB_sqlanywhere()
00060         {
00061                 $this->ADODB_odbc();
00062         }
00063 
00064          function _insertid() {
00065            return $this->GetOne('select @@identity');
00066          }
00067 
00068   function create_blobvar($blobVarName) {
00069    $this->Execute("create variable $blobVarName long binary");
00070    return;
00071   }
00072 
00073   function drop_blobvar($blobVarName) {
00074    $this->Execute("drop variable $blobVarName");
00075    return;
00076   }
00077 
00078   function load_blobvar_from_file($blobVarName, $filename) {
00079    $chunk_size = 1000;
00080 
00081    $fd = fopen ($filename, "rb");
00082 
00083    $integer_chunks = (integer)filesize($filename) / $chunk_size;
00084    $modulus = filesize($filename) % $chunk_size;
00085    if ($modulus != 0){
00086         $integer_chunks += 1;
00087    }
00088 
00089    for($loop=1;$loop<=$integer_chunks;$loop++){
00090         $contents = fread ($fd, $chunk_size);
00091         $contents = bin2hex($contents);
00092 
00093         $hexstring = '';
00094 
00095         for($loop2=0;$loop2<strlen($contents);$loop2+=2){
00096          $hexstring .= '\x' . substr($contents,$loop2,2);
00097          }
00098 
00099         $hexstring = $this->qstr($hexstring);
00100 
00101         $this->Execute("set $blobVarName = $blobVarName || " . $hexstring);
00102    }
00103 
00104    fclose ($fd);
00105    return;
00106   }
00107 
00108   function load_blobvar_from_var($blobVarName, &$varName) {
00109    $chunk_size = 1000;
00110 
00111    $integer_chunks = (integer)strlen($varName) / $chunk_size;
00112    $modulus = strlen($varName) % $chunk_size;
00113    if ($modulus != 0){
00114         $integer_chunks += 1;
00115    }
00116 
00117    for($loop=1;$loop<=$integer_chunks;$loop++){
00118         $contents = substr ($varName, (($loop - 1) * $chunk_size), $chunk_size);
00119         $contents = bin2hex($contents);
00120 
00121         $hexstring = '';
00122 
00123         for($loop2=0;$loop2<strlen($contents);$loop2+=2){
00124          $hexstring .= '\x' . substr($contents,$loop2,2);
00125          }
00126 
00127         $hexstring = $this->qstr($hexstring);
00128 
00129         $this->Execute("set $blobVarName = $blobVarName || " . $hexstring);
00130    }
00131 
00132    return;
00133   }
00134 
00135  /*
00136   Insert a null into the blob field of the table first.
00137   Then use UpdateBlob to store the blob.
00138 
00139   Usage:
00140 
00141   $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
00142   $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');
00143  */
00144   function UpdateBlob($table,$column,&$val,$where,$blobtype='BLOB')
00145   {
00146    $blobVarName = 'hold_blob';
00147    $this->create_blobvar($blobVarName);
00148    $this->load_blobvar_from_var($blobVarName, $val);
00149    $this->Execute("UPDATE $table SET $column=$blobVarName WHERE $where");
00150    $this->drop_blobvar($blobVarName);
00151    return true;
00152   }
00153  }; //class
00154 
00155  class  ADORecordSet_sqlanywhere extends ADORecordSet_odbc {    
00156 
00157   var $databaseType = "sqlanywhere";            
00158 
00159  function ADORecordSet_sqlanywhere($id,$mode=false)
00160  {
00161   $this->ADORecordSet_odbc($id,$mode);
00162  }
00163 
00164 
00165  }; //class
00166 
00167 
00168 } //define
00169 ?>


Généré par Les experts TYPO3 avec  doxygen 1.4.6