1. Sathishkumar S
  2. PowerBuilder
  3. Thursday, 12 December 2024 16:10 PM UTC

Hi All,

I am using PowerBuilder 2022 R3 Build 3356 and MS SQL Server 2019 with the collation set to Latin1_General_100_CI_AI_SC_UTF8.

In a DataWindow, I have a column of type string with a length of 375. I have limited the users to type up to 375 characters only.

In the database, the column data type is varchar(375). The user is typing 375 characters, including some dashes.

However, I noticed an issue: the dash (–), which appears as a single character (ASCII code 226), requires 3 characters of storage length in the database. This leads to the DB error: String or binary data would be truncated.

 

I am using LEN function in PowerScript to find the number of characters typed by the user and display it to them.

Is there a way to find the data length instead of the number of characters?
Are there any other properties available to handle this?
Do you have any alternative ideas?

I need your help to resolve this issue.

Thank you in advance,
Sathishkumar S.

Who is viewing this page
Stuart Macandrew Accepted Answer Pending Moderation
  1. Friday, 13 December 2024 01:40 AM UTC
  2. PowerBuilder
  3. # 1

Copy to a blob variable specifying UTF8 encoding. And then test the len of the blob variable, which will then be the length in bytes and not characters.

Comment
  1. Sathishkumar S
  2. Friday, 13 December 2024 17:23 PM UTC
Hi Stuart,

I have tried as you have suggested, now I am able to count bytes instead of characters.

Thank you.
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Thursday, 12 December 2024 18:17 PM UTC
  2. PowerBuilder
  3. # 2

Hi, Sathishkumar -

PB uses Unicode 16LE encoding internally (2 bytes/char), but a varchar column in SQL Server is single byte/character. Perhaps the column in the table should be defined as nvarchar(375) instead to avoid the translation/expansion of the long dash character, if non-ASCII characters are going to be stored?

Best regards, John

Comment
  1. Chris Pollach @Appeon
  2. Thursday, 12 December 2024 18:38 PM UTC
Hi Sathishkumar ;

In addition to John's comment ...

Note that in UTF-8 based systems, extended characters can take anywhere from 2-4 ASCII characters in length in a DBMS column.

Regards ... Chris

  1. Helpful 1
  1. Sathishkumar S
  2. Friday, 13 December 2024 17:21 PM UTC
Hi John,

Thank you. I have changed the column in the table from varchar(375) to nvarchar(375), and now I am able to insert the record.



Hi Chris,

Yes, I can see in DBMS that the dash (–) took up 3 ASCII characters. I now have a better understanding of the datatypes.



Thanks & Regards,

Sathishkumar.

  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.