diff --git a/CodeGenerator/Generators/QueriesGen.cs b/CodeGenerator/Generators/QueriesGen.cs index 65893286..99559061 100644 --- a/CodeGenerator/Generators/QueriesGen.cs +++ b/CodeGenerator/Generators/QueriesGen.cs @@ -183,15 +183,22 @@ private MemberDeclarationSyntax AddMethodDeclaration(Query query) var argInterface = ClassMember.Args.Name(query.Name); var returnInterface = ClassMember.Row.Name(query.Name); - return query.Cmd switch + try { - ":exec" => ((IExec)dbDriver).ExecDeclare(queryTextConstant, argInterface, query), - ":one" => ((IOne)dbDriver).OneDeclare(queryTextConstant, argInterface, returnInterface, query), - ":many" => ((IMany)dbDriver).ManyDeclare(queryTextConstant, argInterface, returnInterface, query), - ":execrows" => ((IExecRows)dbDriver).ExecRowsDeclare(queryTextConstant, argInterface, query), - ":execlastid" => ((IExecLastId)dbDriver).ExecLastIdDeclare(queryTextConstant, argInterface, query), - ":copyfrom" => ((ICopyFrom)dbDriver).CopyFromDeclare(queryTextConstant, argInterface, query), - _ => throw new NotSupportedException($"{query.Cmd} is not supported") - }; + return query.Cmd switch + { + ":exec" => ((IExec)dbDriver).ExecDeclare(queryTextConstant, argInterface, query), + ":one" => ((IOne)dbDriver).OneDeclare(queryTextConstant, argInterface, returnInterface, query), + ":many" => ((IMany)dbDriver).ManyDeclare(queryTextConstant, argInterface, returnInterface, query), + ":execrows" => ((IExecRows)dbDriver).ExecRowsDeclare(queryTextConstant, argInterface, query), + ":execlastid" => ((IExecLastId)dbDriver).ExecLastIdDeclare(queryTextConstant, argInterface, query), + ":copyfrom" => ((ICopyFrom)dbDriver).CopyFromDeclare(queryTextConstant, argInterface, query), + _ => throw new NotSupportedException($"{query.Cmd} is not supported") + }; + } + catch (Exception e) + { + throw new SystemException($"Failed to add method declaration for query: {query.Name}", e); + } } } \ No newline at end of file diff --git a/Drivers/DbDriver.cs b/Drivers/DbDriver.cs index c55e2b7d..b111eaea 100644 --- a/Drivers/DbDriver.cs +++ b/Drivers/DbDriver.cs @@ -280,11 +280,11 @@ this method uses a few heuristics to assess the data type of the id column public string GetIdColumnType(Query query) { var tableColumns = Tables[query.InsertIntoTable.Schema][query.InsertIntoTable.Name].Columns; - var idColumn = tableColumns.First(c => c.Name.Equals("id", StringComparison.OrdinalIgnoreCase)); + var idColumn = tableColumns.FirstOrDefault(c => c.Name.Equals("id", StringComparison.OrdinalIgnoreCase)); if (idColumn is not null) return GetCsharpType(idColumn, query); - idColumn = tableColumns.First(c => c.Name.Contains("id", StringComparison.CurrentCultureIgnoreCase)); + idColumn = tableColumns.FirstOrDefault(c => c.Name.Contains("id", StringComparison.CurrentCultureIgnoreCase)); return GetCsharpType(idColumn ?? tableColumns[0], query); }