diff --git a/.gitmodules b/.gitmodules index 160fa161229ba825ed3e88a57b57c2951d8b1e55..f384b773bdb89f64db36805c625270b6bf370d96 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "typo3/sysext/workspaces"] path = typo3/sysext/workspaces url = git://git.typo3.org/TYPO3v4/CoreProjects/workspaces/workspaces.git +[submodule "typo3/sysext/dbal"] + path = typo3/sysext/dbal + url = git://git.typo3.org/TYPO3v4/Extensions/dbal.git diff --git a/typo3/sysext/dbal b/typo3/sysext/dbal new file mode 160000 index 0000000000000000000000000000000000000000..96b4ce91b0c2645a498ed586a1c3630db4467462 --- /dev/null +++ b/typo3/sysext/dbal @@ -0,0 +1 @@ +Subproject commit 96b4ce91b0c2645a498ed586a1c3630db4467462 diff --git a/typo3/sysext/dbal/ChangeLog b/typo3/sysext/dbal/ChangeLog deleted file mode 100644 index a3964ca613e9bdbb9116b914489d93a056306deb..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/ChangeLog +++ /dev/null @@ -1,569 +0,0 @@ -2011-01-26 Xavier Perseguers <typo3@perseguers.ch> - - * Set version to 1.2.1 - -2011-01-25 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #17221: Install tool is unable to delete database tables - -2011-01-24 Xavier Perseguers <typo3@perseguers.ch> - - * Set version to 1.2.0 - * Fixed bug #17269: Search with LIKE is case sensitive on Oracle - -2010-12-27 Xavier Perseguers <typo3@perseguers.ch> - - * Set version to 1.2.0beta3 - -2010-12-06 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #16679: Cannot login to backend at the end of 1-2-3 wizard when using Oracle - -2010-12-05 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #16677: PHP notices from XCLASS inclusions - * Fixed bug #16678: DBAL is active with MySQL at the end of 1-2-3 wizard - -2010-12-02 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #16639: Install Tool is unusable since DBAL merge - -2010-12-01 Xavier Perseguers <typo3@perseguers.ch> - - * Set version to 1.2.0beta2 - -2010-12-01 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed use of undefined variable $where in method exec_INSERTquery() with MySQL handler - * Fixed use of undefined variable $mapping in method map_subquery() - * Follow-up for bug #16392: Native tables could not be retrieved anymore - * Code cleanup - * Fixed bug #16492: groupBy and orderBy fail on exec_query (thanks to Oguzhan Alan) - -2010-11-30 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #16501: DBAL does not support multi-column indexes in create table queries - * Added feature #16491: Provide a pass-through flag for sql_exec() which goes directly to the native MySQL engine - -2010-11-18 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #16392: Install tool cannot compare "ENGINE" of MySQL Tables when DBAL is active - -2010-11-17 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #16444: DBAL installs itself automatically whenever the install tool is called - -2010-11-14 Xavier Perseguers <typo3@perseguers.ch> - - * Set version to 1.2.0beta1 - -2010-11-14 Xavier Perseguers <typo3@perseguers.ch> - - * Added feature #15755: Allow DBAL to interact with EM to configure remapping - -2010-10-30 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #16179: 1-2-3 install tool wizard does not let DBAL load early enough - * Fixed bug #15941: Log deprecated functions (and adjust comments) - * Fixed bug #15960: Misleading error message in ux_t3lib_DB->cacheFieldInfo() (thanks to Martin Kuster) - * Fixed bug #16120: UPDATE queries fails for $GLOBALS['TYPO3_DB']->sql_query (thanks to Alan Oguzhan) - -2010-10-19 Xavier Perseguers <typo3@perseguers.ch> - - * Set version to 1.2.0alpha3 - -2010-09-28 Xavier Perseguers <typo3@perseguers.ch> - - * Added feature #15075: [Install] make a pre-check for required php-extensions (thanks to Jigal van Hemert) - -2010-09-21 Xavier Perseguers <typo3@perseguers.ch> - - * Set version to 1.2.0alpha2 - -2010-09-20 Xavier Perseguers <typo3@perseguers.ch> - - * Merged branch QueryCache to trunk - * Updated documentation to describe how to use Memcached to cache prepared queries - * Fixed bug #15751: dbal does not parse setDBinit correctly (thanks to Tamer Erdogan) - -2010-08-30 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #15582: Call to deprecated function template::middle() - -2010-08-24 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed caching with Memcached - * Synchronized code from trunk - -2010-08-23 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #15535: Error: No pages are found on the rootlevel! in Frontend when using Oracle - * Updated ADOdb version dependency - * Set version to 1.2.0alpha1 - -2010-08-19 Xavier Perseguers <typo3@perseguers.ch> - - * Updated caching mechanism to cache prepared queries - * Synchronized code from trunk - * Added unit test for feature #15457 - * Added feature #15457: Add support for prepared queries - -2010-08-14 Xavier Perseguers <typo3@perseguers.ch> - - * Code cleanup with useless blank spaces at end of line - -2010-08-08 Xavier Perseguers <typo3@perseguers.ch> - - * Added unit test for bug #15253: NOT LIKE is not remapped using dbms_lob.instr with Oracle - * Fixed bug #12535: DAM-related: Element browser crashes as where-clause cannot be parsed - -2010-07-27 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #15160: Queries should only be parsed once - -2010-07-17 Xavier Perseguers <typo3@perseguers.ch> - - * Updated PHP documentation - -2010-07-16 Xavier Perseguers <typo3@perseguers.ch> - - * Added unit test for bug #14818: t3lib_db->listQuery() performance - * Fixed bug #14985: FIND_IN_SET should be used isntead of complicated LIKE where clause - -2010-07-11 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #15045: Trailing newlines after php closing tag - -2010-06-27 Xavier Perseguers <typo3@perseguers.ch> - - * Synchronized @deprecated annotations with Core - -2010-06-22 Jeff Segars <jeff@webempoweredchurch.org> - - * Fixed bug #14814: Improve install tool texts - -2010-06-19 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #3855: Log number of returned or affected rows - * Updated copyright year in manual - -2010-06-12 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #13431: Include BE:forceCharset config option (thanks to Armin Guenther) - -2010-06-11 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #14405: Rename the test cases from *_testcase to *Test - -2010-06-03 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #14479: Speed up Oracle layer by not defaulting to dbms_lob.instr for LIKE query (thanks to Michiel Roos) - -2010-05-28 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #7015: t3lib_DB displays wrong SQL in error case - -2010-05-27 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #14496: SQL parser does not handle ALTER TABLE with character set operation - * Fixed bug #14456: SQL parser doesn't accept ALTER TABLE statement without CHANGE, DROP or ADD keyword - * Fixed bug #14457: 1-2-3 Install Process breaks with PostgreSQL - -2010-05-21 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #14372: Mapping does not work with table alias - * Follow-up of changeset 32847: DBAL cannot be loaded if typo3conf/ is not writable - -2010-05-03 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed 1-2-3 installer crash when having only mysql available - -2010-05-01 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #14274: Some exception are not caught when trying to install DBAL in 1-2-3 Install Tool process - * Fixed bug #2186: Error installing static_info_tables - * Fixed bug #14265: Driver dropdown in install tool should be hidden when only MySQL is available - -2010-04-29 Xavier Perseguers <typo3@perseguers.ch> - - * Added autoloader for Install Tool - -2010-04-22 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #14182: Multiple join conditions are not supported - -2010-04-15 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #14120: Add a method to check if database is connected - -2010-04-14 Xavier Perseguers <typo3@perseguers.ch> - - * Set version to 1.1.2 - -2010-04-12 Xavier Perseguers <typo3@perseguers.ch> - - * Added feature #13508: Use exec_TRUNCATEquery() instead of DELETE FROM throughout the core - -2010-04-06 Xavier Perseguers <typo3@perseguers.ch> - - * Added skeleton of a cache for generated queries - -2010-03-07 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #4640: Backend login impossible with MSSQL via ODBC (thanks to Felix Eckhofer) - -2010-02-21 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #2367: No support for LIMIT [PostgreSQL] - -2010-02-14 Xavier Perseguers <typo3@perseguers.ch> - - * Set version to 1.1.1 - -2010-02-14 Xavier Perseguers <typo3@perseguers.ch> - - * Added unit test for #12829: ALTER TABLE is not able to parse length restriction in index creation - -2010-02-13 Xavier Perseguers <typo3@perseguers.ch> - - * Added unit tests for #4493: WHERE func(expr) IN (n,...m) is broken - * Fixed bug #6196: IFNULL operator cannot be parsed - * Fixed bug #13528: Argument 1 passed to ux_t3lib_DB::_quoteFieldNames() must be an array, string given - -2010-02-11 Xavier Perseguers <typo3@perseguers.ch> - - * Follow-up of #13504: Using TRUNCATE instead of TRUNCATETABLE as public DB API - -2010-02-10 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #13504: Cannot parse TRUNCATE TABLE in install tool - -2010-02-09 Xavier Perseguers <typo3@perseguers.ch> - - * Added unit test for bug #13490: Where clause 0=0 cannot be parsed - -2010-02-07 Xavier Perseguers <typo3@perseguers.ch> - - * Added feature #12858: Provide an API to insert multiple rows at once - * Fixed bug #13453: Method compileINSERT of ux_t3lib_sqlparser should be protected - * Added feature #13209: MySQL extended INSERT statements cannot be parsed - -2010-02-06 Xavier Perseguers <typo3@perseguers.ch> - - * Added unit tests for bug #13430: Cannot parse INSERT when VALUES has no space before left parenthesis - -2010-02-05 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #13422: Invalid quoting of numeric column names - -2010-02-03 Xavier Perseguers <typo3@perseguers.ch> - - * Added unit tests for bug #13412: BETWEEN operator is not supported - -2010-01-24 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #13090: version warning with CSS styled content - -2010-01-14 Steffen Kamper <info@sk-typo3.de> - - * Fixed bug #13199: fileadminDir is hardcoded in several places (thanks to Susanne Moog) - -2010-01-08 Xavier Perseguers <typo3@perseguers.ch> - - * Updated copyright year - -2010-01-05 Xavier Perseguers <typo3@perseguers.ch> - - * Added feature #13134: Support of SQL LOCATE function - -2010-01-03 Xavier Perseguers <typo3@perseguers.ch> - - * Added feature #13135: Support for CASE WHEN flow control - -2009-12-30 Xavier Perseguers <typo3@perseguers.ch> - - * Set version to 1.1.0 - -2009-12-28 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #12603: sql_query does not respect "mapping" - * Fixed bug #13104: SQL parser cannot parse escaped single quote in INSERT statement - -2009-12-27 Xavier Perseguers <typo3@perseguers.ch> - - * Updated documentation: now using new documentation template - * Updated documentation: removed obsolete information, added small cookbook for extension developers, added tutorials for Oracle and PostgreSQL - -2009-12-13 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #13003: Move back methods belonging to t3lib_sqlparser - -2009-12-11 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #12897: Cannot parse SQL hints - -2009-11-29 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #12758: Added support for EXISTS (subquery) - -2009-11-29 Xavier Perseguers <typo3@perseguers.ch> - - * Set version to 1.0.2 [TYPO3 4.3.0] - * Fixed bug #12800: Add functionality to work with caching framework (support for "IN (subquery)" in where clause) - * Follow-up of changeset 26118: parts of initial patch for RFC 12231 had actually not been integrated - -2009-11-27 Xavier Perseguers <typo3@perseguers.ch> - - * Cleanup: Reorganized unit-tests - -2009-11-25 Xavier Perseguers <typo3@perseguers.ch> - - * Set version to 1.0.1 - -2009-11-20 Xavier Perseguers <typo3@perseguers.ch> - - * Added unit-test for bug #5708: Fieldmapping doesn't work on the "right side" in where clause with table.field - * Fixed bugs #5044/#11142: Column's default value is not properly quoted in CREATE TABLE - * Added unit-test for bug #12670: Columns with NOT NULL are created as NULLable - -2009-11-17 Xavier Perseguers <typo3@perseguers.ch> - - * Set version to 1.0.0 (stable) - * Updated documentation: updated copyright and refreshed TOC - * Added unit-test for bug #4466: Index on tx_realurl_uniqalias breaks with DBAL - -2009-11-16 Xavier Perseguers <typo3@perseguers.ch> - - * Now using Core dispatcher for backend module (thanks to Oliver Hader) - -2009-11-15 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #12596: RIGHT OUTER JOIN is not supported - -2009-11-11 Xavier Perseguers <typo3@perseguers.ch> - - * Added unit test for bug #11093: bigint (int8) values get converted to int4 by int-cast - -2009-11-10 Xavier Perseguers <typo3@perseguers.ch> - - * Removed comments stating that SQL parser is experimental - * Follow-up of revision 26334: LIKE on Oracle should use dbms_lob.instr() function - * Updated Oracle unit tests to use $GLOBALS['TYPO3_DB'] instead of a fixture to avoid side-effects on SQL rewriting - * Updated general database unit tests to use $GLOBALS['TYPO3_DB'] instead of a fixture to avoid side-effects on SQL rewriting - -2009-11-09 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #10965: Float database field gets converted to integer on insert (thanks to Christian Ducrot) - * Fixed bug #12515: DAM-related: CONCAT operator cannot be used after LIKE - * Fixed bug #10411: Applied missing chunks of patch - -2009-11-07 Xavier Perseguers <typo3@perseguers.ch> - - * Added unit test for RFC #6198: Problem with strings in IN - * Added unit test for RFC #6953: Mapping of fieldnames in SQL-functions like MIN(), MAX() or SUM() does not work - -2009-11-06 Xavier Perseguers <typo3@perseguers.ch> - - * Set version to 0.9.25 - * Fixed bug: tables and fields were not always properly mapped in INNER JOINs - * Added unit tests to test quoting and remapping of tables and fields when using Oracle - -2009-11-05 Xavier Perseguers <typo3@perseguers.ch> - - * Set version to 0.9.24 - * Follow-up of RFC #12452: Reflected change of visibility of method compileFieldCfg() in t3lib_sqlparser - -2009-11-04 Xavier Perseguers <typo3@perseguers.ch> - - * Updated ext_emconf.php's author and extension version dependencies - -2009-11-03 Xavier Perseguers <typo3@perseguers.ch> - - * Added some general unit tests (without any engine-specific test nor mapping) - * Cleanup #12440: Copy DBAL-only SQL parser methods from t3lib_sqlparser to ux_t3lib_sqlparser - * Fixed bug #12231: New caching framework (4.3-dev) does not work with DBAL - -2009-10-28 Xavier Perseguers <typo3@perseguers.ch> - - * Added compatibility operators for PostgreSQL as resource script (thanks to Ries van Twisk) - * Added message in Extension Manager to let users know compatibility scripts may need to be run - -2009-10-27 Xavier Perseguers <typo3@perseguers.ch> - - * Follow-up of changeset 25876: Using tx_dbal_sqlengine instead of t3lib_sqlengine for sample handlers - * Created icons for extension and Debug module - * Cleanup: Applied CGL - -2009-10-26 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #12354: Include t3lib_sqlengine from Core to DBAL - * Fixed bug #12349: Clean-up SQL parser and SQL engine - -2009-10-20 Oliver Hader <oliver@typo3.org> - - * Set version to 0.9.23 - -2009-10-08 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #6953: Mapping of fieldnames in SQL-functions like MIN(), MAX() or SUM() does not work (thanks to Christian and Michael Miousse) - -2009-10-01 Xavier Perseguers <typo3@perseguers.ch> - - * Raised version to 0.9.22 - -2009-09-29 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #12071: t3lib_sqlparser is not able to parse alias of a joined table - -2009-09-20 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #12012: admin_get_tables() method is using PHP5.3-deprecated function mysql_list_tables - -2009-09-18 Xavier Perseguers <typo3@perseguers.ch> - - * Raised version to 0.9.21 - -2009-09-18 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #11984: Remove reference operators for objects - -2009-09-03 Xavier Perseguers <typo3@perseguers.ch> - - * Fixed bug #11436: Unknown tables break Install-Tool (thanks to David Bruchmann) - * Fixed bug #11108: DBAL wildly quotes fields and table names - -2009-09-04 Karsten Dambekalns <karsten@typo3.org> - - * Raised version to 0.9.20 - -2008-02-04 Michael Stucki <michael@typo3.org> - - * Fixed bug #7295: Uninitialized variable in ->handler_getFromTableList() (Patch by Oliver Klee) - -2007-05-30 Karsten Dambekalns <karsten@typo3.org> - - * Added default values and some usability improvements to cached info display in debug module (closes bug #3750) - * EXPLAIN PLAN support for Oracle (closes bug #3850) - * Fixed a warning when using admin_get_fields() on a non-existent table - * Fixed a bug causing inserts with more than one affected CLOB field to fail - * quoteWhereClause() now die()s when the input cannot be parsed by parseWhereClause() - * PHP backtraces can be logged with the queries now (closes bug #3856) - -2007-05-29 Karsten Dambekalns <karsten@typo3.org> - - * Closes bug #4462: creates tables without OIDs on PostgreSQL now - * Closes bugs #4494, #3759: & is translated to BITAND() on Oracle now - * Large text fields are CLOB fields now; for Oracle LIKE comparisons against such fields are translated to dbms_lob.instr() calls. This should fix e.g. bug #5535 as well as issues with TV data that cannot be unserialized (see comments on bug #4638) - * Updates to the manual - * A fix for bug #5481, field mapping not working on the right side of a comparison in WHERE clauses - * Fixed bugs #2438 and #4496 about quoting of DISTINCT in SELECT clauses - -2006-07-19 Karsten Dambekalns <karsten@typo3.org> - - * Fixes SQL issues when searching in list view or with the global search box on the bottom of the BE page - -2006-06-30 Karsten Dambekalns <karsten@typo3.org> - - * this update closes bugs #3638, #2106, #2866, #3754 (for Firefox, broken in MSIE) and maybe a few more - * Implemented support for sysLog() on connection failure - * DBAL now honours the no_pconnect setting - * For handlers in native mode the setDBinit queries are executed upon connection - * The initial value for generated sequences can be configured per handler, to avoid duplicate key errors after having imported data - * BLOB fields are handled correctly now during INSERT and UPDATE - * Setting $store_lastBuiltQuery acts like in t3lib_db now (fill $debug_lastBuiltQuery) - * For the native handler quoting methods directly return the input for speedup, as no quoting is needed in that case - * Added support for native and userdefined handler to MetaType() - * Changed mapping of types to always use the largest possible integer, map tinytext to varchar instead of text - * admin_get_tables() skips tables whose names match /BIN\$/ (coming from the recycle bin on Oracle) - * Importing dumps using the install tool now works, see manual for tips - * Changed the way NOT NULL and DEFAULT are handled when setting up tables, see manual for the rules that now apply - * Code cleanup (indentation, documentation) - * Updated the manual and added new content - -2006-01-19 Karsten Dambekalns <karsten@typo3.org> - - * Changes to connection handling, detecting failed connections. - * Added support for $no_quote_fields in UPDATE and INSERT methods. - -2006-01-04 Karsten Dambekalns <karsten@typo3.org> - - * Changed the way a connection is established with ADOdb. The new - way allows ODBC connections (rather, connections to drivers having - an underscore in their name). - * Changes to ext_tables.sql to make it more portable. - * When printing errors, output the offending SQL as well. - * Some small fixes, enhancements to code documentation. - * Some additions to the manual. - -2005-12-27 Karsten Dambekalns <karsten@typo3.org> - - * Converted locallang to XML, small adaptions to syext location. - * One slight fix to the SQL check in the BE module (wrong output if - an error occurred). - -2005-12-26 Karsten Dambekalns <karsten@typo3.org> - - * Code cleanup and improvements to the mapping. Merged 3rd - party changes done by DIACC GmbH. - -2005-12-23 Karsten Dambekalns <karsten@typo3.org> - - * Fixed a few issues that were left undiscovered yet. - * Added a new module to test query building and parsing - from the DBAL debug module. - * Finalized fix for bug #1649. - -2005-12-22 Karsten Dambekalns <karsten@typo3.org> - - * Fixed bug #2077 (NOT handling breaking, consequently - discarding WHERE clauses). - -2005-12-21 Karsten Dambekalns <karsten@typo3.org> - - * Fixed bug #1781 to allow easier install. - * Closed bug #1204 as not reproducable. Probably rather a - PHP/Apache bug than a DBAL bug. - * Closed bug #1317 which has been fixed earlier. It was due - to a msissing check for the incoming SQL (string/array) in the - native part of exec_UPDATEquery(). - * Fixed parseFieldDef() t3lib_sqlparser to allow datatypes - with just a trailing comma (like in "tyinytext," as opposed - to "varchar(19)". This prevented installation of some - extensions. - * Fixed bug #2072. - * Fixed bug #1206. - * Fixed a bug with error logging and array queries (BLOB). - * Prepared a fix for bug #1649, pending core list approval. - * Fixed a bug in t3lib_page, getMultipleGroupsWhereClause() - where double quotes were used to quote a literal for use in - SQL. THIS IS MYSQL-ONLY! NEVER DO THIS! ALWAYS USE SINGLE - QUOTES! - -2005-06-07 Karsten Dambekalns <karsten@typo3.org> - - Documentation update. - -2005-05-19 Karsten Dambekalns <karsten@typo3.org> - - Committed changes to go along with the library removal done - earlier. Completed debug logging. - -2005-02-07 Karsten Dambekalns <karsten@typo3.org> - - Bringing the DBAL extension AS OF JANUARY 2005 into CVS. Works - pretty well, but still needs more work. A few optimizations are - planned and some bugs in native mode need to be fixed. Checking - this in is (similar to yesterday's commit) more for - historic/archival reasons. This version will NOT work with 3.7.x. - You have been warned. - -2005-02-06 Karsten Dambekalns <karsten@typo3.org> - - Bringing the DBAL extension AS OF JULY 2004 into CVS. This is - rather for historic purposes, more changes will follow in the near - future. This version was already a huge step forward, but it will - not work as expected with 3.7.x or 3.8.x. You have been warned. - -2004-03-28 Kasper Skaarhoej <kasperYYYY@typo3.com> - - Initial revision diff --git a/typo3/sysext/dbal/class.tx_dbal_autoloader.php b/typo3/sysext/dbal/class.tx_dbal_autoloader.php deleted file mode 100644 index 41a4e8aca956e5e0f97c8dfbf8dc7403d5d49cdb..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/class.tx_dbal_autoloader.php +++ /dev/null @@ -1,170 +0,0 @@ -<?php -/*************************************************************** - * Copyright notice - * - * (c) 2010 Xavier Perseguers <typo3@perseguers.ch> - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * A copy is found in the textfile GPL.txt and important notices to the license - * from the author is found in LICENSE.txt distributed with these scripts. - * - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -/** - * Autoloader included from Install Tool that lets DBAL load itself - * if it makes sense. - * - * $Id$ - * - * @author Xavier Perseguers <typo3@perseguers.ch> - * - * @package TYPO3 - * @subpackage dbal - */ -class tx_dbal_autoloader { - - /** - * Activates DBAL if it is supported. - * - * @param tx_install $instObj - * @return void - */ - public function execute(tx_install $instObj) { - if ($instObj->mode == '123') { - switch ($instObj->step) { - case 1: - if (!t3lib_extMgm::isLoaded('dbal') && $this->isDbalSupported()) { - $this->activateDbal(); - - // Reload page to have Install Tool actually load DBAL - $redirectUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'); - t3lib_utility_Http::redirect($redirectUrl); - } - break; - case 2: - if (!t3lib_extMgm::isLoaded('dbal') && $this->isDbalSupported()) { - $this->activateDbal(); - } - break; - case 3: - $driver = $instObj->INSTALL['localconf.php']['typo_db_driver']; - if ($driver === 'mysql') { - $this->deactivateDbal(); - } - break; - } - } - } - - /** - * Returns TRUE if PHP modules to run DBAL are loaded. - * - * @return boolean - */ - protected function isDbalSupported() { - return extension_loaded('odbc') - || extension_loaded('pdo') - || extension_loaded('oci8'); - } - - /** - * Activates DBAL. - * - * @return void - */ - protected function activateDbal() { - $extList = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList']); - if (!t3lib_div::inArray($extList, 'adodb')) { - $extList[] = 'adodb'; - } - if (!t3lib_div::inArray($extList, 'dbal')) { - $extList[] = 'dbal'; - } - $this->updateExtensionList(implode(',', $extList)); - } - - /** - * Dectivates DBAL. - * - * @return void - */ - protected function deactivateDbal() { - $extList = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList']); - $extList = array_flip($extList); - - // Remove sysext dbal and adodb - if (isset($extList['dbal'])) { - unset($extList['dbal']); - } - if (isset($extList['adodb'])) { - unset($extList['adodb']); - } - $extList = array_flip($extList); - - $this->updateExtensionList(implode(',', $extList)); - } - - /** - * Updates the list of extensions. - * - * @param string $newExtList - * @return void - */ - protected function updateExtensionList($newExtList) { - // Instance of install tool - $instObj = t3lib_div::makeInstance('t3lib_install'); - $instObj->allowUpdateLocalConf = 1; - $instObj->updateIdentity = 'TYPO3 Core Update Manager'; - - try { - // Get lines from localconf file - $lines = $instObj->writeToLocalconf_control(); - $instObj->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXT\'][\'extList\']', $newExtList); - $result = $instObj->writeToLocalconf_control($lines); - if ($result === 'nochange') { - $message = 'DBAL was not loaded.'; - if (!@is_writable(PATH_typo3conf)) { - $message .= ' ' . PATH_typo3conf . ' is not writable!'; - } - throw new Exception($message); - } - - $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'] = $newExtList; - // Make sure to get cache file for backend, not frontend - $cacheFilePrefix = $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE']; - $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'] = str_replace('temp_CACHED_FE', 'temp_CACHED', $cacheFilePrefix); - t3lib_extMgm::removeCacheFiles(); - } catch (Exception $e) { - $header = 'Error'; - $message = $e->getMessage(); - t3lib_timeTrack::debug_typo3PrintError($header, $message, FALSE, t3lib_div::getIndpEnv('TYPO3_SITE_URL')); - exit; - } - } - -} - - -if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/class.tx_dbal_autoloader.php'])) { - include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/class.tx_dbal_autoloader.php']); -} - -// Make instance: -$SOBE = t3lib_div::makeInstance('tx_dbal_autoloader'); -$SOBE->execute($this); -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/class.tx_dbal_em.php b/typo3/sysext/dbal/class.tx_dbal_em.php deleted file mode 100644 index c79d1cc9bb565b34ad71ba195e3a0de62ea5b4e1..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/class.tx_dbal_em.php +++ /dev/null @@ -1,392 +0,0 @@ -<?php -/*************************************************************** - * Copyright notice - * - * (c) 2010 Xavier Perseguers <typo3@perseguers.ch> - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * A copy is found in the textfile GPL.txt and important notices to the license - * from the author is found in LICENSE.txt distributed with these scripts. - * - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -/** - * Hooks for TYPO3 Extension Manager. - * - * $Id: class.tx_dbal_em.php 40828 2010-12-05 14:55:53Z xperseguers $ - * - * @author Xavier Perseguers <typo3@perseguers.ch> - * - * @package TYPO3 - * @subpackage dbal - */ -class tx_dbal_em implements tx_em_Index_CheckDatabaseUpdatesHook { - - /** - * Maximal length for an identifier in Oracle. - * - * @var integer - */ - protected $maxIdentifierLength = 30; - - /** - * Table names should be short enough in order to let ADOdb generates - * the corresponding sequence for the auto-increment field 'uid'. - * That is, a sequence of the form {table}_uid - * - * @var integer - */ - protected $tableNameCharacterReservation = 4; - - /** - * Mapping of table and field names. - * - * @var array - */ - protected $mapping; - - /** - * Initializes internal variables. - * - * @return void - */ - protected function init() { - $mapping = @$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['mapping']; - if (!$mapping) { - $mapping = array(); - } - $this->mapping = $mapping; - } - - /** - * Hook that allows pre-processing of database structure modifications. - * This returns a user form that will temporarily replace the standard - * database update form to let user configure mapping. - * - * @param string $extKey: Extension key - * @param array $extInfo: Extension information array - * @param array $diff: Database differences - * @param t3lib_install $instObj: Instance of the installer - * @param SC_mod_tools_em_index $parent: The calling parent object - * @return string Either empty string or a pre-processing user form - */ - public function preProcessDatabaseUpdates($extKey, array $extInfo, array $diff, t3lib_install $instObj, SC_mod_tools_em_index $parent) { - $content = ''; - - // Remapping is only mandatory for Oracle: - if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['handlerCfg']['_DEFAULT']['type'] !== 'adodb' - && $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['handlerCfg']['_DEFAULT']['config']['driver'] !== 'oci8') { - - // Not using Oracle - return ''; - } - - $this->init(); - - if (t3lib_div::GPvar('dbal')) { - $this->updateMapping(t3lib_div::GPvar('dbal'), $instObj); - } - - // Search all table and field names which should be remapped - $tableCandidates = array(); - $fieldsCandidates = array(); - foreach ($diff['extra'] as $table => $config) { - if ($this->needsMapping($table)) { - $tableCandidates[] = $table; - } - foreach ($config['fields'] as $field => $type) { - if ($this->needsMapping($table, $field)) { - if (!isset($fieldsCandidates[$table])) { - $fieldsCandidates[$table] = array(); - } - $fieldsCandidates[$table][$field] = array( - 'fullName' => $field, - ); - } - - } - - /* - if (!isset($config['keys'])) { - continue; // Process next table - } - - foreach ($config['keys'] as $field => $def) { - if ($field !== 'PRIMARY' && $this->needsMapping($table, $field, TRUE)) { - if (!t3lib_div::inArray($tableCandidates, $table)) { - $tableCandidates[] = $table; - } - if (!isset($fieldsCandidates[$table])) { - $fieldsCandidates[$table] = array(); - } - $fieldsCandidates[$table][$field] = array( - 'fullName' => $table . '_' . $field, - ); - } - } - */ - } - - if ($tableCandidates || $fieldsCandidates) { - $mappingSuggestions = $this->getMappingSuggestions($extKey, $extInfo, $tableCandidates, $fieldsCandidates); - $content .= $this->generateMappingForm($tableCandidates, $fieldsCandidates, $mappingSuggestions); - } - - return $content; - } - - /** - * Returns TRUE if either the table or the field name should be remapped. - * - * @param string $table - * @param string $field - * @param boolean $isKeyField - * @return boolean TRUE if mapping is needed, otherwise FALSE - */ - protected function needsMapping($table, $field = '', $isKeyField = FALSE) { - $needsRemapping = FALSE; - - // Take existing DBAL mapping into account - $origTable = $table; - if (isset($this->mapping[$origTable])) { - if (isset($this->mapping[$origTable]['mapTableName'])) { - $table = $this->mapping[$origTable]['mapTableName']; - } - if ($field !== '' && isset($this->mapping[$origTable]['mapFieldNames'])) { - if (isset($this->mapping[$origTable]['mapFieldNames'][$field])) { - $field = $this->mapping[$origTable]['mapFieldNames'][$field]; - } - } - } - - if ($field === '') { - if (substr($table, -3) === '_mm') { - $needsRemapping = strlen($table) > $this->maxIdentifierLength; - } else { - $needsRemapping = strlen($table) > $this->maxIdentifierLength - $this->tableNameCharacterReservation; - } - } elseif (!$isKeyField) { - $needsRemapping = strlen($field) > $this->maxIdentifierLength; - } else { - $needsRemapping = strlen($table . '_' . $field) > $this->maxIdentifierLength; - } - - return $needsRemapping; - } - - /** - * Returns suggestions for the mapping of table/field names. - * - * @param string $extKey - * @param array $extInfo - * @param array $tables - * @param array $fields - * @return array - * @api - */ - public function getMappingSuggestions($extKey, array $extInfo, array $tables, array $fields) { - $suggestions = array(); - switch ($extKey) { - case 'direct_mail': - $suggestions['sys_dmail_ttaddress_category_mm'] = array( - 'mapTableName' => 'sys_dmail_ttaddress_cat_mm', - ); - $suggestions['sys_dmail_ttcontent_category_mm'] = array( - 'mapTableName' => 'sys_dmail_ttcontent_cat_mm', - ); - break; - case 'extbase': - $suggestions['tx_extbase_cache_reflection_tags'] = array( - 'mapTableName' => 'tx_extbase_cache_reflect_tags', - ); - break; - case 'templavoila': - $suggestions['tx_templavoila_datastructure'] = array( - 'mapTableName' => 'tx_templavoila_ds', - ); - $suggestions['tx_templavoila_tmplobj'] = array( - 'mapTableName' => 'tx_templavoila_tmpl', - ); - break; - default: - $dependencies = array_keys($extInfo['EM_CONF']['constraints']['depends']); - if (t3lib_div::inArray($dependencies, 'extbase')) { - $this->storeExtbaseMappingSuggestions($suggestions, $extKey, $extInfo, $tables, $fields); - } - } - - // Existing mapping take precedence over suggestions - $suggestions = t3lib_div::array_merge_recursive_overrule($suggestions, $this->mapping); - - return $suggestions; - } - - /** - * Stores suggestions for the mapping of table/field names for an Extbase-based extension. - * - * @param array &$suggestions - * @param string $extKey - * @param array $extInfo - * @param array $tables - * @param array $fields - * @return void - */ - protected function storeExtbaseMappingSuggestions(array &$suggestions, $extKey, array $extInfo, array $tables, array $fields) { - foreach ($tables as $table) { - // Remove the "domain_model" part of the table name - $suggestions[$table] = array( - 'mapTableName' => str_replace('domain_model_', '', $table), - ); - } - } - - /** - * Generates a mapping form. - * - * @param array $tables - * @param array $fields - * @param array $suggestions - * @return string - */ - protected function generateMappingForm(array $tables, array $fields, array $suggestions) { - $out = array(); - $tableId = uniqid('table'); - $label = 'DBAL Mapping'; - $description = sprintf('Some table names are longer than %s characters and/or some field names are longer than %s characters.' - . ' This is incompatible with your database:' - . ' <ul style="list-style: square; margin: 3px 1em; padding: 3px 1em;">' - . ' <li>Table names should be short enough to let ADOdb generates a sequence of the form {table}_uid for the' - . ' auto-increment "uid" field within %s characters;</li>' - . ' <li>Field names may not contain more than %s characters.</li>' - . ' </ul>', - $this->maxIdentifierLength - $this->tableNameCharacterReservation, - $this->maxIdentifierLength, - $this->maxIdentifierLength, - $this->maxIdentifierLength - ); - - $tables = array_unique(array_merge($tables, array_keys($fields))); - foreach ($tables as $table) { - $newTableName = $table; - if (isset($suggestions[$table]) && isset($suggestions[$table]['mapTableName'])) { - $newTableName = $suggestions[$table]['mapTableName']; - } - $out[] = ' - <tr> - <td style="padding-top: 1em;"><label for="table-' . $table . '">' . $table . '</label></td> - <td style="padding-top: 1em;">=></td> - <td style="padding-top: 1em;"><input type="text" size="35" id="table-' . $table . '" name="dbal[tables][' . $table . ']" value="' . $newTableName . '" /> ' - . strlen($newTableName) . ' characters' - . '</td> - </tr>'; - - if (isset($fields[$table])) { - foreach ($fields[$table] as $field => $info) { - $newFieldName = $field; - if (isset($suggestions[$table]) && isset($suggestions[$table]['mapFieldNames'])) { - if (isset($suggestions[$table]['mapFieldNames'][$field])) { - $newFieldName = $suggestions[$table]['mapFieldNames'][$field]; - } - } - $newFieldFullName = preg_replace('/^' . $table . '/', $newTableName, $info['fullName']); - $newFieldFullName = preg_replace('/' . $field . '$/', $newFieldName, $newFieldFullName); - $out[] = ' - <tr> - <td> <label for="field-' . $table . '_' . $field . '">' . $field . '</label></td> - <td>=></td> - <td><input type="text" size="35" id="field-' . $table . '_' . $field . '" name="dbal[fields][' . $table . '][' . $field . ']" value="' . $newFieldName . '" /> ' - . ($info['fullname'] !== $field ? strlen($newFieldFullName) . ' characters: ' . $newFieldFullName : '') - . '</td> - </tr>'; - } - } - } - - // Compile rows: - $content = ' - <!-- Remapping database fields / tables --> - <h3>' . $label . '</h3> - <p>' . $description . '</p> - <table border="0" cellpadding="2" cellspacing="2" id="' . $tableId . '" class="remap-db-table-fields">' . implode('', $out) . ' - </table>'; - - return $content; - } - - /** - * Updates the mapping in localconf.php according to form input values. - * - * @param array $data - * @param t3lib_install $instObj - * @return void - * @api - */ - public function updateMapping(array $data, t3lib_install $instObj) { - $newMapping = $this->mapping; - - foreach ($data['tables'] as $table => $newName) { - $newName = trim($newName); - if ($newName && $newName !== $table) { - if (!isset($newMapping[$table])) { - $newMapping[$table] = array(); - } - $newMapping[$table]['mapTableName'] = $newName; - } - if (isset($data['fields'][$table])) { - foreach ($data['fields'][$table] as $field => $newName) { - $newName = trim($newName); - if ($newName && $newName !== $field) { - if (!isset($newMapping[$table])) { - $newMapping[$table] = array(); - } - if (!isset($newMapping[$table]['mapFieldNames'])) { - $newMapping[$table]['mapFieldNames'] = array(); - } - $newMapping[$table]['mapFieldNames'][$field] = $newName; - } - } - } - } - - // Sort table and field names - foreach ($newMapping as $table => &$config) { - if (isset($config['mapFieldNames'])) { - ksort($config['mapFieldNames']); - } - } - ksort($newMapping); - - // Write new mapping to localconf.php - $key = '$TYPO3_CONF_VARS[\'EXTCONF\'][\'dbal\'][\'mapping\']'; - $instObj->allowUpdateLocalConf = 1; - $instObj->updateIdentity = 'TYPO3 Extension Manager'; - $lines = $instObj->writeToLocalconf_control(); - $instObj->setArrayValueInLocalconfFile($lines, $key, $newMapping); - - if ($instObj->writeToLocalconf($lines)) { - $this->mapping = $newMapping; - } - } - -} - - -if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/class.tx_dbal_em.php'])) { - include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/class.tx_dbal_em.php']); -} -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/class.tx_dbal_installtool.php b/typo3/sysext/dbal/class.tx_dbal_installtool.php deleted file mode 100644 index 705e850cac57e7926c00c42024420edb19f9718d..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/class.tx_dbal_installtool.php +++ /dev/null @@ -1,587 +0,0 @@ -<?php -/*************************************************************** - * Copyright notice - * - * (c) 2010 Xavier Perseguers <typo3@perseguers.ch> - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * A copy is found in the textfile GPL.txt and important notices to the license - * from the author is found in LICENSE.txt distributed with these scripts. - * - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -/** - * Hooks for TYPO3 Install Tool. - * - * $Id$ - * - * @author Xavier Perseguers <typo3@perseguers.ch> - * - * @package TYPO3 - * @subpackage dbal - */ -class tx_dbal_installtool { - - /** - * @var string - */ - protected $templateFilePath = 'res/Templates/'; - - /** - * @var array - */ - protected $supportedDrivers; - - /** - * @var array - */ - protected $availableDrivers; - - /** - * @var string - */ - protected $driver; - - /** - * Default constructor. - */ - public function __construct() { - $this->supportedDrivers = $this->getSupportedDrivers(); - $this->availableDrivers = $this->getAvailableDrivers(); - - $configDriver =& $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['handlerCfg']['_DEFAULT']['config']['driver']; - $this->driver = t3lib_div::_GET('driver'); - if (!$this->driver && $configDriver) { - $this->driver = $configDriver; - } - } - - /** - * Hooks into Installer to set required PHP modules. - * - * @param array $modules - * @param tx_install $instObj - * @return array modules - */ - public function setRequiredPhpModules(array &$modules, tx_install $instObj) { - foreach ($modules as $key => $module) { - if ($module === 'mysql') { - $dbModules = array(); - foreach ($this->supportedDrivers as $abstractionLayer => $drivers) { - $dbModules = array_merge($dbModules, array_keys($drivers)); - } - $module = $dbModules; - } - $modifiedModules[] = $module; - } - return $modifiedModules; - } - - /** - * Hooks into Installer to let a non-MySQL database to be configured. - * - * @param array $markers - * @param integer $step - * @param tx_install $instObj - * @return void - */ - public function executeStepOutput(array &$markers, $step, tx_install $instObj) { - switch ($step) { - case 2: - $this->createConnectionForm($markers, $instObj); - break; - case 3: - $this->createDatabaseForm($markers, $instObj); - break; - } - } - - /** - * Hooks into Installer to modify lines to be written to localconf.php. - * - * @param array $lines - * @param integer $step - * @param tx_install $instObj - * @return void - */ - public function executeWriteLocalconf(array &$lines, $step, tx_install $instObj) { - switch ($step) { - case 3: - case 4: - $driver = $instObj->INSTALL['localconf.php']['typo_db_driver']; - if (!$driver && $this->driver) { - // Driver was already configured - break; - } - $driverConfig = ''; - switch ($driver) { - case 'oci8': - $driverConfig = '\'driverOptions\' => array(' . - '\'connectSID\' => ' . ($instObj->INSTALL['localconf.php']['typo_db_type'] === 'sid' ? 'TRUE' : 'FALSE') . - ')'; - break; - case 'mssql': - case 'odbc_mssql': - $driverConfig = '\'useNameQuote\' => TRUE'; - break; - case 'mysql': - return; - } - $config = 'array(' . - '\'_DEFAULT\' => array(' . - '\'type\' => \'adodb\',' . - '\'config\' => array(' . - '\'driver\' => \'' . $driver . '\',' . - $driverConfig . - ')' . - ')' . - ');'; - $instObj->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXTCONF\'][\'dbal\'][\'handlerCfg\']', $config, FALSE); - break; - } - } - - /** - * Creates a specialized form to configure the DBMS connection. - * - * @param array $markers - * @param tx_install $instObj - * @return void - */ - protected function createConnectionForm(array &$markers, tx_install $instObj) { - // Normalize current driver - if (!$this->driver) { - $this->driver = $this->getDefaultDriver(); - } - - // Get the template file - $templateFile = @file_get_contents( - t3lib_extMgm::extPath('dbal') . $this->templateFilePath . 'install.html' - ); - // Get the template part from the file - $template = t3lib_parsehtml::getSubpart( - $templateFile, '###TEMPLATE###' - ); - - // Get the subpart for the connection form - $formSubPart = t3lib_parsehtml::getSubpart( - $template, '###CONNECTION_FORM###' - ); - if ($this->getNumberOfAvailableDrivers() == 1 && $this->getDefaultDriver() === 'mysql') { - // Only MySQL is actually available (PDO support may be compiled in - // PHP itself and as such DBAL was activated, behaves as if DBAL were - // not activated - $driverSubPart = '<input type="hidden" name="TYPO3_INSTALL[localconf.php][typo_db_driver]" value="mysql" />'; - } else { - $driverTemplate = t3lib_parsehtml::getSubpart( - $formSubPart, '###DATABASE_DRIVER###' - ); - $driverSubPart = $this->prepareDatabaseDrivers($driverTemplate); - } - $formSubPart = t3lib_parsehtml::substituteSubpart( - $formSubPart, - '###DATABASE_DRIVER###', - $driverSubPart - ); - - // Get the subpart related to selected database driver - if ($this->driver === '' || $this->driver === 'mysql') { - $driverOptionsSubPart = t3lib_parsehtml::getSubpart( - $template, '###DRIVER_MYSQL###' - ); - } else { - $driverOptionsSubPart = t3lib_parsehtml::getSubpart( - $template, '###DRIVER_' . t3lib_div::strtoupper($this->driver) . '###' - ); - if ($driverOptionsSubPart === '') { - $driverOptionsSubPart = t3lib_parsehtml::getSubpart( - $template, '###DRIVER_DEFAULT###' - ); - } - } - - // Define driver-specific markers - $driverMarkers = array(); - switch ($this->driver) { - case 'mssql': - $driverMarkers = array( - 'labelUsername' => 'Username', - 'username' => TYPO3_db_username, - 'labelPassword' => 'Password', - 'password' => TYPO3_db_password, - 'labelHost' => 'Host', - 'host' => TYPO3_db_host ? TYPO3_db_host : 'windows', - 'labelDatabase' => 'Database', - 'database' => TYPO3_db, - ); - $nextStep = $instObj->step + 2; - break; - case 'odbc_mssql': - $driverMarkers = array( - 'labelUsername' => 'Username', - 'username' => TYPO3_db_username, - 'labelPassword' => 'Password', - 'password' => TYPO3_db_password, - 'labelHost' => 'Host', - 'host' => TYPO3_db_host ? TYPO3_db_host : 'windows', - 'database' => 'dummy_string', - ); - $nextStep = $instObj->step + 2; - break; - case 'oci8': - $driverMarkers = array( - 'labelUsername' => 'Username', - 'username' => TYPO3_db_username, - 'labelPassword' => 'Password', - 'password' => TYPO3_db_password, - 'labelHost' => 'Host', - 'host' => TYPO3_db_host ? TYPO3_db_host : 'localhost', - 'labelType' => 'Type', - 'labelSID' => 'SID', - 'labelServiceName' => 'Service Name', - 'labelDatabase' => 'Name', - 'database' => TYPO3_db, - ); - $nextStep = $instObj->step + 2; - break; - case 'postgres': - $driverMarkers = array( - 'labelUsername' => 'Username', - 'username' => TYPO3_db_username, - 'labelPassword' => 'Password', - 'password' => TYPO3_db_password, - 'labelHost' => 'Host', - 'host' => TYPO3_db_host ? TYPO3_db_host : 'localhost', - 'labelDatabase' => 'Database', - 'database' => TYPO3_db, - ); - $nextStep = $instObj->step + 2; - break; - default: - $driverMarkers = array( - 'labelUsername' => 'Username', - 'username' => TYPO3_db_username, - 'labelPassword' => 'Password', - 'password' => TYPO3_db_password, - 'labelHost' => 'Host', - 'host' => TYPO3_db_host ? TYPO3_db_host : 'localhost', - 'labelDatabase' => 'Database', - 'database' => TYPO3_db, - ); - $nextStep = $instObj->step + 1; - break; - } - - // Add header marker for main template - $markers['header'] = 'Connect to your database host'; - // Define the markers content for the subpart - $subPartMarkers = array( - 'step' => $nextStep, - 'action' => htmlspecialchars($instObj->action), - 'encryptionKey' => $instObj->createEncryptionKey(), - 'branch' => TYPO3_branch, - 'driver_options' => $driverOptionsSubPart, - 'continue' => 'Continue', - 'llDescription' => 'If you have not already created a username and password to access the database, please do so now. This can be done using tools provided by your host.' - ); - $subPartMarkers = array_merge($subPartMarkers, $driverMarkers); - - // Add step marker for main template - $markers['step'] = t3lib_parsehtml::substituteMarkerArray( - $formSubPart, - $subPartMarkers, - '###|###', - 1, - 1 - ); - } - - /** - * Prepares the list of database drivers for step 2. - * - * @param string $template - * @return string - */ - protected function prepareDatabaseDrivers($template) { - $subParts = array( - 'abstractionLayer' => t3lib_parsehtml::getSubpart($template, '###ABSTRACTION_LAYER###'), - 'vendor' => t3lib_parsehtml::getSubpart($template, '###VENDOR###'), - ); - - // Create the drop-down list of available drivers - $dropdown = ''; - foreach ($this->availableDrivers as $abstractionLayer => $drivers) { - $options = array(); - foreach ($drivers as $driver => $label) { - $markers = array( - 'driver' => $driver, - 'labelvendor' => $label, - 'onclick' => 'document.location=\'index.php?TYPO3_INSTALL[type]=config&mode=123&step=2&driver=' . $driver . '\';', - 'selected' => '', - ); - if ($driver === $this->driver) { - $markers['selected'] .= ' selected="selected"'; - } - $options[] = t3lib_parsehtml::substituteMarkerArray( - $subParts['vendor'], - $markers, - '###|###', - 1 - ); - } - $subPart = t3lib_parsehtml::substituteSubpart( - $subParts['abstractionLayer'], - '###VENDOR###', - implode("\n", $options) - ); - $dropdown .= t3lib_parsehtml::substituteMarker( - $subPart, - '###LABELABSTRACTIONLAYER###', - $abstractionLayer - ); - } - $form = t3lib_parsehtml::substituteSubpart( - $template, - '###ABSTRACTION_LAYER###', - $dropdown - ); - $form = t3lib_parsehtml::substituteMarker( - $form, - '###LABELDRIVER###', - 'Driver' - ); - return $form; - } - - /** - * Returns a list of DBAL supported database drivers, with a user-friendly name - * and any PHP module dependency. - * - * @return array - */ - protected function getSupportedDrivers() { - $supportedDrivers = array( - 'Native' => array( - 'mysql' => array( - 'label' => 'MySQL/MySQLi (recommended)', - 'combine' => 'OR', - 'extensions' => array('mysql', 'mysqli'), - ), - 'mssql' => array( - 'label' => 'Microsoft SQL Server', - 'extensions' => array('mssql'), - ), - 'oci8' => array( - 'label' => 'Oracle OCI8', - 'extensions' => array('oci8'), - ), - 'postgres' => array( - 'label' => 'PostgreSQL', - 'extensions' => array('pgsql'), - ) - ), - 'ODBC' => array( - 'odbc_mssql' => array( - 'label' => 'Microsoft SQL Server', - 'extensions' => array('odbc', 'mssql'), - ), - ), - ); - return $supportedDrivers; - } - - /** - * Returns a list of database drivers that are available on current server. - * - * @return array - */ - protected function getAvailableDrivers() { - $availableDrivers = array(); - foreach ($this->supportedDrivers as $abstractionLayer => $drivers) { - foreach ($drivers as $driver => $info) { - if (isset($info['combine']) && $info['combine'] === 'OR') { - $isAvailable = FALSE; - } else { - $isAvailable = TRUE; - } - - // Loop through each PHP module dependency to ensure it is loaded - foreach ($info['extensions'] as $extension) { - if (isset($info['combine']) && $info['combine'] === 'OR') { - $isAvailable |= extension_loaded($extension); - } else { - $isAvailable &= extension_loaded($extension); - } - } - - if ($isAvailable) { - if (!isset($availableDrivers[$abstractionLayer])) { - $availableDrivers[$abstractionLayer] = array(); - } - $availableDrivers[$abstractionLayer][$driver] = $info['label']; - } - } - } - return $availableDrivers; - } - - /** - * Returns the number of available drivers. - * - * @return boolean - */ - protected function getNumberOfAvailableDrivers() { - $count = 0; - foreach ($this->availableDrivers as $drivers) { - $count += count($drivers); - } - return $count; - } - - /** - * Returns the driver that is selected by default in the - * Install Tool dropdown list. - * - * @return string - */ - protected function getDefaultDriver() { - $defaultDriver = ''; - if (count($this->availableDrivers)) { - $abstractionLayers = array_keys($this->availableDrivers); - $drivers = array_keys($this->availableDrivers[$abstractionLayers[0]]); - $defaultDriver = $drivers[0]; - } - return $defaultDriver; - } - - /** - * Creates a specialized form to configure the database. - * - * @param array $markers - * @param tx_install $instObj - */ - protected function createDatabaseForm(array &$markers, tx_install $instObj) { - $error_missingConnect = ' - <p class="typo3-message message-error"> - <strong> - There is no connection to the database! - </strong> - <br /> - (Username: <em>' . TYPO3_db_username . '</em>, - Host: <em>' . TYPO3_db_host . '</em>, - Using Password: YES) - <br /> - Go to Step 1 and enter a valid username and password! - </p> - '; - - // Add header marker for main template - $markers['header'] = 'Select database'; - // There should be a database host connection at this point - if ($result = $GLOBALS['TYPO3_DB']->sql_pconnect( - TYPO3_db_host, TYPO3_db_username, TYPO3_db_password - )) { - // Get the template file - $templateFile = @file_get_contents( - t3lib_extMgm::extPath('dbal') . $this->templateFilePath . 'install.html' - ); - // Get the template part from the file - $template = t3lib_parsehtml::getSubpart( - $templateFile, '###TEMPLATE###' - ); - // Get the subpart for the database choice step - $formSubPart = t3lib_parsehtml::getSubpart( - $template, '###DATABASE_FORM###' - ); - // Get the subpart for the database options - $step3DatabaseOptionsSubPart = t3lib_parsehtml::getSubpart( - $formSubPart, '###DATABASEOPTIONS###' - ); - - $dbArr = $instObj->getDatabaseList(); - $dbIncluded = FALSE; - foreach ($dbArr as $dbname) { - // Define the markers content for database options - $step3DatabaseOptionMarkers = array( - 'databaseValue' => htmlspecialchars($dbname), - 'databaseSelected' => ($dbname === TYPO3_db) ? 'selected="selected"' : '', - 'databaseName' => htmlspecialchars($dbname) - ); - // Add the option HTML to an array - $step3DatabaseOptions[] = t3lib_parsehtml::substituteMarkerArray( - $step3DatabaseOptionsSubPart, - $step3DatabaseOptionMarkers, - '###|###', - 1, - 1 - ); - if ($dbname === TYPO3_db) { - $dbIncluded = TRUE; - } - } - if (!$dbIncluded && TYPO3_db) { - // // Define the markers content when no access - $step3DatabaseOptionMarkers = array( - 'databaseValue' => htmlspecialchars(TYPO3_db), - 'databaseSelected' => 'selected="selected"', - 'databaseName' => htmlspecialchars(TYPO3_db) . ' (NO ACCESS!)' - ); - // Add the option HTML to an array - $step3DatabaseOptions[] = t3lib_parsehtml::substituteMarkerArray( - $step3DatabaseOptionsSubPart, - $step3DatabaseOptionMarkers, - '###|###', - 1, - 1 - ); - } - // Substitute the subpart for the database options - $content = t3lib_parsehtml::substituteSubpart( - $formSubPart, - '###DATABASEOPTIONS###', - implode(chr(10), $step3DatabaseOptions) - ); - // Define the markers content - $step3SubPartMarkers = array( - 'step' => $instObj->step + 1, - 'action' => htmlspecialchars($instObj->action), - 'llOption2' => 'Select an EMPTY existing database:', - 'llRemark2' => 'Any tables used by TYPO3 will be overwritten.', - 'continue' => 'Continue' - ); - // Add step marker for main template - $markers['step'] = t3lib_parsehtml::substituteMarkerArray( - $content, - $step3SubPartMarkers, - '###|###', - 1, - 1 - ); - } else { - // Add step marker for main template when no connection - $markers['step'] = $error_missingConnect; - } - } - -} - - -if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/class.tx_dbal_installtool.php'])) { - include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/class.tx_dbal_installtool.php']); -} -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/class.ux_db_list_extra.php b/typo3/sysext/dbal/class.ux_db_list_extra.php deleted file mode 100644 index c40fa5c55859a60c81995cf7eb9257a17d165c36..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/class.ux_db_list_extra.php +++ /dev/null @@ -1,109 +0,0 @@ -<?php -/*************************************************************** -* Copyright notice -* -* (c) 1999-2009 Kasper Skårhøj (kasperYYYY@typo3.com) -* (c) 2006-2009 Karsten Dambekalns <karsten@typo3.org> -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* A copy is found in the textfile GPL.txt and important notices to the license -* from the author is found in LICENSE.txt distributed with these scripts. -* -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ -/** - * Include file extending localRecordList for DBAL compatibility - * - * $Id: class.ux_db_list_extra.php 40828 2010-12-05 14:55:53Z xperseguers $ - * - * @author Kasper Skårhøj <kasperYYYY@typo3.com> - * @author Karsten Dambekalns <k.dambekalns@fishfarm.de> - */ - -/** - * Child class for rendering of Web > List (not the final class. see class.db_list_extra) - * - * @author Kasper Skårhøj <kasperYYYY@typo3.com> - * @author Karsten Dambekalns <k.dambekalns@fishfarm.de> - * @package TYPO3 - * @subpackage DBAL - */ -class ux_localRecordList extends localRecordList { - - /** - * Creates part of query for searching after a word ($this->searchString) fields in input table - * - * DBAL specific: no LIKE for numeric fields, in this case "uid" (breaks on Oracle) - * no LIKE for BLOB fields, skip - * - * @param string Table, in which the fields are being searched. - * @return string Returns part of WHERE-clause for searching, if applicable. - */ - function makeSearchString($table) { - // Make query, only if table is valid and a search string is actually defined: - if ($GLOBALS['TCA'][$table] && $this->searchString) { - - // Loading full table description - we need to traverse fields: - t3lib_div::loadTCA($table); - - // Initialize field array: - $sfields = array(); - $or = ''; - - // add the uid only if input is numeric, cast to int - if (is_numeric($this->searchString)) { - $queryPart = ' AND (uid=' . (int)$this->searchString . ' OR '; - } else { - $queryPart = ' AND ('; - } - - if ($GLOBALS['TYPO3_DB']->runningADOdbDriver('oci8')) { - foreach ($GLOBALS['TCA'][$table]['columns'] as $fieldName => $info) { - if ($GLOBALS['TYPO3_DB']->cache_fieldType[$table][$fieldName]['metaType'] === 'B') { - // skip, LIKE is not supported on BLOB columns... - } elseif ($info['config']['type'] === 'text' || ($info['config']['type'] === 'input' && !preg_match('/date|time|int/', $info['config']['eval']))) { - $queryPart .= $or . $fieldName . ' LIKE \'%' . $GLOBALS['TYPO3_DB']->quoteStr($this->searchString, $table) . '%\''; - $or = ' OR '; - } - } - } else { - // Traverse the configured columns and add all columns that can be searched - foreach ($GLOBALS['TCA'][$table]['columns'] as $fieldName => $info) { - if ($info['config']['type'] === 'text' || ($info['config']['type'] === 'input' && !preg_match('/date|time|int/', $info['config']['eval']))) { - $sfields[] = $fieldName; - } - } - - // If search-fields were defined (and there always are) we create the query: - if (count($sfields)) { - $like = ' LIKE \'%'.$GLOBALS['TYPO3_DB']->quoteStr($this->searchString, $table) . '%\''; // Free-text - $queryPart .= implode($like . ' OR ', $sfields) . $like; - } - } - - // Return query: - return $queryPart . ')'; - } - } -} - - -if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/class.ux_db_list_extra.php'])) { - include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/class.ux_db_list_extra.php']); -} - -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/class.ux_t3lib_db.php b/typo3/sysext/dbal/class.ux_t3lib_db.php deleted file mode 100644 index faedcf6d0ab36e7796ae9138987f68aeb8f0a3ed..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/class.ux_t3lib_db.php +++ /dev/null @@ -1,3891 +0,0 @@ -<?php -/*************************************************************** - * Copyright notice - * - * (c) 2004-2009 Kasper Skårhøj (kasperYYYY@typo3.com) - * (c) 2004-2009 Karsten Dambekalns <karsten@typo3.org> - * (c) 2009-2010 Xavier Perseguers <typo3@perseguers.ch> - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * A copy is found in the textfile GPL.txt and important notices to the license - * from the author is found in LICENSE.txt distributed with these scripts. - * - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ -/** - * Contains a database abstraction layer class for TYPO3 - * - * $Id: class.ux_t3lib_db.php 42596 2011-01-25 20:02:07Z xperseguers $ - * - * @author Kasper Skårhøj <kasper@typo3.com> - * @author Karsten Dambekalns <k.dambekalns@fishfarm.de> - * @author Xavier Perseguers <typo3@perseguers.ch> - */ -/** - * [CLASS/FUNCTION INDEX of SCRIPT] - * - * - * - * 161: class ux_t3lib_DB extends t3lib_DB - * 229: public function __construct() - * 260: protected function initInternalVariables() - * 283: public function clearCachedFieldInfo() - * 294: public function cacheFieldInfo() - * 342: protected function analyzeFields($parsedExtSQL) - * 375: protected function mapCachedFieldInfo($fieldInfo) - * - * SECTION: Query Building (Overriding parent methods) - * 438: public function exec_INSERTquery($table, $fields_values, $no_quote_fields = '') - * 575: public function exec_INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = FALSE) - * 600: public function exec_UPDATEquery($table,$where,$fields_values,$no_quote_fields = '') - * 692: public function exec_DELETEquery($table, $where) - * 759: public function exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '') - * 856: public function exec_TRUNCATEquery($table) - * 914: protected function exec_query(array $queryParts) - * - * SECTION: Query building - * 978: public function INSERTquery($table, $fields_values, $no_quote_fields = '') - * 1052: public function INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = FALSE) - * 1085: public function UPDATEquery($table, $where, $fields_values, $no_quote_fields = '') - * 1170: public function DELETEquery($table, $where) - * 1196: public function SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '') - * 1229: protected function SELECTqueryFromArray(array $params) - * 1267: protected function compileSelectParameters(array $params) - * 1283: public function TRUNCATEquery($table) - * - * SECTION: Prepared Query Support - * 1314: public function prepare_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '', array $input_parameters = array()) - * 1416: protected function getQueryComponents($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit) - * 1465: protected function precompileSELECTquery(array $components) - * 1523: public function exec_PREPAREDquery($query, array $precompiledParts) - * - * SECTION: Functions for quoting table/field names - * 1619: protected function quoteSELECTsubquery(array $components) - * 1634: public function quoteSelectFields($select_fields) - * 1644: public function quoteFieldNames($select_fields) - * 1664: protected function _quoteFieldNames(array $select_fields) - * 1701: public function quoteFromTables($from_table) - * 1717: protected function _quoteFromTables(array $from_table) - * 1746: public function quoteWhereClause($where_clause) - * 1767: protected function _quoteWhereClause(array $where_clause) - * 1843: protected function quoteGroupBy($groupBy) - * 1860: protected function _quoteGroupBy(array $groupBy) - * 1877: protected function quoteOrderBy($orderBy) - * 1894: protected function _quoteOrderBy(array $orderBy) - * - * SECTION: Various helper functions - * 1919: public function fullQuoteStr($str, $table) - * 1932: public function quoteStr($str, $table) - * 1965: public function quoteName($name, $handlerKey = NULL, $useBackticks = FALSE) - * 1984: public function MetaType($type, $table, $max_length = -1) - * 2015: public function MySQLMetaType($t) - * 2062: public function MySQLActualType($meta) - * - * SECTION: SQL wrapper functions (Overriding parent methods) - * 2105: public function sql_error() - * 2125: public function sql_errno() - * 2146: public function sql_num_rows(&$res) - * 2170: public function sql_fetch_assoc(&$res) - * 2233: public function sql_fetch_row(&$res) - * 2279: public function sql_free_result(&$res) - * 2308: public function sql_insert_id() - * 2328: public function sql_affected_rows() - * 2350: public function sql_data_seek(&$res, $seek) - * 2375: public function sql_field_metatype($table, $field) - * 2405: public function sql_field_type(&$res,$pointer) - * - * SECTION: Legacy functions, bound to _DEFAULT handler. (Overriding parent methods) - * 2459: public function sql($db,$query) - * 2477: public function sql_query($query) - * 2516: public function sql_pconnect($TYPO3_db_host, $TYPO3_db_username, $TYPO3_db_password) - * 2534: public function sql_select_db($TYPO3_db) - * - * SECTION: SQL admin functions - * 2566: public function admin_get_dbs() - * 2607: public function admin_get_tables() - * 2673: public function admin_get_fields($tableName) - * 2742: public function admin_get_keys($tableName) - * 2847: public function admin_get_charsets() - * 2857: public function admin_query($query) - * - * SECTION: Handler management - * 2941: public function handler_getFromTableList($tableList) - * 2989: public function handler_init($handlerKey) - * 3107: public function isConnected() - * 3127: public function runningNative() - * 3138: public function runningADOdbDriver($driver) - * - * SECTION: Table/Field mapping - * 3165: protected function map_needMapping($tableList, $fieldMappingOnly = FALSE, array &$parsedTableList = array()) - * 3215: protected function map_assocArray($input, $tables, $rev = FALSE) - * 3263: protected function map_remapSELECTQueryParts($select_fields, $from_table, $where_clause, $groupBy, $orderBy) - * 3357: protected function getMappingKey($tableName) - * 3371: protected function getFreeMappingKey($tableName) - * 3387: protected function map_sqlParts(&$sqlPartArray, $defaultTable) - * 3549: protected function map_subquery(&$parsedQuery) - * 3589: protected function map_genericQueryParsed(&$parsedQuery) - * 3654: protected function map_fieldNamesInArray($table,&$fieldArray) - * - * SECTION: Debugging - * 3695: public function debugHandler($function,$execTime,$inData) - * 3790: public function debug_WHERE($table, $where, $script = '') - * 3813: public function debug_log($query,$ms,$data,$join,$errorFlag, $script='') - * 3846: public function debug_explain($query) - * - * TOTAL FUNCTIONS: 82 - * (This index is automatically created/updated by the extension "extdeveval") - * - */ -/** - * TYPO3 database abstraction layer - * - * @author Kasper Skårhøj <kasper@typo3.com> - * @author Karsten Dambekalns <k.dambekalns@fishfarm.de> - * @package TYPO3 - * @subpackage tx_dbal - */ -class ux_t3lib_DB extends t3lib_DB { - - // Internal, static: - var $printErrors = FALSE; // Enable output of SQL errors after query executions. Set through TYPO3_CONF_VARS, see init() - var $debug = FALSE; // Enable debug mode. Set through TYPO3_CONF_VARS, see init() - var $conf = array(); // Configuration array, copied from TYPO3_CONF_VARS in constructor. - - var $mapping = array(); // See manual. - var $table2handlerKeys = array(); // See manual. - var $handlerCfg = array( // See manual. - '_DEFAULT' => array( - 'type' => 'native', - 'config' => array( - 'username' => '', // Set by default (overridden) - 'password' => '', // Set by default (overridden) - 'host' => '', // Set by default (overridden) - 'database' => '', // Set by default (overridden) - 'driver' => '', // ONLY "adodb" type; eg. "mysql" - 'sequenceStart' => 1, // ONLY "adodb", first number in sequences/serials/... - 'useNameQuote' => 0 // ONLY "adodb", whether to use NameQuote() method from ADOdb to quote names - ) - ), - ); - - - // Internal, dynamic: - var $handlerInstance = array(); // Contains instance of the handler objects as they are created. Exception is the native mySQL calls which are registered as an array with keys "handlerType" = "native" and "link" pointing to the link resource for the connection. - var $lastHandlerKey = ''; // Storage of the handler key of last ( SELECT) query - used for subsequent fetch-row calls etc. - var $lastQuery = ''; // Storage of last SELECT query - var $lastParsedAndMappedQueryArray = array(); // Query array, the last one parsed - - var $resourceIdToTableNameMap = array(); // Mapping of resource ids to table names. - - // Internal, caching: - var $cache_handlerKeyFromTableList = array(); // Caching handlerKeys for table lists - var $cache_mappingFromTableList = array(); // Caching mapping information for table lists - var $cache_autoIncFields = array(); // parsed SQL from standard DB dump file - var $cache_fieldType = array(); // field types for tables/fields - var $cache_primaryKeys = array(); // primary keys - - /** - * SQL parser - * - * @var tx_dbal_sqlengine - */ - var $SQLparser; - - /** - * Installer - * - * @var t3lib_install - */ - var $Installer; - - /** - * Cache for queries - * - * @var t3lib_cache_frontend_VariableFrontend - */ - protected $queryCache; - - - /** - * Constructor. - * Creates SQL parser object and imports configuration from $TYPO3_CONF_VARS['EXTCONF']['dbal'] - */ - public function __construct() { - // Set SQL parser object for internal use: - $this->SQLparser = t3lib_div::makeInstance('tx_dbal_sqlengine'); - $this->Installer = t3lib_div::makeInstance('t3lib_install'); - - if (TYPO3_UseCachingFramework) { - tx_dbal_querycache::initializeCachingFramework(); - - try { - $this->queryCache = $GLOBALS['typo3CacheManager']->getCache( - 'dbal' - ); - } catch (t3lib_cache_exception_NoSuchCache $e) { - tx_dbal_querycache::initDbalCache(); - - $this->queryCache = $GLOBALS['typo3CacheManager']->getCache( - 'dbal' - ); - } - } - - // Set internal variables with configuration: - $this->conf = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']; - $this->initInternalVariables(); - } - - /** - * Setting internal variables from $this->conf. - * - * @return void - */ - protected function initInternalVariables() { - // Set outside configuration: - if (isset($this->conf['mapping'])) { - $this->mapping = $this->conf['mapping']; - } - if (isset($this->conf['table2handlerKeys'])) { - $this->table2handlerKeys = $this->conf['table2handlerKeys']; - } - if (isset($this->conf['handlerCfg'])) { - $this->handlerCfg = $this->conf['handlerCfg']; - } - - $this->cacheFieldInfo(); - // Debugging settings: - $this->printErrors = $this->conf['debugOptions']['printErrors'] ? TRUE : FALSE; - $this->debug = $this->conf['debugOptions']['enabled'] ? TRUE : FALSE; - } - - /** - * Clears the cached field information file. - * - * @return void - */ - public function clearCachedFieldInfo() { - if (file_exists(PATH_typo3conf . 'temp_fieldInfo.php')) { - unlink(PATH_typo3conf . 'temp_fieldInfo.php'); - } - } - - /** - * Caches the field information. - * - * @return void - */ - public function cacheFieldInfo() { - $extSQL = ''; - $parsedExtSQL = array(); - - // try to fetch cached file first - // file is removed when admin_query() is called - if (file_exists(PATH_typo3conf . 'temp_fieldInfo.php')) { - $fdata = unserialize(t3lib_div::getUrl(PATH_typo3conf . 'temp_fieldInfo.php')); - $this->cache_autoIncFields = $fdata['incFields']; - $this->cache_fieldType = $fdata['fieldTypes']; - $this->cache_primaryKeys = $fdata['primaryKeys']; - } else { - // handle stddb.sql, parse and analyze - $extSQL = t3lib_div::getUrl(PATH_site . 't3lib/stddb/tables.sql'); - $parsedExtSQL = $this->Installer->getFieldDefinitions_fileContent($extSQL); - $this->analyzeFields($parsedExtSQL); - - // loop over all installed extensions - foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $ext => $v) { - if (!is_array($v) || !isset($v['ext_tables.sql'])) { - continue; - } - - // fetch db dump (if any) and parse it, then analyze - $extSQL = t3lib_div::getUrl($v['ext_tables.sql']); - $parsedExtSQL = $this->Installer->getFieldDefinitions_fileContent($extSQL); - $this->analyzeFields($parsedExtSQL); - } - - $cachedFieldInfo = array('incFields' => $this->cache_autoIncFields, 'fieldTypes' => $this->cache_fieldType, 'primaryKeys' => $this->cache_primaryKeys); - $cachedFieldInfo = serialize($this->mapCachedFieldInfo($cachedFieldInfo)); - - // write serialized content to file - t3lib_div::writeFile(PATH_typo3conf . 'temp_fieldInfo.php', $cachedFieldInfo); - - if (strcmp(t3lib_div::getUrl(PATH_typo3conf . 'temp_fieldInfo.php'), $cachedFieldInfo)) { - die('typo3conf/temp_fieldInfo.php was NOT updated properly (written content didn\'t match file content) - maybe write access problem?'); - } - } - } - - /** - * Analyzes fields and adds the extracted information to the field type, auto increment and primary key info caches. - * - * @param array $parsedExtSQL The output produced by t3lib_install::getFieldDefinitions_fileContent() - * @return void - * @see t3lib_install::getFieldDefinitions_fileContent() - */ - protected function analyzeFields($parsedExtSQL) { - foreach ($parsedExtSQL as $table => $tdef) { - if (is_array($tdef['fields'])) { - foreach ($tdef['fields'] as $field => $fdef) { - $fdef = $this->SQLparser->parseFieldDef($fdef); - $this->cache_fieldType[$table][$field]['type'] = $fdef['fieldType']; - $this->cache_fieldType[$table][$field]['metaType'] = $this->MySQLMetaType($fdef['fieldType']); - $this->cache_fieldType[$table][$field]['notnull'] = (isset($fdef['featureIndex']['NOTNULL']) && !$this->SQLparser->checkEmptyDefaultValue($fdef['featureIndex'])) ? 1 : 0; - if (isset($fdef['featureIndex']['DEFAULT'])) { - $default = $fdef['featureIndex']['DEFAULT']['value'][0]; - if (isset($fdef['featureIndex']['DEFAULT']['value'][1])) { - $default = $fdef['featureIndex']['DEFAULT']['value'][1] . $default . $fdef['featureIndex']['DEFAULT']['value'][1]; - } - $this->cache_fieldType[$table][$field]['default'] = $default; - } - if (isset($fdef['featureIndex']['AUTO_INCREMENT'])) { - $this->cache_autoIncFields[$table] = $field; - } - if (isset($tdef['keys']['PRIMARY'])) { - $this->cache_primaryKeys[$table] = substr($tdef['keys']['PRIMARY'], 13, -1); - } - } - } - } - } - - /** - * This function builds all definitions for mapped tables and fields - * @see cacheFieldInfo() - */ - protected function mapCachedFieldInfo($fieldInfo) { - if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['mapping'])) { - foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['mapping'] as $mappedTable => $mappedConf) { - if (array_key_exists($mappedTable, $fieldInfo['incFields'])) { - $mappedTableAlias = $mappedConf['mapTableName']; - if (isset($mappedConf['mapFieldNames'][$fieldInfo['incFields'][$mappedTable]])) { - $fieldInfo['incFields'][$mappedTableAlias] = $mappedConf['mapFieldNames'][$fieldInfo['incFields'][$mappedTable]]; - } else { - $fieldInfo['incFields'][$mappedTableAlias] = $fieldInfo['incFields'][$mappedTable]; - } - } - - if (array_key_exists($mappedTable, $fieldInfo['fieldTypes'])) { - foreach ($fieldInfo['fieldTypes'][$mappedTable] as $field => $fieldConf) { - $tempMappedFieldConf[$mappedConf['mapFieldNames'][$field]] = $fieldConf; - } - - $fieldInfo['fieldTypes'][$mappedConf['mapTableName']] = $tempMappedFieldConf; - } - - if (array_key_exists($mappedTable, $fieldInfo['primaryKeys'])) { - $mappedTableAlias = $mappedConf['mapTableName']; - if (isset($mappedConf['mapFieldNames'][$fieldInfo['primaryKeys'][$mappedTable]])) { - $fieldInfo['primaryKeys'][$mappedTableAlias] = $mappedConf['mapFieldNames'][$fieldInfo['primaryKeys'][$mappedTable]]; - } else { - $fieldInfo['primaryKeys'][$mappedTableAlias] = $fieldInfo['primaryKeys'][$mappedTable]; - } - } - } - } - - return $fieldInfo; - } - - - /************************************ - * - * Query Building (Overriding parent methods) - * These functions are extending counterparts in the parent class. - * - **************************************/ - - /* From the ADOdb documentation, this is what we do (_Execute for SELECT, _query for the other actions) - - Execute() is the default way to run queries. You can use the low-level functions _Execute() and _query() to reduce query overhead. - Both these functions share the same parameters as Execute(). - - If you do not have any bind parameters or your database supports binding (without emulation), then you can call _Execute() directly. - Calling this function bypasses bind emulation. Debugging is still supported in _Execute(). - - If you do not require debugging facilities nor emulated binding, and do not require a recordset to be returned, then you can call _query. - This is great for inserts, updates and deletes. Calling this function bypasses emulated binding, debugging, and recordset handling. Either - the resultid, TRUE or FALSE are returned by _query(). - */ - - /** - * Inserts a record for $table from the array with field/value pairs $fields_values. - * - * @param string Table name - * @param array Field values as key=>value pairs. Values will be escaped internally. Typically you would fill an array like "$insertFields" with 'fieldname'=>'value' and pass it to this function as argument. - * @param mixed List/array of keys NOT to quote (eg. SQL functions) - * @return mixed Result from handler, usually TRUE when success and FALSE on failure - */ - public function exec_INSERTquery($table, $fields_values, $no_quote_fields = '') { - - if ($this->debug) { - $pt = t3lib_div::milliseconds(); - } - - // Do field mapping if needed: - $ORIG_tableName = $table; - if ($tableArray = $this->map_needMapping($table)) { - - // Field mapping of array: - $fields_values = $this->map_assocArray($fields_values, $tableArray); - - // Table name: - if ($this->mapping[$table]['mapTableName']) { - $table = $this->mapping[$table]['mapTableName']; - } - } - // Select API: - $this->lastHandlerKey = $this->handler_getFromTableList($ORIG_tableName); - $hType = (string) $this->handlerCfg[$this->lastHandlerKey]['type']; - switch ($hType) { - case 'native': - $this->lastQuery = $this->INSERTquery($table, $fields_values, $no_quote_fields); - if (is_string($this->lastQuery)) { - $sqlResult = mysql_query($this->lastQuery, $this->handlerInstance[$this->lastHandlerKey]['link']); - } else { - $sqlResult = mysql_query($this->lastQuery[0], $this->handlerInstance[$this->lastHandlerKey]['link']); - $new_id = $this->sql_insert_id(); - $where = $this->cache_autoIncFields[$table] . '=' . $new_id; - foreach ($this->lastQuery[1] as $field => $content) { - mysql_query('UPDATE ' . $this->quoteFromTables($table) . ' SET ' . $this->quoteFromTables($field) . '=' . $this->fullQuoteStr($content, $table) . ' WHERE ' . $this->quoteWhereClause($where), $this->handlerInstance[$this->lastHandlerKey]['link']); - } - } - break; - case 'adodb': - // auto generate ID for auto_increment fields if not present (static import needs this!) - // should we check the table name here (static_*)? - if (isset($this->cache_autoIncFields[$table])) { - if (isset($fields_values[$this->cache_autoIncFields[$table]])) { - $new_id = $fields_values[$this->cache_autoIncFields[$table]]; - if ($table != 'tx_dbal_debuglog') { - $this->handlerInstance[$this->lastHandlerKey]->last_insert_id = $new_id; - } - } else { - $new_id = $this->handlerInstance[$this->lastHandlerKey]->GenID($table . '_' . $this->cache_autoIncFields[$table], $this->handlerInstance[$this->lastHandlerKey]->sequenceStart); - $fields_values[$this->cache_autoIncFields[$table]] = $new_id; - if ($table != 'tx_dbal_debuglog') { - $this->handlerInstance[$this->lastHandlerKey]->last_insert_id = $new_id; - } - } - } - - $this->lastQuery = $this->INSERTquery($table, $fields_values, $no_quote_fields); - if (is_string($this->lastQuery)) { - $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery, FALSE); - } else { - $this->handlerInstance[$this->lastHandlerKey]->StartTrans(); - if (strlen($this->lastQuery[0])) { - $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery[0], FALSE); - } - if (is_array($this->lastQuery[1])) { - foreach ($this->lastQuery[1] as $field => $content) { - if (empty($content)) continue; - - if (isset($this->cache_autoIncFields[$table]) && isset($new_id)) { - $this->handlerInstance[$this->lastHandlerKey]->UpdateBlob($this->quoteFromTables($table), $field, $content, $this->quoteWhereClause($this->cache_autoIncFields[$table] . '=' . $new_id)); - } elseif (isset($this->cache_primaryKeys[$table])) { - $where = ''; - $pks = explode(',', $this->cache_primaryKeys[$table]); - foreach ($pks as $pk) { - if (isset($fields_values[$pk])) - $where .= $pk . '=' . $this->fullQuoteStr($fields_values[$pk], $table) . ' AND '; - } - $where = $this->quoteWhereClause($where . '1=1'); - $this->handlerInstance[$this->lastHandlerKey]->UpdateBlob($this->quoteFromTables($table), $field, $content, $where); - } else { - $this->handlerInstance[$this->lastHandlerKey]->CompleteTrans(FALSE); - die('Could not update BLOB >>>> no WHERE clause found!'); // should never ever happen - } - } - } - if (is_array($this->lastQuery[2])) { - foreach ($this->lastQuery[2] as $field => $content) { - if (empty($content)) continue; - - if (isset($this->cache_autoIncFields[$table]) && isset($new_id)) { - $this->handlerInstance[$this->lastHandlerKey]->UpdateClob($this->quoteFromTables($table), $field, $content, $this->quoteWhereClause($this->cache_autoIncFields[$table] . '=' . $new_id)); - } elseif (isset($this->cache_primaryKeys[$table])) { - $where = ''; - $pks = explode(',', $this->cache_primaryKeys[$table]); - foreach ($pks as $pk) { - if (isset($fields_values[$pk])) - $where .= $pk . '=' . $this->fullQuoteStr($fields_values[$pk], $table) . ' AND '; - } - $where = $this->quoteWhereClause($where . '1=1'); - $this->handlerInstance[$this->lastHandlerKey]->UpdateClob($this->quoteFromTables($table), $field, $content, $where); - } else { - $this->handlerInstance[$this->lastHandlerKey]->CompleteTrans(FALSE); - die('Could not update CLOB >>>> no WHERE clause found!'); // should never ever happen - } - } - } - $this->handlerInstance[$this->lastHandlerKey]->CompleteTrans(); - } - break; - case 'userdefined': - $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->exec_INSERTquery($table, $fields_values, $no_quote_fields); - break; - } - - if ($this->printErrors && $this->sql_error()) { - debug(array($this->lastQuery, $this->sql_error())); - } - - if ($this->debug) { - $this->debugHandler( - 'exec_INSERTquery', - t3lib_div::milliseconds() - $pt, - array( - 'handlerType' => $hType, - 'args' => array($table, $fields_values), - 'ORIG_tablename' => $ORIG_tableName - ) - ); - } - // Return output: - return $sqlResult; - } - - /** - * Creates and executes an INSERT SQL-statement for $table with multiple rows. - * This method uses exec_INSERTquery() and is just a syntax wrapper to it. - * - * @param string Table name - * @param array Field names - * @param array Table rows. Each row should be an array with field values mapping to $fields - * @param string/array See fullQuoteArray() - * @return mixed Result from last handler, usually TRUE when success and FALSE on failure - */ - public function exec_INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = FALSE) { - if ((string) $this->handlerCfg[$this->lastHandlerKey]['type'] === 'native') { - return parent::exec_INSERTmultipleRows($table, $fields, $rows, $no_quote_fields); - } - - foreach ($rows as $row) { - $fields_values = array(); - foreach ($fields as $key => $value) { - $fields_values[$value] = $row[$key]; - } - $res = $this->exec_INSERTquery($table, $fields_values, $no_quote_fields); - } - - return $res; - } - - /** - * Updates a record from $table - * - * @param string Database tablename - * @param string WHERE clause, eg. "uid=1". NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself! - * @param array Field values as key=>value pairs. Values will be escaped internally. Typically you would fill an array like "$updateFields" with 'fieldname'=>'value' and pass it to this function as argument. - * @param mixed List/array of keys NOT to quote (eg. SQL functions) - * @return mixed Result from handler, usually TRUE when success and FALSE on failure - */ - public function exec_UPDATEquery($table, $where, $fields_values, $no_quote_fields = '') { - if ($this->debug) { - $pt = t3lib_div::milliseconds(); - } - - // Do table/field mapping: - $ORIG_tableName = $table; - if ($tableArray = $this->map_needMapping($table)) { - - // Field mapping of array: - $fields_values = $this->map_assocArray($fields_values, $tableArray); - - // Where clause table and field mapping: - $whereParts = $this->SQLparser->parseWhereClause($where); - $this->map_sqlParts($whereParts, $tableArray[0]['table']); - $where = $this->SQLparser->compileWhereClause($whereParts, FALSE); - - // Table name: - if ($this->mapping[$table]['mapTableName']) { - $table = $this->mapping[$table]['mapTableName']; - } - } - - // Select API - $this->lastHandlerKey = $this->handler_getFromTableList($ORIG_tableName); - $hType = (string) $this->handlerCfg[$this->lastHandlerKey]['type']; - switch ($hType) { - case 'native': - $this->lastQuery = $this->UPDATEquery($table, $where, $fields_values, $no_quote_fields); - if (is_string($this->lastQuery)) { - $sqlResult = mysql_query($this->lastQuery, $this->handlerInstance[$this->lastHandlerKey]['link']); - } - else { - $sqlResult = mysql_query($this->lastQuery[0], $this->handlerInstance[$this->lastHandlerKey]['link']); - foreach ($this->lastQuery[1] as $field => $content) { - mysql_query('UPDATE ' . $this->quoteFromTables($table) . ' SET ' . $this->quoteFromTables($field) . '=' . $this->fullQuoteStr($content, $table) . ' WHERE ' . $this->quoteWhereClause($where), $this->handlerInstance[$this->lastHandlerKey]['link']); - } - } - break; - case 'adodb': - $this->lastQuery = $this->UPDATEquery($table, $where, $fields_values, $no_quote_fields); - if (is_string($this->lastQuery)) { - $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery, FALSE); - } else { - $this->handlerInstance[$this->lastHandlerKey]->StartTrans(); - if (strlen($this->lastQuery[0])) { - $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery[0], FALSE); - } - if (is_array($this->lastQuery[1])) { - foreach ($this->lastQuery[1] as $field => $content) { - $this->handlerInstance[$this->lastHandlerKey]->UpdateBlob($this->quoteFromTables($table), $field, $content, $this->quoteWhereClause($where)); - } - } - if (is_array($this->lastQuery[2])) { - foreach ($this->lastQuery[2] as $field => $content) { - $this->handlerInstance[$this->lastHandlerKey]->UpdateClob($this->quoteFromTables($table), $field, $content, $this->quoteWhereClause($where)); - } - } - $this->handlerInstance[$this->lastHandlerKey]->CompleteTrans(); - } - break; - case 'userdefined': - $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->exec_UPDATEquery($table, $where, $fields_values, $no_quote_fields); - break; - } - - if ($this->printErrors && $this->sql_error()) { - debug(array($this->lastQuery, $this->sql_error())); - } - - if ($this->debug) { - $this->debugHandler( - 'exec_UPDATEquery', - t3lib_div::milliseconds() - $pt, - array( - 'handlerType' => $hType, - 'args' => array($table, $where, $fields_values), - 'ORIG_from_table' => $ORIG_tableName - ) - ); - } - - // Return result: - return $sqlResult; - } - - /** - * Deletes records from table - * - * @param string Database tablename - * @param string WHERE clause, eg. "uid=1". NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself! - * @return mixed Result from handler - */ - public function exec_DELETEquery($table, $where) { - if ($this->debug) { - $pt = t3lib_div::milliseconds(); - } - - // Do table/field mapping: - $ORIG_tableName = $table; - if ($tableArray = $this->map_needMapping($table)) { - - // Where clause: - $whereParts = $this->SQLparser->parseWhereClause($where); - $this->map_sqlParts($whereParts, $tableArray[0]['table']); - $where = $this->SQLparser->compileWhereClause($whereParts, FALSE); - - // Table name: - if ($this->mapping[$table]['mapTableName']) { - $table = $this->mapping[$table]['mapTableName']; - } - } - - // Select API - $this->lastHandlerKey = $this->handler_getFromTableList($ORIG_tableName); - $hType = (string) $this->handlerCfg[$this->lastHandlerKey]['type']; - switch ($hType) { - case 'native': - $this->lastQuery = $this->DELETEquery($table, $where); - $sqlResult = mysql_query($this->lastQuery, $this->handlerInstance[$this->lastHandlerKey]['link']); - break; - case 'adodb': - $this->lastQuery = $this->DELETEquery($table, $where); - $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery, FALSE); - break; - case 'userdefined': - $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->exec_DELETEquery($table, $where); - break; - } - - if ($this->printErrors && $this->sql_error()) { - debug(array($this->lastQuery, $this->sql_error())); - } - - if ($this->debug) { - $this->debugHandler( - 'exec_DELETEquery', - t3lib_div::milliseconds() - $pt, - array( - 'handlerType' => $hType, - 'args' => array($table, $where), - 'ORIG_from_table' => $ORIG_tableName - ) - ); - } - - // Return result: - return $sqlResult; - } - - /** - * Selects records from Data Source - * - * @param string $select_fields List of fields to select from the table. This is what comes right after "SELECT ...". Required value. - * @param string $from_table Table(s) from which to select. This is what comes right after "FROM ...". Required value. - * @param string $where_clause Optional additional WHERE clauses put in the end of the query. NOTICE: You must escape values in this argument with $this->fullQquoteStr() yourself! DO NOT PUT IN GROUP BY, ORDER BY or LIMIT! - * @param string $groupBy Optional GROUP BY field(s), if none, supply blank string. - * @param string $orderBy Optional ORDER BY field(s), if none, supply blank string. - * @param string $limit Optional LIMIT value ([begin,]max), if none, supply blank string. - * @return mixed Result from handler. Typically object from DBAL layers. - */ - public function exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '') { - if ($this->debug) { - $pt = t3lib_div::milliseconds(); - } - - // Map table / field names if needed: - $ORIG_tableName = $from_table; // Saving table names in $ORIG_from_table since $from_table is transformed beneath: - $parsedFromTable = array(); - $remappedParameters = array(); - if ($tableArray = $this->map_needMapping($ORIG_tableName, FALSE, $parsedFromTable)) { - $from = $parsedFromTable ? $parsedFromTable : $from_table; - $remappedParameters = $this->map_remapSELECTQueryParts($select_fields, $from, $where_clause, $groupBy, $orderBy); - } - - // Get handler key and select API: - $this->lastHandlerKey = $this->handler_getFromTableList($ORIG_tableName); - $hType = (string) $this->handlerCfg[$this->lastHandlerKey]['type']; - switch ($hType) { - case 'native': - if (count($remappedParameters) > 0) { - list($select_fields, $from_table, $where_clause, $groupBy, $orderBy) = $this->compileSelectParameters($remappedParameters); - } - $this->lastQuery = $this->SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit); - $sqlResult = mysql_query($this->lastQuery, $this->handlerInstance[$this->lastHandlerKey]['link']); - $this->resourceIdToTableNameMap[(string) $sqlResult] = $ORIG_tableName; - break; - case 'adodb': - if ($limit != '') { - $splitLimit = t3lib_div::intExplode(',', $limit); // Splitting the limit values: - if ($splitLimit[1]) { // If there are two parameters, do mapping differently than otherwise: - $numrows = $splitLimit[1]; - $offset = $splitLimit[0]; - } else { - $numrows = $splitLimit[0]; - $offset = 0; - } - - if (count($remappedParameters) > 0) { - $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->SelectLimit($this->SELECTqueryFromArray($remappedParameters), $numrows, $offset); - } else { - $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->SelectLimit($this->SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy), $numrows, $offset); - } - $this->lastQuery = $sqlResult->sql; - } else { - if (count($remappedParameters) > 0) { - $this->lastQuery = $this->SELECTqueryFromArray($remappedParameters); - } else { - $this->lastQuery = $this->SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy); - } - $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_Execute($this->lastQuery); - } - - $sqlResult->TYPO3_DBAL_handlerType = 'adodb'; // Setting handler type in result object (for later recognition!) - $sqlResult->TYPO3_DBAL_tableList = $ORIG_tableName; - break; - case 'userdefined': - if (count($remappedParameters) > 0) { - list($select_fields, $from_table, $where_clause, $groupBy, $orderBy) = $this->compileSelectParameters($remappedParameters); - } - $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit); - if (is_object($sqlResult)) { - $sqlResult->TYPO3_DBAL_handlerType = 'userdefined'; // Setting handler type in result object (for later recognition!) - $sqlResult->TYPO3_DBAL_tableList = $ORIG_tableName; - } - break; - } - - if ($this->printErrors && $this->sql_error()) { - debug(array($this->lastQuery, $this->sql_error())); - } - - if ($this->debug) { - $data = array( - 'handlerType' => $hType, - 'args' => array($from_table, $select_fields, $where_clause, $groupBy, $orderBy, $limit), - 'ORIG_from_table' => $ORIG_tableName, - ); - if ($this->conf['debugOptions']['numberRows']) { - $data['numberRows'] = $this->sql_num_rows($sqlResult); - } - $this->debugHandler( - 'exec_SELECTquery', - t3lib_div::milliseconds() - $pt, - $data - ); - } - - // Return result handler. - return $sqlResult; - } - - /** - * Truncates a table. - * - * @param string Database tablename - * @return mixed Result from handler - */ - public function exec_TRUNCATEquery($table) { - if ($this->debug) { - $pt = t3lib_div::milliseconds(); - } - - // Do table/field mapping: - $ORIG_tableName = $table; - if ($tableArray = $this->map_needMapping($table)) { - // Table name: - if ($this->mapping[$table]['mapTableName']) { - $table = $this->mapping[$table]['mapTableName']; - } - } - - // Select API - $this->lastHandlerKey = $this->handler_getFromTableList($ORIG_tableName); - $hType = (string) $this->handlerCfg[$this->lastHandlerKey]['type']; - switch ($hType) { - case 'native': - $this->lastQuery = $this->TRUNCATEquery($table); - $sqlResult = mysql_query($this->lastQuery, $this->handlerInstance[$this->lastHandlerKey]['link']); - break; - case 'adodb': - $this->lastQuery = $this->TRUNCATEquery($table); - $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery, FALSE); - break; - case 'userdefined': - $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->exec_TRUNCATEquery($table); - break; - } - - if ($this->printErrors && $this->sql_error()) { - debug(array($this->lastQuery, $this->sql_error())); - } - - if ($this->debug) { - $this->debugHandler( - 'exec_TRUNCATEquery', - t3lib_div::milliseconds() - $pt, - array( - 'handlerType' => $hType, - 'args' => array($table), - 'ORIG_from_table' => $ORIG_tableName - ) - ); - } - - // Return result: - return $sqlResult; - } - - /** - * Executes a query. - * EXPERIMENTAL since TYPO3 4.4. - * - * @param array $queryParts SQL parsed by method parseSQL() of t3lib_sqlparser - * @return pointer Result pointer / DBAL object - * @see ux_t3lib_db::sql_query() - */ - protected function exec_query(array $queryParts) { - switch ($queryParts['type']) { - case 'SELECT': - $selectFields = $this->SQLparser->compileFieldList($queryParts['SELECT']); - $fromTables = $this->SQLparser->compileFromTables($queryParts['FROM']); - $whereClause = isset($queryParts['WHERE']) ? $this->SQLparser->compileWhereClause($queryParts['WHERE']) : '1=1'; - $groupBy = isset($queryParts['GROUPBY']) ? $this->SQLparser->compileFieldList($queryParts['GROUPBY']) : ''; - $orderBy = isset($queryParts['ORDERBY']) ? $this->SQLparser->compileFieldList($queryParts['ORDERBY']) : ''; - $limit = isset($queryParts['LIMIT']) ? $this->SQLparser->compileWhereClause($queryParts['LIMIT']) : ''; - return $this->exec_SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy, $limit); - - case 'UPDATE': - $table = $queryParts['TABLE']; - $fields = array(); - foreach ($queryParts['FIELDS'] as $fN => $fV) { - $fields[$fN] = $fV[0]; - } - $whereClause = isset($queryParts['WHERE']) ? $this->SQLparser->compileWhereClause($queryParts['WHERE']) : '1=1'; - return $this->exec_UPDATEquery($table, $whereClause, $fields); - - case 'INSERT': - $table = $queryParts['TABLE']; - $values = array(); - if (isset($queryParts['VALUES_ONLY']) && is_array($queryParts['VALUES_ONLY'])) { - $fields = $GLOBALS['TYPO3_DB']->cache_fieldType[$table]; - $fc = 0; - foreach ($fields as $fn => $fd) { - $values[$fn] = $queryParts['VALUES_ONLY'][$fc++][0]; - } - } else { - foreach ($queryParts['FIELDS'] as $fN => $fV) { - $values[$fN] = $fV[0]; - } - } - return $this->exec_INSERTquery($table, $values); - - case 'DELETE': - $table = $queryParts['TABLE']; - $whereClause = isset($queryParts['WHERE']) ? $this->SQLparser->compileWhereClause($queryParts['WHERE']) : '1=1'; - return $this->exec_DELETEquery($table, $whereClause); - - case 'TRUNCATETABLE': - $table = $queryParts['TABLE']; - return $this->exec_TRUNCATEquery($table); - } - } - - - /************************************** - * - * Query building - * - **************************************/ - - /** - * Creates an INSERT SQL-statement for $table from the array with field/value pairs $fields_values. - * Usage count/core: 4 - * - * @param string See exec_INSERTquery() - * @param array See exec_INSERTquery() - * @param mixed See exec_INSERTquery() - * @return mixed Full SQL query for INSERT as string or array (unless $fields_values does not contain any elements in which case it will be FALSE). If BLOB fields will be affected and one is not running the native type, an array will be returned, where 0 => plain SQL, 1 => fieldname/value pairs of BLOB fields - */ - public function INSERTquery($table, $fields_values, $no_quote_fields = '') { - // Table and fieldnames should be "SQL-injection-safe" when supplied to this function (contrary to values in the arrays which may be insecure). - if (is_array($fields_values) && count($fields_values)) { - - if (is_string($no_quote_fields)) { - $no_quote_fields = explode(',', $no_quote_fields); - } elseif (!is_array($no_quote_fields)) { - $no_quote_fields = array(); - } - - $blobfields = array(); - $nArr = array(); - foreach ($fields_values as $k => $v) { - if (!$this->runningNative() && $this->sql_field_metatype($table, $k) == 'B') { - // we skip the field in the regular INSERT statement, it is only in blobfields - $blobfields[$this->quoteFieldNames($k)] = $v; - } elseif (!$this->runningNative() && $this->sql_field_metatype($table, $k) == 'XL') { - // we skip the field in the regular INSERT statement, it is only in clobfields - $clobfields[$this->quoteFieldNames($k)] = $v; - } else { - // Add slashes old-school: - // cast numerical values - $mt = $this->sql_field_metatype($table, $k); - if ($mt{0} == 'I') { - $v = (int) $v; - } elseif ($mt{0} == 'F') { - $v = (double) $v; - } - - $nArr[$this->quoteFieldNames($k)] = (!in_array($k, $no_quote_fields)) ? $this->fullQuoteStr($v, $table) : $v; - } - } - - if (count($blobfields) || count($clobfields)) { - if (count($nArr)) { - $query[0] = 'INSERT INTO ' . $this->quoteFromTables($table) . ' - ( - ' . implode(', - ', array_keys($nArr)) . ' - ) VALUES ( - ' . implode(', - ', $nArr) . ' - )'; - } - if (count($blobfields)) $query[1] = $blobfields; - if (count($clobfields)) $query[2] = $clobfields; - if ($this->debugOutput || $this->store_lastBuiltQuery) $this->debug_lastBuiltQuery = $query[0]; - } else { - $query = 'INSERT INTO ' . $this->quoteFromTables($table) . ' - ( - ' . implode(', - ', array_keys($nArr)) . ' - ) VALUES ( - ' . implode(', - ', $nArr) . ' - )'; - - if ($this->debugOutput || $this->store_lastBuiltQuery) $this->debug_lastBuiltQuery = $query; - } - - return $query; - } - } - - /** - * Creates an INSERT SQL-statement for $table with multiple rows. - * This method will create multiple INSERT queries concatenated with ';' - * - * @param string Table name - * @param array Field names - * @param array Table rows. Each row should be an array with field values mapping to $fields - * @param string/array See fullQuoteArray() - * @return array Full SQL query for INSERT as array of strings (unless $fields_values does not contain any elements in which case it will be FALSE). If BLOB fields will be affected and one is not running the native type, an array will be returned for each row, where 0 => plain SQL, 1 => fieldname/value pairs of BLOB fields. - */ - public function INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = FALSE) { - if ((string) $this->handlerCfg[$this->lastHandlerKey]['type'] === 'native') { - return parent::INSERTmultipleRows($table, $fields, $rows, $no_quote_fields); - } - - $result = array(); - - foreach ($rows as $row) { - $fields_values = array(); - foreach ($fields as $key => $value) { - $fields_values[$value] = $row[$key]; - } - $rowQuery = $this->INSERTquery($table, $fields_values, $no_quote_fields); - if (is_array($rowQuery)) { - $result[] = $rowQuery; - } else { - $result[][0] = $rowQuery; - } - } - - return $result; - } - - /** - * Creates an UPDATE SQL-statement for $table where $where-clause (typ. 'uid=...') from the array with field/value pairs $fields_values. - * Usage count/core: 6 - * - * @param string See exec_UPDATEquery() - * @param string See exec_UPDATEquery() - * @param array See exec_UPDATEquery() - * @param mixed See exec_UPDATEquery() - * @return mixed Full SQL query for UPDATE as string or array (unless $fields_values does not contain any elements in which case it will be FALSE). If BLOB fields will be affected and one is not running the native type, an array will be returned, where 0 => plain SQL, 1 => fieldname/value pairs of BLOB fields - */ - public function UPDATEquery($table, $where, $fields_values, $no_quote_fields = '') { - // Table and fieldnames should be "SQL-injection-safe" when supplied to this function (contrary to values in the arrays which may be insecure). - if (is_string($where)) { - $fields = array(); - $blobfields = array(); - $clobfields = array(); - if (is_array($fields_values) && count($fields_values)) { - - if (is_string($no_quote_fields)) { - $no_quote_fields = explode(',', $no_quote_fields); - } elseif (!is_array($no_quote_fields)) { - $no_quote_fields = array(); - } - - $nArr = array(); - foreach ($fields_values as $k => $v) { - if (!$this->runningNative() && $this->sql_field_metatype($table, $k) == 'B') { - // we skip the field in the regular UPDATE statement, it is only in blobfields - $blobfields[$this->quoteFieldNames($k)] = $v; - } elseif (!$this->runningNative() && $this->sql_field_metatype($table, $k) == 'XL') { - // we skip the field in the regular UPDATE statement, it is only in clobfields - $clobfields[$this->quoteFieldNames($k)] = $v; - } else { - // Add slashes old-school: - // cast numeric values - $mt = $this->sql_field_metatype($table, $k); - if ($mt{0} == 'I') { - $v = (int) $v; - } elseif ($mt{0} == 'F') { - $v = (double) $v; - } - $nArr[] = $this->quoteFieldNames($k) . '=' . ((!in_array($k, $no_quote_fields)) ? $this->fullQuoteStr($v, $table) : $v); - } - } - } - - if (count($blobfields) || count($clobfields)) { - if (count($nArr)) { - $query[0] = 'UPDATE ' . $this->quoteFromTables($table) . ' - SET - ' . implode(', - ', $nArr) . - (strlen($where) > 0 ? ' - WHERE - ' . $this->quoteWhereClause($where) : ''); - } - if (count($blobfields)) { - $query[1] = $blobfields; - } - if (count($clobfields)) { - $query[2] = $clobfields; - } - if ($this->debugOutput || $this->store_lastBuiltQuery) { - $this->debug_lastBuiltQuery = $query[0]; - } - } else { - $query = 'UPDATE ' . $this->quoteFromTables($table) . ' - SET - ' . implode(', - ', $nArr) . - (strlen($where) > 0 ? ' - WHERE - ' . $this->quoteWhereClause($where) : ''); - - if ($this->debugOutput || $this->store_lastBuiltQuery) { - $this->debug_lastBuiltQuery = $query; - } - } - return $query; - } else { - throw new InvalidArgumentException( - 'TYPO3 Fatal Error: "Where" clause argument for UPDATE query was not a string in $this->UPDATEquery() !', - 1270853880 - ); - } - } - - /** - * Creates a DELETE SQL-statement for $table where $where-clause - * Usage count/core: 3 - * - * @param string See exec_DELETEquery() - * @param string See exec_DELETEquery() - * @return string Full SQL query for DELETE - */ - public function DELETEquery($table, $where) { - if (is_string($where)) { - $table = $this->quoteFromTables($table); - $where = $this->quoteWhereClause($where); - - $query = parent::DELETEquery($table, $where); - - if ($this->debugOutput || $this->store_lastBuiltQuery) $this->debug_lastBuiltQuery = $query; - return $query; - } else { - die('<strong>TYPO3 Fatal Error:</strong> "Where" clause argument for DELETE query was not a string in $this->DELETEquery() !'); - } - } - - /** - * Creates a SELECT SQL-statement - * Usage count/core: 11 - * - * @param string See exec_SELECTquery() - * @param string See exec_SELECTquery() - * @param string See exec_SELECTquery() - * @param string See exec_SELECTquery() - * @param string See exec_SELECTquery() - * @param string See exec_SELECTquery() - * @return string Full SQL query for SELECT - */ - public function SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '') { - $this->lastHandlerKey = $this->handler_getFromTableList($from_table); - $hType = (string) $this->handlerCfg[$this->lastHandlerKey]['type']; - if ($hType === 'adodb' && $this->runningADOdbDriver('postgres')) { - // Possibly rewrite the LIMIT to be PostgreSQL-compatible - $splitLimit = t3lib_div::intExplode(',', $limit); // Splitting the limit values: - if ($splitLimit[1]) { // If there are two parameters, do mapping differently than otherwise: - $numrows = $splitLimit[1]; - $offset = $splitLimit[0]; - $limit = $numrows . ' OFFSET ' . $offset; - } - } - - $select_fields = $this->quoteFieldNames($select_fields); - $from_table = $this->quoteFromTables($from_table); - $where_clause = $this->quoteWhereClause($where_clause); - $groupBy = $this->quoteGroupBy($groupBy); - $orderBy = $this->quoteOrderBy($orderBy); - - // Call parent method to build actual query - $query = parent::SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit); - - if ($this->debugOutput || $this->store_lastBuiltQuery) { - $this->debug_lastBuiltQuery = $query; - } - - return $query; - } - - /** - * Creates a SELECT SQL-statement to be used with an ADOdb backend. - * - * @param array parsed parameters: array($select_fields, $from_table, $where_clause, $groupBy, $orderBy) - * @return string Full SQL query for SELECT - */ - protected function SELECTqueryFromArray(array $params) { - // $select_fields - $params[0] = $this->_quoteFieldNames($params[0]); - // $from_table - $params[1] = $this->_quoteFromTables($params[1]); - // $where_clause - if (count($params[2]) > 0) { - $params[2] = $this->_quoteWhereClause($params[2]); - } - // $group_by - if (count($params[3]) > 0) { - $params[3] = $this->_quoteGroupBy($params[3]); - } - // $order_by - if (count($params[4]) > 0) { - $params[4] = $this->_quoteOrderBy($params[4]); - } - - // Compile the SELECT parameters - list($select_fields, $from_table, $where_clause, $groupBy, $orderBy) = $this->compileSelectParameters($params); - - // Call parent method to build actual query - $query = parent::SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy); - - if ($this->debugOutput || $this->store_lastBuiltQuery) { - $this->debug_lastBuiltQuery = $query; - } - - return $query; - } - - /** - * Compiles and returns an array of SELECTquery parameters (without $limit) to - * be used with SELECTquery() or exec_SELECTquery(). - * - * @param array $params - * @return array array($select_fields, $from_table, $where_clause, $groupBy, $orderBy) - */ - protected function compileSelectParameters(array $params) { - $select_fields = $this->SQLparser->compileFieldList($params[0]); - $from_table = $this->SQLparser->compileFromTables($params[1]); - $where_clause = (count($params[2]) > 0) ? $this->SQLparser->compileWhereClause($params[2]) : ''; - $groupBy = (count($params[3]) > 0) ? $this->SQLparser->compileFieldList($params[3]) : ''; - $orderBy = (count($params[4]) > 0) ? $this->SQLparser->compileFieldList($params[4]) : ''; - - return array($select_fields, $from_table, $where_clause, $groupBy, $orderBy); - } - - /** - * Creates a TRUNCATE TABLE SQL-statement - * - * @param string See exec_TRUNCATEquery() - * @return string Full SQL query for TRUNCATE TABLE - */ - public function TRUNCATEquery($table) { - $table = $this->quoteFromTables($table); - - // Call parent method to build actual query - $query = parent::TRUNCATEquery($table); - - if ($this->debugOutput || $this->store_lastBuiltQuery) { - $this->debug_lastBuiltQuery = $query; - } - - return $query; - } - - /************************************** - * - * Prepared Query Support - * - **************************************/ - - /** - * Creates a SELECT prepared SQL statement. - * - * @param string See exec_SELECTquery() - * @param string See exec_SELECTquery() - * @param string See exec_SELECTquery() - * @param string See exec_SELECTquery() - * @param string See exec_SELECTquery() - * @param string See exec_SELECTquery() - * @param array $input_parameters An array of values with as many elements as there are bound parameters in the SQL statement being executed. All values are treated as t3lib_db_PreparedStatement::PARAM_AUTOTYPE. - * @return t3lib_db_PreparedStatement Prepared statement - */ - public function prepare_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '', array $input_parameters = array()) { - if ($this->debug) { - $pt = t3lib_div::milliseconds(); - } - - $precompiledParts = array(); - - if ($this->queryCache) { - $cacheKey = 'prepare_SELECTquery-' . tx_dbal_querycache::getCacheKey(array( - 'selectFields' => $select_fields, - 'fromTable' => $from_table, - 'whereClause' => $where_clause, - 'groupBy' => $groupBy, - 'orderBy' => $orderBy, - 'limit' => $limit, - )); - if ($this->queryCache->has($cacheKey)) { - $precompiledParts = $this->queryCache->get($cacheKey); - if ($this->debug) { - $data = array( - 'args' => array($from_table, $select_fields, $where_clause, $groupBy, $orderBy, $limit, $input_parameters), - 'precompiledParts' => $precompiledParts, - ); - $this->debugHandler( - 'prepare_SELECTquery (cache hit)', - t3lib_div::milliseconds() - $pt, - $data - ); - } - } - } - - if (count($precompiledParts) == 0) { - // Map table / field names if needed: - $ORIG_tableName = $from_table; // Saving table names in $ORIG_from_table since $from_table is transformed beneath: - $parsedFromTable = array(); - $queryComponents = array(); - if ($tableArray = $this->map_needMapping($ORIG_tableName, FALSE, $parsedFromTable)) { - $from = $parsedFromTable ? $parsedFromTable : $from_table; - $components = $this->map_remapSELECTQueryParts($select_fields, $from, $where_clause, $groupBy, $orderBy); - $queryComponents['SELECT'] = $components[0]; - $queryComponents['FROM'] = $components[1]; - $queryComponents['WHERE'] = $components[2]; - $queryComponents['GROUPBY'] = $components[3]; - $queryComponents['ORDERBY'] = $components[4]; - $queryComponents['parameters'] = $components[5]; - } else { - $queryComponents = $this->getQueryComponents($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit); - } - - $queryComponents['ORIG_tableName'] = $ORIG_tableName; - - if (!$this->runningNative()) { - // Quotes all fields - $queryComponents['SELECT'] = $this->_quoteFieldNames($queryComponents['SELECT']); - $queryComponents['FROM'] = $this->_quoteFromTables($queryComponents['FROM']); - $queryComponents['WHERE'] = $this->_quoteWhereClause($queryComponents['WHERE']); - $queryComponents['GROUPBY'] = $this->_quoteGroupBy($queryComponents['GROUPBY']); - $queryComponents['ORDERBY'] = $this->_quoteOrderBy($queryComponents['ORDERBY']); - } - - $precompiledParts = $this->precompileSELECTquery($queryComponents); - if ($this->queryCache) { - try { - $this->queryCache->set($cacheKey, $precompiledParts); - } catch (t3lib_cache_Exception $e) { - if ($this->debug) { - t3lib_div::devLog($e->getMessage(), 'dbal', 1); - } - } - } - } - - $preparedStatement = t3lib_div::makeInstance('t3lib_db_PreparedStatement', '', $from_table, $precompiledParts); - /* @var $preparedStatement t3lib_db_PreparedStatement */ - - // Bind values to parameters - foreach ($input_parameters as $key => $value) { - $preparedStatement->bindValue($key, $value, t3lib_db_PreparedStatement::PARAM_AUTOTYPE); - } - - if ($this->debug) { - $data = array( - 'args' => array($from_table, $select_fields, $where_clause, $groupBy, $orderBy, $limit, $input_parameters), - 'ORIG_from_table' => $ORIG_tableName, - ); - $this->debugHandler( - 'prepare_SELECTquery', - t3lib_div::milliseconds() - $pt, - $data - ); - } - - // Return prepared statement - return $preparedStatement; - } - - /** - * Returns the parsed query components. - * - * @param string $select_fields - * @param string $from_table - * @param string $where_clause - * @param string $groupBy - * @param string $orderBy - * @param string $limit - * @return array - */ - protected function getQueryComponents($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit) { - $queryComponents = array( - 'SELECT' => '', - 'FROM' => '', - 'WHERE' => '', - 'GROUPBY' => '', - 'ORDERBY' => '', - 'LIMIT' => '', - 'parameters' => array(), - ); - - $this->lastHandlerKey = $this->handler_getFromTableList($from_table); - $hType = (string) $this->handlerCfg[$this->lastHandlerKey]['type']; - if ($hType === 'adodb' && $this->runningADOdbDriver('postgres')) { - // Possibly rewrite the LIMIT to be PostgreSQL-compatible - $splitLimit = t3lib_div::intExplode(',', $limit); // Splitting the limit values: - if ($splitLimit[1]) { // If there are two parameters, do mapping differently than otherwise: - $numrows = $splitLimit[1]; - $offset = $splitLimit[0]; - $limit = $numrows . ' OFFSET ' . $offset; - } - } - $queryComponents['LIMIT'] = $limit; - - $queryComponents['SELECT'] = $this->SQLparser->parseFieldList($select_fields); - if ($this->SQLparser->parse_error) { - die($this->SQLparser->parse_error . ' in ' . __FILE__ . ' : ' . __LINE__); - } - - $queryComponents['FROM'] = $this->SQLparser->parseFromTables($from_table); - - $queryComponents['WHERE'] = $this->SQLparser->parseWhereClause($where_clause, '', $queryComponents['parameters']); - if (!is_array($queryComponents['WHERE'])) { - die('Could not parse where clause in ' . __FILE__ . ' : ' . __LINE__); - } - - $queryComponents['GROUPBY'] = $this->SQLparser->parseFieldList($groupBy); - $queryComponents['ORDERBY'] = $this->SQLparser->parseFieldList($orderBy); - - // Return the query components - return $queryComponents; - } - - /** - * Precompiles a SELECT prepared SQL statement. - * - * @param array $components - * @return array Precompiled SQL statement - */ - protected function precompileSELECTquery(array $components) { - $parameterWrap = '__' . dechex(time()) . '__'; - foreach ($components['parameters'] as $key => $params) { - if ($key === '?') { - foreach ($params as $index => $param) { - $components['parameters'][$key][$index][0] = $parameterWrap . $param[0] . $parameterWrap; - } - } else { - $components['parameters'][$key][0] = $parameterWrap . $params[0] . $parameterWrap; - } - } - - $select_fields = $this->SQLparser->compileFieldList($components['SELECT']); - $from_table = $this->SQLparser->compileFromTables($components['FROM']); - $where_clause = $this->SQLparser->compileWhereClause($components['WHERE']); - $groupBy = $this->SQLparser->compileFieldList($components['GROUPBY']); - $orderBy = $this->SQLparser->compileFieldList($components['ORDERBY']); - $limit = $components['LIMIT']; - $precompiledParts = array(); - - $this->lastHandlerKey = $this->handler_getFromTableList($components['ORIG_tableName']); - $hType = (string) $this->handlerCfg[$this->lastHandlerKey]['type']; - $precompiledParts['handler'] = $hType; - $precompiledParts['ORIG_tableName'] = $components['ORIG_tableName']; - - switch ($hType) { - case 'native': - $query = parent::SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit); - $precompiledParts['queryParts'] = explode($parameterWrap, $query); - break; - case 'adodb': - $query = parent::SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy); - $precompiledParts['queryParts'] = explode($parameterWrap, $query); - $precompiledParts['LIMIT'] = $limit; - break; - case 'userdefined': - $precompiledParts['queryParts'] = array( - 'SELECT' => $select_fields, - 'FROM' => $from_table, - 'WHERE' => $where_clause, - 'GROUPBY' => $groupBy, - 'ORDERBY' => $orderBy, - 'LIMIT' => $limit, - ); - break; - } - - return $precompiledParts; - } - - /** - * Executes a prepared query. - * - * @param string $query The query to execute - * @param array $queryComponents The components of the query to execute - * @return pointer MySQL result pointer / DBAL object - * @access protected This method may only be called by t3lib_db_PreparedStatement - */ - public function exec_PREPAREDquery($query, array $precompiledParts) { - if ($this->debug) { - $pt = t3lib_div::milliseconds(); - } - - // Get handler key and select API: - switch ($precompiledParts['handler']) { - case 'native': - $this->lastQuery = $query; - $sqlResult = mysql_query($this->lastQuery, $this->handlerInstance[$this->lastHandlerKey]['link']); - $this->resourceIdToTableNameMap[(string) $sqlResult] = $precompiledParts['ORIG_tableName']; - break; - case 'adodb': - $limit = $precompiledParts['LIMIT']; - if ($this->runningADOdbDriver('postgres')) { - // Possibly rewrite the LIMIT to be PostgreSQL-compatible - $splitLimit = t3lib_div::intExplode(',', $limit); // Splitting the limit values: - if ($splitLimit[1]) { // If there are two parameters, do mapping differently than otherwise: - $numrows = $splitLimit[1]; - $offset = $splitLimit[0]; - $limit = $numrows . ' OFFSET ' . $offset; - } - } - if ($limit != '') { - $splitLimit = t3lib_div::intExplode(',', $limit); // Splitting the limit values: - if ($splitLimit[1]) { // If there are two parameters, do mapping differently than otherwise: - $numrows = $splitLimit[1]; - $offset = $splitLimit[0]; - } else { - $numrows = $splitLimit[0]; - $offset = 0; - } - - $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->SelectLimit($query, $numrows, $offset); - $this->lastQuery = $sqlResult->sql; - } else { - $this->lastQuery = $query; - $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_Execute($this->lastQuery); - } - - $sqlResult->TYPO3_DBAL_handlerType = 'adodb'; // Setting handler type in result object (for later recognition!) - $sqlResult->TYPO3_DBAL_tableList = $precompiledParts['ORIG_tableName']; - break; - case 'userdefined': - $queryParts = $precompiledParts['queryParts']; - $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->exec_SELECTquery( - $queryParts['SELECT'], - $queryParts['FROM'], - $queryParts['WHERE'], - $queryParts['GROUPBY'], - $queryParts['ORDERBY'], - $queryParts['LIMIT'] - ); - if (is_object($sqlResult)) { - $sqlResult->TYPO3_DBAL_handlerType = 'userdefined'; // Setting handler type in result object (for later recognition!) - $sqlResult->TYPO3_DBAL_tableList = $precompiledParts['ORIG_tableName']; - } - break; - } - - if ($this->printErrors && $this->sql_error()) { - debug(array($this->lastQuery, $this->sql_error())); - } - - if ($this->debug) { - $data = array( - 'handlerType' => $precompiledParts['handler'], - 'args' => $precompiledParts, - 'ORIG_from_table' => $precompiledParts['ORIG_tableName'], - ); - if ($this->conf['debugOptions']['numberRows']) { - $data['numberRows'] = $this->sql_num_rows($sqlResult); - } - $this->debugHandler( - 'exec_PREPAREDquery', - t3lib_div::milliseconds() - $pt, - $data - ); - } - - // Return result handler. - return $sqlResult; - } - - /************************************** - * - * Functions for quoting table/field names - * - **************************************/ - - /** - * Quotes components of a SELECT subquery. - * - * @param array $components Array of SQL query components - * @return array - */ - protected function quoteSELECTsubquery(array $components) { - $components['SELECT'] = $this->_quoteFieldNames($components['SELECT']); - $components['FROM'] = $this->_quoteFromTables($components['FROM']); - $components['WHERE'] = $this->_quoteWhereClause($components['WHERE']); - return $components; - } - - /** - * Quotes field (and table) names with the quote character suitable for the DB being used - * Use quoteFieldNames instead! - * - * @param string List of fields to be selected from DB - * @return string Quoted list of fields to be selected from DB - * @deprecated since TYPO3 4.0, will be removed in TYPO3 4.6 - */ - public function quoteSelectFields($select_fields) { - t3lib_div::logDeprecatedFunction(); - - $this->quoteFieldNames($select_fields); - } - - /** - * Quotes field (and table) names with the quote character suitable for the DB being used - * - * @param string List of fields to be used in query to DB - * @return string Quoted list of fields to be in query to DB - */ - public function quoteFieldNames($select_fields) { - if ($select_fields == '') { - return ''; - } - if ($this->runningNative()) { - return $select_fields; - } - - $select_fields = $this->SQLparser->parseFieldList($select_fields); - if ($this->SQLparser->parse_error) { - die($this->SQLparser->parse_error . ' in ' . __FILE__ . ' : ' . __LINE__); - } - $select_fields = $this->_quoteFieldNames($select_fields); - - return $this->SQLparser->compileFieldList($select_fields); - } - - /** - * Quotes field (and table) names in a SQL SELECT clause acccording to DB rules - * - * @param array $select_fields The parsed fields to quote - * @return array - * @see quoteFieldNames() - */ - protected function _quoteFieldNames(array $select_fields) { - foreach ($select_fields as $k => $v) { - if ($select_fields[$k]['field'] != '' && $select_fields[$k]['field'] != '*' && !is_numeric($select_fields[$k]['field'])) { - $select_fields[$k]['field'] = $this->quoteName($select_fields[$k]['field']); - } - if ($select_fields[$k]['table'] != '' && !is_numeric($select_fields[$k]['table'])) { - $select_fields[$k]['table'] = $this->quoteName($select_fields[$k]['table']); - } - if ($select_fields[$k]['as'] != '') { - $select_fields[$k]['as'] = $this->quoteName($select_fields[$k]['as']); - } - if (isset($select_fields[$k]['func_content.']) && $select_fields[$k]['func_content.'][0]['func_content'] != '*') { - $select_fields[$k]['func_content.'][0]['func_content'] = $this->quoteFieldNames($select_fields[$k]['func_content.'][0]['func_content']); - $select_fields[$k]['func_content'] = $this->quoteFieldNames($select_fields[$k]['func_content']); - } - if (isset($select_fields[$k]['flow-control'])) { - // Quoting flow-control statements - if ($select_fields[$k]['flow-control']['type'] === 'CASE') { - if (isset($select_fields[$k]['flow-control']['case_field'])) { - $select_fields[$k]['flow-control']['case_field'] = $this->quoteFieldNames($select_fields[$k]['flow-control']['case_field']); - } - foreach ($select_fields[$k]['flow-control']['when'] as $key => $when) { - $select_fields[$k]['flow-control']['when'][$key]['when_value'] = $this->_quoteWhereClause($when['when_value']); - } - } - } - } - - return $select_fields; - } - - /** - * Quotes table names with the quote character suitable for the DB being used - * - * @param string List of tables to be selected from DB - * @return string Quoted list of tables to be selected from DB - */ - public function quoteFromTables($from_table) { - if ($from_table == '') { - return ''; - } - if ($this->runningNative()) { - return $from_table; - } - - $from_table = $this->SQLparser->parseFromTables($from_table); - $from_table = $this->_quoteFromTables($from_table); - return $this->SQLparser->compileFromTables($from_table); - } - - /** - * Quotes table names in a SQL FROM clause acccording to DB rules - * - * @param array $from_table The parsed FROM clause to quote - * @return array - * @see quoteFromTables() - */ - protected function _quoteFromTables(array $from_table) { - foreach ($from_table as $k => $v) { - $from_table[$k]['table'] = $this->quoteName($from_table[$k]['table']); - if ($from_table[$k]['as'] != '') { - $from_table[$k]['as'] = $this->quoteName($from_table[$k]['as']); - } - if (is_array($v['JOIN'])) { - foreach ($v['JOIN'] as $joinCnt => $join) { - $from_table[$k]['JOIN'][$joinCnt]['withTable'] = $this->quoteName($join['withTable']); - $from_table[$k]['JOIN'][$joinCnt]['as'] = ($join['as']) ? $this->quoteName($join['as']) : ''; - foreach ($from_table[$k]['JOIN'][$joinCnt]['ON'] as &$condition) { - $condition['left']['table'] = ($condition['left']['table']) ? $this->quoteName($condition['left']['table']) : ''; - $condition['left']['field'] = $this->quoteName($condition['left']['field']); - $condition['right']['table'] = ($condition['right']['table']) ? $this->quoteName($condition['right']['table']) : ''; - $condition['right']['field'] = $this->quoteName($condition['right']['field']); - } - } - } - } - - return $from_table; - } - - /** - * Quotes the field (and table) names within a where clause with the quote character suitable for the DB being used - * - * @param string A where clause that can be parsed by parseWhereClause - * @return string Usable where clause with quoted field/table names - */ - public function quoteWhereClause($where_clause) { - if ($where_clause === '' || $this->runningNative()) { - return $where_clause; - } - - $where_clause = $this->SQLparser->parseWhereClause($where_clause); - if (is_array($where_clause)) { - $where_clause = $this->_quoteWhereClause($where_clause); - $where_clause = $this->SQLparser->compileWhereClause($where_clause); - } else { - die('Could not parse where clause in ' . __FILE__ . ' : ' . __LINE__); - } - - return $where_clause; - } - - /** - * Quotes field names in a SQL WHERE clause acccording to DB rules - * - * @param array $where_clause The parsed WHERE clause to quote - * @return array - * @see quoteWhereClause() - */ - protected function _quoteWhereClause(array $where_clause) { - foreach ($where_clause as $k => $v) { - // Look for sublevel: - if (is_array($where_clause[$k]['sub'])) { - $where_clause[$k]['sub'] = $this->_quoteWhereClause($where_clause[$k]['sub']); - } elseif (isset($v['func'])) { - switch ($where_clause[$k]['func']['type']) { - case 'EXISTS': - $where_clause[$k]['func']['subquery'] = $this->quoteSELECTsubquery($v['func']['subquery']); - break; - case 'FIND_IN_SET': - // quoteStr that will be used for Oracle - $pattern = str_replace($where_clause[$k]['func']['str'][1], '\\' . $where_clause[$k]['func']['str'][1], $where_clause[$k]['func']['str'][0]); - // table is not really needed and may in fact be empty in real statements - // but it's not overriden from t3lib_db at the moment... - $patternForLike = $this->escapeStrForLike($pattern, $where_clause[$k]['func']['table']); - $where_clause[$k]['func']['str_like'] = $patternForLike; - - // BEWARE: no break here to have next statements too - case 'IFNULL': - case 'LOCATE': - if ($where_clause[$k]['func']['table'] != '') { - $where_clause[$k]['func']['table'] = $this->quoteName($v['func']['table']); - } - if ($where_clause[$k]['func']['field'] != '') { - $where_clause[$k]['func']['field'] = $this->quoteName($v['func']['field']); - } - break; - } - } else { - if ($where_clause[$k]['table'] != '') { - $where_clause[$k]['table'] = $this->quoteName($where_clause[$k]['table']); - } - if (!is_numeric($where_clause[$k]['field'])) { - $where_clause[$k]['field'] = $this->quoteName($where_clause[$k]['field']); - } - if (isset($where_clause[$k]['calc_table'])) { - if ($where_clause[$k]['calc_table'] != '') { - $where_clause[$k]['calc_table'] = $this->quoteName($where_clause[$k]['calc_table']); - } - if ($where_clause[$k]['calc_field'] != '') { - $where_clause[$k]['calc_field'] = $this->quoteName($where_clause[$k]['calc_field']); - } - } - } - if ($where_clause[$k]['comparator']) { - if (isset($v['value']['operator'])) { - foreach ($where_clause[$k]['value']['args'] as $argK => $fieldDef) { - $where_clause[$k]['value']['args'][$argK]['table'] = $this->quoteName($fieldDef['table']); - $where_clause[$k]['value']['args'][$argK]['field'] = $this->quoteName($fieldDef['field']); - } - } else { - // Detecting value type; list or plain: - if (t3lib_div::inList('NOTIN,IN', strtoupper(str_replace(array(' ', "\n", "\r", "\t"), '', $where_clause[$k]['comparator'])))) { - if (isset($v['subquery'])) { - $where_clause[$k]['subquery'] = $this->quoteSELECTsubquery($v['subquery']); - } - } else { - if ((!isset($where_clause[$k]['value'][1]) || $where_clause[$k]['value'][1] == '') && is_string($where_clause[$k]['value'][0]) && strstr($where_clause[$k]['value'][0], '.')) { - $where_clause[$k]['value'][0] = $this->quoteFieldNames($where_clause[$k]['value'][0]); - } - } - } - } - } - - return $where_clause; - } - - /** - * Quotes the field (and table) names within a group by clause with the quote - * character suitable for the DB being used - * - * @param string A group by clause that can by parsed by parseFieldList - * @return string Usable group by clause with quoted field/table names - */ - protected function quoteGroupBy($groupBy) { - if ($groupBy === '') { - return ''; - } - if ($this->runningNative()) { - return $groupBy; - } - - $groupBy = $this->SQLparser->parseFieldList($groupBy); - $groupBy = $this->_quoteGroupBy($groupBy); - - return $this->SQLparser->compileFieldList($groupBy); - } - - /** - * Quotes field names in a SQL GROUP BY clause acccording to DB rules - * - * @param array $groupBy The parsed GROUP BY clause to quote - * @return array - * @see quoteGroupBy() - */ - protected function _quoteGroupBy(array $groupBy) { - foreach ($groupBy as $k => $v) { - $groupBy[$k]['field'] = $this->quoteName($groupBy[$k]['field']); - if ($groupBy[$k]['table'] != '') { - $groupBy[$k]['table'] = $this->quoteName($groupBy[$k]['table']); - } - } - return $groupBy; - } - - /** - * Quotes the field (and table) names within an order by clause with the quote - * character suitable for the DB being used - * - * @param string An order by clause that can by parsed by parseFieldList - * @return string Usable order by clause with quoted field/table names - */ - protected function quoteOrderBy($orderBy) { - if ($orderBy === '') { - return ''; - } - if ($this->runningNative()) { - return $orderBy; - } - - $orderBy = $this->SQLparser->parseFieldList($orderBy); - $orderBy = $this->_quoteOrderBy($orderBy); - - return $this->SQLparser->compileFieldList($orderBy); - } - - /** - * Quotes field names in a SQL ORDER BY clause acccording to DB rules - * - * @param array $orderBy The parsed ORDER BY clause to quote - * @return array - * @see quoteOrderBy() - */ - protected function _quoteOrderBy(array $orderBy) { - foreach ($orderBy as $k => $v) { - $orderBy[$k]['field'] = $this->quoteName($orderBy[$k]['field']); - if ($orderBy[$k]['table'] != '') { - $orderBy[$k]['table'] = $this->quoteName($orderBy[$k]['table']); - } - } - return $orderBy; - } - - - /************************************** - * - * Various helper functions - * - **************************************/ - - /** - * Escaping and quoting values for SQL statements. - * - * @param string Input string - * @param string Table name for which to quote string. Just enter the table that the field-value is selected from (and any DBAL will look up which handler to use and then how to quote the string!). - * @return string Output string; Wrapped in single quotes and quotes in the string (" / ') and \ will be backslashed (or otherwise based on DBAL handler) - * @see quoteStr() - */ - public function fullQuoteStr($str, $table) { - return '\'' . $this->quoteStr($str, $table) . '\''; - } - - /** - * Substitution for PHP function "addslashes()" - * NOTICE: You must wrap the output of this function in SINGLE QUOTES to be DBAL compatible. Unless you have to apply the single quotes yourself you should rather use ->fullQuoteStr()! - * - * @param string Input string - * @param string Table name for which to quote string. Just enter the table that the field-value is selected from (and any DBAL will look up which handler to use and then how to quote the string!). - * @return string Output string; Quotes (" / ') and \ will be backslashed (or otherwise based on DBAL handler) - * @see quoteStr() - */ - public function quoteStr($str, $table) { - $this->lastHandlerKey = $this->handler_getFromTableList($table); - switch ((string) $this->handlerCfg[$this->lastHandlerKey]['type']) { - case 'native': - if ($this->handlerInstance[$this->lastHandlerKey]['link']) { - $str = mysql_real_escape_string($str, $this->handlerInstance[$this->lastHandlerKey]['link']); - } else { - // link may be NULL when unit testing DBAL - $str = str_replace('\'', '\\\'', $str); - } - break; - case 'adodb': - $str = substr($this->handlerInstance[$this->lastHandlerKey]->qstr($str), 1, -1); - break; - case 'userdefined': - $str = $this->handlerInstance[$this->lastHandlerKey]->quoteStr($str); - break; - default: - die('No handler found!!!'); - break; - } - - return $str; - } - - /** - * Quotes an object name (table name, field, ...) - * - * @param string Object's name - * @param string Handler key - * @param boolean If method NameQuote() is not used, whether to use backticks instead of driver-specific quotes - * @return string Properly-quoted object's name - */ - public function quoteName($name, $handlerKey = NULL, $useBackticks = FALSE) { - $handlerKey = $handlerKey ? $handlerKey : $this->lastHandlerKey; - $useNameQuote = isset($this->handlerCfg[$handlerKey]['config']['useNameQuote']) ? $this->handlerCfg[$handlerKey]['config']['useNameQuote'] : FALSE; - if ($useNameQuote) { - return $this->handlerInstance[$handlerKey]->DataDictionary->NameQuote($name); - } else { - $quote = $useBackticks ? '`' : $this->handlerInstance[$handlerKey]->nameQuote; - return $quote . $name . $quote; - } - } - - /** - * Return MetaType for native field type (ADOdb only!) - * - * @param string native type as reported by admin_get_fields() - * @param string Table name for which query type string. Important for detection of DBMS handler of the query! - * @return string Meta type (currenly ADOdb syntax only, http://phplens.com/lens/adodb/docs-adodb.htm#metatype) - */ - public function MetaType($type, $table, $max_length = -1) { - $this->lastHandlerKey = $this->handler_getFromTableList($table); - $str = ''; - switch ((string) $this->handlerCfg[$this->lastHandlerKey]['type']) { - case 'native': - $str = $type; - break; - case 'adodb': - if (in_array($table, $this->cache_fieldType)) { - $rs = $this->handlerInstance[$this->lastHandlerKey]->SelectLimit('SELECT * FROM ' . $this->quoteFromTables($table), 1); - $str = $rs->MetaType($type, $max_length); - } - break; - case 'userdefined': - $str = $this->handlerInstance[$this->lastHandlerKey]->MetaType($str, $table, $max_length); - break; - default: - die('No handler found!!!'); - break; - } - - return $str; - } - - - /** - * Return MetaType for native MySQL field type - * - * @param string native type as reported as in mysqldump files - * @return string Meta type (currenly ADOdb syntax only, http://phplens.com/lens/adodb/docs-adodb.htm#metatype) - */ - public function MySQLMetaType($t) { - - switch (strtoupper($t)) { - case 'STRING': - case 'CHAR': - case 'VARCHAR': - case 'TINYBLOB': - case 'TINYTEXT': - case 'ENUM': - case 'SET': - return 'C'; - - case 'TEXT': - case 'LONGTEXT': - case 'MEDIUMTEXT': - return 'XL'; - - case 'IMAGE': - case 'LONGBLOB': - case 'BLOB': - case 'MEDIUMBLOB': - return 'B'; - - case 'YEAR': - case 'DATE': - return 'D'; - - case 'TIME': - case 'DATETIME': - case 'TIMESTAMP': - return 'T'; - - case 'FLOAT': - case 'DOUBLE': - return 'F'; - - case 'INT': - case 'INTEGER': - case 'TINYINT': - case 'SMALLINT': - case 'MEDIUMINT': - case 'BIGINT': - return 'I8'; // we always return I8 to be on the safe side. Under some circumstances the fields are to small otherwise... - - default: - return 'N'; - } - } - - /** - * Return actual MySQL type for meta field type - * - * @param string Meta type (currenly ADOdb syntax only, http://phplens.com/lens/adodb/docs-adodb.htm#metatype) - * @return string native type as reported as in mysqldump files, uppercase - */ - public function MySQLActualType($meta) { - switch (strtoupper($meta)) { - case 'C': - return 'VARCHAR'; - case 'XL': - case 'X': - return 'LONGTEXT'; - - case 'C2': - return 'VARCHAR'; - case 'X2': - return 'LONGTEXT'; - - case 'B': - return 'LONGBLOB'; - - case 'D': - return 'DATE'; - case 'T': - return 'DATETIME'; - case 'L': - return 'TINYINT'; - - case 'I': - case 'I1': - case 'I2': - case 'I4': - case 'I8': - return 'BIGINT'; // we only have I8 in DBAL, see MySQLMetaType() - - case 'F': - return 'DOUBLE'; - case 'N': - return 'NUMERIC'; - - default: - return $meta; - } - } - - - /************************************** - * - * SQL wrapper functions (Overriding parent methods) - * (For use in your applications) - * - **************************************/ - - /** - * Returns the error status on the most recent sql() execution (based on $this->lastHandlerKey) - * - * @return string Handler error strings - */ - public function sql_error() { - switch ($this->handlerCfg[$this->lastHandlerKey]['type']) { - case 'native': - $output = mysql_error($this->handlerInstance[$this->lastHandlerKey]['link']); - break; - case 'adodb': - $output = $this->handlerInstance[$this->lastHandlerKey]->ErrorMsg(); - break; - case 'userdefined': - $output = $this->handlerInstance[$this->lastHandlerKey]->sql_error(); - break; - } - return $output; - } - - /** - * Returns the error number on the most recent sql() execution (based on $this->lastHandlerKey) - * - * @return int Handler error number - */ - public function sql_errno() { - switch ($this->handlerCfg[$this->lastHandlerKey]['type']) { - case 'native': - $output = mysql_errno($this->handlerInstance[$this->lastHandlerKey]['link']); - break; - case 'adodb': - $output = $this->handlerInstance[$this->lastHandlerKey]->ErrorNo(); - break; - case 'userdefined': - $output = $this->handlerInstance[$this->lastHandlerKey]->sql_errno(); - break; - } - return $output; - } - - /** - * Returns the number of selected rows. - * - * @param pointer Result pointer / DBAL object - * @return integer Number of resulting rows. - */ - public function sql_num_rows(&$res) { - if ($res === FALSE) { - return 0; - } - - $handlerType = is_object($res) ? $res->TYPO3_DBAL_handlerType : 'native'; - switch ($handlerType) { - case 'native': - $output = mysql_num_rows($res); - break; - case 'adodb': - $output = method_exists($res, 'RecordCount') ? $res->RecordCount() : 0; - break; - case 'userdefined': - $output = $res->sql_num_rows(); - break; - } - return $output; - } - - /** - * Returns an associative array that corresponds to the fetched row, or FALSE if there are no more rows. - * - * @param pointer MySQL result pointer (of SELECT query) / DBAL object - * @return array Associative array of result row. - */ - public function sql_fetch_assoc(&$res) { - $output = array(); - - $handlerType = is_object($res) ? $res->TYPO3_DBAL_handlerType : (is_resource($res) ? 'native' : FALSE); - switch ($handlerType) { - case 'native': - $output = mysql_fetch_assoc($res); - $tableList = $this->resourceIdToTableNameMap[(string) $res]; // Reading list of tables from SELECT query: - break; - case 'adodb': - // Check if method exists for the current $res object. - // If a table exists in TCA but not in the db, a error - // occured because $res is not a valid object. - if (method_exists($res, 'FetchRow')) { - $output = $res->FetchRow(); - $tableList = $res->TYPO3_DBAL_tableList; // Reading list of tables from SELECT query: - - // Removing all numeric/integer keys. - // A workaround because in ADOdb we would need to know what we want before executing the query... - // MSSQL does not support ADODB_FETCH_BOTH and always returns an assoc. array instead. So - // we don't need to remove anything. - if (is_array($output)) { - if ($this->runningADOdbDriver('mssql')) { - // MSSQL does not know such thing as an empty string. So it returns one space instead, which we must fix. - foreach ($output as $key => $value) { - if ($value === ' ') { - $output[$key] = ''; - } - } - } else { - foreach ($output as $key => $value) { - if (is_integer($key)) { - unset($output[$key]); - } - } - } - } - } - break; - case 'userdefined': - $output = $res->sql_fetch_assoc(); - $tableList = $res->TYPO3_DBAL_tableList; // Reading list of tables from SELECT query: - break; - } - - // Table/Fieldname mapping: - if (is_array($output)) { - if ($tables = $this->map_needMapping($tableList, TRUE)) { - $output = $this->map_assocArray($output, $tables, 1); - } - } - - // Return result: - return $output; - } - - /** - * Returns an array that corresponds to the fetched row, or FALSE if there are no more rows. - * The array contains the values in numerical indices. - * - * @param pointer MySQL result pointer (of SELECT query) / DBAL object - * @return array Array with result rows. - */ - public function sql_fetch_row(&$res) { - $handlerType = is_object($res) ? $res->TYPO3_DBAL_handlerType : 'native'; - switch ($handlerType) { - case 'native': - $output = mysql_fetch_row($res); - break; - case 'adodb': - // Check if method exists for the current $res object. - // If a table exists in TCA but not in the db, a error - // occured because $res is not a valid object. - if (method_exists($res, 'FetchRow')) { - $output = $res->FetchRow(); - - // Removing all assoc. keys. - // A workaround because in ADOdb we would need to know what we want before executing the query... - // MSSQL does not support ADODB_FETCH_BOTH and always returns an assoc. array instead. So - // we need to convert resultset. - if (is_array($output)) { - $keyIndex = 0; - foreach ($output as $key => $value) { - unset($output[$key]); - if (is_integer($key) || $this->runningADOdbDriver('mssql')) { - $output[$keyIndex] = $value; - if ($value === ' ') { - // MSSQL does not know such thing as an empty string. So it returns one space instead, which we must fix. - $output[$keyIndex] = ''; - } - $keyIndex++; - } - } - } - } - break; - case 'userdefined': - $output = $res->sql_fetch_row(); - break; - } - return $output; - } - - /** - * Free result memory / unset result object - * - * @param pointer MySQL result pointer to free / DBAL object - * @return boolean Returns TRUE on success or FALSE on failure. - */ - public function sql_free_result(&$res) { - if ($res === FALSE) { - return FALSE; - } - - $handlerType = is_object($res) ? $res->TYPO3_DBAL_handlerType : 'native'; - switch ($handlerType) { - case 'native': - $output = mysql_free_result($res); - break; - case 'adodb': - if (method_exists($res, 'Close')) { - $res->Close(); - unset($res); - $output = TRUE; - } else { - $output = FALSE; - } - break; - case 'userdefined': - unset($res); - break; - } - return $output; - } - - /** - * Get the ID generated from the previous INSERT operation - * - * @return integer The uid of the last inserted record. - */ - public function sql_insert_id() { - switch ($this->handlerCfg[$this->lastHandlerKey]['type']) { - case 'native': - $output = mysql_insert_id($this->handlerInstance[$this->lastHandlerKey]['link']); - break; - case 'adodb': - $output = $this->handlerInstance[$this->lastHandlerKey]->last_insert_id; - break; - case 'userdefined': - $output = $this->handlerInstance[$this->lastHandlerKey]->sql_insert_id(); - break; - } - return $output; - } - - /** - * Returns the number of rows affected by the last INSERT, UPDATE or DELETE query - * - * @return integer Number of rows affected by last query - */ - public function sql_affected_rows() { - switch ($this->handlerCfg[$this->lastHandlerKey]['type']) { - case 'native': - $output = mysql_affected_rows(); - break; - case 'adodb': - $output = $this->handlerInstance[$this->lastHandlerKey]->Affected_Rows(); - break; - case 'userdefined': - $output = $this->handlerInstance[$this->lastHandlerKey]->sql_affected_rows(); - break; - } - return $output; - } - - /** - * Move internal result pointer - * - * @param pointer MySQL result pointer (of SELECT query) / DBAL object - * @param integer Seek result number. - * @return boolean Returns TRUE on success or FALSE on failure. - */ - public function sql_data_seek(&$res, $seek) { - $handlerType = is_object($res) ? $res->TYPO3_DBAL_handlerType : 'native'; - switch ($handlerType) { - case 'native': - $output = mysql_data_seek($res, $seek); - break; - case 'adodb': - $output = $res->Move($seek); - break; - case 'userdefined': - $output = $res->sql_data_seek($seek); - break; - } - return $output; - } - - /** - * Get the type of the specified field in a result - * - * If the first parameter is a string, it is used as table name for the lookup. - * - * @param pointer MySQL result pointer (of SELECT query) / DBAL object / table name - * @param integer Field index. In case of ADOdb a string (field name!) FIXME - * @return string Returns the type of the specified field index - */ - public function sql_field_metatype($table, $field) { - // If $table and/or $field are mapped, use the original names instead - foreach ($this->mapping as $tableName => $tableMapInfo) { - if (isset($tableMapInfo['mapTableName']) && $tableMapInfo['mapTableName'] === $table) { - // Table name is mapped => use original name - $table = $tableName; - } - - if (isset($tableMapInfo['mapFieldNames'])) { - foreach ($tableMapInfo['mapFieldNames'] as $fieldName => $fieldMapInfo) { - if ($fieldMapInfo === $field) { - // Field name is mapped => use original name - $field = $fieldName; - } - } - } - } - - return $this->cache_fieldType[$table][$field]['metaType']; - } - - /** - * Get the type of the specified field in a result - * - * If the first parameter is a string, it is used as table name for the lookup. - * - * @param pointer MySQL result pointer (of SELECT query) / DBAL object / table name - * @param integer Field index. In case of ADOdb a string (field name!) FIXME - * @return string Returns the type of the specified field index - */ - public function sql_field_type(&$res, $pointer) { - if ($res === NULL) { - debug(array('no res in sql_field_type!')); - return 'text'; - } - elseif (is_string($res)) { - if ($res === 'tx_dbal_debuglog') return 'text'; - $handlerType = 'adodb'; - } - else { - $handlerType = is_object($res) ? $res->TYPO3_DBAL_handlerType : 'native'; - } - - switch ($handlerType) { - case 'native': - $output = mysql_field_type($res, $pointer); - break; - case 'adodb': - if (is_string($pointer)) { - $output = $this->cache_fieldType[$res][$pointer]['type']; - } - - break; - case 'userdefined': - $output = $res->sql_field_type($pointer); - break; - } - - return $output; - } - - - /********** - * - * Legacy functions, bound to _DEFAULT handler. (Overriding parent methods) - * Deprecated or still experimental. - * - **********/ - - /** - * Executes query (on DEFAULT handler!) - * DEPRECATED - use exec_* functions from this class instead! - * - * @param string Database name - * @param string Query to execute - * @return pointer Result pointer - * @deprecated since TYPO3 4.1, will be removed in TYPO3 4.6 - */ - public function sql($db, $query) { - t3lib_div::logDeprecatedFunction(); - - return $this->sql_query($query); - } - - /** - * Executes a query - * EXPERIMENTAL - This method will make its best to handle the query correctly - * but if it cannot, it will simply pass the query to DEFAULT handler. - * - * You should use exec_* function from this class instead! - * If you don't, anything that does not use the _DEFAULT handler will probably break! - * - * This method was deprecated in TYPO3 4.1 but is considered experimental since TYPO3 4.4 - * as it tries to handle the query correctly anyway. - * - * @param string Query to execute - * @return pointer Result pointer / DBAL object - */ - public function sql_query($query) { - $globalConfig = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['dbal']); - if ($globalConfig['sql_query.passthrough']) { - return parent::sql_query($query); - } - - // This method is heavily used by Extbase, try to handle it with DBAL-native methods - $queryParts = $this->SQLparser->parseSQL($query); - if (is_array($queryParts) && t3lib_div::inList('SELECT,UPDATE,INSERT,DELETE', $queryParts['type'])) { - return $this->exec_query($queryParts); - } - - switch ($this->handlerCfg['_DEFAULT']['type']) { - case 'native': - $sqlResult = mysql_query($query, $this->handlerInstance['_DEFAULT']['link']); - break; - case 'adodb': - $sqlResult = $this->handlerInstance['_DEFAULT']->Execute($query); - $sqlResult->TYPO3_DBAL_handlerType = 'adodb'; - break; - case 'userdefined': - $sqlResult = $this->handlerInstance['_DEFAULT']->sql_query($query); - $sqlResult->TYPO3_DBAL_handlerType = 'userdefined'; - break; - } - - if ($this->printErrors && $this->sql_error()) { - debug(array($this->lastQuery, $this->sql_error())); - } - - return $sqlResult; - } - - /** - * Opening the _DEFAULT connection handler to the database. - * This is typically done by the scripts "init.php" in the backend or "index_ts.php" in the frontend (tslib_fe->connectToMySQL()) - * You wouldn't need to use this at any time - let TYPO3 core handle this. - * - * @param string Database host IP/domain - * @param string Username to connect with. - * @param string Password to connect with. - * @return mixed Returns handler connection value - * @see handler_init() - */ - public function sql_pconnect($TYPO3_db_host, $TYPO3_db_username, $TYPO3_db_password) { - // Overriding the _DEFAULT handler configuration of username, password, localhost and database name: - $this->handlerCfg['_DEFAULT']['config']['username'] = $TYPO3_db_username; - $this->handlerCfg['_DEFAULT']['config']['password'] = $TYPO3_db_password; - $this->handlerCfg['_DEFAULT']['config']['host'] = $TYPO3_db_host; - $this->handlerCfg['_DEFAULT']['config']['database'] = TYPO3_db; - - // Initializing and output value: - $sqlResult = $this->handler_init('_DEFAULT'); - return $sqlResult; - } - - /** - * Select database for _DEFAULT handler. - * - * @param string Database to connect to. - * @return boolean Always returns TRUE; function is obsolete, database selection is made in handler_init() function! - */ - public function sql_select_db($TYPO3_db) { - return TRUE; - } - - - /************************************** - * - * SQL admin functions - * (For use in the Install Tool and Extension Manager) - * - **************************************/ - - /** - * Listing databases from current MySQL connection. NOTICE: It WILL try to select those databases and thus break selection of current database. - * Use in Install Tool only! - * Usage count/core: 1 - * - * @return array Each entry represents a database name - */ - public function admin_get_dbs() { - $dbArr = array(); - switch ($this->handlerCfg['_DEFAULT']['type']) { - case 'native': - $db_list = mysql_list_dbs($this->link); - while ($row = mysql_fetch_object($db_list)) { - if ($this->sql_select_db($row->Database)) { - $dbArr[] = $row->Database; - } - } - break; - case 'adodb': - // check needed for install tool - otherwise it will just die because the call to - // MetaDatabases is done on a stdClass instance - if (method_exists($this->handlerInstance['_DEFAULT'], 'MetaDatabases')) { - $sqlDBs = $this->handlerInstance['_DEFAULT']->MetaDatabases(); - if (is_array($sqlDBs)) { - foreach ($sqlDBs as $k => $theDB) { - $dbArr[] = $theDB; - } - } - } - break; - case 'userdefined': - $dbArr = $this->handlerInstance['_DEFAULT']->admin_get_tables(); - break; - } - - return $dbArr; - } - - /** - * Returns the list of tables from the system (quering the DBMSs) - * It looks up all tables from the DBMS of the _DEFAULT handler and then add all tables *configured* to be managed by other handlers - * - * When fetching the tables, it skips tables whose names begin with BIN$, as this is taken as a table coming from the "Recycle Bin" on Oracle. - * - * @return array Tables in an array (tablename is in both key and value) - * @todo Should the check for Oracle Recycle Bin stuff be moved elsewhere? - * @todo Should return table details in value! see t3lib_db::admin_get_tables() - */ - public function admin_get_tables() { - $whichTables = array(); - - // Getting real list of tables: - switch ($this->handlerCfg['_DEFAULT']['type']) { - case 'native': - $tables_result = mysql_query('SHOW TABLE STATUS FROM `' . TYPO3_db . '`', $this->handlerInstance['_DEFAULT']['link']); - if (!$this->sql_error()) { - while ($theTable = $this->sql_fetch_assoc($tables_result)) { - $whichTables[$theTable['Name']] = $theTable; - } - } - break; - case 'adodb': - // check needed for install tool - otherwise it will just die because the call to - // MetaTables is done on a stdClass instance - if (method_exists($this->handlerInstance['_DEFAULT'], 'MetaTables')) { - $sqlTables = $this->handlerInstance['_DEFAULT']->MetaTables('TABLES'); - while (list($k, $theTable) = each($sqlTables)) { - if (preg_match('/BIN\$/', $theTable)) continue; // skip tables from the Oracle 10 Recycle Bin - $whichTables[$theTable] = $theTable; - } - } - break; - case 'userdefined': - $whichTables = $this->handlerInstance['_DEFAULT']->admin_get_tables(); - break; - } - - // Check mapping: - if (is_array($this->mapping) && count($this->mapping)) { - - // Mapping table names in reverse, first getting list of real table names: - $tMap = array(); - foreach ($this->mapping as $tN => $tMapInfo) { - if (isset($tMapInfo['mapTableName'])) { - $tMap[$tMapInfo['mapTableName']] = $tN; - } - } - - // Do mapping: - $newList = array(); - foreach ($whichTables as $tN => $tDefinition) { - if (isset($tMap[$tN])) { - $tN = $tMap[$tN]; - } - $newList[$tN] = $tDefinition; - } - - $whichTables = $newList; - } - - // Adding tables configured to reside in other DBMS (handler by other handlers than the default): - if (is_array($this->table2handlerKeys)) { - foreach ($this->table2handlerKeys as $key => $handlerKey) { - $whichTables[$key] = $key; - } - } - - return $whichTables; - } - - /** - * Returns information about each field in the $table (quering the DBMS) - * In a DBAL this should look up the right handler for the table and return compatible information - * This function is important not only for the Install Tool but probably for DBALs as well since they might need to look up table specific information in order to construct correct queries. In such cases this information should probably be cached for quick delivery - * - * @param string Table name - * @return array Field information in an associative array with fieldname => field row - */ - public function admin_get_fields($tableName) { - $output = array(); - - // Do field mapping if needed: - $ORIG_tableName = $tableName; - if ($tableArray = $this->map_needMapping($tableName)) { - - // Table name: - if ($this->mapping[$tableName]['mapTableName']) { - $tableName = $this->mapping[$tableName]['mapTableName']; - } - } - - // Find columns - $this->lastHandlerKey = $this->handler_getFromTableList($ORIG_tableName); - switch ((string) $this->handlerCfg[$this->lastHandlerKey]['type']) { - case 'native': - $columns_res = mysql_query('SHOW columns FROM ' . $tableName, $this->handlerInstance[$this->lastHandlerKey]['link']); - while ($fieldRow = mysql_fetch_assoc($columns_res)) { - $output[$fieldRow['Field']] = $fieldRow; - } - break; - case 'adodb': - $fieldRows = $this->handlerInstance[$this->lastHandlerKey]->MetaColumns($tableName, FALSE); - if (is_array($fieldRows)) { - foreach ($fieldRows as $k => $fieldRow) { - settype($fieldRow, 'array'); - $fieldRow['Field'] = $fieldRow['name']; - $ntype = $this->MySQLActualType($this->MetaType($fieldRow['type'], $tableName)); - $ntype .= (($fieldRow['max_length'] != -1) ? (($ntype == 'INT') ? '(11)' : '(' . $fieldRow['max_length'] . ')') : ''); - $fieldRow['Type'] = strtolower($ntype); - $fieldRow['Null'] = ''; - $fieldRow['Key'] = ''; - $fieldRow['Default'] = $fieldRow['default_value']; - $fieldRow['Extra'] = ''; - $output[$fieldRow['name']] = $fieldRow; - } - } - break; - case 'userdefined': - $output = $this->handlerInstance[$this->lastHandlerKey]->admin_get_fields($tableName); - break; - } - - // mapping should be done: - if (is_array($tableArray) && is_array($this->mapping[$ORIG_tableName]['mapFieldNames'])) { - $revFields = array_flip($this->mapping[$ORIG_tableName]['mapFieldNames']); - - $newOutput = array(); - foreach ($output as $fN => $fInfo) { - if (isset($revFields[$fN])) { - $fN = $revFields[$fN]; - $fInfo['Field'] = $fN; - } - $newOutput[$fN] = $fInfo; - } - $output = $newOutput; - } - - return $output; - } - - /** - * Returns information about each index key in the $table (quering the DBMS) - * In a DBAL this should look up the right handler for the table and return compatible information - * - * @param string Table name - * @return array Key information in a numeric array - */ - public function admin_get_keys($tableName) { - $output = array(); - - // Do field mapping if needed: - $ORIG_tableName = $tableName; - if ($tableArray = $this->map_needMapping($tableName)) { - - // Table name: - if ($this->mapping[$tableName]['mapTableName']) { - $tableName = $this->mapping[$tableName]['mapTableName']; - } - } - - // Find columns - $this->lastHandlerKey = $this->handler_getFromTableList($ORIG_tableName); - switch ((string) $this->handlerCfg[$this->lastHandlerKey]['type']) { - case 'native': - $keyRes = mysql_query('SHOW keys FROM ' . $tableName, $this->handlerInstance[$this->lastHandlerKey]['link']); - while ($keyRow = mysql_fetch_assoc($keyRes)) { - $output[] = $keyRow; - } - break; - case 'adodb': - $keyRows = $this->handlerInstance[$this->lastHandlerKey]->MetaIndexes($tableName); - if ($keyRows !== FALSE) { - while (list($k, $theKey) = each($keyRows)) { - $theKey['Table'] = $tableName; - $theKey['Non_unique'] = (int) !$theKey['unique']; - $theKey['Key_name'] = str_replace($tableName . '_', '', $k); - - // the following are probably not needed anyway... - $theKey['Collation'] = ''; - $theKey['Cardinality'] = ''; - $theKey['Sub_part'] = ''; - $theKey['Packed'] = ''; - $theKey['Null'] = ''; - $theKey['Index_type'] = ''; - $theKey['Comment'] = ''; - - // now map multiple fields into multiple rows (we mimic MySQL, remember...) - $keycols = $theKey['columns']; - while (list($c, $theCol) = each($keycols)) { - $theKey['Seq_in_index'] = $c + 1; - $theKey['Column_name'] = $theCol; - $output[] = $theKey; - } - } - } - $priKeyRow = $this->handlerInstance[$this->lastHandlerKey]->MetaPrimaryKeys($tableName); - $theKey = array(); - $theKey['Table'] = $tableName; - $theKey['Non_unique'] = 0; - $theKey['Key_name'] = 'PRIMARY'; - - // the following are probably not needed anyway... - $theKey['Collation'] = ''; - $theKey['Cardinality'] = ''; - $theKey['Sub_part'] = ''; - $theKey['Packed'] = ''; - $theKey['Null'] = ''; - $theKey['Index_type'] = ''; - $theKey['Comment'] = ''; - - // now map multiple fields into multiple rows (we mimic MySQL, remember...) - if ($priKeyRow !== FALSE) { - while (list($c, $theCol) = each($priKeyRow)) { - $theKey['Seq_in_index'] = $c + 1; - $theKey['Column_name'] = $theCol; - $output[] = $theKey; - } - } - break; - case 'userdefined': - $output = $this->handlerInstance[$this->lastHandlerKey]->admin_get_keys($tableName); - break; - } - - // mapping should be done: - if (is_array($tableArray) && is_array($this->mapping[$ORIG_tableName]['mapFieldNames'])) { - $revFields = array_flip($this->mapping[$ORIG_tableName]['mapFieldNames']); - - $newOutput = array(); - foreach ($output as $kN => $kInfo) { - // Table: - $kInfo['Table'] = $ORIG_tableName; - - // Column - if (isset($revFields[$kInfo['Column_name']])) { - $kInfo['Column_name'] = $revFields[$kInfo['Column_name']]; - } - - // Write it back: - $newOutput[$kN] = $kInfo; - } - $output = $newOutput; - } - - return $output; - } - - /** - * mysql() wrapper function, used by the Install Tool. - * - * @return array - */ - public function admin_get_charsets() { - return array(); - } - - /** - * mysql() wrapper function, used by the Install Tool and EM for all queries regarding management of the database! - * - * @param string Query to execute - * @return pointer Result pointer - */ - public function admin_query($query) { - $parsedQuery = $this->SQLparser->parseSQL($query); - $ORIG_table = $parsedQuery['TABLE']; - - if (is_array($parsedQuery)) { - - // Process query based on type: - switch ($parsedQuery['type']) { - case 'CREATETABLE': - case 'ALTERTABLE': - case 'DROPTABLE': - if (file_exists(PATH_typo3conf . 'temp_fieldInfo.php')) unlink(PATH_typo3conf . 'temp_fieldInfo.php'); - $this->map_genericQueryParsed($parsedQuery); - break; - case 'INSERT': - case 'TRUNCATETABLE': - $this->map_genericQueryParsed($parsedQuery); - break; - case 'CREATEDATABASE': - die('Creating a database with DBAL is not supported. Did you really read the manual?'); - break; - default: - die('ERROR: Invalid Query type (' . $parsedQuery['type'] . ') for ->admin_query() function!: "' . htmlspecialchars($query) . '"'); - break; - } - - // Setting query array (for other applications to access if needed) - $this->lastParsedAndMappedQueryArray = $parsedQuery; - - // Execute query (based on handler derived from the TABLE name which we actually know for once!) - $this->lastHandlerKey = $this->handler_getFromTableList($ORIG_table); - switch ((string) $this->handlerCfg[$this->lastHandlerKey]['type']) { - case 'native': - // Compiling query: - $compiledQuery = $this->SQLparser->compileSQL($this->lastParsedAndMappedQueryArray); - - //if ($this->lastParsedAndMappedQueryArray['type'] == 'INSERT') { - // return mysql_query($compiledQuery, $this->link); - //} - return mysql_query($compiledQuery, $this->link); - break; - case 'adodb': - // Compiling query: - $compiledQuery = $this->SQLparser->compileSQL($this->lastParsedAndMappedQueryArray); - switch ($this->lastParsedAndMappedQueryArray['type']) { - case 'INSERT': - return $this->exec_INSERTquery($this->lastParsedAndMappedQueryArray['TABLE'], $compiledQuery); - case 'TRUNCATETABLE': - return $this->exec_TRUNCATEquery($this->lastParsedAndMappedQueryArray['TABLE']); - } - return $this->handlerInstance[$this->lastHandlerKey]->DataDictionary->ExecuteSQLArray($compiledQuery); - break; - case 'userdefined': - // Compiling query: - $compiledQuery = $this->SQLparser->compileSQL($this->lastParsedAndMappedQueryArray); - - return $this->handlerInstance[$this->lastHandlerKey]->admin_query($compiledQuery); - break; - } - } else die('ERROR: Query could not be parsed: "' . htmlspecialchars($parsedQuery) . '". Query: "' . htmlspecialchars($query) . '"'); - } - - - /************************************ - * - * Handler management - * - **************************************/ - - /** - * Return the handler key pointing to an appropriate database handler as found in $this->handlerCfg array - * Notice: TWO or more tables in the table list MUST use the SAME handler key - otherwise a fatal error is thrown! (Logically, no database can possibly join two tables from separate sources!) - * - * @param string Table list, eg. "pages" or "pages, tt_content" or "pages AS A, tt_content AS B" - * @return string Handler key (see $this->handlerCfg array) for table - */ - public function handler_getFromTableList($tableList) { - - $key = $tableList; - - if (!isset($this->cache_handlerKeyFromTableList[$key])) { - - // Get tables separated: - $_tableList = $tableList; - $tableArray = $this->SQLparser->parseFromTables($_tableList); - - // If success, traverse the tables: - if (is_array($tableArray) && count($tableArray)) { - $outputHandlerKey = ''; - - foreach ($tableArray as $vArray) { - // Find handler key, select "_DEFAULT" if none is specifically configured: - $handlerKey = $this->table2handlerKeys[$vArray['table']] ? $this->table2handlerKeys[$vArray['table']] : '_DEFAULT'; - - // In case of separate handler keys for joined tables: - if ($outputHandlerKey && $handlerKey != $outputHandlerKey) { - die('DBAL fatal error: Tables in this list "' . $tableList . '" didn\'t use the same DB handler!'); - } - - $outputHandlerKey = $handlerKey; - } - - // Check initialized state; if handler is NOT initialized (connected) then we will connect it! - if (!isset($this->handlerInstance[$outputHandlerKey])) { - $this->handler_init($outputHandlerKey); - } - - // Return handler key: - $this->cache_handlerKeyFromTableList[$key] = $outputHandlerKey; - } else { - die('DBAL fatal error: No handler found in handler_getFromTableList() for: "' . $tableList . '" (' . $tableArray . ')'); - } - } - - return $this->cache_handlerKeyFromTableList[$key]; - } - - /** - * Initialize handler (connecting to database) - * - * @param string Handler key - * @return boolean If connection went well, return TRUE - * @see handler_getFromTableList() - */ - public function handler_init($handlerKey) { - - // Find handler configuration: - $cfgArray = $this->handlerCfg[$handlerKey]; - $handlerType = (string) $cfgArray['type']; - $output = FALSE; - - if (is_array($cfgArray)) { - if (!$cfgArray['config']['database']) { - // Configuration is incomplete - return; - } - switch ($handlerType) { - case 'native': - if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['no_pconnect']) { - $link = mysql_connect($cfgArray['config']['host'] . (isset($cfgArray['config']['port']) ? ':' . $cfgArray['config']['port'] : ''), $cfgArray['config']['username'], $cfgArray['config']['password'], TRUE); - } else { - $link = mysql_pconnect($cfgArray['config']['host'] . (isset($cfgArray['config']['port']) ? ':' . $cfgArray['config']['port'] : ''), $cfgArray['config']['username'], $cfgArray['config']['password']); - } - - // Set handler instance: - $this->handlerInstance[$handlerKey] = array('handlerType' => 'native', 'link' => $link); - - // If link succeeded: - if ($link) { - // For default, set ->link (see t3lib_DB) - if ($handlerKey == '_DEFAULT') { - $this->link = $link; - } - - // Select database as well: - if (mysql_select_db($cfgArray['config']['database'], $link)) { - $output = TRUE; - } - $setDBinit = t3lib_div::trimExplode(LF, str_replace("' . LF . '", LF, $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']), TRUE); - foreach ($setDBinit as $v) { - if (mysql_query($v, $link) === FALSE) { - t3lib_div::sysLog('Could not initialize DB connection with query "' . $v . '".', 'Core', 3); - } - } - } else { - t3lib_div::sysLog('Could not connect to MySQL server ' . $cfgArray['config']['host'] . ' with user ' . $cfgArray['config']['username'] . '.', 'Core', 4); - } - break; - case 'adodb': - $output = TRUE; - require_once(t3lib_extMgm::extPath('adodb') . 'adodb/adodb.inc.php'); - if (!defined('ADODB_FORCE_NULLS')) define('ADODB_FORCE_NULLS', 1); - $GLOBALS['ADODB_FORCE_TYPE'] = ADODB_FORCE_VALUE; - $GLOBALS['ADODB_FETCH_MODE'] = ADODB_FETCH_BOTH; - - $this->handlerInstance[$handlerKey] = &ADONewConnection($cfgArray['config']['driver']); - - // Set driver-specific options - if (isset($cfgArray['config']['driverOptions'])) { - foreach ($cfgArray['config']['driverOptions'] as $optionName => $optionValue) { - $optionSetterName = 'set' . ucfirst($optionName); - if (method_exists($this->handlerInstance[$handlerKey], $optionSetterName)) { - $this->handlerInstance[$handlerKey]->$optionSetterName($optionValue); - } else { - $this->handlerInstance[$handlerKey]->$optionName = $optionValue; - } - } - } - - if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['no_pconnect']) { - $this->handlerInstance[$handlerKey]->Connect($cfgArray['config']['host'] . (isset($cfgArray['config']['port']) ? ':' . $cfgArray['config']['port'] : ''), $cfgArray['config']['username'], $cfgArray['config']['password'], $cfgArray['config']['database']); - } else { - $this->handlerInstance[$handlerKey]->PConnect($cfgArray['config']['host'] . (isset($cfgArray['config']['port']) ? ':' . $cfgArray['config']['port'] : ''), $cfgArray['config']['username'], $cfgArray['config']['password'], $cfgArray['config']['database']); - } - if (!$this->handlerInstance[$handlerKey]->isConnected()) { - $dsn = $cfgArray['config']['driver'] . '://' . $cfgArray['config']['username'] . - (strlen($cfgArray['config']['password']) ? ':XXXX@' : '') . - $cfgArray['config']['host'] . (isset($cfgArray['config']['port']) ? ':' . $cfgArray['config']['port'] : '') . '/' . $cfgArray['config']['database'] . - ($GLOBALS['TYPO3_CONF_VARS']['SYS']['no_pconnect'] ? '' : '?persistent=1'); - t3lib_div::sysLog('Could not connect to DB server using ADOdb on ' . $cfgArray['config']['host'] . ' with user ' . $cfgArray['config']['username'] . '.', 'Core', 4); - error_log('DBAL error: Connection to ' . $dsn . ' failed. Maybe PHP doesn\'t support the database?'); - $output = FALSE; - } else { - $this->handlerInstance[$handlerKey]->DataDictionary = NewDataDictionary($this->handlerInstance[$handlerKey]); - $this->handlerInstance[$handlerKey]->last_insert_id = 0; - if (isset($cfgArray['config']['sequenceStart'])) { - $this->handlerInstance[$handlerKey]->sequenceStart = $cfgArray['config']['sequenceStart']; - } else { - $this->handlerInstance[$handlerKey]->sequenceStart = 1; - } - } - break; - case 'userdefined': - // Find class file: - $fileName = t3lib_div::getFileAbsFileName($cfgArray['config']['classFile']); - if (@is_file($fileName)) { - require_once($fileName); - } else die('DBAL error: "' . $fileName . '" was not a file to include.'); - - // Initialize: - $this->handlerInstance[$handlerKey] = t3lib_div::makeInstance($cfgArray['config']['class']); - $this->handlerInstance[$handlerKey]->init($cfgArray, $this); - - if (is_object($this->handlerInstance[$handlerKey])) { - $output = TRUE; - } - break; - default: - die('ERROR: Invalid handler type: "' . $cfgArray['type'] . '"'); - break; - } - - return $output; - } else die('ERROR: No handler for key "' . $handlerKey . '"'); - } - - - /** - * Checks if database is connected. - * - * @return boolean - */ - public function isConnected() { - $result = FALSE; - switch ((string) $this->handlerCfg[$this->lastHandlerKey]['type']) { - case 'native': - $result = is_resource($this->link); - break; - case 'adodb': - case 'userdefined': - $result = is_object($this->handlerInstance[$this->lastHandlerKey]) && $this->handlerInstance[$this->lastHandlerKey]->isConnected(); - break; - } - return $result; - } - - - /** - * Checks whether the DBAL is currently inside an operation running on the "native" DB handler (i.e. MySQL) - * - * @return boolean TRUE if running on "native" DB handler (i.e. MySQL) - */ - public function runningNative() { - return ((string) $this->handlerCfg[$this->lastHandlerKey]['type']==='native'); - } - - - /** - * Checks whether the ADOdb handler is running with a driver that contains the argument - * - * @param string $driver Driver name, matched with strstr(). - * @return boolean TRUE if running with the given driver - */ - public function runningADOdbDriver($driver) { - return strstr($this->handlerCfg[$this->lastHandlerKey]['config']['driver'], $driver); - } - - - /************************************ - * - * Table/Field mapping - * - **************************************/ - - /** - * Checks if mapping is needed for a table(list) - * - * @param string List of tables in query - * @param boolean If TRUE, it will check only if FIELDs are configured and ignore the mapped table name if any. - * @param array Parsed list of tables, should be passed as reference to be reused and prevent double parsing - * @return mixed Returns an array of table names (parsed version of input table) if mapping is needed, otherwise just FALSE. - */ - protected function map_needMapping($tableList, $fieldMappingOnly = FALSE, array &$parsedTableList = array()) { - $key = $tableList . '|' . $fieldMappingOnly; - if (!isset($this->cache_mappingFromTableList[$key])) { - $this->cache_mappingFromTableList[$key] = FALSE; // Default: - - $tables = $this->SQLparser->parseFromTables($tableList); - if (is_array($tables)) { - $parsedTableList = $tables; - foreach ($tables as $tableCfg) { - if ($fieldMappingOnly) { - if (is_array($this->mapping[$tableCfg['table']]['mapFieldNames'])) { - $this->cache_mappingFromTableList[$key] = $tables; - } elseif (is_array($tableCfg['JOIN'])) { - foreach ($tableCfg['JOIN'] as $join) { - if (is_array($this->mapping[$join['withTable']]['mapFieldNames'])) { - $this->cache_mappingFromTableList[$key] = $tables; - break; - } - } - } - } else { - if (is_array($this->mapping[$tableCfg['table']])) { - $this->cache_mappingFromTableList[$key] = $tables; - } elseif (is_array($tableCfg['JOIN'])) { - foreach ($tableCfg['JOIN'] as $join) { - if (is_array($this->mapping[$join['withTable']])) { - $this->cache_mappingFromTableList[$key] = $tables; - break; - } - } - } - } - } - } - } - - return $this->cache_mappingFromTableList[$key]; - } - - /** - * Takes an associated array with field => value pairs and remaps the field names if configured for this table in $this->mapping array. - * Be careful not to map a field name to another existing fields name (although you can use this to swap fieldnames of course...:-) - * Observe mapping problems with join-results (more than one table): Joined queries should always prefix the table name to avoid problems with this. - * Observe that alias fields are not mapped of course (should not be a problem though) - * - * @param array Input array, associative keys - * @param array Array of tables from the query. Normally just one table; many tables in case of a join. NOTICE: for multiple tables (with joins) there MIGHT occur trouble with fields of the same name in the two tables: This function traverses the mapping information for BOTH tables and applies mapping without checking from which table the field really came! - * @param boolean If TRUE, reverse direction. Default direction is to map an array going INTO the database (thus mapping TYPO3 fieldnames to PHYSICAL field names!) - * @return array Output array, with mapped associative keys. - */ - protected function map_assocArray($input, $tables, $rev = FALSE) { - // Traverse tables from query (hopefully only one table): - foreach ($tables as $tableCfg) { - $tableKey = $this->getMappingKey($tableCfg['table']); - if (is_array($this->mapping[$tableKey]['mapFieldNames'])) { - - // Get the map (reversed if needed): - if ($rev) { - $theMap = array_flip($this->mapping[$tableKey]['mapFieldNames']); - } else { - $theMap = $this->mapping[$tableKey]['mapFieldNames']; - } - - // Traverse selected record, map fieldnames: - $output = array(); - foreach ($input as $fN => $value) { - - // Set the field name, change it if found in mapping array: - if ($theMap[$fN]) { - $newKey = $theMap[$fN]; - } else { - $newKey = $fN; - } - - // Set value to fieldname: - $output[$newKey] = $value; - } - - // When done, override the $input array with the result: - $input = $output; - } - } - - // Return input array (which might have been altered in the mean time) - return $input; - } - - /** - * Remaps table/field names in a SELECT query's parts - * - * @param mixed Either parsed list of tables (SQLparser->parseFromTables()) or list of fields to select from the table. This is what comes right after "SELECT ...". Required value. - * @param string Table(s) from which to select. This is what comes right after "FROM ...". Require value. - * @param string Where clause. This is what comes right after "WHERE ...". Can be blank. - * @param string Group by field(s) - * @param string Order by field(s) - * @return void - * @see exec_SELECTquery() - */ - protected function map_remapSELECTQueryParts($select_fields, $from_table, $where_clause, $groupBy, $orderBy) { - // Backup current mapping as it may be altered if aliases on mapped tables are found - $backupMapping = $this->mapping; - - // Tables: - $tables = is_array($from_table) ? $from_table : $this->SQLparser->parseFromTables($from_table); - $defaultTable = $tables[0]['table']; - // Prepare mapping for aliased tables. This will copy the definition of the original table name. - // The alias is prefixed with a database-incompatible character to prevent naming clash with real table name - // Further access to $this->mapping should be made through $this->getMappingKey() method - foreach ($tables as $k => $v) { - if ($v['as'] && is_array($this->mapping[$v['table']]['mapFieldNames'])) { - $mappingKey = $this->getFreeMappingKey($v['as']); - $this->mapping[$mappingKey]['mapFieldNames'] =& $this->mapping[$v['table']]['mapFieldNames']; - } - if (is_array($v['JOIN'])) { - foreach ($v['JOIN'] as $joinCnt => $join) { - if ($join['as'] && is_array($this->mapping[$join['withTable']]['mapFieldNames'])) { - $mappingKey = $this->getFreeMappingKey($join['as']); - $this->mapping[$mappingKey]['mapFieldNames'] =& $this->mapping[$join['withTable']]['mapFieldNames']; - } - } - } - } - foreach ($tables as $k => $v) { - $tableKey = $this->getMappingKey($v['table']); - if ($this->mapping[$tableKey]['mapTableName']) { - $tables[$k]['table'] = $this->mapping[$tableKey]['mapTableName']; - } - // Mapping JOINS - if (is_array($v['JOIN'])) { - foreach ($v['JOIN'] as $joinCnt => $join) { - // Mapping withTable of the JOIN - $withTableKey = $this->getMappingKey($join['withTable']); - if ($this->mapping[$withTableKey]['mapTableName']) { - $tables[$k]['JOIN'][$joinCnt]['withTable'] = $this->mapping[$withTableKey]['mapTableName']; - } - $onPartsArray = array(); - // Mapping ON parts of the JOIN - if (is_array($tables[$k]['JOIN'][$joinCnt]['ON'])) { - foreach ($tables[$k]['JOIN'][$joinCnt]['ON'] as &$condition) { - // Left side of the comparator - $leftTableKey = $this->getMappingKey($condition['left']['table']); - if (isset($this->mapping[$leftTableKey]['mapFieldNames'][$condition['left']['field']])) { - $condition['left']['field'] = $this->mapping[$leftTableKey]['mapFieldNames'][$condition['left']['field']]; - } - if (isset($this->mapping[$leftTableKey]['mapTableName'])) { - $condition['left']['table'] = $this->mapping[$leftTableKey]['mapTableName']; - } - // Right side of the comparator - $rightTableKey = $this->getMappingKey($condition['right']['table']); - if (isset($this->mapping[$rightTableKey]['mapFieldNames'][$condition['right']['field']])) { - $condition['right']['field'] = $this->mapping[$rightTableKey]['mapFieldNames'][$condition['right']['field']]; - } - if (isset($this->mapping[$rightTableKey]['mapTableName'])) { - $condition['right']['table'] = $this->mapping[$rightTableKey]['mapTableName']; - } - } - } - } - } - } - $fromParts = $tables; - - // Where clause: - $parameterReferences = array(); - $whereParts = $this->SQLparser->parseWhereClause($where_clause, '', $parameterReferences); - $this->map_sqlParts($whereParts, $defaultTable); - - // Select fields: - $selectParts = $this->SQLparser->parseFieldList($select_fields); - $this->map_sqlParts($selectParts, $defaultTable); - - // Group By fields - $groupByParts = $this->SQLparser->parseFieldList($groupBy); - $this->map_sqlParts($groupByParts, $defaultTable); - - // Order By fields - $orderByParts = $this->SQLparser->parseFieldList($orderBy); - $this->map_sqlParts($orderByParts, $defaultTable); - - // Restore the original mapping - $this->mapping = $backupMapping; - - return array($selectParts, $fromParts, $whereParts, $groupByParts, $orderByParts, $parameterReferences); - } - - /** - * Returns the key to be used when retrieving information from $this->mapping. This ensures - * that mapping from aliased tables is properly retrieved. - * - * @param string $tableName - * @return string - */ - protected function getMappingKey($tableName) { - // Search deepest alias mapping - while (isset($this->mapping['*' . $tableName])) { - $tableName = '*' . $tableName; - } - return $tableName; - } - - /** - * Returns a free key to be used to store mapping information in $this->mapping. - * - * @param string $tableName - * @return string - */ - protected function getFreeMappingKey($tableName) { - while (isset($this->mapping[$tableName])) { - $tableName = '*' . $tableName; - } - return $tableName; - } - - /** - * Generic mapping of table/field names arrays (as parsed by tx_dbal_sqlengine) - * - * @param array Array with parsed SQL parts; Takes both fields, tables, where-parts, group and order-by. Passed by reference. - * @param string Default table name to assume if no table is found in $sqlPartArray - * @return void - * @access private - * @see map_remapSELECTQueryParts() - */ - protected function map_sqlParts(&$sqlPartArray, $defaultTable) { - $defaultTableKey = $this->getMappingKey($defaultTable); - // Traverse sql Part array: - if (is_array($sqlPartArray)) { - foreach ($sqlPartArray as $k => $v) { - - if (isset($sqlPartArray[$k]['type'])) { - switch ($sqlPartArray[$k]['type']) { - case 'flow-control': - $temp = array($sqlPartArray[$k]['flow-control']); - $this->map_sqlParts($temp, $defaultTable); // Call recursively! - $sqlPartArray[$k]['flow-control'] = $temp[0]; - break; - case 'CASE': - if (isset($sqlPartArray[$k]['case_field'])) { - $fieldArray = explode('.', $sqlPartArray[$k]['case_field']); - if (count($fieldArray) == 1 && is_array($this->mapping[$defaultTableKey]['mapFieldNames']) && isset($this->mapping[$defaultTableKey]['mapFieldNames'][$fieldArray[0]])) { - $sqlPartArray[$k]['case_field'] = $this->mapping[$defaultTableKey]['mapFieldNames'][$fieldArray[0]]; - } - elseif (count($fieldArray) == 2) { - // Map the external table - $table = $fieldArray[0]; - $tableKey = $this->getMappingKey($table); - if (isset($this->mapping[$tableKey]['mapTableName'])) { - $table = $this->mapping[$tableKey]['mapTableName']; - } - // Map the field itself - $field = $fieldArray[1]; - if (is_array($this->mapping[$tableKey]['mapFieldNames']) && isset($this->mapping[$tableKey]['mapFieldNames'][$fieldArray[1]])) { - $field = $this->mapping[$tableKey]['mapFieldNames'][$fieldArray[1]]; - } - $sqlPartArray[$k]['case_field'] = $table . '.' . $field; - } - } - foreach ($sqlPartArray[$k]['when'] as $key => $when) { - $this->map_sqlParts($sqlPartArray[$k]['when'][$key]['when_value'], $defaultTable); - } - break; - } - } - - // Look for sublevel (WHERE parts only) - if (is_array($sqlPartArray[$k]['sub'])) { - $this->map_sqlParts($sqlPartArray[$k]['sub'], $defaultTable); // Call recursively! - } elseif (isset($sqlPartArray[$k]['func'])) { - switch ($sqlPartArray[$k]['func']['type']) { - case 'EXISTS': - $this->map_subquery($sqlPartArray[$k]['func']['subquery']); - break; - case 'FIND_IN_SET': - case 'IFNULL': - case 'LOCATE': - // For the field, look for table mapping (generic): - $t = $sqlPartArray[$k]['func']['table'] ? $sqlPartArray[$k]['func']['table'] : $defaultTable; - $t = $this->getMappingKey($t); - if (is_array($this->mapping[$t]['mapFieldNames']) && $this->mapping[$t]['mapFieldNames'][$sqlPartArray[$k]['func']['field']]) { - $sqlPartArray[$k]['func']['field'] = $this->mapping[$t]['mapFieldNames'][$sqlPartArray[$k]['func']['field']]; - } - if ($this->mapping[$t]['mapTableName']) { - $sqlPartArray[$k]['func']['table'] = $this->mapping[$t]['mapTableName']; - } - break; - } - } else { - // For the field, look for table mapping (generic): - $t = $sqlPartArray[$k]['table'] ? $sqlPartArray[$k]['table'] : $defaultTable; - $t = $this->getMappingKey($t); - - // Mapping field name, if set: - if (is_array($this->mapping[$t]['mapFieldNames']) && isset($this->mapping[$t]['mapFieldNames'][$sqlPartArray[$k]['field']])) { - $sqlPartArray[$k]['field'] = $this->mapping[$t]['mapFieldNames'][$sqlPartArray[$k]['field']]; - } - - // Mapping field name in SQL-functions like MIN(), MAX() or SUM() - if ($this->mapping[$t]['mapFieldNames']) { - $fieldArray = explode('.', $sqlPartArray[$k]['func_content']); - if (count($fieldArray) == 1 && is_array($this->mapping[$t]['mapFieldNames']) && isset($this->mapping[$t]['mapFieldNames'][$fieldArray[0]])) { - $sqlPartArray[$k]['func_content.'][0]['func_content'] = $this->mapping[$t]['mapFieldNames'][$fieldArray[0]]; - $sqlPartArray[$k]['func_content'] = $this->mapping[$t]['mapFieldNames'][$fieldArray[0]]; - } - elseif (count($fieldArray) == 2) { - // Map the external table - $table = $fieldArray[0]; - $tableKey = $this->getMappingKey($table); - if (isset($this->mapping[$tableKey]['mapTableName'])) { - $table = $this->mapping[$tableKey]['mapTableName']; - } - // Map the field itself - $field = $fieldArray[1]; - if (is_array($this->mapping[$tableKey]['mapFieldNames']) && isset($this->mapping[$tableKey]['mapFieldNames'][$fieldArray[1]])) { - $field = $this->mapping[$tableKey]['mapFieldNames'][$fieldArray[1]]; - } - $sqlPartArray[$k]['func_content.'][0]['func_content'] = $table . '.' . $field; - $sqlPartArray[$k]['func_content'] = $table . '.' . $field; - } - - // Mapping flow-control statements - if (isset($sqlPartArray[$k]['flow-control'])) { - if (isset($sqlPartArray[$k]['flow-control']['type'])) { - $temp = array($sqlPartArray[$k]['flow-control']); - $this->map_sqlParts($temp, $t); // Call recursively! - $sqlPartArray[$k]['flow-control'] = $temp[0]; - } - } - } - - // Do we have a function (e.g., CONCAT) - if (isset($v['value']['operator'])) { - foreach ($sqlPartArray[$k]['value']['args'] as $argK => $fieldDef) { - $tableKey = $this->getMappingKey($fieldDef['table']); - if (isset($this->mapping[$tableKey]['mapTableName'])) { - $sqlPartArray[$k]['value']['args'][$argK]['table'] = $this->mapping[$tableKey]['mapTableName']; - } - if (is_array($this->mapping[$tableKey]['mapFieldNames']) && isset($this->mapping[$tableKey]['mapFieldNames'][$fieldDef['field']])) { - $sqlPartArray[$k]['value']['args'][$argK]['field'] = $this->mapping[$tableKey]['mapFieldNames'][$fieldDef['field']]; - } - } - } - - // Do we have a subquery (WHERE parts only)? - if (isset($sqlPartArray[$k]['subquery'])) { - $this->map_subquery($sqlPartArray[$k]['subquery']); - } - - // do we have a field name in the value? - // this is a very simplistic check, beware - if (!is_numeric($sqlPartArray[$k]['value'][0]) && !isset($sqlPartArray[$k]['value'][1])) { - $fieldArray = explode('.', $sqlPartArray[$k]['value'][0]); - if (count($fieldArray) == 1 && is_array($this->mapping[$t]['mapFieldNames']) && isset($this->mapping[$t]['mapFieldNames'][$fieldArray[0]])) { - $sqlPartArray[$k]['value'][0] = $this->mapping[$t]['mapFieldNames'][$fieldArray[0]]; - } elseif (count($fieldArray) == 2) { - // Map the external table - $table = $fieldArray[0]; - $tableKey = $this->getMappingKey($table); - if (isset($this->mapping[$tableKey]['mapTableName'])) { - $table = $this->mapping[$tableKey]['mapTableName']; - } - // Map the field itself - $field = $fieldArray[1]; - if (is_array($this->mapping[$tableKey]['mapFieldNames']) && isset($this->mapping[$tableKey]['mapFieldNames'][$fieldArray[1]])) { - $field = $this->mapping[$tableKey]['mapFieldNames'][$fieldArray[1]]; - } - $sqlPartArray[$k]['value'][0] = $table . '.' . $field; - } - } - - // Map table? - $tableKey = $this->getMappingKey($sqlPartArray[$k]['table']); - if ($sqlPartArray[$k]['table'] && $this->mapping[$tableKey]['mapTableName']) { - $sqlPartArray[$k]['table'] = $this->mapping[$tableKey]['mapTableName']; - } - } - } - } - } - - /** - * Maps table and field names in a subquery. - * - * @param array $parsedQuery - * @return void - */ - protected function map_subquery(&$parsedQuery) { - // Backup current mapping as it may be altered - $backupMapping = $this->mapping; - - foreach ($parsedQuery['FROM'] as $k => $v) { - $mappingKey = $v['table']; - if ($v['as'] && is_array($this->mapping[$v['table']]['mapFieldNames'])) { - $mappingKey = $this->getFreeMappingKey($v['as']); - } else { - // Should ensure that no alias is defined in the external query - // which would correspond to a real table name in the subquery - if ($this->getMappingKey($v['table']) !== $v['table']) { - $mappingKey = $this->getFreeMappingKey($v['table']); - // This is the only case when 'mapTableName' should be copied - $this->mapping[$mappingKey]['mapTableName'] =& $this->mapping[$v['table']]['mapTableName']; - } - } - if ($mappingKey !== $v['table']) { - $this->mapping[$mappingKey]['mapFieldNames'] =& $this->mapping[$v['table']]['mapFieldNames']; - } - } - - // Perform subquery's remapping - $defaultTable = $parsedQuery['FROM'][0]['table']; - $this->map_sqlParts($parsedQuery['SELECT'], $defaultTable); - $this->map_sqlParts($parsedQuery['FROM'], $defaultTable); - $this->map_sqlParts($parsedQuery['WHERE'], $defaultTable); - - // Restore the mapping - $this->mapping = $backupMapping; - } - - /** - * Will do table/field mapping on a general tx_dbal_sqlengine-compliant SQL query - * (May still not support all query types...) - * - * @param array Parsed QUERY as from tx_dbal_sqlengine::parseSQL(). NOTICE: Passed by reference! - * @return void - * @see tx_dbal_sqlengine::parseSQL() - */ - protected function map_genericQueryParsed(&$parsedQuery) { - - // Getting table - same for all: - $table = $parsedQuery['TABLE']; - if ($table) { - // Do field mapping if needed: - if ($tableArray = $this->map_needMapping($table)) { - - // Table name: - if ($this->mapping[$table]['mapTableName']) { - $parsedQuery['TABLE'] = $this->mapping[$table]['mapTableName']; - } - - // Based on type, do additional changes: - switch ($parsedQuery['type']) { - case 'ALTERTABLE': - - // Changing field name: - $newFieldName = $this->mapping[$table]['mapFieldNames'][$parsedQuery['FIELD']]; - if ($newFieldName) { - if ($parsedQuery['FIELD'] == $parsedQuery['newField']) { - $parsedQuery['FIELD'] = $parsedQuery['newField'] = $newFieldName; - } else $parsedQuery['FIELD'] = $newFieldName; - } - - // Changing key field names: - if (is_array($parsedQuery['fields'])) { - $this->map_fieldNamesInArray($table, $parsedQuery['fields']); - } - break; - case 'CREATETABLE': - // Remapping fields: - if (is_array($parsedQuery['FIELDS'])) { - $newFieldsArray = array(); - foreach ($parsedQuery['FIELDS'] as $fN => $fInfo) { - if ($this->mapping[$table]['mapFieldNames'][$fN]) { - $fN = $this->mapping[$table]['mapFieldNames'][$fN]; - } - $newFieldsArray[$fN] = $fInfo; - } - $parsedQuery['FIELDS'] = $newFieldsArray; - } - - // Remapping keys: - if (is_array($parsedQuery['KEYS'])) { - foreach ($parsedQuery['KEYS'] as $kN => $kInfo) { - $this->map_fieldNamesInArray($table, $parsedQuery['KEYS'][$kN]); - } - } - break; - - /// ... and here support for all other query types should be! - - } - } - } else die('ERROR, mapping: No table found in parsed Query array...'); - } - - /** - * Re-mapping field names in array - * - * @param string (TYPO3) Table name for fields. - * @param array Array of fieldnames to remap. Notice: Passed by reference! - * @return void - */ - protected function map_fieldNamesInArray($table, &$fieldArray) { - if (is_array($this->mapping[$table]['mapFieldNames'])) { - foreach ($fieldArray as $k => $v) { - if ($this->mapping[$table]['mapFieldNames'][$v]) { - $fieldArray[$k] = $this->mapping[$table]['mapFieldNames'][$v]; - } - } - } - } - - - /************************************** - * - * Debugging - * - **************************************/ - - /** - * Debug handler for query execution - * - * @param string Function name from which this function is called. - * @param string Execution time in ms of the query - * @param array In-data of various kinds. - * @return void - * @access private - */ - public function debugHandler($function, $execTime, $inData) { - // we don't want to log our own log/debug SQL - $script = substr(PATH_thisScript, strlen(PATH_site)); - - if (substr($script, -strlen('dbal/mod1/index.php')) != 'dbal/mod1/index.php' && !strstr($inData['args'][0], 'tx_dbal_debuglog')) { - $data = array(); - $errorFlag = 0; - $joinTable = ''; - - if ($this->sql_error()) { - $data['sqlError'] = $this->sql_error(); - $errorFlag |= 1; - } - - // if lastQuery is empty (for whatever reason) at least log inData.args - if (empty($this->lastQuery)) { - $query = implode(' ', $inData['args']); - } else { - $query = $this->lastQuery; - } - - if ($this->conf['debugOptions']['numberRows']) { - switch ($function) { - case 'exec_INSERTquery': - case 'exec_UPDATEquery': - case 'exec_DELETEquery': - $data['numberRows'] = $this->sql_affected_rows(); - break; - case 'exec_SELECTquery': - $data['numberRows'] = $inData['numberRows']; - break; - } - } - - if ($this->conf['debugOptions']['backtrace']) { - $backtrace = debug_backtrace(); - unset($backtrace[0]); // skip this very method :) - $data['backtrace'] = array_slice($backtrace, 0, $this->conf['debugOptions']['backtrace']); - } - - switch ($function) { - case 'exec_INSERTquery': - case 'exec_UPDATEquery': - case 'exec_DELETEquery': - $this->debug_log($query, $execTime, $data, $joinTable, $errorFlag, $script); - break; - - case 'exec_SELECTquery': - // Get explain data: - if ($this->conf['debugOptions']['EXPLAIN'] && t3lib_div::inList('adodb,native', $inData['handlerType'])) { - $data['EXPLAIN'] = $this->debug_explain($this->lastQuery); - } - - // Check parsing of Query: - if ($this->conf['debugOptions']['parseQuery']) { - $parseResults = array(); - $parseResults['SELECT'] = $this->SQLparser->debug_parseSQLpart('SELECT', $inData['args'][1]); - $parseResults['FROM'] = $this->SQLparser->debug_parseSQLpart('FROM', $inData['args'][0]); - $parseResults['WHERE'] = $this->SQLparser->debug_parseSQLpart('WHERE', $inData['args'][2]); - $parseResults['GROUPBY'] = $this->SQLparser->debug_parseSQLpart('SELECT', $inData['args'][3]); // Using select field list syntax - $parseResults['ORDERBY'] = $this->SQLparser->debug_parseSQLpart('SELECT', $inData['args'][4]); // Using select field list syntax - - foreach ($parseResults as $k => $v) { - if (!strlen($parseResults[$k])) unset($parseResults[$k]); - } - if (count($parseResults)) { - $data['parseError'] = $parseResults; - $errorFlag |= 2; - } - } - - // Checking joinTables: - if ($this->conf['debugOptions']['joinTables']) { - if (count(explode(',', $inData['ORIG_from_table'])) > 1) { - $joinTable = $inData['args'][0]; - } - } - - // Logging it: - $this->debug_log($query, $execTime, $data, $joinTable, $errorFlag, $script); - if (!empty($inData['args'][2])) - $this->debug_WHERE($inData['args'][0], $inData['args'][2], $script); - break; - } - } - } - - /** - * Logs the where clause for debugging purposes. - * - * @param string $table Table name(s) the query was targeted at - * @param string $where The WHERE clause to be logged - * @param string $script The script calling the logging - * @return void - */ - public function debug_WHERE($table, $where, $script = '') { - $insertArray = array( - 'tstamp' => $GLOBALS['EXEC_TIME'], - 'beuser_id' => intval($GLOBALS['BE_USER']->user['uid']), - 'script' => $script, - 'tablename' => $table, - 'whereclause' => $where - ); - - $this->exec_INSERTquery('tx_dbal_debuglog_where', $insertArray); - } - - /** - * Inserts row in the log table - * - * @param string The current query - * @param integer Execution time of query in milliseconds - * @param array Data to be stored serialized. - * @param string Join string if there IS a join. - * @param integer Error status. - * @param string $script The script calling the logging - * @return void - */ - public function debug_log($query, $ms, $data, $join, $errorFlag, $script = '') { - if (is_array($query)) { - $queryToLog = $query[0] . ' -- '; - if (count($query[1])) { - $queryToLog .= count($query[1]) . ' BLOB FIELDS: ' . implode(', ', array_keys($query[1])); - } - if (count($query[2])) { - $queryToLog .= count($query[2]) . ' CLOB FIELDS: ' . implode(', ', array_keys($query[2])); - } - } else { - $queryToLog = $query; - } - $insertArray = array( - 'tstamp' => $GLOBALS['EXEC_TIME'], - 'beuser_id' => intval($GLOBALS['BE_USER']->user['uid']), - 'script' => $script, - 'exec_time' => $ms, - 'table_join' => $join, - 'serdata' => serialize($data), - 'query' => $queryToLog, - 'errorFlag' => $errorFlag - ); - - $this->exec_INSERTquery('tx_dbal_debuglog', $insertArray); - } - - /** - * Perform EXPLAIN query on DEFAULT handler! - * - * @param string SELECT Query - * @return array The Explain result rows in an array - * @todo Not supporting other than the default handler? And what about DBMS of other kinds than MySQL - support for EXPLAIN? - */ - public function debug_explain($query) { - $output = array(); - $hType = (string) $this->handlerCfg[$this->lastHandlerKey]['type']; - switch ($hType) { - case 'native': - $res = $this->sql_query('EXPLAIN ' . $query); - while ($row = $this->sql_fetch_assoc($res)) { - $output[] = $row; - } - break; - case 'adodb': - switch ($this->handlerCfg['_DEFAULT']['config']['driver']) { - case 'oci8': - $res = $this->sql_query('EXPLAIN PLAN ' . $query); - $output[] = 'EXPLAIN PLAN data logged to default PLAN_TABLE'; - break; - default: - $res = $this->sql_query('EXPLAIN ' . $query); - while ($row = $this->sql_fetch_assoc($res)) { - $output[] = $row; - } - break; - } - break; - } - - return $output; - } -} - - -if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/class.ux_t3lib_db.php'])) { - include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/class.ux_t3lib_db.php']); -} - -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/class.ux_t3lib_sqlparser.php b/typo3/sysext/dbal/class.ux_t3lib_sqlparser.php deleted file mode 100644 index 7f5dc70b8721d60014c8bf85c888b5a591f7d9d6..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/class.ux_t3lib_sqlparser.php +++ /dev/null @@ -1,698 +0,0 @@ -<?php -/*************************************************************** - * Copyright notice - * - * (c) 2004-2009 Kasper Skårhøj (kasperYYYY@typo3.com) - * (c) 2004-2009 Karsten Dambekalns <karsten@typo3.org> - * (c) 2009-2010 Xavier Perseguers <typo3@perseguers.ch> - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * A copy is found in the textfile GPL.txt and important notices to the license - * from the author is found in LICENSE.txt distributed with these scripts. - * - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ -/** - * PHP SQL engine - * - * $Id: class.ux_t3lib_sqlparser.php 42538 2011-01-24 15:04:19Z xperseguers $ - * - * @author Kasper Skårhøj <kasperYYYY@typo3.com> - * @author Karsten Dambekalns <k.dambekalns@fishfarm.de> - * @author Xavier Perseguers <typo3@perseguers.ch> - */ - - -/** - * PHP SQL engine / server - * - * @author Kasper Skårhøj <kasper@typo3.com> - * @package TYPO3 - * @subpackage t3lib - */ -class ux_t3lib_sqlparser extends t3lib_sqlparser { - - /** - * Compiles a "SELECT [output] FROM..:" field list based on input array (made with ->parseFieldList()) - * Can also compile field lists for ORDER BY and GROUP BY. - * - * @param array Array of select fields, (made with ->parseFieldList()) - * @param boolean Whether comments should be compiled - * @param boolean Whether function mapping should take place - * @return string Select field string - * @see parseFieldList() - */ - public function compileFieldList($selectFields, $compileComments = TRUE, $functionMapping = TRUE) { - switch ((string) $GLOBALS['TYPO3_DB']->handlerCfg[$GLOBALS['TYPO3_DB']->lastHandlerKey]['type']) { - case 'native': - $output = parent::compileFieldList($selectFields, $compileComments); - break; - case 'adodb': - $output = ''; - // Traverse the selectFields if any: - if (is_array($selectFields)) { - $outputParts = array(); - foreach ($selectFields as $k => $v) { - - // Detecting type: - switch ($v['type']) { - case 'function': - $outputParts[$k] = $v['function'] . '(' . $v['func_content'] . ')'; - break; - case 'flow-control': - if ($v['flow-control']['type'] === 'CASE') { - $outputParts[$k] = $this->compileCaseStatement($v['flow-control'], $functionMapping); - } - break; - case 'field': - $outputParts[$k] = ($v['distinct'] ? $v['distinct'] : '') . ($v['table'] ? $v['table'] . '.' : '') . $v['field']; - break; - } - - // Alias: - if ($v['as']) { - $outputParts[$k] .= ' ' . $v['as_keyword'] . ' ' . $v['as']; - } - - // Specifically for ORDER BY and GROUP BY field lists: - if ($v['sortDir']) { - $outputParts[$k] .= ' ' . $v['sortDir']; - } - } - // TODO: Handle SQL hints in comments according to current DBMS - if ( /* $compileComments */ - FALSE && $selectFields[0]['comments']) { - $output = $selectFields[0]['comments'] . ' '; - } - $output .= implode(', ', $outputParts); - } - break; - } - return $output; - } - - /** - * Compiles a CASE ... WHEN flow-control construct based on input array (made with ->parseCaseStatement()) - * - * @param array Array of case components, (made with ->parseCaseStatement()) - * @param boolean Whether function mapping should take place - * @return string case when string - * @see parseCaseStatement() - */ - protected function compileCaseStatement(array $components, $functionMapping = TRUE) { - switch ((string) $GLOBALS['TYPO3_DB']->handlerCfg[$GLOBALS['TYPO3_DB']->lastHandlerKey]['type']) { - case 'native': - $output = parent::compileCaseStatement($components); - break; - case 'adodb': - $statement = 'CASE'; - if (isset($components['case_field'])) { - $statement .= ' ' . $components['case_field']; - } elseif (isset($components['case_value'])) { - $statement .= ' ' . $components['case_value'][1] . $components['case_value'][0] . $components['case_value'][1]; - } - foreach ($components['when'] as $when) { - $statement .= ' WHEN '; - $statement .= $this->compileWhereClause($when['when_value'], $functionMapping); - $statement .= ' THEN '; - $statement .= $when['then_value'][1] . $when['then_value'][0] . $when['then_value'][1]; - } - if (isset($components['else'])) { - $statement .= ' ELSE '; - $statement .= $components['else'][1] . $components['else'][0] . $components['else'][1]; - } - $statement .= ' END'; - $output = $statement; - break; - } - return $output; - } - - /** - * Add slashes function used for compiling queries - * This method overrides the method from t3lib_sqlparser because - * the input string is already properly escaped. - * - * @param string Input string - * @return string Output string - */ - protected function compileAddslashes($str) { - return $str; - } - - /************************* - * - * Compiling queries - * - *************************/ - - /** - * Compiles an INSERT statement from components array - * - * @param array Array of SQL query components - * @return string SQL INSERT query / array - * @see parseINSERT() - */ - protected function compileINSERT($components) { - switch ((string) $GLOBALS['TYPO3_DB']->handlerCfg[$GLOBALS['TYPO3_DB']->lastHandlerKey]['type']) { - case 'native': - $query = parent::compileINSERT($components); - break; - case 'adodb': - $values = array(); - - if (isset($components['VALUES_ONLY']) && is_array($components['VALUES_ONLY'])) { - $valuesComponents = $components['EXTENDED'] === '1' ? $components['VALUES_ONLY'] : array($components['VALUES_ONLY']); - $tableFields = array_keys($GLOBALS['TYPO3_DB']->cache_fieldType[$components['TABLE']]); - } else { - $valuesComponents = $components['EXTENDED'] === '1' ? $components['FIELDS'] : array($components['FIELDS']); - $tableFields = array_keys($valuesComponents[0]); - } - - foreach ($valuesComponents as $valuesComponent) { - $fields = array(); - $fc = 0; - foreach ($valuesComponent as $fV) { - $fields[$tableFields[$fc++]] = $fV[0]; - } - $values[] = $fields; - } - $query = count($values) === 1 ? $values[0] : $values; - break; - } - - return $query; - } - - /** - * Compiles a DROP TABLE statement from components array - * - * @param array Array of SQL query components - * @return string SQL DROP TABLE query - * @see compileSQL() - */ - private function compileDROPTABLE($components) { - switch ((string) $GLOBALS['TYPO3_DB']->handlerCfg[$GLOBALS['TYPO3_DB']->lastHandlerKey]['type']) { - case 'native': - $query = 'DROP TABLE' . ($components['ifExists'] ? ' IF EXISTS' : '') . ' ' . $components['TABLE']; - break; - case 'adodb': - $handlerKey = $GLOBALS['TYPO3_DB']->handler_getFromTableList($components['TABLE']); - $tableName = $GLOBALS['TYPO3_DB']->quoteName($components['TABLE'], $handlerKey, TRUE); - $query = $GLOBALS['TYPO3_DB']->handlerInstance[$handlerKey]->DataDictionary->DropTableSQL($tableName); - break; - } - - return $query; - } - - /** - * Compiles a CREATE TABLE statement from components array - * - * @param array Array of SQL query components - * @return array array with SQL CREATE TABLE/INDEX command(s) - * @see parseCREATETABLE() - */ - public function compileCREATETABLE($components) { - // Execute query (based on handler derived from the TABLE name which we actually know for once!) - switch ((string) $GLOBALS['TYPO3_DB']->handlerCfg[$GLOBALS['TYPO3_DB']->handler_getFromTableList($components['TABLE'])]['type']) { - case 'native': - $query[] = parent::compileCREATETABLE($components); - break; - case 'adodb': - // Create fields and keys: - $fieldsKeys = array(); - $indexKeys = array(); - - foreach ($components['FIELDS'] as $fN => $fCfg) { - $handlerKey = $GLOBALS['TYPO3_DB']->handler_getFromTableList($components['TABLE']); - $fieldsKeys[$fN] = $GLOBALS['TYPO3_DB']->quoteName($fN, $handlerKey, TRUE) . ' ' . $this->compileFieldCfg($fCfg['definition']); - } - - if (isset($components['KEYS']) && is_array($components['KEYS'])) { - foreach ($components['KEYS'] as $kN => $kCfg) { - if ($kN === 'PRIMARYKEY') { - foreach ($kCfg as $n => $field) { - $fieldsKeys[$field] .= ' PRIMARY'; - } - } elseif ($kN === 'UNIQUE') { - foreach ($kCfg as $n => $field) { - $indexKeys = array_merge($indexKeys, $GLOBALS['TYPO3_DB']->handlerInstance[$GLOBALS['TYPO3_DB']->handler_getFromTableList($components['TABLE'])]->DataDictionary->CreateIndexSQL($n, $components['TABLE'], $field, array('UNIQUE'))); - } - } else { - $indexKeys = array_merge($indexKeys, $GLOBALS['TYPO3_DB']->handlerInstance[$GLOBALS['TYPO3_DB']->handler_getFromTableList($components['TABLE'])]->DataDictionary->CreateIndexSQL($components['TABLE'] . '_' . $kN, $components['TABLE'], $kCfg)); - } - } - } - - // Generally create without OID on PostgreSQL - $tableOptions = array('postgres' => 'WITHOUT OIDS'); - - // Fetch table/index generation query: - $tableName = $GLOBALS['TYPO3_DB']->quoteName($components['TABLE'], NULL, TRUE); - $query = array_merge($GLOBALS['TYPO3_DB']->handlerInstance[$GLOBALS['TYPO3_DB']->lastHandlerKey]->DataDictionary->CreateTableSQL($tableName, implode(',' . chr(10), $fieldsKeys), $tableOptions), $indexKeys); - break; - } - - return $query; - } - - /** - * Compiles an ALTER TABLE statement from components array - * - * @param array Array of SQL query components - * @return string SQL ALTER TABLE query - * @see parseALTERTABLE() - */ - public function compileALTERTABLE($components) { - // Execute query (based on handler derived from the TABLE name which we actually know for once!) - switch ((string) $GLOBALS['TYPO3_DB']->handlerCfg[$GLOBALS['TYPO3_DB']->lastHandlerKey]['type']) { - case 'native': - $query[] = parent::compileALTERTABLE($components); - break; - case 'adodb': - $tableName = $GLOBALS['TYPO3_DB']->quoteName($components['TABLE'], NULL, TRUE); - $fieldName = $GLOBALS['TYPO3_DB']->quoteName($components['FIELD'], NULL, TRUE); - switch (strtoupper(str_replace(array(' ', "\n", "\r", "\t"), '', $components['action']))) { - case 'ADD': - $query = $GLOBALS['TYPO3_DB']->handlerInstance[$GLOBALS['TYPO3_DB']->lastHandlerKey]->DataDictionary->AddColumnSQL($tableName, $fieldName . ' ' . $this->compileFieldCfg($components['definition'])); - break; - case 'CHANGE': - $query = $GLOBALS['TYPO3_DB']->handlerInstance[$GLOBALS['TYPO3_DB']->lastHandlerKey]->DataDictionary->AlterColumnSQL($tableName, $fieldName . ' ' . $this->compileFieldCfg($components['definition'])); - break; - case 'DROP': - case 'DROPKEY': - break; - case 'ADDKEY': - case 'ADDPRIMARYKEY': - case 'ADDUNIQUE': - $query .= ' (' . implode(',', $components['fields']) . ')'; - break; - case 'DEFAULTCHARACTERSET': - case 'ENGINE': - // ??? todo! - break; - } - break; - } - - return $query; - } - - /** - * Compile field definition - * - * @param array Field definition parts - * @return string Field definition string - */ - public function compileFieldCfg($fieldCfg) { - switch ((string) $GLOBALS['TYPO3_DB']->handlerCfg[$GLOBALS['TYPO3_DB']->lastHandlerKey]['type']) { - case 'native': - $cfg = parent::compileFieldCfg($fieldCfg); - break; - case 'adodb': - // Set type: - $type = $GLOBALS['TYPO3_DB']->MySQLMetaType($fieldCfg['fieldType']); - $cfg = $type; - - // Add value, if any: - if (strlen($fieldCfg['value']) && (in_array($type, array('C', 'C2')))) { - $cfg .= ' ' . $fieldCfg['value']; - } elseif (!isset($fieldCfg['value']) && (in_array($type, array('C', 'C2')))) { - $cfg .= ' 255'; // add 255 as length for varchar without specified length (e.g. coming from tinytext, tinyblob) - } - - // Add additional features: - $noQuote = TRUE; - if (is_array($fieldCfg['featureIndex'])) { - - // MySQL assigns DEFAULT value automatically if NOT NULL, fake this here - // numeric fields get 0 as default, other fields an empty string - if (isset($fieldCfg['featureIndex']['NOTNULL']) && !isset($fieldCfg['featureIndex']['DEFAULT']) && !isset($fieldCfg['featureIndex']['AUTO_INCREMENT'])) { - switch ($type) { - case 'I8': - case 'F': - case 'N': - $fieldCfg['featureIndex']['DEFAULT'] = array('keyword' => 'DEFAULT', 'value' => array('0', '')); - break; - default: - $fieldCfg['featureIndex']['DEFAULT'] = array('keyword' => 'DEFAULT', 'value' => array('', '\'')); - } - } - - foreach ($fieldCfg['featureIndex'] as $feature => $featureDef) { - switch (TRUE) { - // unsigned only for mysql, as it is mysql specific - case ($feature === 'UNSIGNED' && !$GLOBALS['TYPO3_DB']->runningADOdbDriver('mysql')): - // auto_increment is removed, it is handled by (emulated) sequences - case ($feature === 'AUTO_INCREMENT'): - // never add NOT NULL if running on Oracle and we have an empty string as default - case ($feature === 'NOTNULL' && $GLOBALS['TYPO3_DB']->runningADOdbDriver('oci8')): - continue; - case ($feature === 'NOTNULL'): - $cfg .= ' NOTNULL'; - break; - default: - $cfg .= ' ' . $featureDef['keyword']; - } - - // Add value if found: - if (is_array($featureDef['value'])) { - if ($featureDef['value'][0] === '') { - $cfg .= ' "\'\'"'; - } else { - $cfg .= ' ' . $featureDef['value'][1] . $this->compileAddslashes($featureDef['value'][0]) . $featureDef['value'][1]; - if (!is_numeric($featureDef['value'][0])) { - $noQuote = FALSE; - } - } - } - } - } - if ($noQuote) { - $cfg .= ' NOQUOTE'; - } - break; - } - - // Return field definition string: - return $cfg; - } - - /** - * Checks if the submitted feature index contains a default value definition and the default value - * - * @param array $featureIndex A feature index as produced by parseFieldDef() - * @return boolean - * @see t3lib_sqlparser::parseFieldDef() - */ - public function checkEmptyDefaultValue($featureIndex) { - if (is_array($featureIndex['DEFAULT']['value'])) { - if (!is_numeric($featureIndex['DEFAULT']['value'][0]) && empty($featureIndex['DEFAULT']['value'][0])) { - return TRUE; - } else { - return FALSE; - } - } - return TRUE; - } - - /** - * Implodes an array of WHERE clause configuration into a WHERE clause. - * - * DBAL-specific: The only(!) handled "calc" operators supported by parseWhereClause() are: - * - the bitwise logical and (&) - * - the addition (+) - * - the substraction (-) - * - the multiplication (*) - * - the division (/) - * - the modulo (%) - * - * @param array WHERE clause configuration - * @return string WHERE clause as string. - * @see t3lib_sqlparser::parseWhereClause() - */ - public function compileWhereClause($clauseArray, $functionMapping = TRUE) { - switch ((string) $GLOBALS['TYPO3_DB']->handlerCfg[$GLOBALS['TYPO3_DB']->lastHandlerKey]['type']) { - case 'native': - $output = parent::compileWhereClause($clauseArray); - break; - case 'adodb': - // Prepare buffer variable: - $output = ''; - - // Traverse clause array: - if (is_array($clauseArray)) { - foreach ($clauseArray as $k => $v) { - - // Set operator: - $output .= $v['operator'] ? ' ' . $v['operator'] : ''; - - // Look for sublevel: - if (is_array($v['sub'])) { - $output .= ' (' . trim($this->compileWhereClause($v['sub'], $functionMapping)) . ')'; - } elseif (isset($v['func']) && $v['func']['type'] === 'EXISTS') { - $output .= ' ' . trim($v['modifier']) . ' EXISTS (' . $this->compileSELECT($v['func']['subquery']) . ')'; - } else { - - if (isset($v['func']) && $v['func']['type'] === 'LOCATE') { - $output .= ' ' . trim($v['modifier']); - switch (TRUE) { - case ($GLOBALS['TYPO3_DB']->runningADOdbDriver('mssql') && $functionMapping): - $output .= ' CHARINDEX('; - $output .= $v['func']['substr'][1] . $v['func']['substr'][0] . $v['func']['substr'][1]; - $output .= ', ' . ($v['func']['table'] ? $v['func']['table'] . '.' : '') . $v['func']['field']; - $output .= isset($v['func']['pos']) ? ', ' . $v['func']['pos'][0] : ''; - $output .= ')'; - break; - case ($GLOBALS['TYPO3_DB']->runningADOdbDriver('oci8') && $functionMapping): - $output .= ' INSTR('; - $output .= ($v['func']['table'] ? $v['func']['table'] . '.' : '') . $v['func']['field']; - $output .= ', ' . $v['func']['substr'][1] . $v['func']['substr'][0] . $v['func']['substr'][1]; - $output .= isset($v['func']['pos']) ? ', ' . $v['func']['pos'][0] : ''; - $output .= ')'; - break; - default: - $output .= ' LOCATE('; - $output .= $v['func']['substr'][1] . $v['func']['substr'][0] . $v['func']['substr'][1]; - $output .= ', ' . ($v['func']['table'] ? $v['func']['table'] . '.' : '') . $v['func']['field']; - $output .= isset($v['func']['pos']) ? ', ' . $v['func']['pos'][0] : ''; - $output .= ')'; - break; - } - } elseif (isset($v['func']) && $v['func']['type'] === 'IFNULL') { - $output .= ' ' . trim($v['modifier']) . ' '; - switch (TRUE) { - case ($GLOBALS['TYPO3_DB']->runningADOdbDriver('mssql') && $functionMapping): - $output .= 'ISNULL'; - break; - case ($GLOBALS['TYPO3_DB']->runningADOdbDriver('oci8') && $functionMapping): - $output .= 'NVL'; - break; - default: - $output .= 'IFNULL'; - break; - } - $output .= '('; - $output .= ($v['func']['table'] ? $v['func']['table'] . '.' : '') . $v['func']['field']; - $output .= ', ' . $v['func']['default'][1] . $this->compileAddslashes($v['func']['default'][0]) . $v['func']['default'][1]; - $output .= ')'; - } elseif (isset($v['func']) && $v['func']['type'] === 'FIND_IN_SET') { - $output .= ' ' . trim($v['modifier']) . ' '; - if ($functionMapping) { - switch (TRUE) { - case ($GLOBALS['TYPO3_DB']->runningADOdbDriver('mssql')): - $field = ($v['func']['table'] ? $v['func']['table'] . '.' : '') . $v['func']['field']; - if (!isset($v['func']['str_like'])) { - $v['func']['str_like'] = $v['func']['str'][0]; - } - $output .= '\',\'+' . $field . '+\',\' LIKE \'%,' . $v['func']['str_like'] . ',%\''; - break; - case ($GLOBALS['TYPO3_DB']->runningADOdbDriver('oci8')): - $field = ($v['func']['table'] ? $v['func']['table'] . '.' : '') . $v['func']['field']; - if (!isset($v['func']['str_like'])) { - $v['func']['str_like'] = $v['func']['str'][0]; - } - $output .= '\',\'||' . $field . '||\',\' LIKE \'%,' . $v['func']['str_like'] . ',%\''; - break; - case ($GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres')): - $output .= ' FIND_IN_SET('; - $output .= $v['func']['str'][1] . $v['func']['str'][0] . $v['func']['str'][1]; - $output .= ', ' . ($v['func']['table'] ? $v['func']['table'] . '.' : '') . $v['func']['field']; - $output .= ') != 0'; - break; - default: - $field = ($v['func']['table'] ? $v['func']['table'] . '.' : '') . $v['func']['field']; - if (!isset($v['func']['str_like'])) { - $v['func']['str_like'] = $v['func']['str'][0]; - } - $output .= '(' - . $field . ' LIKE \'%,' . $v['func']['str_like'] . ',%\'' - . ' OR ' . $field . ' LIKE \'' . $v['func']['str_like'] . ',%\'' - . ' OR ' . $field . ' LIKE \'%,' . $v['func']['str_like'] . '\'' - . ' OR ' . $field . '= ' . $v['func']['str'][1] . $v['func']['str'][0] . $v['func']['str'][1] - . ')'; - break; - } - } else /* !$functionMapping */ { - switch (TRUE) { - case ($GLOBALS['TYPO3_DB']->runningADOdbDriver('mssql')): - case ($GLOBALS['TYPO3_DB']->runningADOdbDriver('oci8')): - case ($GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres')): - $output .= ' FIND_IN_SET('; - $output .= $v['func']['str'][1] . $v['func']['str'][0] . $v['func']['str'][1]; - $output .= ', ' . ($v['func']['table'] ? $v['func']['table'] . '.' : '') . $v['func']['field']; - $output .= ')'; - break; - default: - $field = ($v['func']['table'] ? $v['func']['table'] . '.' : '') . $v['func']['field']; - if (!isset($v['func']['str_like'])) { - $v['func']['str_like'] = $v['func']['str'][0]; - } - $output .= '(' - . $field . ' LIKE \'%,' . $v['func']['str_like'] . ',%\'' - . ' OR ' . $field . ' LIKE \'' . $v['func']['str_like'] . ',%\'' - . ' OR ' . $field . ' LIKE \'%,' . $v['func']['str_like'] . '\'' - . ' OR ' . $field . '= ' . $v['func']['str'][1] . $v['func']['str'][0] . $v['func']['str'][1] - . ')'; - break; - } - } - } else { - - // Set field/table with modifying prefix if any: - $output .= ' ' . trim($v['modifier']) . ' '; - - // DBAL-specific: Set calculation, if any: - if ($v['calc'] === '&' && $functionMapping) { - switch (TRUE) { - case $GLOBALS['TYPO3_DB']->runningADOdbDriver('oci8'): - // Oracle only knows BITAND(x,y) - sigh - $output .= 'BITAND(' . trim(($v['table'] ? $v['table'] . '.' : '') . $v['field']) . ',' . $v['calc_value'][1] . $this->compileAddslashes($v['calc_value'][0]) . $v['calc_value'][1] . ')'; - break; - default: - // MySQL, MS SQL Server, PostgreSQL support the &-syntax - $output .= trim(($v['table'] ? $v['table'] . '.' : '') . $v['field']) . $v['calc'] . $v['calc_value'][1] . $this->compileAddslashes($v['calc_value'][0]) . $v['calc_value'][1]; - break; - } - } elseif ($v['calc']) { - $output .= trim(($v['table'] ? $v['table'] . '.' : '') . $v['field']) . $v['calc']; - if (isset($v['calc_table'])) { - $output .= trim(($v['calc_table'] ? $v['calc_table'] . '.' : '') . $v['calc_field']); - } else { - $output .= $v['calc_value'][1] . $this->compileAddslashes($v['calc_value'][0]) . $v['calc_value'][1]; - } - } elseif (!($GLOBALS['TYPO3_DB']->runningADOdbDriver('oci8') && preg_match('/(NOT )?LIKE( BINARY)?/', $v['comparator']) && $functionMapping)) { - $output .= trim(($v['table'] ? $v['table'] . '.' : '') . $v['field']); - } - } - - // Set comparator: - if ($v['comparator']) { - $isLikeOperator = preg_match('/(NOT )?LIKE( BINARY)?/', $v['comparator']); - switch (TRUE) { - case ($GLOBALS['TYPO3_DB']->runningADOdbDriver('oci8') && $isLikeOperator && $functionMapping): - // Oracle cannot handle LIKE on CLOB fields - sigh - if (isset($v['value']['operator'])) { - $values = array(); - foreach ($v['value']['args'] as $fieldDef) { - $values[] = ($fieldDef['table'] ? $fieldDef['table'] . '.' : '') . $fieldDef['field']; - } - $compareValue = ' ' . $v['value']['operator'] . '(' . implode(',', $values) . ')'; - } else { - $compareValue = $v['value'][1] . $this->compileAddslashes(trim($v['value'][0], '%')) . $v['value'][1]; - } - if (t3lib_div::isFirstPartOfStr($v['comparator'], 'NOT')) { - $output .= 'NOT '; - } - // To be on the safe side - $isLob = TRUE; - if ($v['table']) { - // Table and field names are quoted: - $tableName = substr($v['table'], 1, strlen($v['table']) - 2); - $fieldName = substr($v['field'], 1, strlen($v['field']) - 2); - $fieldType = $GLOBALS['TYPO3_DB']->sql_field_metatype($tableName, $fieldName); - $isLob = ($fieldType === 'B' || $fieldType === 'XL'); - } - if (strtoupper(substr($v['comparator'], -6)) === 'BINARY') { - if ($isLob) { - $output .= '(dbms_lob.instr(' . trim(($v['table'] ? $v['table'] . '.' : '') . $v['field']) . ', ' . $compareValue . ',1,1) > 0)'; - } else { - $output .= '(instr(' . trim(($v['table'] ? $v['table'] . '.' : '') . $v['field']) . ', ' . $compareValue . ',1,1) > 0)'; - } - } else { - if ($isLob) { - $output .= '(dbms_lob.instr(LOWER(' . trim(($v['table'] ? $v['table'] . '.' : '') . $v['field']) . '), ' . t3lib_div::strtolower($compareValue) . ',1,1) > 0)'; - } else { - $output .= '(instr(LOWER(' . trim(($v['table'] ? $v['table'] . '.' : '') . $v['field']) . '), ' . t3lib_div::strtolower($compareValue) . ',1,1) > 0)'; - } - } - break; - default: - if ($isLikeOperator && $functionMapping) { - if ($GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres') || - $GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres64') || - $GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres7') || - $GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres8')) { - - // Remap (NOT)? LIKE to (NOT)? ILIKE - // and (NOT)? LIKE BINARY to (NOT)? LIKE - switch ($v['comparator']) { - // Remap (NOT)? LIKE to (NOT)? ILIKE - case 'LIKE': - $v['comparator'] = 'ILIKE'; - break; - case 'NOT LIKE': - $v['comparator'] = 'NOT ILIKE'; - break; - default: - $v['comparator'] = str_replace(' BINARY', '', $v['comparator']); - break; - } - } else { - // No more BINARY operator - $v['comparator'] = str_replace(' BINARY', '', $v['comparator']); - } - } - - $output .= ' ' . $v['comparator']; - - // Detecting value type; list or plain: - if (t3lib_div::inList('NOTIN,IN', strtoupper(str_replace(array(' ', TAB, CR, LF), '', $v['comparator'])))) { - if (isset($v['subquery'])) { - $output .= ' (' . $this->compileSELECT($v['subquery']) . ')'; - } else { - $valueBuffer = array(); - foreach ($v['value'] as $realValue) { - $valueBuffer[] = $realValue[1] . $this->compileAddslashes($realValue[0]) . $realValue[1]; - } - $output .= ' (' . trim(implode(',', $valueBuffer)) . ')'; - } - } elseif (t3lib_div::inList('BETWEEN,NOT BETWEEN', $v['comparator'])) { - $lbound = $v['values'][0]; - $ubound = $v['values'][1]; - $output .= ' ' . $lbound[1] . $this->compileAddslashes($lbound[0]) . $lbound[1]; - $output .= ' AND '; - $output .= $ubound[1] . $this->compileAddslashes($ubound[0]) . $ubound[1]; - } elseif (isset($v['value']['operator'])) { - $values = array(); - foreach ($v['value']['args'] as $fieldDef) { - $values[] = ($fieldDef['table'] ? $fieldDef['table'] . '.' : '') . $fieldDef['field']; - } - $output .= ' ' . $v['value']['operator'] . '(' . implode(',', $values) . ')'; - } else { - $output .= ' ' . $v['value'][1] . $this->compileAddslashes($v['value'][0]) . $v['value'][1]; - } - break; - } - } - } - } - } - break; - } - - return $output; - } -} - - -if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/class.ux_t3lib_sqlparser.php'])) { - include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/class.ux_t3lib_sqlparser.php']); -} - -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/doc/class.tslib_fe.php.diff b/typo3/sysext/dbal/doc/class.tslib_fe.php.diff deleted file mode 100644 index 5a1739e181ac40b669ca228b79a357067624874d..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/doc/class.tslib_fe.php.diff +++ /dev/null @@ -1,39 +0,0 @@ -Index: typo3/sysext/cms/tslib/class.tslib_fe.php -=================================================================== -RCS file: /cvsroot/typo3/TYPO3core/typo3/sysext/cms/tslib/class.tslib_fe.php,v -retrieving revision 1.104.2.25 -diff -u -w -r1.104.2.25 class.tslib_fe.php ---- typo3/sysext/cms/tslib/class.tslib_fe.php 7 Jun 2006 10:02:10 -0000 1.104.2.25 -+++ typo3/sysext/cms/tslib/class.tslib_fe.php 27 Jun 2006 19:36:14 -0000 -@@ -1579,16 +1579,22 @@ - - $GLOBALS['TT']->push('Cache Query',''); - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( -- 'S.*', -- 'cache_pages S,pages P', -- 'S.hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->newHash, 'cache_pages').' -- AND S.page_id=P.uid -- AND S.expires > '.intval($GLOBALS['EXEC_TIME']).' -- AND P.deleted=0 -- AND P.hidden=0 -- AND P.starttime<='.intval($GLOBALS['EXEC_TIME']).' -- AND (P.endtime=0 OR P.endtime>'.intval($GLOBALS['EXEC_TIME']).')' -+ '*', -+ 'cache_pages', -+ 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->newHash, 'cache_pages').' -+ AND expires > '.intval($GLOBALS['EXEC_TIME']) - ); -+ if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { -+ $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( -+ 'uid', -+ 'pages', -+ 'uid='.$row['page_id'].' -+ AND deleted=0 -+ AND hidden=0 -+ AND starttime<='.intval($GLOBALS['EXEC_TIME']).' -+ AND (endtime=0 OR endtime>'.intval($GLOBALS['EXEC_TIME']).')' -+ ); -+ } - $GLOBALS['TT']->pull(); - - if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { diff --git a/typo3/sysext/dbal/doc/manual.sxw b/typo3/sysext/dbal/doc/manual.sxw deleted file mode 100644 index 60f94f687d991fc2442531dea1b8a303308cd90c..0000000000000000000000000000000000000000 Binary files a/typo3/sysext/dbal/doc/manual.sxw and /dev/null differ diff --git a/typo3/sysext/dbal/ext_autoload.php b/typo3/sysext/dbal/ext_autoload.php deleted file mode 100644 index 263768b889dc7c8a8b5f916e0bd73efb451e4d5e..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/ext_autoload.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -// DO NOT CHANGE THIS FILE! It is automatically generated by extdeveval::buildAutoloadRegistry. -// This file was generated on 2010-04-06 21:47 - - -$extensionPath = t3lib_extMgm::extPath('dbal'); -return array( - 'tx_dbal_querycache' => $extensionPath . 'lib/class.tx_dbal_querycache.php', - 'tx_dbal_sqlengine' => $extensionPath . 'lib/class.tx_dbal_sqlengine.php', - 'ux_t3lib_sqlparser' => $extensionPath . 'class.ux_t3lib_sqlparser.php', -); -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/ext_conf_template.txt b/typo3/sysext/dbal/ext_conf_template.txt deleted file mode 100644 index 44fe9d19dfde52483d54f4da8f3842ed3f0b3df3..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/ext_conf_template.txt +++ /dev/null @@ -1,6 +0,0 @@ - # cat=basic; type=boolean; label=Enable MySQL pass-through: Method $GLOBALS['TYPO3_DB']->sql_query() is only experimentally supported by DBAL. Its use should be avoided. When active, this flag tells DBAL to not try to parse the query and always send it as-this to MySQL, thus as if DBAL were not loaded. -sql_query.passthrough=1 - - # cat=basic; type=user[EXT:dbal/lib/class.tx_dbal_tsparserext.php:tx_dbal_tsparserext->displayMessage]; -Compatibility= - diff --git a/typo3/sysext/dbal/ext_emconf.php b/typo3/sysext/dbal/ext_emconf.php deleted file mode 100644 index 432e0cd2645d5432bd8ab1a23f95dd08f1f9ab18..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/ext_emconf.php +++ /dev/null @@ -1,52 +0,0 @@ -<?php - -######################################################################## -# Extension Manager/Repository config file for ext "dbal". -# -# Auto generated 26-01-2011 20:08 -# -# Manual updates: -# Only the data in the array - everything else is removed by next -# writing. "version" and "dependencies" must not be touched! -######################################################################## - -$EM_CONF[$_EXTKEY] = array( - 'title' => 'Database Abstraction Layer', - 'description' => 'A database abstraction layer implementation for TYPO3 4.5 based on ADOdb and offering a lot of other features.', - 'category' => 'be', - 'shy' => 0, - 'dependencies' => 'adodb', - 'conflicts' => '', - 'priority' => '', - 'loadOrder' => '', - 'module' => 'mod1', - 'state' => 'stable', - 'internal' => 0, - 'uploadfolder' => 0, - 'createDirs' => '', - 'modify_tables' => '', - 'clearCacheOnLoad' => 0, - 'lockType' => '', - 'author' => 'Xavier Perseguers', - 'author_email' => 'typo3@perseguers.ch', - 'author_company' => '', - 'CGLcompliance' => '', - 'CGLcompliance_note' => '', - 'version' => '1.2.1', - '_md5_values_when_last_written' => 'a:45:{s:9:"ChangeLog";s:4:"459c";s:28:"class.tx_dbal_autoloader.php";s:4:"997d";s:20:"class.tx_dbal_em.php";s:4:"ba79";s:29:"class.tx_dbal_installtool.php";s:4:"efa0";s:26:"class.ux_db_list_extra.php";s:4:"99be";s:21:"class.ux_t3lib_db.php";s:4:"76dd";s:28:"class.ux_t3lib_sqlparser.php";s:4:"e16e";s:16:"ext_autoload.php";s:4:"93d1";s:21:"ext_conf_template.txt";s:4:"9134";s:12:"ext_icon.gif";s:4:"c9ba";s:17:"ext_localconf.php";s:4:"19e0";s:14:"ext_tables.php";s:4:"b187";s:14:"ext_tables.sql";s:4:"1f95";s:19:"last_synched_target";s:4:"da4f";s:27:"doc/class.tslib_fe.php.diff";s:4:"0083";s:14:"doc/manual.sxw";s:4:"7b79";s:45:"handlers/class.tx_dbal_handler_openoffice.php";s:4:"bfe6";s:43:"handlers/class.tx_dbal_handler_rawmysql.php";s:4:"0ba5";s:40:"handlers/class.tx_dbal_handler_xmldb.php";s:4:"a558";s:32:"lib/class.tx_dbal_querycache.php";s:4:"367f";s:31:"lib/class.tx_dbal_sqlengine.php";s:4:"8736";s:33:"lib/class.tx_dbal_tsparserext.php";s:4:"b52c";s:14:"mod1/clear.gif";s:4:"cc11";s:13:"mod1/conf.php";s:4:"6e63";s:14:"mod1/index.php";s:4:"0cc6";s:18:"mod1/locallang.xml";s:4:"0b57";s:22:"mod1/locallang_mod.xml";s:4:"86ef";s:19:"mod1/moduleicon.gif";s:4:"2b8f";s:10:"res/README";s:4:"be19";s:26:"res/Templates/install.html";s:4:"62c9";s:30:"res/oracle/indexed_search.diff";s:4:"ec81";s:23:"res/oracle/realurl.diff";s:4:"86da";s:25:"res/oracle/scheduler.diff";s:4:"7c06";s:27:"res/oracle/templavoila.diff";s:4:"1fd5";s:43:"res/postgresql/postgresql-compatibility.sql";s:4:"bbff";s:22:"tests/BaseTestCase.php";s:4:"e0d1";s:26:"tests/FakeDbConnection.php";s:4:"7914";s:23:"tests/dbGeneralTest.php";s:4:"c1a0";s:21:"tests/dbMssqlTest.php";s:4:"8f26";s:22:"tests/dbOracleTest.php";s:4:"b086";s:26:"tests/dbPostgresqlTest.php";s:4:"f81d";s:30:"tests/sqlParserGeneralTest.php";s:4:"c438";s:31:"tests/fixtures/mssql.config.php";s:4:"cd6d";s:30:"tests/fixtures/oci8.config.php";s:4:"452f";s:36:"tests/fixtures/postgresql.config.php";s:4:"e8d6";}', - 'constraints' => array( - 'depends' => array( - 'adodb' => '5.11.0-', - 'php' => '5.2.0-0.0.0', - 'typo3' => '4.5.0-0.0.0', - ), - 'conflicts' => array( - ), - 'suggests' => array( - ), - ), - 'suggests' => array( - ), -); - -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/ext_icon.gif b/typo3/sysext/dbal/ext_icon.gif deleted file mode 100644 index 8b6190cbaf581de8524eb49a4ba969ab388843f2..0000000000000000000000000000000000000000 Binary files a/typo3/sysext/dbal/ext_icon.gif and /dev/null differ diff --git a/typo3/sysext/dbal/ext_localconf.php b/typo3/sysext/dbal/ext_localconf.php deleted file mode 100644 index 86220e268d97c81af227eb7dd4462abc979a9b51..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/ext_localconf.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php -if (!defined('TYPO3_MODE')) { - die ('Access denied.'); -} - -$GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_db.php'] = t3lib_extMgm::extPath('dbal') . 'class.ux_t3lib_db.php'; -$GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_sqlparser.php'] = t3lib_extMgm::extPath('dbal') . 'class.ux_t3lib_sqlparser.php'; -$GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/class.db_list_extra.inc'] = t3lib_extMgm::extPath('dbal') . 'class.ux_db_list_extra.php'; - -// Register a hook for the installer -$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['stepOutput'][] = 'EXT:dbal/class.tx_dbal_installtool.php:tx_dbal_installtool'; -$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['writeLocalconf'][] = 'EXT:dbal/class.tx_dbal_installtool.php:tx_dbal_installtool'; -$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['requiredPhpModules'][] = 'EXT:dbal/class.tx_dbal_installtool.php:tx_dbal_installtool'; - -// Register a hook for the extension manager -$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/mod/tools/em/index.php']['checkDBupdates'][] = 'EXT:dbal/class.tx_dbal_em.php:tx_dbal_em'; -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/ext_tables.php b/typo3/sysext/dbal/ext_tables.php deleted file mode 100644 index 4f5438c723b9d06f23dff1f0247fbeece421e4a3..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/ext_tables.php +++ /dev/null @@ -1,9 +0,0 @@ -<?php -if (!defined('TYPO3_MODE')) { - die ('Access denied.'); -} - -if (TYPO3_MODE === 'BE') { - t3lib_extMgm::addModule('tools', 'txdbalM1', '', t3lib_extMgm::extPath($_EXTKEY) . 'mod1/'); -} -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/ext_tables.sql b/typo3/sysext/dbal/ext_tables.sql deleted file mode 100644 index 9428be0344d566e012a2ed4bda50fb0e902fe1dd..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/ext_tables.sql +++ /dev/null @@ -1,33 +0,0 @@ - -# -# Table structure for table 'tx_dbal_debuglog' -# -CREATE TABLE tx_dbal_debuglog ( - uid int(11) unsigned NOT NULL auto_increment, - tstamp int(11) unsigned DEFAULT '0', - beuser_id int(11) unsigned DEFAULT '0', - script varchar(255) DEFAULT '' NOT NULL, - exec_time int(11) unsigned DEFAULT '0', - table_join varchar(255) DEFAULT '' NOT NULL, - serdata blob, - query text, - errorFlag int(11) unsigned DEFAULT '0', - - PRIMARY KEY (uid), - KEY tstamp (tstamp) -); - -# -# Table structure for table 'tx_dbal_debuglog_where' -# -CREATE TABLE tx_dbal_debuglog_where ( - uid int(11) unsigned NOT NULL auto_increment, - tstamp int(11) unsigned DEFAULT '0', - beuser_id int(11) unsigned DEFAULT '0', - script varchar(255) DEFAULT '' NOT NULL, - tablename varchar(255) DEFAULT '' NOT NULL, - whereclause text, - - PRIMARY KEY (uid), - KEY tstamp (tstamp) -); diff --git a/typo3/sysext/dbal/handlers/class.tx_dbal_handler_openoffice.php b/typo3/sysext/dbal/handlers/class.tx_dbal_handler_openoffice.php deleted file mode 100644 index 64da9357006c009e35a8e32f108a4811f8eeefb5..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/handlers/class.tx_dbal_handler_openoffice.php +++ /dev/null @@ -1,235 +0,0 @@ -<?php -/*************************************************************** -* Copyright notice -* -* (c) 2004-2009 Kasper Skårhøj (kasper@typo3.com) -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* A copy is found in the textfile GPL.txt and important notices to the license -* from the author is found in LICENSE.txt distributed with these scripts. -* -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ -/** - * Contains an example DBAL handler class - * - * $Id: class.tx_dbal_handler_openoffice.php 40828 2010-12-05 14:55:53Z xperseguers $ - * - * @author Kasper Skårhøj <kasper@typo3.com> - */ -/** - * [CLASS/FUNCTION INDEX of SCRIPT] - * - * - * - * 74: class tx_dbal_handler_xmldb extends tx_dbal_sqlengine - * 91: function init($config, &$pObj) - * 128: function readDataSource($table) - * 157: function saveDataSource($table) - * 184: function xmlDB_writeStructure() - * 193: function xmlDB_readStructure() - * - * SECTION: SQL admin functions - * 217: function admin_get_tables() - * 242: function admin_get_fields($tableName) - * 276: function admin_get_keys($tableName) - * 314: function admin_query($query) - * - * TOTAL FUNCTIONS: 9 - * (This index is automatically created/updated by the extension "extdeveval") - * - */ - - - - - - - - - - -/** - * Example DBAL handler class - * Stores data in an Open Office Calc Spreadsheet - * - * @author Kasper Skårhøj <kasper@typo3.com> - * @package TYPO3 - * @subpackage tx_dbal - */ -class tx_dbal_handler_openoffice extends tx_dbal_sqlengine { - - var $config = array(); - var $pObj; // Set from DBAL class. - - var $spreadSheetFiles = ''; - var $unzip; // Object - - /** - * Initialize handler - * - * @param array Configuration from DBAL - * @param object Parent object - * @return boolean TRUE on success. - */ - function init($config, $pObj) { - $this->config = $config['config']; - - if (t3lib_extMgm::isLoaded('libunzipped')) { - - // Include Unzip library: - require_once(t3lib_extMgm::extPath('libunzipped').'class.tx_libunzipped.php'); - - // Find database file: - $sxc_file = t3lib_div::getFileAbsFileName($this->config['sxc_file']); - if (@is_file($sxc_file)) { - - // Initialize Unzip object: - $this->unzip = t3lib_div::makeInstance('tx_libunzipped'); - $this->spreadSheetFiles = $this->unzip->init($sxc_file); - - if (is_array($this->spreadSheetFiles)) { - return TRUE; - } else $this->errorStatus = 'Spreadsheet could not be unzipped...?'; - } else $this->errorStatus = 'The Spreadsheet file "'.$sxc_file.'" was not found!'; - } else $this->errorStatus = 'This data handler needs the extension "tx_libunzipped" to be installed!'; - - return FALSE; - } - - /** - * Setting table data (overriding function) - * - * @param string Table name - * @return void - */ - function readDataSource($table) { - if (!is_array($this->spreadSheetFiles)) { - die('Spreadsheet Data Source FATAL ERROR: No spreadsheet file loaded. Init() must have failed!'); - } - - $this->data[$table] = array(); - - // Read content.xml: - $content_xml = $this->unzip->getFileFromArchive('content.xml'); - - // Testing for writing back: - $content_xml = str_replace('Felt A1','FELT A1',$content_xml); - - // Writing file back (to database) - $this->unzip->putFileToArchive('content.xml', $content_xml['content']); - - // Writing ZIP content back to zip-archive file: - $result = $this->unzip->compileZipFile($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . 'dbtest_output.sxc'); - - debug($result); - - exit; - } - - /** - * Saving data source - * - * @param string Table name - * @return boolean TRUE on success - */ - function saveDataSource($table) { - } - - - - - - - - - - /************************************** - * - * SQL admin functions - * (For use in the Install Tool and Extension Manager) - * - **************************************/ - - /** - * Returns the list of tables from the database - * - * @return array Tables in an array with tablename as key and an array with status information as value - */ - function admin_get_tables() { - - $whichTables = array(); - return $whichTables; - } - - /** - * Returns information about each field in the $table - * - * @param string Table name - * @return array Field information in an associative array with fieldname => field row - */ - function admin_get_fields($tableName) { - return array(); - } - - /** - * Returns information about each index key in the $table - * - * @param string Table name - * @return array Key information in a numeric array - */ - function admin_get_keys($tableName) { - return array(); - } - - /** - * mysql() wrapper function, used by the Install Tool and EM for all queries regarding management of the database! - * - * @param string Query to execute - * @return pointer Result pointer - */ - function admin_query($query) { - - $parsedQuery = $this->parseSQL($query); - $table = $parsedQuery['TABLE']; - - if (is_array($parsedQuery)) { - // Process query based on type: - switch($parsedQuery['type']) { - case 'CREATETABLE': - break; - case 'ALTERTABLE': - break; - case 'DROPTABLE': - break; - default: - $this->errorStatus = 'Query type "'.$parsedQuery['type'].'" was not supported!'; - break; - } - - } else $this->errorStatus = 'SQL parse error: '.$parsedQuery; - - return FALSE; - } -} - - -if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/handlers/class.tx_dbal_handler_openoffice.php'])) { - include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/handlers/class.tx_dbal_handler_openoffice.php']); -} - -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/handlers/class.tx_dbal_handler_rawmysql.php b/typo3/sysext/dbal/handlers/class.tx_dbal_handler_rawmysql.php deleted file mode 100644 index 0f60525da574b59b80812f1f4c881c25e4328cd9..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/handlers/class.tx_dbal_handler_rawmysql.php +++ /dev/null @@ -1,356 +0,0 @@ -<?php -/*************************************************************** -* Copyright notice -* -* (c) 2004-2009 Kasper Skårhøj (kasper@typo3.com) -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* A copy is found in the textfile GPL.txt and important notices to the license -* from the author is found in LICENSE.txt distributed with these scripts. -* -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ -/** - * Contains an example DBAL handler class - * - * $Id: class.tx_dbal_handler_rawmysql.php 40828 2010-12-05 14:55:53Z xperseguers $ - * - * @author Kasper Skårhøj <kasper@typo3.com> - */ -/** - * [CLASS/FUNCTION INDEX of SCRIPT] - * - * - * - * 86: class tx_dbal_handler_rawmysql extends tx_dbal_sqlengine - * 99: function init($config,&$pObj) - * 123: function exec_INSERTquery($table,$fields_values) - * 135: function exec_UPDATEquery($table,$where,$fields_values) - * 146: function exec_DELETEquery($table,$where) - * 161: function exec_SELECTquery($select_fields,$from_table,$where_clause,$groupBy,$orderBy,$limit) - * 173: function sql_error() - * 182: function sql_insert_id() - * 191: function sql_affected_rows() - * 201: function sql_query($query) - * 213: function quoteStr($str) - * - * SECTION: SQL admin functions - * 237: function admin_get_tables() - * 254: function admin_get_fields($tableName) - * 272: function admin_get_keys($tableName) - * 290: function admin_query($query) - * - * - * 308: class tx_dbal_handler_rawmysql_sqlObj extends tx_dbal_sqlengine_resultobj - * 317: function sql_num_rows() - * 326: function sql_fetch_assoc() - * 335: function sql_fetch_row() - * 345: function sql_data_seek($pointer) - * - * TOTAL FUNCTIONS: 18 - * (This index is automatically created/updated by the extension "extdeveval") - * - */ - - - - - - - - - - -/** - * Example DBAL userdefined handler class - * It simply makes pass-through of MySQL - * - * @author Kasper Skårhøj <kasper@typo3.com> - * @package TYPO3 - * @subpackage tx_dbal - */ -class tx_dbal_handler_rawmysql extends tx_dbal_sqlengine { - - var $config = array(); - var $link; - var $pObj; // Set from DBAL class. - - /** - * Initialize. - * For MySQL we will have to connect to the database and select the database. - * - * @param array Configuration array from handler - * @param object Parent object. - * @return boolean TRUE if connection and database selection worked out well. - */ - function init($config,&$pObj) { - $this->config = $config['config']; - $this->pObj = $pObj; - $this->link = mysql_pconnect( - $this->config['host'], - $this->config['username'], - $this->config['password'] - ); - - // Select database as well: - if (mysql_select_db($this->config['database'], $this->link)) { - $output = TRUE; - } - - return $output; - } - - /** - * Execute INSERT query - * - * @param string Table name - * @param array Field=>Value array - * @return boolean TRUE on success - */ - function exec_INSERTquery($table,$fields_values) { - return mysql_query($GLOBALS['TYPO3_DB']->INSERTquery($table,$fields_values), $this->link); - } - - /** - * Execute UPDATE query - * - * @param string Table name - * @param string WHERE clause - * @param array Field=>Value array - * @return boolean TRUE on success - */ - function exec_UPDATEquery($table,$where,$fields_values) { - return mysql_query($GLOBALS['TYPO3_DB']->UPDATEquery($table,$where,$fields_values), $this->link); - } - - /** - * Execute DELETE query - * - * @param string Table name - * @param string WHERE clause - * @return boolean TRUE on success - */ - function exec_DELETEquery($table,$where) { - return mysql_query($GLOBALS['TYPO3_DB']->DELETEquery($table,$where), $this->link); - } - - /** - * Execute SELECT query - * - * @param string List of fields to select from the table. This is what comes right after "SELECT ...". Required value. - * @param string Table(s) from which to select. This is what comes right after "FROM ...". Required value. - * @param string Optional additional WHERE clauses put in the end of the query. NOTICE: You must escape values with addslashes() first - * @param string Optional GROUP BY field(s), if none, supply blank string. - * @param string Optional ORDER BY field(s), if none, supply blank string. - * @param string Optional LIMIT value ([begin,]max), if none, supply blank string. - * @return object Result object - */ - function exec_SELECTquery($select_fields,$from_table,$where_clause,$groupBy,$orderBy,$limit) { - $res = t3lib_div::makeInstance('tx_dbal_handler_rawmysql_sqlObj'); // Create result object - $this->pObj->lastQuery = $GLOBALS['TYPO3_DB']->SELECTquery($select_fields,$from_table,$where_clause,$groupBy,$orderBy,$limit); - $res->result = mysql(TYPO3_db, $this->pObj->lastQuery, $this->link); // Execute query - return $res; - } - - /** - * mysql_error() wrapper - * - * @return string mysql_error() - */ - function sql_error() { - return mysql_error(); - } - - /** - * mysql_insert_id() wrapper - * - * @return integer mysql_insert_id(); - */ - function sql_insert_id() { - return mysql_insert_id(); - } - - /** - * mysql_affected_rows() wrapper - * - * @return integer mysql_affected_rows() - */ - function sql_affected_rows() { - return mysql_affected_rows(); - } - - /** - * mysql_query() wrapper - * - * @param string Query string - * @return object Result object - */ - function sql_query($query) { - $res = t3lib_div::makeInstance('tx_dbal_handler_rawmysql_sqlObj'); - $res->result = mysql_query($query, $this->link); - return $res; - } - - /** - * Escape quotes in strings - * - * @param string Input string - * @return string Output string - */ - function quoteStr($str) { - return addslashes($str); - } - - - - - - - - - - /************************************** - * - * SQL admin functions - * (For use in the Install Tool and Extension Manager) - * - **************************************/ - - /** - * Returns the list of tables from the database, quering MySQL for it. - * - * @return array Tables in an array (tablename is in both key and value) - * @todo Should return table details in value! see t3lib_db::admin_get_tables() - */ - function admin_get_tables() { - $whichTables = array(); - $tables_result = mysql_list_tables($this->config['database'], $this->link); - if (!mysql_error()) { - while ($theTable = mysql_fetch_assoc($tables_result)) { - $whichTables[current($theTable)] = current($theTable); - } - } - return $whichTables; - } - - /** - * Returns information about each field in the $table, quering MySQL for it. - * - * @param string Table name - * @return array Field information in an associative array with fieldname => field row - */ - function admin_get_fields($tableName) { - $output = array(); - - if ($columns_res = @mysql_query('SHOW columns FROM '.$tableName, $this->link)) { - while($fieldRow = mysql_fetch_assoc($columns_res)) { - $output[$fieldRow["Field"]] = $fieldRow; - } - } - - return $output; - } - - /** - * Returns information about each index key in the $table, quering MySQL for it. - * - * @param string Table name - * @return array Key information in a numeric array - */ - function admin_get_keys($tableName) { - $output = array(); - - if ($keyRes = @mysql_query('SHOW keys FROM '.$tableName, $this->link)) { - while($keyRow = mysql_fetch_assoc($keyRes)) { - $output[] = $keyRow; - } - } - - return $output; - } - - /** - * mysql() wrapper function, used by the Install Tool and EM for all queries regarding management of the database! - * - * @param string Query to execute - * @return pointer Result pointer - */ - function admin_query($query) { - return $this->sql_query($query); - } -} - - - - - - - -/** - * Result object for this MySQL userdefined handler - * - * @author Kasper Skårhøj <kasper@typo3.com> - * @package TYPO3 - * @subpackage tx_dbal - */ -class tx_dbal_handler_rawmysql_sqlObj extends tx_dbal_sqlengine_resultobj { - - var $result = ''; // Not array here, but resource pointer. - - /** - * mysql_num_rows() Wrapper - * - * @return integer mysql_num_rows() - */ - function sql_num_rows() { - return mysql_num_rows($this->result); - } - - /** - * mysql_fetch_assoc() Wrapper - * - * @return array mysql_fetch_assoc() - */ - function sql_fetch_assoc() { - return mysql_fetch_assoc($this->result); - } - - /** - * mysql_fetch_row() wrapper - * - * @return array mysql_fetch_row() - */ - function sql_fetch_row() { - return mysql_fetch_row($this->result); - } - - /** - * mysql_data_seek() wrapper - * - * @param integer Pointer to go to. - * @return boolean mysql_data_seek() - */ - function sql_data_seek($pointer) { - return mysql_data_seek($this->result,$pointer); - } -} - - -if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/handlers/class.tx_dbal_handler_rawmysql.php'])) { - include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/handlers/class.tx_dbal_handler_rawmysql.php']); -} -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/handlers/class.tx_dbal_handler_xmldb.php b/typo3/sysext/dbal/handlers/class.tx_dbal_handler_xmldb.php deleted file mode 100644 index 49846f7d6cb2f52eb5f9f9ff0bb9ed729c438094..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/handlers/class.tx_dbal_handler_xmldb.php +++ /dev/null @@ -1,425 +0,0 @@ -<?php -/*************************************************************** -* Copyright notice -* -* (c) 2004-2009 Kasper Skårhøj (kasper@typo3.com) -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* A copy is found in the textfile GPL.txt and important notices to the license -* from the author is found in LICENSE.txt distributed with these scripts. -* -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ -/** - * Contains an example DBAL handler class - * - * $Id: class.tx_dbal_handler_xmldb.php 40828 2010-12-05 14:55:53Z xperseguers $ - * - * @author Kasper Skårhøj <kasper@typo3.com> - */ -/** - * [CLASS/FUNCTION INDEX of SCRIPT] - * - * - * - * 74: class tx_dbal_handler_xmldb extends tx_dbal_sqlengine - * 91: function init($config, &$pObj) - * 128: function readDataSource($table) - * 157: function saveDataSource($table) - * 184: function xmlDB_writeStructure() - * 193: function xmlDB_readStructure() - * - * SECTION: SQL admin functions - * 217: function admin_get_tables() - * 242: function admin_get_fields($tableName) - * 276: function admin_get_keys($tableName) - * 314: function admin_query($query) - * - * TOTAL FUNCTIONS: 9 - * (This index is automatically created/updated by the extension "extdeveval") - * - */ - - - - - - - - - - -/** - * Example DBAL handler class - * Stores data in XML, not a database. - * - * @author Kasper Skårhøj <kasper@typo3.com> - * @package TYPO3 - * @subpackage tx_dbal - */ -class tx_dbal_handler_xmldb extends tx_dbal_sqlengine { - - var $config = array(); - var $pObj; // Set from DBAL class. - - // Database Storage directory: - var $DBdir = ''; - var $DBstructure = array( - 'tables' => array() - ); - - /** - * Initialize handler - * - * @param array Configuration from DBAL - * @param object Parent object - * @return void - */ - function init($config, $pObj) { - $this->config = $config['config']; - - $dbStorage = t3lib_div::getFileAbsFileName($this->config['DBstorageDir']); - if ($dbStorage && @is_dir($dbStorage) && ($dbStorage{strlen($dbStorage)-1} == '/')) { - $this->DBdir = $dbStorage; - - // Read structure file: - if (@is_file($this->DBdir.'_STRUCTURE.xml')) { - $this->xmlDB_readStructure(); - if (is_array($this->DBstructure)) { - return TRUE; - } else { - $this->errorStatus = 'The database structure array could not be loaded correctly. "_STRUCTURE.xml" may be corrupt'; - } - } else { - $this->xmlDB_writeStructure(); - if (@is_file($this->DBdir.'_STRUCTURE.xml')) { - return TRUE; - } else { - $this->errorStatus = 'The database structure file could not be created in dir "'.$dbStorage.'"'; - } - } - - - } else $this->errorStatus = 'The database storage dir "'.$dbStorage.'" did not exist!'; - -debug($this->errorStatus,'XMLDB connect ERROR:'); - return FALSE; - } - - /** - * Setting table data (overriding function) - * - * @param string Table name - * @return void - */ - function readDataSource($table) { - - if (!$this->DBdir) { - $this->errorStatus = 'XMLdatabase not connected'; - return FALSE; - } - - // Reading table: - if (is_array($this->DBstructure['tables'][$table])) { - if (!isset($this->data[$table])) { // Checking if it has already been read - $newTableFile = 'TABLE_'.$table.'.xml'; - if (@is_file($this->DBdir.$newTableFile)) { - $this->data[$table] = t3lib_div::xml2array(t3lib_div::getUrl($this->DBdir.$newTableFile)); - if (!is_array($this->data[$table])) $this->data[$table] = array(); - return TRUE; - } else { - $this->data[$table] = array(); - $this->errorStatus = 'Tablefile for "'.$table.'" not found'; - } - } - } else $this->errorStatus = 'Table "'.$table.'" not found'; - } - - /** - * Saving data source - * - * @param string Table name - * @return boolean TRUE on success - */ - function saveDataSource($table) { - - if (!$this->DBdir) { - $this->errorStatus = 'XMLdatabase not connected'; - return FALSE; - } - - // Writing table: - if (is_array($this->DBstructure['tables'][$table])) { - $newTableFile = 'TABLE_'.$table.'.xml'; - if (t3lib_div::getFileAbsFileName($this->DBdir.$newTableFile) && @is_file($this->DBdir.$newTableFile)) { - - $storeInCharset = $GLOBALS['LANG']->charSet; - $xmlValue = t3lib_div::array2xml($this->data[$table],'',0,'T3xmlDB',0,array('useIndexTagForNum'=>'rec')); - $content = '<?xml version="1.0" encoding="'.$storeInCharset.'" standalone="yes" ?>'.chr(10).$xmlValue; - t3lib_div::writeFile($this->DBdir.$newTableFile,$content); - - return TRUE; - } else $this->errorStatus = 'Tablefile for "'.$table.'" not found'; - } else $this->errorStatus = 'Table "'.$table.'" not found'; - } - - /** - * Writing database structure - * - * @return void - */ - function xmlDB_writeStructure() { - t3lib_div::writeFile($this->DBdir.'_STRUCTURE.xml', t3lib_div::array2xml($this->DBstructure,'',0,'T3xmlDBStructure',0,array('useIndexTagForNum'=>'item'))); - } - - /** - * Reading database structure - * - * @return void - */ - function xmlDB_readStructure() { - $this->DBstructure = t3lib_div::xml2array(t3lib_div::getUrl($this->DBdir.'_STRUCTURE.xml')); - } - - - - - - - - - - /************************************** - * - * SQL admin functions - * (For use in the Install Tool and Extension Manager) - * - **************************************/ - - /** - * Returns the list of tables from the database - * - * @return array Tables in an array (tablename is in both key and value) - * @todo Should return table details in value! see t3lib_db::admin_get_tables() - */ - function admin_get_tables() { - - if (!$this->DBdir) { - $this->errorStatus = 'XMLdatabase not connected'; - return FALSE; - } - - $whichTables = array(); - - // Traverse tables: - if (is_array($this->DBstructure['tables'])) { - foreach($this->DBstructure['tables'] as $tableName => $tableInfo) { - $whichTables[$tableName] = $tableName; - } - } - - return $whichTables; - } - - /** - * Returns information about each field in the $table - * - * @param string Table name - * @return array Field information in an associative array with fieldname => field row - */ - function admin_get_fields($tableName) { - - if (!$this->DBdir) { - $this->errorStatus = 'XMLdatabase not connected'; - return FALSE; - } - - $output = array(); - - // Traverse fields in table: - if (is_array($this->DBstructure['tables'][$tableName]) && is_array($this->DBstructure['tables'][$tableName]['FIELDS'])) { - foreach($this->DBstructure['tables'][$tableName]['FIELDS'] as $fieldName => $fieldInfo) { - $output[$fieldName] = array( - 'Field' => $fieldName, - 'Type' => $fieldInfo['definition']['fieldType']. - ($fieldInfo['definition']['value']?'('.$fieldInfo['definition']['value'].')':''). - (isset($fieldInfo['definition']['featureIndex']['UNSIGNED']) ? ' '.$fieldInfo['definition']['featureIndex']['UNSIGNED']['keyword'] : ''), - 'Null' => isset($fieldInfo['definition']['featureIndex']['NOTNULL']) ? '' : 'Yes', - 'Key' => '', - 'Default' => $fieldInfo['definition']['featureIndex']['DEFAULT']['value'][0], - 'Extra' => isset($fieldInfo['definition']['featureIndex']['AUTO_INCREMENT']) ? 'auto_increment' : '', - ); - } - } - - return $output; - } - - /** - * Returns information about each index key in the $table - * - * @param string Table name - * @return array Key information in a numeric array - */ - function admin_get_keys($tableName) { - - if (!$this->DBdir) { - $this->errorStatus = 'XMLdatabase not connected'; - return FALSE; - } - - $output = array(); - - // Traverse fields in table: - if (is_array($this->DBstructure['tables'][$tableName]) && is_array($this->DBstructure['tables'][$tableName]['KEYS'])) { - foreach($this->DBstructure['tables'][$tableName]['KEYS'] as $keyName => $keyInfo) { - foreach($keyInfo as $seq => $keyField) { - $output[] = array( - 'Table' => $tableName, - 'Non_unique' => ($keyName=='PRIMARYKEY' ? 0 : 1), - 'Key_name' => ($keyName=='PRIMARYKEY' ? 'PRIMARY' : $keyName), - 'Seq_in_index' => $seq+1, - 'Column_name' => $keyField, - 'Collation' => 'A', - 'Cardinality' => '', - 'Sub_part' => '', - 'Packed' => '', - 'Comment' => '', - ); - } - } - } - - return $output; - } - - /** - * mysql() wrapper function, used by the Install Tool and EM for all queries regarding management of the database! - * - * @param string Query to execute - * @return pointer Result pointer - */ - function admin_query($query) { - - if (!$this->DBdir) { - $this->errorStatus = 'XMLdatabase not connected'; - return FALSE; - } - - $parsedQuery = $this->parseSQL($query); - $table = $parsedQuery['TABLE']; - - if (is_array($parsedQuery)) { - // Process query based on type: - switch($parsedQuery['type']) { - case 'CREATETABLE': - if (!is_array($this->DBstructure['tables'][$table])) { - $newTableFile = 'TABLE_'.$table.'.xml'; - if (!@is_file($this->DBdir.$newTableFile)) { - - // Write table file: - t3lib_div::writeFile($this->DBdir.$newTableFile, ''); // Create file - if (@is_file($this->DBdir.$newTableFile)) { - - // Set and write structure - if (!is_array($this->DBstructure['tables'])) $this->DBstructure['tables']=array(); - $this->DBstructure['tables'][(string)$table] = $parsedQuery; // I have some STRANGE behaviours with this variable - had to do this trick to make it work! - - $this->xmlDB_writeStructure(); - return TRUE; - } else $this->errorStatus = 'Table file "'.$this->DBdir.$newTableFile.'" could not be created! Cannot create table!'; - } else $this->errorStatus = 'Table file "'.$this->DBdir.$newTableFile.'" already exists! Cannot create table!'; - } else $this->errorStatus = 'Table "'.$table.'" already exists!'; - break; - case 'ALTERTABLE': - if (is_array($this->DBstructure['tables'][$table])) { - switch($parsedQuery['action']) { - case 'ADD': - if (!is_array($this->DBstructure['tables'][$table]['FIELDS'][$parsedQuery['FIELD']])) { - $this->DBstructure['tables'][$table]['FIELDS'][$parsedQuery['FIELD']]['definition'] = $parsedQuery['definition']; // Adding field in the end of list. - $this->xmlDB_writeStructure(); - return TRUE; - - // TODO: Should traverse all data an add that field in arrays! - } else $this->errorStatus = 'Field "'.$parsedQuery['FIELD'].'" already exists!'; - break; - case 'CHANGE': - if (is_array($this->DBstructure['tables'][$table]['FIELDS'])) { - if (is_array($this->DBstructure['tables'][$table]['FIELDS'][$parsedQuery['FIELD']])) { - $newFieldInfo = array(); - foreach($this->DBstructure['tables'][$table]['FIELDS'] as $fieldName => $fieldDefinition) { - if (!strcmp($fieldName,$parsedQuery['FIELD'])) { - - // New fieldname? - if ($parsedQuery['newField']) { - if (!is_array($this->DBstructure['tables'][$table]['FIELDS'][$parsedQuery['newField']])) { - $fieldName = $parsedQuery['newField']; - } else { - $this->errorStatus = 'A field in the table was already named "'.$parsedQuery['newField'].'"'; - return FALSE; - } - } - // Set new field definition: - $fieldDefinition['definition'] = $parsedQuery['definition']; - } - - // Set the whole thing in new var: - $newFieldInfo[$fieldName] = $fieldDefinition; - } - $this->DBstructure['tables'][$table]['FIELDS'] = $newFieldInfo; - $this->xmlDB_writeStructure(); - return TRUE; - - // TODO: Should traverse all data an remove that field in arrays! - } else $this->errorStatus = 'Field "'.$parsedQuery['FIELD'].'" does not exist!'; - } else $this->errorStatus = 'There are not fields in the table - strange!'; - break; - case 'DROP': - if (is_array($this->DBstructure['tables'][$table]['FIELDS'][$parsedQuery['FIELD']])) { - unset($this->DBstructure['tables'][$table]['FIELDS'][$parsedQuery['FIELD']]); // Removing it... - $this->xmlDB_writeStructure(); - return TRUE; - - // TODO: Should traverse all data an remove that field in arrays! - } else $this->errorStatus = 'Field "'.$parsedQuery['FIELD'].'" does not exist!'; - break; - } - } else $this->errorStatus = 'Table "'.$table.'" does not exist!'; - break; - case 'DROPTABLE': - - // TODO: - debug($parsedQuery); - - - break; - default: - $this->errorStatus = 'Query type "'.$parsedQuery['type'].'" was not supported!'; - break; - } - - } else $this->errorStatus = 'SQL parse error: '.$parsedQuery; - - return FALSE; - } -} - - -if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/handlers/class.tx_dbal_handler_xmldb.php'])) { - include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/handlers/class.tx_dbal_handler_xmldb.php']); -} -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/last_synched_target b/typo3/sysext/dbal/last_synched_target deleted file mode 100644 index 7ad98c325e505507e4c302727b3d873d72032be9..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/last_synched_target +++ /dev/null @@ -1 +0,0 @@ -https://svn.typo3.org/TYPO3v4/Extensions/dbal/tags/1.2.1/ diff --git a/typo3/sysext/dbal/lib/class.tx_dbal_querycache.php b/typo3/sysext/dbal/lib/class.tx_dbal_querycache.php deleted file mode 100644 index 260bc1295e9e8d2dae4f211a93b2790ff1889ea3..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/lib/class.tx_dbal_querycache.php +++ /dev/null @@ -1,96 +0,0 @@ -<?php -/*************************************************************** - * Copyright notice - * - * (c) 2010 Xavier Perseguers <typo3@perseguers.ch> - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * A copy is found in the textfile GPL.txt and important notices to the license - * from the author is found in LICENSE.txt distributed with these scripts. - * - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - - -/** - * Cache engine helper for generated queries. - * - * $Id$ - * - * @author Xavier Perseguers <typo3@perseguers.ch> - * @package TYPO3 - * @subpackage dbal - */ -class tx_dbal_querycache { - - /** - * Initializes the caching framework by loading the cache manager and factory - * into the global context. - * - * @return void - */ - public static function initializeCachingFramework() { - t3lib_cache::initializeCachingFramework(); - } - - /** - * Initializes the DBAL cache. - * - * @return void - */ - public static function initDbalCache() { - try { - if (is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dbal'])) { - $backend = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dbal']['backend']; - $options = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dbal']['options']; - } else { - // Transient storage, will be better than nothing - $backend = 't3lib_cache_backend_TransientMemoryBackend'; - $options = array(); - } - - $GLOBALS['typo3CacheFactory']->create( - 'dbal', - 't3lib_cache_frontend_VariableFrontend', - $backend, - $options - ); - } catch (t3lib_cache_exception_DuplicateIdentifier $e) { - // Do nothing, a DBAL cache already exists - } - } - - /** - * Returns a proper cache key. - * - * @param mixed $config - * @return void - */ - public static function getCacheKey($config) { - if (is_array($config)) { - return md5(serialize($config)); - } else { - return $config; - } - } -} - -if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/lib/class.tx_dbal_querycache.php'])) { - include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/lib/class.tx_dbal_querycache.php']); -} - -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/lib/class.tx_dbal_sqlengine.php b/typo3/sysext/dbal/lib/class.tx_dbal_sqlengine.php deleted file mode 100644 index 46268024a44806d8dcf80480fbf521b224837967..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/lib/class.tx_dbal_sqlengine.php +++ /dev/null @@ -1,855 +0,0 @@ -<?php -/*************************************************************** - * Copyright notice - * - * (c) 2009-2010 Xavier Perseguers <typo3@perseguers.ch> - * (c) 2004-2009 Kasper Skårhøj <kasperYYYY@typo3.com> - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * A copy is found in the textfile GPL.txt and important notices to the license - * from the author is found in LICENSE.txt distributed with these scripts. - * - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - - -/** - * PHP SQL engine - * - * $Id: class.tx_dbal_sqlengine.php 40828 2010-12-05 14:55:53Z xperseguers $ - * - * @author Kasper Skårhøj <kasperYYYY@typo3.com> - * @author Xavier Perseguers <typo3@perseguers.ch> - */ -/** - * [CLASS/FUNCTION INDEX of SCRIPT] - * - * - * - * 106: class tx_dbal_sqlengine extends ux_t3lib_sqlparser - * 128: public function init($config, $pObj) - * 136: public function resetStatusVars() - * 152: private function processAccordingToConfig(&$value, $fInfo) - * - * SECTION: SQL queries - * 207: public function exec_INSERTquery($table, $fields_values) - * 275: public function exec_UPDATEquery($table, $where, $fields_values) - * 334: public function exec_DELETEquery($table, $where) - * 385: public function exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit) - * 428: public function sql_query($query) - * 439: public function sql_error() - * 448: public function sql_insert_id() - * 457: public function sql_affected_rows() - * 467: public function quoteStr($str) - * - * SECTION: SQL admin functions - * 493: public function admin_get_tables() - * 504: public function admin_get_fields($tableName) - * 515: public function admin_get_keys($tableName) - * 526: public function admin_query($query) - * - * SECTION: Data Source I/O - * 551: public function readDataSource($table) - * 563: public function saveDataSource($table) - * - * SECTION: SQL engine functions (PHP simulation of SQL) - still experimental - * 593: public function selectFromData($table, $where) - * 631: public function select_evalSingle($table,$config,&$itemKeys) - * 750: public function getResultSet($keys, $table, $fieldList) - * - * SECTION: Debugging - * 793: public function debug_printResultSet($array) - * - * - * 832: class tx_dbal_sqlengine_resultobj - * 846: public function sql_num_rows() - * 855: public function sql_fetch_assoc() - * 866: public function sql_fetch_row() - * 884: public function sql_data_seek($pointer) - * 897: public function sql_field_type() - * - * TOTAL FUNCTIONS: 27 - * (This index is automatically created/updated by the extension "extdeveval") - * - */ - - -/** - * PHP SQL engine / server - * Basically this is trying to emulation SQL record selection by PHP, thus allowing SQL queries into alternative data storages managed by PHP. - * EXPERIMENTAL! - * - * @author Kasper Skårhøj <kasperYYYY@typo3.com> - * @package TYPO3 - * @subpackage t3lib - */ -class tx_dbal_sqlengine extends ux_t3lib_sqlparser { - - // array with data records: [table name][num.index] = records - var $data = array(); // Data source storage - - - // Internal, SQL Status vars: - var $errorStatus = ''; // Set with error message of last operation - var $lastInsertedId = 0; // Set with last inserted unique ID - var $lastAffectedRows = 0; // Set with last number of affected rows. - - - /** - * Dummy function for initializing SQL handler. Create you own in derived classes. - * - * @param array Configuration array from handler - * @param object Parent object - * @return void - */ - public function init($config, $pObj) { - } - - /** - * Reset SQL engine status variables (insert id, affected rows, error status) - * - * @return void - */ - public function resetStatusVars() { - $this->errorStatus = ''; - $this->lastInsertedId = 0; - $this->lastAffectedRows = 0; - } - - /** - * Processing of update/insert values based on field type. - * - * The input value is typecast and trimmed/shortened according to the field - * type and the configuration options from the $fInfo parameter. - * - * @param mixed $value The input value to process - * @param array $fInfo Field configuration data - * @return mixed The processed input value - */ - private function processAccordingToConfig(&$value, $fInfo) { - $options = $this->parseFieldDef($fInfo['Type']); - - switch (strtolower($options['fieldType'])) { - case 'int': - case 'smallint': - case 'tinyint': - case 'mediumint': - $value = intval($value); - if ($options['featureIndex']['UNSIGNED']) { - $value = t3lib_div::intInRange($value, 0); - } - break; - case 'double': - $value = (double) $value; - break; - case 'varchar': - case 'char': - $value = substr($value, 0, trim($options['value'])); - break; - case 'text': - case 'blob': - $value = substr($value, 0, 65536); - break; - case 'tinytext': - case 'tinyblob': - $value = substr($value, 0, 256); - break; - case 'mediumtext': - case 'mediumblob': - // ?? - break; - } - } - - - /******************************** - * - * SQL queries - * This is the SQL access functions used when this class is instantiated as a SQL handler with DBAL. Override these in derived classes. - * - ********************************/ - - /** - * Execute an INSERT query - * - * @param string Table name - * @param array Field values as key=>value pairs. - * @return boolean TRUE on success and FALSE on failure (error is set internally) - */ - public function exec_INSERTquery($table, $fields_values) { - - // Initialize - $this->resetStatusVars(); - - // Reading Data Source if not done already. - $this->readDataSource($table); - - // If data source is set: - if (is_array($this->data[$table])) { - - $fieldInformation = $this->admin_get_fields($table); // Should cache this...! - - // Looking for unique keys: - $saveArray = array(); - foreach ($fieldInformation as $fInfo) { - - // Field name: - $fN = $fInfo['Field']; - - // Set value: -// FIXME $options not defined - $saveArray[$fN] = isset($fields_values[$fN]) ? $fields_values[$fN] : $options['Default']; - - // Process value: - $this->processAccordingToConfig($saveArray[$fN], $fInfo); - - // If an auto increment field is found, find the largest current uid: - if ($fInfo['Extra'] == 'auto_increment') { - - // Get all UIDs: - $uidArray = array(); - foreach ($this->data[$table] as $r) { - $uidArray[] = $r[$fN]; - } - - // If current value is blank or already in array, we create a new: - if (!$saveArray[$fN] || in_array(intval($saveArray[$fN]), $uidArray)) { - if (count($uidArray)) { - $saveArray[$fN] = max($uidArray) + 1; - } else $saveArray[$fN] = 1; - } - - // Update "last inserted id": - $this->lastInsertedId = $saveArray[$fN]; - } - } - - // Insert row in table: - $this->data[$table][] = $saveArray; - - // Save data source - $this->saveDataSource($table); - - return TRUE; - } else $this->errorStatus = 'No data loaded.'; - - return FALSE; - } - - /** - * Execute UPDATE query on table - * - * @param string Table name - * @param string WHERE clause - * @param array Field values as key=>value pairs. - * @return boolean TRUE on success and FALSE on failure (error is set internally) - */ - public function exec_UPDATEquery($table, $where, $fields_values) { - - // Initialize: - $this->resetStatusVars(); - - // Reading Data Source if not done already. - $this->readDataSource($table); - - // If anything is there: - if (is_array($this->data[$table])) { - - // Parse WHERE clause: - $where = $this->parseWhereClause($where); - - if (is_array($where)) { - - // Field information - $fieldInformation = $this->admin_get_fields($table); // Should cache this...! - - // Traverse fields to update: - foreach ($fields_values as $fName => $fValue) { - $this->processAccordingToConfig($fields_values[$fName], $fieldInformation[$fName]); - } - - // Do query, returns array with keys to the data array of the result: - $itemKeys = $this->selectFromData($table, $where); - - // Set "last affected rows": - $this->lastAffectedRows = count($itemKeys); - - // Update rows: - if ($this->lastAffectedRows) { - // Traverse result set here: - foreach ($itemKeys as $dataArrayKey) { - - // Traverse fields to update: - foreach ($fields_values as $fName => $fValue) { - $this->data[$table][$dataArrayKey][$fName] = $fValue; - } - } - - // Save data source - $this->saveDataSource($table); - } - - return TRUE; - } else $this->errorStatus = 'WHERE clause contained errors: ' . $where; - } else $this->errorStatus = 'No data loaded.'; - - return FALSE; - } - - /** - * Execute DELETE query - * - * @param string Table to delete from - * @param string WHERE clause - * @return boolean TRUE on success and FALSE on failure (error is set internally) - */ - public function exec_DELETEquery($table, $where) { - - // Initialize: - $this->resetStatusVars(); - - // Reading Data Source if not done already. - $this->readDataSource($table); - - // If anything is there: - if (is_array($this->data[$table])) { - - // Parse WHERE clause: - $where = $this->parseWhereClause($where); - - if (is_array($where)) { - - // Do query, returns array with keys to the data array of the result: - $itemKeys = $this->selectFromData($table, $where); - - // Set "last affected rows": - $this->lastAffectedRows = count($itemKeys); - - // Remove rows: - if ($this->lastAffectedRows) { - // Traverse result set: - foreach ($itemKeys as $dataArrayKey) { - unset($this->data[$table][$dataArrayKey]); - } - - // Saving data source - $this->saveDataSource($table); - } - - return TRUE; - } else $this->errorStatus = 'WHERE clause contained errors: ' . $where; - } else $this->errorStatus = 'No data loaded.'; - - return FALSE; - } - - /** - * Execute SELECT query - * - * @param string List of fields to select from the table. This is what comes right after "SELECT ...". Required value. - * @param string Table(s) from which to select. This is what comes right after "FROM ...". Required value. - * @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! - * @param string Optional GROUP BY field(s), if none, supply blank string. - * @param string Optional ORDER BY field(s), if none, supply blank string. - * @param string Optional LIMIT value ([begin,]max), if none, supply blank string. - * @return object Returns result object, but if errors, returns FALSE - */ - public function exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit) { - - // Initialize: - $this->resetStatusVars(); - - // Create result object - $sqlObj = t3lib_div::makeInstance('tx_dbal_sqlengine_resultobj'); - $sqlObj->result = array(); // Empty result as a beginning - - // Get table list: - $tableArray = $this->parseFromTables($from_table); - $table = $tableArray[0]['table']; - - // Reading Data Source if not done already. - $this->readDataSource($table); - - // If anything is there: - if (is_array($this->data[$table])) { - - // Parse WHERE clause: - $where = $this->parseWhereClause($where_clause); - if (is_array($where)) { - - // Do query, returns array with keys to the data array of the result: - $itemKeys = $this->selectFromData($table, $where); - - // Finally, read the result rows into this variable: - $sqlObj->result = $this->getResultSet($itemKeys, $table, '*'); - // Reset and return result: - reset($sqlObj->result); - return $sqlObj; - } else $this->errorStatus = 'WHERE clause contained errors: ' . $where; - } else $this->errorStatus = 'No data loaded: ' . $this->errorStatus; - - return FALSE; - } - - /** - * Performs an SQL query on the "database" - * - * @param string Query to execute - * @return object Result object or FALSE if error - */ - public function sql_query($query) { - $res = t3lib_div::makeInstance('tx_dbal_sqlengine_resultobj'); - $res->result = array(); - return $res; - } - - /** - * Returns most recent error - * - * @return string Error message, if any - */ - public function sql_error() { - return $this->errorStatus; - } - - /** - * Returns most recently create unique ID (of INSERT queries) - * - * @return integer Last unique id created. - */ - public function sql_insert_id() { - return $this->lastInsertedId; - } - - /** - * Returns affected rows (of UPDATE and DELETE queries) - * - * @return integer Last amount of affected rows. - */ - public function sql_affected_rows() { - return $this->lastAffectedRows; - } - - /** - * Quoting strings for insertion in SQL queries - * - * @param string Input String - * @return string String, with quotes escaped - */ - public function quoteStr($str) { - return addslashes($str); - } - - - /************************************** - * - * SQL admin functions - * (For use in the Install Tool and Extension Manager) - * - **************************************/ - - /** - * (DUMMY) Returns the list of tables from the database - * - * @return array Tables in an array (tablename is in both key and value) - * @todo Should return table details in value! see t3lib_db::admin_get_tables() - */ - public function admin_get_tables() { - $whichTables = array(); - return $whichTables; - } - - /** - * (DUMMY) Returns information about each field in the $table - * - * @param string Table name - * @return array Field information in an associative array with fieldname => field row - */ - public function admin_get_fields($tableName) { - $output = array(); - return $output; - } - - /** - * (DUMMY) Returns information about each index key in the $table - * - * @param string Table name - * @return array Key information in a numeric array - */ - public function admin_get_keys($tableName) { - $output = array(); - return $output; - } - - /** - * (DUMMY) mysql() wrapper function, used by the Install Tool and EM for all queries regarding management of the database! - * - * @param string Query to execute - * @return pointer Result pointer - */ - public function admin_query($query) { - return $this->sql_query($query); - } - - - /******************************** - * - * Data Source I/O - * - ********************************/ - - /** - * Dummy function for setting table data. Create your own. - * NOTICE: Handler to "table-locking" needs to be made probably! - * - * @param string Table name - * @return void - * @todo Table locking tools? - */ - public function readDataSource($table) { - $this->data[$table] = array(); - } - - /** - * Dummy function for setting table data. Create your own. - * NOTICE: Handler to "table-locking" needs to be made probably! - * - * @param string Table name - * @return void - * @todo Table locking tools? - */ - public function saveDataSource($table) { - debug($this->data[$table]); - } - - - /******************************** - * - * SQL engine functions (PHP simulation of SQL) - still experimental - * - ********************************/ - - /** - * PHP simulation of SQL "SELECT" - * Yet EXPERIMENTAL! - * - * @param string Table name - * @param array Where clause parsed into array - * @return array Array of keys pointing to result rows in $this->data[$table] - */ - public function selectFromData($table, $where) { - - $output = array(); - if (is_array($this->data[$table])) { - - // All keys: - $OR_index = 0; - - foreach ($where as $config) { - - if (strtoupper($config['operator']) == 'OR') { - $OR_index++; - } -// FIXME: unknown variable $itemKeys - if (!isset($itemKeys[$OR_index])) $itemKeys[$OR_index] = array_keys($this->data[$table]); - - $this->select_evalSingle($table, $config, $itemKeys[$OR_index]); - } - - foreach ($itemKeys as $uidKeys) { - $output = array_merge($output, $uidKeys); - } - $output = array_unique($output); - } - - return $output; - } - - /** - * Evalutaion of a WHERE-clause-array. - * Yet EXPERIMENTAL - * - * @param string Tablename - * @param array WHERE-configuration array - * @param array Data array to work on. - * @return void Data array passed by reference - * @see selectFromData() - */ - public function select_evalSingle($table, $config, &$itemKeys) { - $neg = preg_match('/^AND[[:space:]]+NOT$/', trim($config['operator'])); - - if (is_array($config['sub'])) { - $subSelKeys = $this->selectFromData($table, $config['sub']); - if ($neg) { - foreach ($itemKeys as $kk => $vv) { - if (in_array($vv, $subSelKeys)) { - unset($itemKeys[$kk]); - } - } - } else { - $itemKeys = array_intersect($itemKeys, $subSelKeys); - } - } else { - $comp = strtoupper(str_replace(array(' ', "\t", "\r", "\n"), '', $config['comparator'])); - $mod = strtoupper($config['modifier']); - switch ($comp) { - case 'NOTLIKE': - case 'LIKE': - $like_value = strtolower($config['value'][0]); - if (substr($like_value, 0, 1) == '%') { - $wildCard_begin = TRUE; - $like_value = substr($like_value, 1); - } - if (substr($like_value, -1) == '%') { - $wildCard_end = TRUE; - $like_value = substr($like_value, 0, -1); - } - break; - case 'NOTIN': - case 'IN': - $in_valueArray = array(); - foreach ($config['value'] as $vParts) { - $in_valueArray[] = (string) $vParts[0]; - } - break; - } - - foreach ($itemKeys as $kk => $v) { - $field_value = $this->data[$table][$v][$config['field']]; - - // Calculate it: - if ($config['calc'] == '&') { - $field_value &= intval($config['calc_value']); - } - - // Compare it: - switch ($comp) { - case '<=': - $bool = $field_value <= $config['value'][0]; - break; - case '>=': - $bool = $field_value >= $config['value'][0]; - break; - case '<': - $bool = $field_value < $config['value'][0]; - break; - case '>': - $bool = $field_value > $config['value'][0]; - break; - case '=': - $bool = !strcmp($field_value, $config['value'][0]); - break; - case '!=': - $bool = strcmp($field_value, $config['value'][0]); - break; - case 'NOTIN': - case 'IN': - $bool = in_array((string) $field_value, $in_valueArray); - if ($comp == 'NOTIN') $bool = !$bool; - break; - case 'NOTLIKE': - case 'LIKE': - if (!strlen($like_value)) { - $bool = TRUE; - } elseif ($wildCard_begin && !$wildCard_end) { - $bool = !strcmp(substr(strtolower($field_value), -strlen($like_value)), $like_value); - } elseif (!$wildCard_begin && $wildCard_end) { - $bool = !strcmp(substr(strtolower($field_value), 0, strlen($like_value)), $like_value); - } elseif ($wildCard_begin && $wildCard_end) { - $bool = strstr($field_value, $like_value); - } else { - $bool = !strcmp(strtolower($field_value), $like_value); - } - if ($comp == 'NOTLIKE') $bool = !$bool; - break; - default: - $bool = $field_value ? TRUE : FALSE; - break; - } - - // General negation: - if ($neg) $bool = !$bool; - - // Modify? - switch ($mod) { - case 'NOT': - case '!': - $bool = !$bool; - break; - } - - // Action: - if (!$bool) { - unset($itemKeys[$kk]); - } - } - } - } - - /** - * Returning result set based on result keys, table and field list - * - * @param array Result keys - * @param string Tablename - * @param string Fieldlist (commaseparated) - * @return array Result array with "rows" - */ - public function getResultSet($keys, $table, $fieldList) { - $fields = t3lib_div::trimExplode(',', $fieldList); - - $output = array(); - foreach ($keys as $kValue) { - if ($fieldList == '*') { - $output[$kValue] = $this->data[$table][$kValue]; - } else { - foreach ($fields as $fieldName) { - $output[$kValue][$fieldName] = $this->data[$table][$kValue][$fieldName]; - } - } - } - - return $output; - } - - - /************************* - * - * Debugging - * - *************************/ - - /** - * Returns the result set (in array) as HTML table. For debugging. - * - * @param array Result set array (array of rows) - * @return string HTML table - */ - public function debug_printResultSet($array) { - - if (count($array)) { - $tRows = array(); - $fields = array_keys(current($array)); - $tCell[] = ' - <td>IDX</td>'; - foreach ($fields as $fieldName) { - $tCell[] = ' - <td>' . htmlspecialchars($fieldName) . '</td>'; - } - $tRows[] = '<tr>' . implode('', $tCell) . '</tr>'; - - - foreach ($array as $index => $rec) { - - $tCell = array(); - $tCell[] = ' - <td>' . htmlspecialchars($index) . '</td>'; - foreach ($fields as $fieldName) { - $tCell[] = ' - <td>' . htmlspecialchars($rec[$fieldName]) . '</td>'; - } - $tRows[] = '<tr>' . implode('', $tCell) . '</tr>'; - } - - return '<table border="1">' . implode('', $tRows) . '</table>'; - } else 'Empty resultset'; - } -} - - -/** - * PHP SQL engine, result object - * - * @author Kasper Skårhøj <kasperYYYY@typo3.com> - * @package TYPO3 - * @subpackage dbal - */ -class tx_dbal_sqlengine_resultobj { - - // Result array, must contain the fields in the order they were selected in the SQL statement (for sql_fetch_row()) - var $result = array(); - - var $TYPO3_DBAL_handlerType = ''; - var $TYPO3_DBAL_tableList = ''; - - - /** - * Counting number of rows - * - * @return integer - */ - public function sql_num_rows() { - return count($this->result); - } - - /** - * Fetching next row in result array - * - * @return array Associative array - */ - public function sql_fetch_assoc() { - $row = current($this->result); - next($this->result); - return $row; - } - - /** - * Fetching next row, numerical indices - * - * @return array Numerical array - */ - public function sql_fetch_row() { - $resultRow = $this->sql_fetch_assoc(); - - if (is_array($resultRow)) { - $numArray = array(); - foreach ($resultRow as $value) { - $numArray[] = $value; - } - return $numArray; - } - } - - /** - * Seeking position in result - * - * @param integer Position pointer. - * @return boolean Returns TRUE on success - */ - public function sql_data_seek($pointer) { - reset($this->result); - for ($a = 0; $a < $pointer; $a++) { - next($this->result); - } - return TRUE; - } - - /** - * Returning SQL field type - * - * @return string Blank string, not supported (it seems) - */ - public function sql_field_type() { - return ''; - } -} - - -if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/lib/class.tx_dbal_sqlengine.php'])) { - include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/lib/class.tx_dbal_sqlengine.php']); -} - -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/lib/class.tx_dbal_tsparserext.php b/typo3/sysext/dbal/lib/class.tx_dbal_tsparserext.php deleted file mode 100644 index 6b7435c5896823e4303587e1df2d6b9579eea757..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/lib/class.tx_dbal_tsparserext.php +++ /dev/null @@ -1,71 +0,0 @@ -<?php -/*************************************************************** - * Copyright notice - * - * (c) 2009-2010 Xavier Perseguers <typo3@perseguers.ch> - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * A copy is found in the textfile GPL.txt and important notices to the license - * from the author is found in LICENSE.txt distributed with these scripts. - * - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - - -/** - * Class that renders fields for the Extension Manager configuration. - * - * $Id: class.tx_dbal_tsparserext.php 40828 2010-12-05 14:55:53Z xperseguers $ - * @author Xavier Perseguers <typo3@perseguers.ch> - * - * @package TYPO3 - * @subpackage dbal - */ -class tx_dbal_tsparserext { - - /** - * Renders a message for EM. - * - * @param array $params - * @param t3lib_tsStyleConfig $tsObj - * @return string - */ - function displayMessage(array &$params, t3lib_tsStyleConfig $tsObj) { - $out = ' - <div> - <div class="typo3-message message-information"> - <div class="message-header">PostgreSQL</div> - <div class="message-body"> - If you use a PostgreSQL database, make sure to run SQL scripts located in<br /> - <tt>' . t3lib_extMgm::extPath('dbal') . 'res/postgresql/</tt><br /> - to ensure best compatibility with TYPO3. - </div> - </div> - </div> - '; - - return $out; - } - -} - - -if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/lib/class.tx_dbal_tsparserext.php'])) { - include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/lib/class.tx_dbal_tsparserext.php']); -} - -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/mod1/clear.gif b/typo3/sysext/dbal/mod1/clear.gif deleted file mode 100644 index 9ed1269764b890333782a01489c53f5ac896f2aa..0000000000000000000000000000000000000000 Binary files a/typo3/sysext/dbal/mod1/clear.gif and /dev/null differ diff --git a/typo3/sysext/dbal/mod1/conf.php b/typo3/sysext/dbal/mod1/conf.php deleted file mode 100644 index bdbe6d7067cc880b1fe1ee06fdf21a7bc3df255c..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/mod1/conf.php +++ /dev/null @@ -1,9 +0,0 @@ -<?php -$MCONF['name'] = 'tools_txdbalM1'; - -$MCONF['access'] = 'admin'; -$MCONF['script'] = '_DISPATCH'; - -$MLANG['default']['tabs_images']['tab'] = 'moduleicon.gif'; -$MLANG['default']['ll_ref'] = 'LLL:EXT:dbal/mod1/locallang_mod.xml'; -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/mod1/index.php b/typo3/sysext/dbal/mod1/index.php deleted file mode 100644 index 9948a9d329a9b8ebfa1fc368afe66d7d528e1823..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/mod1/index.php +++ /dev/null @@ -1,602 +0,0 @@ -<?php -/*************************************************************** - * Copyright notice - * - * (c) 2004-2009 Kasper Skårhøj (kasperYYYY@typo3.com) - * (c) 2004-2009 Karsten Dambekalns (karsten@typo3.org) - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -/** - * Module 'DBAL Debug' for the 'dbal' extension. - * - * @author Kasper Skårhøj <kasperYYYY@typo3.com> - * @author Karsten Dambekalns <karsten@typo3.org> - */ - -$LANG->includeLLFile('EXT:dbal/mod1/locallang.xml'); -$BE_USER->modAccess($MCONF, 1); - - -/** - * Script class; Backend module for DBAL extension - * - * @author Kasper Skårhøj <kasper@typo3.com> - * @author Karsten Dambekalns <karsten@typo3.org> - * @package TYPO3 - * @subpackage dbal - */ -class tx_dbal_module1 extends t3lib_SCbase { - - /** - * @var string - */ - protected $thisScript; - - /** - * Adds items to the ->MOD_MENU array. Used for the function menu selector. - * - * @return void - */ - public function menuConfig() { - $this->MOD_MENU = array( - 'function' => array( - 0 => $GLOBALS['LANG']->getLL('Debug_log'), - 'info' => $GLOBALS['LANG']->getLL('Cached_info'), - 'sqlcheck' => $GLOBALS['LANG']->getLL('SQL_check'), - ) - ); - parent::menuConfig(); - } - - /** - * Main function of the module. Write the content to $this->content - * - * @return void - */ - public function main() { - - $this->thisScript = 'mod.php?M=' . $this->MCONF['name']; - - // Clean up settings: - $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']); - - // Draw the header - $this->doc = t3lib_div::makeInstance('noDoc'); - $this->doc->backPath = $GLOBALS['BACK_PATH']; - $this->doc->form = '<form action="" method="post">'; - - // JavaScript - $this->doc->JScode = $this->doc->wrapScriptTags(' - script_ended = 0; - function jumpToUrl(URL) { // - window.location.href = URL; - } - '); - - // DBAL page title: - $this->content .= $this->doc->startPage($GLOBALS['LANG']->getLL('title')); - $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('title')); - $this->content .= $this->doc->spacer(5); - $this->content .= $this->doc->section('', $this->doc->funcMenu('', t3lib_BEfunc::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']))); - - // Debug log: - switch ($this->MOD_SETTINGS['function']) { - case 'info': - $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('Cached_info'), $this->printCachedInfo()); - break; - case 'sqlcheck': - $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('SQL_check'), $this->printSqlCheck()); - break; - case 0: - $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('Debug_log'), $this->printLogMgm()); - break; - } - - // ShortCut - if ($GLOBALS['BE_USER']->mayMakeShortcut()) { - $this->content .= $this->doc->spacer(20) . $this->doc->section('', $this->doc->makeShortcutIcon('id', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name'])); - } - - $this->content .= $this->doc->spacer(10); - } - - /** - * Prints out the module HTML - * - * @return string HTML output - */ - public function printContent() { - $this->content .= $this->doc->endPage(); - echo $this->content; - } - - /** - * Displays a form to check DBAL SQL methods and parse raw SQL. - * - * @return string HTML output - */ - protected function printSqlCheck() { - $input = t3lib_div::_GP('tx_dbal'); - - $out = ' - <form name="sql_check" action="' . $this->thisScript . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '"> - <script type="text/javascript"> -/*<![CDATA[*/ -function updateQryForm(s) { - document.getElementById(\'tx-dbal-result\').style.display = \'none\'; - switch(s) { - case \'SELECT\': - document.getElementById(\'tx-dbal-qryupdate\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qryfields\').style.display = \'table-row\'; - document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qryfrom\').style.display = \'table-row\'; - document.getElementById(\'tx-dbal-qryinto\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\'; - document.getElementById(\'tx-dbal-qrygroup\').style.display = \'table-row\'; - document.getElementById(\'tx-dbal-qryorder\').style.display = \'table-row\'; - document.getElementById(\'tx-dbal-qrylimit\').style.display = \'table-row\'; - break; - case \'INSERT\': - document.getElementById(\'tx-dbal-qryupdate\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qryfields\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'table-row\'; - document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qryfrom\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qryinto\').style.display = \'table-row\'; - document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\'; - document.getElementById(\'tx-dbal-qrygroup\').style.display = \'table-row\'; - document.getElementById(\'tx-dbal-qryorder\').style.display = \'table-row\'; - document.getElementById(\'tx-dbal-qrylimit\').style.display = \'table-row\'; - break; - case \'UPDATE\': - document.getElementById(\'tx-dbal-qryupdate\').style.display = \'table-row\'; - document.getElementById(\'tx-dbal-qryfields\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'table-row\'; - document.getElementById(\'tx-dbal-qryfrom\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qryinto\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qryupdate\').style.display = \'table-row\'; - document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\'; - document.getElementById(\'tx-dbal-qrygroup\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qryorder\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qrylimit\').style.display = \'none\'; - break; - case \'DELETE\': - document.getElementById(\'tx-dbal-qryupdate\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qryfields\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qryfrom\').style.display = \'table-row\'; - document.getElementById(\'tx-dbal-qryinto\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\'; - document.getElementById(\'tx-dbal-qrygroup\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qryorder\').style.display = \'none\'; - document.getElementById(\'tx-dbal-qrylimit\').style.display = \'none\'; - break; - } -} -/*]]>*/ - </script> - <table> - <tr class="tableheader bgColor5"><th colspan="2">Easy SQL check</th></tr> - <tr><td colspan="2"> - <select name="tx_dbal[QUERY]"size="1" onchange="updateQryForm(this.options[this.selectedIndex].value)"> - <option value="SELECT" ' . ($input['QUERY'] === 'SELECT' ? 'selected="selected"' : '') . '>SELECT</option> - <option value="INSERT" ' . ($input['QUERY'] === 'INSERT' ? 'selected="selected"' : '') . '>INSERT</option> - <option value="UPDATE" ' . ($input['QUERY'] === 'UPDATE' ? 'selected="selected"' : '') . '>UPDATE</option> - <option value="DELETE" ' . ($input['QUERY'] === 'DELETE' ? 'selected="selected"' : '') . '>DELETE</option> - </select> - </td></tr> - <tr id="tx-dbal-qryupdate" style="display:none;"><td></td><td><input name="tx_dbal[UPDATE]" value="' . $input['UPDATE'] . '" type="text" size="30" maxsize="100" /></td></tr> - <tr id="tx-dbal-qryfields"><td></td><td><input name="tx_dbal[FIELDS]" value="' . $input['FIELDS'] . '" type="text" size="30" maxsize="100" /></td></tr> - <tr id="tx-dbal-qryinsertvalues" style="display:none;"><td></td><td><textarea name="tx_dbal[INSERTVALUES]" cols="30" rows="4">' . $input['INSERTVALUES'] . '</textarea></td></tr> - <tr id="tx-dbal-qryupdatevalues" style="display:none;"><th>SET</th><td><textarea name="tx_dbal[UPDATEVALUES]" cols="30" rows="4">' . $input['UPDATEVALUES'] . '</textarea></td></tr> - <tr id="tx-dbal-qryfrom"><th>FROM</th><td><input name="tx_dbal[FROM]" value="' . $input['FROM'] . '" type="text" size="30" maxsize="100" /></td></tr> - <tr id="tx-dbal-qryinto" style="display:none;"><th>INTO</th><td><input name="tx_dbal[INTO]" value="' . $input['INTO'] . '" type="text" size="30" maxsize="100" /></td></tr> - <tr id="tx-dbal-qrywhere"><th>WHERE</th><td><input name="tx_dbal[WHERE]" value="' . $input['WHERE'] . '" type="text" size="30" maxsize="100" /></td></tr> - <tr id="tx-dbal-qrygroup"><th>GROUP BY</th><td><input name="tx_dbal[GROUP]" value="' . $input['GROUP'] . '" type="text" size="30" maxsize="100" /></td></tr> - <tr id="tx-dbal-qryorder"><th>ORDER BY</th><td><input name="tx_dbal[ORDER]" value="' . $input['ORDER'] . '" type="text" size="30" maxsize="100" /></td></tr> - <tr id="tx-dbal-qrylimit"><th>LIMIT</th><td><input name="tx_dbal[LIMIT]" value="' . $input['LIMIT'] . '" type="text" size="30" maxsize="100" /></td></tr> - <tr><td></td><td style="text-align:right;"><input type="submit" value="CHECK" /></td></tr> - <script type="text/javascript"> -/*<![CDATA[*/ -updateQryForm(\'' . $input['QUERY'] . '\'); -/*]]>*/ - </script> - '; - - $out .= '<tr id="tx-dbal-result" class="bgColor4"><th>Result:</th><td>'; - switch ($input['QUERY']) { - case 'SELECT': - $qry = $GLOBALS['TYPO3_DB']->SELECTquery($input['FIELDS'], $input['FROM'], $input['WHERE'], $input['GROUP'], $input['ORDER'], $input['LIMIT']); - break; - case 'INSERT': - $qry = $GLOBALS['TYPO3_DB']->INSERTquery($input['INTO'], $this->createFieldsValuesArray($input['INSERTVALUES'])); - break; - case 'UPDATE': - $qry = $GLOBALS['TYPO3_DB']->UPDATEquery($input['UPDATE'], $input['WHERE'], $this->createFieldsValuesArray($input['UPDATEVALUES'])); - break; - case 'DELETE': - $qry = $GLOBALS['TYPO3_DB']->DELETEquery($input['FROM'], $input['WHERE']); - break; - } - $out .= '<pre>' . htmlspecialchars($qry) . '</pre></td></tr>'; - - $out .= ' - <tr class="tableheader bgColor5"><th colspan="2">RAW SQL check</th></tr> - <tr><td colspan="2" style="text-align:right;"><textarea name="tx_dbal[RAWSQL]" cols="60" rows="5">' . $input['RAWSQL'] . '</textarea><br /><input type="submit" value="CHECK" /></td></tr>'; - if (!empty($input['RAWSQL'])) { - $out .= '<tr class="bgColor4">'; - $parseResult = $GLOBALS['TYPO3_DB']->SQLparser->parseSQL($input['RAWSQL']); - if (is_array($parseResult)) { - $newQuery = $GLOBALS['TYPO3_DB']->SQLparser->compileSQL($parseResult); - $testResult = $GLOBALS['TYPO3_DB']->SQLparser->debug_parseSQLpartCompare($input['RAWSQL'], $newQuery); - if (!is_array($testResult)) { - $out .= '<td colspan="2">' . $newQuery; - } else { - $out .= '<td colspan="2">' . htmlspecialchars($testResult[0]) . '</td></tr> - <tr><th>Error:</th><td style="border:2px solid #f00;">Input query did not match the parsed and recompiled query exactly (not observing whitespace):<br />' . htmlspecialchars($testResult[1]); - } - } else { - $out .= '<th>Result:</th><td style="border:2px solid #f00;">' . $parseResult; - } - $out .= '</td></tr>'; - } - - $out .= '</table></form>'; - return $out; - } - - /** - * Parses a very simple text format into an array. - * - * Each line is seen as a key/value pair that is exploded at =. This is used - * in the simple SQL check to input values for INSERT and UPDATE statements. - * - * @param string $in String to parse into key/value array. - * @return array Array created from the input string. - */ - protected function createFieldsValuesArray($in) { - $ret = array(); - $in = explode(chr(10), $in); - foreach ($in as $v) { - $fv = explode('=', $v); - $ret[$fv[0]] = $fv[1]; - } - - return $ret; - } - - /** - * Prints out the cached information about the database. - * - * The DBAL caches a lot of information, e.g. about auto increment fields, - * field types and primary keys. This method formats all this into a HTML - * table to display in the BE. - * - * @return string HTML output - */ - protected function printCachedInfo() { - // Get cmd: - if ((string) t3lib_div::_GP('cmd') === 'clear') { - $GLOBALS['TYPO3_DB']->clearCachedFieldInfo(); - $GLOBALS['TYPO3_DB']->cacheFieldInfo(); - } - - $out = '<a name="autoincrement"></a><h2>auto_increment</h2>'; - $out .= '<table border="1" cellspacing="0"><tbody><tr><th>Table</th><th>Field</th></tr>'; - ksort($GLOBALS['TYPO3_DB']->cache_autoIncFields); - foreach ($GLOBALS['TYPO3_DB']->cache_autoIncFields as $table => $field) { - $out .= '<tr>'; - $out .= '<td>' . $table . '</td>'; - $out .= '<td>' . $field . '</td>'; - $out .= '</tr>'; - } - $out .= '</tbody></table>'; - - $out .= $this->doc->spacer(5); - $out .= '<a name="primarykeys"></a><h2>Primary keys</h2>'; - $out .= '<table border="1" cellspacing="0"><tbody><tr><th>Table</th><th>Field(s)</th></tr>'; - ksort($GLOBALS['TYPO3_DB']->cache_primaryKeys); - foreach ($GLOBALS['TYPO3_DB']->cache_primaryKeys as $table => $field) { - $out .= '<tr>'; - $out .= '<td>' . $table . '</td>'; - $out .= '<td>' . $field . '</td>'; - $out .= '</tr>'; - } - $out .= '</tbody></table>'; - - $out .= $this->doc->spacer(5); - $out .= '<a name="fieldtypes"></a><h2>Field types</h2>'; - $out .= '<table border="1" cellspacing="0"><tbody><tr><th colspan="5">Table</th></tr><tr><th>Field</th><th>Type</th><th><a href="#metatypes">Metatype</a></th><th>NOT NULL</th><th>Default</th></th></tr>'; - ksort($GLOBALS['TYPO3_DB']->cache_fieldType); - foreach ($GLOBALS['TYPO3_DB']->cache_fieldType as $table => $fields) { - $out .= '<th colspan="5">' . $table . '</th>'; - foreach ($fields as $field => $data) { - $out .= '<tr>'; - $out .= '<td>' . $field . '</td>'; - $out .= '<td>' . $data['type'] . '</td>'; - $out .= '<td>' . $data['metaType'] . '</td>'; - $out .= '<td>' . ($data['notnull'] ? 'NOT NULL' : '') . '</td>'; - $out .= '<td>' . $data['default'] . '</td>'; - $out .= '</tr>'; - } - } - $out .= '</tbody></table>'; - - $out .= $this->doc->spacer(5); - $out .= '<a name="metatypes"></a><h2>Metatype explanation</h2>'; - $out .= '<pre> - C: Varchar, capped to 255 characters. - X: Larger varchar, capped to 4000 characters (to be compatible with Oracle). - XL: For Oracle, returns CLOB, otherwise the largest varchar size. - - C2: Multibyte varchar - X2: Multibyte varchar (largest size) - - B: BLOB (binary large object) - - D: Date (some databases do not support this, and we return a datetime type) - T: Datetime or Timestamp - L: Integer field suitable for storing booleans (0 or 1) - I: Integer (mapped to I4) - I1: 1-byte integer - I2: 2-byte integer - I4: 4-byte integer - I8: 8-byte integer - F: Floating point number - N: Numeric or decimal number</pre>'; - - $menu = '<a href="' . $this->thisScript . '&cmd=clear">CLEAR DATA</a><hr />'; - $menu .= '<a href="#autoincrement">auto_increment</a> | <a href="#primarykeys">Primary keys</a> | <a href="#fieldtypes">Field types</a> | <a href="#metatypes">Metatype explanation</a><hr />'; - - return $menu . $out; - } - - /** - * Printing the debug-log from the DBAL extension - * - * To enabled debugging, you will have to enabled it in the configuration! - * - * @return string HTML content - */ - protected function printLogMgm() { - - // Disable debugging in any case... - $GLOBALS['TYPO3_DB']->debug = FALSE; - - // Get cmd: - $cmd = (string) t3lib_div::_GP('cmd'); - switch ($cmd) { - case 'flush': - $res = $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('tx_dbal_debuglog'); - $res = $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('tx_dbal_debuglog_where'); - $outStr = 'Log FLUSHED!'; - break; - case 'joins': - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('table_join,exec_time,query,script', 'tx_dbal_debuglog', 'table_join!=\'\'', 'table_join,script,exec_time,query'); - - // Init vars in which to pick up the query result: - $tableIndex = array(); - $tRows = array(); - $tRows[] = ' - <tr> - <td>Execution time</td> - <td>Table joins</td> - <td>Script</td> - <td>Query</td> - </tr>'; - - while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { - $tableArray = $GLOBALS['TYPO3_DB']->SQLparser->parseFromTables($row['table_join']); - - // Create table name index: - foreach ($tableArray as $a) { - foreach ($tableArray as $b) { - if ($b['table'] != $a['table']) { - $tableIndex[$a['table']][$b['table']] = 1; - } - } - } - - // Create output row - $tRows[] = ' - <tr> - <td>' . htmlspecialchars($row['exec_time']) . '</td> - <td>' . htmlspecialchars($row['table_join']) . '</td> - <td>' . htmlspecialchars($row['script']) . '</td> - <td>' . htmlspecialchars($row['query']) . '</td> - </tr>'; - } - - // Printing direct joins: - $outStr .= '<h4>Direct joins:</h4>' . t3lib_div::view_array($tableIndex); - - - // Printing total dependencies: - foreach ($tableIndex as $priTable => $a) { - foreach ($tableIndex as $tableN => $v) { - foreach ($v as $tableP => $vv) { - if ($tableP == $priTable) { - $tableIndex[$priTable] = array_merge($v, $a); - } - } - } - } - $outStr .= '<h4>Total dependencies:</h4>' . t3lib_div::view_array($tableIndex); - - // Printing data rows: - $outStr .= ' - <table border="1" cellspacing="0">' . implode('', $tRows) . ' - </table>'; - break; - case 'errors': - - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('serdata,exec_time,query,script', 'tx_dbal_debuglog', 'errorFlag>0', '', 'tstamp DESC'); - - // Init vars in which to pick up the query result: - $tRows = array(); - $tRows[] = ' - <tr> - <td>Execution time</td> - <td>Error data</td> - <td>Script</td> - <td>Query</td> - </tr>'; - - while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { - // Create output row - $tRows[] = ' - <tr> - <td>' . htmlspecialchars($row['exec_time']) . '</td> - <td>' . t3lib_div::view_array(unserialize($row['serdata'])) . '</td> - <td>' . htmlspecialchars($row['script']) . '</td> - <td>' . htmlspecialchars($row['query']) . '</td> - </tr>'; - } - - // Printing data rows: - $outStr .= ' - <table border="1" cellspacing="0">' . implode('', $tRows) . ' - </table>'; - break; - case 'parsing': - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('query,serdata', 'tx_dbal_debuglog', 'errorFlag&2=2'); - $tRows = array(); - while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { - // Create output row - $tRows[] = ' - <tr> - <td>' . htmlspecialchars($row['query']) . '</td> - </tr>'; - } - - // Printing data rows: - $outStr .= ' - <table border="1" cellspacing="0">' . implode('', $tRows) . ' - </table>'; - break; - case 'where': - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tstamp,script,tablename,whereclause', 'tx_dbal_debuglog_where', '', '', 'tstamp DESC'); - $tRows = array(); - $tRows[] = ' - <tr> - <td>Time</td> - <td>Script</td> - <td>Table</td> - <td>WHERE clause</td> - </tr>'; - while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { - $tRows[] = ' - <tr> - <td>' . t3lib_BEfunc::datetime($row['tstamp']) . '</td> - <td>' . htmlspecialchars($row['script']) . '</td> - <td>' . htmlspecialchars($row['tablename']) . '</td> - <td>' . str_replace(array('\'\'', '""', 'IS NULL', 'IS NOT NULL'), array('<span style="background-color:#ff0000;color:#ffffff;padding:2px;font-weight:bold;">\'\'</span>', '<span style="background-color:#ff0000;color:#ffffff;padding:2px;font-weight:bold;">""</span>', '<span style="background-color:#00ff00;color:#ffffff;padding:2px;font-weight:bold;">IS NULL</span>', '<span style="background-color:#00ff00;color:#ffffff;padding:2px;font-weight:bold;">IS NOT NULL</span>'), htmlspecialchars($row['whereclause'])) . '</td> - </tr>'; - } - - $outStr = ' - <table border="1" cellspacing="0">' . implode('', $tRows) . ' - </table>'; - break; - default: - - // Look for request to view specific script exec: - $specTime = t3lib_div::_GP('specTime'); - - if ($specTime) { - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('exec_time,errorFlag,table_join,serdata,query', 'tx_dbal_debuglog', 'tstamp=' . (int) $specTime); - $tRows = array(); - $tRows[] = ' - <tr> - <td>Execution time</td> - <td>Error</td> - <td>Table joins</td> - <td>Data</td> - <td>Query</td> - </tr>'; - while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { - $tRows[] = ' - <tr> - <td>' . htmlspecialchars($row['exec_time']) . '</td> - <td>' . ($row['errorFlag'] ? 1 : 0) . '</td> - <td>' . htmlspecialchars($row['table_join']) . '</td> - <td>' . t3lib_div::view_array(unserialize($row['serdata'])) . '</td> - <td>' . str_replace(array('\'\'', '""', 'IS NULL', 'IS NOT NULL'), array('<span style="background-color:#ff0000;color:#ffffff;padding:2px;font-weight:bold;">\'\'</span>', '<span style="background-color:#ff0000;color:#ffffff;padding:2px;font-weight:bold;">""</span>', '<span style="background-color:#00ff00;color:#ffffff;padding:2px;font-weight:bold;">IS NULL</span>', '<span style="background-color:#00ff00;color:#ffffff;padding:2px;font-weight:bold;">IS NOT NULL</span>'), htmlspecialchars($row['query'])) . '</td> - </tr>'; - } - } else { - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tstamp,script, SUM(exec_time) as calc_sum, count(*) AS qrycount, MAX(errorFlag) as error', 'tx_dbal_debuglog', '', 'tstamp,script', 'tstamp DESC'); - $tRows = array(); - $tRows[] = ' - <tr> - <td>Time</td> - <td># of queries</td> - <td>Error</td> - <td>Time (ms)</td> - <td>Script</td> - </tr>'; - while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { - $tRows[] = ' - <tr> - <td>' . t3lib_BEfunc::datetime($row['tstamp']) . '</td> - <td>' . htmlspecialchars($row['qrycount']) . '</td> - <td>' . ($row['error'] ? '<strong style="color:#f00">ERR</strong>' : '') . '</td> - <td>' . htmlspecialchars($row['calc_sum']) . '</td> - <td><a href="' . $this->thisScript . '&specTime=' . intval($row['tstamp']) . '">' . htmlspecialchars($row['script']) . '</a></td> - </tr>'; - } - } - $outStr = ' - <table border="1" cellspacing="0">' . implode('', $tRows) . ' - </table>'; - - break; - } - - $menu = ' - <a href="' . $this->thisScript . '&cmd=flush">FLUSH LOG</a> - - <a href="' . $this->thisScript . '&cmd=joins">JOINS</a> - - <a href="' . $this->thisScript . '&cmd=errors">ERRORS</a> - - <a href="' . $this->thisScript . '&cmd=parsing">PARSING</a> - - <a href="' . $this->thisScript . '">LOG</a> - - <a href="' . $this->thisScript . '&cmd=where">WHERE</a> - - - <a href="' . htmlspecialchars(t3lib_div::linkThisScript()) . '" target="tx_debuglog">[New window]</a> - <hr /> - '; - return $menu . $outStr; - } -} - -if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/mod1/index.php'])) { - include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/mod1/index.php']); -} - - -// Make instance: -$SOBE = t3lib_div::makeInstance('tx_dbal_module1'); -$SOBE->init(); -$SOBE->main(); -$SOBE->printContent(); - -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/mod1/locallang.xml b/typo3/sysext/dbal/mod1/locallang.xml deleted file mode 100644 index 9d8b2274a081dd34e4c40b2bcd22b4b4495f24da..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/mod1/locallang.xml +++ /dev/null @@ -1,15 +0,0 @@ -<?xml version="1.0" encoding="utf-8" standalone="yes" ?> -<T3locallang> - <meta type="array"> - <description>DBAL debugging module</description> - <type>module</type> - </meta> - <data type="array"> - <languageKey index="default" type="array"> - <label index="title">DBAL Analysis Module</label> - <label index="Debug_log">Debug log</label> - <label index="Cached_info">Cached info</label> - <label index="SQL_check">SQL Check</label> - </languageKey> - </data> -</T3locallang> \ No newline at end of file diff --git a/typo3/sysext/dbal/mod1/locallang_mod.xml b/typo3/sysext/dbal/mod1/locallang_mod.xml deleted file mode 100644 index dd86095da164ff1ba5734d70158cb42a9a5b54af..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/mod1/locallang_mod.xml +++ /dev/null @@ -1,12 +0,0 @@ -<?xml version="1.0" encoding="utf-8" standalone="yes" ?> -<T3locallang> - <meta type="array"> - <description>DBAL debugging module</description> - <type>module</type> - </meta> - <data type="array"> - <languageKey index="default" type="array"> - <label index="mlang_tabs_tab">DBAL Debug</label> - </languageKey> - </data> -</T3locallang> \ No newline at end of file diff --git a/typo3/sysext/dbal/mod1/moduleicon.gif b/typo3/sysext/dbal/mod1/moduleicon.gif deleted file mode 100644 index 08b5ed5bb804db03faf795db42b63e68fbf7fe4c..0000000000000000000000000000000000000000 Binary files a/typo3/sysext/dbal/mod1/moduleicon.gif and /dev/null differ diff --git a/typo3/sysext/dbal/res/README b/typo3/sysext/dbal/res/README deleted file mode 100644 index a8e92664ed8a2dbabdfaf94d461ffef478e99835..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/res/README +++ /dev/null @@ -1 +0,0 @@ -This directory contains various resources for supported DBMS. They may be useful to solve some edge-cases not yet supported in either TYPO3 or DBAL. diff --git a/typo3/sysext/dbal/res/Templates/install.html b/typo3/sysext/dbal/res/Templates/install.html deleted file mode 100644 index 19925b7fab91673ad52c391d0312fb2b411bf7dd..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/res/Templates/install.html +++ /dev/null @@ -1,202 +0,0 @@ -?xml version="1.0" encoding="utf-8"?> -<!DOCTYPE html - PUBLIC "-//W3C//DTD XHTML 1.1//EN" - "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> -<head> - <meta http-equiv="content-type" content="text/html; charset=utf-8" /> - <title>Template: Step Output</title> -</head> -<body> -<!-- ###TEMPLATE### begin --> - -<!-- ###CONNECTION_FORM### begin --> -<script type="text/javascript" src="../contrib/prototype/prototype.js"></script> -<script type="text/javascript" src="../sysext/install/Resources/Public/Javascript/install.js"></script> - -<p>###LLDESCRIPTION###</p> -<form method="post" action="###ACTION###"> - <fieldset class="t3-install-form-label-width-7"> - <ol> - <li class="t3-install-hidden"> - <input type="hidden" value="###STEP###" name="step" /> - <input type="hidden" value="###ENCRYPTIONKEY###" name="TYPO3_INSTALL[localconf.php][encryptionKey]" /> - <input type="hidden" value="###BRANCH###" name="TYPO3_INSTALL[localconf.php][compat_version]" /> - </li> - <!-- ###DATABASE_DRIVER### begin --> - <li> - <label>###LABELDRIVER###</label> - <select name="TYPO3_INSTALL[localconf.php][typo_db_driver]"> - <!-- ###ABSTRACTION_LAYER### begin --> - <optgroup label="###LABELABSTRACTIONLAYER###"> - <!-- ###VENDOR### begin --> - <option value="###DRIVER###"###SELECTED### onclick="###ONCLICK###">###LABELVENDOR###</option> - <!-- ###VENDOR### end --> - </optgroup> - <!-- ###ABSTRACTION_LAYER### end --> - </select> - </li> - <!-- ###DATABASE_DRIVER### end --> - - ###DRIVER_OPTIONS### - </ol> - </fieldset> - <fieldset class="t3-install-form-submit"> - <ol> - <li> - <button type="submit">###CONTINUE###<span class="t3-install-form-button-icon-positive"> </span></button> - </li> - </ol> - </fieldset> -</form> -<!-- ###CONNECTION_FORM### end --> - - - - -<!-- ###DATABASE_FORM### begin --> -<form id="t3-install-123-step3" method="post" action="###ACTION###"> - <fieldset> - <ol> - <li class="t3-install-hidden"> - <input type="hidden" value="###STEP###" name="step" /> - </li> - <li> - <label for="t3-install-123-database">###LLOPTION2###</label> - <p>###LLREMARK2###</p> - <select id="t3-install-123-database" name="TYPO3_INSTALL[localconf.php][typo_db]"> - <option value="">Select database</option> - <!-- ###DATABASEOPTIONS### begin --> - <option value="###DATABASEVALUE###" ###DATABASESELECTED###>###DATABASENAME###</option> - <!-- ###DATABASEOPTIONS### end --> - </select> - </li> - </ol> - </fieldset> - <fieldset class="t3-install-form-submit"> - <ol> - <li> - <button type="submit">###CONTINUE###<span class="t3-install-form-button-icon-positive"> </span></button> - </li> - </ol> - </fieldset> -</form> -<!-- ###DATABASE_FORM### end --> - - - - - -<!-- ###DRIVER_MYSQL### begin --> -<!-- ###DRIVER_MYSQLI### begin --> -<li> - <label for="t3-install-form-username">###LABELUSERNAME###</label> - <input id="t3-install-form-username" class="t3-install-form-input-text" type="text" value="###USERNAME###" name="TYPO3_INSTALL[localconf.php][typo_db_username]" /> -</li> -<li> - <label for="t3-install-form-password">###LABELPASSWORD###</label> - <input id="t3-install-form-password" class="t3-install-form-input-text" type="password" value="###PASSWORD###" name="TYPO3_INSTALL[localconf.php][typo_db_password]" /> -</li> -<li> - <label for="t3-install-form-host">###LABELHOST###</label> - <input id="t3-install-form-host" class="t3-install-form-input-text" type="text" value="###HOST###" name="TYPO3_INSTALL[localconf.php][typo_db_host]" /> -</li> -<!-- ###DRIVER_MYSQLI### end --> -<!-- ###DRIVER_MYSQL### end --> - - - - -<!-- ###DRIVER_DEFAULT### begin --> -<li> - <label for="t3-install-form-username">###LABELUSERNAME###</label> - <input id="t3-install-form-username" class="t3-install-form-input-text" type="text" value="###USERNAME###" name="TYPO3_INSTALL[localconf.php][typo_db_username]" /> -</li> -<li> - <label for="t3-install-form-password">###LABELPASSWORD###</label> - <input id="t3-install-form-password" class="t3-install-form-input-text" type="password" value="###PASSWORD###" name="TYPO3_INSTALL[localconf.php][typo_db_password]" /> -</li> -<li> - <label for="t3-install-form-host">###LABELHOST###</label> - <input id="t3-install-form-host" class="t3-install-form-input-text" type="text" value="###HOST###" name="TYPO3_INSTALL[localconf.php][typo_db_host]" /> -</li> -<li> - <label for="t3-install-form-database">###LABELDATABASE###</label> - <input id="t3-install-form-database" class="t3-install-form-input-text" type="text" value="###DATABASE###" name="TYPO3_INSTALL[localconf.php][typo_db]" /> -</li> -<!-- ###DRIVER_DEFAULT### end --> - - - - -<!-- ###DRIVER_MSSQL### begin --> -<li> - <label for="t3-install-form-username">###LABELUSERNAME###</label> - <input id="t3-install-form-username" class="t3-install-form-input-text" type="text" value="###USERNAME###" name="TYPO3_INSTALL[localconf.php][typo_db_username]" /> -</li> -<li> - <label for="t3-install-form-password">###LABELPASSWORD###</label> - <input id="t3-install-form-password" class="t3-install-form-input-text" type="password" value="###PASSWORD###" name="TYPO3_INSTALL[localconf.php][typo_db_password]" /> -</li> -<li> - <label for="t3-install-form-host">###LABELHOST###</label> - <input id="t3-install-form-host" class="t3-install-form-input-text" type="text" value="###HOST###" name="TYPO3_INSTALL[localconf.php][typo_db_host]" /> -</li> -<li> - <label for="t3-install-form-database">###LABELDATABASE###</label> - <input id="t3-install-form-database" class="t3-install-form-input-text" type="text" value="###DATABASE###" name="TYPO3_INSTALL[localconf.php][typo_db]" /> -</li> -<!-- ###DRIVER_MSSQL### end --> - - - - - -<!-- ###DRIVER_ODBC_MSSQL### begin --> -<li> - <label for="t3-install-form-username">###LABELUSERNAME###</label> - <input id="t3-install-form-username" class="t3-install-form-input-text" type="text" value="###USERNAME###" name="TYPO3_INSTALL[localconf.php][typo_db_username]" /> -</li> -<li> - <label for="t3-install-form-password">###LABELPASSWORD###</label> - <input id="t3-install-form-password" class="t3-install-form-input-text" type="password" value="###PASSWORD###" name="TYPO3_INSTALL[localconf.php][typo_db_password]" /> -</li> -<li> - <label for="t3-install-form-host">###LABELHOST###</label> - <input id="t3-install-form-host" class="t3-install-form-input-text" type="text" value="###HOST###" name="TYPO3_INSTALL[localconf.php][typo_db_host]" /> -</li> -<input type="hidden" value="###DATABASE###" name="TYPO3_INSTALL[localconf.php][typo_db]" /> -<!-- ###DRIVER_ODBC_MSSQL### end --> - - - - -<!-- ###DRIVER_OCI8### begin --> -<li> - <label for="t3-install-form-username">###LABELUSERNAME###</label> - <input id="t3-install-form-username" class="t3-install-form-input-text" type="text" value="###USERNAME###" name="TYPO3_INSTALL[localconf.php][typo_db_username]" /> -</li> -<li> - <label for="t3-install-form-password">###LABELPASSWORD###</label> - <input id="t3-install-form-password" class="t3-install-form-input-text" type="password" value="###PASSWORD###" name="TYPO3_INSTALL[localconf.php][typo_db_password]" /> -</li> -<li> - <label for="t3-install-form-host">###LABELHOST###</label> - <input id="t3-install-form-host" class="t3-install-form-input-text" type="text" value="###HOST###" name="TYPO3_INSTALL[localconf.php][typo_db_host]" /> -</li> -<li> - <label for="t3-install-form-type">###LABELTYPE###</label> - <select id="t3-install-form-type" name="TYPO3_INSTALL[localconf.php][typo_db_type]"> - <option value="sid">###LABELSID###</option> - <option value="servicename">###LABELSERVICENAME###</option> - </select> -</li> -<li> - <label for="t3-install-form-database">###LABELDATABASE###</label> - <input id="t3-install-form-database" class="t3-install-form-input-text" type="text" value="###DATABASE###" name="TYPO3_INSTALL[localconf.php][typo_db]" /> -</li> -<!-- ###DRIVER_OCI8### end --> - -<!-- ###TEMPLATE### end --> -</body> -</html> \ No newline at end of file diff --git a/typo3/sysext/dbal/res/oracle/indexed_search.diff b/typo3/sysext/dbal/res/oracle/indexed_search.diff deleted file mode 100644 index 94c6061da62ccb411a1b399bb7445349763cc8d4..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/res/oracle/indexed_search.diff +++ /dev/null @@ -1,13 +0,0 @@ -Index: ext_tables.sql -=================================================================== ---- ext_tables.sql (revision 6890) -+++ ext_tables.sql (working copy) -@@ -107,7 +107,7 @@ - CREATE TABLE index_stat_search ( - uid int(11) NOT NULL auto_increment, - searchstring varchar(255) DEFAULT '' NOT NULL, -- searchoptions blob, -+ searchoptions varchar(4000), - tstamp int(11) DEFAULT '0' NOT NULL, - feuser_id int(11) unsigned DEFAULT '0' NOT NULL, - cookie varchar(10) DEFAULT '' NOT NULL, diff --git a/typo3/sysext/dbal/res/oracle/realurl.diff b/typo3/sysext/dbal/res/oracle/realurl.diff deleted file mode 100644 index dab08d66cc31ccb4be638b0cf470697a1ef668bf..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/res/oracle/realurl.diff +++ /dev/null @@ -1,66 +0,0 @@ -Index: ext_tables.sql -=================================================================== ---- ext_tables.sql (revision 29851) -+++ ext_tables.sql (working copy) -@@ -7,7 +7,7 @@ - language_id int(11) DEFAULT '0' NOT NULL, - rootpage_id int(11) DEFAULT '0' NOT NULL, - mpvar tinytext NOT NULL, -- pagepath text NOT NULL, -+ pagepath varchar(4000) NOT NULL, - expire int(11) DEFAULT '0' NOT NULL, - - PRIMARY KEY (cache_id), -@@ -41,7 +41,7 @@ - CREATE TABLE tx_realurl_chashcache ( - spurl_hash char(32) DEFAULT '' NOT NULL, - chash_string varchar(32) DEFAULT '' NOT NULL, -- spurl_string text, -+ spurl_string varchar(4000), - - PRIMARY KEY (spurl_hash), - KEY chash_string (chash_string) -@@ -55,7 +55,7 @@ - CREATE TABLE tx_realurl_urldecodecache ( - url_hash char(32) DEFAULT '' NOT NULL, - spurl tinytext NOT NULL, -- content blob NOT NULL, -+ content varchar(4000) NOT NULL, - page_id int(11) DEFAULT '0' NOT NULL, - rootpage_id int(11) DEFAULT '0' NOT NULL, - tstamp int(11) DEFAULT '0' NOT NULL, -@@ -73,7 +73,7 @@ - url_hash char(32) DEFAULT '' NOT NULL, - origparams tinytext NOT NULL, - internalExtras tinytext NOT NULL, -- content text NOT NULL, -+ content varchar(4000) NOT NULL, - page_id int(11) DEFAULT '0' NOT NULL, - tstamp int(11) DEFAULT '0' NOT NULL, - -@@ -83,9 +83,9 @@ - - CREATE TABLE tx_realurl_errorlog ( - url_hash int(11) DEFAULT '0' NOT NULL, -- url text NOT NULL, -- error text NOT NULL, -- last_referer text NOT NULL, -+ url varchar(4000) NOT NULL, -+ error varchar(4000) NOT NULL, -+ last_referer varchar(4000) NOT NULL, - counter int(11) DEFAULT '0' NOT NULL, - cr_date int(11) DEFAULT '0' NOT NULL, - tstamp int(11) DEFAULT '0' NOT NULL, -@@ -97,9 +97,9 @@ - - CREATE TABLE tx_realurl_redirects ( - url_hash int(11) DEFAULT '0' NOT NULL, -- url text NOT NULL, -- destination text NOT NULL, -- last_referer text NOT NULL, -+ url varchar(4000) NOT NULL, -+ destination varchar(4000) NOT NULL, -+ last_referer varchar(4000) NOT NULL, - counter int(11) DEFAULT '0' NOT NULL, - tstamp int(11) DEFAULT '0' NOT NULL, - has_moved int(11) DEFAULT '0' NOT NULL, diff --git a/typo3/sysext/dbal/res/oracle/scheduler.diff b/typo3/sysext/dbal/res/oracle/scheduler.diff deleted file mode 100644 index 17982a404392ea8bc1e656c7acdbcc5f73c48779..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/res/oracle/scheduler.diff +++ /dev/null @@ -1,15 +0,0 @@ -Index: ext_tables.sql -=================================================================== ---- ext_tables.sql (revision 6890) -+++ ext_tables.sql (working copy) -@@ -10,8 +10,8 @@ - lastexecution_time int(11) unsigned DEFAULT '0' NOT NULL, - lastexecution_failure text NOT NULL, - lastexecution_context char(3) DEFAULT '' NOT NULL, -- serialized_task_object blob, -- serialized_executions blob, -+ serialized_task_object varchar(4000), -+ serialized_executions varchar(4000), - PRIMARY KEY (uid), - KEY index_nextexecution (nextexecution) - ); diff --git a/typo3/sysext/dbal/res/oracle/templavoila.diff b/typo3/sysext/dbal/res/oracle/templavoila.diff deleted file mode 100644 index 7a6de97ff3373e791fdf6281f53b50c06ad0e8b4..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/res/oracle/templavoila.diff +++ /dev/null @@ -1,13 +0,0 @@ -Index: ext_tables.sql -=================================================================== ---- ext_tables.sql (revision 29620) -+++ ext_tables.sql (working copy) -@@ -24,7 +24,7 @@ - title varchar(60) DEFAULT '' NOT NULL, - datastructure varchar(100) DEFAULT '' NOT NULL, - fileref tinytext, -- templatemapping blob, -+ templatemapping mediumtext, - previewicon tinytext, - description tinytext, - rendertype varchar(32) DEFAULT '' NOT NULL, diff --git a/typo3/sysext/dbal/res/postgresql/postgresql-compatibility.sql b/typo3/sysext/dbal/res/postgresql/postgresql-compatibility.sql deleted file mode 100644 index 8b31aa4451032b6f229001a408c863aa098761ea..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/res/postgresql/postgresql-compatibility.sql +++ /dev/null @@ -1,115 +0,0 @@ --- Add Compatibility operators --- --- SQL below solves a particular case where in the search option in the list module (and possible other modules) --- integers types are compared against text types. While this is perfectly 'valid' in MySQL, this is not valid in PostgreSQL. --- --- An example of such SQL generated by TYPO3 is (see "uid" LIKE '%Old%'): --- SELECT count(*) --- FROM "tx_rvtcouponfeeds_programnames" --- WHERE "pid" = 100 AND ("uid" LIKE '%Old%' OR "programname" LIKE '%Old%' OR "programurl" LIKE '%Old%') --- --- The functions add compatibility operators for PostgreSQL to make sure comparison is possible and the SQL doesn't return an error. --- --- Note: You may consider having a look at project mysqlcompat on http://pgfoundry.org/projects/mysqlcompat --- and report in DBAL bugtracker if you need another compatibility operator added. --- --- $Id: postgresql-compatibility.sql 35742 2010-07-16 13:22:56Z xperseguers $ --- R. van Twisk <typo3@rvt.dds.nl> - - -CREATE OR REPLACE FUNCTION t3compat_operator_like(t text, i integer) RETURNS boolean AS -$BODY$ -BEGIN - RETURN t LIKE i; -END -$BODY$ -LANGUAGE 'plpgsql' VOLATILE -COST 1; - -CREATE OR REPLACE FUNCTION t3compat_operator_like(i integer, t text) RETURNS boolean AS -$BODY$ -BEGIN - RETURN i::text LIKE t; -END -$BODY$ -LANGUAGE 'plpgsql' VOLATILE -COST 1; - -CREATE OR REPLACE FUNCTION t3compat_operator_eq(t text, i integer) RETURNS boolean AS -$BODY$ -BEGIN - RETURN i::text=t; -END -$BODY$ -LANGUAGE 'plpgsql' VOLATILE -COST 1; - -CREATE OR REPLACE FUNCTION t3compat_operator_eq(i integer, t text) RETURNS boolean AS -$BODY$ -BEGIN - RETURN i::text=t; -END -$BODY$ -LANGUAGE 'plpgsql' VOLATILE -COST 1; - --- Operator for LIKE -CREATE OPERATOR ~~ (PROCEDURE = t3compat_operator_like, LEFTARG = integer, RIGHTARG = text); -CREATE OPERATOR ~~ (PROCEDURE = t3compat_operator_like, LEFTARG = text, RIGHTARG = integer); --- Operator for Equality -CREATE OPERATOR = (PROCEDURE = t3compat_operator_eq, LEFTARG = integer, RIGHTARG = text); -CREATE OPERATOR = (PROCEDURE = t3compat_operator_eq, LEFTARG = text, RIGHTARG = integer); - --- LOCATE() -CREATE OR REPLACE FUNCTION locate(text, text, integer) -RETURNS integer AS $$ -SELECT POSITION($1 IN SUBSTRING ($2 FROM $3)) + $3 - 1 -$$ IMMUTABLE STRICT LANGUAGE SQL; - -CREATE OR REPLACE FUNCTION locate(text, text) -RETURNS integer AS $$ -SELECT locate($1, $2, 1) -$$ IMMUTABLE STRICT LANGUAGE SQL; - --- IFNULL -CREATE OR REPLACE FUNCTION ifnull(anyelement, anyelement) -RETURNS anyelement AS $$ -SELECT COALESCE($1, $2) -$$ IMMUTABLE STRICT LANGUAGE SQL; - --- FIND_IN_SET --- FIND_IN_SET() -CREATE OR REPLACE FUNCTION find_in_set(text, text) -RETURNS integer AS $$ -DECLARE - list text[]; - len integer; -BEGIN - IF $2 = '' THEN - RETURN 0; - END IF; - list := pg_catalog.string_to_array($2, ','); - len := pg_catalog.array_upper(list, 1); - FOR i IN 1..len LOOP - IF list[i] = $1 THEN - RETURN i; - END IF; - END LOOP; - RETURN 0; -END; -$$ STRICT IMMUTABLE LANGUAGE PLPGSQL; - --- Remove Compatibility operators --- ---DROP OPERATOR ~~ (integer,text); ---DROP OPERATOR ~~ (text,integer); ---DROP OPERATOR = (integer,text); ---DROP OPERATOR = (text,integer); ---DROP FUNCTION t3compat_operator_like(integer, text); ---DROP FUNCTION t3compat_operator_like(text, integer); ---DROP FUNCTION t3compat_operator_eq(integer, text); ---DROP FUNCTION t3compat_operator_eq(text, integer); ---DROP FUNCTION locate(text, text); ---DROP FUNCTION locate(text, text, integer); ---DROP FUNCTION ifnull(anyelement, anyelement); - diff --git a/typo3/sysext/dbal/tests/BaseTestCase.php b/typo3/sysext/dbal/tests/BaseTestCase.php deleted file mode 100644 index e093cbbb6c67a8e21b7ee3cb94c35f74e664da40..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/tests/BaseTestCase.php +++ /dev/null @@ -1,89 +0,0 @@ -<?php -/*************************************************************** - * Copyright notice - * - * (c) 2009 Robert Lemke <robert@typo3.org> - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -/** - * The mother of all test cases. - * - * Subclass this base class if you want to take advantage of the framework - * capabilities. - * - * $Id: BaseTestCase.php 40716 2010-12-01 10:49:27Z xperseguers $ - * - * @author Robert Lemke <robert@typo3.org> - * - * This method is backported from FLOW3's BaseTestCase class. - * @link https://svn.typo3.org/FLOW3/Packages/Testing/trunk/Classes/BaseTestCase.php - * - * @package TYPO3 - * @subpackage dbal - */ -abstract class BaseTestCase extends tx_phpunit_testcase { - - /** - * Creates a proxy class of the specified class which allows - * for calling even protected methods and access of protected properties. - * - * @param protected $className Full qualified name of the original class - * @return string Full qualified name of the built class - * @api - */ - protected function buildAccessibleProxy($className) { - $accessibleClassName = uniqid('AccessibleTestProxy'); - $class = new ReflectionClass($className); - $abstractModifier = $class->isAbstract() ? 'abstract ' : ''; - eval(' - ' . $abstractModifier . 'class ' . $accessibleClassName . ' extends ' . $className . ' { - public function _call($methodName) { - return call_user_func_array(array($this, $methodName), array_slice(func_get_args(), 1)); - } - public function _callRef($methodName, &$arg1 = NULL, &$arg2 = NULL, &$arg3 = NULL, &$arg4 = NULL, &$arg5 = NULL, &$arg6 = NULL, &$arg7 = NULL, &$arg8 = NULL, &$arg9 = NULL) { - switch (func_num_args()) { - case 0 : return $this->$methodName(); - case 1 : return $this->$methodName($arg1); - case 2 : return $this->$methodName($arg1, $arg2); - case 3 : return $this->$methodName($arg1, $arg2, $arg3); - case 4 : return $this->$methodName($arg1, $arg2, $arg3, $arg4); - case 5 : return $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5); - case 6 : return $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6); - case 7 : return $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7); - case 8 : return $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8); - case 9 : return $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8, $arg9); - } - } - public function _set($propertyName, $value) { - $this->$propertyName = $value; - } - public function _setRef($propertyName, &$value) { - $this->$propertyName = $value; - } - public function _get($propertyName) { - return $this->$propertyName; - } - } - '); - return $accessibleClassName; - } -} - -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/tests/FakeDbConnection.php b/typo3/sysext/dbal/tests/FakeDbConnection.php deleted file mode 100644 index e3836e43eed47c2e69c3038d6f83b89d1529be61..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/tests/FakeDbConnection.php +++ /dev/null @@ -1,66 +0,0 @@ -<?php -/*************************************************************** - * Copyright notice - * - * (c) 2009 Xavier Perseguers <typo3@perseguers.ch> - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - - -/** - * Fake ADOdb connection factory. - * - * $Id: FakeDbConnection.php 40716 2010-12-01 10:49:27Z xperseguers $ - * - * @author Xavier Perseguers <typo3@perseguers.ch> - * - * @package TYPO3 - * @subpackage dbal - */ -class FakeDbConnection { - - /** - * Creates a fake database connection. - * - * @param ux_t3lib_db $db - * @param string $databaseType Type of the database (e.g., 'oracle') - * @param string $driver Driver to use (e.g., 'oci8') - * @return ADOConnection - */ - public static function connect(ux_t3lib_db $db, $driver) { - // Make sure to have a clean configuration - $db->clearCachedFieldInfo(); - $db->_call('initInternalVariables'); - - include_once(t3lib_extMgm::extPath('adodb') . 'adodb/drivers/adodb-' . $driver . '.inc.php'); - - $handlerKey = '_DEFAULT'; - $db->lastHandlerKey = $handlerKey; - $db->handlerInstance[$handlerKey] = t3lib_div::makeInstance('ADODB_' . $driver); - - // From method handler_init() - $db->handlerInstance[$handlerKey]->DataDictionary = NewDataDictionary($db->handlerInstance[$handlerKey]); - - // DataDictionary being set, a connectionID may be arbitrarily chosen - $db->handlerInstance[$handlerKey]->_connectionID = rand(1, 1000); - } - -} - -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/tests/dbGeneralTest.php b/typo3/sysext/dbal/tests/dbGeneralTest.php deleted file mode 100644 index faa445f8fdc0840754be7dde054d5d93e36c877d..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/tests/dbGeneralTest.php +++ /dev/null @@ -1,303 +0,0 @@ -<?php -/*************************************************************** - * Copyright notice - * - * (c) 2009 Xavier Perseguers <typo3@perseguers.ch> - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - - -require_once('BaseTestCase.php'); - -/** - * Testcase for class ux_t3lib_db. - * - * $Id$ - * - * @author Xavier Perseguers <typo3@perseguers.ch> - * - * @package TYPO3 - * @subpackage dbal - */ -class dbGeneralTest extends BaseTestCase { - - /** - * @var t3lib_db - */ - protected $db; - - /** - * @var array - */ - protected $loadedExtensions; - - /** - * @var array - */ - protected $temporaryFiles; - - /** - * Prepares the environment before running a test. - */ - public function setUp() { - // Backup list of loaded extensions - $this->loadedExtensions = $GLOBALS['TYPO3_LOADED_EXT']; - // Backup database connection - $this->db = $GLOBALS['TYPO3_DB']; - $this->temporaryFiles = array(); - - $className = self::buildAccessibleProxy('ux_t3lib_db'); - $GLOBALS['TYPO3_DB'] = new $className; - $GLOBALS['TYPO3_DB']->lastHandlerKey = '_DEFAULT'; - } - - /** - * Cleans up the environment after running a test. - */ - public function tearDown() { - // Clear DBAL-generated cache files - $GLOBALS['TYPO3_DB']->clearCachedFieldInfo(); - // Delete temporary files - foreach ($this->temporaryFiles as $filename) unlink($filename); - // Restore DB connection - $GLOBALS['TYPO3_DB'] = $this->db; - // Restore list of loaded extensions - $GLOBALS['TYPO3_LOADED_EXT'] = $this->loadedExtensions; - } - - /** - * Cleans a SQL query. - * - * @param mixed $sql - * @return mixed (string or array) - */ - private function cleanSql($sql) { - if (!is_string($sql)) { - return $sql; - } - - $sql = str_replace("\n", ' ', $sql); - $sql = preg_replace('/\s+/', ' ', $sql); - return trim($sql); - } - - /** - * Creates a fake extension with a given table definition. - * - * @param string $tableDefinition SQL script to create the extension's tables - * @return void - */ - protected function createFakeExtension($tableDefinition) { - // Prepare a fake extension configuration - $ext_tables = t3lib_div::tempnam('ext_tables'); - t3lib_div::writeFile($ext_tables, $tableDefinition); - $this->temporaryFiles[] = $ext_tables; - - $GLOBALS['TYPO3_LOADED_EXT']['test_dbal'] = array( - 'ext_tables.sql' => $ext_tables - ); - - // Append our test table to the list of existing tables - $GLOBALS['TYPO3_DB']->clearCachedFieldInfo(); - $GLOBALS['TYPO3_DB']->_call('initInternalVariables'); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12515 - */ - public function concatCanBeParsedAfterLikeOperator() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'sys_refindex, tx_dam_file_tracking', - 'sys_refindex.tablename = \'tx_dam_file_tracking\'' - . ' AND sys_refindex.ref_string LIKE CONCAT(tx_dam_file_tracking.file_path, tx_dam_file_tracking.file_name)' - )); - $expected = 'SELECT * FROM sys_refindex, tx_dam_file_tracking WHERE sys_refindex.tablename = \'tx_dam_file_tracking\''; - $expected .= ' AND sys_refindex.ref_string LIKE CONCAT(tx_dam_file_tracking.file_path, tx_dam_file_tracking.file_name)'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=10965 - */ - public function floatNumberCanBeStoredInDatabase() { - $this->createFakeExtension(' - CREATE TABLE tx_test_dbal ( - foo double default \'0\', - foobar integer default \'0\' - ); - '); - $data = array( - 'foo' => 99.12, - 'foobar' => -120, - ); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->INSERTquery('tx_test_dbal', $data)); - $expected = 'INSERT INTO tx_test_dbal ( foo, foobar ) VALUES ( \'99.12\', \'-120\' )'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=11093 - */ - public function positive64BitIntegerIsSupported() { - $this->createFakeExtension(' - CREATE TABLE tx_test_dbal ( - foo int default \'0\', - foobar bigint default \'0\' - ); - '); - $data = array( - 'foo' => 9223372036854775807, - 'foobar' => 9223372036854775807, - ); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->INSERTquery('tx_test_dbal', $data)); - $expected = 'INSERT INTO tx_test_dbal ( foo, foobar ) VALUES ( \'9223372036854775807\', \'9223372036854775807\' )'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=11093 - */ - public function negative64BitIntegerIsSupported() { - $this->createFakeExtension(' - CREATE TABLE tx_test_dbal ( - foo int default \'0\', - foobar bigint default \'0\' - ); - '); - $data = array( - 'foo' => -9223372036854775808, - 'foobar' => -9223372036854775808, - ); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->INSERTquery('tx_test_dbal', $data)); - $expected = 'INSERT INTO tx_test_dbal ( foo, foobar ) VALUES ( \'-9223372036854775808\', \'-9223372036854775808\' )'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * http://bugs.typo3.org/view.php?id=12858 - */ - public function sqlForInsertWithMultipleRowsIsValid() { - $fields = array('uid', 'pid', 'title', 'body'); - $rows = array( - array('1', '2', 'Title #1', 'Content #1'), - array('3', '4', 'Title #2', 'Content #2'), - array('5', '6', 'Title #3', 'Content #3'), - ); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->INSERTmultipleRows('tt_content', $fields, $rows)); - - $expected = 'INSERT INTO tt_content (uid, pid, title, body) VALUES '; - $expected .= "('1', '2', 'Title #1', 'Content #1'), "; - $expected .= "('3', '4', 'Title #2', 'Content #2'), "; - $expected .= "('5', '6', 'Title #3', 'Content #3')"; - - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=4493 - */ - public function minFunctionAndInOperatorCanBeParsed() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'pages', - 'MIN(uid) IN (1,2,3,4)' - )); - $expected = 'SELECT * FROM pages WHERE MIN(uid) IN (1,2,3,4)'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=4493 - */ - public function maxFunctionAndInOperatorCanBeParsed() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'pages', - 'MAX(uid) IN (1,2,3,4)' - )); - $expected = 'SELECT * FROM pages WHERE MAX(uid) IN (1,2,3,4)'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12535 - */ - public function likeBinaryOperatorIsKept() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'tt_content', - 'bodytext LIKE BINARY \'test\'' - )); - $expected = 'SELECT * FROM tt_content WHERE bodytext LIKE BINARY \'test\''; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12535 - */ - public function notLikeBinaryOperatorIsKept() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'tt_content', - 'bodytext NOT LIKE BINARY \'test\'' - )); - $expected = 'SELECT * FROM tt_content WHERE bodytext NOT LIKE BINARY \'test\''; - $this->assertEquals($expected, $query); - } - - /////////////////////////////////////// - // Tests concerning prepared queries - /////////////////////////////////////// - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=15457 - */ - public function similarNamedParametersAreProperlyReplaced() { - $sql = 'SELECT * FROM cache WHERE tag = :tag1 OR tag = :tag10 OR tag = :tag100'; - $parameterValues = array( - ':tag1' => 'tag-one', - ':tag10' => 'tag-two', - ':tag100' => 'tag-three', - ); - - $className = self::buildAccessibleProxy('t3lib_db_PreparedStatement'); - $query = $sql; - $precompiledQueryParts = array(); - $statement = new $className($sql, 'cache'); - $statement->bindValues($parameterValues); - $parameters = $statement->_get('parameters'); - - $statement->_callRef('replaceValuesInQuery', $query, $precompiledQueryParts, $parameters); - $expected = 'SELECT * FROM cache WHERE tag = \'tag-one\' OR tag = \'tag-two\' OR tag = \'tag-three\''; - $this->assertEquals($expected, $query); - } -} - -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/tests/dbMssqlTest.php b/typo3/sysext/dbal/tests/dbMssqlTest.php deleted file mode 100644 index 1c2272ac815e768cea10768a48f1d26b51c00e6f..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/tests/dbMssqlTest.php +++ /dev/null @@ -1,262 +0,0 @@ -<?php -/*************************************************************** - * Copyright notice - * - * (c) 2009 Xavier Perseguers <typo3@perseguers.ch> - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - - -require_once('BaseTestCase.php'); -require_once('FakeDbConnection.php'); - -/** - * Testcase for class ux_t3lib_db. Testing MS SQL database handling. - * - * $Id$ - * - * @author Xavier Perseguers <typo3@perseguers.ch> - * - * @package TYPO3 - * @subpackage dbal - */ -class dbMssqlTest extends BaseTestCase { - - /** - * @var t3lib_db - */ - protected $db; - - /** - * @var array - */ - protected $dbalConfig; - - /** - * Prepares the environment before running a test. - */ - public function setUp() { - // Backup DBAL configuration - $this->dbalConfig = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']; - // Backup database connection - $this->db = $GLOBALS['TYPO3_DB']; - // Reconfigure DBAL to use MS SQL - require('fixtures/mssql.config.php'); - - $className = self::buildAccessibleProxy('ux_t3lib_db'); - $GLOBALS['TYPO3_DB'] = new $className; - $parserClassName = self::buildAccessibleProxy('ux_t3lib_sqlparser'); - $GLOBALS['TYPO3_DB']->SQLparser = new $parserClassName; - - $this->assertFalse($GLOBALS['TYPO3_DB']->isConnected()); - - // Initialize a fake MS SQL connection - FakeDbConnection::connect($GLOBALS['TYPO3_DB'], 'mssql'); - - $this->assertTrue($GLOBALS['TYPO3_DB']->isConnected()); - } - - /** - * Cleans up the environment after running a test. - */ - public function tearDown() { - // Clear DBAL-generated cache files - $GLOBALS['TYPO3_DB']->clearCachedFieldInfo(); - // Restore DBAL configuration - $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal'] = $this->dbalConfig; - // Restore DB connection - $GLOBALS['TYPO3_DB'] = $this->db; - } - - /** - * Cleans a SQL query. - * - * @param mixed $sql - * @return mixed (string or array) - */ - private function cleanSql($sql) { - if (!is_string($sql)) { - return $sql; - } - - $sql = str_replace("\n", ' ', $sql); - $sql = preg_replace('/\s+/', ' ', $sql); - return trim($sql); - } - - /** - * @test - */ - public function configurationIsUsingAdodbAndDriverMssql() { - $configuration = $GLOBALS['TYPO3_DB']->conf['handlerCfg']; - $this->assertTrue(is_array($configuration) && count($configuration) > 0, 'No configuration found'); - $this->assertEquals('adodb', $configuration['_DEFAULT']['type']); - $this->assertTrue($GLOBALS['TYPO3_DB']->runningADOdbDriver('mssql') !== FALSE, 'Not using mssql driver'); - } - - /** - * @test - */ - public function tablesWithMappingAreDetected() { - $tablesWithMapping = array_keys($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['mapping']); - - foreach ($GLOBALS['TYPO3_DB']->cache_fieldType as $table => $fieldTypes) { - $tableDef = $GLOBALS['TYPO3_DB']->_call('map_needMapping', $table); - - if (in_array($table, $tablesWithMapping)) { - self::assertTrue(is_array($tableDef), 'Table ' . $table . ' was expected to need mapping'); - } else { - self::assertFalse($tableDef, 'Table ' . $table . ' was not expected to need mapping'); - } - } - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14985 - */ - public function findInSetIsProperlyRemapped() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'fe_users', - 'FIND_IN_SET(10, usergroup)' - )); - $expected = 'SELECT * FROM "fe_users" WHERE \',\'+"usergroup"+\',\' LIKE \'%,10,%\''; - $this->assertEquals($expected, $query); - } - - /////////////////////////////////////// - // Tests concerning remapping with - // external (non-TYPO3) databases - /////////////////////////////////////// - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13490 - */ - public function canRemapPidToZero() { - $selectFields = 'uid, FirstName, LastName'; - $fromTables = 'Members'; - $whereClause = 'pid=0 AND cruser_id=1'; - $groupBy = ''; - $orderBy = ''; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT "MemberID", "FirstName", "LastName" FROM "Members" WHERE 0 = 0 AND 1 = 1'; - $this->assertEquals($expected, $query); - } - - /////////////////////////////////////// - // Tests concerning advanced operators - /////////////////////////////////////// - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13134 - */ - public function locateStatementIsProperlyQuoted() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*, CASE WHEN' . - ' LOCATE(' . $GLOBALS['TYPO3_DB']->fullQuoteStr('(fce)', 'tx_templavoila_tmplobj') . ', datastructure)>0 THEN 2' . - ' ELSE 1' . - ' END AS scope', - 'tx_templavoila_tmplobj', - '1=1' - )); - $expected = 'SELECT *, CASE WHEN CHARINDEX(\'(fce)\', "datastructure") > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13134 - */ - public function locateStatementWithPositionIsProperlyQuoted() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*, CASE WHEN' . - ' LOCATE(' . $GLOBALS['TYPO3_DB']->fullQuoteStr('(fce)', 'tx_templavoila_tmplobj') . ', datastructure, 4)>0 THEN 2' . - ' ELSE 1' . - ' END AS scope', - 'tx_templavoila_tmplobj', - '1=1' - )); - $expected = 'SELECT *, CASE WHEN CHARINDEX(\'(fce)\', "datastructure", 4) > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13134 - */ - public function locateStatementIsProperlyRemapped() { - $selectFields = '*, CASE WHEN' . - ' LOCATE(' . $GLOBALS['TYPO3_DB']->fullQuoteStr('(fce)', 'tx_templavoila_tmplobj') . ', datastructure, 4)>0 THEN 2' . - ' ELSE 1' . - ' END AS scope'; - $fromTables = 'tx_templavoila_tmplobj'; - $whereClause = '1=1'; - $groupBy = ''; - $orderBy = ''; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT *, CASE WHEN CHARINDEX(\'(fce)\', "ds", 4) > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13134 - */ - public function locateStatementWithExternalTableIsProperlyRemapped() { - $selectFields = '*, CASE WHEN' . - ' LOCATE(' . $GLOBALS['TYPO3_DB']->fullQuoteStr('(fce)', 'tx_templavoila_tmplobj') . ', tx_templavoila_tmplobj.datastructure, 4)>0 THEN 2' . - ' ELSE 1' . - ' END AS scope'; - $fromTables = 'tx_templavoila_tmplobj'; - $whereClause = '1=1'; - $groupBy = ''; - $orderBy = ''; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT *, CASE WHEN CHARINDEX(\'(fce)\', "tx_templavoila_tmplobj"."ds", 4) > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=6196 - */ - public function IfNullIsProperlyRemapped() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'tt_news_cat_mm', - 'IFNULL(tt_news_cat_mm.uid_foreign,0) IN (21,22)' - )); - $expected = 'SELECT * FROM "tt_news_cat_mm" WHERE ISNULL("tt_news_cat_mm"."uid_foreign", 0) IN (21,22)'; - $this->assertEquals($expected, $query); - } -} - -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/tests/dbOracleTest.php b/typo3/sysext/dbal/tests/dbOracleTest.php deleted file mode 100644 index 2ce1ff4dd54ff7b537841e984e8c5c644d0aabc7..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/tests/dbOracleTest.php +++ /dev/null @@ -1,1145 +0,0 @@ -<?php -/*************************************************************** - * Copyright notice - * - * (c) 2009 Xavier Perseguers <typo3@perseguers.ch> - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - - -require_once('BaseTestCase.php'); -require_once('FakeDbConnection.php'); - -/** - * Testcase for class ux_t3lib_db. Testing Oracle database handling. - * - * $Id$ - * - * @author Xavier Perseguers <typo3@perseguers.ch> - * - * @package TYPO3 - * @subpackage dbal - */ -class dbOracleTest extends BaseTestCase { - - /** - * @var t3lib_db - */ - protected $db; - - /** - * @var array - */ - protected $dbalConfig; - - /** - * Prepares the environment before running a test. - */ - public function setUp() { - // Backup DBAL configuration - $this->dbalConfig = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']; - // Backup database connection - $this->db = $GLOBALS['TYPO3_DB']; - // Reconfigure DBAL to use Oracle - require('fixtures/oci8.config.php'); - - $className = self::buildAccessibleProxy('ux_t3lib_db'); - $GLOBALS['TYPO3_DB'] = new $className; - $parserClassName = self::buildAccessibleProxy('ux_t3lib_sqlparser'); - $GLOBALS['TYPO3_DB']->SQLparser = new $parserClassName; - - $this->assertFalse($GLOBALS['TYPO3_DB']->isConnected()); - - // Initialize a fake Oracle connection - FakeDbConnection::connect($GLOBALS['TYPO3_DB'], 'oci8'); - - $this->assertTrue($GLOBALS['TYPO3_DB']->isConnected()); - } - - /** - * Cleans up the environment after running a test. - */ - public function tearDown() { - // Clear DBAL-generated cache files - $GLOBALS['TYPO3_DB']->clearCachedFieldInfo(); - // Restore DBAL configuration - $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal'] = $this->dbalConfig; - // Restore DB connection - $GLOBALS['TYPO3_DB'] = $this->db; - } - - /** - * Cleans a SQL query. - * - * @param mixed $sql - * @return mixed (string or array) - */ - private function cleanSql($sql) { - if (!is_string($sql)) { - return $sql; - } - - $sql = str_replace("\n", ' ', $sql); - $sql = preg_replace('/\s+/', ' ', $sql); - return trim($sql); - } - - /** - * @test - */ - public function configurationIsUsingAdodbAndDriverOci8() { - $configuration = $GLOBALS['TYPO3_DB']->conf['handlerCfg']; - $this->assertTrue(is_array($configuration) && count($configuration) > 0, 'No configuration found'); - $this->assertEquals('adodb', $configuration['_DEFAULT']['type']); - $this->assertTrue($GLOBALS['TYPO3_DB']->runningADOdbDriver('oci8') !== FALSE, 'Not using oci8 driver'); - } - - /** - * @test - */ - public function tablesWithMappingAreDetected() { - $tablesWithMapping = array_keys($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['mapping']); - - foreach ($GLOBALS['TYPO3_DB']->cache_fieldType as $table => $fieldTypes) { - $tableDef = $GLOBALS['TYPO3_DB']->_call('map_needMapping', $table); - - if (in_array($table, $tablesWithMapping)) { - self::assertTrue(is_array($tableDef), 'Table ' . $table . ' was expected to need mapping'); - } else { - self::assertFalse($tableDef, 'Table ' . $table . ' was not expected to need mapping'); - } - } - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12897 - */ - public function sqlHintIsRemoved() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '/*! SQL_NO_CACHE */ content', - 'tx_realurl_urlencodecache', - '1=1' - )); - $expected = 'SELECT "content" FROM "tx_realurl_urlencodecache" WHERE 1 = 1'; - $this->assertEquals($expected, $query); - } - - /** - * @test - */ - public function canCompileInsertWithFields() { - $parseString = 'INSERT INTO static_territories (uid, pid, tr_iso_nr, tr_parent_iso_nr, tr_name_en) '; - $parseString .= "VALUES ('1', '0', '2', '0', 'Africa');"; - $components = $GLOBALS['TYPO3_DB']->SQLparser->_callRef('parseINSERT', $parseString); - - $this->assertTrue(is_array($components), $components); - $insert = $GLOBALS['TYPO3_DB']->SQLparser->_callRef('compileINSERT', $components); - - $expected = array( - 'uid' => '1', - 'pid' => '0', - 'tr_iso_nr' => '2', - 'tr_parent_iso_nr' => '0', - 'tr_name_en' => 'Africa', - ); - $this->assertEquals($expected, $insert); - } - - /** - * @test - * http://bugs.typo3.org/view.php?id=13209 - */ - public function canCompileExtendedInsert() { - $parseString = "INSERT INTO static_territories VALUES ('1', '0', '2', '0', 'Africa'),('2', '0', '9', '0', 'Oceania')," . - "('3', '0', '19', '0', 'Americas'),('4', '0', '142', '0', 'Asia');"; - $components = $GLOBALS['TYPO3_DB']->SQLparser->_callRef('parseINSERT', $parseString); - - $this->assertTrue(is_array($components), $components); - $insert = $GLOBALS['TYPO3_DB']->SQLparser->_callRef('compileINSERT', $components); - - $this->assertEquals(4, count($insert)); - - for ($i = 0; $i < count($insert); $i++) { - foreach (t3lib_div::trimExplode(',', 'uid,pid,tr_iso_nr,tr_parent_iso_nr,tr_name_en') as $field) { - $this->assertTrue(isset($insert[$i][$field]), 'Could not find ' . $field . ' column'); - } - } - } - - /** - * @test - * http://bugs.typo3.org/view.php?id=12858 - */ - public function sqlForInsertWithMultipleRowsIsValid() { - $fields = array('uid', 'pid', 'title', 'body'); - $rows = array( - array('1', '2', 'Title #1', 'Content #1'), - array('3', '4', 'Title #2', 'Content #2'), - array('5', '6', 'Title #3', 'Content #3'), - ); - $query = $GLOBALS['TYPO3_DB']->INSERTmultipleRows('tt_content', $fields, $rows); - - $expected[0] = 'INSERT INTO "tt_content" ( "uid", "pid", "title", "body" ) VALUES ( \'1\', \'2\', \'Title #1\', \'Content #1\' )'; - $expected[1] = 'INSERT INTO "tt_content" ( "uid", "pid", "title", "body" ) VALUES ( \'3\', \'4\', \'Title #2\', \'Content #2\' )'; - $expected[2] = 'INSERT INTO "tt_content" ( "uid", "pid", "title", "body" ) VALUES ( \'5\', \'6\', \'Title #3\', \'Content #3\' )'; - - $this->assertEquals(count($expected), count($query)); - for ($i = 0; $i < count($query); $i++) { - $this->assertTrue(is_array($query[$i]), 'Expected array: ' . $query[$i]); - $this->assertEquals(1, count($query[$i])); - $this->assertEquals($expected[$i], $this->cleanSql($query[$i][0])); - } - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=15535 - */ - public function groupConditionsAreProperlyTransformed() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'pages', - 'pid=0 AND pages.deleted=0 AND pages.hidden=0 AND pages.starttime<=1281620460 ' - . 'AND (pages.endtime=0 OR pages.endtime>1281620460) AND NOT pages.t3ver_state>0 ' - . 'AND pages.doktype<200 AND (pages.fe_group=\'\' OR pages.fe_group IS NULL OR ' - . 'pages.fe_group=\'0\' OR FIND_IN_SET(\'0\',pages.fe_group) OR FIND_IN_SET(\'-1\',pages.fe_group))' - )); - $expected = 'SELECT * FROM "pages" WHERE "pid" = 0 AND "pages"."deleted" = 0 AND "pages"."hidden" = 0 ' - . 'AND "pages"."starttime" <= 1281620460 AND ("pages"."endtime" = 0 OR "pages"."endtime" > 1281620460) ' - . 'AND NOT "pages"."t3ver_state" > 0 AND "pages"."doktype" < 200 AND ("pages"."fe_group" = \'\' ' - . 'OR "pages"."fe_group" IS NULL OR "pages"."fe_group" = \'0\' OR \',\'||"pages"."fe_group"||\',\' LIKE \'%,0,%\' ' - . 'OR \',\'||"pages"."fe_group"||\',\' LIKE \'%,-1,%\')'; - $this->assertEquals($expected, $query); - } - - /////////////////////////////////////// - // Tests concerning quoting - /////////////////////////////////////// - - /** - * @test - */ - public function selectQueryIsProperlyQuoted() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - 'uid', // select fields - 'tt_content', // from table - 'pid=1', // where clause - 'cruser_id', // group by - 'tstamp' // order by - )); - $expected = 'SELECT "uid" FROM "tt_content" WHERE "pid" = 1 GROUP BY "cruser_id" ORDER BY "tstamp"'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * http://bugs.typo3.org/view.php?id=13504 - */ - public function truncateQueryIsProperlyQuoted() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->TRUNCATEquery('be_users')); - $expected = 'TRUNCATE TABLE "be_users"'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=2438 - */ - public function distinctFieldIsProperlyQuoted() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - 'COUNT(DISTINCT pid)', // select fields - 'tt_content', // from table - '1=1' // where clause - )); - $expected = 'SELECT COUNT(DISTINCT "pid") FROM "tt_content" WHERE 1 = 1'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=10411 - * @remark Remapping is not expected here - */ - public function multipleInnerJoinsAreProperlyQuoted() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'tt_news_cat INNER JOIN tt_news_cat_mm ON tt_news_cat.uid = tt_news_cat_mm.uid_foreign INNER JOIN tt_news ON tt_news.uid = tt_news_cat_mm.uid_local', - '1=1' - )); - $expected = 'SELECT * FROM "tt_news_cat"'; - $expected .= ' INNER JOIN "tt_news_cat_mm" ON "tt_news_cat"."uid"="tt_news_cat_mm"."uid_foreign"'; - $expected .= ' INNER JOIN "tt_news" ON "tt_news"."uid"="tt_news_cat_mm"."uid_local"'; - $expected .= ' WHERE 1 = 1'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=6198 - */ - public function stringsWithinInClauseAreProperlyQuoted() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - 'COUNT(DISTINCT tx_dam.uid) AS count', - 'tx_dam', - 'tx_dam.pid IN (1) AND tx_dam.file_type IN (\'gif\',\'png\',\'jpg\',\'jpeg\') AND tx_dam.deleted = 0' - )); - $expected = 'SELECT COUNT(DISTINCT "tx_dam"."uid") AS "count" FROM "tx_dam"'; - $expected .= ' WHERE "tx_dam"."pid" IN (1) AND "tx_dam"."file_type" IN (\'gif\',\'png\',\'jpg\',\'jpeg\') AND "tx_dam"."deleted" = 0'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12515 - * @remark Remapping is not expected here - */ - public function concatAfterLikeOperatorIsProperlyQuoted() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'sys_refindex, tx_dam_file_tracking', - 'sys_refindex.tablename = \'tx_dam_file_tracking\'' - . ' AND sys_refindex.ref_string LIKE CONCAT(tx_dam_file_tracking.file_path, tx_dam_file_tracking.file_name)' - )); - $expected = 'SELECT * FROM "sys_refindex", "tx_dam_file_tracking" WHERE "sys_refindex"."tablename" = \'tx_dam_file_tracking\''; - $expected .= ' AND (instr(LOWER("sys_refindex"."ref_string"), CONCAT("tx_dam_file_tracking"."file_path","tx_dam_file_tracking"."file_name"),1,1) > 0)'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12231 - */ - public function cachingFrameworkQueryIsProperlyQuoted() { - $currentTime = time(); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - 'content', - 'cache_hash', - 'identifier = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('abbbabaf2d4b3f9a63e8dde781f1c106', 'cache_hash') . - ' AND (crdate + lifetime >= ' . $currentTime . ' OR lifetime = 0)' - )); - $expected = 'SELECT "content" FROM "cache_hash" WHERE "identifier" = \'abbbabaf2d4b3f9a63e8dde781f1c106\' AND ("crdate"+"lifetime" >= ' . $currentTime . ' OR "lifetime" = 0)'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12231 - */ - public function calculatedFieldsAreProperlyQuoted() { - $currentTime = time(); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - 'identifier', - 'cachingframework_cache_pages', - 'crdate + lifetime < ' . $currentTime . ' AND lifetime > 0' - )); - $expected = 'SELECT "identifier" FROM "cachingframework_cache_pages" WHERE "crdate"+"lifetime" < ' . $currentTime . ' AND "lifetime" > 0'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * http://bugs.typo3.org/view.php?id=13422 - */ - public function numericColumnsAreNotQuoted() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '1', - 'be_users', - 'username = \'_cli_scheduler\' AND admin = 0 AND be_users.deleted = 0' - )); - $expected = 'SELECT 1 FROM "be_users" WHERE "username" = \'_cli_scheduler\' AND "admin" = 0 AND "be_users"."deleted" = 0'; - $this->assertEquals($expected, $query); - } - - /////////////////////////////////////// - // Tests concerning remapping - /////////////////////////////////////// - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=10411 - * @remark Remapping is expected here - */ - public function tablesAndFieldsAreRemappedInMultipleJoins() { - $selectFields = '*'; - $fromTables = 'tt_news_cat INNER JOIN tt_news_cat_mm ON tt_news_cat.uid = tt_news_cat_mm.uid_foreign INNER JOIN tt_news ON tt_news.uid = tt_news_cat_mm.uid_local'; - $whereClause = '1=1'; - $groupBy = ''; - $orderBy = ''; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT * FROM "ext_tt_news_cat"'; - $expected .= ' INNER JOIN "ext_tt_news_cat_mm" ON "ext_tt_news_cat"."cat_uid"="ext_tt_news_cat_mm"."uid_foreign"'; - $expected .= ' INNER JOIN "ext_tt_news" ON "ext_tt_news"."news_uid"="ext_tt_news_cat_mm"."local_uid"'; - $expected .= ' WHERE 1 = 1'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=6953 - */ - public function fieldWithinSqlFunctionIsRemapped() { - $selectFields = 'tstamp, script, SUM(exec_time) AS calc_sum, COUNT(*) AS qrycount, MAX(errorFlag) AS error'; - $fromTables = 'tx_dbal_debuglog'; - $whereClause = '1=1'; - $groupBy = ''; - $orderBy = ''; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT "tstamp", "script", SUM("exec_time") AS "calc_sum", COUNT(*) AS "qrycount", MAX("errorflag") AS "error" FROM "tx_dbal_debuglog" WHERE 1 = 1'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=6953 - */ - public function tableAndFieldWithinSqlFunctionIsRemapped() { - $selectFields = 'MAX(tt_news_cat.uid) AS biggest_id'; - $fromTables = 'tt_news_cat INNER JOIN tt_news_cat_mm ON tt_news_cat.uid = tt_news_cat_mm.uid_foreign'; - $whereClause = 'tt_news_cat_mm.uid_local > 50'; - $groupBy = ''; - $orderBy = ''; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT MAX("ext_tt_news_cat"."cat_uid") AS "biggest_id" FROM "ext_tt_news_cat"'; - $expected .= ' INNER JOIN "ext_tt_news_cat_mm" ON "ext_tt_news_cat"."cat_uid"="ext_tt_news_cat_mm"."uid_foreign"'; - $expected .= ' WHERE "ext_tt_news_cat_mm"."local_uid" > 50'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12515 - * @remark Remapping is expected here - */ - public function concatAfterLikeOperatorIsRemapped() { - $selectFields = '*'; - $fromTables = 'sys_refindex, tx_dam_file_tracking'; - $whereClause = 'sys_refindex.tablename = \'tx_dam_file_tracking\'' - . ' AND sys_refindex.ref_string LIKE CONCAT(tx_dam_file_tracking.file_path, tx_dam_file_tracking.file_name)'; - $groupBy = ''; - $orderBy = ''; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT * FROM "sys_refindex", "tx_dam_file_tracking" WHERE "sys_refindex"."tablename" = \'tx_dam_file_tracking\''; - $expected .= ' AND (instr(LOWER("sys_refindex"."ref_string"), CONCAT("tx_dam_file_tracking"."path","tx_dam_file_tracking"."filename"),1,1) > 0)'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=5708 - */ - public function fieldIsMappedOnRightSideOfAJoinCondition() { - $selectFields = 'cpg_categories.uid, cpg_categories.name'; - $fromTables = 'cpg_categories, pages'; - $whereClause = 'pages.uid = cpg_categories.pid AND pages.deleted = 0 AND 1 = 1'; - $groupBy = ''; - $orderBy = 'cpg_categories.pos'; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT "cpg_categories"."uid", "cpg_categories"."name" FROM "cpg_categories", "my_pages" WHERE "my_pages"."page_uid" = "cpg_categories"."page_id"'; - $expected .= ' AND "my_pages"."deleted" = 0 AND 1 = 1 ORDER BY "cpg_categories"."pos"'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14372 - */ - public function fieldFromAliasIsRemapped() { - $selectFields = 'news.uid'; - $fromTables = 'tt_news AS news'; - $whereClause = 'news.uid = 1'; - $groupBy = ''; - $orderBy = ''; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT "news"."news_uid" FROM "ext_tt_news" AS "news" WHERE "news"."news_uid" = 1'; - $this->assertEquals($expected, $query); - } - - /** - * Trick here is that we already have a mapping for both table tt_news and table tt_news_cat - * (see tests/fixtures/oci8.config.php) which is used as alias name. - * - * @test - * @see http://bugs.typo3.org/view.php?id=14372 - */ - public function fieldFromAliasIsRemappedWithoutBeingTricked() { - $selectFields = 'tt_news_cat.uid'; - $fromTables = 'tt_news AS tt_news_cat'; - $whereClause = 'tt_news_cat.uid = 1'; - $groupBy = ''; - $orderBy = ''; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT "tt_news_cat"."news_uid" FROM "ext_tt_news" AS "tt_news_cat" WHERE "tt_news_cat"."news_uid" = 1'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14372 - */ - public function aliasRemappingDoesNotAlterFurtherQueries() { - $selectFields = 'foo.uid'; - $fromTables = 'tt_news AS foo'; - $whereClause = 'foo.uid = 1'; - $groupBy = ''; - $orderBy = ''; - - // First call to possibly alter (in memory) the mapping from localconf.php - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - - $selectFields = 'uid'; - $fromTables = 'foo'; - $whereClause = 'uid = 1'; - $groupBy = ''; - $orderBy = ''; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT "uid" FROM "foo" WHERE "uid" = 1'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14372 - */ - public function fieldFromAliasInJoinIsRemapped() { - $selectFields = 'cat.uid, cat_mm.uid_local, news.uid'; - $fromTables = 'tt_news_cat AS cat' . - ' INNER JOIN tt_news_cat_mm AS cat_mm ON cat.uid = cat_mm.uid_foreign' . - ' INNER JOIN tt_news AS news ON news.uid = cat_mm.uid_local'; - $whereClause = '1=1'; - $groupBy = ''; - $orderBy = ''; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT "cat"."cat_uid", "cat_mm"."local_uid", "news"."news_uid"'; - $expected .= ' FROM "ext_tt_news_cat" AS "cat"'; - $expected .= ' INNER JOIN "ext_tt_news_cat_mm" AS "cat_mm" ON "cat"."cat_uid"="cat_mm"."uid_foreign"'; - $expected .= ' INNER JOIN "ext_tt_news" AS "news" ON "news"."news_uid"="cat_mm"."local_uid"'; - $expected .= ' WHERE 1 = 1'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14372 - */ - public function aliasRemappingWithInSubqueryDoesNotAffectMainQuery() { - $selectFields = 'foo.uid'; - $fromTables = 'tt_news AS foo INNER JOIN tt_news_cat_mm ON tt_news_cat_mm.uid_local = foo.uid'; - $whereClause = 'tt_news_cat_mm.uid_foreign IN (SELECT foo.uid FROM tt_news_cat AS foo WHERE foo.hidden = 0)'; - $groupBy = ''; - $orderBy = 'foo.uid'; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT "foo"."news_uid" FROM "ext_tt_news" AS "foo"'; - $expected .= ' INNER JOIN "ext_tt_news_cat_mm" ON "ext_tt_news_cat_mm"."local_uid"="foo"."news_uid"'; - $expected .= ' WHERE "ext_tt_news_cat_mm"."uid_foreign" IN ('; - $expected .= 'SELECT "foo"."cat_uid" FROM "ext_tt_news_cat" AS "foo" WHERE "foo"."hidden" = 0'; - $expected .= ')'; - $expected .= ' ORDER BY "foo"."news_uid"'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14372 - */ - public function aliasRemappingWithExistsSubqueryDoesNotAffectMainQuery() { - $selectFields = 'foo.uid'; - $fromTables = 'tt_news AS foo INNER JOIN tt_news_cat_mm ON tt_news_cat_mm.uid_local = foo.uid'; - $whereClause = 'EXISTS (SELECT foo.uid FROM tt_news_cat AS foo WHERE foo.hidden = 0)'; - $groupBy = ''; - $orderBy = 'foo.uid'; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT "foo"."news_uid" FROM "ext_tt_news" AS "foo"'; - $expected .= ' INNER JOIN "ext_tt_news_cat_mm" ON "ext_tt_news_cat_mm"."local_uid"="foo"."news_uid"'; - $expected .= ' WHERE EXISTS ('; - $expected .= 'SELECT "foo"."cat_uid" FROM "ext_tt_news_cat" AS "foo" WHERE "foo"."hidden" = 0'; - $expected .= ')'; - $expected .= ' ORDER BY "foo"."news_uid"'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14372 - */ - public function aliasRemappingSupportsNestedSubqueries() { - $selectFields = 'foo.uid'; - $fromTables = 'tt_news AS foo'; - $whereClause = 'uid IN (' . - 'SELECT foobar.uid_local FROM tt_news_cat_mm AS foobar WHERE uid_foreign IN (' . - 'SELECT uid FROM tt_news_cat WHERE deleted = 0' . - '))'; - $groupBy = ''; - $orderBy = ''; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT "foo"."news_uid" FROM "ext_tt_news" AS "foo"'; - $expected .= ' WHERE "news_uid" IN ('; - $expected .= 'SELECT "foobar"."local_uid" FROM "ext_tt_news_cat_mm" AS "foobar" WHERE "uid_foreign" IN ('; - $expected .= 'SELECT "cat_uid" FROM "ext_tt_news_cat" WHERE "deleted" = 0'; - $expected .= ')'; - $expected .= ')'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14372 - */ - public function remappingDoesNotMixUpAliasesInSubquery() { - $selectFields = 'pages.uid'; - $fromTables = 'tt_news AS pages INNER JOIN tt_news_cat_mm AS cat_mm ON cat_mm.uid_local = pages.uid'; - $whereClause = 'pages.pid IN (SELECT uid FROM pages WHERE deleted = 0 AND cat_mm.uid_local != 100)'; - $groupBy = ''; - $orderBy = 'pages.uid'; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT "pages"."news_uid" FROM "ext_tt_news" AS "pages"'; - $expected .= ' INNER JOIN "ext_tt_news_cat_mm" AS "cat_mm" ON "cat_mm"."local_uid"="pages"."news_uid"'; - $expected .= ' WHERE "pages"."pid" IN ('; - $expected .= 'SELECT "page_uid" FROM "my_pages" WHERE "deleted" = 0 AND "cat_mm"."local_uid" != 100'; - $expected .= ')'; - $expected .= ' ORDER BY "pages"."news_uid"'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14479 - */ - public function likeIsRemappedAccordingToFieldType() { - $select = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'tt_content', - 'tt_content.bodytext LIKE \'foo%\'' - )); - $expected = 'SELECT * FROM "tt_content" WHERE (dbms_lob.instr(LOWER("tt_content"."bodytext"), \'foo\',1,1) > 0)'; - $this->assertEquals($expected, $select); - - $select = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'fe_users', - 'fe_users.usergroup LIKE \'2\'' - )); - $expected = 'SELECT * FROM "fe_users" WHERE (instr(LOWER("fe_users"."usergroup"), \'2\',1,1) > 0)'; - $this->assertEquals($expected, $select); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=15253 - */ - public function notLikeIsRemappedAccordingToFieldType() { - $select = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'tt_content', - 'tt_content.bodytext NOT LIKE \'foo%\'' - )); - $expected = 'SELECT * FROM "tt_content" WHERE NOT (dbms_lob.instr(LOWER("tt_content"."bodytext"), \'foo\',1,1) > 0)'; - $this->assertEquals($expected, $select); - - $select = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'fe_users', - 'fe_users.usergroup NOT LIKE \'2\'' - )); - $expected = 'SELECT * FROM "fe_users" WHERE NOT (instr(LOWER("fe_users"."usergroup"), \'2\',1,1) > 0)'; - $this->assertEquals($expected, $select); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14479 - */ - public function instrIsUsedForCEOnPages() { - $select = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'tt_content', - 'uid IN (62) AND tt_content.deleted=0 AND tt_content.t3ver_state<=0' . - ' AND tt_content.hidden=0 AND (tt_content.starttime<=1264487640)' . - ' AND (tt_content.endtime=0 OR tt_content.endtime>1264487640)' . - ' AND (tt_content.fe_group=\'\' OR tt_content.fe_group IS NULL OR tt_content.fe_group=\'0\'' . - ' OR (tt_content.fe_group LIKE \'%,0,%\' OR tt_content.fe_group LIKE \'0,%\' OR tt_content.fe_group LIKE \'%,0\'' . - ' OR tt_content.fe_group=\'0\')' . - ' OR (tt_content.fe_group LIKE\'%,-1,%\' OR tt_content.fe_group LIKE \'-1,%\' OR tt_content.fe_group LIKE \'%,-1\'' . - ' OR tt_content.fe_group=\'-1\'))' - )); - $expected = 'SELECT * FROM "tt_content"'; - $expected .= ' WHERE "uid" IN (62) AND "tt_content"."deleted" = 0 AND "tt_content"."t3ver_state" <= 0'; - $expected .= ' AND "tt_content"."hidden" = 0 AND ("tt_content"."starttime" <= 1264487640)'; - $expected .= ' AND ("tt_content"."endtime" = 0 OR "tt_content"."endtime" > 1264487640)'; - $expected .= ' AND ("tt_content"."fe_group" = \'\' OR "tt_content"."fe_group" IS NULL OR "tt_content"."fe_group" = \'0\''; - $expected .= ' OR ((instr(LOWER("tt_content"."fe_group"), \',0,\',1,1) > 0)'; - $expected .= ' OR (instr(LOWER("tt_content"."fe_group"), \'0,\',1,1) > 0)'; - $expected .= ' OR (instr(LOWER("tt_content"."fe_group"), \',0\',1,1) > 0)'; - $expected .= ' OR "tt_content"."fe_group" = \'0\')'; - $expected .= ' OR ((instr(LOWER("tt_content"."fe_group"), \',-1,\',1,1) > 0)'; - $expected .= ' OR (instr(LOWER("tt_content"."fe_group"), \'-1,\',1,1) > 0)'; - $expected .= ' OR (instr(LOWER("tt_content"."fe_group"), \',-1\',1,1) > 0)'; - $expected .= ' OR "tt_content"."fe_group" = \'-1\'))'; - $this->assertEquals($expected, $select); - } - - /////////////////////////////////////// - // Tests concerning DB management - /////////////////////////////////////// - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12670 - */ - public function notNullableColumnsWithDefaultEmptyStringAreCreatedAsNullable() { - $parseString = ' - CREATE TABLE tx_realurl_uniqalias ( - uid int(11) NOT NULL auto_increment, - tstamp int(11) DEFAULT \'0\' NOT NULL, - tablename varchar(60) DEFAULT \'\' NOT NULL, - field_alias varchar(255) DEFAULT \'\' NOT NULL, - field_id varchar(60) DEFAULT \'\' NOT NULL, - value_alias varchar(255) DEFAULT \'\' NOT NULL, - value_id int(11) DEFAULT \'0\' NOT NULL, - lang int(11) DEFAULT \'0\' NOT NULL, - expire int(11) DEFAULT \'0\' NOT NULL, - - PRIMARY KEY (uid), - KEY tablename (tablename), - KEY bk_realurl01 (field_alias,field_id,value_id,lang,expire), - KEY bk_realurl02 (tablename,field_alias,field_id,value_alias(220),expire) - ); - '; - - $components = $GLOBALS['TYPO3_DB']->SQLparser->_callRef('parseCREATETABLE', $parseString); - $this->assertTrue(is_array($components), 'Not an array: ' . $components); - - $sqlCommands = $GLOBALS['TYPO3_DB']->SQLparser->_call('compileCREATETABLE', $components); - $this->assertTrue(is_array($sqlCommands), 'Not an array: ' . $sqlCommands); - $this->assertEquals(4, count($sqlCommands)); - - $expected = $this->cleanSql(' - CREATE TABLE "tx_realurl_uniqalias" ( - "uid" NUMBER(20) NOT NULL, - "tstamp" NUMBER(20) DEFAULT 0, - "tablename" VARCHAR(60) DEFAULT \'\', - "field_alias" VARCHAR(255) DEFAULT \'\', - "field_id" VARCHAR(60) DEFAULT \'\', - "value_alias" VARCHAR(255) DEFAULT \'\', - "value_id" NUMBER(20) DEFAULT 0, - "lang" NUMBER(20) DEFAULT 0, - "expire" NUMBER(20) DEFAULT 0, - PRIMARY KEY ("uid") - ) - '); - $this->assertEquals($expected, $this->cleanSql($sqlCommands[0])); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=11142 - * @see http://bugs.typo3.org/view.php?id=12670 - */ - public function defaultValueIsProperlyQuotedInCreateTable() { - $parseString = ' - CREATE TABLE tx_test ( - uid int(11) NOT NULL auto_increment, - lastname varchar(60) DEFAULT \'unknown\' NOT NULL, - firstname varchar(60) DEFAULT \'\' NOT NULL, - language varchar(2) NOT NULL, - tstamp int(11) DEFAULT \'0\' NOT NULL, - - PRIMARY KEY (uid), - KEY name (name) - ); - '; - - $components = $GLOBALS['TYPO3_DB']->SQLparser->_callRef('parseCREATETABLE', $parseString); - $this->assertTrue(is_array($components), 'Not an array: ' . $components); - - $sqlCommands = $GLOBALS['TYPO3_DB']->SQLparser->_call('compileCREATETABLE', $components); - $this->assertTrue(is_array($sqlCommands), 'Not an array: ' . $sqlCommands); - $this->assertEquals(2, count($sqlCommands)); - - $expected = $this->cleanSql(' - CREATE TABLE "tx_test" ( - "uid" NUMBER(20) NOT NULL, - "lastname" VARCHAR(60) DEFAULT \'unknown\', - "firstname" VARCHAR(60) DEFAULT \'\', - "language" VARCHAR(2) DEFAULT \'\', - "tstamp" NUMBER(20) DEFAULT 0, - PRIMARY KEY ("uid") - ) - '); - $this->assertEquals($expected, $this->cleanSql($sqlCommands[0])); - } - - /////////////////////////////////////// - // Tests concerning subqueries - /////////////////////////////////////// - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12758 - */ - public function inWhereClauseWithSubqueryIsProperlyQuoted() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'tx_crawler_queue', - 'process_id IN (SELECT process_id FROM tx_crawler_process WHERE active=0 AND deleted=0)' - )); - $expected = 'SELECT * FROM "tx_crawler_queue" WHERE "process_id" IN (SELECT "process_id" FROM "tx_crawler_process" WHERE "active" = 0 AND "deleted" = 0)'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12758 - */ - public function subqueryIsRemappedForInWhereClause() { - $selectFields = '*'; - $fromTables = 'tx_crawler_queue'; - $whereClause = 'process_id IN (SELECT process_id FROM tx_crawler_process WHERE active=0 AND deleted=0)'; - $groupBy = ''; - $orderBy = ''; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT * FROM "tx_crawler_queue" WHERE "process_id" IN (SELECT "ps_id" FROM "tx_crawler_ps" WHERE "is_active" = 0 AND "deleted" = 0)'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12800 - */ - public function cachingFrameworkQueryIsSupported() { - $currentTime = time(); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->DELETEquery( - 'cachingframework_cache_hash_tags', - 'identifier IN (' . - $GLOBALS['TYPO3_DB']->SELECTsubquery( - 'identifier', - 'cachingframework_cache_pages', - 'crdate + lifetime < ' . $currentTime . ' AND lifetime > 0' - ) . - ')' - )); - $expected = 'DELETE FROM "cachingframework_cache_hash_tags" WHERE "identifier" IN ('; - $expected .= 'SELECT "identifier" FROM "cachingframework_cache_pages" WHERE "crdate"+"lifetime" < ' . $currentTime . ' AND "lifetime" > 0'; - $expected .= ')'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12800 - */ - public function cachingFrameworkQueryIsRemapped() { - $currentTime = time(); - $table = 'cachingframework_cache_hash_tags'; - $where = 'identifier IN (' . - $GLOBALS['TYPO3_DB']->SELECTsubquery( - 'identifier', - 'cachingframework_cache_pages', - 'crdate + lifetime < ' . $currentTime . ' AND lifetime > 0' - ) . - ')'; - - // Perform remapping (as in method exec_DELETEquery) - if ($tableArray = $GLOBALS['TYPO3_DB']->_call('map_needMapping', $table)) { - // Where clause: - $whereParts = $GLOBALS['TYPO3_DB']->SQLparser->parseWhereClause($where); - $GLOBALS['TYPO3_DB']->_callRef('map_sqlParts', $whereParts, $tableArray[0]['table']); - $where = $GLOBALS['TYPO3_DB']->SQLparser->compileWhereClause($whereParts, FALSE); - - // Table name: - if ($GLOBALS['TYPO3_DB']->mapping[$table]['mapTableName']) { - $table = $GLOBALS['TYPO3_DB']->mapping[$table]['mapTableName']; - } - } - - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->DELETEquery($table, $where)); - $expected = 'DELETE FROM "cf_cache_hash_tags" WHERE "identifier" IN ('; - $expected .= 'SELECT "identifier" FROM "cf_cache_pages" WHERE "crdate"+"lifetime" < ' . $currentTime . ' AND "lifetime" > 0'; - $expected .= ')'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12758 - */ - public function existsWhereClauseIsProperlyQuoted() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'tx_crawler_process', - 'active = 0 AND NOT EXISTS (' . - $GLOBALS['TYPO3_DB']->SELECTsubquery( - '*', - 'tx_crawler_queue', - 'tx_crawler_queue.process_id = tx_crawler_process.process_id AND tx_crawler_queue.exec_time = 0)' - ) . - ')' - )); - $expected = 'SELECT * FROM "tx_crawler_process" WHERE "active" = 0 AND NOT EXISTS ('; - $expected .= 'SELECT * FROM "tx_crawler_queue" WHERE "tx_crawler_queue"."process_id" = "tx_crawler_process"."process_id" AND "tx_crawler_queue"."exec_time" = 0'; - $expected .= ')'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12758 - */ - public function subqueryIsRemappedForExistsWhereClause() { - $selectFields = '*'; - $fromTables = 'tx_crawler_process'; - $whereClause = 'active = 0 AND NOT EXISTS (' . - $GLOBALS['TYPO3_DB']->SELECTsubquery( - '*', - 'tx_crawler_queue', - 'tx_crawler_queue.process_id = tx_crawler_process.process_id AND tx_crawler_queue.exec_time = 0' - ) . - ')'; - $groupBy = ''; - $orderBy = ''; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT * FROM "tx_crawler_ps" WHERE "is_active" = 0 AND NOT EXISTS ('; - $expected .= 'SELECT * FROM "tx_crawler_queue" WHERE "tx_crawler_queue"."process_id" = "tx_crawler_ps"."ps_id" AND "tx_crawler_queue"."exec_time" = 0'; - $expected .= ')'; - $this->assertEquals($expected, $query); - } - - /////////////////////////////////////// - // Tests concerning advanced operators - /////////////////////////////////////// - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13135 - */ - public function caseStatementIsProperlyQuoted() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - 'process_id, CASE active' . - ' WHEN 1 THEN ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('one', 'tx_crawler_process') . - ' WHEN 2 THEN ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('two', 'tx_crawler_process') . - ' ELSE ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('out of range', 'tx_crawler_process') . - ' END AS number', - 'tx_crawler_process', - '1=1' - )); - $expected = 'SELECT "process_id", CASE "active" WHEN 1 THEN \'one\' WHEN 2 THEN \'two\' ELSE \'out of range\' END AS "number" FROM "tx_crawler_process" WHERE 1 = 1'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13135 - */ - public function caseStatementIsProperlyRemapped() { - $selectFields = 'process_id, CASE active' . - ' WHEN 1 THEN ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('one', 'tx_crawler_process') . - ' WHEN 2 THEN ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('two', 'tx_crawler_process') . - ' ELSE ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('out of range', 'tx_crawler_process') . - ' END AS number'; - $fromTables = 'tx_crawler_process'; - $whereClause = '1=1'; - $groupBy = ''; - $orderBy = ''; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT "ps_id", CASE "is_active" WHEN 1 THEN \'one\' WHEN 2 THEN \'two\' ELSE \'out of range\' END AS "number" '; - $expected .= 'FROM "tx_crawler_ps" WHERE 1 = 1'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13135 - */ - public function caseStatementWithExternalTableIsProperlyRemapped() { - $selectFields = 'process_id, CASE tt_news.uid' . - ' WHEN 1 THEN ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('one', 'tt_news') . - ' WHEN 2 THEN ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('two', 'tt_news') . - ' ELSE ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('out of range', 'tt_news') . - ' END AS number'; - $fromTables = 'tx_crawler_process, tt_news'; - $whereClause = '1=1'; - $groupBy = ''; - $orderBy = ''; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT "ps_id", CASE "ext_tt_news"."news_uid" WHEN 1 THEN \'one\' WHEN 2 THEN \'two\' ELSE \'out of range\' END AS "number" '; - $expected .= 'FROM "tx_crawler_ps", "ext_tt_news" WHERE 1 = 1'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13134 - */ - public function locateStatementIsProperlyQuoted() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*, CASE WHEN' . - ' LOCATE(' . $GLOBALS['TYPO3_DB']->fullQuoteStr('(fce)', 'tx_templavoila_tmplobj') . ', datastructure)>0 THEN 2' . - ' ELSE 1' . - ' END AS scope', - 'tx_templavoila_tmplobj', - '1=1' - )); - $expected = 'SELECT *, CASE WHEN INSTR("datastructure", \'(fce)\') > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13134 - */ - public function locateStatementWithPositionIsProperlyQuoted() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*, CASE WHEN' . - ' LOCATE(' . $GLOBALS['TYPO3_DB']->fullQuoteStr('(fce)', 'tx_templavoila_tmplobj') . ', datastructure, 4)>0 THEN 2' . - ' ELSE 1' . - ' END AS scope', - 'tx_templavoila_tmplobj', - '1=1' - )); - $expected = 'SELECT *, CASE WHEN INSTR("datastructure", \'(fce)\', 4) > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=6196 - */ - public function IfNullIsProperlyRemapped() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'tt_news_cat_mm', - 'IFNULL(tt_news_cat_mm.uid_foreign,0) IN (21,22)' - )); - $expected = 'SELECT * FROM "tt_news_cat_mm" WHERE NVL("tt_news_cat_mm"."uid_foreign", 0) IN (21,22)'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14985 - */ - public function findInSetIsProperlyRemapped() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'fe_users', - 'FIND_IN_SET(10, usergroup)' - )); - $expected = 'SELECT * FROM "fe_users" WHERE \',\'||"usergroup"||\',\' LIKE \'%,10,%\''; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14985 - */ - public function findInSetFieldIsProperlyRemapped() { - $selectFields = 'fe_group'; - $fromTables = 'tt_news'; - $whereClause = 'FIND_IN_SET(10, fe_group)'; - $groupBy = ''; - $orderBy = ''; - - $remappedParameters = $GLOBALS['TYPO3_DB']->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy); - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->_call('SELECTqueryFromArray', $remappedParameters)); - - $expected = 'SELECT "usergroup" FROM "ext_tt_news" WHERE \',\'||"ext_tt_news"."usergroup"||\',\' LIKE \'%,10,%\''; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14818 - */ - public function listQueryIsProperlyRemapped() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'fe_users', - $GLOBALS['TYPO3_DB']->listQuery('usergroup', 10, 'fe_users') - )); - $expected = 'SELECT * FROM "fe_users" WHERE \',\'||"usergroup"||\',\' LIKE \'%,10,%\''; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12535 - */ - public function likeBinaryOperatorIsRemoved() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'tt_content', - 'bodytext LIKE BINARY \'test\'' - )); - $expected = 'SELECT * FROM "tt_content" WHERE (dbms_lob.instr(LOWER("bodytext"), \'test\',1,1) > 0)'; - $this->assertEquals($expected, $query); - } -} - -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/tests/dbPostgresqlTest.php b/typo3/sysext/dbal/tests/dbPostgresqlTest.php deleted file mode 100644 index 5330b619db6da027e111b1c3262d13d5e7c29d97..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/tests/dbPostgresqlTest.php +++ /dev/null @@ -1,235 +0,0 @@ -<?php -/*************************************************************** - * Copyright notice - * - * (c) 2010 Xavier Perseguers <typo3@perseguers.ch> - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - - -require_once('BaseTestCase.php'); -require_once('FakeDbConnection.php'); - -/** - * Testcase for class ux_t3lib_db. Testing PostgreSQL database handling. - * - * $Id$ - * - * @author Xavier Perseguers <typo3@perseguers.ch> - * - * @package TYPO3 - * @subpackage dbal - */ -class dbPostgresqlTest extends BaseTestCase { - - /** - * @var t3lib_db - */ - protected $db; - - /** - * @var array - */ - protected $dbalConfig; - - /** - * Prepares the environment before running a test. - */ - public function setUp() { - // Backup DBAL configuration - $this->dbalConfig = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']; - // Backup database connection - $this->db = $GLOBALS['TYPO3_DB']; - // Reconfigure DBAL to use PostgreSQL - require('fixtures/postgresql.config.php'); - - $className = self::buildAccessibleProxy('ux_t3lib_db'); - $GLOBALS['TYPO3_DB'] = new $className; - $parserClassName = self::buildAccessibleProxy('ux_t3lib_sqlparser'); - $GLOBALS['TYPO3_DB']->SQLparser = new $parserClassName; - - $this->assertFalse($GLOBALS['TYPO3_DB']->isConnected()); - - // Initialize a fake PostgreSQL connection (using 'postgres7' as 'postgres' is remapped to it in AdoDB) - FakeDbConnection::connect($GLOBALS['TYPO3_DB'], 'postgres7'); - - $this->assertTrue($GLOBALS['TYPO3_DB']->isConnected()); - } - - /** - * Cleans up the environment after running a test. - */ - public function tearDown() { - // Clear DBAL-generated cache files - $GLOBALS['TYPO3_DB']->clearCachedFieldInfo(); - // Restore DBAL configuration - $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal'] = $this->dbalConfig; - // Restore DB connection - $GLOBALS['TYPO3_DB'] = $this->db; - } - - /** - * Cleans a SQL query. - * - * @param mixed $sql - * @return mixed (string or array) - */ - private function cleanSql($sql) { - if (!is_string($sql)) { - return $sql; - } - - $sql = str_replace("\n", ' ', $sql); - $sql = preg_replace('/\s+/', ' ', $sql); - return trim($sql); - } - - /** - * @test - */ - public function configurationIsUsingAdodbAndDriverPostgres() { - $configuration = $GLOBALS['TYPO3_DB']->conf['handlerCfg']; - $this->assertTrue(is_array($configuration) && count($configuration) > 0, 'No configuration found'); - $this->assertEquals('adodb', $configuration['_DEFAULT']['type']); - $this->assertTrue($GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres') !== FALSE, 'Not using postgres driver'); - } - - /** - * @test - */ - public function tablesWithMappingAreDetected() { - $tablesWithMapping = array_keys($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['mapping']); - - foreach ($GLOBALS['TYPO3_DB']->cache_fieldType as $table => $fieldTypes) { - $tableDef = $GLOBALS['TYPO3_DB']->_call('map_needMapping', $table); - - if (in_array($table, $tablesWithMapping)) { - self::assertTrue(is_array($tableDef), 'Table ' . $table . ' was expected to need mapping'); - } else { - self::assertFalse($tableDef, 'Table ' . $table . ' was not expected to need mapping'); - } - } - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=2367 - */ - public function limitIsProperlyRemapped() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'be_users', - '1=1', - '', - '', - '20' - )); - $expected = 'SELECT * FROM "be_users" WHERE 1 = 1 LIMIT 20'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=2367 - */ - public function limitWithSkipIsProperlyRemapped() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'be_users', - '1=1', - '', - '', - '20,40' - )); - $expected = 'SELECT * FROM "be_users" WHERE 1 = 1 LIMIT 40 OFFSET 20'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14985 - */ - public function findInSetIsProperlyRemapped() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'fe_users', - 'FIND_IN_SET(10, usergroup)' - )); - $expected = 'SELECT * FROM "fe_users" WHERE FIND_IN_SET(10, "usergroup") != 0'; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12535 - */ - public function likeBinaryOperatorIsRemappedToLike() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'tt_content', - 'bodytext LIKE BINARY \'test\'' - )); - $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" LIKE \'test\''; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12535 - */ - public function notLikeBinaryOperatorIsRemappedToNotLike() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'tt_content', - 'bodytext NOT LIKE BINARY \'test\'' - )); - $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" NOT LIKE \'test\''; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12535 - */ - public function likeOperatorIsRemappedToIlike() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'tt_content', - 'bodytext LIKE \'test\'' - )); - $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" ILIKE \'test\''; - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12535 - */ - public function notLikeOperatorIsRemappedToNotIlike() { - $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery( - '*', - 'tt_content', - 'bodytext NOT LIKE \'test\'' - )); - $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" NOT ILIKE \'test\''; - $this->assertEquals($expected, $query); - } -} - -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/tests/fixtures/mssql.config.php b/typo3/sysext/dbal/tests/fixtures/mssql.config.php deleted file mode 100644 index fc2b88200f9abd89002a64bb2e369a8d1292cf1e..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/tests/fixtures/mssql.config.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php -/** - * MS SQL configuration - * - * $Id: mssql.config.php 37022 2010-08-19 19:34:19Z xperseguers $ - * - * @author Xavier Perseguers <typo3@perseguers.ch> - * - * @package TYPO3 - * @subpackage dbal - */ -global $TYPO3_CONF_VARS; - -$TYPO3_CONF_VARS['EXTCONF']['dbal']['handlerCfg'] = array( - '_DEFAULT' => array( - 'type' => 'adodb', - 'config' => array( - 'driver' => 'mssql', - 'useNameQuote' => FALSE, - ), - ), -); - -$TYPO3_CONF_VARS['EXTCONF']['dbal']['mapping'] = array( - 'tx_templavoila_tmplobj' => array( - 'mapFieldNames' => array( - 'datastructure' => 'ds', - ), - ), - 'Members' => array( - 'mapFieldNames' => array( - 'pid' => '0', - 'cruser_id' => '1', - 'uid' => 'MemberID', - ), - ), -); - -$TYPO3_CONF_VARS['EXTCONF']['dbal']['table2handlerKeys'] = array(); -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/tests/fixtures/oci8.config.php b/typo3/sysext/dbal/tests/fixtures/oci8.config.php deleted file mode 100644 index 397246e42f5b58dbbf32f43348fa60e91d1a20f5..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/tests/fixtures/oci8.config.php +++ /dev/null @@ -1,85 +0,0 @@ -<?php -/** - * Oracle configuration - * - * $Id: oci8.config.php 37022 2010-08-19 19:34:19Z xperseguers $ - * - * @author Xavier Perseguers <typo3@perseguers.ch> - * - * @package TYPO3 - * @subpackage dbal - */ -global $TYPO3_CONF_VARS; - -$TYPO3_CONF_VARS['EXTCONF']['dbal']['handlerCfg'] = array( - '_DEFAULT' => array( - 'type' => 'adodb', - 'config' => array( - 'driver' => 'oci8', - ), - ), -); - -$TYPO3_CONF_VARS['EXTCONF']['dbal']['mapping'] = array( - 'cachingframework_cache_hash' => array( - 'mapTableName' => 'cf_cache_hash', - ), - 'cachingframework_cache_hash_tags' => array( - 'mapTableName' => 'cf_cache_hash_tags', - ), - 'cachingframework_cache_pages' => array( - 'mapTableName' => 'cf_cache_pages', - ), - 'cpg_categories' => array( - 'mapFieldNames' => array( - 'pid' => 'page_id', - ), - ), - 'pages' => array( - 'mapTableName' => 'my_pages', - 'mapFieldNames' => array( - 'uid' => 'page_uid', - ), - ), - 'tt_news' => array( - 'mapTableName' => 'ext_tt_news', - 'mapFieldNames' => array( - 'uid' => 'news_uid', - 'fe_group' => 'usergroup', - ), - ), - 'tt_news_cat' => array( - 'mapTableName' => 'ext_tt_news_cat', - 'mapFieldNames' => array( - 'uid' => 'cat_uid', - ), - ), - 'tt_news_cat_mm' => array( - 'mapTableName' => 'ext_tt_news_cat_mm', - 'mapFieldNames' => array( - 'uid_local' => 'local_uid', - ), - ), - 'tx_crawler_process' => array( - 'mapTableName' => 'tx_crawler_ps', - 'mapFieldNames' => array( - 'process_id' => 'ps_id', - 'active' => 'is_active', - ), - ), - 'tx_dam_file_tracking' => array( - 'mapFieldNames' => array( - 'file_name' => 'filename', - 'file_path' => 'path', - ), - ), - 'tx_dbal_debuglog' => array( - 'mapFieldNames' => array( - 'errorFlag' => 'errorflag', - ), - ), - 'tx_templavoila_datastructure' => array( - 'mapTableName' => 'tx_templavoila_ds', - ), -); -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/tests/fixtures/postgresql.config.php b/typo3/sysext/dbal/tests/fixtures/postgresql.config.php deleted file mode 100644 index 57f218f1d70c8c665a7dabb59dc3c088e239b6e0..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/tests/fixtures/postgresql.config.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php -/** - * PostgreSQL configuration - * - * $Id$ - * - * @author Xavier Perseguers <typo3@perseguers.ch> - * - * @package TYPO3 - * @subpackage dbal - */ -global $TYPO3_CONF_VARS; - -$TYPO3_CONF_VARS['EXTCONF']['dbal']['handlerCfg'] = array( - '_DEFAULT' => array( - 'type' => 'adodb', - 'config' => array( - 'driver' => 'postgres', - ), - ), -); -?> \ No newline at end of file diff --git a/typo3/sysext/dbal/tests/sqlParserGeneralTest.php b/typo3/sysext/dbal/tests/sqlParserGeneralTest.php deleted file mode 100644 index 13cd22165923ad91d4f867d2186520a2aafdc500..0000000000000000000000000000000000000000 --- a/typo3/sysext/dbal/tests/sqlParserGeneralTest.php +++ /dev/null @@ -1,807 +0,0 @@ -<?php -/*************************************************************** - * Copyright notice - * - * (c) 2009 Xavier Perseguers <typo3@perseguers.ch> - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - - -require_once('BaseTestCase.php'); - -/** - * Testcase for class ux_t3lib_sqlparser - * - * $Id$ - * - * @author Xavier Perseguers <typo3@perseguers.ch> - * - * @package TYPO3 - * @subpackage dbal - */ -class sqlParserGeneralTest extends BaseTestCase { - - /** - * @var ux_t3lib_sqlparser (extended to make protected methods public) - */ - protected $fixture; - - /** - * Prepares the environment before running a test. - */ - public function setUp() { - $className = self::buildAccessibleProxy('ux_t3lib_sqlparser'); - $this->fixture = new $className; - } - - /** - * Cleans up the environment after running a test. - */ - public function tearDown() { - unset($this->fixture); - } - - /** - * Cleans a SQL query. - * - * @param mixed $sql - * @return mixed (string or array) - */ - private function cleanSql($sql) { - if (!is_string($sql)) { - return $sql; - } - - $sql = str_replace("\n", ' ', $sql); - $sql = preg_replace('/\s+/', ' ', $sql); - return trim($sql); - } - - /** - * @test - */ - public function canExtractPartsOfAQuery() { - $parseString = "SELECT *\nFROM pages WHERE pid IN (1,2,3,4)"; - $regex = '^SELECT[[:space:]]+(.*)[[:space:]]+'; - $trimAll = TRUE; - $fields = $this->fixture->_callRef('nextPart', $parseString, $regex, $trimAll); - - $this->assertEquals( - '*', - $fields - ); - $this->assertEquals( - 'FROM pages WHERE pid IN (1,2,3,4)', - $parseString - ); - - $regex = '^FROM ([^)]+) WHERE'; - $table = $this->fixture->_callRef('nextPart', $parseString, $regex); - - $this->assertEquals( - 'pages', - $table - ); - $this->assertEquals( - 'pages WHERE pid IN (1,2,3,4)', - $parseString - ); - } - - /** - * @test - */ - public function canGetIntegerValue() { - $parseString = '1024'; - $value = $this->fixture->_callRef('getValue', $parseString); - $expected = array(1024); - - $this->assertEquals($expected, $value); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13104 - */ - public function canGetStringValue() { - $parseString = '"some owner\\\'s string"'; - $value = $this->fixture->_callRef('getValue', $parseString); - $expected = array('some owner\'s string', '"'); - - $this->assertEquals($expected, $value); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13104 - */ - public function canGetStringValueWithSingleQuote() { - $parseString = "'some owner\'s string'"; - $value = $this->fixture->_callRef('getValue', $parseString); - $expected = array('some owner\'s string', "'"); - - $this->assertEquals($expected, $value); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13104 - */ - public function canGetStringValueWithDoubleQuote() { - $parseString = '"the \"owner\" is here"'; - $value = $this->fixture->_callRef('getValue', $parseString); - $expected = array('the "owner" is here', '"'); - - $this->assertEquals($expected, $value); - } - - /** - * @test - */ - public function canGetListOfValues() { - $parseString = '( 1, 2, 3 ,4)'; - $operator = 'IN'; - $values = $this->fixture->_callRef('getValue', $parseString, $operator); - $expected = array( - array(1), - array(2), - array(3), - array(4) - ); - - $this->assertEquals($expected, $values); - } - - /** - * @test - */ - public function parseWhereClauseReturnsArray() { - $parseString = 'uid IN (1,2) AND (starttime < ' . time() . ' OR cruser_id + 10 < 20)'; - $where = $this->fixture->parseWhereClause($parseString); - - $this->assertTrue(is_array($where), $where); - $this->assertTrue(empty($parseString), 'parseString is not empty'); - } - - /** - * @test - */ - public function canSelectAllFieldsFromPages() { - $sql = 'SELECT * FROM pages'; - $expected = $sql; - $actual = $this->cleanSql($this->fixture->debug_testSQL($sql)); - - $this->assertEquals($expected, $actual); - } - - /** - * @test - * http://bugs.typo3.org/view.php?id=13504 - */ - public function canParseTruncateTable() { - $sql = 'TRUNCATE TABLE be_users'; - $expected = $sql; - $actual = $this->cleanSql($this->fixture->debug_testSQL($sql)); - - $this->assertEquals($expected, $actual); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13412 - */ - public function canParseAndCompileBetweenOperator() { - $parseString = '((scheduled BETWEEN 1265068628 AND 1265068828 ) OR scheduled <= 1265068728) AND NOT exec_time AND NOT process_id AND page_id=1 AND parameters_hash = \'854e9a2a77\''; - $where = $this->fixture->parseWhereClause($parseString); - - $this->assertTrue(is_array($where), $where); - $this->assertTrue(empty($parseString), 'parseString is not empty'); - - $whereClause = $this->cleanSql($this->fixture->compileWhereClause($where)); - $expected = '((scheduled BETWEEN 1265068628 AND 1265068828) OR scheduled <= 1265068728) AND NOT exec_time AND NOT process_id AND page_id = 1 AND parameters_hash = \'854e9a2a77\''; - $this->assertEquals($expected, $whereClause); - } - - /** - * @test - * http://bugs.typo3.org/view.php?id=13430 - */ - public function canParseInsertWithoutSpaceAfterValues() { - $parseString = "INSERT INTO static_country_zones VALUES('483', '0', 'NL', 'NLD', '528', 'DR', 'Drenthe', '');"; - $components = $this->fixture->_callRef('parseINSERT', $parseString); - - $this->assertTrue(is_array($components), $components); - $insert = $this->cleanSql($this->fixture->_callRef('compileINSERT', $components)); - $expected = "INSERT INTO static_country_zones VALUES ('483', '0', 'NL', 'NLD', '528', 'DR', 'Drenthe', '')"; - $this->assertEquals($expected, $insert); - } - - /** - * @test - * http://bugs.typo3.org/view.php?id=13430 - */ - public function canParseInsertWithSpaceAfterValues() { - $parseString = "INSERT INTO static_country_zones VALUES ('483', '0', 'NL', 'NLD', '528', 'DR', 'Drenthe', '');"; - $components = $this->fixture->_callRef('parseINSERT', $parseString); - - $this->assertTrue(is_array($components), $components); - $insert = $this->cleanSql($this->fixture->_callRef('compileINSERT', $components)); - $expected = "INSERT INTO static_country_zones VALUES ('483', '0', 'NL', 'NLD', '528', 'DR', 'Drenthe', '')"; - $this->assertEquals($expected, $insert); - } - - /** - * @test - */ - public function canParseInsertWithFields() { - $parseString = 'INSERT INTO static_territories (uid, pid, tr_iso_nr, tr_parent_iso_nr, tr_name_en) '; - $parseString .= "VALUES ('1', '0', '2', '0', 'Africa');"; - $components = $this->fixture->_callRef('parseINSERT', $parseString); - - $this->assertTrue(is_array($components), $components); - $insert = $this->cleanSql($this->fixture->_callRef('compileINSERT', $components)); - $expected = 'INSERT INTO static_territories (uid, pid, tr_iso_nr, tr_parent_iso_nr, tr_name_en) '; - $expected .= "VALUES ('1', '0', '2', '0', 'Africa')"; - $this->assertEquals($expected, $insert); - } - - /** - * @test - * http://bugs.typo3.org/view.php?id=13209 - */ - public function canParseExtendedInsert() { - $parseString = "INSERT INTO static_territories VALUES ('1', '0', '2', '0', 'Africa'),('2', '0', '9', '0', 'Oceania')," . - "('3', '0', '19', '0', 'Americas'),('4', '0', '142', '0', 'Asia');"; - $components = $this->fixture->_callRef('parseINSERT', $parseString); - - $this->assertTrue(is_array($components), $components); - $insert = $this->cleanSql($this->fixture->_callRef('compileINSERT', $components)); - $expected = "INSERT INTO static_territories VALUES ('1', '0', '2', '0', 'Africa'), ('2', '0', '9', '0', 'Oceania'), " . - "('3', '0', '19', '0', 'Americas'), ('4', '0', '142', '0', 'Asia')"; - $this->assertEquals($expected, $insert); - } - - /** - * @test - * http://bugs.typo3.org/view.php?id=13209 - */ - public function canParseExtendedInsertWithFields() { - $parseString = 'INSERT INTO static_territories (uid, pid, tr_iso_nr, tr_parent_iso_nr, tr_name_en) '; - $parseString .= "VALUES ('1', '0', '2', '0', 'Africa'),('2', '0', '9', '0', 'Oceania');"; - $components = $this->fixture->_callRef('parseINSERT', $parseString); - - $this->assertTrue(is_array($components), $components); - $insert = $this->cleanSql($this->fixture->_callRef('compileINSERT', $components)); - $expected = 'INSERT INTO static_territories (uid, pid, tr_iso_nr, tr_parent_iso_nr, tr_name_en) '; - $expected .= "VALUES ('1', '0', '2', '0', 'Africa'), ('2', '0', '9', '0', 'Oceania')"; - $this->assertEquals($expected, $insert); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=6196 - */ - public function canParseIfNullOperator() { - $parseString = 'IFNULL(tt_news_cat_mm.uid_foreign,0) IN (21,22)'; - $whereParts = $this->fixture->parseWhereClause($parseString); - - $this->assertTrue(is_array($whereParts), $whereParts); - $this->assertTrue(empty($parseString), 'parseString is not empty'); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=6196 - */ - public function canParseIfNullOperatorWithAdditionalClauses() { - $parseString = '1=1 AND IFNULL(tt_news_cat_mm.uid_foreign,0) IN (21,22) AND tt_news.sys_language_uid IN (0,-1) '; - $parseString .= 'AND tt_news.pid > 0 AND tt_news.pid IN (61) AND tt_news.deleted=0 AND tt_news.t3ver_state<=0 '; - $parseString .= 'AND tt_news.hidden=0 AND tt_news.starttime<=1266065460 AND (tt_news.endtime=0 OR tt_news.endtime>1266065460) '; - $parseString .= 'AND (tt_news.fe_group=\'\' OR tt_news.fe_group IS NULL OR tt_news.fe_group=\'0\' '; - $parseString .= 'OR (tt_news.fe_group LIKE \'%,0,%\' OR tt_news.fe_group LIKE \'0,%\' OR tt_news.fe_group LIKE \'%,0\' '; - $parseString .= 'OR tt_news.fe_group=\'0\') OR (tt_news.fe_group LIKE \'%,-1,%\' OR tt_news.fe_group LIKE \'-1,%\' '; - $parseString .= 'OR tt_news.fe_group LIKE \'%,-1\' OR tt_news.fe_group=\'-1\'))'; - $whereParts = $this->fixture->parseWhereClause($parseString); - - $this->assertTrue(is_array($whereParts), $whereParts); - $this->assertTrue(empty($parseString), 'parseString is not empty'); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=6196 - */ - public function canCompileIfNullOperator() { - $parseString = 'SELECT * FROM tx_irfaq_q_cat_mm WHERE IFNULL(tx_irfaq_q_cat_mm.uid_foreign,0) = 1'; - $components = $this->fixture->_callRef('parseSELECT', $parseString); - - $this->assertTrue(is_array($components), $components); - $select = $this->cleanSql($this->fixture->_callRef('compileSELECT', $components)); - $expected = 'SELECT * FROM tx_irfaq_q_cat_mm WHERE IFNULL(tx_irfaq_q_cat_mm.uid_foreign, 0) = 1'; - $this->assertEquals($expected, $select); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14456 - */ - public function canParseAlterEngineStatement() { - $parseString = 'ALTER TABLE tx_realurl_pathcache ENGINE=InnoDB'; - $components = $this->fixture->_callRef('parseALTERTABLE', $parseString); - - $this->assertTrue(is_array($components), $components); - $alterTable = $this->cleanSql($this->fixture->_callRef('compileALTERTABLE', $components)); - $expected = 'ALTER TABLE tx_realurl_pathcache ENGINE = InnoDB'; - $this->assertTrue(is_array($alterTable), $alterTable); - $this->assertEquals($expected, $alterTable[0]); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14496 - */ - public function canParseAlterCharacterSetStatement() { - $parseString = 'ALTER TABLE `index_phash` DEFAULT CHARACTER SET utf8'; - $components = $this->fixture->_callRef('parseALTERTABLE', $parseString); - - $this->assertTrue(is_array($components), $components); - $alterTable = $this->cleanSql($this->fixture->_callRef('compileALTERTABLE', $components)); - $expected = 'ALTER TABLE index_phash DEFAULT CHARACTER SET utf8'; - $this->assertTrue(is_array($alterTable), $alterTable); - $this->assertEquals($expected, $alterTable[0]); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14985 - */ - public function canParseFindInSetStatement() { - $parseString = 'SELECT * FROM fe_users WHERE FIND_IN_SET(10, usergroup)'; - $components = $this->fixture->_callRef('parseSELECT', $parseString); - - $this->assertTrue(is_array($components), $components); - $selectTable = $this->cleanSql($this->fixture->_callRef('compileSELECT', $components)); - $expected = 'SELECT * FROM fe_users WHERE FIND_IN_SET(10, usergroup)'; - $this->assertEquals($expected, $selectTable); - } - - /////////////////////////////////////// - // Tests concerning JOINs - /////////////////////////////////////// - - /** - * @test - */ - public function parseFromTablesWithInnerJoinReturnsArray() { - $parseString = 'be_users INNER JOIN pages ON pages.cruser_id = be_users.uid'; - $tables = $this->fixture->parseFromTables($parseString); - - $this->assertTrue(is_array($tables), $tables); - $this->assertTrue(empty($parseString), 'parseString is not empty'); - } - - /** - * @test - */ - public function parseFromTablesWithLeftOuterJoinReturnsArray() { - $parseString = 'be_users LEFT OUTER JOIN pages ON be_users.uid = pages.cruser_id'; - $tables = $this->fixture->parseFromTables($parseString); - - $this->assertTrue(is_array($tables), $tables); - $this->assertTrue(empty($parseString), 'parseString is not empty'); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12596 - */ - public function parseFromTablesWithRightOuterJoinReturnsArray() { - $parseString = 'tx_powermail_fieldsets RIGHT JOIN tt_content ON tx_powermail_fieldsets.tt_content = tt_content.uid'; - $tables = $this->fixture->parseFromTables($parseString); - - $this->assertTrue(is_array($tables), $tables); - $this->assertTrue(empty($parseString), 'parseString is not empty'); - } - - /** - * @test - */ - public function parseFromTablesWithMultipleJoinsReturnsArray() { - $parseString = 'be_users LEFT OUTER JOIN pages ON be_users.uid = pages.cruser_id INNER JOIN cache_pages cp ON cp.page_id = pages.uid'; - $tables = $this->fixture->parseFromTables($parseString); - - $this->assertTrue(is_array($tables), $tables); - $this->assertTrue(empty($parseString), 'parseString is not empty'); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12596 - */ - public function parseFromTablesWithMultipleJoinsAndParenthesesReturnsArray() { - $parseString = 'tx_powermail_fieldsets RIGHT JOIN tt_content ON tx_powermail_fieldsets.tt_content = tt_content.uid LEFT JOIN tx_powermail_fields ON tx_powermail_fieldsets.uid = tx_powermail_fields.fieldset'; - $tables = $this->fixture->parseFromTables($parseString); - - $this->assertTrue(is_array($tables), $tables); - $this->assertTrue(empty($parseString), 'parseString is not empty'); - } - - /** - * @test - */ - public function canUseInnerJoinInSelect() { - $sql = 'SELECT pages.uid, be_users.username FROM be_users INNER JOIN pages ON pages.cruser_id = be_users.uid'; - $expected = 'SELECT pages.uid, be_users.username FROM be_users INNER JOIN pages ON pages.cruser_id=be_users.uid'; - $actual = $this->cleanSql($this->fixture->debug_testSQL($sql)); - - $this->assertEquals($expected, $actual); - } - - /** - * @test - */ - public function canUseMultipleInnerJoinsInSelect() { - $sql = 'SELECT * FROM tt_news_cat INNER JOIN tt_news_cat_mm ON tt_news_cat.uid = tt_news_cat_mm.uid_foreign INNER JOIN tt_news ON tt_news.uid = tt_news_cat_mm.uid_local'; - $expected = 'SELECT * FROM tt_news_cat INNER JOIN tt_news_cat_mm ON tt_news_cat.uid=tt_news_cat_mm.uid_foreign INNER JOIN tt_news ON tt_news.uid=tt_news_cat_mm.uid_local'; - $actual = $this->cleanSql($this->fixture->debug_testSQL($sql)); - - $this->assertEquals($expected, $actual); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14182 - */ - public function canParseMultipleJoinConditions() { - $sql = 'SELECT * FROM T1 LEFT OUTER JOIN T2 ON T2.pid = T1.uid AND T2.size = 4 WHERE T1.cr_userid = 1'; - $expected = 'SELECT * FROM T1 LEFT OUTER JOIN T2 ON T2.pid=T1.uid AND T2.size=4 WHERE T1.cr_userid = 1'; - $actual = $this->cleanSql($this->fixture->debug_testSQL($sql)); - - $this->assertEquals($expected, $actual); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=14182 - */ - public function canParseMultipleJoinConditionsWithLessThanOperator() { - $sql = 'SELECT * FROM T1 LEFT OUTER JOIN T2 ON T2.size < 4 OR T2.pid = T1.uid WHERE T1.cr_userid = 1'; - $expected = 'SELECT * FROM T1 LEFT OUTER JOIN T2 ON T2.size<4 OR T2.pid=T1.uid WHERE T1.cr_userid = 1'; - $actual = $this->cleanSql($this->fixture->debug_testSQL($sql)); - - $this->assertEquals($expected, $actual); - } - - /////////////////////////////////////// - // Tests concerning DB management - /////////////////////////////////////// - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=4466 - */ - public function indexMayContainALengthRestrictionInCreateTable() { - $parseString = ' - CREATE TABLE tx_realurl_uniqalias ( - uid int(11) NOT NULL auto_increment, - tstamp int(11) DEFAULT \'0\' NOT NULL, - tablename varchar(60) DEFAULT \'\' NOT NULL, - field_alias varchar(255) DEFAULT \'\' NOT NULL, - field_id varchar(60) DEFAULT \'\' NOT NULL, - value_alias varchar(255) DEFAULT \'\' NOT NULL, - value_id int(11) DEFAULT \'0\' NOT NULL, - lang int(11) DEFAULT \'0\' NOT NULL, - expire int(11) DEFAULT \'0\' NOT NULL, - - PRIMARY KEY (uid), - KEY tablename (tablename), - KEY bk_realurl01 (field_alias,field_id,value_id,lang,expire), - KEY bk_realurl02 (tablename,field_alias,field_id,value_alias(220),expire) - ); - '; - - $createTables = $this->fixture->_callRef('parseCREATETABLE', $parseString); - $this->assertTrue(is_array($createTables), $createTables); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=16501 - */ - public function indexMayBeCreatedOnMultipleColumns() { - $sql = ' - CREATE TABLE sys_registry ( - uid int(11) unsigned NOT NULL auto_increment, - entry_namespace varchar(128) DEFAULT \'\' NOT NULL, - entry_key varchar(128) DEFAULT \'\' NOT NULL, - entry_value blob, - PRIMARY KEY (uid), - UNIQUE KEY entry_identifier (entry_namespace,entry_key) - ) - '; - $parseString = $sql; - - $createTables = $this->fixture->_callRef('parseCREATETABLE', $parseString); - $this->assertTrue(is_array($createTables), $createTables); - - $actual = $this->fixture->_callRef('compileCREATETABLE', $createTables); - $this->assertEquals($this->cleanSql($sql), $this->cleanSql($actual[0])); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12829 - */ - public function indexMayContainALengthRestrictionInAlterTable() { - $parseString = 'ALTER TABLE tx_realurl_uniqalias ADD KEY bk_realurl02 (tablename,field_alias,field_id,value_alias(220),expire)'; - $alterTables = $this->fixture->_callRef('parseALTERTABLE', $parseString); - $this->assertTrue(is_array($alterTables), $alterTables); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=2186 - */ - public function canParseUniqueIndexCreation() { - $sql = 'ALTER TABLE static_territories ADD UNIQUE uid (uid)'; - $expected = $sql; - $alterTables = $this->fixture->_callRef('parseALTERTABLE', $sql); - $queries = $this->fixture->compileSQL($alterTables); - - $this->assertTrue(is_array($queries), $queries); - $this->assertTrue(count($queries) == 1, $queries); - $this->assertEquals($expected, $queries[0]); - } - - /////////////////////////////////////// - // Tests concerning subqueries - /////////////////////////////////////// - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12758 - */ - public function inWhereClauseSupportsSubquery() { - $parseString = 'process_id IN (SELECT process_id FROM tx_crawler_process WHERE active=0 AND deleted=0)'; - $whereParts = $this->fixture->parseWhereClause($parseString); - - $this->assertTrue(is_array($whereParts), $whereParts); - $this->assertTrue(empty($parseString), 'parseString is not empty'); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12758 - */ - public function inWhereClauseWithSubqueryIsProperlyCompiled() { - $sql = 'SELECT * FROM tx_crawler_queue WHERE process_id IN (SELECT process_id FROM tx_crawler_process WHERE active=0 AND deleted=0)'; - $expected = 'SELECT * FROM tx_crawler_queue WHERE process_id IN (SELECT process_id FROM tx_crawler_process WHERE active = 0 AND deleted = 0)'; - $actual = $this->cleanSql($this->fixture->debug_testSQL($sql)); - - $this->assertEquals($expected, $actual); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12758 - */ - public function whereClauseSupportsExistsKeyword() { - $parseString = 'EXISTS (SELECT * FROM tx_crawler_queue WHERE tx_crawler_queue.process_id = tx_crawler_process.process_id AND tx_crawler_queue.exec_time = 0)'; - $whereParts = $this->fixture->parseWhereClause($parseString); - - $this->assertTrue(is_array($whereParts), $whereParts); - $this->assertTrue(empty($parseString), 'parseString is not empty'); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=12758 - */ - public function existsClauseIsProperlyCompiled() { - $sql = 'SELECT * FROM tx_crawler_process WHERE active = 0 AND NOT EXISTS (SELECT * FROM tx_crawler_queue WHERE tx_crawler_queue.process_id = tx_crawler_process.process_id AND tx_crawler_queue.exec_time = 0)'; - $expected = 'SELECT * FROM tx_crawler_process WHERE active = 0 AND NOT EXISTS (SELECT * FROM tx_crawler_queue WHERE tx_crawler_queue.process_id = tx_crawler_process.process_id AND tx_crawler_queue.exec_time = 0)'; - $actual = $this->cleanSql($this->fixture->debug_testSQL($sql)); - - $this->assertEquals($expected, $actual); - } - - /////////////////////////////////////// - // Tests concerning advanced operators - /////////////////////////////////////// - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13135 - */ - public function caseWithBooleanConditionIsSupportedInFields() { - $parseString = 'CASE WHEN 1>0 THEN 2 ELSE 1 END AS foo, other_column'; - $fieldList = $this->fixture->parseFieldList($parseString); - - $this->assertTrue(is_array($fieldList), $fieldList); - $this->assertTrue(empty($parseString), 'parseString is not empty'); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13135 - */ - public function caseWithBooleanConditionIsProperlyCompiled() { - $sql = 'SELECT CASE WHEN 1>0 THEN 2 ELSE 1 END AS foo, other_column FROM mytable'; - $expected = 'SELECT CASE WHEN 1 > 0 THEN 2 ELSE 1 END AS foo, other_column FROM mytable'; - $actual = $this->cleanSql($this->fixture->debug_testSQL($sql)); - - $this->assertEquals($expected, $actual); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13135 - */ - public function caseWithMultipleWhenIsSupportedInFields() { - $parseString = 'CASE column WHEN 1 THEN \'one\' WHEN 2 THEN \'two\' ELSE \'out of range\' END AS number'; - $fieldList = $this->fixture->parseFieldList($parseString); - - $this->assertTrue(is_array($fieldList), $fieldList); - $this->assertTrue(empty($parseString), 'parseString is not empty'); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13135 - */ - public function caseWithMultipleWhenIsProperlyCompiled() { - $sql = 'SELECT CASE column WHEN 1 THEN \'one\' WHEN 2 THEN \'two\' ELSE \'out of range\' END AS number FROM mytable'; - $expected = 'SELECT CASE column WHEN 1 THEN \'one\' WHEN 2 THEN \'two\' ELSE \'out of range\' END AS number FROM mytable'; - $actual = $this->cleanSql($this->fixture->debug_testSQL($sql)); - - $this->assertEquals($expected, $actual); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13134 - */ - public function locateIsSupported() { - $sql = 'SELECT * FROM tx_templavoila_tmplobj WHERE LOCATE(\'(fce)\', datastructure)>0'; - $expected = 'SELECT * FROM tx_templavoila_tmplobj WHERE LOCATE(\'(fce)\', datastructure) > 0'; - $actual = $this->cleanSql($this->fixture->debug_testSQL($sql)); - - $this->assertEquals($expected, $actual); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13134 - */ - public function locateWithPositionIsSupported() { - $sql = 'SELECT * FROM tx_templavoila_tmplobj WHERE LOCATE(\'(fce)\' , datastructure ,10)>0'; - $expected = 'SELECT * FROM tx_templavoila_tmplobj WHERE LOCATE(\'(fce)\', datastructure, 10) > 0'; - $actual = $this->cleanSql($this->fixture->debug_testSQL($sql)); - - $this->assertEquals($expected, $actual); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=13134 - * @see http://bugs.typo3.org/view.php?id=13135 - */ - public function locateWithinCaseIsSupported() { - $sql = 'SELECT *, CASE WHEN LOCATE(\'(fce)\', datastructure)>0 THEN 2 ELSE 1 END AS scope FROM tx_templavoila_tmplobj'; - $expected = 'SELECT *, CASE WHEN LOCATE(\'(fce)\', datastructure) > 0 THEN 2 ELSE 1 END AS scope FROM tx_templavoila_tmplobj'; - $actual = $this->cleanSql($this->fixture->debug_testSQL($sql)); - - $this->assertEquals($expected, $actual); - } - - /////////////////////////////////////// - // Tests concerning prepared queries - /////////////////////////////////////// - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=15457 - */ - public function namedPlaceholderIsSupported() { - $sql = 'SELECT * FROM pages WHERE pid = :pid ORDER BY title'; - $expected = 'SELECT * FROM pages WHERE pid = :pid ORDER BY title'; - $actual = $this->cleanSql($this->fixture->debug_testSQL($sql)); - - $this->assertEquals($expected, $actual); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=15457 - */ - public function questionMarkPlaceholderIsSupported() { - $sql = 'SELECT * FROM pages WHERE pid = ? ORDER BY title'; - $expected = 'SELECT * FROM pages WHERE pid = ? ORDER BY title'; - $actual = $this->cleanSql($this->fixture->debug_testSQL($sql)); - - $this->assertEquals($expected, $actual); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=15457 - */ - public function parametersAreReferenced() { - $sql = 'SELECT * FROM pages WHERE pid = :pid1 OR pid = :pid2'; - $components = $this->fixture->_callRef('parseSELECT', $sql); - - $this->assertTrue(is_array($components['parameters']), 'References to parameters not found'); - $this->assertEquals(2, count($components['parameters'])); - $this->assertTrue(is_array($components['parameters']), 'References to parameters not found'); - $this->assertTrue(isset($components['parameters'][':pid1'])); - $this->assertTrue(isset($components['parameters'][':pid2'])); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=15457 - */ - public function sameParameterIsReferencedInSubquery() { - $sql = 'SELECT * FROM pages WHERE uid = :pageId OR uid IN (SELECT uid FROM pages WHERE pid = :pageId)'; - $pageId = 12; - - $components = $this->fixture->_callRef('parseSELECT', $sql); - $components['parameters'][':pageId'][0] = $pageId; - $query = $this->cleanSql($this->fixture->_callRef('compileSELECT', $components)); - $expected = 'SELECT * FROM pages WHERE uid = 12 OR uid IN (SELECT uid FROM pages WHERE pid = 12)'; - - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=15457 - */ - public function namedParametersMayBeSafelyReplaced() { - $sql = 'SELECT * FROM pages WHERE pid = :pid AND title NOT LIKE \':pid\''; - $pid = 12; - - $components = $this->fixture->_callRef('parseSELECT', $sql); - $components['parameters'][':pid'][0] = $pid; - $query = $this->cleanSql($this->fixture->_callRef('compileSELECT', $components)); - $expected = 'SELECT * FROM pages WHERE pid = ' . $pid . ' AND title NOT LIKE \':pid\''; - - $this->assertEquals($expected, $query); - } - - /** - * @test - * @see http://bugs.typo3.org/view.php?id=15457 - */ - public function questionMarkParametersMayBeSafelyReplaced() { - $sql = 'SELECT * FROM pages WHERE pid = ? AND timestamp < ? AND title != \'How to test?\''; - $parameterValues = array(12, 1281782690); - - $components = $this->fixture->_callRef('parseSELECT', $sql); - for ($i = 0; $i < count($components['parameters']['?']); $i++) { - $components['parameters']['?'][$i][0] = $parameterValues[$i]; - } - $query = $this->cleanSql($this->fixture->_callRef('compileSELECT', $components)); - $expected = 'SELECT * FROM pages WHERE pid = 12 AND timestamp < 1281782690 AND title != \'How to test?\''; - - $this->assertEquals($expected, $query); - } -} - -?> \ No newline at end of file