Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ jobs:
matrix:
go: ['1.20', '1.21']
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)
os: ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- name: Set up Go 1.x
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module github.com/pganalyze/pg_query_go/v6

go 1.14
go 1.20

require (
github.com/google/go-cmp v0.5.5
google.golang.org/protobuf v1.31.0
)

require golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
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
14 changes: 14 additions & 0 deletions parser/string_to_bytes.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))
}
Loading