class.tx_dbal_sqlengine.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2009-2010 Xavier Perseguers <typo3@perseguers.ch>
00006 *  (c) 2004-2009 Kasper Skårhøj <kasperYYYY@typo3.com>
00007 *  All rights reserved
00008 *
00009 *  This script is part of the TYPO3 project. The TYPO3 project is
00010 *  free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  The GNU General Public License can be found at
00016 *  http://www.gnu.org/copyleft/gpl.html.
00017 *  A copy is found in the textfile GPL.txt and important notices to the license
00018 *  from the author is found in LICENSE.txt distributed with these scripts.
00019 *
00020 *
00021 *  This script is distributed in the hope that it will be useful,
00022 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024 *  GNU General Public License for more details.
00025 *
00026 *  This copyright notice MUST APPEAR in all copies of the script!
00027 ***************************************************************/
00028 
00029 
00030 /**
00031  * PHP SQL engine
00032  *
00033  * $Id: class.tx_dbal_sqlengine.php 35523 2010-07-11 14:04:44Z xperseguers $
00034  *
00035  * @author Kasper Skårhøj <kasperYYYY@typo3.com>
00036  * @author Xavier Perseguers <typo3@perseguers.ch>
00037  */
00038 /**
00039  * [CLASS/FUNCTION INDEX of SCRIPT]
00040  *
00041  *
00042  *
00043  *  104: class tx_dbal_sqlengine extends ux_t3lib_sqlparser
00044  *  126:     function init($config, &$pObj)
00045  *  134:     function resetStatusVars()
00046  *  150:     function processAccordingToConfig(&$value,$fInfo)
00047  *
00048  *              SECTION: SQL queries
00049  *  205:     function exec_INSERTquery($table,$fields_values)
00050  *  273:     function exec_UPDATEquery($table,$where,$fields_values)
00051  *  332:     function exec_DELETEquery($table,$where)
00052  *  383:     function exec_SELECTquery($select_fields,$from_table,$where_clause,$groupBy,$orderBy,$limit)
00053  *  426:     function sql_query($query)
00054  *  437:     function sql_error()
00055  *  446:     function sql_insert_id()
00056  *  455:     function sql_affected_rows()
00057  *  465:     function quoteStr($str)
00058  *
00059  *              SECTION: SQL admin functions
00060  *  490:     function admin_get_tables()
00061  *  501:     function admin_get_fields($tableName)
00062  *  512:     function admin_get_keys($tableName)
00063  *  523:     function admin_query($query)
00064  *
00065  *              SECTION: Data Source I/O
00066  *  548:     function readDataSource($table)
00067  *  560:     function saveDataSource($table)
00068  *
00069  *              SECTION: SQL engine functions (PHP simulation of SQL) - still experimental
00070  *  590:     function selectFromData($table,$where)
00071  *  628:     function select_evalSingle($table,$config,&$itemKeys)
00072  *  747:     function getResultSet($keys, $table, $fieldList)
00073  *
00074  *              SECTION: Debugging
00075  *  790:     function debug_printResultSet($array)
00076  *
00077  *
00078  *  829: class tx_dbal_sqlengine_resultobj
00079  *  843:     function sql_num_rows()
00080  *  852:     function sql_fetch_assoc()
00081  *  863:     function sql_fetch_row()
00082  *  881:     function sql_data_seek($pointer)
00083  *  894:     function sql_field_type()
00084  *
00085  * TOTAL FUNCTIONS: 27
00086  * (This index is automatically created/updated by the extension "extdeveval")
00087  *
00088  */
00089 
00090 
00091 
00092 
00093 
00094 
00095 
00096 
00097 /**
00098  * PHP SQL engine / server
00099  * Basically this is trying to emulation SQL record selection by PHP, thus allowing SQL queries into alternative data storages managed by PHP.
00100  * EXPERIMENTAL!
00101  *
00102  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00103  * @package TYPO3
00104  * @subpackage t3lib
00105  */
00106 class tx_dbal_sqlengine extends ux_t3lib_sqlparser {
00107 
00108         // array with data records: [table name][num.index] = records
00109     var $data = array();                        // Data source storage
00110 
00111 
00112         // Internal, SQL Status vars:
00113     var $errorStatus = '';                      // Set with error message of last operation
00114     var $lastInsertedId = 0;                    // Set with last inserted unique ID
00115     var $lastAffectedRows = 0;                  // Set with last number of affected rows.
00116 
00117 
00118 
00119 
00120 
00121     /**
00122      * Dummy function for initializing SQL handler. Create you own in derived classes.
00123      *
00124      * @param   array       Configuration array from handler
00125      * @param   object      Parent object
00126      * @return  void
00127      */
00128     public function init($config, $pObj) {
00129     }
00130 
00131     /**
00132      * Reset SQL engine status variables (insert id, affected rows, error status)
00133      *
00134      * @return  void
00135      */
00136     public function resetStatusVars() {
00137         $this->errorStatus = '';
00138         $this->lastInsertedId = 0;
00139         $this->lastAffectedRows = 0;
00140     }
00141 
00142     /**
00143      * Processing of update/insert values based on field type.
00144      *
00145      * The input value is typecast and trimmed/shortened according to the field
00146      * type and the configuration options from the $fInfo parameter.
00147      *
00148      * @param   mixed       $value The input value to process
00149      * @param   array       $fInfo Field configuration data
00150      * @return  mixed       The processed input value
00151      */
00152     private function processAccordingToConfig(&$value, $fInfo) {
00153         $options = $this->parseFieldDef($fInfo['Type']);
00154 
00155         switch(strtolower($options['fieldType']))   {
00156             case 'int':
00157             case 'smallint':
00158             case 'tinyint':
00159             case 'mediumint':
00160                 $value = intval($value);
00161                 if ($options['featureIndex']['UNSIGNED'])   {
00162                     $value = t3lib_div::intInRange($value,0);
00163                 }
00164             break;
00165             case 'double':
00166                 $value = (double)$value;
00167             break;
00168             case 'varchar':
00169             case 'char':
00170                 $value = substr($value,0,trim($options['value']));
00171             break;
00172             case 'text':
00173             case 'blob':
00174                 $value = substr($value,0,65536);
00175             break;
00176             case 'tinytext':
00177             case 'tinyblob':
00178                 $value = substr($value,0,256);
00179             break;
00180             case 'mediumtext':
00181             case 'mediumblob':
00182                 // ??
00183             break;
00184         }
00185     }
00186 
00187 
00188 
00189 
00190 
00191 
00192 
00193     /********************************
00194      *
00195      * SQL queries
00196      * This is the SQL access functions used when this class is instantiated as a SQL handler with DBAL. Override these in derived classes.
00197      *
00198      ********************************/
00199 
00200     /**
00201      * Execute an INSERT query
00202      *
00203      * @param   string      Table name
00204      * @param   array       Field values as key=>value pairs.
00205      * @return  boolean     TRUE on success and FALSE on failure (error is set internally)
00206      */
00207     public function exec_INSERTquery($table, $fields_values) {
00208 
00209             // Initialize
00210         $this->resetStatusVars();
00211 
00212             // Reading Data Source if not done already.
00213         $this->readDataSource($table);
00214 
00215             // If data source is set:
00216         if (is_array($this->data[$table]))  {
00217 
00218             $fieldInformation = $this->admin_get_fields($table);        // Should cache this...!
00219 
00220                 // Looking for unique keys:
00221             $saveArray = array();
00222             foreach($fieldInformation as $fInfo)    {
00223 
00224                     // Field name:
00225                 $fN = $fInfo['Field'];
00226 
00227                     // Set value:
00228 // FIXME $options not defined
00229                 $saveArray[$fN] = isset($fields_values[$fN]) ? $fields_values[$fN] : $options['Default'];
00230 
00231                     // Process value:
00232                 $this->processAccordingToConfig($saveArray[$fN], $fInfo);
00233 
00234                     // If an auto increment field is found, find the largest current uid:
00235                 if ($fInfo['Extra'] == 'auto_increment')    {
00236 
00237                         // Get all UIDs:
00238                     $uidArray = array();
00239                     foreach($this->data[$table] as $r)  {
00240                         $uidArray[] = $r[$fN];
00241                     }
00242 
00243                         // If current value is blank or already in array, we create a new:
00244                     if (!$saveArray[$fN] || in_array(intval($saveArray[$fN]), $uidArray))   {
00245                         if (count($uidArray))   {
00246                             $saveArray[$fN] = max($uidArray)+1;
00247                         } else $saveArray[$fN] = 1;
00248                     }
00249 
00250                         // Update "last inserted id":
00251                     $this->lastInsertedId = $saveArray[$fN];
00252                 }
00253             }
00254 
00255                 // Insert row in table:
00256             $this->data[$table][] = $saveArray;
00257 
00258                 // Save data source
00259             $this->saveDataSource($table);
00260 
00261             return TRUE;
00262         } else $this->errorStatus = 'No data loaded.';
00263 
00264         return FALSE;
00265     }
00266 
00267     /**
00268      * Execute UPDATE query on table
00269      *
00270      * @param   string      Table name
00271      * @param   string      WHERE clause
00272      * @param   array       Field values as key=>value pairs.
00273      * @return  boolean     TRUE on success and FALSE on failure (error is set internally)
00274      */
00275     public function exec_UPDATEquery($table, $where, $fields_values) {
00276 
00277             // Initialize:
00278         $this->resetStatusVars();
00279 
00280             // Reading Data Source if not done already.
00281         $this->readDataSource($table);
00282 
00283             // If anything is there:
00284         if (is_array($this->data[$table]))  {
00285 
00286                 // Parse WHERE clause:
00287             $where = $this->parseWhereClause($where);
00288 
00289             if (is_array($where))   {
00290 
00291                     // Field information
00292                 $fieldInformation = $this->admin_get_fields($table);        // Should cache this...!
00293 
00294                     // Traverse fields to update:
00295                 foreach($fields_values as $fName => $fValue)    {
00296                     $this->processAccordingToConfig($fields_values[$fName],$fieldInformation[$fName]);
00297                 }
00298 
00299                     // Do query, returns array with keys to the data array of the result:
00300                 $itemKeys = $this->selectFromData($table,$where);
00301 
00302                     // Set "last affected rows":
00303                 $this->lastAffectedRows = count($itemKeys);
00304 
00305                     // Update rows:
00306                 if ($this->lastAffectedRows)    {
00307                         // Traverse result set here:
00308                     foreach($itemKeys as $dataArrayKey) {
00309 
00310                             // Traverse fields to update:
00311                         foreach($fields_values as $fName => $fValue)    {
00312                             $this->data[$table][$dataArrayKey][$fName] = $fValue;
00313                         }
00314                     }
00315 
00316                     // Save data source
00317                     $this->saveDataSource($table);
00318                 }
00319 
00320                 return TRUE;
00321             } else $this->errorStatus = 'WHERE clause contained errors: '.$where;
00322         } else $this->errorStatus = 'No data loaded.';
00323 
00324         return FALSE;
00325     }
00326 
00327     /**
00328      * Execute DELETE query
00329      *
00330      * @param   string      Table to delete from
00331      * @param   string      WHERE clause
00332      * @return  boolean     TRUE on success and FALSE on failure (error is set internally)
00333      */
00334     public function exec_DELETEquery($table, $where) {
00335 
00336             // Initialize:
00337         $this->resetStatusVars();
00338 
00339             // Reading Data Source if not done already.
00340         $this->readDataSource($table);
00341 
00342             // If anything is there:
00343         if (is_array($this->data[$table]))  {
00344 
00345                 // Parse WHERE clause:
00346             $where = $this->parseWhereClause($where);
00347 
00348             if (is_array($where))   {
00349 
00350                     // Do query, returns array with keys to the data array of the result:
00351                 $itemKeys = $this->selectFromData($table,$where);
00352 
00353                     // Set "last affected rows":
00354                 $this->lastAffectedRows = count($itemKeys);
00355 
00356                     // Remove rows:
00357                 if ($this->lastAffectedRows)    {
00358                         // Traverse result set:
00359                     foreach($itemKeys as $dataArrayKey) {
00360                         unset($this->data[$table][$dataArrayKey]);
00361                     }
00362 
00363                         // Saving data source
00364                     $this->saveDataSource($table);
00365                 }
00366 
00367                 return TRUE;
00368             } else $this->errorStatus = 'WHERE clause contained errors: '.$where;
00369         } else $this->errorStatus = 'No data loaded.';
00370 
00371         return FALSE;
00372     }
00373 
00374     /**
00375      * Execute SELECT query
00376      *
00377      * @param   string      List of fields to select from the table. This is what comes right after "SELECT ...". Required value.
00378      * @param   string      Table(s) from which to select. This is what comes right after "FROM ...". Required value.
00379      * @param   string      Optional additional WHERE clauses put in the end of the query. NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself! DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
00380      * @param   string      Optional GROUP BY field(s), if none, supply blank string.
00381      * @param   string      Optional ORDER BY field(s), if none, supply blank string.
00382      * @param   string      Optional LIMIT value ([begin,]max), if none, supply blank string.
00383      * @return  object      Returns result object, but if errors, returns false
00384      */
00385     public function exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit) {
00386 
00387             // Initialize:
00388         $this->resetStatusVars();
00389 
00390             // Create result object
00391         $sqlObj = t3lib_div::makeInstance('tx_dbal_sqlengine_resultobj');
00392         $sqlObj->result = array();  // Empty result as a beginning
00393 
00394             // Get table list:
00395         $tableArray = $this->parseFromTables($from_table);
00396         $table = $tableArray[0]['table'];
00397 
00398             // Reading Data Source if not done already.
00399         $this->readDataSource($table);
00400 
00401             // If anything is there:
00402         if (is_array($this->data[$table]))  {
00403 
00404                 // Parse WHERE clause:
00405             $where = $this->parseWhereClause($where_clause);
00406             if (is_array($where))   {
00407 
00408                     // Do query, returns array with keys to the data array of the result:
00409                 $itemKeys = $this->selectFromData($table,$where);
00410 
00411                     // Finally, read the result rows into this variable:
00412                 $sqlObj->result = $this->getResultSet($itemKeys,$table,'*');
00413                     // Reset and return result:
00414                 reset($sqlObj->result);
00415                 return $sqlObj;
00416             } else $this->errorStatus = 'WHERE clause contained errors: '.$where;
00417         }  else $this->errorStatus = 'No data loaded: '.$this->errorStatus;
00418 
00419         return FALSE;
00420     }
00421 
00422     /**
00423      * Performs an SQL query on the "database"
00424      *
00425      * @param   string      Query to execute
00426      * @return  object      Result object or false if error
00427      */
00428     public function sql_query($query) {
00429         $res = t3lib_div::makeInstance('tx_dbal_sqlengine_resultobj');
00430         $res->result = array();
00431         return $res;
00432     }
00433 
00434     /**
00435      * Returns most recent error
00436      *
00437      * @return  string      Error message, if any
00438      */
00439     public function sql_error() {
00440         return $this->errorStatus;
00441     }
00442 
00443     /**
00444      * Returns most recently create unique ID (of INSERT queries)
00445      *
00446      * @return  integer     Last unique id created.
00447      */
00448     public function sql_insert_id() {
00449         return $this->lastInsertedId;
00450     }
00451 
00452     /**
00453      * Returns affected rows (of UPDATE and DELETE queries)
00454      *
00455      * @return  integer     Last amount of affected rows.
00456      */
00457     public function sql_affected_rows() {
00458         return $this->lastAffectedRows;
00459     }
00460 
00461     /**
00462      * Quoting strings for insertion in SQL queries
00463      *
00464      * @param   string      Input String
00465      * @return  string      String, with quotes escaped
00466      */
00467     public function quoteStr($str) {
00468         return addslashes($str);
00469     }
00470 
00471 
00472 
00473 
00474 
00475 
00476 
00477 
00478 
00479 
00480     /**************************************
00481      *
00482      * SQL admin functions
00483      * (For use in the Install Tool and Extension Manager)
00484      *
00485      **************************************/
00486 
00487     /**
00488      * (DUMMY) Returns the list of tables from the database
00489      *
00490      * @return  array       Tables in an array (tablename is in both key and value)
00491      * @todo    Should return table details in value! see t3lib_db::admin_get_tables()
00492      */
00493     public function admin_get_tables() {
00494         $whichTables = array();
00495         return $whichTables;
00496     }
00497 
00498     /**
00499      * (DUMMY) Returns information about each field in the $table
00500      *
00501      * @param   string      Table name
00502      * @return  array       Field information in an associative array with fieldname => field row
00503      */
00504     public function admin_get_fields($tableName) {
00505         $output = array();
00506         return $output;
00507     }
00508 
00509     /**
00510      * (DUMMY) Returns information about each index key in the $table
00511      *
00512      * @param   string      Table name
00513      * @return  array       Key information in a numeric array
00514      */
00515     public function admin_get_keys($tableName) {
00516         $output = array();
00517         return $output;
00518     }
00519 
00520     /**
00521      * (DUMMY) mysql() wrapper function, used by the Install Tool and EM for all queries regarding management of the database!
00522      *
00523      * @param   string      Query to execute
00524      * @return  pointer     Result pointer
00525      */
00526     public function admin_query($query) {
00527         return $this->sql_query($query);
00528     }
00529 
00530 
00531 
00532 
00533 
00534 
00535 
00536 
00537     /********************************
00538      *
00539      * Data Source I/O
00540      *
00541      ********************************/
00542 
00543     /**
00544      * Dummy function for setting table data. Create your own.
00545      * NOTICE: Handler to "table-locking" needs to be made probably!
00546      *
00547      * @param   string      Table name
00548      * @return  void
00549      * @todo    Table locking tools?
00550      */
00551     public function readDataSource($table) {
00552         $this->data[$table] = array();
00553     }
00554 
00555     /**
00556      * Dummy function for setting table data. Create your own.
00557      * NOTICE: Handler to "table-locking" needs to be made probably!
00558      *
00559      * @param   string      Table name
00560      * @return  void
00561      * @todo    Table locking tools?
00562      */
00563     public function saveDataSource($table) {
00564         debug($this->data[$table]);
00565     }
00566 
00567 
00568 
00569 
00570 
00571 
00572 
00573 
00574 
00575 
00576 
00577 
00578 
00579     /********************************
00580      *
00581      * SQL engine functions (PHP simulation of SQL) - still experimental
00582      *
00583      ********************************/
00584 
00585     /**
00586      * PHP simulation of SQL "SELECT"
00587      * Yet EXPERIMENTAL!
00588      *
00589      * @param   string      Table name
00590      * @param   array       Where clause parsed into array
00591      * @return  array       Array of keys pointing to result rows in $this->data[$table]
00592      */
00593     public function selectFromData($table, $where) {
00594 
00595         $output = array();
00596         if (is_array($this->data[$table]))  {
00597 
00598                 // All keys:
00599             $OR_index = 0;
00600 
00601             foreach($where as $config)  {
00602 
00603                 if (strtoupper($config['operator'])=='OR')  {
00604                     $OR_index++;
00605                 }
00606 
00607                 if (!isset($itemKeys[$OR_index]))   $itemKeys[$OR_index] = array_keys($this->data[$table]);
00608 
00609                 $this->select_evalSingle($table,$config,$itemKeys[$OR_index]);
00610             }
00611 
00612             foreach($itemKeys as $uidKeys)  {
00613                 $output = array_merge($output, $uidKeys);
00614             }
00615             $output = array_unique($output);
00616         }
00617 
00618         return $output;
00619     }
00620 
00621     /**
00622      * Evalutaion of a WHERE-clause-array.
00623      * Yet EXPERIMENTAL
00624      *
00625      * @param   string      Tablename
00626      * @param   array       WHERE-configuration array
00627      * @param   array       Data array to work on.
00628      * @return  void        Data array passed by reference
00629      * @see selectFromData()
00630      */
00631     public function select_evalSingle($table,$config,&$itemKeys) {
00632         $neg = preg_match('/^AND[[:space:]]+NOT$/',trim($config['operator']));
00633 
00634         if (is_array($config['sub']))   {
00635             $subSelKeys = $this->selectFromData($table,$config['sub']);
00636             if ($neg)   {
00637                 foreach($itemKeys as $kk => $vv)    {
00638                     if (in_array($vv,$subSelKeys))  {
00639                         unset($itemKeys[$kk]);
00640                     }
00641                 }
00642             } else {
00643                 $itemKeys = array_intersect($itemKeys, $subSelKeys);
00644             }
00645         } else {
00646             $comp = strtoupper(str_replace(array(' ',"\t","\r","\n"),'',$config['comparator']));
00647             $mod = strtoupper($config['modifier']);
00648             switch($comp)   {
00649                 case 'NOTLIKE':
00650                 case 'LIKE':
00651                     $like_value = strtolower($config['value'][0]);
00652                     if (substr($like_value,0,1)=='%')   {
00653                         $wildCard_begin = TRUE;
00654                         $like_value = substr($like_value,1);
00655                     }
00656                     if (substr($like_value,-1)=='%')    {
00657                         $wildCard_end = TRUE;
00658                         $like_value = substr($like_value,0,-1);
00659                     }
00660                 break;
00661                 case 'NOTIN':
00662                 case 'IN':
00663                     $in_valueArray = array();
00664                     foreach($config['value'] as $vParts)    {
00665                         $in_valueArray[] = (string)$vParts[0];
00666                     }
00667                 break;
00668             }
00669 
00670             foreach($itemKeys as $kk => $v) {
00671                 $field_value = $this->data[$table][$v][$config['field']];
00672 
00673                     // Calculate it:
00674                 if ($config['calc']=='&')   {
00675                     $field_value&=intval($config['calc_value']);
00676                 }
00677 
00678                     // Compare it:
00679                 switch($comp)   {
00680                     case '<=':
00681                         $bool = $field_value <= $config['value'][0];
00682                     break;
00683                     case '>=':
00684                         $bool = $field_value >= $config['value'][0];
00685                     break;
00686                     case '<':
00687                         $bool = $field_value < $config['value'][0];
00688                     break;
00689                     case '>':
00690                         $bool = $field_value > $config['value'][0];
00691                     break;
00692                     case '=':
00693                         $bool = !strcmp($field_value,$config['value'][0]);
00694                     break;
00695                     case '!=':
00696                         $bool = strcmp($field_value,$config['value'][0]);
00697                     break;
00698                     case 'NOTIN':
00699                     case 'IN':
00700                         $bool = in_array((string)$field_value, $in_valueArray);
00701                         if ($comp=='NOTIN') $bool = !$bool;
00702                     break;
00703                     case 'NOTLIKE':
00704                     case 'LIKE':
00705                         if (!strlen($like_value))   {
00706                             $bool = TRUE;
00707                         } elseif ($wildCard_begin && !$wildCard_end)    {
00708                             $bool = !strcmp(substr(strtolower($field_value),-strlen($like_value)),$like_value);
00709                         } elseif (!$wildCard_begin && $wildCard_end)    {
00710                             $bool = !strcmp(substr(strtolower($field_value),0,strlen($like_value)),$like_value);
00711                         } elseif ($wildCard_begin && $wildCard_end) {
00712                             $bool = strstr($field_value,$like_value);
00713                         } else {
00714                             $bool = !strcmp(strtolower($field_value),$like_value);
00715                         }
00716                         if ($comp=='NOTLIKE')   $bool = !$bool;
00717                     break;
00718                     default:
00719                         $bool = $field_value ? TRUE : FALSE;
00720                     break;
00721                 }
00722 
00723                     // General negation:
00724                 if ($neg)   $bool = !$bool;
00725 
00726                     // Modify?
00727                 switch($mod)    {
00728                     case 'NOT':
00729                     case '!':
00730                         $bool = !$bool;
00731                     break;
00732                 }
00733 
00734                     // Action:
00735                 if (!$bool) {
00736                     unset($itemKeys[$kk]);
00737                 }
00738             }
00739         }
00740     }
00741 
00742     /**
00743      * Returning result set based on result keys, table and field list
00744      *
00745      * @param   array       Result keys
00746      * @param   string      Tablename
00747      * @param   string      Fieldlist (commaseparated)
00748      * @return  array       Result array with "rows"
00749      */
00750     public function getResultSet($keys, $table, $fieldList) {
00751         $fields = t3lib_div::trimExplode(',',$fieldList);
00752 
00753         $output = array();
00754         foreach($keys as $kValue)   {
00755             if ($fieldList=='*')    {
00756                 $output[$kValue] = $this->data[$table][$kValue];
00757             } else {
00758                 foreach($fields as $fieldName)  {
00759                     $output[$kValue][$fieldName] = $this->data[$table][$kValue][$fieldName];
00760                 }
00761             }
00762         }
00763 
00764         return $output;
00765     }
00766 
00767 
00768 
00769 
00770 
00771 
00772 
00773 
00774 
00775 
00776 
00777 
00778 
00779 
00780 
00781     /*************************
00782      *
00783      * Debugging
00784      *
00785      *************************/
00786 
00787     /**
00788      * Returns the result set (in array) as HTML table. For debugging.
00789      *
00790      * @param   array       Result set array (array of rows)
00791      * @return  string      HTML table
00792      */
00793     public function debug_printResultSet($array) {
00794 
00795         if (count($array))  {
00796             $tRows=array();
00797             $fields = array_keys(current($array));
00798                     $tCell[]='
00799                             <td>IDX</td>';
00800                 foreach($fields as $fieldName)  {
00801                     $tCell[]='
00802                             <td>'.htmlspecialchars($fieldName).'</td>';
00803                 }
00804                 $tRows[]='<tr>'.implode('',$tCell).'</tr>';
00805 
00806 
00807             foreach($array as $index => $rec)   {
00808 
00809                 $tCell=array();
00810                 $tCell[]='
00811                         <td>'.htmlspecialchars($index).'</td>';
00812                 foreach($fields as $fieldName)  {
00813                     $tCell[]='
00814                             <td>'.htmlspecialchars($rec[$fieldName]).'</td>';
00815                 }
00816                 $tRows[]='<tr>'.implode('',$tCell).'</tr>';
00817             }
00818 
00819             return '<table border="1">'.implode('',$tRows).'</table>';
00820         } else 'Empty resultset';
00821     }
00822 }
00823 
00824 
00825 /**
00826  * PHP SQL engine, result object
00827  *
00828  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00829  * @package TYPO3
00830  * @subpackage dbal
00831  */
00832 class tx_dbal_sqlengine_resultobj {
00833 
00834         // Result array, must contain the fields in the order they were selected in the SQL statement (for sql_fetch_row())
00835     var $result = array();
00836 
00837     var $TYPO3_DBAL_handlerType = '';
00838     var $TYPO3_DBAL_tableList = '';
00839 
00840 
00841     /**
00842      * Counting number of rows
00843      *
00844      * @return  integer
00845      */
00846     public function sql_num_rows() {
00847         return count($this->result);
00848     }
00849 
00850     /**
00851      * Fetching next row in result array
00852      *
00853      * @return  array       Associative array
00854      */
00855     public function sql_fetch_assoc() {
00856         $row = current($this->result);
00857         next($this->result);
00858         return $row;
00859     }
00860 
00861     /**
00862      * Fetching next row, numerical indices
00863      *
00864      * @return  array       Numerical array
00865      */
00866     public function sql_fetch_row() {
00867         $resultRow = $this->sql_fetch_assoc();
00868 
00869         if (is_array($resultRow))   {
00870             $numArray = array();
00871             foreach($resultRow as $value)   {
00872                 $numArray[]=$value;
00873             }
00874             return $numArray;
00875         }
00876     }
00877 
00878     /**
00879      * Seeking position in result
00880      *
00881      * @param   integer     Position pointer.
00882      * @return  boolean     Returns true on success
00883      */
00884     public function sql_data_seek($pointer) {
00885         reset($this->result);
00886         for ($a=0;$a<$pointer;$a++) {
00887             next($this->result);
00888         }
00889         return TRUE;
00890     }
00891 
00892     /**
00893      * Returning SQL field type
00894      *
00895      * @return  string      Blank string, not supported (it seems)
00896      */
00897     public function sql_field_type() {
00898         return '';
00899     }
00900 }
00901 
00902 
00903 
00904 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dbal/lib/class.tx_dbal_sqlengine.php']) {
00905     include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dbal/lib/class.tx_dbal_sqlengine.php']);
00906 }
00907 
00908 ?>

Generated on Sat Sep 4 04:17:15 2010 for TYPO3 API by  doxygen 1.4.7