执行SQL语句
@param string $sql
@return IResult
6382
public function execute($sql)
    {
        try{
            if(null === $this->queryType)
            {
                $this->queryType = QueryType::WRITE;
            }
            if(!$this->isInitDb)
            {
                $this->db = Db::getInstance($this->poolName, $this->queryType);
            }
            if(!$this->db)
            {
                return new Result(false);
            }
            $stmt = $this->db->prepare($sql);
            if($stmt)
            {
                if($this->defer)
                {
                    $defer = $stmt->deferExecute($this->binds);
                }
                else
                {
                    $stmt->execute($this->binds) ? $stmt : false;
                }
            }
            return new Result($stmt, $this->modelClass, $defer ?? null);
        } finally {
            $this->__init();
        }
    }
691560
function Execute($sql)
	{
		$result = null;
		
		if ($this->ConnectionSetting->IsReadOnlySlave) {
			
			// this is a read-only slave connection attempting a write operation.  we
			// will only proceed if the connection specifies a "master" delegate connection
			if (!$this->_masterAdapter) {
				
				if ($this->ConnectionSetting->MasterConnectionDelegate) {
					
					$this->Observe("DataAdapter ($this->_label) (DataAdapter.Execute) Delegating write operation from Slave to Master Connection", OBSERVE_INFO);
				
					$this->_masterAdapter = new DataAdapter($this->ConnectionSetting->MasterConnectionDelegate);
					
					foreach ($this->_observers as $observer) {
						$this->_masterAdapter->AttachObserver($observer);
					}
				}
				else {
					throw new Exception('DB Write operation was attempted on a read-only slave connection');
				}
			}
			
			// we have a master connection initialized and ready to use
			$result = $this->_masterAdapter->Execute($sql);

		}
		else {
			$this->RequireConnection(true);
			$this->Observe("DataAdapter ($this->_label) (DataAdapter.Execute) " . $sql, OBSERVE_QUERY);
			$result = -1;
			
			try
			{
				$result = $this->_driver->Execute($this->_dbconn, $sql);
				$this->_num_retries = 0;
			}
			catch (Exception $ex)
			{
				// retry one time a communication error occurs
				if ($this->_num_retries == 0 && DataAdapter::$RETRY_ON_COMMUNICATION_ERROR && $this->IsCommunicationError($ex))
				{
					$this->_num_retries++;
					$this->Observe("DataAdapter ($this->_label) Communication error.  Retry attempt " . $this->_num_retries, OBSERVE_WARN);
					sleep(2); // slight delay to prevent throttling
					return $this->Execute($sql);
				}
				
				$msg = "DataAdapter ($this->_label)" . ' Error Executing SQL: ' . $ex->getMessage() . ' (retry attempts: '.$this->_num_retries.')';
				
				$this->Observe($msg,OBSERVE_FATAL);
				throw new Exception($msg,$ex->getCode());
			}
			}
		return $result;
	}
452659
public function query(string $sql)
    {
        try {
            $this->stmt = $this->dbh->query($sql);            
            return $this;
        } catch (\PDOException $e) {
            die("Error: " . $e->getMessage());
        }
    }
170953
protected function query_one ( $sql )
	{
		$sql = $this->sql_printf(func_get_args());
		if (!($res = mysql_query($sql, $this->conn)))
		{
			$this->sql_errcheck($sql);
		}
		$val = @mysql_result($res, 0, 0);
		mysql_free_result($res);
		return $val;
	}
1228485
public function executeRaw($sql) {
        if (!is_string($sql)) throw new IllegalTypeException('Illegal type of parameter $sql: '.gettype($sql));
        if (!$this->isConnected())
            $this->connect();

        // execute statement
        try {
            $result = mysql_query($sql, $this->hConnection);
            $result || trigger_error('SQL-Error '.mysql_errno($this->hConnection).': '.mysql_error($this->hConnection), E_USER_ERROR);
        }
        catch (\Exception $ex) {
            $ex = new DatabaseException($ex->getMessage(), mysql_errno($this->hConnection), $ex);
            throw $ex->addMessage('Database: '.$this->getConnectionDescription().NL.'SQL: "'.$sql.'"');
        }

        $affected = 0;

        // track last_insert_id
        $id = mysql_insert_id($this->hConnection);
        if ($id) $this->lastInsertId = $id + ($affected=mysql_affected_rows($this->hConnection)) - 1;

        // track last_affected_rows
        if (!is_resource($result)) {                                               // a row returning statement never modifies rows
            $version = $this->getVersionNumber();
            if ($version < 5005005) $pattern = '/^\s*(INSERT|UPDATE|DELETE)\b/i';   // < 5.5.5.
            else                    $pattern = '/^\s*(INSERT|UPDATE|DELETE|ALTER\s+TABLE|LOAD\s+DATA\s+INFILE)\b/i';
            if (preg_match($pattern, $sql)) {
                if (!$id) $affected = mysql_affected_rows($this->hConnection);
                $this->lastAffectedRows = $affected;
            }
        }
        return $result;
    }
1125979
public function selectValue($sql)
    {
        $result = $this->execute($sql);
        if ($result->count()) {
            $row = $result->current();
            return reset($row);
        }
    }
1096221
public function query($sql) {
        $result = $this->executeRaw($sql);
        return new PostgresResult($this, $sql, $result, $this->lastAffectedRows());
    }
522333
protected function runTableCheckCommand($sql)
    {
        $testResults = $this->query($sql);
        foreach ($testResults as $testRecord) {
            if (strtolower($testRecord['Msg_text']) != 'ok') {
                return false;
            }
        }
        return true;
    }
581791
protected function query($sql) {
		$this->sqlCnt++;
		$res = $this->db->query($sql);
		if (!$res) {
			$this->dbError = $this->db->error;
		}
		return $res;
	}
1290138
public function query($sql)
    {
        try {
            $start = microtime(true);

            $result = $this->prepare($sql);
            $this->execute($result);

            if ($this->saveAffectedRows($result) === 0 && $this->isResult($result) && ! $this->isSelectQuery($sql)) {
                $result = true;
            }
            $this->getConnect()->logQuery($sql, [], $this->getElapsedTime($start));
        } catch (\Exception $exception) {
            $this->lastError = $this->isResult($result) ? $result->errorInfo() : [];
            $code = $this->isResult($result) ? $result->errorCode() : '';
            $this->lastErrorNo = $this->isResult($result) ? (empty($code) ? $exception->getCode() : $code) : '';
            throw (new Exceptions\QueryException($exception->getMessage(), $exception->getCode()))
                ->setQuery($sql);
        }

        return $result;
    }
687229
public function query($sql) {
        try {
            $lastExecMode = $this->skipResults;
            $this->skipResults = false;

            /** @var \SQLite3Result $result */
            $result = $this->executeRaw($sql);
            return new SQLiteResult($this, $sql, $result, $this->lastInsertId(), $this->lastAffectedRows());
        }
        finally {
            $this->skipResults = $lastExecMode;
        }
    }
1198468
public function select(): IResult
    {
        $builder = new SelectBuilder($this);
        $sql = $builder->build();
        if(!$this->isInitQueryType && !$this->isInTransaction())
        {
            $this->queryType = QueryType::READ;
        }
        return $this->execute($sql);
    }
12323
public function execute($sql) {
        //
        // TODO: check mysql_unbuffered_query() with mysql_free_result() for larger result sets
        //       @see  https://www.percona.com/blog/2006/06/26/handling-of-big-parts-of-data/
        //       @see  https://dev.mysql.com/doc/refman/5.7/en/mysql-use-result.html

        $result = $this->executeRaw($sql);
        if (is_resource($result))
            mysql_free_result($result);               // release the result
        return $this;
    }
248989
public function execute($sql, array $parameters = [])
    {
        $sth = $this->prepare($sql);
        $sth->execute($parameters);
        return $sth;
    }
844785
public function sql($sql, $val = false) {
        #$val为true时，返回执行结果
        $result = preg_split('/;(\r|\n)/is', $sql);
        if ($val) {
            foreach ((array) $result as $r) {
                if ($row = $this->connection->query($r)) {
                    return $row;
                } else {
                    return false;
                }
            }
        }
        foreach ((array) $result as $r) {
            if (!$this->connection->execute($r)) {
                return false;
            }
        }
        return true;
    }
884659
protected function execute($sql)
    {
        $this->lastQuery = $sql;

        $this->debugLog(sprintf('Executing SQL: %s', $sql));

        $this->sqlStatement = $this->getConnection()->prepare($sql, []);
        $this->sqlStatement->execute();
        $this->lastId = $this->connection->lastInsertId(sprintf('%s_id_seq', $this->getEntity()));

        // If their is an id, save it!
        if ($this->lastId) {
            $this->handleLastId($this->getEntity(), $this->lastId);
        }

        return $this->sqlStatement;
    }
55209
public function load($sql)
	{
		$this->pdo()->exec($sql);
		$this->pdo()->exec('FLUSH TABLES');

		return $this;
	}