2
0

Add support for pointers to pointers

Using types like **string allows the inner pointer to be nil’ed out,
avoiding the need for NullX types.

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
This commit is contained in:
Jonathan Rudenberg
2015-09-06 12:46:47 -04:00
committed by Jack Christensen
parent 4ebb0508b6
commit 272262536b
3 changed files with 150 additions and 21 deletions
+9
View File
@@ -14,6 +14,7 @@ import (
"os"
"os/user"
"path/filepath"
"reflect"
"regexp"
"strconv"
"strings"
@@ -752,6 +753,14 @@ func (c *Conn) sendPreparedQuery(ps *PreparedStatement, arguments ...interface{}
case string:
err = encodeText(wbuf, arguments[i])
default:
if v := reflect.ValueOf(arguments[i]); v.Kind() == reflect.Ptr {
if v.IsNil() {
wbuf.WriteInt32(-1)
continue
} else {
arguments[i] = v.Elem().Interface()
}
}
switch oid {
case BoolOid:
err = encodeBool(wbuf, arguments[i])