console: surround string type column default value with quotes (close #4371) (#4423)

This commit is contained in:
ShahAnuj2610 2020-04-17 21:32:13 +05:30 committed by GitHub
parent b2d65d16d3
commit bf719cbf34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 55 deletions

View File

@ -31,6 +31,7 @@ The order, collapsed state of columns and page size is now persisted across page
- console: decouple data rows and count fetch in data browser to account for really large tables (close #3793) (#4269)
- console: update cookie policy for API calls to "same-origin"
- console: redirect to /:table/browse from /:table (close #4330) (#4374)
- console: surround string type column default value with quotes (close #4371) (#4423)
- console: add undefined check to fix error (close #4444) (#4445)
- docs: add One-Click Render deployment guide (close #3683) (#4209)
- server: add support for `_inc` on `real`, `double`, `numeric` and `money` (fix #3573)

View File

@ -9,7 +9,7 @@ import {
import { UPDATE_MIGRATION_STATUS_ERROR } from '../../../Main/Actions';
import { setTable } from '../DataActions.js';
import { isPostgresFunction } from '../utils';
import { isColTypeString, isPostgresFunction } from '../utils';
import { sqlEscapeText } from '../../../Common/utils/sqlUtils';
import { getRunSqlQuery } from '../../../Common/utils/v1QueryUtils';
import { getTableModifyRoute } from '../../../Common/utils/routesUtils';
@ -188,7 +188,7 @@ const createTableSql = () => {
currentCols[i].default.value !== ''
) {
if (
currentCols[i].type === 'text' &&
isColTypeString(currentCols[i].type) &&
!isPostgresFunction(currentCols[i].default.value)
) {
// if a column type is text and if it has a non-func default value, add a single quote by default

View File

@ -27,7 +27,7 @@ import {
getUniqueConstraintName,
} from '../Common/Components/utils';
import { isPostgresFunction } from '../utils';
import { isColTypeString, isPostgresFunction } from '../utils';
import {
sqlEscapeText,
getCreateCheckConstraintSql,
@ -1182,7 +1182,7 @@ const addColSql = (
let defWithQuotes = "''";
const checkIfFunctionFormat = isPostgresFunction(colDefault);
if (colType === 'text' && colDefault !== '' && !checkIfFunctionFormat) {
if (isColTypeString(colType) && colDefault !== '' && !checkIfFunctionFormat) {
defWithQuotes = "'" + colDefault + "'";
} else {
defWithQuotes = colDefault;
@ -1544,11 +1544,11 @@ const saveColumnChangesSql = (colName, column, onSuccess) => {
}
const colDefaultWithQuotes =
colType === 'text' && !isPostgresFunction(colDefault)
isColTypeString(colType) && !isPostgresFunction(colDefault)
? `'${colDefault}'`
: colDefault;
const originalColDefaultWithQuotes =
colType === 'text' && !isPostgresFunction(originalColDefault)
isColTypeString(colType) && !isPostgresFunction(originalColDefault)
? `'${originalColDefault}'`
: originalColDefault;

View File

@ -667,3 +667,6 @@ WHERE
AND relname = '${tableName}';
`;
};
export const isColTypeString = colType =>
['text', 'varchar', 'char', 'bpchar', 'name'].includes(colType);