(
table: DBTable,
isDBMLFlow: boolean = false
)
| 98 | |
| 99 | // Helper function to properly quote table/schema names with special characters |
| 100 | const getQuotedTableName = ( |
| 101 | table: DBTable, |
| 102 | isDBMLFlow: boolean = false |
| 103 | ): string => { |
| 104 | // Check if a name is already quoted |
| 105 | const isAlreadyQuoted = (name: string) => { |
| 106 | return ( |
| 107 | (name.startsWith('"') && name.endsWith('"')) || |
| 108 | (name.startsWith('`') && name.endsWith('`')) || |
| 109 | (name.startsWith('[') && name.endsWith(']')) |
| 110 | ); |
| 111 | }; |
| 112 | |
| 113 | // Only add quotes if needed and not already quoted |
| 114 | const quoteIfNeeded = (name: string) => { |
| 115 | if (isAlreadyQuoted(name)) { |
| 116 | return name; |
| 117 | } |
| 118 | const needsQuoting = /[^a-zA-Z0-9_]/.test(name) || isDBMLFlow; |
| 119 | return needsQuoting ? `"${name}"` : name; |
| 120 | }; |
| 121 | |
| 122 | if (table.schema) { |
| 123 | const quotedSchema = quoteIfNeeded(table.schema); |
| 124 | const quotedTable = quoteIfNeeded(table.name); |
| 125 | return `${quotedSchema}.${quotedTable}`; |
| 126 | } else { |
| 127 | return quoteIfNeeded(table.name); |
| 128 | } |
| 129 | }; |
| 130 | |
| 131 | const getQuotedFieldName = ( |
| 132 | fieldName: string, |
no test coverage detected