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

Support Guid ToString in SqLite, add test for mssql and sqlite #4297

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

jogibear9988
Copy link
Member

@jogibear9988 jogibear9988 commented Oct 10, 2023

Fix #4295

@jogibear9988
Copy link
Member Author

Should I add "Guid.ToString" in Expressions.cs and create a Builder wich does nothing in Standard and in Sqlite I implement the logic. Same as I've done for TimeSpan in this: https://github.com/linq2db/linq2db/pull/3994/files#diff-0381ba7e238d0f1809d47075f54b06e6c5fb0dfd9c7f0ed1017188c0eab15e38
Would this be a better solution?

@MaceWindu
Copy link
Contributor

I'm a bit lost here. What you need to achieve? If you need guid.ToString mapping to SQL you should implement it in mappings (Expressions.cs probably).

Another thing that looks incorrect is that proposed mapping generates upper-case guid. It is common to use lowercased guid string and default mapping should generate lowercased guid.

@jogibear9988
Copy link
Member Author

I'm a bit lost here. What you need to achieve? If you need guid.ToString mapping to SQL you should implement it in mappings (Expressions.cs probably).

Another thing that looks incorrect is that proposed mapping generates upper-case guid. It is common to use lowercased guid string and default mapping should generate lowercased guid.

I'd like to be able to use for example guid.ToString().Contains("aa") in LINQ.
I can change to a lowercase. And I look to move to expressions

@igor-tkachev
Copy link
Member

We already have it for other types. See Expressions.cs line 555.

@jogibear9988
Copy link
Member Author

@igor-tkachev
changed code to use expression.cs and a converter in Sql Helper class

@jogibear9988
Copy link
Member Author

/azp run test-all

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@linq2dbot
Copy link

Test baselines changed by this PR. Don't forget to merge/close baselines PR after this pr merged/closed.

@jogibear9988
Copy link
Member Author

/azp run test-all

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jogibear9988
Copy link
Member Author

The test 3791 does not work for ClickHouse with this change

ClickHouse.Client.ClickHouseServerException : Code: 53. DB::Exception: Can't infer common type for joined columns: OtherId: Nullable(String) at left, a_Association.Id: UUID at right. There is no supertype for types String, UUID because some of them are String/FixedString and some of them are not. (TYPE_MISMATCH) (version 23.12.2.59 (official build))

	public void Issue3791Test([DataSources] string context)
	{
		var ms = new MappingSchema();
		ms.SetConvertExpression<Guid, string>(a => a.ToString());
		ms.SetConvertExpression<string, Guid>(a => Guid.Parse(a));

		using var db = GetDataContext(context);

		using var table = db.CreateLocalTable<Issue3791Table>();
		using var _     = db.CreateLocalTable<Issue3791GuidTable>();

		table.LoadWith(a => a.Association).ToList();
	}

but for me it's not clear, when the convertExpression is used. Do I need to change smth. or need this to be fixed inside of linq2db?

@jogibear9988
Copy link
Member Author

Is the ms.SetConvertExpression<Guid, string> used before my handling of ToSting in Expressions.cs?

@jogibear9988
Copy link
Member Author

/azp run test-all

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jogibear9988
Copy link
Member Author

/azp run test-all

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jogibear9988
Copy link
Member Author

/azp run test-all

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@linq2dbot
Copy link

Test baselines changed by this PR. Don't forget to merge/close baselines PR after this pr merged/closed.

@jogibear9988
Copy link
Member Author

all tests work, ready for review

viceroypenguin
viceroypenguin previously approved these changes Jan 31, 2024
viceroypenguin
viceroypenguin previously approved these changes Jan 31, 2024
@viceroypenguin
Copy link
Contributor

/azp run test-all

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jogibear9988
Copy link
Member Author

1 test failed, but it's unrelated to the pull req, cause the Code from the pull req is only used in the new test...

image

Source/LinqToDB/Sql/Sql.cs Show resolved Hide resolved
Source/LinqToDB/Linq/Expressions.cs Show resolved Hide resolved
Source/LinqToDB/Sql/Sql.cs Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Override how Guid.ToString for Sqlite is implemented in SQL
7 participants