diff --git a/apps/studio/components/interfaces/Storage/__tests__/EmptyBucketModal.test.tsx b/apps/studio/components/interfaces/Storage/__tests__/EmptyBucketModal.test.tsx index a9b79f4daa36b..dd76310edc547 100644 --- a/apps/studio/components/interfaces/Storage/__tests__/EmptyBucketModal.test.tsx +++ b/apps/studio/components/interfaces/Storage/__tests__/EmptyBucketModal.test.tsx @@ -69,7 +69,7 @@ describe(`EmptyBucketModal`, () => { path: `/platform/storage/:ref/buckets/:id/empty`, }) // Called by useStorageExplorerStateSnapshot but seems - // to be unnecessary for succesful test? + // to be unnecessary for successful test? // // useProjectSettingsV2Query -> ProjectSettings // GET /platform/projects/:ref/settings diff --git a/apps/studio/components/interfaces/TableGridEditor/TableEntity.utils.ts b/apps/studio/components/interfaces/TableGridEditor/TableEntity.utils.ts index 41afdff860200..7d208f3b351e5 100644 --- a/apps/studio/components/interfaces/TableGridEditor/TableEntity.utils.ts +++ b/apps/studio/components/interfaces/TableGridEditor/TableEntity.utils.ts @@ -39,12 +39,21 @@ export const formatTableRowsToSQL = (table: SupaTable, rows: any[]) => { // We only check for NULL, array and JSON types, everything else we stringify // given that Postgres can implicitly cast the right type based on the column type + // For string types, we need to deal with escaping single quotes + const stringFormats = ['text', 'varchar'] + if (val === null) { return 'null' } else if (dataType === 'ARRAY') { return `'${JSON.stringify(val).replace('[', '{').replace(/.$/, '}')}'` } else if (format?.includes('json')) { return `${JSON.stringify(val).replace(/\\"/g, '"').replace(/'/g, "''").replace('"', "'").replace(/.$/, "'")}` + } else if ( + typeof format === 'string' && + typeof val === 'string' && + stringFormats.includes(format) + ) { + return `'${val.replaceAll("'", "''")}'` } else { return `'${val}'` } diff --git a/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx b/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx index f835be98f68b7..84dff45cae3d2 100644 --- a/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx +++ b/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx @@ -210,11 +210,13 @@ const EntityListItem: ItemRenderer = ({ connectionString: project?.connectionString, table: supaTable, }) + const formattedRows = rows.map((row) => { - const formattedRow = row - Object.keys(row).map((column) => { - if (typeof row[column] === 'object' && row[column] !== null) - formattedRow[column] = JSON.stringify(formattedRow[column]) + const formattedRow = { ...row } + Object.keys(row).forEach((column) => { + if (typeof row[column] === 'object' && row[column] !== null) { + formattedRow[column] = JSON.stringify(row[column]) + } }) return formattedRow })