Skip to content

feat:stmt2 query free result by adapter - #34200

Merged
guanshengliang merged 2 commits into
mainfrom
fix/main/6597880825
Jan 8, 2026
Merged

feat:stmt2 query free result by adapter#34200
guanshengliang merged 2 commits into
mainfrom
fix/main/6597880825

Conversation

@Pengrongkun

Copy link
Copy Markdown
Contributor

Description

Issue(s)

  • Close/close/Fix/fix/Resolve/resolve: Issue Link

Checklist

Please check the items in the checklist if applicable.

  • Is the user manual updated?
  • Are the test cases passed and automated?
  • Is there no significant decrease in test coverage?

Copilot AI review requested due to automatic review settings January 7, 2026 08:58
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Pengrongkun, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new feature that allows stmt2 queries to manage result sets using an adapter mechanism. Specifically, it modifies the stmtUseResult2 function to conditionally release query results based on a useAdapter configuration flag. This change aims to provide more flexible control over result set lifecycle, likely for integration with external components or different memory management strategies. The update also includes comprehensive test cases to ensure the correct behavior of this new adapter-based result handling for both synchronous and asynchronous query executions.

Highlights

  • Adapter-based Result Handling: Introduced a new mechanism in stmtUseResult2 to conditionally manage query results using an adapter. If the useAdapter configuration is enabled, the function transfers ownership of the result set and nullifies the internal pointer, allowing for external management.
  • Configuration Integration: Integrated tconfig.h and added logic to check for a useAdapter item in the system configuration (tsCfg) to determine the result handling strategy.
  • New Test Case for Adapter Functionality: Added a dedicated test case, query_use_adapter, to thoroughly validate the new adapter-based result handling for stmt2 queries. This test covers both synchronous and asynchronous query execution paths with result verification.
  • Enhanced Query Test Robustness: Modified existing stmt2 query tests to execute bind_param and exec operations multiple times within a loop, followed by result fetching and assertions, thereby increasing test coverage and robustness for repeated query executions.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a useAdapter option for stmt2 queries. When enabled, the ownership of the result set (TAOS_RES) is transferred to the caller, who then becomes responsible for freeing it using taos_free_result. This is useful in adapter scenarios where the result set's lifecycle needs to be managed independently of the statement object. The implementation in clientStmt2.c is correct, and new tests have been added to cover this feature. My review found one minor issue in the new test case where an assertion was missing.

