Skip to content

Commit c6b6680

Browse files
committed
fix: mysql implementation case bug
1 parent 029ba38 commit c6b6680

File tree

1 file changed

+58
-58
lines changed

1 file changed

+58
-58
lines changed

src/connectors/mysql/index.ts

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ export class MySQLConnector implements Connector {
9090
try {
9191
// In MySQL, schemas are equivalent to databases
9292
const [rows] = await this.pool.query(`
93-
SELECT schema_name
94-
FROM information_schema.schemata
95-
ORDER BY schema_name
93+
SELECT SCHEMA_NAME
94+
FROM INFORMATION_SCHEMA.SCHEMATA
95+
ORDER BY SCHEMA_NAME
9696
`) as [any[], any];
9797

98-
return rows.map(row => row.schema_name);
98+
return rows.map(row => row.SCHEMA_NAME);
9999
} catch (error) {
100100
console.error("Error getting schemas:", error);
101101
throw error;
@@ -112,20 +112,20 @@ export class MySQLConnector implements Connector {
112112
// MySQL uses the terms 'database' and 'schema' interchangeably
113113
// The DATABASE() function returns the current database context
114114
const schemaClause = schema ?
115-
'WHERE table_schema = ?' :
116-
'WHERE table_schema = DATABASE()';
115+
'WHERE TABLE_SCHEMA = ?' :
116+
'WHERE TABLE_SCHEMA = DATABASE()';
117117

118118
const queryParams = schema ? [schema] : [];
119119

120120
// Get all tables from the specified schema or current database
121121
const [rows] = await this.pool.query(`
122-
SELECT table_name
123-
FROM information_schema.tables
122+
SELECT TABLE_NAME
123+
FROM INFORMATION_SCHEMA.TABLES
124124
${schemaClause}
125-
ORDER BY table_name
125+
ORDER BY TABLE_NAME
126126
`, queryParams) as [any[], any];
127127

128-
return rows.map(row => row.table_name);
128+
return rows.map(row => row.TABLE_NAME);
129129
} catch (error) {
130130
console.error("Error getting tables:", error);
131131
throw error;
@@ -141,19 +141,19 @@ export class MySQLConnector implements Connector {
141141
// In MySQL, if no schema is provided, use the current active database
142142
// DATABASE() function returns the name of the current database
143143
const schemaClause = schema ?
144-
'WHERE table_schema = ?' :
145-
'WHERE table_schema = DATABASE()';
144+
'WHERE TABLE_SCHEMA = ?' :
145+
'WHERE TABLE_SCHEMA = DATABASE()';
146146

147147
const queryParams = schema ? [schema, tableName] : [tableName];
148148

149149
const [rows] = await this.pool.query(`
150-
SELECT COUNT(*) as count
151-
FROM information_schema.tables
150+
SELECT COUNT(*) AS COUNT
151+
FROM INFORMATION_SCHEMA.TABLES
152152
${schemaClause}
153-
AND table_name = ?
153+
AND TABLE_NAME = ?
154154
`, queryParams) as [any[], any];
155155

156-
return rows[0].count > 0;
156+
return rows[0].COUNT > 0;
157157
} catch (error) {
158158
console.error("Error checking if table exists:", error);
159159
throw error;
@@ -181,7 +181,7 @@ export class MySQLConnector implements Connector {
181181
NON_UNIQUE,
182182
SEQ_IN_INDEX
183183
FROM
184-
information_schema.STATISTICS
184+
INFORMATION_SCHEMA.STATISTICS
185185
WHERE
186186
${schemaClause}
187187
AND TABLE_NAME = ?
@@ -243,22 +243,22 @@ export class MySQLConnector implements Connector {
243243
// If no schema is provided, use the current database context via DATABASE() function
244244
// This means tables will be retrieved from whatever database the connection is currently using
245245
const schemaClause = schema ?
246-
'WHERE table_schema = ?' :
247-
'WHERE table_schema = DATABASE()';
246+
'WHERE TABLE_SCHEMA = ?' :
247+
'WHERE TABLE_SCHEMA = DATABASE()';
248248

249249
const queryParams = schema ? [schema, tableName] : [tableName];
250250

251251
// Get table columns
252252
const [rows] = await this.pool.query(`
253253
SELECT
254-
column_name,
255-
data_type,
256-
is_nullable,
257-
column_default
258-
FROM information_schema.columns
254+
COLUMN_NAME as column_name,
255+
DATA_TYPE as data_type,
256+
IS_NULLABLE as is_nullable,
257+
COLUMN_DEFAULT as column_default
258+
FROM INFORMATION_SCHEMA.COLUMNS
259259
${schemaClause}
260-
AND table_name = ?
261-
ORDER BY ordinal_position
260+
AND TABLE_NAME = ?
261+
ORDER BY ORDINAL_POSITION
262262
`, queryParams) as [any[], any];
263263

264264
return rows;
@@ -276,20 +276,20 @@ export class MySQLConnector implements Connector {
276276
try {
277277
// In MySQL, if no schema is provided, use the current database context
278278
const schemaClause = schema ?
279-
'WHERE routine_schema = ?' :
280-
'WHERE routine_schema = DATABASE()';
279+
'WHERE ROUTINE_SCHEMA = ?' :
280+
'WHERE ROUTINE_SCHEMA = DATABASE()';
281281

282282
const queryParams = schema ? [schema] : [];
283283

284284
// Get all stored procedures and functions
285285
const [rows] = await this.pool.query(`
286-
SELECT routine_name
287-
FROM information_schema.routines
286+
SELECT ROUTINE_NAME
287+
FROM INFORMATION_SCHEMA.ROUTINES
288288
${schemaClause}
289-
ORDER BY routine_name
289+
ORDER BY ROUTINE_NAME
290290
`, queryParams) as [any[], any];
291291

292-
return rows.map(row => row.routine_name);
292+
return rows.map(row => row.ROUTINE_NAME);
293293
} catch (error) {
294294
console.error("Error getting stored procedures:", error);
295295
throw error;
@@ -304,36 +304,36 @@ export class MySQLConnector implements Connector {
304304
try {
305305
// In MySQL, if no schema is provided, use the current database context
306306
const schemaClause = schema ?
307-
'WHERE r.routine_schema = ?' :
308-
'WHERE r.routine_schema = DATABASE()';
307+
'WHERE r.ROUTINE_SCHEMA = ?' :
308+
'WHERE r.ROUTINE_SCHEMA = DATABASE()';
309309

310310
const queryParams = schema ? [schema, procedureName] : [procedureName];
311311

312312
// Get details of the stored procedure
313313
const [rows] = await this.pool.query(`
314314
SELECT
315-
r.routine_name AS procedure_name,
315+
r.ROUTINE_NAME AS procedure_name,
316316
CASE
317-
WHEN r.routine_type = 'PROCEDURE' THEN 'procedure'
317+
WHEN r.ROUTINE_TYPE = 'PROCEDURE' THEN 'procedure'
318318
ELSE 'function'
319319
END AS procedure_type,
320-
LOWER(r.routine_type) AS routine_type,
321-
r.routine_definition,
322-
r.dtd_identifier AS return_type,
320+
LOWER(r.ROUTINE_TYPE) AS routine_type,
321+
r.ROUTINE_DEFINITION,
322+
r.DTD_IDENTIFIER AS return_type,
323323
(
324324
SELECT GROUP_CONCAT(
325-
CONCAT(p.parameter_name, ' ', p.parameter_mode, ' ', p.data_type)
326-
ORDER BY p.ordinal_position
325+
CONCAT(p.PARAMETER_NAME, ' ', p.PARAMETER_MODE, ' ', p.DATA_TYPE)
326+
ORDER BY p.ORDINAL_POSITION
327327
SEPARATOR ', '
328328
)
329-
FROM information_schema.parameters p
330-
WHERE p.specific_schema = r.routine_schema
331-
AND p.specific_name = r.routine_name
332-
AND p.parameter_name IS NOT NULL
329+
FROM INFORMATION_SCHEMA.PARAMETERS p
330+
WHERE p.SPECIFIC_SCHEMA = r.ROUTINE_SCHEMA
331+
AND p.SPECIFIC_NAME = r.ROUTINE_NAME
332+
AND p.PARAMETER_NAME IS NOT NULL
333333
) AS parameter_list
334-
FROM information_schema.routines r
334+
FROM INFORMATION_SCHEMA.ROUTINES r
335335
${schemaClause}
336-
AND r.routine_name = ?
336+
AND r.ROUTINE_NAME = ?
337337
`, queryParams) as [any[], any];
338338

339339
if (rows.length === 0) {
@@ -343,8 +343,8 @@ export class MySQLConnector implements Connector {
343343

344344
const procedure = rows[0];
345345

346-
// If routine_definition is NULL, try to get the procedure body from mysql.proc
347-
let definition = procedure.routine_definition;
346+
// If ROUTINE_DEFINITION is NULL, try to get the procedure body from mysql.proc
347+
let definition = procedure.ROUTINE_DEFINITION;
348348

349349
try {
350350
const schemaValue = schema || await this.getCurrentSchema();
@@ -381,16 +381,16 @@ export class MySQLConnector implements Connector {
381381
// Last attempt - try to get from information_schema.routines if not found yet
382382
if (!definition) {
383383
const [bodyRows] = await this.pool.query(`
384-
SELECT routine_definition, routine_body
385-
FROM information_schema.routines
386-
WHERE routine_schema = ? AND routine_name = ?
384+
SELECT ROUTINE_DEFINITION, ROUTINE_BODY
385+
FROM INFORMATION_SCHEMA.ROUTINES
386+
WHERE ROUTINE_SCHEMA = ? AND ROUTINE_NAME = ?
387387
`, [schemaValue, procedureName]) as [any[], any];
388388

389389
if (bodyRows && bodyRows.length > 0) {
390-
if (bodyRows[0].routine_definition) {
391-
definition = bodyRows[0].routine_definition;
392-
} else if (bodyRows[0].routine_body) {
393-
definition = bodyRows[0].routine_body;
390+
if (bodyRows[0].ROUTINE_DEFINITION) {
391+
definition = bodyRows[0].ROUTINE_DEFINITION;
392+
} else if (bodyRows[0].ROUTINE_BODY) {
393+
definition = bodyRows[0].ROUTINE_BODY;
394394
}
395395
}
396396
}
@@ -415,8 +415,8 @@ export class MySQLConnector implements Connector {
415415

416416
// Helper method to get current schema (database) name
417417
private async getCurrentSchema(): Promise<string> {
418-
const [rows] = await this.pool!.query('SELECT DATABASE() as db') as [any[], any];
419-
return rows[0].db;
418+
const [rows] = await this.pool!.query('SELECT DATABASE() AS DB') as [any[], any];
419+
return rows[0].DB;
420420
}
421421

422422
async executeQuery(query: string): Promise<QueryResult> {

0 commit comments

Comments
 (0)