🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.java
Article #154014

getByte('UTF-8'). length

#154014
From: J-23
Date: Thu, 15 May 2014 13:28
55 lines
3040 bytes
Witam
Piszę w jawie jedną rzecz i potrzebuje sprawdzić ile dane słowo np 
"Warszawa" zawiera miejsca w pamięci zakodowane jako UTF8

zacząłem za tym googlować i znalazłem coś takiego

String s = "Warszawa"
s.getByte('UTF-8').length - zwraca mi bodajrze 7 bajtów

mam pole w tabeli (baza Firebird)
zadeklarowane w ten sposób

KOD	VARCHAR(6)

IBExpert mnoży wielkość tego VARCHAR * 4

http://ibexpert.net/ibe/index.php?n=Doc.ConvertYourFirebirdApplicationsToUnicode

The importance of field size

The extra storage required by different character sets needs to be taken 
into consideration when specifying field size. For example, when you are 
working in a non-Unicode database:

  CREATE TABLE TEST5 (TXT VARCHAR(32000))

is not a problem, even though it’s not necessarily a good idea to define 
your VARCHAR(32000) that big. But you may have a problem in the Unicode 
database, because Firebird has to consider that the information that is 
stored here is could be, for example, a complete list of Chinese 
characters. As every single character needs up to 4 bytes, it must have 
the room to store up to 32000*4. So the actual maximum VARCHAR length 
with UTF8 is 8191 and not 32000.

This also needs to be taken into consideration when you are using 
variables; you have to think about the same issue. You should always 
take into consideration that variables might be subject to internal 
limitation.

And simply replacing your large VARCHARs with blobs is not necessarily 
the solution. Every time you change it, the versions are stored in the 
memory which can have a huge negative impact on server performance. So 
if you do work with variables that are blobs, do not manipulate them too 
often. Or alternatively work on VARCHAR variables and combine them in 
the last step to a single blob.

więc ja również pobieram tę wartość przemnożoną przez 4 co by dawało to 
(24 bajty) ale moje myślenie tutaj jest chyba błędne i nie powinienem 
pomnażać tej wartości przez 4 bo Firebird mi krzyczy że się nie mieści.

i tu pytanie do Was którą wartość powinienem brać pod uwagę to 
przemnożoną bo jak tak to oznacza że coś skopałem przy pobieraniu 
wielkości w bajtach UTF8?

Pozdrawiam
Technical Details
Message-ID: <ll2fe1$v5e$1@node1.news.atman.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
From: J-23 <baczeklu@o2.pl>
Newsgroups: pl.comp.lang.java
Subject: getByte('UTF-8'). length
Date: Thu, 15 May 2014 15:28:32 +0200
Organization: ATMAN - ATM S.A.
Lines: 55
Message-ID: <ll2fe1$v5e$1@node1.news.atman.pl>
NNTP-Posting-Host: 213-238-69-40.adsl.inetia.pl
Mime-Version: 1.0
X-Trace: node1.news.atman.pl 1400160513 31918 213.238.69.40 (15 May 2014 13:28:33 GMT)
X-Complaints-To: usenet@atman.pl
NNTP-Posting-Date: Thu, 15 May 2014 13:28:33 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit