@@ -72,6 +72,136 @@ func Test_Issue2594(t *testing.T) {
7272 })
7373}
7474
75+ // https://github.com/gogf/gf/issues/4495
76+ // Test Tables() returns correct tables using USER_TABLES (for current user)
77+ // and ALL_TABLES (when schema is specified).
78+ func Test_Issue4495_Tables (t * testing.T ) {
79+ table1 := createInitTable ()
80+ table2 := createInitTable ()
81+ defer dropTable (table1 )
82+ defer dropTable (table2 )
83+
84+ // Test 1: Tables() returns tables for current user (using USER_TABLES)
85+ gtest .C (t , func (t * gtest.T ) {
86+ tables , err := db .Tables (ctx )
87+ t .AssertNil (err )
88+
89+ // Should contain our created tables (case-insensitive comparison for DM)
90+ found1 := false
91+ found2 := false
92+ for _ , tbl := range tables {
93+ if gstr .Equal (tbl , table1 ) {
94+ found1 = true
95+ }
96+ if gstr .Equal (tbl , table2 ) {
97+ found2 = true
98+ }
99+ }
100+ t .Assert (found1 , true )
101+ t .Assert (found2 , true )
102+ })
103+
104+ // Test 2: Tables() with explicit schema parameter (using ALL_TABLES with OWNER filter)
105+ gtest .C (t , func (t * gtest.T ) {
106+ tables , err := db .Tables (ctx , TestDBName )
107+ t .AssertNil (err )
108+
109+ // Should contain our created tables
110+ found1 := false
111+ found2 := false
112+ for _ , tbl := range tables {
113+ if gstr .Equal (tbl , table1 ) {
114+ found1 = true
115+ }
116+ if gstr .Equal (tbl , table2 ) {
117+ found2 = true
118+ }
119+ }
120+ t .Assert (found1 , true )
121+ t .Assert (found2 , true )
122+ })
123+ }
124+
125+ // https://github.com/gogf/gf/issues/4495
126+ // Test TableFields() returns correct field info with proper schema handling.
127+ func Test_Issue4495_TableFields (t * testing.T ) {
128+ table := createInitTable ()
129+ defer dropTable (table )
130+
131+ // Test 1: TableFields() without schema uses current schema
132+ gtest .C (t , func (t * gtest.T ) {
133+ fields , err := db .TableFields (ctx , table )
134+ t .AssertNil (err )
135+ t .Assert (len (fields ) > 0 , true )
136+
137+ // Verify key fields exist
138+ _ , hasID := fields ["ID" ]
139+ _ , hasAccountName := fields ["ACCOUNT_NAME" ]
140+ t .Assert (hasID , true )
141+ t .Assert (hasAccountName , true )
142+ })
143+
144+ // Test 2: TableFields() with explicit schema parameter
145+ gtest .C (t , func (t * gtest.T ) {
146+ fields , err := db .TableFields (ctx , table , TestDBName )
147+ t .AssertNil (err )
148+ t .Assert (len (fields ) > 0 , true )
149+
150+ // Verify key fields exist
151+ _ , hasID := fields ["ID" ]
152+ _ , hasAccountName := fields ["ACCOUNT_NAME" ]
153+ t .Assert (hasID , true )
154+ t .Assert (hasAccountName , true )
155+ })
156+
157+ // Test 3: TableFields() with Schema() method
158+ gtest .C (t , func (t * gtest.T ) {
159+ fields , err := db .Schema (TestDBName ).TableFields (ctx , table )
160+ t .AssertNil (err )
161+ t .Assert (len (fields ) > 0 , true )
162+
163+ // Verify ID is primary key
164+ idField , hasID := fields ["ID" ]
165+ t .Assert (hasID , true )
166+ t .Assert (idField .Key , "PRI" )
167+ })
168+ }
169+
170+ // https://github.com/gogf/gf/issues/4495
171+ // Test cache isolation for different schemas.
172+ func Test_Issue4495_CacheIsolation (t * testing.T ) {
173+ table := createInitTable ()
174+ defer dropTable (table )
175+
176+ gtest .C (t , func (t * gtest.T ) {
177+ // Get tables using default schema
178+ tables1 , err := db .Tables (ctx )
179+ t .AssertNil (err )
180+
181+ // Get tables using explicit schema
182+ tables2 , err := db .Schema (TestDBName ).Tables (ctx )
183+ t .AssertNil (err )
184+
185+ // Both should contain the created table
186+ found1 := false
187+ found2 := false
188+ for _ , tbl := range tables1 {
189+ if gstr .Equal (tbl , table ) {
190+ found1 = true
191+ break
192+ }
193+ }
194+ for _ , tbl := range tables2 {
195+ if gstr .Equal (tbl , table ) {
196+ found2 = true
197+ break
198+ }
199+ }
200+ t .Assert (found1 , true )
201+ t .Assert (found2 , true )
202+ })
203+ }
204+
75205// Test_MultilineSQLStatement tests that multi-line SQL statements are properly supported.
76206// This test verifies that newlines and tabs in SQL queries are preserved,
77207// which is essential for readability and proper SQL statement handling.
0 commit comments