@@ -12,12 +12,12 @@ import (
1212)
1313
1414type result struct {
15- localResv2 * local_result_v2
15+ chdb_result * chdb_result
1616}
1717
18- func newChdbResult (cRes * local_result_v2 ) ChdbResult {
18+ func newChdbResult (cRes * chdb_result ) ChdbResult {
1919 res := & result {
20- localResv2 : cRes ,
20+ chdb_result : cRes ,
2121 }
2222 // runtime.SetFinalizer(res, res.Free)
2323 return res
@@ -26,61 +26,66 @@ func newChdbResult(cRes *local_result_v2) ChdbResult {
2626
2727// Buf implements ChdbResult.
2828func (c * result ) Buf () []byte {
29- if c .localResv2 != nil {
30- if c .localResv2 .buf != nil && c .localResv2 .len > 0 {
31- return unsafe .Slice (c .localResv2 .buf , c .localResv2 .len )
29+ if c .chdb_result != nil {
30+ buf := chdbResultBuffer (c .chdb_result )
31+ if buf != nil {
32+ // Assuming we have a way to get the length of the buffer
33+ // Thlis is a placeholder; replace with actual length retrieva logic
34+ length := c .Len () // Replace with actual length
35+ return unsafe .Slice (buf , length )
3236 }
37+
3338 }
3439 return nil
3540}
3641
3742// BytesRead implements ChdbResult.
3843func (c * result ) BytesRead () uint64 {
39- if c .localResv2 != nil {
40- return c . localResv2 . bytes_read
44+ if c .chdb_result != nil {
45+ return chdbResultBytesRead ( c . chdb_result )
4146 }
4247 return 0
4348}
4449
4550// Elapsed implements ChdbResult.
4651func (c * result ) Elapsed () float64 {
47- if c .localResv2 != nil {
48- return c . localResv2 . elapsed
52+ if c .chdb_result != nil {
53+ return chdbResultElapsed ( c . chdb_result )
4954 }
5055 return 0
5156}
5257
5358// Error implements ChdbResult.
5459func (c * result ) Error () error {
55- if c .localResv2 != nil {
56- if c . localResv2 . error_message != nil {
57- return errors .New (ptrToGoString ( c . localResv2 . error_message ) )
60+ if c .chdb_result != nil {
61+ if s := chdbResultError ( c . chdb_result ); s != "" {
62+ return errors .New (s )
5863 }
5964 }
6065 return nil
6166}
6267
6368// Free implements ChdbResult.
6469func (c * result ) Free () {
65- if c .localResv2 != nil {
66- freeResultV2 (c .localResv2 )
67- c .localResv2 = nil
70+ if c .chdb_result != nil {
71+ chdbDestroyQueryResult (c .chdb_result )
72+ c .chdb_result = nil
6873 }
6974
7075}
7176
7277// Len implements ChdbResult.
7378func (c * result ) Len () int {
74- if c .localResv2 != nil {
75- return int (c . localResv2 . len )
79+ if c .chdb_result != nil {
80+ return int (chdbResultLen ( c . chdb_result ) )
7681 }
7782 return 0
7883}
7984
8085// RowsRead implements ChdbResult.
8186func (c * result ) RowsRead () uint64 {
82- if c .localResv2 != nil {
83- return c . localResv2 . rows_read
87+ if c .chdb_result != nil {
88+ return chdbResultRowsRead ( c . chdb_result )
8489 }
8590 return 0
8691}
@@ -95,15 +100,10 @@ func (c *result) String() string {
95100}
96101
97102type connection struct {
98- conn * * chdb_conn
99- }
100-
101- // CancelQuery implements ChdbConn.
102- func (c * connection ) CancelQuery (query ChdbResult ) (err error ) {
103- panic ("unimplemented" )
103+ conn * chdb_connection
104104}
105105
106- func newChdbConn (conn * * chdb_conn ) ChdbConn {
106+ func newChdbConn (conn * chdb_connection ) ChdbConn {
107107 c := & connection {
108108 conn : conn ,
109109 }
@@ -114,28 +114,26 @@ func newChdbConn(conn **chdb_conn) ChdbConn {
114114// Close implements ChdbConn.
115115func (c * connection ) Close () {
116116 if c .conn != nil {
117- closeConn (c .conn )
117+ chdbCloseConn (c .conn )
118118 }
119119}
120120
121121// Query implements ChdbConn.
122122func (c * connection ) Query (queryStr string , formatStr string ) (result ChdbResult , err error ) {
123-
124123 if c .conn == nil {
125124 return nil , fmt .Errorf ("invalid connection" )
126125 }
127126
128- rawConn := * c .conn
129-
130- res := queryConn (rawConn , queryStr , formatStr )
127+ res := chdbQuery (c .conn .internal_data , queryStr , formatStr )
131128 if res == nil {
132129 // According to the C ABI of chDB v1.2.0, the C function query_stable_v2
133130 // returns nil if the query returns no data. This is not an error. We
134131 // will change this behavior in the future.
135132 return newChdbResult (res ), nil
136133 }
137- if res .error_message != nil {
138- return nil , errors .New (ptrToGoString (res .error_message ))
134+ errMsg := chdbResultError (res )
135+ if errMsg != "" {
136+ return nil , errors .New (errMsg )
139137 }
140138
141139 return newChdbResult (res ), nil
@@ -148,28 +146,23 @@ func (c *connection) QueryStreaming(queryStr string, formatStr string) (result C
148146 return nil , fmt .Errorf ("invalid connection" )
149147 }
150148
151- rawConn := * c .conn
152-
153- res := queryConnStreaming (rawConn , queryStr , formatStr )
149+ res := chdbStreamQuery (c .conn .internal_data , queryStr , formatStr )
154150 if res == nil {
155151 // According to the C ABI of chDB v1.2.0, the C function query_stable_v2
156152 // returns nil if the query returns no data. This is not an error. We
157153 // will change this behavior in the future.
158- return newStreamingResult (rawConn , res ), nil
154+ return newStreamingResult (c . conn , res ), nil
159155 }
160- if s := streamingResultError (res ); s != nil {
161- return nil , errors .New (* s )
156+ if s := chdbResultError (res ); s != "" {
157+ return nil , errors .New (s )
162158 }
163159
164- return newStreamingResult (rawConn , res ), nil
160+ return newStreamingResult (c . conn , res ), nil
165161}
166162
167163func (c * connection ) Ready () bool {
168164 if c .conn != nil {
169- deref := * c .conn
170- if deref != nil {
171- return deref .connected
172- }
165+ return true
173166 }
174167 return false
175168}
@@ -221,15 +214,15 @@ func NewConnection(argc int, argv []string) (ChdbConn, error) {
221214 // fmt.Println("arg: ", arg)
222215 // }
223216
224- var conn * * chdb_conn
217+ var conn * chdb_connection
225218 var err error
226219 func () {
227220 defer func () {
228221 if r := recover (); r != nil {
229222 err = fmt .Errorf ("C++ exception: %v" , r )
230223 }
231224 }()
232- conn = connectChdb (len (new_argv ), c_argv )
225+ conn = chdbConnect (len (new_argv ), c_argv )
233226 }()
234227
235228 if err != nil {
0 commit comments