Skip to content

How about create a sqlite driver with Microsoft.Data.Sqlite.Core ? #2318

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

Closed
beginor opened this issue Feb 26, 2020 · 9 comments
Closed

How about create a sqlite driver with Microsoft.Data.Sqlite.Core ? #2318

beginor opened this issue Feb 26, 2020 · 9 comments

Comments

@beginor
Copy link
Member

beginor commented Feb 26, 2020

Microsoft.Data.Sqlite.Core is a .NETStandard 2.0 nuget package, can be used in any .NET platform that supports .NETStandard 2.0, it it provided by microsoft, should be the official sqlite provider for .net.

Since NHibernate is a .NETStandard 2.0 too, so how about create a new a sqlite driver with it?

I have create a MsSqliteDriver in my nhibernate-extensions repository, the configuration file is hibernate.sqlite.config and the unit test file is MsSqliteDriverTest

please review it, if it is acceptable, I can create a merge request fot it. And if it is not acceptable, I would like to publish a separate nuget package。

@fredericDelaporte
Copy link
Member

There is some discussion about it in #1638, have you seen it? Also check some scattered comments like here and in #847.

Speaking of which, #847 is about changing how we handle drivers, for ceasing to handle them all through reflection and having them all in the main library. But it is no more moving for now.

Anyway, for the driver to be included, you should first make sure it passes successfully the NHibernate test suite.

@beginor
Copy link
Member Author

beginor commented Feb 27, 2020

Sorry, I have seen #847 , but I have not seen #1638 , I will make a full test with NHibernate test suite first.

@beginor
Copy link
Member Author

beginor commented Feb 27, 2020

I have done a test with the driver built with Microsoft.Data.Sqlite.Core in my fork repo, the test result summary is:

Test Run Failed.
Total tests: 12348
     Passed: 10183
     Failed: 447
    Skipped: 1460
 Total time: 14.5821 Minutes

I get the same errors like in #1638 :

  • SqliteConnection does not support nested transactions.
  • Specified method is not supported. (System.Data.Common.DbConnection.GetSchema)
  • Unable to cast object of type 'System.String' to type 'System.DateTime'
  • ...

And I have done a test with the driver NHibernate.Driver.SQLite20Driver, the test result summary is:

Test Run Summary
  Overall result: Warning
  Test Count: 12418, Passed: 10850, Failed: 0, Warnings: 0, Inconclusive: 72, Skipped: 1496
    Skipped Tests - Ignored: 1297, Explicit: 199, Other: 0
  Start time: 2020-02-27 02:58:17Z
    End time: 2020-02-27 03:10:21Z
    Duration: 724.329 seconds

As discussed in #1638 , the driver from microsoft is incompleted.

However, I would like to publish a driver third part extension driver called NHibernate.Extensions.Sqlite.

@beginor beginor closed this as completed Feb 27, 2020
@fredericDelaporte
Copy link
Member

fredericDelaporte commented Feb 27, 2020

A bunch of the errors you have seen may be manageable.

A cast trouble could be some db type for which the parameters would require adjustments by overriding InitializeParameter in the driver, by example. It could also be that the data provider handles the type differently than what the dialect expects. In such case you may have to write a specific dialect for the driver, redefining some db types mappings.

Since not all databases have the same abilities, we also have some mechanisms to flag what is unsupported and should not be tested. But it is a bit messy currently. That is done through properties scattered on the driver and dialect base classes to be overridden, and also on NHibernate.Test.TestDialect (see derived classes). Sometimes that is even the driver type or dialect class type which is directly checked by the test case...
You should be able to see in the failing tests if they use something like that for being ignored when it is expected the tested database (or in that case, the tested driver) does not support them.

We may accept a few new unsupported cases with new disabling flags (preferably through TestDialect), but not if the driver/db has too many specific unsupported cases.

For now it is likely this driver is a bit too far from passing the test suite.

However, I would like to publish a driver third part extension driver called NHibernate.Extensions.Sqlite.

As you wish. We do neither monitor, nor complain about, third party extensions. We may be annoyed by some names being taken on NuGet, but we cope with that when that happens. (Usually by tweaking the name of what we were willing to add.)

@beginor
Copy link
Member Author

beginor commented Feb 28, 2020

Thanks for your advice, I will continue to try when I have time.

I publish NHibernate.Extensions.Sqlite package because I want to use it in nhibernate/NHibernate.AspNetCore.Identity#19 now.

However, if any the name of the packages wanted by nhibernate, I can transfer the ownership.

@fredericDelaporte
Copy link
Member

You may have a look at #1662 for an example of how the specific behavior/limitations/... of a database or driver could be handled. (Mind that this one was adding support for a kind of database we were not having. It has more changes than what we may accept for adding just a driver alternative for a database we already support.)

@PriyankaChandrabose
Copy link

PriyankaChandrabose commented Oct 6, 2023

@beginor -- I am using the dialect and driver provided in the NHibernate.Extensions.Sqlite but the schemaupdate is not working - no new tables or columns are being updated

ERROR NHibernate.Tool.hbm2ddl.SchemaUpdate - could not complete schema update
System.ArgumentException: More restrictions were provided than the collection 'Tables' supports.
at Microsoft.Data.Sqlite.SqliteConnection.GetSchema(String collectionName, String[] restrictionValues)
at NHibernate.Dialect.Schema.AbstractDataBaseSchema.GetTables(String catalog, String schemaPattern, String tableNamePattern, String[] types)
at NHibernate.Dialect.Schema.SQLiteDataBaseMetaData.GetTables(String catalog, String schemaPattern, String tableNamePattern, String[] types)
at NHibernate.Tool.hbm2ddl.DatabaseMetadata.GetTableMetadata(String name, String schema, String catalog, Boolean isQuoted)
at NHibernate.Cfg.Configuration.GenerateSchemaUpdateScript(Dialect dialect, IDatabaseMetadata databaseMetadata)
at NHibernate.Tool.hbm2ddl.SchemaUpdate.Execute(Action`1 scriptAction, Boolean doUpdate)

@beginor
Copy link
Member Author

beginor commented Oct 7, 2023

@PriyankaChandrabose I do not use nhibernate's SchemaUpdate, maybe this is a limition of Microsoft.Data.Sqlite.Core .

@pp-mluthi
Copy link

@PriyankaChandrabose I do not use nhibernate's SchemaUpdate, maybe this is a limition of Microsoft.Data.Sqlite.Core .

How do you handle the update of the schema without using SchemaUpdate ?

Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants