-
Notifications
You must be signed in to change notification settings - Fork 97
Initial implementation for DBConnection.GetSchema(String) #443 #449
Conversation
@Thorium, |
The Appveyor test fails as I was naive and used the test database file |
Use |
[Fact] | ||
public void GetSchema_has_collections() | ||
{ | ||
var connectionString = "Data Source=readonly.db"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try datasource as :memory:
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's hammer out the design of these collections in #443 before iterating on this PR.
var dt = new DataTable(collectionName); | ||
switch (collectionName) | ||
{ | ||
case "DataTypes": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use DbMetaDataCollectionNames.DataTypes
dt.Columns.AddRange(new[] { | ||
new DataColumn("DataType", typeof(string)), | ||
new DataColumn("TypeName", typeof(string)), | ||
new DataColumn("ProviderDbType", typeof(int)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use DbMetaDataColumnNames.DataType
, etc.
new DataColumn("CONSTRAINT_NAME") | ||
}); | ||
foreach(var tablename in tables){ | ||
var relationQuery = "pragma foreign_key_list(" + tablename + ")"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can combine this and the previous query using this syntax:
SELECT t.name,
fk.table,
fk.from,
fk.to
FROM sqlite_master t,
pragma_foreign_key_list(t.name) fk
WHERE t.type = 'table'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea, however DB Browser for SQLite doesn't support that, so I don't know how widely that is supported.
We should probably implement the MetaDataCollections collection to show which collections we currently support. For the collections we do support, we should probably include all the "usual" columns (even if we don't populate them with data). |
Let's add a few more tests to make sure the data returned is correct. |
@bricelam MetaDataCollections and more testing have been added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good
/// <returns>A DataTable that contains schema information.</returns> | ||
public override System.Data.DataTable GetSchema(string collectionName) | ||
{ | ||
return GetSchema(collectionName, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we should also add:
public override DataTable GetSchema()
=> GetSchema(DbMetaDataCollectionNames.MetaDataCollections, null);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
dt.Rows.Add(new object[] { "System.DateTime","date",6 }); | ||
dt.Rows.Add(new object[] { "System.DateTime","time",6 }); | ||
dt.Rows.Add(new object[] { "System.Guid","uniqueidentifier",4 }); | ||
dt.Rows.Add(new object[] { "System.Guid","guid",4 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to refine this information before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The information here describes what types of .NET can be mapped to types that will be understood by the database driver, and the corresponding System.Data.Common DbTypes. This information is taken from the System.Data.SQLite.dll library.
I think this is more of a design decision. Do you want to continue from here?
I'm already happy with the current implementation but feel free to change what ever you need.
Closing this per our discussion. Querying directly for this metadata (and hard-coding a list of supported types) is the correct way to handle this for the time being. |
No description provided.