Builder::get_sql()

Get all the pieces of the SQL constructed to used against the DB.


Return

(string)


Top ↑

Source

File: src/Events/Custom_Tables/V1/Models/Builder.php

	public function get_sql() {
		// If this query is already invalid return an empty string.
		if ( $this->invalid ) {
			return '';
		}

		global $wpdb;
		$pieces = [
			$this->operation,
			"FROM `{$wpdb->prefix}{$this->model->table_name()}`",
		];

		foreach ( $this->joins as $joins ) {
			foreach ( $joins as $line ) {
				$pieces[] = $line;
			}
		}

		$where = $this->get_where_clause();

		if ( $where !== '' ) {
			$pieces[] = $where;
		}

		if ( ! empty( $this->order ) ) {
			$pieces[] = 'ORDER BY `' . $this->order['column'] . '` ' . $this->order['order'];
		}

		if ( isset( $this->limit ) ) {
			$pieces[] = $wpdb->prepare( "LIMIT %d", (int) $this->limit );
		}

		if ( isset( $this->offset ) ) {
			$pieces[] = $wpdb->prepare( "OFFSET %d", (int) $this->offset );
		}

		return implode( "\n", $pieces );
	}

Top ↑

Changelog

Changelog
Version Description
6.0.0 Introduced.