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

Implement reverse engineering of views for SQLite #15627

Merged
merged 1 commit into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,15 @@ private IEnumerable<DatabaseTable> GetTables(DbConnection connection, IEnumerabl
command.CommandText = new StringBuilder()
.AppendLine("SELECT \"name\"")
.AppendLine("FROM \"sqlite_master\"")
.Append("WHERE \"type\" = 'table' AND instr(\"name\", 'sqlite_') <> 1 AND \"name\" NOT IN ('")
.Append("WHERE \"type\" IN ('table', 'view') AND instr(\"name\", 'sqlite_') <> 1 AND \"name\" NOT IN ('")
.Append(HistoryRepository.DefaultTableName)
.Append("', 'ElementaryGeometries', 'geometry_columns', 'geometry_columns_auth', ")
.Append("'geometry_columns_field_infos', 'geometry_columns_statistics', 'geometry_columns_time', ")
.Append("'spatial_ref_sys', 'spatial_ref_sys_aux', 'SpatialIndex', 'spatialite_history', ")
.Append("'sql_statements_log', 'views_geometry_columns', 'views_geometry_columns_auth', ")
.Append("'views_geometry_columns_field_infos', 'views_geometry_columns_statistics', ")
.Append("'virts_geometry_columns', 'virts_geometry_columns_auth', ")
.Append("'geom_cols_ref_sys', 'spatial_ref_sys_all', ")
.AppendLine("'virts_geometry_columns_field_infos', 'virts_geometry_columns_statistics');")
.ToString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,33 @@ Name text NOT NULL
"DROP TABLE MountainsColumns;");
}

[Fact]
public void Create_view_columns()
{
Test(
@"
CREATE VIEW MountainsColumnsView
AS
SELECT
CAST(100 AS integer) AS Id,
CAST('' AS text) AS Name;",
Enumerable.Empty<string>(),
Enumerable.Empty<string>(),
dbModel =>
{
var table = dbModel.Tables.Single();

Assert.Equal(2, table.Columns.Count);
Assert.Equal(null, table.PrimaryKey);
Assert.All(
table.Columns, c => Assert.Equal("MountainsColumnsView", c.Table.Name));

Assert.Single(table.Columns.Where(c => c.Name == "Id"));
Assert.Single(table.Columns.Where(c => c.Name == "Name"));
},
"DROP VIEW MountainsColumnsView;");
}

[Fact]
public void Create_primary_key()
{
Expand Down