/** * Prepares the field value and retrieve special chars, backup field and data array * * @param array $current_row a row of the table * @param array $column description of column in given table * @param array $extracted_columnspec associative array containing type, * spec_in_brackets and possibly * enum_set_values (another array) * @param boolean $real_null_value whether column value null or not null * @param array $gis_data_types list of GIS data types * @param string $column_name_appendix string to append to column name in input * @param bool $as_is use the data as is, used in repopulating * * @return array $real_null_value, $data, $special_chars, $backup_field, * $special_chars_encoded */ function PMA_getSpecialCharsAndBackupFieldForExistingRow($current_row, $column, $extracted_columnspec, $real_null_value, $gis_data_types, $column_name_appendix, $as_is) { $special_chars_encoded = ''; $data = null; // (we are editing) if (!isset($current_row[$column['Field']])) { $real_null_value = true; $current_row[$column['Field']] = ''; $special_chars = ''; $data = $current_row[$column['Field']]; } elseif ($column['True_Type'] == 'bit') { $special_chars = $as_is ? $current_row[$column['Field']] : PMA\libraries\Util::printableBitValue($current_row[$column['Field']], $extracted_columnspec['spec_in_brackets']); } elseif ((substr($column['True_Type'], 0, 9) == 'timestamp' || $column['True_Type'] == 'datetime' || $column['True_Type'] == 'time') && mb_strpos($current_row[$column['Field']], ".") !== false) { $current_row[$column['Field']] = $as_is ? $current_row[$column['Field']] : PMA\libraries\Util::addMicroseconds($current_row[$column['Field']]); $special_chars = htmlspecialchars($current_row[$column['Field']]); } elseif (in_array($column['True_Type'], $gis_data_types)) { // Convert gis data to Well Know Text format $current_row[$column['Field']] = $as_is ? $current_row[$column['Field']] : PMA\libraries\Util::asWKT($current_row[$column['Field']], true); $special_chars = htmlspecialchars($current_row[$column['Field']]); } else { // special binary "characters" if ($column['is_binary'] || $column['is_blob'] && $GLOBALS['cfg']['ProtectBinary'] !== 'all') { $current_row[$column['Field']] = $as_is ? $current_row[$column['Field']] : bin2hex($current_row[$column['Field']]); } // end if $special_chars = htmlspecialchars($current_row[$column['Field']]); //We need to duplicate the first \n or otherwise we will lose //the first newline entered in a VARCHAR or TEXT column $special_chars_encoded = PMA\libraries\Util::duplicateFirstNewline($special_chars); $data = $current_row[$column['Field']]; } // end if... else... //when copying row, it is useful to empty auto-increment column // to prevent duplicate key error if (isset($_REQUEST['default_action']) && $_REQUEST['default_action'] === 'insert') { if ($column['Key'] === 'PRI' && mb_strpos($column['Extra'], 'auto_increment') !== false) { $data = $special_chars_encoded = $special_chars = null; } } // If a timestamp field value is not included in an update // statement MySQL auto-update it to the current timestamp; // however, things have changed since MySQL 4.1, so // it's better to set a fields_prev in this situation $backup_field = '<input type="hidden" name="fields_prev' . $column_name_appendix . '" value="' . htmlspecialchars($current_row[$column['Field']]) . '" />'; return array($real_null_value, $special_chars_encoded, $special_chars, $data, $backup_field); }
/** * test for generating string contains printable bit value of selected data * * @param number $a Value * @param int $b Length * @param string $e Expected output * * @return void * * @dataProvider printableBitValueDataProvider */ public function testPrintableBitValue($a, $b, $e) { $this->assertEquals($e, PMA\libraries\Util::printableBitValue($a, $b)); }