Skip to content

Commit 58cf603

Browse files
seantleonardgamewizzzzAniruddh25RubenCerna2079
authored
[Cherrypick] [Port] Modified capitalization in metadata queries (#2315)
## Port metadata - Porting from `main` to `release/1.2` - Issue: #1896 - PR: #1921 ## Why make this change? - Resolves #1896 ## What is this change? - These changes impact API builder startup. The query output has not been modified, but certain field references are capitalized. - The proper case is used to avoid "field not found" and "key field not found" errors when the database collation is case-sensitive. ## How was this tested? - [x] Integration Tests - Ran locally; about 5 tests failed, but it was the same ones that failed before modifications - [ ] Unit Tests ## Sample Request(s) - N/A Co-authored-by: gamewizzzz <[email protected]> Co-authored-by: Aniruddh Munde <[email protected]> Co-authored-by: RubenCerna2079 <[email protected]> Co-authored-by: Ruben Cerna <[email protected]>
1 parent 4a85495 commit 58cf603

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

src/Core/Resolvers/DWSqlQueryBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,10 @@ public string BuildStoredProcedureResultDetailsQuery(string databaseObjectName)
324324
public string BuildQueryToGetReadOnlyColumns(string schemaParamName, string tableParamName)
325325
{
326326
// For 'timestamp' columns sc.is_computed = 0.
327-
string query = "SELECT ifsc.column_name from sys.columns as sc INNER JOIN INFORMATION_SCHEMA.COLUMNS as ifsc " +
328-
"ON (sc.is_computed = 1 or ifsc.data_type = 'timestamp') " +
329-
$"AND sc.object_id = object_id({schemaParamName}+'.'+{tableParamName}) and ifsc.table_name = {tableParamName} " +
330-
$"AND ifsc.table_schema = {schemaParamName} and ifsc.column_name = sc.name;";
327+
string query = "SELECT ifsc.COLUMN_NAME from sys.columns as sc INNER JOIN INFORMATION_SCHEMA.COLUMNS as ifsc " +
328+
"ON (sc.is_computed = 1 or ifsc.DATA_TYPE = 'timestamp') " +
329+
$"AND sc.object_id = object_id({schemaParamName}+'.'+{tableParamName}) AND ifsc.TABLE_SCHEMA = {schemaParamName} " +
330+
$"AND ifsc.TABLE_NAME = {tableParamName} AND ifsc.COLUMN_NAME = sc.name;";
331331

332332
return query;
333333
}

src/Core/Resolvers/MsSqlQueryBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,10 @@ public string BuildStoredProcedureResultDetailsQuery(string databaseObjectName)
509509
public string BuildQueryToGetReadOnlyColumns(string schemaParamName, string tableParamName)
510510
{
511511
// For 'timestamp' columns sc.is_computed = 0.
512-
string query = "SELECT ifsc.column_name from sys.columns as sc INNER JOIN information_schema.columns as ifsc " +
513-
"ON (sc.is_computed = 1 or ifsc.data_type = 'timestamp') " +
514-
$"AND sc.object_id = object_id({schemaParamName}+'.'+{tableParamName}) and ifsc.table_name = {tableParamName} " +
515-
$"AND ifsc.table_schema = {schemaParamName} and ifsc.column_name = sc.name;";
512+
string query = "SELECT ifsc.COLUMN_NAME from sys.columns as sc INNER JOIN INFORMATION_SCHEMA.COLUMNS as ifsc " +
513+
"ON (sc.is_computed = 1 or ifsc.DATA_TYPE = 'timestamp') " +
514+
$"AND sc.object_id = object_id({schemaParamName}+'.'+{tableParamName}) AND ifsc.TABLE_SCHEMA = {schemaParamName} " +
515+
$"AND ifsc.TABLE_NAME = {tableParamName} AND ifsc.COLUMN_NAME = sc.name;";
516516

517517
return query;
518518
}

src/Core/Resolvers/MySqlQueryBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ private static string GetMySQLDefaultValue(ColumnDefinition column)
356356
/// <inheritdoc/>
357357
public string BuildQueryToGetReadOnlyColumns(string schemaParamName, string tableParamName)
358358
{
359-
string query = "select column_name as column_name from information_schema.columns " +
360-
$"where table_schema = {schemaParamName} and table_name = {tableParamName} and generation_expression != '';";
359+
string query = "select COLUMN_NAME as COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS " +
360+
$"where TABLE_SCHEMA = {schemaParamName} and TABLE_NAME = {tableParamName} and GENERATION_EXPRESSION != '';";
361361
return query;
362362
}
363363

src/Core/Resolvers/PostgresQueryBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public string BuildStoredProcedureResultDetailsQuery(string databaseObjectName)
228228
/// <inheritdoc/>
229229
public string BuildQueryToGetReadOnlyColumns(string schemaParamName, string tableParamName)
230230
{
231-
string query = "SELECT attname AS column_name FROM pg_attribute " +
231+
string query = $"SELECT attname AS {QuoteIdentifier("COLUMN_NAME")} FROM pg_attribute " +
232232
$"WHERE attrelid = ({schemaParamName} || '.' || {tableParamName})::regclass AND attgenerated = 's';";
233233
return query;
234234
}

src/Core/Services/MetadataProviders/SqlMetadataProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1841,7 +1841,7 @@ private async Task<List<string>>
18411841
foreach (DbResultSetRow readOnlyFieldRowWithProperties in readOnlyFieldRowsWithProperties.Rows)
18421842
{
18431843
Dictionary<string, object?> readOnlyFieldInfo = readOnlyFieldRowWithProperties.Columns;
1844-
string fieldName = (string)readOnlyFieldInfo["column_name"]!;
1844+
string fieldName = (string)readOnlyFieldInfo["COLUMN_NAME"]!;
18451845
readOnlyFields.Add(fieldName);
18461846
}
18471847

0 commit comments

Comments
 (0)