예제 #1
0
 /**
  * @test
  * @see http://forge.typo3.org/issues/15366
  */
 public function canParseUniqueIndexCreation()
 {
     $sql = 'ALTER TABLE static_territories ADD UNIQUE uid (uid)';
     $expected = $sql;
     $alterTables = $this->subject->_callRef('parseALTERTABLE', $sql);
     $queries = $this->subject->compileSQL($alterTables);
     $this->assertEquals($expected, $queries);
 }
예제 #2
0
 /**
  * @test
  * @see http://forge.typo3.org/issues/23374
  */
 public function questionMarkParametersMayBeSafelyReplaced()
 {
     $sql = 'SELECT * FROM pages WHERE pid = ? AND timestamp < ? AND title != \'How to test?\'';
     $parameterValues = array(12, 1281782690);
     $components = $this->subject->_callRef('parseSELECT', $sql);
     $questionMarkParamCount = count($components['parameters']['?']);
     for ($i = 0; $i < $questionMarkParamCount; $i++) {
         $components['parameters']['?'][$i][0] = $parameterValues[$i];
     }
     $result = $this->subject->compileSQL($components);
     $expected = 'SELECT * FROM pages WHERE pid = 12 AND timestamp < 1281782690 AND title != \'How to test?\'';
     $this->assertEquals($expected, $this->cleanSql($result));
 }
 /**
  * mysqli() wrapper function, used by the Install Tool and EM for all queries regarding management of the database!
  *
  * @param string $query Query to execute
  * @throws \InvalidArgumentException
  * @return bool|\mysqli_result|object MySQLi result object / DBAL object
  */
 public function admin_query($query)
 {
     $parsedQuery = $this->SQLparser->parseSQL($query);
     if (!is_array($parsedQuery)) {
         throw new \InvalidArgumentException('ERROR: Query could not be parsed: "' . htmlspecialchars($parsedQuery) . '". Query: "' . htmlspecialchars($query) . '"', 1310027793);
     }
     $ORIG_table = $parsedQuery['TABLE'];
     // Process query based on type:
     switch ($parsedQuery['type']) {
         case 'CREATETABLE':
         case 'ALTERTABLE':
             $this->createMappingsIfRequired($parsedQuery);
             // Fall-through next instruction
         // Fall-through next instruction
         case 'DROPTABLE':
             $this->clearCachedFieldInfo();
             $this->map_genericQueryParsed($parsedQuery);
             break;
         case 'INSERT':
         case 'TRUNCATETABLE':
             $this->map_genericQueryParsed($parsedQuery);
             break;
         case 'CREATEDATABASE':
             throw new \InvalidArgumentException('Creating a database with DBAL is not supported. Did you really read the manual?', 1310027716);
             break;
         default:
             throw new \InvalidArgumentException('ERROR: Invalid Query type (' . $parsedQuery['type'] . ') for ->admin_query() function!: "' . htmlspecialchars($query) . '"', 1310027740);
     }
     // 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!)
     $result = null;
     $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 (in_array($this->lastParsedAndMappedQueryArray['type'], array('INSERT', 'DROPTABLE', 'ALTERTABLE'))) {
                 $result = $this->query($compiledQuery);
             } else {
                 $result = $this->query($compiledQuery[0]);
             }
             break;
         case 'adodb':
             // Compiling query:
             $compiledQuery = $this->SQLparser->compileSQL($this->lastParsedAndMappedQueryArray);
             switch ($this->lastParsedAndMappedQueryArray['type']) {
                 case 'INSERT':
                     $result = $this->exec_INSERTquery($this->lastParsedAndMappedQueryArray['TABLE'], $compiledQuery);
                     break;
                 case 'TRUNCATETABLE':
                     $result = $this->exec_TRUNCATEquery($this->lastParsedAndMappedQueryArray['TABLE']);
                     break;
                 default:
                     if (!is_array($compiledQuery)) {
                         $compiledQuery = array($compiledQuery);
                     }
                     $result = $this->handlerInstance[$this->lastHandlerKey]->DataDictionary->ExecuteSQLArray($compiledQuery);
             }
             break;
         case 'userdefined':
             // Compiling query:
             $compiledQuery = $this->SQLparser->compileSQL($this->lastParsedAndMappedQueryArray);
             $result = $this->handlerInstance[$this->lastHandlerKey]->admin_query($compiledQuery);
         default:
     }
     return $result;
 }