@@ -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 ("test" )
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,10 +100,10 @@ func (c *result) String() string {
95100}
96101
97102type connection struct {
98- conn * * chdb_conn
103+ conn * chdb_connection
99104}
100105
101- func newChdbConn (conn * * chdb_conn ) ChdbConn {
106+ func newChdbConn (conn * chdb_connection ) ChdbConn {
102107 c := & connection {
103108 conn : conn ,
104109 }
@@ -109,28 +114,26 @@ func newChdbConn(conn **chdb_conn) ChdbConn {
109114// Close implements ChdbConn.
110115func (c * connection ) Close () {
111116 if c .conn != nil {
112- closeConn (c .conn )
117+ chdbCloseConn (c .conn . internal_data )
113118 }
114119}
115120
116121// Query implements ChdbConn.
117122func (c * connection ) Query (queryStr string , formatStr string ) (result ChdbResult , err error ) {
118-
119123 if c .conn == nil {
120124 return nil , fmt .Errorf ("invalid connection" )
121125 }
122126
123- rawConn := * c .conn
124-
125- res := queryConn (rawConn , queryStr , formatStr )
127+ res := chdbQuery (c .conn .internal_data , queryStr , formatStr )
126128 if res == nil {
127129 // According to the C ABI of chDB v1.2.0, the C function query_stable_v2
128130 // returns nil if the query returns no data. This is not an error. We
129131 // will change this behavior in the future.
130132 return newChdbResult (res ), nil
131133 }
132- if res .error_message != nil {
133- return nil , errors .New (ptrToGoString (res .error_message ))
134+ errMsg := chdbResultError (res )
135+ if errMsg != "" {
136+ return nil , errors .New ("test" )
134137 }
135138
136139 return newChdbResult (res ), nil
@@ -143,28 +146,23 @@ func (c *connection) QueryStreaming(queryStr string, formatStr string) (result C
143146 return nil , fmt .Errorf ("invalid connection" )
144147 }
145148
146- rawConn := * c .conn
147-
148- res := queryConnStreaming (rawConn , queryStr , formatStr )
149+ res := chdbStreamQuery (c .conn .internal_data , queryStr , formatStr )
149150 if res == nil {
150151 // According to the C ABI of chDB v1.2.0, the C function query_stable_v2
151152 // returns nil if the query returns no data. This is not an error. We
152153 // will change this behavior in the future.
153- return newStreamingResult (rawConn , res ), nil
154+ return newStreamingResult (c . conn , res ), nil
154155 }
155- if s := streamingResultError (res ); s != nil {
156- return nil , errors .New (* s )
156+ if s := chdbResultError (res ); s != "" {
157+ return nil , errors .New (s )
157158 }
158159
159- return newStreamingResult (rawConn , res ), nil
160+ return newStreamingResult (c . conn , res ), nil
160161}
161162
162163func (c * connection ) Ready () bool {
163164 if c .conn != nil {
164- deref := * c .conn
165- if deref != nil {
166- return deref .connected
167- }
165+ return true
168166 }
169167 return false
170168}
@@ -216,15 +214,15 @@ func NewConnection(argc int, argv []string) (ChdbConn, error) {
216214 // fmt.Println("arg: ", arg)
217215 // }
218216
219- var conn * * chdb_conn
217+ var conn * chdb_connection
220218 var err error
221219 func () {
222220 defer func () {
223221 if r := recover (); r != nil {
224222 err = fmt .Errorf ("C++ exception: %v" , r )
225223 }
226224 }()
227- conn = connectChdb (len (new_argv ), c_argv )
225+ conn = chdbConnect (len (new_argv ), c_argv )
228226 }()
229227
230228 if err != nil {
0 commit comments