Get create sql for function

@param string $tbl - table name
@return string with full query
328585
public static function getCreateFunction($tbl): string
    {
        $sql = self::getInstance()->sql_query("SHOW CREATE FUNCTION `$tbl`");

        $q = $sql->fetch(PDO::FETCH_ASSOC);

        return strtr($q['Create Function'], ["\r" => '', "\n" => '', "\t" => '']);
    }
252830
public function getCreateTempTableSQL($xmldb_table) {
        // Do we know collation?
        $collation = $this->mdb->get_dbcollation();
        $this->temptables->add_temptable($xmldb_table->getName());

        $sqlarr = parent::getCreateTableSQL($xmldb_table);

        // Let's inject the extra MySQL tweaks.
        foreach ($sqlarr as $i=>$sql) {
            if (strpos($sql, 'CREATE TABLE ') === 0) {
                // We do not want the engine hack included in create table SQL.
                $sqlarr[$i] = preg_replace('/^CREATE TABLE (.*)/s', 'CREATE TEMPORARY TABLE $1', $sql);
                if ($collation) {
                    if (strpos($collation, 'utf8_') === 0) {
                        $sqlarr[$i] .= " DEFAULT CHARACTER SET utf8";
                    }
                    $sqlarr[$i] .= " DEFAULT COLLATE $collation ROW_FORMAT=DYNAMIC";
                }
            }
        }

        return $sqlarr;
    }
138482
private function getTblStructure()
    {
        if (strpos($this->tbl, '{db_prefix}') !== 0 || strpos($this->tbl, $this->prefix) !== 0) {
            $this->tbl = $this->prefix . $this->tbl;
        }
        else {
            $this->tbl = str_replace('{db_prefix}', $this->prefix, $this->tbl);
        }
        
        $driver_class = '\Core\Data\Db\\' . ucfirst($this->db->dbh->getPrefix());
        
        /* @var $db_subs TableInfoAbstract */
        $db_subs = new $driver_class($this, $this->tbl);
        
        $db_subs->loadColumns($this->tbl);
        $this->columns = $db_subs->getColumns();
        
        $db_subs->loadIndexes($this->tbl);
        $this->indexes = $db_subs->getIndexes();
    }
534735
protected function createSelectQuery()
    {
        $query = $this->handler->createSelectQuery();
        $query->select(
            $this->handler->quoteColumn(self::COLUMN_ID),
            $this->handler->quoteColumn(self::COLUMN_URL),
            $this->handler->quoteColumn(self::COLUMN_ORIGINAL_URL_MD5),
            $this->handler->quoteColumn(self::COLUMN_IS_VALID),
            $this->handler->quoteColumn(self::COLUMN_LAST_CHECKED),
            $this->handler->quoteColumn(self::COLUMN_CREATED),
            $this->handler->quoteColumn(self::COLUMN_MODIFIED)
        )->from(
            $this->handler->quoteTable(self::URL_TABLE)
        );

        return $query;
    }
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;
	}
24135
private function getLanguageQuery()
    {
        $languageQuery = $this->dbHandler->createSelectQuery();
        $languageQuery
            ->select(
                $languageQuery->expr->searchedCase(
                    [
                        $languageQuery->expr->lAnd(
                            $languageQuery->expr->eq(
                                $this->dbHandler->quoteColumn('initial_language_id'),
                                ':languageId'
                            ),
                            // wrap bitwise check into another "neq" to provide cross-DBMS compatibility
                            $languageQuery->expr->neq(
                                $languageQuery->expr->bitAnd(
                                    $this->dbHandler->quoteColumn('language_mask'),
                                    ':languageId'
                                ),
                                0
                            )
                        ),
                        $languageQuery->expr->bitOr(
                            ':languageId',
                            1
                        ),
                    ],
                    ':languageId'
                )
            )
            ->from('ezcontentobject')
            ->where(
                $languageQuery->expr->eq(
                    'id',
                    ':contentId'
                )
            );

        return $languageQuery;
    }
991107
static function getTable($query) {
    if (!self::isWriteQuery($query)) {
      throw new DbException("Query '$query' is not a write query");
    }
    $query = " " . strtolower(preg_replace("/\\s+/i", " ", $query)) . " ";
    if (preg_match("# (update|delete from|insert into|create table|alter table|drop table) ([^ ;]+)[ ;]#i", $query, $matches)) {
      return $matches[2];
    }
    if (preg_match("# from migrations #i", $query, $matches)) {
      return "migrations";
    }
    if (preg_match("# (show tables) #i", $query, $matches)) {
      return "global";
    }
    throw new DbException("Could not identify table for query '$query'");
  }
