class.t3lib_sqlengine.php

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

Generated on Sat Jan 3 04:23:27 2009 for TYPO3 API by  doxygen 1.4.7