PMA\libraries\Table::getNonGeneratedColumns PHP Method

getNonGeneratedColumns() public method

Get non-generated columns in table
public getNonGeneratedColumns ( boolean $backquoted = true ) : array
$backquoted boolean whether to quote name with backticks ``
return array
    public function getNonGeneratedColumns($backquoted = true)
    {
        $columns_meta_query = 'SHOW COLUMNS FROM ' . $this->getFullName(true);
        $ret = array();
        $columns_meta_query_result = $this->_dbi->fetchResult($columns_meta_query);
        if ($columns_meta_query_result && $columns_meta_query_result !== false) {
            foreach ($columns_meta_query_result as $column) {
                $value = $column['Field'];
                if ($backquoted === true) {
                    $value = Util::backquote($value);
                }
                if (strpos($column['Extra'], 'GENERATED') === false) {
                    array_push($ret, $value);
                }
            }
        }
        return $ret;
    }

Usage Example

Example #1
0
/**
 * Export at the table level
 *
 * @param string       $db              the database to export
 * @param string       $table           the table to export
 * @param string       $whatStrucOrData structure or data or both
 * @param ExportPlugin $export_plugin   the selected export plugin
 * @param string       $crlf            end of line character(s)
 * @param string       $err_url         the URL in case of error
 * @param string       $export_type     the export type
 * @param bool         $do_relation     whether to export relation info
 * @param bool         $do_comments     whether to add comments
 * @param bool         $do_mime         whether to add MIME info
 * @param bool         $do_dates        whether to add dates
 * @param string       $allrows         whether "dump all rows" was ticked
 * @param string       $limit_to        upper limit
 * @param string       $limit_from      starting limit
 * @param string       $sql_query       query for which exporting is requested
 * @param array        $aliases         Alias information for db/table/column
 *
 * @return void
 */
function PMA_exportTable($db, $table, $whatStrucOrData, $export_plugin, $crlf, $err_url, $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $allrows, $limit_to, $limit_from, $sql_query, $aliases)
{
    $db_alias = !empty($aliases[$db]['alias']) ? $aliases[$db]['alias'] : '';
    if (!$export_plugin->exportDBHeader($db, $db_alias)) {
        return;
    }
    if (isset($allrows) && $allrows == '0' && $limit_to > 0 && $limit_from >= 0) {
        $add_query = ' LIMIT ' . ($limit_from > 0 ? $limit_from . ', ' : '') . $limit_to;
    } else {
        $add_query = '';
    }
    $_table = new Table($table, $db);
    $is_view = $_table->isView();
    if ($whatStrucOrData == 'structure' || $whatStrucOrData == 'structure_and_data') {
        if ($is_view) {
            if (isset($GLOBALS['sql_create_view'])) {
                if (!$export_plugin->exportStructure($db, $table, $crlf, $err_url, 'create_view', $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $aliases)) {
                    return;
                }
            }
        } else {
            if (isset($GLOBALS['sql_create_table'])) {
                if (!$export_plugin->exportStructure($db, $table, $crlf, $err_url, 'create_table', $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $aliases)) {
                    return;
                }
            }
        }
    }
    // If this is an export of a single view, we have to export data;
    // for example, a PDF report
    // if it is a merge table, no data is exported
    if ($whatStrucOrData == 'data' || $whatStrucOrData == 'structure_and_data') {
        if (!empty($sql_query)) {
            // only preg_replace if needed
            if (!empty($add_query)) {
                // remove trailing semicolon before adding a LIMIT
                $sql_query = preg_replace('%;\\s*$%', '', $sql_query);
            }
            $local_query = $sql_query . $add_query;
            $GLOBALS['dbi']->selectDb($db);
        } else {
            // Data is exported only for Non-generated columns
            $tableObj = new PMA\libraries\Table($table, $db);
            $nonGeneratedCols = $tableObj->getNonGeneratedColumns(true);
            $local_query = 'SELECT ' . implode(', ', $nonGeneratedCols) . ' FROM ' . PMA\libraries\Util::backquote($db) . '.' . PMA\libraries\Util::backquote($table) . $add_query;
        }
        if (!$export_plugin->exportData($db, $table, $crlf, $err_url, $local_query, $aliases)) {
            return;
        }
    }
    // now export the triggers (needs to be done after the data because
    // triggers can modify already imported tables)
    if (isset($GLOBALS['sql_create_trigger']) && ($whatStrucOrData == 'structure' || $whatStrucOrData == 'structure_and_data')) {
        if (!$export_plugin->exportStructure($db, $table, $crlf, $err_url, 'triggers', $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $aliases)) {
            return;
        }
    }
    if (!$export_plugin->exportDBFooter($db)) {
        return;
    }
    if (isset($GLOBALS['sql_metadata'])) {
        // Types of metadata to export.
        // In the future these can be allowed to be selected by the user
        $metadataTypes = PMA_getMetadataTypesToExport();
        $export_plugin->exportMetadata($db, $table, $metadataTypes);
    }
}
All Usage Examples Of PMA\libraries\Table::getNonGeneratedColumns