fix: fields default not correctly set in table filler

This commit is contained in:
Fabio Di Stasio 2021-07-01 19:18:57 +02:00
parent 7ca69e51ae
commit faa07a077c
4 changed files with 20 additions and 13 deletions

View File

@ -333,8 +333,15 @@ export class MySQLClient extends AntaresCore {
const details = fieldArr.slice(2).join(' ');
let defaultValue = null;
if (details.includes('DEFAULT'))
if (details.includes('DEFAULT')) {
defaultValue = details.match(/(?<=DEFAULT ).*?$/gs)[0].split(' COMMENT')[0];
const defaultValueArr = defaultValue.split('');
if (defaultValueArr[0] === '\'') {
defaultValueArr.shift();
defaultValueArr.pop();
defaultValue = defaultValueArr.join('');
}
}
const typeAndLength = nameAndType[1].replace(')', '').split('(');

View File

@ -252,32 +252,31 @@ export default {
else {
if ([...NUMBER, ...FLOAT].includes(field.type))
fieldDefault = Number.isNaN(+field.default) ? null : +field.default;
if ([...TEXT, ...LONG_TEXT].includes(field.type)) {
else if ([...TEXT, ...LONG_TEXT].includes(field.type)) {
fieldDefault = field.default
? field.default.includes('\'')
? field.default.split('\'')[1]
: field.default
: '';
}
if ([...TIME, ...DATE].includes(field.type))
else if ([...TIME, ...DATE].includes(field.type))
fieldDefault = field.default;
if (BIT.includes(field.type))
else if (BIT.includes(field.type))
fieldDefault = field.default.replaceAll('\'', '').replaceAll('b', '');
if (DATETIME.includes(field.type)) {
if (field.default && field.default.toLowerCase().includes('current_timestamp')) {
else if (DATETIME.includes(field.type)) {
if (field.default && ['current_timestamp', 'now()'].includes(field.default.toLowerCase())) {
let datePrecision = '';
for (let i = 0; i < field.datePrecision; i++)
datePrecision += i === 0 ? '.S' : 'S';
fieldDefault = moment().format(`YYYY-MM-DD HH:mm:ss${datePrecision}`);
}
else
fieldDefault = field.default;
}
if (field.enumValues)
else if (field.enumValues)
fieldDefault = field.enumValues.replaceAll('\'', '').split(',');
else
fieldDefault = field.default;
}
rowObj[field.name] = { value: fieldDefault };

View File

@ -48,6 +48,7 @@
v-model="optionsProxy.autoIncrement"
class="form-input"
type="number"
:disabled="optionsProxy.autoIncrement === null"
>
</div>
</div>

View File

@ -284,7 +284,7 @@ export default {
.query-area-resizer {
position: absolute;
height: 5px;
height: 4px;
bottom: 40px;
width: 100%;
cursor: ns-resize;