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

Sqlite: Cast from char to int gives incorrect results #23161

Closed
Tracked by #22950
bricelam opened this issue Oct 31, 2020 · 1 comment · Fixed by #31585
Closed
Tracked by #22950

Sqlite: Cast from char to int gives incorrect results #23161

bricelam opened this issue Oct 31, 2020 · 1 comment · Fixed by #31585
Assignees
Labels
area-query area-sqlite closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. punted-for-6.0 type-bug
Milestone

Comments

@bricelam
Copy link
Contributor

bricelam commented Oct 31, 2020

Currently, we generate CAST($charValue AS INTEGER), but this gives incorrect results for digit characters. Instead, we should generate unicode($charValue).

using System.Diagnostics;
using System.Linq;
using Microsoft.EntityFrameworkCore;

var db = new Context();
db.Database.OpenConnection();
db.Database.EnsureCreated();

var value = db.Entities
    .Select(e => (int)e.Value)
    .First();
Debug.Assert(value == 49);

class Entity
{
    public int Id { get; set; }
    public char Value { get; set; }
}

class Context : DbContext
{
    public DbSet<Entity> Entities { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder options)
        => options.UseSqlite("Data Source=:memory:");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Entity>()
            .HasData(new Entity { Id = 1, Value = '1' });
    }
}
@bricelam
Copy link
Contributor Author

bricelam commented Oct 31, 2020

The opposite is also true, but only for integer values 0-9, so it seems less important. If we want to go the extra mile, that translation would be char($intValue).

@ajcvickers ajcvickers added this to the 6.0.0 milestone Nov 3, 2020
@AndriySvyryd AndriySvyryd modified the milestones: 6.0.0, Backlog Sep 15, 2021
@bricelam bricelam removed their assignment Jul 8, 2023
@bricelam bricelam self-assigned this Aug 29, 2023
bricelam added a commit to bricelam/efcore that referenced this issue Aug 29, 2023
@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 29, 2023
@bricelam bricelam modified the milestones: Backlog, 8.0.0 Aug 29, 2023
bricelam added a commit to bricelam/efcore that referenced this issue Aug 31, 2023
bricelam added a commit that referenced this issue Aug 31, 2023
@bricelam bricelam modified the milestones: 8.0.0, 8.0.0-rc2 Aug 31, 2023
@ajcvickers ajcvickers modified the milestones: 8.0.0-rc2, 8.0.0 Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query area-sqlite closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. punted-for-6.0 type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants