Gets an array containing some SQL to user for when selecting, params for
that SQL, and the filter that was used in constructing the sql.

@global moodle_database $DB
@return string
962612
protected function get_instance_sql() {
        global $DB;
        if ($this->_instancessql === null) {
            $instances = $this->get_enrolment_instances();
            $filter = $this->get_enrolment_filter();
            if ($filter && array_key_exists($filter, $instances)) {
                $sql = " = :ifilter";
                $params = array('ifilter'=>$filter);
            } else {
                $filter = 0;
                if ($instances) {
                    list($sql, $params) = $DB->get_in_or_equal(array_keys($this->get_enrolment_instances()), SQL_PARAMS_NAMED);
                } else {
                    // no enabled instances, oops, we should probably say something
                    $sql = "= :never";
                    $params = array('never'=>-1);
                }
            }
            $this->instancefilter = $filter;
            $this->_instancessql = array($sql, $params, $filter);
        }
        return $this->_instancessql;
    }
70505
public function getArray($sql = null, $parameters = array()) {
		$this->execute($sql);
		$result = array();
		while (!!$objs = mysqli_fetch_assoc($this->result) ) {
			$result[] = $objs;
		}
		return $result;
	}
395297
public function get_sql_filter($data) {
        $field  = $this->field;
        if (is_array($field)) {
            $res = " {$field[0]} = {$field[1]} ";
        } else {
            $res = " {$field} = 0 ";
        }
        return array($res, array());
    }
100503
protected function getDb()
    {
        return \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
    }
661480
public function getForDynamoDB()
    {
        $parameters = parent::getForDynamoDB();

        foreach($this->filters as $name => $filter) {
            /* @var $filter AttributeCondition */
            $parameters['ScanFilter'][$name] = $filter->getForDynamoDB();
        }

        return $parameters;
    }
1140795
public function get_sql_filter($data) {
        global $DB;
        static $counter = 0;
        $name = 'ex_cohort'.$counter++;

        $operator = $data['operator'];
        $value    = $data['value'];

        $params = array();

        if ($value === '') {
            return '';
        }

        $not = '';
        switch($operator) {
            case 0: // Contains.
                $res = $DB->sql_like('idnumber', ":$name", false, false);
                $params[$name] = "%$value%";
                break;
            case 1: // Does not contain.
                $not = 'NOT';
                $res = $DB->sql_like('idnumber', ":$name", false, false);
                $params[$name] = "%$value%";
                break;
            case 2: // Equal to.
                $res = $DB->sql_like('idnumber', ":$name", false, false);
                $params[$name] = "$value";
                break;
            case 3: // Starts with.
                $res = $DB->sql_like('idnumber', ":$name", false, false);
                $params[$name] = "$value%";
                break;
            case 4: // Ends with.
                $res = $DB->sql_like('idnumber', ":$name", false, false);
                $params[$name] = "%$value";
                break;
            case 5: // Empty.
                $not = 'NOT';
                $res = '(idnumber IS NOT NULL AND idnumber <> :'.$name.')';
                $params[$name] = '';
                break;
            default:
                return '';
        }

        $sql = "id $not IN (SELECT userid
                         FROM {cohort_members}
                         JOIN {cohort} ON {cohort_members}.cohortid = {cohort}.id
                        WHERE $res)";

        return array($sql, $params);
    }
502678
function DB()
	{
	global $_ADODB_ACTIVE_DBS;

		if ($this->_dbat < 0) {
			$false = false;
			$this->Error("No database connection set: use ADOdb_Active_Record::SetDatabaseAdaptor(\$db)", "DB");
			return $false;
		}
		$activedb = $_ADODB_ACTIVE_DBS[$this->_dbat];
		$db = $activedb->db;
		return $db;
	}
272417
protected function getAttributesFromDb()
	{
		$connection_name = Config::get('laravel-import-export::baseconf.connection_name');
		return DB::connection($connection_name)
			->table($this->config["table"])
			->select($this->createSelect() )
			->get();
	}
521460
public function get_selected_users() {
        global $DB;
        $idlist = array();
        if (!empty($this->filters->userids)) {

            $idlist = explode(',', $this->filters->userids);
            list($where, $params) = $DB->get_in_or_equal($idlist);
            return $DB->get_records_select('user', "id $where", $params);

        }
        return $idlist;
    }
