Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
Fix NULL conversion for optional fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrej Mihajlov committed Oct 8, 2016
1 parent e94cfcf commit 5e1079a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Sources/PostgreSQL/Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public class Database {
defer {
for i in 0..<values.count {
let p = paramsValues[i]
if p == nil {
continue
}

let mp = UnsafeMutablePointer(mutating: p)
mp?.deinitialize()
var i = 0
Expand Down Expand Up @@ -85,6 +89,13 @@ public class Database {
.allocate(capacity: values.count)

for i in 0..<values.count {
// PQexecParams converts nil pointer to NULL.
// see: https://www.postgresql.org/docs/9.1/static/libpq-exec.html
if values[i] == .null {
paramsValues[i] = nil
continue
}

var ch = values[i].string?.bytes ?? []
ch.append(0)

Expand Down

0 comments on commit 5e1079a

Please sign in to comment.