package nosqldb_sdk import ( "C" ) import ( "encoding/json" "nosql_db_sdk_ffi/util/ptrproxy" "unsafe" "github.com/oracle/nosql-go-sdk/nosqldb" ) // StringArray 構造体を定義 type StringArray struct { List []string `json:"list"` } //export ffi_nosqldb_query_result_get_results func ffi_nosqldb_query_result_get_results(unsafe_nosqldb_query_result_ptr NosqldbQueryResult) (*C.char, Error) { nosqldb_query_result_ptr, ok := ptrproxy.Deref(unsafe.Pointer(unsafe_nosqldb_query_result_ptr)) if !ok { return nil, C.CString("NosqldbQureyResultPtr cannot deref") } query_result := (*nosqldb.QueryResult)(nosqldb_query_result_ptr) res, err := query_result.GetResults() if err != nil { return nil, C.CString(err.Error()) } // []*types.MapValue型から[]string型に変換 stringSlice := make([]string, len(res)) for i, go_map := range res { value, err := json.Marshal(go_map) if !ok { return nil, C.CString(err.Error()) } stringSlice[i] = string(value) } strArr := StringArray{ List: stringSlice, } jsonData, err := json.Marshal(strArr) if err != nil { return nil, C.CString(err.Error()) } return C.CString(string(jsonData)), nil }