Skip to content

Commit

Permalink
Map IVsDataView well-known type
Browse files Browse the repository at this point in the history
Part of #23, fixes #27
  • Loading branch information
bricelam committed Jul 24, 2022
1 parent 671098b commit ff7565d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
30 changes: 30 additions & 0 deletions VS.Data.Sqlite.IntegrationTests/MappedObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.VisualStudio.Data.Services;
using Microsoft.VisualStudio.Data.Services.RelationalObjectModel;
using Microsoft.VisualStudio.Data.Services.SupportEntities;
using Microsoft.VisualStudio.LanguageServer.Client;
using Microsoft.VisualStudio.Shell;
using Xunit;

Expand Down Expand Up @@ -110,4 +111,33 @@ public void Can_select_tables_with_restrictions()
tables,
t => Assert.Equal("A", t.Name));
}

[VsFact]
public void Can_select_views()
{
var connectionFactory = (IVsDataConnectionFactory)ServiceProvider.GlobalProvider.GetService(typeof(IVsDataConnectionFactory));
var connection = connectionFactory.CreateConnection(
PackageGuids.guidSqliteDataProvider,
"Data Source=:memory:",
encryptedString: false);

var command = (IVsDataCommand)connection.GetService(typeof(IVsDataCommand));
command.ExecuteWithoutResults(@"
CREATE VIEW view1 AS
SELECT 1 AS Value;
");

var selector = (IVsDataMappedObjectSelector)connection.GetService(typeof(IVsDataMappedObjectSelector));
var views = selector.SelectMappedObjects<IVsDataView>();

Assert.Collection(
views,
v =>
{
Assert.Equal("main", v.Catalog);
Assert.Null(v.Schema);
Assert.Equal("view1", v.Name);
Assert.Equal(new object[] { "main", null, "view1" }, v.Identifier);
});
}
}
20 changes: 20 additions & 0 deletions VS.Data.Sqlite/SqliteObjectSupport.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,25 @@
</Property>
</Properties>
</MappedType>
<MappedType name="View" underlyingType="View">
<Selection restrictions="{Name}" ordering="Name" />
<Identifier>
<Part name="Catalog">
<Conversion>
<Calculate expr="'main'" exprType="System.String" />
</Conversion>
</Part>
<Part name="Name" underlyingMember="Name" />
</Identifier>
<Properties>
<Property name="Catalog" isIdentifierPart="true" />
<Property name="Name" isIdentifierPart="true" />
<Property name="IsSystemObject" underlyingMember="Name">
<Conversion>
<Calculate expr="{0} LIKE 'sqlite_%'" exprType="System.Boolean" />
</Conversion>
</Property>
</Properties>
</MappedType>
</MappedTypes>
</DataObjectSupport>

0 comments on commit ff7565d

Please sign in to comment.