Skip to content

Comments

fix:根据id查询数据时,如id为空值会导致查询结果可能为多条记录引发TooManyResultsException问题修复#212

Merged
lu-yg merged 1 commit intoopentiny:developfrom
easychn:develop-queryfix
Apr 27, 2025
Merged

fix:根据id查询数据时,如id为空值会导致查询结果可能为多条记录引发TooManyResultsException问题修复#212
lu-yg merged 1 commit intoopentiny:developfrom
easychn:develop-queryfix

Conversation

@JasonWellGao
Copy link
Contributor

@JasonWellGao JasonWellGao commented Apr 23, 2025

fix:根据id查询数据时,如id为空值会导致查询结果可能为多条记录引发TooManyResultsException问题修复

Summary by CodeRabbit

  • Refactor
    • Simplified multiple database queries by making the ID filter unconditional, ensuring that queries always require and use the ID parameter.
  • Bug Fixes
    • Improved reliability of data retrieval by removing conditional checks on ID parameters in various queries, reducing the risk of incomplete filtering.

@coderabbitai
Copy link

coderabbitai bot commented Apr 23, 2025

Walkthrough

The changes across multiple MyBatis XML mapper files remove conditional checks for the id parameter in various SQL SELECT and UPDATE statements. Previously, these queries included the id = #{id} condition only if id was not null, using <if test="id != null"> blocks. The updates eliminate these conditional blocks and directly include the id = #{id} condition in the WHERE clauses, making the use of the id parameter mandatory and unconditional in the affected queries. No changes were made to public APIs or entity declarations.

Changes

File(s) Change Summary
.../mappers/AppExtensionMapper.xml
.../mappers/AppMapper.xml
Removed conditional <if> checks for id in WHERE clauses; now always filter by id unconditionally.
.../mappers/BlockGroupMapper.xml
.../mappers/BlockHistoryMapper.xml
.../mappers/BlockMapper.xml
Simplified queries by removing conditional checks for id in WHERE clauses; id filter is now unconditional.
.../mappers/ComponentLibraryMapper.xml
.../mappers/ComponentMapper.xml
Eliminated conditional logic for id in select statements; id filter is always applied.
.../mappers/DatasourceMapper.xml Made id filter unconditional in the WHERE clause of select statement.
.../mappers/I18nEntryMapper.xml Removed conditional check for id; query always filters by id.
.../mappers/MaterialMapper.xml Simplified query by always applying id filter without conditional check.
.../mappers/PageMapper.xml WHERE clause now always includes P.id = #{id} without conditional logic.
.../mappers/PageTemplateMapper.xml Removed conditional and redundant AND; always filters by id.
.../mappers/PlatformMapper.xml Eliminated conditional check; always filters by id in select statement.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Mapper
    participant Database

    Client->>Mapper: Request entity by id
    Mapper->>Database: SELECT ... WHERE id = #{id}
    Database-->>Mapper: Return result
    Mapper-->>Client: Return entity
Loading

Poem

A hop and a skip through the mapper files,
Gone are the checks, replaced with new styles.
No more "if id is not null," just straight to the chase,
Every query now finds its place.
Simpler and cleaner, the SQLs all cheer,
The rabbit approves—let's give a big ear! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3560053 and 59aefee.

📒 Files selected for processing (13)
  • base/src/main/resources/mappers/AppExtensionMapper.xml (1 hunks)
  • base/src/main/resources/mappers/AppMapper.xml (1 hunks)
  • base/src/main/resources/mappers/BlockGroupMapper.xml (1 hunks)
  • base/src/main/resources/mappers/BlockHistoryMapper.xml (1 hunks)
  • base/src/main/resources/mappers/BlockMapper.xml (1 hunks)
  • base/src/main/resources/mappers/ComponentLibraryMapper.xml (1 hunks)
  • base/src/main/resources/mappers/ComponentMapper.xml (1 hunks)
  • base/src/main/resources/mappers/DatasourceMapper.xml (1 hunks)
  • base/src/main/resources/mappers/I18nEntryMapper.xml (1 hunks)
  • base/src/main/resources/mappers/MaterialMapper.xml (1 hunks)
  • base/src/main/resources/mappers/PageMapper.xml (1 hunks)
  • base/src/main/resources/mappers/PageTemplateMapper.xml (1 hunks)
  • base/src/main/resources/mappers/PlatformMapper.xml (1 hunks)
