Raised DBAL version from 1.1.1 to 1.1.2
authorXavier Perseguers <typo3@perseguers.ch>
Tue, 13 Apr 2010 22:44:31 +0000 (22:44 +0000)
committerXavier Perseguers <typo3@perseguers.ch>
Tue, 13 Apr 2010 22:44:31 +0000 (22:44 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@7355 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/dbal/ChangeLog
typo3/sysext/dbal/class.ux_db_list_extra.php [changed mode: 0755->0644]
typo3/sysext/dbal/class.ux_t3lib_db.php
typo3/sysext/dbal/ext_emconf.php
typo3/sysext/dbal/last_synched_target
typo3/sysext/dbal/mod1/index.php
typo3/sysext/dbal/tests/db_postgresql_testcase.php [new file with mode: 0644]
typo3/sysext/dbal/tests/fixtures/mssql.config.php
typo3/sysext/dbal/tests/fixtures/postgresql.config.php [new file with mode: 0644]

index f8e21f7..36a939c 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-04-14  Xavier Perseguers  <typo3@perseguers.ch>
+
+       * Raised DBAL version from 1.1.1 to 1.1.2
+
 2010-04-13  Ernesto Baschny  <ernst@cron-it.de>
 
        * Added feature #13998: Introduce automatic versioning of CSS and JS files (thanks to Lars Houmark)
index e85d57b..df1f3b1 100644 (file)
@@ -1,3 +1,19 @@
+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-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
old mode 100755 (executable)
new mode 100644 (file)
index d03e22c..1af1f68 100644 (file)
@@ -1088,6 +1088,18 @@ class ux_t3lib_DB extends t3lib_DB {
         * @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);
@@ -1660,12 +1672,22 @@ class ux_t3lib_DB extends t3lib_DB {
 
                                                // 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)) {
-                                               foreach ($output as $key => $value) {
-                                                       if (is_integer($key)) {
-                                                               unset($output[$key]);
+                                               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]);
+                                                               }
                                                        }
-                                                       elseif ($value === ' ' && $this->runningADOdbDriver('mssql')) $output[$key] = ''; // MSSQL does not know such thing as an empty string. So it returns one space instead, which we must fix.
                                                }
                                        }
                                }
@@ -1709,10 +1731,20 @@ class ux_t3lib_DB extends t3lib_DB {
 
                                                // 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) {
-                                                       if (!is_integer($key))  unset($output[$key]);
-                                                       elseif ($value === ' ' && $this->runningADOdbDriver('mssql')) $output[$key] = ''; // MSSQL does not know such thing as an empty string. So it returns one space instead, which we must fix.
+                                                       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++;
+                                                       }
                                                }
                                        }
                                }
index 4523afb..f6edfa1 100644 (file)
@@ -3,7 +3,7 @@
 ########################################################################
 # Extension Manager/Repository config file for ext "dbal".
 #
-# Auto generated 14-02-2010 18:58
+# Auto generated 14-04-2010 00:05
 #
 # Manual updates:
 # Only the data in the array - everything else is removed by next
@@ -32,13 +32,13 @@ $EM_CONF[$_EXTKEY] = array(
        'author_company' => '',
        'CGLcompliance' => '',
        'CGLcompliance_note' => '',
-       'version' => '1.1.1',
-       '_md5_values_when_last_written' => 'a:37:{s:9:"ChangeLog";s:4:"3ce2";s:26:"class.ux_db_list_extra.php";s:4:"7b9e";s:21:"class.ux_t3lib_db.php";s:4:"95c8";s:28:"class.ux_t3lib_sqlparser.php";s:4:"a9d4";s:16:"ext_autoload.php";s:4:"821a";s:21:"ext_conf_template.txt";s:4:"f5cf";s:12:"ext_icon.gif";s:4:"c9ba";s:17:"ext_localconf.php";s:4:"5280";s:14:"ext_tables.php";s:4:"8414";s:14:"ext_tables.sql";s:4:"1f95";s:27:"doc/class.tslib_fe.php.diff";s:4:"0083";s:14:"doc/manual.sxw";s:4:"b022";s:45:"handlers/class.tx_dbal_handler_openoffice.php";s:4:"775f";s:43:"handlers/class.tx_dbal_handler_rawmysql.php";s:4:"2f1b";s:40:"handlers/class.tx_dbal_handler_xmldb.php";s:4:"e363";s:31:"lib/class.tx_dbal_sqlengine.php";s:4:"f1bb";s:33:"lib/class.tx_dbal_tsparserext.php";s:4:"862d";s:14:"mod1/clear.gif";s:4:"cc11";s:13:"mod1/conf.php";s:4:"6e63";s:14:"mod1/index.php";s:4:"6944";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: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:"034c";s:22:"tests/BaseTestCase.php";s:4:"f736";s:26:"tests/FakeDbConnection.php";s:4:"7bab";s:29:"tests/db_general_testcase.php";s:4:"42f4";s:27:"tests/db_mssql_testcase.php";s:4:"106d";s:28:"tests/db_oracle_testcase.php";s:4:"e710";s:36:"tests/sqlparser_general_testcase.php";s:4:"cc6d";s:31:"tests/fixtures/mssql.config.php";s:4:"56c1";s:30:"tests/fixtures/oci8.config.php";s:4:"7179";}',
+       'version' => '1.1.2',
+       '_md5_values_when_last_written' => 'a:39:{s:9:"ChangeLog";s:4:"91de";s:26:"class.ux_db_list_extra.php";s:4:"60d9";s:21:"class.ux_t3lib_db.php";s:4:"6cc1";s:28:"class.ux_t3lib_sqlparser.php";s:4:"a9d4";s:16:"ext_autoload.php";s:4:"821a";s:21:"ext_conf_template.txt";s:4:"f5cf";s:12:"ext_icon.gif";s:4:"c9ba";s:17:"ext_localconf.php";s:4:"5280";s:14:"ext_tables.php";s:4:"8414";s:14:"ext_tables.sql";s:4:"1f95";s:27:"doc/class.tslib_fe.php.diff";s:4:"0083";s:14:"doc/manual.sxw";s:4:"b022";s:45:"handlers/class.tx_dbal_handler_openoffice.php";s:4:"775f";s:43:"handlers/class.tx_dbal_handler_rawmysql.php";s:4:"2f1b";s:40:"handlers/class.tx_dbal_handler_xmldb.php";s:4:"e363";s:31:"lib/class.tx_dbal_sqlengine.php";s:4:"f1bb";s:33:"lib/class.tx_dbal_tsparserext.php";s:4:"862d";s:14:"mod1/clear.gif";s:4:"cc11";s:13:"mod1/conf.php";s:4:"6e63";s:14:"mod1/index.php";s:4:"4a5e";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: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:"034c";s:22:"tests/BaseTestCase.php";s:4:"f736";s:26:"tests/FakeDbConnection.php";s:4:"7bab";s:29:"tests/db_general_testcase.php";s:4:"42f4";s:27:"tests/db_mssql_testcase.php";s:4:"106d";s:28:"tests/db_oracle_testcase.php";s:4:"e710";s:32:"tests/db_postgresql_testcase.php";s:4:"5f32";s:36:"tests/sqlparser_general_testcase.php";s:4:"cc6d";s:31:"tests/fixtures/mssql.config.php";s:4:"ff95";s:30:"tests/fixtures/oci8.config.php";s:4:"7179";s:36:"tests/fixtures/postgresql.config.php";s:4:"87a1";}',
        'constraints' => array(
                'depends' => array(
                        'adodb' => '5.10.0-',
                        'php' => '5.2.0-0.0.0',
-                       'typo3' => '4.3.0-0.0.0',
+                       'typo3' => '4.4.0beta1-0.0.0',
                ),
                'conflicts' => array(
                ),
index 013dfa0..cf9eea5 100644 (file)
@@ -1 +1 @@
-https://svn.typo3.org/TYPO3v4/Extensions/dbal/tags/1.1.1/
+https://svn.typo3.org/TYPO3v4/Extensions/dbal/tags/1.1.2/
index fdfedae..8b32363 100644 (file)
@@ -387,8 +387,8 @@ updateQryForm(\'' . $input['QUERY'] . '\');
                $cmd = (string)t3lib_div::_GP('cmd');
                switch ($cmd) {
                        case 'flush':
-                               $res = $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_dbal_debuglog', '');
-                               $res = $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_dbal_debuglog_where', '');
+                               $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':
diff --git a/typo3/sysext/dbal/tests/db_postgresql_testcase.php b/typo3/sysext/dbal/tests/db_postgresql_testcase.php
new file mode 100644 (file)
index 0000000..4e8daba
--- /dev/null
@@ -0,0 +1,162 @@
+<?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 db_postgresql_testcase 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;
+
+                       // 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']->handlerInstance['_DEFAULT']->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);
+       }
+}
+?>
\ No newline at end of file
index ba394cf..9b1023e 100644 (file)
@@ -35,4 +35,6 @@ $TYPO3_CONF_VARS['EXTCONF']['dbal']['mapping'] = array(
                ),
        ),
 );
+
+$TYPO3_CONF_VARS['EXTCONF']['dbal']['table2handlerKeys'] = array();
 ?>
\ 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
new file mode 100644 (file)
index 0000000..9ebd54a
--- /dev/null
@@ -0,0 +1,22 @@
+<?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