Skip to content

Commit 0a50e11

Browse files
[release] fix: GetIdColumnType bugfix (#387)
* fix: GetIdColumnType bugfix * fix: add indication of in which query an exception was thrown
1 parent ab04fd7 commit 0a50e11

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

CodeGenerator/Generators/QueriesGen.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,22 @@ private MemberDeclarationSyntax AddMethodDeclaration(Query query)
183183
var argInterface = ClassMember.Args.Name(query.Name);
184184
var returnInterface = ClassMember.Row.Name(query.Name);
185185

186-
return query.Cmd switch
186+
try
187187
{
188-
":exec" => ((IExec)dbDriver).ExecDeclare(queryTextConstant, argInterface, query),
189-
":one" => ((IOne)dbDriver).OneDeclare(queryTextConstant, argInterface, returnInterface, query),
190-
":many" => ((IMany)dbDriver).ManyDeclare(queryTextConstant, argInterface, returnInterface, query),
191-
":execrows" => ((IExecRows)dbDriver).ExecRowsDeclare(queryTextConstant, argInterface, query),
192-
":execlastid" => ((IExecLastId)dbDriver).ExecLastIdDeclare(queryTextConstant, argInterface, query),
193-
":copyfrom" => ((ICopyFrom)dbDriver).CopyFromDeclare(queryTextConstant, argInterface, query),
194-
_ => throw new NotSupportedException($"{query.Cmd} is not supported")
195-
};
188+
return query.Cmd switch
189+
{
190+
":exec" => ((IExec)dbDriver).ExecDeclare(queryTextConstant, argInterface, query),
191+
":one" => ((IOne)dbDriver).OneDeclare(queryTextConstant, argInterface, returnInterface, query),
192+
":many" => ((IMany)dbDriver).ManyDeclare(queryTextConstant, argInterface, returnInterface, query),
193+
":execrows" => ((IExecRows)dbDriver).ExecRowsDeclare(queryTextConstant, argInterface, query),
194+
":execlastid" => ((IExecLastId)dbDriver).ExecLastIdDeclare(queryTextConstant, argInterface, query),
195+
":copyfrom" => ((ICopyFrom)dbDriver).CopyFromDeclare(queryTextConstant, argInterface, query),
196+
_ => throw new NotSupportedException($"{query.Cmd} is not supported")
197+
};
198+
}
199+
catch (Exception e)
200+
{
201+
throw new SystemException($"Failed to add method declaration for query: {query.Name}", e);
202+
}
196203
}
197204
}

Drivers/DbDriver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,11 @@ this method uses a few heuristics to assess the data type of the id column
280280
public string GetIdColumnType(Query query)
281281
{
282282
var tableColumns = Tables[query.InsertIntoTable.Schema][query.InsertIntoTable.Name].Columns;
283-
var idColumn = tableColumns.First(c => c.Name.Equals("id", StringComparison.OrdinalIgnoreCase));
283+
var idColumn = tableColumns.FirstOrDefault(c => c.Name.Equals("id", StringComparison.OrdinalIgnoreCase));
284284
if (idColumn is not null)
285285
return GetCsharpType(idColumn, query);
286286

287-
idColumn = tableColumns.First(c => c.Name.Contains("id", StringComparison.CurrentCultureIgnoreCase));
287+
idColumn = tableColumns.FirstOrDefault(c => c.Name.Contains("id", StringComparison.CurrentCultureIgnoreCase));
288288
return GetCsharpType(idColumn ?? tableColumns[0], query);
289289
}
290290

0 commit comments

Comments
 (0)