Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor(database/gdb): add quote for FieldsPrefix#4485

Merged
hailaz merged 7 commits intogogf:masterfrom
hicolin:feature/add_quote_for_fieldsPrefix
Nov 21, 2025
Merged

refactor(database/gdb): add quote for FieldsPrefix#4485
hailaz merged 7 commits intogogf:masterfrom
hicolin:feature/add_quote_for_fieldsPrefix

Conversation

@hicolin
Copy link
Contributor

@hicolin hicolin commented Oct 18, 2025

Code example:

	var res *BasicInfo
	err := g.DB().Model("basic_info").
		FieldsPrefix("basic_info", basicInfoColumns).
		Where("id", 35813305356386305).Scan(&res)
	if err != nil {
		panic(err)
	}
	g.Dump(res)

SQL generated before modification :

SELECT basic_info.id,basic_info.full_name,basic_info.contact FROM `basic_info` WHERE (`id`=35813305356386305) AND `delete_time` IS NULL LIMIT 1

SQL generated after modification:

SELECT `basic_info`.`id`,`basic_info`.`full_name`,`basic_info`.`contact` FROM `basic_info` WHERE (`id`=35813305356386305) AND `delete_time` IS NULL LIMIT 1

@gqcn
Copy link
Member

gqcn commented Oct 22, 2025

@hicolin The CI failed, you need update the expect result of the unit testing case for the CLI, too.

@hailaz hailaz requested a review from Copilot October 29, 2025 06:42
Copy link
Contributor

Copilot AI left a comment

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 proper SQL identifier quoting for table aliases and field names in the FieldsPrefix and FieldsExPrefix functions to ensure that generated SQL queries have correctly quoted identifiers (using backticks for MySQL).

  • Changed field prefix formatting from simple string concatenation to use QuoteWord for proper SQL identifier quoting
  • Updated both FieldsPrefix and FieldsExPrefix methods to wrap table aliases and field names with appropriate quote characters
  • Updated test expectation to reflect the correctly quoted SQL output

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
database/gdb/gdb_model_fields.go Modified FieldsPrefix and FieldsExPrefix to use QuoteWord for quoting table aliases and field names in SQL queries
contrib/drivers/mysql/testdata/fix_gdb_join_expect.sql Updated expected SQL output to include backticks around all table aliases and field names

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

@hicolin hicolin changed the title refactor(database/gdb): add quote for FieldsPrefix and FieldsExPrefix refactor(database/gdb): add quote for FieldsPrefix Nov 3, 2025
@hailaz hailaz merged commit 99d6985 into gogf:master Nov 21, 2025
18 checks passed
@hicolin hicolin deleted the feature/add_quote_for_fieldsPrefix branch December 26, 2025 01:10
@hicolin hicolin restored the feature/add_quote_for_fieldsPrefix branch December 26, 2025 01:11
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.

3 participants