feat(database/gdb): support Scan into basic types - #4870
Open
hailaz wants to merge 30 commits into
Open
Conversation
…sic or slice types
- Implemented TestScanReflectValueInput to verify gconv functions correctly unwrap reflect.Value types for basic types. - Added TestScanPointerElementSlice to test scanning into slices of pointers for various basic types, including cross-type conversions.
…rs in Scan and IsBasicKind
… return actual values
…t expanding fields
…sic types
- Refactor isExpandingField to inspect Raw content instead of rejecting
all Raw types, correctly distinguishing single-column expressions like
Raw("username") from expanding ones like Raw("name,age")
- Add isExpandingFieldStr to detect top-level commas while ignoring
commas nested inside function parentheses (e.g. COUNT(DISTINCT a,b))
- Extract validateFieldsExSingleColumn to verify FieldsEx leaves exactly
one column, with graceful skip when DB is unavailable
- Fix getFieldsFiltered to expand Raw entries with comma-separated field
lists so they are correctly excluded from the SELECT clause
- Update unit tests to match corrected Raw field behavior
- Add MySQL integration tests for FieldsEx with string, []string,
variadic args, and gdb.Raw input types
… into basic types" This reverts commit 8a869cb.
# Conflicts: # util/gconv/gconv_z_unit_scan_basic_types_test.go
FieldsEx is an exclusion list and does not declare a single result column. Accepting it let Scan reuse Value()/Array(), which return FirstResultColumn before any column-count check and silently drop the remaining columns.
…pt single column results
…gleFieldSpecified fix(converter): enhance comment for pointer element handling in Scan method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
Model.Scan现在支持将单列查询结果扫描到基本类型、基本类型指针、基本类型切片,以及基本类型指针切片。这补齐了 #3977 中的缺口:此前用户只能绕道
Value()/Array(),而且仍然无法把结果直接扫进int、string、float64、bool这类标量。行为说明
int/uint/float/bool/string及其定长变体,以及*T、[]T、[]*T。Scan行为保持不变。Fields()或FieldSum()这类会产出字段的辅助方法指定列。FieldsEx仅在过滤后只剩一列时才被接受。*、a.*,以及gdb.Raw("name,age")。gdb.Raw("name")、COUNT(*)、COUNT(DISTINCT id, username)。var name string)返回sql.ErrNoRowsvar namePtr *string)保持nil,不返回sql.ErrNoRowssql.ErrNoRows其他改动
reflection.IsBasicKind,只有切片元素是真正的标量时才会走基本类型路径,避免把[]Record这类结果误判成标量切片。gconv对指针元素的分配逻辑,以便正确填充[]*T。