1239632
function _query($sql,$inputarr=false)
	{
	GLOBAL $php_errormsg;
		if (isset($php_errormsg)) $php_errormsg = '';
		$this->_error = '';

		if ($inputarr) {
			if (is_array($sql)) {
				$stmtid = $sql[1];
			} else {
				$stmtid = odbc_prepare($this->_connectionID,$sql);

				if ($stmtid == false) {
					$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
					return false;
				}
			}

			if (! odbc_execute($stmtid,$inputarr)) {
				//@odbc_free_result($stmtid);
				if ($this->_haserrorfunctions) {
					$this->_errorMsg = odbc_errormsg();
					$this->_errorCode = odbc_error();
				}
				return false;
			}

		} else if (is_array($sql)) {
			$stmtid = $sql[1];
			if (!odbc_execute($stmtid)) {
				//@odbc_free_result($stmtid);
				if ($this->_haserrorfunctions) {
					$this->_errorMsg = odbc_errormsg();
					$this->_errorCode = odbc_error();
				}
				return false;
			}
		} else
			$stmtid = odbc_exec($this->_connectionID,$sql);

		$this->_lastAffectedRows = 0;
		if ($stmtid) {
			if (@odbc_num_fields($stmtid) == 0) {
				$this->_lastAffectedRows = odbc_num_rows($stmtid);
				$stmtid = true;
			} else {
				$this->_lastAffectedRows = 0;
				odbc_binmode($stmtid,$this->binmode);
				odbc_longreadlen($stmtid,$this->maxblobsize);
			}

			if ($this->_haserrorfunctions) {
				$this->_errorMsg = '';
				$this->_errorCode = 0;
			} else
				$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
		} else {
			if ($this->_haserrorfunctions) {
				$this->_errorMsg = odbc_errormsg();
				$this->_errorCode = odbc_error();
			} else
				$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
		}
		return $stmtid;
	}
942852
public function getEmails($tbl = 'managers')
	{
		if (!in_array($tbl, array('applicants', 'members', 'managers', 'invitees')))
		{
			return false;
		}

		$db = \App::get('db');

		if (empty($db))
		{
			return false;
		}

		$query = 'SELECT u.email FROM #__users AS u, #__xgroups_' . $tbl . ' AS gm WHERE gm.gidNumber=' . $db->quote($this->gidNumber) . ' AND u.id=gm.uidNumber;';

		$db->setQuery($query);

		$emails = $db->loadColumn();

		return $emails;
	}
363028
public static function swapTable($tbl): string
    {
        $tmp_tbl = $tbl . '_' . NOW;
        $new_tbl = $tmp_tbl . '_new';

        self::getInstance()->sql_query(str_replace('`' . $tbl . '`', '`' . $new_tbl . '`', self::getCreateTable($tbl)));
        self::getInstance()->sql_query('RENAME TABLE `' . $tbl . '` TO `' . $tmp_tbl . '`, `' . $new_tbl . '` TO `' . $tbl . '`');

        return $tmp_tbl;
    }
577126
protected static function getCreateTableSql($table)
    {
        $db = Yii::$app->db;
        $row = $db->createCommand('SHOW CREATE TABLE ' . $db->schema->quoteTableName($table->fullName))->queryOne();
        if (isset($row['Create Table'])) {
            $sql = $row['Create Table'];
        } else {
            $row = array_values($row);
            $sql = $row[1];
        }

        return $sql;
    }
997061
public function createQuery()
    {
        $query = \Parable\ORM\Query::createInstance();
        $query->setTableName($this->getTableName());
        return $query;
    }
1277097
private function getSQLForSelect()
    {
        $query = 'SELECT ' . implode(', ', $this->sqlParts['select']);

        $query .= ($this->sqlParts['from'] ? ' FROM ' . implode(', ', $this->getFromClauses()) : '')
            . ($this->sqlParts['where'] !== null ? ' WHERE ' . ((string) $this->sqlParts['where']) : '')
            . ($this->sqlParts['groupBy'] ? ' GROUP BY ' . implode(', ', $this->sqlParts['groupBy']) : '')
            . ($this->sqlParts['having'] !== null ? ' HAVING ' . ((string) $this->sqlParts['having']) : '')
            . ($this->sqlParts['orderBy'] ? ' ORDER BY ' . implode(', ', $this->sqlParts['orderBy']) : '');

        if ($this->isLimitQuery()) {
            return $this->connection->getDatabasePlatform()->modifyLimitQuery(
                $query,
                $this->maxResults,
                $this->firstResult
            );
        }

        return $query;
    }
