diff --git a/example/example_methods.go b/example/example_methods.go index 610ed83..8af6d0e 100644 --- a/example/example_methods.go +++ b/example/example_methods.go @@ -49,6 +49,11 @@ func ConcatAll(tableName, colName string) string { //CreatedTimeTrigger example trigger func CreatedTimeTrigger(td *plgo.TriggerData) *plgo.TriggerRow { + var id int + var value string + td.NewRow.Scan(&id, &value) + td.NewRow.Set(0, id+10) + td.NewRow.Set(1, value+value) return td.NewRow } diff --git a/pl.go b/pl.go index 65c0356..a667531 100644 --- a/pl.go +++ b/pl.go @@ -651,19 +651,20 @@ func (stmt *Stmt) spiArgs(args []interface{}) (valuesP *C.Datum, nullsP *C.char, values := make([]Datum, len(args)) nulls := make([]C.char, len(args)) for i, arg := range args { - if stmt.typeIds[i] == C.JSONBOID { + switch stmt.typeIds[i] { + case C.JSONBOID: jsonData, err := json.Marshal(arg) if err != nil { return nil, nil, err } values[i] = (Datum)(C.jsonb_to_datum(C.CString(string(jsonData)))) - } else if stmt.typeIds[i] == C.JSONOID { + case C.JSONOID: jsonData, err := json.Marshal(arg) if err != nil { return nil, nil, err } values[i] = toDatum(string(jsonData)) - } else { + default: values[i] = toDatum(arg) } nulls[i] = C.char(' ') @@ -958,21 +959,16 @@ func scanVal(oid C.Oid, typeName string, val C.Datum, arg interface{}) error { } } default: - if oid == C.JSONBOID { + switch oid { + case C.JSONBOID: jsonData := []byte(C.GoString(C.datum_to_jsonb_cstring(val))) - if err := json.Unmarshal(jsonData, arg); err != nil { - return err - } - return nil - } - if oid == C.JSONOID { + return json.Unmarshal(jsonData, arg) + case C.JSONOID: jsonData := []byte(C.GoString(C.datum_to_cstring(val))) - if err := json.Unmarshal(jsonData, arg); err != nil { - return err - } - return nil + return json.Unmarshal(jsonData, arg) + default: + return fmt.Errorf("Unsupported type in Scan (%T) %s", arg, typeName) } - return fmt.Errorf("Unsupported type in Scan (%s) %s", reflect.TypeOf(arg).String(), typeName) } return nil } diff --git a/test/plgotest b/test/plgotest index 64cafe8..70113fc 100755 --- a/test/plgotest +++ b/test/plgotest @@ -3,6 +3,6 @@ rm -rf build plgo cd build -sudo make install +sudo make install &> /dev/null cd .. psql -U root -d postgres -c "select plgotest()" diff --git a/test/plgotest.go b/test/plgotest.go index 4ef6197..c0e6791 100644 --- a/test/plgotest.go +++ b/test/plgotest.go @@ -26,7 +26,7 @@ func PLGoTest() { testQueryOutputArrayInt(t) testQueryOutputArrayFloat(t) testJSON(t) - testGoroutines(t) + //testGoroutines(t) } func testConnection(t *log.Logger) { @@ -34,17 +34,13 @@ func testConnection(t *log.Logger) { if err != nil { t.Fatal(err) } - _, err = plgo.Open() - if err == nil { - t.Println("Double openned") - } err = db.Close() if err != nil { t.Fatal(err) } err = db.Close() if err == nil { - t.Println("Double closed") + t.Fatal("Double closed") } } @@ -157,8 +153,7 @@ func testQueryOutputInt(t *log.Logger) { } func testQueryOutputTime(t *log.Logger) { - n := time.Now() - n = n.Add(time.Nanosecond * time.Duration(-n.Nanosecond())) + n := time.Now().Round(time.Second) var tests = []struct { query string args []interface{}