CREATE FUNCTION problem

Hi,
There is an occasional bug with the CREATE FUNCTION in the generated DDL script. Here is what I did.

  • Reverse engineer a database that has a function with the following header (as per Microsoft SQL Server Management Studio):
    CREATE FUNCTION [dbo].[GenerateDateWeekDayTable]
    (
    @StartDate datetime,
    @EndDate datetime,
    @DayPart char(5) – support ‘day’,‘month’,‘year’,‘hour’, default ‘day’
    )
    RETURNS
    […]
  • Use TDM to generate the DDL script to create that database.
  • The same function is generated as:
    CREATE FUNCTION [dbo].[GenerateDateWeekDayTable] (@StartDate datetime,
    @EndDate datetime,
    @DayPart char(5) – support ‘day’,‘month’,‘year’,‘hour’, default ‘day’)
    RETURNS
    […]

-> As you can see, the closing parentheses is at the end of the comment rather than on a new line or after “char(5)”, which makes the DDL script invalid.

I am evaluating TDM 3.4.14.6.

gabriel

Hi,

thank you for the detailed problem description. In this case, when a comment is the last thing before the closing parenthesis it outputs invalid code. This will be fixed. Thank you!

CR #67453

Regards,

Vaclav

Argument – comment)

will be:
Argument – comment
)

Hi Gabriel,

This script can help you. It will add a line to the end of the list of all Arguments in every function.
Example:

Here’s the script:

function main()
{
var app = System.GetInterface(‘Application’);
var Model = app.Models.GetObject(0);
var Function, i;

for (i=0; i<Model.Functions.Count; i++)
{
Function = Model.Functions.GetObject(i);
Function.ArgumentList = Function.ArgumentList + “\r\n”;
}
}

Run the script in Scripting Window (Tools menu, Expert mode must be turned on).

If you have any questions, please write us back. Thanks.

Regards,

Vladka + TDM Team