1
0
mirror of https://github.com/phpmyadmin/phpmyadmin.git synced 2026-10-28 07:41:55 +03:00

Merge pull request #582 from kasunchathuranga/fractionalSecs

Use fractional seconds in time, datetime and timestamp
This commit is contained in:
Isaac Bennetch
2013-08-27 06:37:30 -07:00
7 changed files with 526 additions and 216 deletions

View File

@@ -203,10 +203,12 @@ function PMA_addDatepicker($this_element, options)
stepMinutes: 1,
stepHours: 1,
showSecond: true,
showMillisec: true,
showMicrosec: true,
showTimepicker: showTimeOption,
showButtonPanel: false,
dateFormat: 'yy-mm-dd', // yy means year with four digits
timeFormat: 'HH:mm:ss',
timeFormat: 'HH:mm:ss.lc',
altFieldTimeOnly: false,
showAnim: '',
beforeShow: function (input, inst) {

File diff suppressed because it is too large Load Diff

View File

@@ -985,11 +985,24 @@ function PMA_makegrid(t, enableResize, enableReorder, enableVisib, enableGridEdi
// (after adding a datepicker, the input field doesn't display the time anymore, only the date)
if (is_null
|| current_datetime_value == '0000-00-00'
|| current_datetime_value == '0000-00-00 00:00:00'
|| current_datetime_value == '0000-00-00 00:00:00.000000'
) {
$input_field.val(current_datetime_value);
} else {
$editArea.datetimepicker('setDate', current_datetime_value);
var date;
if (current_datetime_value.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{6}$/)) {
date = new Date(current_datetime_value.substring(0, 10));
var hour = current_datetime_value.substring(11, 13);
var min = current_datetime_value.substring(14, 16);
var sec = current_datetime_value.substring(17, 19);
var milli = current_datetime_value.substring(20, 23);
var micro = current_datetime_value.substring(23);
date.setHours(hour, min, sec, milli);
date.setMicroseconds(micro);
} else {
date = new Date(current_datetime_value);
}
$editArea.datetimepicker('setDate', date);
}
$editArea.append('<div class="cell_edit_hint">' + g.cellEditHint + '</div>');

View File

@@ -132,6 +132,7 @@ function isDate(val, tmstmp)
* The following patterns are accepted in this validation (accepted in mysql as well)
* 1) 2:3:4
* 2) 2:23:43
* 3) 2:23:43.123456
*/
function isTime(val)
{
@@ -142,7 +143,7 @@ function isTime(val)
}
}
val = arrayVal.join(":");
var tmexp = new RegExp(/^(([0-1][0-9])|(2[0-3])):((0[0-9])|([1-5][0-9])):((0[0-9])|([1-5][0-9]))$/);
var tmexp = new RegExp(/^(([0-1][0-9])|(2[0-3])):((0[0-9])|([1-5][0-9])):((0[0-9])|([1-5][0-9]))(\.[0-9]{1,6}){0,1}$/);
return tmexp.test(val);
}

View File

@@ -47,6 +47,7 @@ class PMA_DisplayResults
const DATE_FIELD = 'date';
const DATETIME_FIELD = 'datetime';
const TIMESTAMP_FIELD = 'timestamp';
const TIME_FIELD = 'time';
const STRING_FIELD = 'string';
const GEOMETRY_FIELD = 'geometry';
const BLOB_FIELD = 'BLOB';
@@ -3892,6 +3893,11 @@ class PMA_DisplayResults
);
$formatted = true;
}
} elseif ((substr($meta->type, 0, 9) == self::TIMESTAMP_FIELD)
|| ($meta->type == self::DATETIME_FIELD)
|| ($meta->type == self::TIME_FIELD)
) {
$column = PMA_Util::addMicroseconds($column);
}
if ($formatted) {

View File

@@ -4291,5 +4291,26 @@ class PMA_Util
return $result;
}
/**
* Add fractional seconds to time, datetime and timestamp strings.
* If the string contsins fractional seconds,
* pads it with 0s upto 6 decimal places.
*
* @param string $value time, datetime or timestamp strings
*
* @return string time, datetime or timestamp strings with fractional seconds
*/
public static function addMicroseconds($value)
{
if (empty($value) || $value == 'CURRENT_TIMESTAMP') {
return $value;
} elseif (strpos($value, '.')) {
$value .= '000000';
return substr($value, 0, strpos($value, '.') + 7);
} else {
return $value . '.000000';
}
}
}
?>

View File

@@ -1668,6 +1668,11 @@ function PMA_getSpecialCharsAndBackupFieldForExistingRow(
$special_chars = PMA_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'
) {
$special_chars = PMA_Util::addMicroseconds($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']] = PMA_Util::asWKT(
@@ -1753,6 +1758,11 @@ function PMA_getSpecialCharsAndBackupFieldForInsertingMode(
if ($column['True_Type'] == 'bit') {
$special_chars = PMA_Util::convertBitDefaultValue($column['Default']);
} elseif (substr($column['True_Type'], 0, 9) == 'timestamp'
|| $column['True_Type'] == 'datetime'
|| $column['True_Type'] == 'time'
) {
$special_chars = PMA_Util::addMicroseconds($column['Default']);
} else {
$special_chars = htmlspecialchars($column['Default']);
}
@@ -2416,9 +2426,20 @@ function PMA_verifyWhetherValueCanBeTruncatedAndAppendExtraData(
. PMA_Util::backquote($table)
. ' WHERE ' . $_REQUEST['where_clause'][0];
if ($GLOBALS['dbi']->fetchValue($sql_for_real_value) !== false) {
$extra_data['truncatableFieldValue']
= $GLOBALS['dbi']->fetchValue($sql_for_real_value);
$result = $GLOBALS['dbi']->tryQuery(
$sql_for_real_value, 0, PMA_DBI_QUERY_STORE, false
);
$fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
$meta = $fields_meta[0];
$new_value = $GLOBALS['dbi']->fetchValue($result);
if ($new_value !== false) {
if ((substr($meta->type, 0, 9) == 'timestamp')
|| ($meta->type == 'datetime')
|| ($meta->type == 'time')
) {
$new_value = PMA_Util::addMicroseconds($new_value);
}
$extra_data['truncatableFieldValue'] = $new_value;
} else {
$extra_data['isNeedToRecheck'] = false;
}