ASSERT_EQ(strncmp((char*)row[1], "abc", 3), 0);
ASSERT_EQ(strncmp((char*)row[2], "abc", 3), 0);
row = taos_fetch_row(pRes);
ASSERT_NE(row, nullptr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test fetches the second row from the result set but does not validate its content. This makes the test for the asynchronous query case incomplete. To ensure correctness, assertions should be added for the second row's data, similar to what is done in the synchronous query part of this test.

      ASSERT_NE(row, nullptr);
      ASSERT_EQ(strncmp((char*)row[0], "tb2", 3), 0);
      ASSERT_EQ(strncmp((char*)row[1], "xyz", 3), 0);
      ASSERT_EQ(strncmp((char*)row[2], "abc", 3), 0);

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for querying and freeing result sets through an adapter in the stmt2 implementation. The feature allows the stmt2 prepared statement API to properly manage query results when using the adapter mode.

Key changes:

  • Modified existing query tests to iterate multiple times and fetch result sets
  • Added new test case query_use_adapter to verify adapter-based query result handling
  • Implemented adapter-aware result handling in stmtUseResult2 function

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.

File Description
source/client/test/stmt2Test.cpp Extended existing synchronous and asynchronous query tests to execute 3 iterations with result fetching; added comprehensive test case for adapter mode with both sync and async query scenarios
source/client/src/clientStmt2.c Added adapter detection logic in stmtUseResult2 to transfer ownership of pRequest when useAdapter is enabled, preventing double-free issues

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -2692,6 +2695,17 @@ TAOS_RES* stmtUseResult2(TAOS_STMT2* stmt) {
return NULL;
}

Copilot AI Jan 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent pattern for accessing configuration. The code directly uses the global tsCfg variable, while other parts of the codebase (e.g., clientEnv.c, clientMain.c) use taosGetCfg() to retrieve the configuration. Consider using the taosGetCfg() function for consistency and to ensure proper initialization checks are performed.

Copilot uses AI. Check for mistakes.
Comment thread source/client/src/clientStmt2.c Outdated

SConfigItem* pItem = cfgGetItem(tsCfg, "useAdapter");
if (pItem == NULL) {
STMT2_ELOG_E("Invalid option useAdapter");

Copilot AI Jan 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message "Invalid option useAdapter" is misleading. This error occurs when cfgGetItem returns NULL, which could mean the configuration system hasn't been initialized or the item doesn't exist, not that the option value itself is invalid. Consider using a more descriptive message like "Failed to get useAdapter configuration" or "Configuration item useAdapter not found".

Suggested change
STMT2_ELOG_E("Invalid option useAdapter");
if (tsCfg == NULL) {
STMT2_ELOG_E("Failed to get useAdapter configuration: configuration system not initialized");
} else {
STMT2_ELOG_E("Failed to get useAdapter configuration: configuration item not found");
}

Copilot uses AI. Check for mistakes.
ASSERT_NE(row, nullptr);
ASSERT_EQ(strncmp((char*)row[0], "tb2", 3), 0);
ASSERT_EQ(strncmp((char*)row[1], "xyz", 3), 0);
ASSERT_EQ(strncmp((char*)row[2], "abc", 3), 0);

Copilot AI Jan 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memory leak: The result obtained from taos_stmt2_result should be freed using taos_free_result after use. In the loop, the result from each iteration is not freed, which will cause a resource leak when executing multiple iterations.

Suggested change
ASSERT_EQ(strncmp((char*)row[2], "abc", 3), 0);
ASSERT_EQ(strncmp((char*)row[2], "abc", 3), 0);
taos_free_result(pRes);

Copilot uses AI. Check for mistakes.

taos_stmt2_exec(stmt, NULL);
checkError(stmt, code, __FILE__, __LINE__);
taos_stmt2_exec(stmt, NULL);

Copilot AI Jan 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error checking for taos_stmt2_exec is incorrect. The code checks the return value of the previous taos_stmt2_bind_param call stored in 'code', not the actual return value from taos_stmt2_exec. This should be: code = taos_stmt2_exec(stmt, NULL); checkError(stmt, code, FILE, LINE);

Suggested change
taos_stmt2_exec(stmt, NULL);
code = taos_stmt2_exec(stmt, NULL);

Copilot uses AI. Check for mistakes.
code = taos_stmt2_bind_param(stmt, &bindv, -1);
checkError(stmt, code, __FILE__, __LINE__);

taos_stmt2_exec(stmt, NULL);

Copilot AI Jan 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error checking for taos_stmt2_exec is incorrect. The code checks the return value of the previous taos_stmt2_bind_param call stored in 'code', not the actual return value from taos_stmt2_exec. This should be: code = taos_stmt2_exec(stmt, NULL); checkError(stmt, code, FILE, LINE);

Suggested change
taos_stmt2_exec(stmt, NULL);
code = taos_stmt2_exec(stmt, NULL);

Copilot uses AI. Check for mistakes.
code = taos_stmt2_bind_param(stmt, &bindv, -1);
checkError(stmt, code);

taos_stmt2_exec(stmt, NULL);

Copilot AI Jan 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error checking for taos_stmt2_exec is incorrect. The code checks the return value of the previous taos_stmt2_bind_param call stored in 'code', not the actual return value from taos_stmt2_exec. This should be: code = taos_stmt2_exec(stmt, NULL); checkError(stmt, code, ...);

Suggested change
taos_stmt2_exec(stmt, NULL);
code = taos_stmt2_exec(stmt, NULL);

Copilot uses AI. Check for mistakes.
code = taos_stmt2_bind_param(stmt, &bindv, -1);
checkError(stmt, code);

taos_stmt2_exec(stmt, NULL);

Copilot AI Jan 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error checking for taos_stmt2_exec is incorrect. The code checks the return value of the previous taos_stmt2_bind_param call stored in 'code', not the actual return value from taos_stmt2_exec. This should be: code = taos_stmt2_exec(stmt, NULL); checkError(stmt, code, ...);

Suggested change
taos_stmt2_exec(stmt, NULL);
code = taos_stmt2_exec(stmt, NULL);

Copilot uses AI. Check for mistakes.
Comment on lines +2141 to +2142
row = taos_fetch_row(pRes);
ASSERT_NE(row, nullptr);

Copilot AI Jan 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incomplete test assertions: The test fetches a second row but only checks that it's not null without verifying the content of the second row. This test should also include assertions for row[0], row[1], and row[2] to ensure data correctness, similar to the first test case in the synchronous section.

Copilot uses AI. Check for mistakes.
@guanshengliang
guanshengliang merged commit 973a489 into main Jan 8, 2026
13 of 14 checks passed
@guanshengliang
guanshengliang deleted the fix/main/6597880825 branch January 8, 2026 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants