LLBL Entity cannot get a string from a mysql longtext

Posts   
 
    
njbelf
User
Posts: 70
Joined: 07-Jun-2017
# Posted on: 10-Nov-2017 19:59:40   

Hi, I am not sure where the fault lies in this but we are attempting to get a string out of a mysql longtext column.

In the designer, the entity type uses a .NET type of string and the Field Mapping to the MySQL database shows the Longtext column with no warnings or error messages. However, when attempting to use the entity, we get the following exception:

System.InvalidCastException: 'Unable to cast object of type 'System.Byte[]' to type 'System.String'."

The pertinent code from the entity:

    public virtual System.String PossibleResponses
    {
        get { return (System.String)GetValue((int)QuestionsFieldIndex.PossibleResponses, true); }
        set { SetValue((int)QuestionsFieldIndex.PossibleResponses, value); }
    }

The exception is generated in the getter.

We are using Devart version 8.10 as the connector, and LLBL v5.2 RTM (5.2.3)

As I said at the beginning, I am not sure if this is an LLBL or Devart problem so I thought I would post in both places.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39612
Joined: 17-Aug-2003
# Posted on: 10-Nov-2017 22:46:15   

The database field type, is 'long text' and the field is seen by the designer as string typed field?

According to this: https://dev.mysql.com/doc/refman/5.7/en/blob.html LONG TEXT is seen as non-binary strings, and LONG BLOB is seen as binary strings. I know you can define 'binary' on a long text column in mysql, but that's not determined by our driver. We use describe table, which returns 'LONG TEXT' for the type, not whether it's binary or not.

Frans Bouma | Lead developer LLBLGen Pro
njbelf
User
Posts: 70
Joined: 07-Jun-2017
# Posted on: 13-Nov-2017 16:09:09   

Otis wrote:

The database field type, is 'long text' and the field is seen by the designer as string typed field?

That is correct.. we are not setting anything as 'binary' The field is a LONG TEXT in the MySQL database and actually holds JSON.

Otis wrote:

According to this: https://dev.mysql.com/doc/refman/5.7/en/blob.html LONG TEXT is seen as non-binary strings, and LONG BLOB is seen as binary strings. I know you can define 'binary' on a long text column in mysql, but that's not determined by our driver. We use describe table, which returns 'LONG TEXT' for the type, not whether it's binary or not.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 13-Nov-2017 16:46:58   

Is there a chance the code is not in synch with the view you are seeing in the designer?

Might be that the designer mapping has changed but code was not re-generated, as it seems that the field is treated as LongBlob, while in the designer it appears as Longtext.

So just to be sure could you please regenerated the code, and make sure you are using that recently generated code.

Thanks.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Nov-2017 06:05:41   

I can't reproduce it with a simple test:

[TestMethod]
public void FetchLongText()
{
    var customer = new CustomerEntity("ALFKI");
    using (var adapter = new DataAccessAdapter())
    {
        adapter.FetchEntity(customer);
    }

            
    Assert.IsNotNull(customer);
    Assert.IsFalse(customer.IsNew);
    Assert.IsTrue(customer.BigJsonData.Length > 0);
}

BigJsonData is a longtext. I'm using LLBLGen v5.2.2, Devart 8.2.65 and MySql 5.5

Please check what Walaa says. If it persists please give us more information:

  • TemplateSet (Adapter or SelfServicing)
  • Code that triggers the error
  • Full exception message and StackTrace
David Elizondo | LLBLGen Support Team
njbelf
User
Posts: 70
Joined: 07-Jun-2017
# Posted on: 14-Nov-2017 16:13:28   

Walaa wrote:

Is there a chance the code is not in synch with the view you are seeing in the designer?

Might be that the designer mapping has changed but code was not re-generated, as it seems that the field is treated as LongBlob, while in the designer it appears as Longtext.

So just to be sure could you please regenerated the code, and make sure you are using that recently generated code.

Thanks.

We traced the problem down to the MySQL database having been set up as UTF8. We changed it to Latin1 and it all seems to work just fine now.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 14-Nov-2017 17:10:22   

That wouldn't have crossed my mind frowning

Anyway, thanks for the feedback, surely someone will benefit from it.