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

Microsoft.Data.Sqlite v6 crashes with ArgumentException #534

Closed
da3dsoul opened this issue Oct 1, 2022 · 5 comments · Fixed by #620 or #619
Closed

Microsoft.Data.Sqlite v6 crashes with ArgumentException #534

da3dsoul opened this issue Oct 1, 2022 · 5 comments · Fixed by #620 or #619
Labels
Milestone

Comments

@da3dsoul
Copy link

da3dsoul commented Oct 1, 2022

File a bug

We moved to Microsoft.Data.Sqlite 6, as it has better support for dropping columns in Sqlite by my understanding

In our move, we encountered the old GetSchema issue, which seems to be addressed in v6...kind of.

NHibernate used to get around the issue by catching the NotSupportedException. Now it doesn't throw, but instead goes through:
SqliteDialect -> SqliteDataBaseMetaData -> AbstractDataBaseSchema -> GetReservedWords() -> Connection.GetSchema(string) with this implementation:

		public virtual ISet<string> GetReservedWords()
		{
			var result = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
			DataTable dtReservedWords = Connection.GetSchema(DbMetaDataCollectionNames.ReservedWords);
			foreach (DataRow row in dtReservedWords.Rows)
			{
				result.Add(row["ReservedWord"].ToString());
			}

			if (IncludeDataTypesInReservedWords)
			{
				DataTable dtTypes = Connection.GetSchema(DbMetaDataCollectionNames.DataTypes);
				foreach (DataRow row in dtTypes.Rows)
				{
					result.Add(row["TypeName"].ToString());
				}
			}

			return result;
		}

which then goes to SqliteConnection.GetSchema(string collectionName, Array.Empty())

        public override DataTable GetSchema(string collectionName, string?[] restrictionValues)
        {
            if (restrictionValues is not null && restrictionValues.Length != 0)
            {
                throw new ArgumentException(Resources.TooManyRestrictions(collectionName));
            }

            if (string.Equals(collectionName, DbMetaDataCollectionNames.MetaDataCollections, StringComparison.OrdinalIgnoreCase))
            {
                return new DataTable(DbMetaDataCollectionNames.MetaDataCollections)
                {
                    Columns =
                    {
                        { DbMetaDataColumnNames.CollectionName },
                        { DbMetaDataColumnNames.NumberOfRestrictions, typeof(int) },
                        { DbMetaDataColumnNames.NumberOfIdentifierParts, typeof(int) }
                    },
                    Rows =
                    {
                        new object[] { DbMetaDataCollectionNames.MetaDataCollections, 0, 0 },
                        new object[] { DbMetaDataCollectionNames.ReservedWords, 0, 0 }
                    }
                };
            }
            else if (string.Equals(collectionName, DbMetaDataCollectionNames.ReservedWords, StringComparison.OrdinalIgnoreCase))
            {
                var dataTable = new DataTable(DbMetaDataCollectionNames.ReservedWords)
                {
                    Columns =
                    {
                        { DbMetaDataColumnNames.ReservedWord }
                    }
                };

                int rc;
                string keyword;
                var count = sqlite3_keyword_count();
                for (var i = 0; i < count; i++)
                {
                    rc = sqlite3_keyword_name(i, out keyword);
                    SqliteException.ThrowExceptionForRC(rc, null);

                    dataTable.Rows.Add(new object[] { keyword });
                }

                return dataTable;
            }

            throw new ArgumentException(Resources.UnknownCollection(collectionName));
        }

DataTypes isn't handled there, so if IncludeDataTypesInReservedWords is true, which it always is for SqliteDataBaseMetaData, then it will throw the ArgumentException.

I don't how important DataTypes is in this context, but there's the research I've done. Hope I helped.

@da3dsoul
Copy link
Author

da3dsoul commented Oct 1, 2022

I am on 5.3.13, which came out today, btw

@hazzik
Copy link
Member

hazzik commented Oct 2, 2022

@da3dsoul NHibernate does not support Microsoft’s implementation of SQLite out of the box. I guess you are using one from NHibernate.Extensions. Please file bug there.

https://github.com/beginor/nhibernate-extensions

@hazzik hazzik closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2022
@da3dsoul
Copy link
Author

da3dsoul commented Oct 2, 2022

Ah actually it was FluentNHibernate. Fair enough. Well, just so you know, by making IncludeDataTypesInReservedWords false, it does seem to work. I can also confirm that the newer features like drop column work via SQLQuery, which is nice.
I appreciate you trying to point me in the right direction

@hazzik hazzik transferred this issue from nhibernate/nhibernate-core Oct 2, 2022
@hazzik hazzik reopened this Oct 2, 2022
hazzik added a commit that referenced this issue Sep 15, 2023
@hazzik hazzik modified the milestones: v3.2.1, v3.3.0 Sep 15, 2023
@hazzik hazzik added the bug label Sep 18, 2023
@hazzik
Copy link
Member

hazzik commented Sep 18, 2023

Fixed by #619

@hazzik hazzik linked a pull request Sep 18, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants