Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go: ['1.20', '1.21']
go: ['1.14', '1.15', '1.16', '1.17', '1.18', '1.19', '1.20', '1.21']
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

temponary for check CI on old versions of go (because minimal version of go in go.mod - 1.14)
before merge - need to remove my changes

os: ['ubuntu-latest', 'windows-latest']
include:
- go: 1.16 # Oldest Go version still tested (Windows requires 1.20+ due to https://github.com/golang/go/issues/57455)
Expand Down
9 changes: 3 additions & 6 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func ScanToProtobuf(input string) (result []byte, err error) {
}

// ParseToProtobuf - Parses the given SQL statement into a parse tree (Protobuf format)
func ParseToProtobuf(input string) (result []byte, err error) {
func ParseToProtobuf(input string) ([]byte, error) {
inputC := C.CString(input)
defer C.free(unsafe.Pointer(inputC))

Expand All @@ -110,13 +110,10 @@ func ParseToProtobuf(input string) (result []byte, err error) {
defer C.pg_query_free_protobuf_parse_result(resultC)

if resultC.error != nil {
err = newPgQueryError(resultC.error)
return
return nil, newPgQueryError(resultC.error)
}

result = []byte(C.GoStringN(resultC.parse_tree.data, C.int(resultC.parse_tree.len)))

return
return toBytes(C.GoStringN(resultC.parse_tree.data, C.int(resultC.parse_tree.len))), nil
}

// DeparseFromProtobuf - Deparses the given Protobuf format parse tree into a SQL statement
Expand Down
19 changes: 19 additions & 0 deletions parser/string_to_bytes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build !go1.20
// +build !go1.20

package parser

import (
"reflect"
"unsafe"
)

func toBytes(s string) (b []byte) {
pb := (*reflect.SliceHeader)(unsafe.Pointer(&b))
ps := (*reflect.StringHeader)(unsafe.Pointer(&s))
pb.Data = ps.Data
pb.Len = ps.Len
pb.Cap = ps.Len

return b
}
14 changes: 14 additions & 0 deletions parser/string_to_bytes_go1.20.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build go1.20
// +build go1.20

package parser

import "unsafe"

func toBytes(s string) (b []byte) {
if s == "" {
return nil
}

return unsafe.Slice(unsafe.StringData(s), len(s))

Check failure on line 13 in parser/string_to_bytes_go1.20.go

View workflow job for this annotation

GitHub Actions / build (1.20, ubuntu-latest)

unsafe.StringData requires go1.20 or later (-lang was set to go1.14; check go.mod)

Check failure on line 13 in parser/string_to_bytes_go1.20.go

View workflow job for this annotation

GitHub Actions / build (1.20, windows-latest)

unsafe.StringData requires go1.20 or later (-lang was set to go1.14; check go.mod)
}
Loading