Skip to content

SHOW FULL COLUMNS FROM xxxx Error: Error 1146 (42S02): Table 'xxx' doesn't exist #4240

Open
@tiansin

Description

@tiansin

Go version

1.24

GoFrame version

2.9.0

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

子查询使用子查询时输出了错误日志,通过调试后发现,在如下位置进入后就会输出错误日志 :

if conditionArray.Len() == 0 && gstr.Contains(m.tables, ",") {

package test

import (
	"context"
	"fmt"
	"testing"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/test/gtest"
)

func createTable() string {
	db := g.DB()
	db.SetDebug(true)
	tableName := "test_bug"
	if _, err := db.Exec(context.Background(), fmt.Sprintf(`
	    CREATE TABLE %s (
	        id      int(10) unsigned NOT NULL AUTO_INCREMENT,
			name   varchar(255) DEFAULT NULL,
			age    int(10) DEFAULT NULL,
	        PRIMARY KEY (id)
	    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
	    `, tableName,
	)); err != nil {
		gtest.Fatal(err)
	}
	return tableName
}

func dropTable(table string) {
	db := g.DB()
	if _, err := db.Exec(context.Background(), fmt.Sprintf("DROP TABLE IF EXISTS `%s`", table)); err != nil {
		gtest.Error(err)
	}
}

func Test_mainFile(t *testing.T) {
	db := g.DB()

	tableName := createTable()
	defer dropTable(tableName)

	gtest.C(t, func(t *gtest.T) {
		_, err := db.Model("? as u", g.Model("test_bug").Fields("name", "age")).Where("age", 18).Count()
		t.Assert(err, nil)

		_, err = db.Model("? as u", g.Model("test_bug").Group("name").Group("age").Having("age > ", 1)).Where("age", 18).Count()
		t.Assert(err, nil)
	})
}

What did you see happen?

2025-04-10T00:02:00.809+08:00 [ERRO] {20ace88cddb1341821692532d7fa3f4d} [ 0 ms] [default] [apigame] [rows:0 ] SHOW FULL COLUMNS FROM age
Error: Error 1146 (42S02): Table 'apigame.age' doesn't exist

What did you expect to see?

无报错.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIt is confirmed a bug, but don't worry, we'll handle it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions