@@ -12,12 +12,12 @@ import (
12
12
)
13
13
14
14
type result struct {
15
- localResv2 * local_result_v2
15
+ chdb_result * chdb_result
16
16
}
17
17
18
- func newChdbResult (cRes * local_result_v2 ) ChdbResult {
18
+ func newChdbResult (cRes * chdb_result ) ChdbResult {
19
19
res := & result {
20
- localResv2 : cRes ,
20
+ chdb_result : cRes ,
21
21
}
22
22
// runtime.SetFinalizer(res, res.Free)
23
23
return res
@@ -26,61 +26,66 @@ func newChdbResult(cRes *local_result_v2) ChdbResult {
26
26
27
27
// Buf implements ChdbResult.
28
28
func (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 )
32
36
}
37
+
33
38
}
34
39
return nil
35
40
}
36
41
37
42
// BytesRead implements ChdbResult.
38
43
func (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 )
41
46
}
42
47
return 0
43
48
}
44
49
45
50
// Elapsed implements ChdbResult.
46
51
func (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 )
49
54
}
50
55
return 0
51
56
}
52
57
53
58
// Error implements ChdbResult.
54
59
func (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 )
58
63
}
59
64
}
60
65
return nil
61
66
}
62
67
63
68
// Free implements ChdbResult.
64
69
func (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
68
73
}
69
74
70
75
}
71
76
72
77
// Len implements ChdbResult.
73
78
func (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 ) )
76
81
}
77
82
return 0
78
83
}
79
84
80
85
// RowsRead implements ChdbResult.
81
86
func (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 )
84
89
}
85
90
return 0
86
91
}
@@ -95,15 +100,10 @@ func (c *result) String() string {
95
100
}
96
101
97
102
type 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
104
104
}
105
105
106
- func newChdbConn (conn * * chdb_conn ) ChdbConn {
106
+ func newChdbConn (conn * chdb_connection ) ChdbConn {
107
107
c := & connection {
108
108
conn : conn ,
109
109
}
@@ -114,28 +114,26 @@ func newChdbConn(conn **chdb_conn) ChdbConn {
114
114
// Close implements ChdbConn.
115
115
func (c * connection ) Close () {
116
116
if c .conn != nil {
117
- closeConn (c .conn )
117
+ chdbCloseConn (c .conn )
118
118
}
119
119
}
120
120
121
121
// Query implements ChdbConn.
122
122
func (c * connection ) Query (queryStr string , formatStr string ) (result ChdbResult , err error ) {
123
-
124
123
if c .conn == nil {
125
124
return nil , fmt .Errorf ("invalid connection" )
126
125
}
127
126
128
- rawConn := * c .conn
129
-
130
- res := queryConn (rawConn , queryStr , formatStr )
127
+ res := chdbQuery (c .conn .internal_data , queryStr , formatStr )
131
128
if res == nil {
132
129
// According to the C ABI of chDB v1.2.0, the C function query_stable_v2
133
130
// returns nil if the query returns no data. This is not an error. We
134
131
// will change this behavior in the future.
135
132
return newChdbResult (res ), nil
136
133
}
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 )
139
137
}
140
138
141
139
return newChdbResult (res ), nil
@@ -148,28 +146,23 @@ func (c *connection) QueryStreaming(queryStr string, formatStr string) (result C
148
146
return nil , fmt .Errorf ("invalid connection" )
149
147
}
150
148
151
- rawConn := * c .conn
152
-
153
- res := queryConnStreaming (rawConn , queryStr , formatStr )
149
+ res := chdbStreamQuery (c .conn .internal_data , queryStr , formatStr )
154
150
if res == nil {
155
151
// According to the C ABI of chDB v1.2.0, the C function query_stable_v2
156
152
// returns nil if the query returns no data. This is not an error. We
157
153
// will change this behavior in the future.
158
- return newStreamingResult (rawConn , res ), nil
154
+ return newStreamingResult (c . conn , res ), nil
159
155
}
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 )
162
158
}
163
159
164
- return newStreamingResult (rawConn , res ), nil
160
+ return newStreamingResult (c . conn , res ), nil
165
161
}
166
162
167
163
func (c * connection ) Ready () bool {
168
164
if c .conn != nil {
169
- deref := * c .conn
170
- if deref != nil {
171
- return deref .connected
172
- }
165
+ return true
173
166
}
174
167
return false
175
168
}
@@ -221,15 +214,15 @@ func NewConnection(argc int, argv []string) (ChdbConn, error) {
221
214
// fmt.Println("arg: ", arg)
222
215
// }
223
216
224
- var conn * * chdb_conn
217
+ var conn * chdb_connection
225
218
var err error
226
219
func () {
227
220
defer func () {
228
221
if r := recover (); r != nil {
229
222
err = fmt .Errorf ("C++ exception: %v" , r )
230
223
}
231
224
}()
232
- conn = connectChdb (len (new_argv ), c_argv )
225
+ conn = chdbConnect (len (new_argv ), c_argv )
233
226
}()
234
227
235
228
if err != nil {
0 commit comments