This method returns the first row match in a query.
@param null
@return \MySQLResponseObject
@throws This method does not throw an error
339190
public function first()
	{
		//get the limit clause value
		$limit = $this->limits;

		//get the offset value
		$limitOffset = $this->offset;

		//set the limit to 1
		$this->limit(1);

		//get all
		$all = $this->all();

		//get the first
		$first = ArrayUtility::first($all->result_array())->get();

		//if limit is defined
		if ( $limit ) 
		{
			//set the limit property
			$this->limits = $limit;

		}

		//if limit offset is set
		if ( $limitOffset ) 
		{
			//set the offset
			$this->offset = $limitOffset;

		}

		//get the response object instance
		$this->responseObject
			->setResultArray($first);

		//return the full response object
		return $this->responseObject;

	}
1201633
public static function firstOrNull($fields = null)
    {
        static $request;
        if (!$request) {
            $request = Di::getDefault()->getShared('request');
        }

        if (!$request->isAjax()) {
            return null;
        }

        $model = new static();
        return static::get($request->getId($model->getPrimaryKey()));
    }
593920
public function first()
    {
        try {
            $row = $this->baseQuery->first();

            if ($row === null) {
                return $row;
            } else {
                return $this->processFetchedRow($row);
            }
        } catch (\Throwable $exception) {
            return $this->handleException($exception);
        }
    }
865377
public function execOne()
    {
        $args = func_get_args();

        if (count($args) > 1) {
            $template = array_shift($args);
            $this->currentQuery = vsprintf($template, $args);
        } elseif (count($args) == 1) {
            $this->currentQuery = $args[0];
        } else {
            return null;
        }

        $res = $this->dbExec();
        $rows = $res->count();
        if ($rows > 1) {
            throw $this->createException('Return set contains more than one row');
        } elseif ($rows == 0) {
            return null;
        }

        return $res->current();
    }
596927
public function first()
    {
        $this->seek(0);

        if ($this->count()) {
            return $this->rows[ $this->position ];
        }

        return new Row();
    }
522832
protected function query_row ( $sql )
	{
		$sql = $this->sql_printf(func_get_args());
		if (!($res = mysqli_query( $this->conn, $sql)))
		{
			$this->sql_errcheck($sql);
		}
		if ($row = mysqli_fetch_array($res))
		{
			$rs = $row;
		}
		else
		{
			$rs = false;
		}
		((mysqli_free_result($res) || (is_object($res) && (get_class($res) == "mysqli_result"))) ? true : false);
		return $rs;
	}
107533
public function nextQuery()
    {
        $sql = null;

        while (($line = $this->sqlReader->readLine()) !== null) {
            $delimiter = $this->parent->getDelimiter();
            $project = $this->parent->getOwningTarget()->getProject();
            $line = $project->replaceProperties(trim($line));

            if (($line != $delimiter) && (StringHelper::startsWith("//", $line)
                    || StringHelper::startsWith("--", $line)
                    || StringHelper::startsWith("#", $line))
            ) {
                continue;
            }

            $sql .= " " . $line . "\n";

            /**
             * fix issue with PDO and wrong formated multistatements
             *
             * @issue 1108
             */
            if (StringHelper::endsWith($delimiter, $line)) {
                break;
            }
        }

        return $sql;
    }
734979
public function first(): ?\stdClass
    {
        $pdoStatement = $this->provideStatement();
        $pdoStatement = $this->execute($pdoStatement);
        $row = $pdoStatement->fetch(\PDO::FETCH_OBJ);
        return (!empty($row)) ? $row : null;
    }
