Updating a record with cyrilic text

Hi i’m trying to update a record with a cyrilic text. But the text get saved as
???

my field is set as nvarchar(max) and in fact if I set the record manually on the db the value is stored correctly.
But when saved from OrmLite it goes crazy.

I never had to deal with cyrilic so I may miss something.

my orm lite poco is

  [CompositeIndex(new string[] {"Key", "LanguageId", "ApplicationId"}, Unique = true)]
  public class Translation : AuditBase, IHasIntId, IHasId<int>
  {
    [AutoIncrement]
    public int Id { get; set; }

    [Reference]
    public Application Application { get; set; }

    public int ApplicationId { get; set; }

    public string Key { get; set; }

    [Reference]
    public Language Language { get; set; }

    public int LanguageId { get; set; }

    [CustomField("{NMAX_TEXT}")]
    public string Value { get; set; }
  }

OrmLite just passes the string as a parameter to the underlying ADO .NET provider, so the underlying RDBMS data type and/or collation needs to support it.

What’s the problematic SQL OrmLite generates that has the issue?

OrmLiteUtils.PrintSql();

This is the output

UPDATE "Translation" SET "ApplicationId"=@ApplicationId, "Key"=@Key, "LanguageId"=@LanguageId, "Value"=@Value, "CreatedDate"=@CreatedDate, "CreatedBy"=@CreatedBy, "ModifiedDate"=@ModifiedDate, "ModifiedBy"=@ModifiedBy, "DeletedDate"=@DeletedDate, "DeletedBy"=@DeletedBy WHERE "Id"=@Id
PARAMS: @Id=36, @ApplicationId=2, @Key=continue, @LanguageId=3, @Value=Продолжай, @CreatedDate=01/31/2021 22:12:17, @CreatedBy=admin@localhost.local, @ModifiedDate=01/31/2021 22:12:17, @ModifiedBy=admin@localhost.local, @DeletedDate=, @DeletedBy=

Looking around i found that this is working

update Translation SET Value = N'недавний чемодан' where Id = 34

this is not
update Translation SET Value = 'недавний чемодан' where Id = 34

basically before the string an N should be added, there is any way i can add this N?, on my real app i’m using autocrud.

That’s expected behavior when using inline SQL when inserting Unicode text in literal strings, it’s not an option in DB parameters which shouldn’t need it. What’s the value you’re inserting and what’s the data type you’re inserting it into? If you’ve used OrmLite to generate the table can you provide the CREATE TABLE SQL.

The data type i’m inserting into is nvarchar(max) on the Value Column

create table Translation
(
    Id            int identity
        primary key,
    ApplicationId int           not null,
    [Key]         varchar(8000),
    LanguageId    int           not null,
    Value         nvarchar(max),
    CreatedDate   datetime      not null,
    CreatedBy     varchar(8000) not null,
    ModifiedDate  datetime      not null,
    ModifiedBy    varchar(8000) not null,
    DeletedDate   datetime,
    DeletedBy     varchar(8000)
)
go

create index idx_translation_deleteddate
    on Translation (DeletedDate)
go

create unique index uidx_translation_key_languageid_applicationid
    on Translation ([Key], LanguageId, ApplicationId)
go

Can you try changing the StringConverter to use unicode by default:

OrmLiteConfig.DialectProvider.GetStringConverter().UseUnicode = true;
1 Like

Yeah now it works :slight_smile: thanks as usual your support is really appreciated you saved me :smile:

1 Like