11#include " LocalChdb.h"
2- #include " LocalServer.h"
32#include " chdb.h"
3+ #include " chdb-internal.h"
44#include " PythonImporter.h"
55#include " PythonTableCache.h"
6- #include " TableFunctionPython .h"
6+ #include " StoragePython .h"
77
8- #include < mutex>
98#include < Common/logger_useful.h>
109
1110namespace py = pybind11;
1211
1312extern bool inside_main = true ;
1413
15- local_result_v2 * queryToBuffer (
14+ chdb_result * queryToBuffer (
1615 const std::string & queryStr,
1716 const std::string & output_format = " CSV" ,
1817 const std::string & path = {},
@@ -60,7 +59,7 @@ local_result_v2 * queryToBuffer(
6059 argv_char.push_back (const_cast <char *>(arg.c_str ()));
6160
6261 py::gil_scoped_release release;
63- return query_stable_v2 (argv_char.size (), argv_char.data ());
62+ return chdb_query_cmdline (argv_char.size (), argv_char.data ());
6463}
6564
6665// Pybind11 will take over the ownership of the `query_result` object
@@ -218,22 +217,22 @@ connection_wrapper::connection_wrapper(const std::string & conn_str)
218217 argv_char.push_back (const_cast <char *>(arg.c_str ()));
219218 }
220219
221- conn = connect_chdb (argv_char.size (), argv_char.data ());
220+ conn = chdb_connect (argv_char.size (), argv_char.data ());
222221 db_path = path;
223222 is_memory_db = (path == " :memory:" );
224223}
225224
226225connection_wrapper::~connection_wrapper ()
227226{
228227 py::gil_scoped_release release;
229- close_conn (conn);
228+ chdb_close_conn (conn);
230229}
231230
232231void connection_wrapper::close ()
233232{
234233 {
235234 py::gil_scoped_release release;
236- close_conn (conn);
235+ chdb_close_conn (conn);
237236 }
238237 // Ensure that if a new connection is created before this object is destroyed that we don't try to close it.
239238 conn = nullptr ;
@@ -254,15 +253,17 @@ query_result * connection_wrapper::query(const std::string & query_str, const st
254253 CHDB::PythonTableCache::findQueryableObjFromQuery (query_str);
255254
256255 py::gil_scoped_release release;
257- auto * result = query_conn (*conn, query_str.c_str (), format.c_str ());
258- if (result-> len == 0 )
256+ auto * result = chdb_query (*conn, query_str.c_str (), format.c_str ());
257+ if (chdb_result_length ( result) )
259258 {
260259 LOG_DEBUG (getLogger (" CHDB" ), " Empty result returned for query: {}" , query_str);
261260 }
262- if (result->error_message )
261+
262+ auto * error_msg = chdb_result_error (result);
263+ if (error_msg)
263264 {
264- std::string msg_copy (result-> error_message );
265- free_result_v2 (result);
265+ std::string msg_copy (error_msg );
266+ chdb_destroy_query_result (result);
266267 throw std::runtime_error (msg_copy);
267268 }
268269 return new query_result (result, false );
@@ -273,12 +274,12 @@ streaming_query_result * connection_wrapper::send_query(const std::string & quer
273274 CHDB::PythonTableCache::findQueryableObjFromQuery (query_str);
274275
275276 py::gil_scoped_release release;
276- auto * result = query_conn_streaming (*conn, query_str.c_str (), format.c_str ());
277- const auto * error_msg = chdb_streaming_result_error (result);
277+ auto * result = chdb_stream_query (*conn, query_str.c_str (), format.c_str ());
278+ auto * error_msg = chdb_result_error (result);
278279 if (error_msg)
279280 {
280281 std::string msg_copy (error_msg);
281- chdb_destroy_result (result);
282+ chdb_destroy_query_result (result);
282283 throw std::runtime_error (msg_copy);
283284 }
284285
@@ -292,15 +293,16 @@ query_result * connection_wrapper::streaming_fetch_result(streaming_query_result
292293 if (!streaming_result || !streaming_result->get_result ())
293294 return nullptr ;
294295
295- auto * result = chdb_streaming_fetch_result (*conn, streaming_result->get_result ());
296+ auto * result = chdb_stream_fetch_result (*conn, streaming_result->get_result ());
296297
297- if (result-> len == 0 )
298+ if (chdb_result_length ( result) == 0 )
298299 LOG_DEBUG (getLogger (" CHDB" ), " Empty result returned for streaming query" );
299300
300- if (result->error_message )
301+ auto * error_msg = chdb_result_error (result);
302+ if (error_msg)
301303 {
302- std::string msg_copy (result-> error_message );
303- free_result_v2 (result);
304+ std::string msg_copy (error_msg );
305+ chdb_destroy_query_result (result);
304306 throw std::runtime_error (msg_copy);
305307 }
306308
@@ -314,7 +316,7 @@ void connection_wrapper::streaming_cancel_query(streaming_query_result * streami
314316 if (!streaming_result || !streaming_result->get_result ())
315317 return ;
316318
317- chdb_streaming_cancel_query (*conn, streaming_result->get_result ());
319+ chdb_stream_cancel_query (*conn, streaming_result->get_result ());
318320}
319321
320322void cursor_wrapper::execute (const std::string & query_str)
@@ -324,7 +326,7 @@ void cursor_wrapper::execute(const std::string & query_str)
324326
325327 // Use JSONCompactEachRowWithNamesAndTypes format for better type support
326328 py::gil_scoped_release release;
327- current_result = query_conn (conn->get_conn (), query_str.c_str (), " JSONCompactEachRowWithNamesAndTypes" );
329+ current_result = chdb_query (conn->get_conn (), query_str.c_str (), " JSONCompactEachRowWithNamesAndTypes" );
328330}
329331
330332
@@ -389,7 +391,7 @@ PYBIND11_MODULE(_chdb, m)
389391 .def (" view" , &memoryview_wrapper::view);
390392
391393 py::class_<query_result>(m, " query_result" )
392- .def (py::init<local_result_v2 *>(), py::return_value_policy::take_ownership)
394+ .def (py::init<chdb_result *>(), py::return_value_policy::take_ownership)
393395 .def (" data" , &query_result::data)
394396 .def (" bytes" , &query_result::bytes)
395397 .def (" __str__" , &query_result::str)
@@ -399,13 +401,15 @@ PYBIND11_MODULE(_chdb, m)
399401 .def (" size" , &query_result::size)
400402 .def (" rows_read" , &query_result::rows_read)
401403 .def (" bytes_read" , &query_result::bytes_read)
404+ .def (" storage_rows_read" , &query_result::storage_rows_read)
405+ .def (" storage_bytes_read" , &query_result::storage_bytes_read)
402406 .def (" elapsed" , &query_result::elapsed)
403407 .def (" get_memview" , &query_result::get_memview)
404408 .def (" has_error" , &query_result::has_error)
405409 .def (" error_message" , &query_result::error_message);
406410
407411 py::class_<streaming_query_result>(m, " streaming_query_result" )
408- .def (py::init<chdb_streaming_result *>(), py::return_value_policy::take_ownership)
412+ .def (py::init<chdb_result *>(), py::return_value_policy::take_ownership)
409413 .def (" has_error" , &streaming_query_result::has_error)
410414 .def (" error_message" , &streaming_query_result::error_message);
411415
@@ -447,6 +451,8 @@ PYBIND11_MODULE(_chdb, m)
447451 .def (" data_size" , &cursor_wrapper::data_size)
448452 .def (" rows_read" , &cursor_wrapper::rows_read)
449453 .def (" bytes_read" , &cursor_wrapper::bytes_read)
454+ .def (" storage_rows_read" , &cursor_wrapper::storage_rows_read)
455+ .def (" storage_bytes_read" , &cursor_wrapper::storage_bytes_read)
450456 .def (" elapsed" , &cursor_wrapper::elapsed)
451457 .def (" has_error" , &cursor_wrapper::has_error)
452458 .def (" error_message" , &cursor_wrapper::error_message);
@@ -492,7 +498,7 @@ PYBIND11_MODULE(_chdb, m)
492498
493499 auto destroy_import_cache = []()
494500 {
495- DB::LocalServer::cleanupConnection ();
501+ CHDB::chdbCleanupConnection ();
496502 CHDB::PythonTableCache::clear ();
497503 CHDB::PythonImporter::destroy ();
498504 };
0 commit comments