1112690
public function query($sql = null)
    {
        if (!$sql) {
            $sqlWhere = '';
            if (!empty($this->getWhere())) {
                $sqlWhere = $this->getWhere();
            }

            $sqlLimit = '';
            if (!empty($this->getLimit())) {
                $sqlLimit = $this->getLimit();
            }

            $sqlOrder = '';
            $orderBy = $this->getOrderBy();
            if (!empty($orderBy)) {
                $sqlOrder = $orderBy;
            }

            $sqlSelect = "SELECT " . $this->getSelect();
            $sqlFrom = " FROM " . $this->getTable();

            $sql = $sqlSelect . $sqlFrom . $sqlWhere . $sqlOrder . $sqlLimit;
        }
        $this->setLastQuery($sql);

        try {
            $stmt = $this->db->prepare($sql);
            $this->setLastQuery($stmt->queryString, $this->getParameters());
            $stmt->execute($this->getParameters());
        } catch (\PDOException $e) {
            throw new DatabaseException($e->getMessage() . '<br>' . $this->getLastQuery()[0]);
        }

        $this->setResult($stmt);
        $this->clearQuery();

        return $this;
    }
646637
public function first($throw = true)
	{
		$this->limit(1);

		$result = $this->offsetGet(0);

		if ($result) {
			return $result;
		} elseif ($throw) {
			throw new \PDOException(get_class($this) . ' "' . $this->table_name . '" not found (' . implode($this->where_scope, ', ') . ')');
		}

		return null;
	}
309819
public function row(int $number = 0)
    {
        if (!isset($this->rows[$number])) {
            return null;
        }

        return $this->cleanClone()->addPristineRecordRef(
            $this->rows[$number],
            $this->rowGetState($number)
        );
    }
1139276
public QueryResult<T> first() {
        if (response != null && response.size() > 0) {
            return response.get(0);
        }
        return null;
    }
595589
public function first( $columns = ['*'] )
	{
		$results = $this->take( 1 )->get( $columns );

		return count( $results ) > 0 ? reset( $results ) : null;
	}
189487
public function first()
    {
        $sql = clone($this);
        $sql->limit(1);
        $collection = $this->query($sql);
        return $collection->isEmpty() ? null : $collection[0];
    }
1306686
public function getQueries($index = null)
    {
        //Argument 1 must be an int string or null
        Argument::i()->test(1, 'int', 'string', 'null');
        
        //if no index
        if (is_null($index)) {
            //return all the queries
            return $this->queries;
        }
        
        //is it the first?
        if ($index == self::FIRST) {
            //index is 0 then
            $index = 0;
        //is it the last?
        } else if ($index == self::LAST) {
            //set index to the last one
            $index = count($this->queries) - 1;
        }
        
        //if we have that record
        if (isset($this->queries[$index])) {
            //return it
            return $this->queries[$index];
        }
        
        return null;
    }
636404
public function getFirstItem()
    {
        $results = $this->getItems();

        if (empty($results)) {
            return null;
        }

        $firstItem = reset($results);

        return $firstItem;
    }
58820
public static function ExecuteEach()
	{
		$arguments = func_get_args();
		$executeQueryBuilders = is_array($arguments[0])? $arguments[0] : $arguments;

		$db = self::connect();
		$db->beginTransaction();
		
		try
		{
			$results = null;

			foreach($executeQueryBuilders as $executeQueryBuilder)
			{				
				$executeQuery = $executeQueryBuilder($results);
				$query = $db->prepare($executeQuery["statement"]);
			
				foreach($executeQuery["parameters"] as $key => $parameter)
				{
					if(!isset($parameter["type"]))
						$parameter["type"] = PDO::PARAM_STR;
						
					$query->bindParam($key,$parameter["value"],$parameter["type"]);
				}
					
				$query->execute();
				$rowsAffected = $query->rowCount();
				$lastID = $db->lastInsertId();

				$results = (object) array(
					DatabaseReturn::RowsAffected => $rowsAffected,
					DatabaseReturn::LastInsertID => $lastID
				);
			}
		}
		catch (PDOException $e)
		{
			$db->rollBack();
			$exception = "Sorry, there was a problem with query execution. ({$e->getMessage()})";
		}

		if($exception) throw new \Exception($exception);
		
		$db->commit();
		return $results;
	}