marcominerva/DatabaseGPT

GetCreateTablesScriptAsync in Sql Server provider table name splitting issue

ErikEJ opened this issue · 1 comments

var splittedTableNames = tables.Select(t =>
{
    var parts = t.Split('.', StringSplitOptions.TrimEntries);
    var schema = parts[0].TrimStart('[').TrimEnd(']');
    var name = parts[1].TrimStart('[').TrimEnd(']');
    return new { Schema = schema, Name = name };
});

This can "easily" break, as this is a valid CREATE TABLE statement:

CREATE TABLE "[.[Ew!l💩]"
(
	Id int
)

One possible solution could be to create an abstraction like:

public class Table
{
   string? Schema { get; set;}
   string Name { get; set;}
}

Happy to create a PR if interested?

Of course, feel free to make a PR for this improvement. Thank you for your contribution!