Given one XMLDB Statement, build the needed SQL insert sentences to execute it.

@param string $statement SQL statement.
@return array Array of sentences in the SQL statement.
979424
function getExecuteInsertSQL($statement) {

         $results = array();  //Array where all the sentences will be stored

         if ($sentences = $statement->getSentences()) {
             foreach ($sentences as $sentence) {
                 // Get the list of fields
                 $fields = $statement->getFieldsFromInsertSentence($sentence);
                 // Get the values of fields
                 $values = $statement->getValuesFromInsertSentence($sentence);
                 // Look if we have some CONCAT value and transform it dynamically
                 foreach($values as $key => $value) {
                     // Trim single quotes
                     $value = trim($value,"'");
                     if (stristr($value, 'CONCAT') !== false){
                         // Look for data between parenthesis
                         preg_match("/CONCAT\s*\((.*)\)$/is", trim($value), $matches);
                         if (isset($matches[1])) {
                             $part = $matches[1];
                             // Convert the comma separated string to an array
                             $arr = xmldb_object::comma2array($part);
                             if ($arr) {
                                 $value = $this->getConcatSQL($arr);
                             }
                         }
                     }
                     // Values to be sent to DB must be properly escaped
                     $value = $this->addslashes($value);
                     // Back trimmed quotes
                     $value = "'" . $value . "'";
                     // Back to the array
                     $values[$key] = $value;
                 }

                 // Iterate over fields, escaping them if necessary
                 foreach($fields as $key => $field) {
                     $fields[$key] = $this->getEncQuoted($field);
                 }
                 // Build the final SQL sentence and add it to the array of results
             $sql = 'INSERT INTO ' . $this->getEncQuoted($this->prefix . $statement->getTable()) .
                         '(' . implode(', ', $fields) . ') ' .
                         'VALUES (' . implode(', ', $values) . ')';
                 $results[] = $sql;
             }

         }
         return $results;
    }
669436
public function attachTo($statement)
    {
        $bindings = $this->bindings();
        if (empty($bindings)) {
            return;
        }

        foreach ($bindings as $b) {
            $statement->bindValue($b['placeholder'], $b['value'], $b['type']);
        }
    }
849053
protected function queryStatement(Statement $statement)
    {
        // 要查询的SQL语句必须是字符串
        if ($statement->isNull()) {
            trigger_error('要查询的语句不能为空', E_USER_ERROR);
        }

        // 记录开始时间
        $begin = timeLog();

        // 获取要执行的语句的Prepare和Params
        $prepare = $statement->getPrepare();
        $params = $statement->getParams();

        //是否需要记录日志
        $logEnabled = $this->logEnabled();

        //先记录日志,以免出错崩溃
        if ($logEnabled) {
            FileLog::instance()->sqlBefore('query', $statement->getSql());
        }

        // 从读服务器进行读操作
        $connect = $this->connectRead();

        // 如果绑定参数为空,直接执行就好.
        if (empty($params)) {
            $ret = $connect->query($prepare);
            $result = $ret->fetchAll(\PDO::FETCH_ASSOC);
            unset($ret);
        } else {
            $result = $this->bindQuery($connect, $prepare, $params);
        }

        // 计算耗时
        $interval = timeLog($begin);

        //如果需要记录日志
        if ($logEnabled) {
            // 记录耗时
            FileLog::instance()->sqlAfter('afterQuery', $statement->getSql(), $result, $interval, $statement->getOperation());

            // 记录调试信息
            Debug::setSql('Query', $prepare, $interval * 1000, $params, $statement->getSql());
        }
        return $result;
    }
1353398
public function exec($statement) {
		$ociPdoStatement = $this->query($statement);
		$count = $ociPdoStatement->rowCount();
		$ociPdoStatement->closeCursor();

		return $count;
	}
416898
public static function getFlags($statement, $all = false)
    {
        $flags = ['querytype' => false];
        if ($all) {
            $flags = self::$ALLFLAGS;
        }

        if ($statement instanceof AlterStatement) {
            $flags['querytype'] = 'ALTER';
            $flags['reload'] = true;
        } elseif ($statement instanceof CreateStatement) {
            $flags['querytype'] = 'CREATE';
            $flags['reload'] = true;
        } elseif ($statement instanceof AnalyzeStatement) {
            $flags['querytype'] = 'ANALYZE';
            $flags['is_maint'] = true;
        } elseif ($statement instanceof CheckStatement) {
            $flags['querytype'] = 'CHECK';
            $flags['is_maint'] = true;
        } elseif ($statement instanceof ChecksumStatement) {
            $flags['querytype'] = 'CHECKSUM';
            $flags['is_maint'] = true;
        } elseif ($statement instanceof OptimizeStatement) {
            $flags['querytype'] = 'OPTIMIZE';
            $flags['is_maint'] = true;
        } elseif ($statement instanceof RepairStatement) {
            $flags['querytype'] = 'REPAIR';
            $flags['is_maint'] = true;
        } elseif ($statement instanceof CallStatement) {
            $flags['querytype'] = 'CALL';
            $flags['is_procedure'] = true;
        } elseif ($statement instanceof DeleteStatement) {
            $flags['querytype'] = 'DELETE';
            $flags['is_delete'] = true;
            $flags['is_affected'] = true;
        } elseif ($statement instanceof DropStatement) {
            $flags['querytype'] = 'DROP';
            $flags['reload'] = true;

            if ($statement->options->has('DATABASE')
                || $statement->options->has('SCHEMA')
            ) {
                $flags['drop_database'] = true;
            }
        } elseif ($statement instanceof ExplainStatement) {
            $flags['querytype'] = 'EXPLAIN';
            $flags['is_explain'] = true;
        } elseif ($statement instanceof InsertStatement) {
            $flags['querytype'] = 'INSERT';
            $flags['is_affected'] = true;
            $flags['is_insert'] = true;
        } elseif ($statement instanceof LoadStatement) {
            $flags['querytype'] = 'LOAD';
            $flags['is_affected'] = true;
            $flags['is_insert'] = true;
        } elseif ($statement instanceof ReplaceStatement) {
            $flags['querytype'] = 'REPLACE';
            $flags['is_affected'] = true;
            $flags['is_replace'] = true;
            $flags['is_insert'] = true;
        } elseif ($statement instanceof SelectStatement) {
            $flags = self::getFlagsSelect($statement, $flags);
        } elseif ($statement instanceof ShowStatement) {
            $flags['querytype'] = 'SHOW';
            $flags['is_show'] = true;
        } elseif ($statement instanceof UpdateStatement) {
            $flags['querytype'] = 'UPDATE';
            $flags['is_affected'] = true;
        } elseif ($statement instanceof SetStatement) {
            $flags['querytype'] = 'SET';
        }

        if (($statement instanceof SelectStatement)
            || ($statement instanceof UpdateStatement)
            || ($statement instanceof DeleteStatement)
        ) {
            if (! empty($statement->limit)) {
                $flags['limit'] = true;
            }
            if (! empty($statement->order)) {
                $flags['order'] = true;
            }
        }

        return $flags;
    }
1319550
public function exec($statement)
    {
        $connection = $this->getWrappedConnection();

        $logger = $this->_config->getSQLLogger();
        if ($logger) {
            $logger->startQuery($statement);
        }

        try {
            $result = $connection->exec($statement);
        } catch (Throwable $ex) {
            throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement);
        }

        if ($logger) {
            $logger->stopQuery();
        }

        return $result;
    }
1261749
public function exec( $statement ){
		$this->logStatement( $statement );
		try{
			$this->numberExecutes++;
			$this->numberStatements++;
			return parent::exec( $statement );
		}
		catch( \PDOException $e ){
			$this->logError( $e, $statement );										//  logs Error and throws SQL Exception
		}
	}
681480
public function query(string $statement) : array
    {
        try {
            return $this->getConnection()->query($statement)->fetchAll(\PDO::FETCH_ASSOC);
        } catch (\PDOException $e) {
            throw new ParserRuntimeException('Statement could not be executed.', 0, $e);
        }
    }
758537
public function prepare($statement) {
        $this->connect();

        $this->statement = new Statement($statement, $this->getParams(), $this->routings);
        $this->statement->setFetchMode($this->defaultFetchMode);

        return $this->statement;
    }
1254347
public function queryAssoc($statement, $params = array()) {
        $start = microtime(true);
        $query = $this->prepare($statement);
        try {
            $query->execute($params);
        } catch (\PDOException $e){
            $this->error($e->getMessage(), array(
                'File' => __FILE__,
                'Line' => __LINE__ - 4,
                'Query' => $statement .'',
                'Params' => $params,
                'Trace' => $e->getTraceAsString()
            ));
            return null;
        }
        $r = $query->fetchAll(\PDO::FETCH_ASSOC);
        $this->debug($statement . '', array(
            'params' => $params,
            'intoArray' => 'assoc',
            'rows' => count($r),
            'time' => microtime(true) - $start,
            'dns' => $this->dns
        ));
        return $r;
    }
370969
protected function buildJoin($statements)
    {
        $sql = '';

        if (!array_key_exists('joins', $statements) || !is_array($statements['joins'])) {
            return $sql;
        }

        foreach ($statements['joins'] as $joinArr) {
            if (is_array($joinArr['table'])) {
                $mainTable = $joinArr['table'][0];
                $aliasTable = $joinArr['table'][1];
                $table = $this->wrapSanitizer($mainTable) . ' AS ' . $this->wrapSanitizer($aliasTable);
            } else {
                $table = $joinArr['table'] instanceof Raw ?
                    (string) $joinArr['table'] :
                    $this->wrapSanitizer($joinArr['table']);
            }
            $joinBuilder = $joinArr['joinBuilder'];

            $sqlArr = array(
                $sql,
                strtoupper($joinArr['type']),
                'JOIN',
                $table,
                'ON',
                $joinBuilder->getQuery('criteriaOnly', false)->getSql()
            );

            $sql = $this->concatenateQuery($sqlArr);
        }

        return $sql;
    }
642047
public static function Execute($statement, $parameters = array(), $return=false)
	{
		$db = self::connect();
		$rowsAffected = 0;
		$lastID = 0;
		
		try
		{
			$query = $db->prepare($statement);
			
			foreach($parameters as $key => $parameter)
			{
				if(!isset($parameter["type"]))
					$parameter["type"] = PDO::PARAM_STR;
				
				$query->bindParam($key,$parameter["value"],$parameter["type"]);
			}
			
			$db->beginTransaction();
			$query->execute();
			$rowsAffected += $query->rowCount();
			$lastID = $db->lastInsertId();
			$db->commit();
		}
		catch (PDOException $e)
		{
			$db->rollBack();
			$exception = "Sorry, there was a problem with query execution. ({$e->getMessage()})";
		}

		if($exception) throw new \Exception($exception);
		
		$returnObject = (object) array(
			DatabaseReturn::RowsAffected => $rowsAffected,
			DatabaseReturn::LastInsertID => $lastID
		);
		
		if($return) return $returnObject;
		else return $rowsAffected;
	}
994671
protected function insertExecute(string $statement, array $values): ?array {
		
		// our insert method should return either a single ID or a list of created IDs.
		// we can use the ExtendedPdo's fetchAffected method to determine how many were
		// inserted and then use that to determine our return value.  if nothing at all
		// was inserted, we return null.
		
		$affected = $this->dbConn->fetchAffected($statement, array_values($values));
		
		if ($affected === 0) {
			return null;
		}
		
		if ($affected === 1) {
			return [$this->getInsertedId()];
		}
		
		// if we haven't returned, then we inserted more than 1 row.  we can construct a
		// list of the IDs that were created by using the last ID and range as follows.
		// to identify our first ID, it would seem like $lastId - $affected would be enough,
		// but if we inserted 5 rows ending at 10, 10 - 5 = 5 and we don't want a range to
		// be [10,9,8,7,6,5] because that's six IDs.  so, we want to do 10 - (5 - 1) which
		// would result in [10,9,8,7,6] which is the correct response.
		
		$lastId = $this->getInsertedId();
		$firstId = $lastId - ($affected - 1);
		return range($lastId, $firstId);
	}
247037
private function executeWrite($statement, array $parameters)
    {
        if ($this->transactionCount == 0) {
            $connection = $this->pool->selectWriteConnection();
        } else {
            $connection = $this->transactionConnection;
        }

        try {
            return $connection->execute(
                $this->expandPlaceholders($statement, $parameters),
                $parameters
            );
        } catch (ConnectionException $e) {
            $this->pool->disableWriteConnection($connection);
            if ($this->pool->getWriteConnectionCount() == 0) {
                throw $e;
            }

            return $this->executeWrite($statement, $parameters);
        }
    }
1254602
protected function getStatement($sql)
    {
        if (!isset($this->statements[$sql])) {
            $this->statements[$sql] = $this->adapter->prepare($sql);
        }
        return $this->statements[$sql];
    }
416787
protected function executeStatement(Statement $statement): bool
    {
        // 要执行的SQL语句必须是字符串
        if ($statement->isNull()) {
            trigger_error('要执行的语句不能为空', E_USER_ERROR);
        }

        // 记录开始时间
        $begin = timeLog();

        // 获取数据库句柄(只使用写服务器)
        $connect = $this->connectWrite();

        // 获取要执行的语句的Prepare和Params
        $prepare = $statement->getPrepare();
        $params = $statement->getParams();

        //是否需要记录日志
        $logEnabled = $this->logEnabled();

        //先记录日志,以免出错崩溃
        if ($logEnabled) {
            FileLog::instance()->sqlBefore('execute', $statement->getSql());
        }

        // 如果参数为空,就不必使用prepare模式了,直接执行
        if (empty($params)) {
            $result = $connect->exec($prepare);
        } elseif ($statement->isQuery()) {
            // 先预备,再附加参数进行执行
            $result = $this->bindExecute($connect, $prepare, $params);
        } else {
            // 先预备,再附加参数进行执行
            $stmt = $connect->prepare($prepare);
            $result = $stmt->execute($params);
            unset($stmt);
        }

        // 计算耗时
        $interval = timeLog($begin);

        // 记录耗时
        if ($logEnabled) {
            FileLog::instance()->sqlAfter('afterExecute', $statement->getSql(), $result, $interval, $statement->getOperation());

            // 输出调试信息:执行时间
            Debug::setSql('Execute', $prepare, $interval * 1000, $params, $statement->getSql());
        }

        return boolval($result);
    }
965917
public function q(string $statement, ...$params)
    {
        /**
         * @var array $result
         */
        $result = (array) $this->safeQuery(
            $statement,
            $params,
            self::DEFAULT_FETCH_STYLE,
            false,
            true
        );
        return $result;
    }