812414
protected function get_searchsql() {
        global $DB;

        $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
        $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
        $params = array(
            'contextlevel' => CONTEXT_COURSE,
            'fullnamesearch' => '%'.$this->get_search().'%',
            'shortnamesearch' => '%'.$this->get_search().'%'
        );

        $select     = " SELECT c.id, c.fullname, c.shortname, c.visible, c.sortorder ";
        $from       = " FROM {course} c ";
        $where      = " WHERE (".$DB->sql_like('c.fullname', ':fullnamesearch', false)." OR ".
            $DB->sql_like('c.shortname', ':shortnamesearch', false).")";
        $orderby    = " ORDER BY c.sortorder";

        if ($this->currentcourseid !== null && !$this->includecurrentcourse) {
            $where .= " AND c.id <> :currentcourseid";
            $params['currentcourseid'] = $this->currentcourseid;
        }

        return array($select.$ctxselect.$from.$ctxjoin.$where.$orderby, $params);
    }
305519
public function getSql()
    {
        $where = (count($this->conditions) === 0)
            ? ''
            : 'WHERE ' . implode(' and ', $this->conditions);
        $sql = "SELECT $this->select FROM $this->table $where $this->order $this->limit $this->offset";
        return $sql;
    }
569364
public function get_sql() : string {
		if ( empty( $this->columns_to_select ) ) {
			// this should be the default behavior
			$this->columns_to_select = [ '*' ];
		}

		$from = ' FROM ' . implode( ', ', $this->from ) . ' ';

		if ( ! empty( $this->joins ) ) {
			$from .= $this->joins;
		}

		$from  .= 'WHERE ' . $this->where_clause;
		$select = 'SELECT ' . implode( ', ', $this->columns_to_select ) . $from;

		if ( ! empty( $this->group_by ) ) {
			$select .= 'GROUP BY ' . implode( ', ', $this->group_by ) . ' ';
		}

		if ( $this->order_by !== '' ) {
			$select .= 'ORDER BY ' . $this->order_by . ' ';
		}

		$select .= 'LIMIT ' . $this->limit;

		if ( $this->offset !== '' ) {
			$select .= ' OFFSET ' . $this->offset;
		}

		return $select;
	}
632242
public function get_cm_sql() {
        $joins = array();
        $params = array();

        if ($this->filterparams->logreader instanceof logstore_legacy\log\store) {
            // The legacy store doesn't support context level.
            $joins[] = "cmid = :cmid";
            $params['cmid'] = $this->filterparams->modid;
        } else {
            $joins[] = "contextinstanceid = :contextinstanceid";
            $joins[] = "contextlevel = :contextmodule";
            $params['contextinstanceid'] = $this->filterparams->modid;
            $params['contextmodule'] = CONTEXT_MODULE;
        }

        $sql = implode(' AND ', $joins);
        return array($sql, $params);
    }
143099
protected function _getQuery()
    {
        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
        $sArtId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('oxid');
        $sSynchArtId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('synchoxid');

        $sAttrViewName = $this->_getViewName('oxattribute');
        $sO2AViewName = $this->_getViewName('oxobject2attribute');
        if ($sArtId) {
            // all categories article is in
            $sQAdd = " from {$sO2AViewName} left join {$sAttrViewName} " .
                     "on {$sAttrViewName}.oxid={$sO2AViewName}.oxattrid " .
                     " where {$sO2AViewName}.oxobjectid = " . $oDb->quote($sArtId) . " ";
        } else {
            $sQAdd = " from {$sAttrViewName} where {$sAttrViewName}.oxid not in ( select {$sO2AViewName}.oxattrid " .
                     "from {$sO2AViewName} left join {$sAttrViewName} " .
                     "on {$sAttrViewName}.oxid={$sO2AViewName}.oxattrid " .
                     " where {$sO2AViewName}.oxobjectid = " . $oDb->quote($sSynchArtId) . " ) ";
        }

        return $sQAdd;
    }
115330
public function dbgSelect() {
		$sql = $this->buildSQL();
		$params = $this->getParameters();

		return $this->replaceParams($sql, $params);
	}
743343
private function getSql() {
        $sql = str_replace(['%TABLE%',
                            '%DISTINCT%',
                            '%FIELD%',
                            '%JOIN%',
                            '%WHERE%',
                            '%GROUP%',
                            '%HAVING%',
                            '%ORDER%',
                            '%LIMIT%',
                            '%LOCK%',
                            '%COMMENT%',
                            '%FORCE%'], [$this->table,
                                         $this->distinct,
                                         $this->parseField(),
                                         $this->parseJoin(),
                                         $this->whereSql(),
                                         $this->group,
                                         $this->having,
                                         $this->order,
                                         $this->limit,
                                         $this->lock,
                                         $this->comment,
                                         $this->force], $this->selectSql);
        return $sql;
    }
680575
public function getDbSelect()
    {
        if ($this->_dbSelect == null) {
            $this->_dbSelect = $this->_zendDb->select();
        }

        return $this->_dbSelect;
    }