@@ -336,7 +336,7 @@ final class PostgreSQLPluginDriver: LibPQBackedDriver, @unchecked Sendable {
336336
337337 func fetchTableDDL( table: String , schema: String ? ) async throws -> String {
338338 let safeTable = escapeLiteral ( table)
339- let quotedTable = " \" \ ( table. replacingOccurrences ( of : " \" " , with : " \" \" " ) ) \" "
339+ let quotedTable = quoteIdentifier ( table)
340340 let caps = versionedCapabilities
341341
342342 let identityClause : String = caps. hasIdentityColumns ? """
@@ -431,7 +431,7 @@ final class PostgreSQLPluginDriver: LibPQBackedDriver, @unchecked Sendable {
431431 var parts = columnDefs
432432 parts. append ( contentsOf: constraints)
433433
434- let quotedSchema = " \" \ ( core. currentSchema. replacingOccurrences ( of : " \" " , with : " \" \" " ) ) \" "
434+ let quotedSchema = quoteIdentifier ( core. currentSchema)
435435 let ddl = " CREATE TABLE \( quotedSchema) . \( quotedTable) ( \n " +
436436 parts. joined ( separator: " , \n " ) +
437437 " \n ); "
@@ -599,9 +599,9 @@ final class PostgreSQLPluginDriver: LibPQBackedDriver, @unchecked Sendable {
599599 let incrementBy = row [ 4 ] . asText ?? " 1 "
600600 let cycle = row [ 5 ] . asText == " t " ? " CYCLE " : " "
601601 let lastValue = row. count > 6 ? row [ 6 ] . asText : nil
602- let quotedSeqName = " \" \ ( seqName. replacingOccurrences ( of : " \" " , with : " \" \" " ) ) \" "
603- let escapedSchemaForLiteral = schemaName . replacingOccurrences ( of : " ' " , with : " '' " )
604- let escapedSeqForLiteral = seqName . replacingOccurrences ( of : " ' " , with : " '' " )
602+ let quotedSeqName = quoteIdentifier ( seqName)
603+ let escapedSchemaForLiteral = escapeStringLiteral ( schemaName )
604+ let escapedSeqForLiteral = escapeStringLiteral ( seqName )
605605 var ddl = " CREATE SEQUENCE \( quotedSeqName) INCREMENT BY \( incrementBy) "
606606 + " MINVALUE \( minVal) MAXVALUE \( maxVal) "
607607 + " START WITH \( startVal) \( cycle) ; "
@@ -692,7 +692,7 @@ final class PostgreSQLPluginDriver: LibPQBackedDriver, @unchecked Sendable {
692692 }
693693
694694 func createDatabase( _ request: PluginCreateDatabaseRequest ) async throws {
695- let quotedName = request. name. replacingOccurrences ( of : " \" " , with : " \" \" " )
695+ let quotedName = quoteIdentifier ( request. name)
696696
697697 guard let encoding = request. values [ " encoding " ] else {
698698 throw LibPQPluginError (
@@ -709,7 +709,7 @@ final class PostgreSQLPluginDriver: LibPQBackedDriver, @unchecked Sendable {
709709 )
710710 }
711711
712- var sql = " CREATE DATABASE \" \ ( quotedName) \" ENCODING ' \( encoding) ' "
712+ var sql = " CREATE DATABASE \( quotedName) ENCODING ' \( encoding) ' "
713713
714714 let supportsProvider = versionedCapabilities. hasDatabaseICULocale
715715 let provider = supportsProvider ? ( request. values [ " provider " ] ?? " libc " ) : " libc "
@@ -789,8 +789,7 @@ final class PostgreSQLPluginDriver: LibPQBackedDriver, @unchecked Sendable {
789789 }
790790
791791 func dropDatabase( name: String ) async throws {
792- let escapedName = name. replacingOccurrences ( of: " \" " , with: " \" \" " )
793- _ = try await execute ( query: " DROP DATABASE \" \( escapedName) \" " )
792+ _ = try await execute ( query: " DROP DATABASE \( quoteIdentifier ( name) ) " )
794793 }
795794
796795 private struct Template1Defaults {
0 commit comments