@@ -42,30 +42,6 @@ public function isOnUpdateCurrentTimestamp(string $table, string $column): bool
4242 return !($ result === null );
4343 }
4444
45- /**
46- * Get the virtual column definition by table and column name.
47- *
48- * @param string $table Table name.
49- * @param string $column Column name.
50- * @return string|null The virtual column definition. NULL if not found.
51- */
52- public function getVirtualDefinition (string $ table , string $ column ): ?string
53- {
54- return $ this ->getGenerationExpression ($ table , $ column , 'VIRTUAL GENERATED ' );
55- }
56-
57- /**
58- * Get the stored column definition by table and column name.
59- *
60- * @param string $table Table name.
61- * @param string $column Column name.
62- * @return string|null The stored column definition. NULL if not found.
63- */
64- public function getStoredDefinition (string $ table , string $ column ): ?string
65- {
66- return $ this ->getGenerationExpression ($ table , $ column , 'STORED GENERATED ' );
67- }
68-
6945 /**
7046 * Get a list of stored procedures.
7147 *
@@ -141,45 +117,4 @@ private function getProcedure(string $procedure): mixed
141117 {
142118 return DB ::selectOne ("SHOW CREATE PROCEDURE $ procedure " );
143119 }
144-
145- /**
146- * Get the column GENERATION_EXPRESSION when EXTRA is 'VIRTUAL GENERATED' or 'STORED GENERATED'.
147- *
148- * @param 'VIRTUAL GENERATED'|'STORED GENERATED' $extra
149- */
150- private function getGenerationExpression (string $ table , string $ column , string $ extra ): ?string
151- {
152- try {
153- $ definition = DB ::selectOne (
154- "SELECT GENERATION_EXPRESSION
155- FROM information_schema.COLUMNS
156- WHERE TABLE_NAME = ' $ table'
157- AND COLUMN_NAME = ' $ column'
158- AND EXTRA = ' $ extra' " ,
159- );
160- } catch (QueryException $ exception ) {
161- // Check if error caused by missing column 'GENERATION_EXPRESSION'.
162- // The column is introduced since MySQL 5.7 and MariaDB 10.2.5.
163- // @see https://mariadb.com/kb/en/information-schema-columns-table/
164- // @see https://dev.mysql.com/doc/refman/5.7/en/information-schema-columns-table.html
165- if (
166- Str::contains (
167- $ exception ->getMessage (),
168- "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'GENERATION_EXPRESSION' " ,
169- true ,
170- )
171- ) {
172- return null ;
173- }
174-
175- throw $ exception ;
176- }
177-
178- if ($ definition === null ) {
179- return null ;
180- }
181-
182- $ definitionArr = array_change_key_case ((array ) $ definition );
183- return $ definitionArr ['generation_expression ' ] !== '' ? $ definitionArr ['generation_expression ' ] : null ;
184- }
185120}
0 commit comments