Skip to content

Commit

Permalink
Implement reverse engineering of views for SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikEJ authored and smitpatel committed May 9, 2019
1 parent 7f70b88 commit 97b7479
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
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

0 comments on commit 97b7479

Please sign in to comment.