class.t3lib_sqlengine.php

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

Generated on Sat Jul 4 04:15:47 2009 for TYPO3 API by  doxygen 1.5.8