Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to inherit 'SqlScriptGenerator' class #42

Open
terryfkjc opened this issue Apr 2, 2023 · 1 comment
Open

Unable to inherit 'SqlScriptGenerator' class #42

terryfkjc opened this issue Apr 2, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@terryfkjc
Copy link

Is your feature request related to a problem? Please describe.

Consider the following code to inherit SqlScriptGenerator

internal class CustomSqlScriptGenerator : SqlScriptGenerator
{
	public CustomSqlScriptGenerator(SqlScriptGeneratorOptions options) : base(options)
	{
	}

	internal override SqlScriptGeneratorVisitor CreateSqlScriptGeneratorVisitor(SqlScriptGeneratorOptions options, ScriptWriter scriptWriter)
	{
		throw new NotImplementedException();
	}
}

However, this will get compilation error because SqlScriptGeneratorVisitor and ScriptWriter are marked as internal, which is impossible to inherit this class.

Describe the solution you'd like

  • Change CreateSqlScriptGeneratorVisitor(...) become protected instead of internal
  • Remove ScriptWriter parameter in CreateSqlScriptGeneratorVisitor(...). This can avoid to mark ScriptWriter as public. Instantiation of ScriptWriter will be handled by child class of SqlScriptGenerator. See example below.
  • Mark SqlScriptGeneratorVisitor as public accessible. SqlScriptGeneratorVisitor will be used to visit the expression tree when generating TSQL script.

Here is the suggested changes:

protected abstract SqlScriptGeneratorVisitor CreateSqlScriptGeneratorVisitor(SqlScriptGeneratorOptions options);

And update Sql###ScriptGenerator become

Example:

public sealed class Sql100ScriptGenerator : SqlScriptGenerator
{
    public Sql100ScriptGenerator()
        : this(new SqlScriptGeneratorOptions())
    {
    }

    public Sql100ScriptGenerator(SqlScriptGeneratorOptions options)
        : base(options)
    {
    }

    protected override SqlScriptGeneratorVisitor CreateSqlScriptGeneratorVisitor(SqlScriptGeneratorOptions options)
    {
        // Create instance of ScriptWriter. 
        //Currently this is created by private function in SqlScriptGenerator
        ScriptWriter scriptWriter = new ScriptWriter(options);

        ScriptGeneratorSupporter.CheckForNullReference((object) options, nameof (options));
        ScriptGeneratorSupporter.CheckForNullReference((object) scriptWriter, nameof (scriptWriter));
        return (SqlScriptGeneratorVisitor) new Sql100ScriptGeneratorVisitor(options, scriptWriter);
    }
}
@dzsquared dzsquared added the enhancement New feature or request label Apr 5, 2023
@zijchen zijchen transferred this issue from microsoft/DacFx Jun 6, 2023
@zijchen
Copy link
Member

zijchen commented Jun 6, 2023

I believe this is the line of code in question:

internal abstract SqlScriptGeneratorVisitor CreateSqlScriptGeneratorVisitor(SqlScriptGeneratorOptions options, ScriptWriter scriptWriter);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants