[ Index ]
 

Code source de CMS made simple 1.0.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/adodb_lite/adodbSQL_drivers/sqlite/ -> sqlite_extend_module.inc (source)

   1  <?php
   2  /**

   3   * ADOdb Lite Extend Module for Mysqlt

   4   * 

   5   */
   6  
   7  eval('class sqlite_extend_EXTENDER extends '. $last_module . '_ADOConnection { }');
   8  
   9  class sqlite_extend_ADOConnection extends sqlite_extend_EXTENDER
  10  {
  11      function &GetAssoc($sql, $inputarr=false, $force_array = false, $first2cols = false)
  12      {
  13          $data = false;
  14          $result =& $this->Execute($sql, $inputarr);
  15          if ($result) {
  16              $data =& $result->GetAssoc($force_array, $first2cols);
  17              $result->Close();
  18          }
  19          return $data;
  20      }
  21  
  22      /**

  23       * Generates a sequence id and stores it in $this->genID;

  24       * GenID is only available if $this->hasGenID = true;

  25       *

  26       * @param seqname        name of sequence to use

  27       * @param startID        if sequence does not exist, start at this ID

  28       * @return        0 if not supported, otherwise a sequence id

  29       */
  30  
  31      var $_genSeqSQL = "create table %s (id integer)";
  32      var $_dropSeqSQL = 'drop table %s';
  33      var $genID = 0;
  34  
  35  	function GenID($seqname='adodbseq', $startID=1)
  36      {
  37          $MAXLOOPS = 100;
  38          while (--$MAXLOOPS>=0) {
  39              @($num = $this->GetOne("select id from $seq"));
  40              if ($num === false) {
  41                  $this->Execute(sprintf($this->_genSeqSQL, $seq));    
  42                  $start -= 1;
  43                  $num = '0';
  44                  $result = $this->Execute("insert into $seq values($start)");
  45                  if (!$result)
  46                      return false;
  47              }
  48              $this->Execute("update $seq set id=id+1 where id=$num");
  49  
  50              if ($this->affected_rows() > 0) {
  51                  $num += 1;
  52                  $this->genID = $num;
  53                  return $num;
  54              }
  55          }
  56          if ($fn = $this->raiseErrorFn) {
  57              $fn($this->databaseType, 'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts", $seq, $num);
  58          }
  59          return false;
  60      }
  61  
  62  	function CreateSequence($seqname='adodbseq', $start=1)
  63      {
  64          $ok = $this->Execute(sprintf($this->_genSeqSQL, $seqname));
  65          if (!$ok)
  66              return false;
  67          $start -= 1;
  68          return $this->Execute("insert into $seqname values($start)");
  69      }
  70  
  71  	function DropSequence($seqname)
  72      {
  73          return $this->Execute(sprintf($this->_dropSeqSQL, $seqname));
  74      }
  75  
  76  }
  77  
  78  eval('class sqlite_extend_resultset_EXTENDER extends '. $last_module . '_ResultSet { }');
  79  
  80  class sqlite_extend_ResultSet extends sqlite_extend_resultset_EXTENDER
  81  {
  82      function &GetAssoc($force_array = false, $first2cols = false) 
  83      {
  84          $results = false;
  85          
  86          if ($this->_numOfFields > 1) {
  87              $numIndex = isset($this->fields[0]);
  88              $results = array();
  89              if (!$first2cols && ($this->_numOfFields > 2 || $force_array)) {
  90                  if ($numIndex) {
  91                      while (!$this->EOF) {
  92                          $results[trim($this->fields[0])] = array_slice($this->fields, 1);
  93                          $this->MoveNext();
  94                      }
  95                  } else {
  96                      while (!$this->EOF) {
  97                          $results[trim(reset($this->fields))] = array_slice($this->fields, 1);
  98                          $this->MoveNext();
  99                      }
 100                  }
 101              } else {
 102                  if ($numIndex) {
 103                      while (!$this->EOF) {
 104                          $results[trim(($this->fields[0]))] = $this->fields[1];
 105                          $this->MoveNext();
 106                      }
 107                  } else {
 108                      while (!$this->EOF) {
 109                          $v1 = trim(reset($this->fields));
 110                          $v2 = ''.next($this->fields); 
 111                          $results[$v1] = $v2;
 112                          $this->MoveNext();
 113                      }
 114                  }
 115              }
 116          }
 117          return $results; 
 118      }
 119  
 120  	function PO_RecordCount($table="", $condition="")
 121      {
 122          $lnumrows = $this->_numOfRows;
 123          if($lnumrows == -1 && $this->connectionId)
 124          {
 125              if($table)
 126              {
 127                  if ($condition)
 128                      $condition = " WHERE " . $condition; 
 129                  $resultrows = &$this->connectionId->Execute("SELECT COUNT(*) FROM $table $condition");
 130                  if ($resultrows)
 131                      $lnumrows = reset($resultrows->fields);
 132              }
 133          }
 134          return $lnumrows;
 135      }
 136  
 137  	function CurrentRow()
 138      {
 139          return $this->_currentRow;
 140      }
 141  
 142  	function AbsolutePosition()
 143      {
 144          return $this->_currentRow;
 145      }
 146  
 147  	function NextRecordSet()
 148      {
 149          return false;
 150      }
 151  
 152  }
 153  ?>


Généré le : Tue Apr 3 18:50:37 2007 par Balluche grâce à PHPXref 0.7