349260
public function getRawQuery()
    {
        $sql = array();

        foreach ($this->getClauses() as $clause) {
            if (!$clause->isEmpty()) {
                $sql[] = $clause;
            }
        }

        return implode(' ', $sql);
    }
1356495
private function getRuleSelectQuery(): QueryBuilder
    {
        $query = $this->connection->createQueryBuilder();
        $query->select('DISTINCT r.*', 'rd.*')
            ->from('ngbm_rule', 'r')
            ->innerJoin(
                'r',
                'ngbm_rule_data',
                'rd',
                $query->expr()->eq('rd.rule_id', 'r.id')
            );

        return $query;
    }
564158
public function update($tbl, $where, $data){
		$table_definition = $this->exdb->get_table_definition($tbl);
		$delete_flg_id = $table_definition->system_columns->delete_flg;

		foreach($table_definition->columns as $key=>$val){
			if( !array_key_exists( $key, $where ) && !array_key_exists( $key, $data ) ){continue;}
			if( $table_definition->columns->{$key}->type == 'password' ){
				// パスワードをハッシュ値化
				if( array_key_exists($key, $where) ){ $where[$key] = $this->exdb->encrypt_password($where[$key]); }
				if( strlen($data[$key]) ){
					if( array_key_exists($key, $data) ){ $data[$key] = $this->exdb->encrypt_password($data[$key]); }
				}else{
					unset($data[$key]);
				}
			}elseif( $table_definition->columns->{$key}->type == 'delete_flg' ){
				// delete_flgを 0 or 1 に整形
				if( array_key_exists($key, $where) ){ $where[$key] = ($where[$key] ? 1 : 0); }
				if( array_key_exists($key, $data) ){ $data[$key] = ($data[$key] ? 1 : 0); }
			}
		}
		if( is_string($delete_flg_id) && @is_null( $where[$delete_flg_id] ) ){
			$where[$delete_flg_id] = 0;
		}

		$errors = $this->exdb->validate( $tbl, $data );
		if( count($errors) ){
			return false;
		}

		$sql = array();
		$sql['update'] = 'UPDATE '.$this->exdb->get_physical_table_name($tbl).'';
		$sql['set'] = ' SET ';
		$sql['where'] = ' WHERE ';
		$sql['close'] = ';';

		$bind_data = array();

		$sql_set = array();
		$is_update_date = false;
		foreach( $data as $column_name => $data_row ){
			array_push($sql_set, $column_name.'=:__set__'.$column_name);
			$bind_data['__set__'.$column_name] = $data_row;
			if( $table_definition->system_columns->update_date === $column_name ){
				$is_update_date = true;
			}
		}

		$sql_where = array();
		foreach( $where as $column_name => $cond ){
			array_push($sql_where, $column_name.'=:__where__'.$column_name);
			$bind_data['__where__'.$column_name] = $cond;
		}

		if($table_definition->system_columns->update_date){
			// 最終更新日時を自動的にセットする
			$bind_data[':__set__'.$table_definition->system_columns->update_date] = date("Y-m-d H:i:s");
			if( !$is_update_date ){
				array_push($sql_set, $table_definition->system_columns->update_date.'=:__set__'.$table_definition->system_columns->update_date);
			}
		}


		$sql_template = $sql['update'].(count($sql_set) ? $sql['set'].implode($sql_set, ', ') : '').(count($sql_where) ? $sql['where'].implode($sql_where, ' AND ') : '').$sql['close'];
		// var_dump($sql_template);
		$sth = $this->exdb->pdo()->prepare( $sql_template );
		$result = $sth->execute( $bind_data );
		if( $result === false ){
			return false;
		}
		$result = $sth->rowCount();
		// var_dump($result);

		return $result;
	}
832008
protected function _getFinalSql($tablePrefix, $repeat = false)
    {
        $db = \Zend_Registry::getInstance()->get('db');

        $sqlSuffix = $db->quoteIdentifier($tablePrefix . '_changed') . " timestamp NOT NULL,\n"
            . $db->quoteIdentifier($tablePrefix . '_changed_by') . " bigint(20) NOT NULL,\n"
            . $db->quoteIdentifier($tablePrefix . '_created') . " timestamp NOT NULL,\n"
            . $db->quoteIdentifier($tablePrefix . '_created_by') . " bigint(20) NOT NULL,\n";
        if ($repeat) {
            $sqlSuffix .= 'PRIMARY KEY  (`' . $tablePrefix . '_id`, `' . $tablePrefix . '_response_id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;';
        } else {
            $sqlSuffix .= 'PRIMARY KEY  (`' . $tablePrefix . '_id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;';
        }

        return $sqlSuffix;
    }