diff --git a/Sources/PostgresStORM.swift b/Sources/PostgresStORM.swift index 149915f..8cd8479 100644 --- a/Sources/PostgresStORM.swift +++ b/Sources/PostgresStORM.swift @@ -73,9 +73,9 @@ open class PostgresStORM: StORM, StORMProtocol { let result = thisConnection.server.exec(statement: statement, params: params) // set exec message - errorMsg = thisConnection.server.errorMessage().trimmingCharacters(in: .whitespacesAndNewlines) - if StORMdebug { LogFile.info("Error msg: \(errorMsg)", logFile: "./StORMlog.txt") } + errorMsg = thisConnection.server.errorMessage().trimmingCharacters(in: .whitespacesAndNewlines) if isError() { + if StORMdebug { LogFile.info("Error msg: \(errorMsg)", logFile: "./StORMlog.txt") } thisConnection.server.close() throw StORMError.error(errorMsg) } @@ -107,8 +107,8 @@ open class PostgresStORM: StORM, StORMProtocol { // set exec message errorMsg = thisConnection.server.errorMessage().trimmingCharacters(in: .whitespacesAndNewlines) - if StORMdebug { LogFile.info("Error msg: \(errorMsg)", logFile: "./StORMlog.txt") } if isError() { + if StORMdebug { LogFile.info("Error msg: \(errorMsg)", logFile: "./StORMlog.txt") } thisConnection.server.close() throw StORMError.error(errorMsg) } diff --git a/Sources/parseRows.swift b/Sources/parseRows.swift index 2e6c527..3ee2410 100644 --- a/Sources/parseRows.swift +++ b/Sources/parseRows.swift @@ -61,7 +61,9 @@ extension PostgresStORM { let output = result.getFieldString(tupleIndex: x, fieldIndex: f) let formatter = DateFormatter() formatter.dateFormat = "yyyy/MM/dd hh:mm Z" - params[result.fieldName(index: f)!] = formatter.date(from: output!) + if let output = output { + params[result.fieldName(index: f)!] = formatter.date(from: output) + } // time // timestamp