Ejemplo n.º 1
0
 /**
  * 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':
         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:
                     $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;
 }