🔇 Additional comments (13)
base/src/main/resources/mappers/PageTemplateMapper.xml (1)

174-174: Enforce mandatory ID filter in queryPageTemplateById
The <where> clause now directly includes id = #{id}, removing the <if> wrapper. This simplification guarantees the query always filters by id, preventing unintended multi-row results when id is empty or null.

base/src/main/resources/mappers/MaterialMapper.xml (1)

232-232: Enforce mandatory ID filter in queryMaterialById
The <where> clause now always includes id = #{id} without a conditional test, ensuring the mapper strictly returns at most one record and avoids accidental multi-row results on empty IDs.

base/src/main/resources/mappers/DatasourceMapper.xml (1)

132-132: Enforce mandatory ID filter in queryDatasourceById
By removing the <if> guard and directly including id = #{id}, this change ensures the datasource query always filters by the provided id, eliminating the risk of returning multiple rows when id is null or empty.

base/src/main/resources/mappers/AppMapper.xml (1)

331-331: Enforce mandatory ID filter in queryAppById
The <where> block now unconditionally applies id = #{id}, dropping the previous null-check. This ensures the query is always scoped to the given id and prevents unexpected multi-row results.

base/src/main/resources/mappers/ComponentLibraryMapper.xml (1)

340-340: Enforce mandatory ID filter in queryComponentLibraryById
The <where> clause always includes CL.id = #{id} now, removing the conditional wrapper. This change guarantees the query is strictly by primary key and avoids multiple-result exceptions on empty or null IDs.

base/src/main/resources/mappers/PlatformMapper.xml (1)

224-226: Enforce mandatory id filter to prevent broad result sets
Removing the <if test="id != null"> wrapper ensures the id = #{id} condition always applies, preventing empty or null id parameters from skipping the filter and returning multiple rows. This directly addresses the TooManyResultsException issue.

base/src/main/resources/mappers/I18nEntryMapper.xml (1)

156-158: Make id condition mandatory to avoid missing filter
By eliminating the conditional <if> around E.id = #{id}, the query always filters on id. This prevents null or empty id values from resulting in unbounded result sets and fixes the multi-row exception.

base/src/main/resources/mappers/ComponentMapper.xml (1)

259-261: Require id parameter unconditionally in queryComponentById
The removal of the null-check wrapper guarantees the id filter is always applied, preventing empty id inputs from producing broad queries. This aligns with the PR objective to fix TooManyResultsException.

base/src/main/resources/mappers/BlockHistoryMapper.xml (1)

251-253: Enforce id = #{id} filter unconditionally
This change makes the id condition mandatory in the <where> clause, ensuring that null or missing id no longer leads to unbounded queries and subsequent TooManyResultsException.

base/src/main/resources/mappers/PageMapper.xml (1)

244-246: Always apply P.id = #{id} for queryPageById
By removing the conditional check, the id filter is enforced in every execution, preventing scenarios where an empty id would return all pages. This resolves the root cause of the multi-row exception.

base/src/main/resources/mappers/BlockMapper.xml (1)

245-247: Enforce mandatory ID filter for queryBlockById
The <where> clause now unconditionally includes id = #{id}, ensuring that passing an empty or null ID won’t result in an unqualified query and preventing potential TooManyResultsException.

base/src/main/resources/mappers/BlockGroupMapper.xml (1)

326-331: Enforce mandatory ID filter for queryBlockGroupAndBlockById
By removing the conditional <if> wrapper, bg.id = #{id} is always applied, guaranteeing that the query cannot return multiple records when id is missing and aligning with the PR’s fix.

base/src/main/resources/mappers/AppExtensionMapper.xml (1)

148-152: Enforce mandatory ID filter for updateAppExtensionById
The <where> block now always includes id = #{id}, preventing accidental full-table updates if id is null or empty and addressing the root cause of unintended multiple-row modifications.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants