Getting the size of a field. lazarus / 16-Databases ---------------------------------------------------------------------- cov · 2013-05-15 21:06 I'm using Code: [Select]fldSz:=SQLQuery1.FieldByName('FIELDNAME').Size; to get the size of the field. However, fldsz reports that the field size (as defined by the VARCHAR(n) argument) is 11, yet opening the Table in Flame Robin suggest that the field size is actually VARCHAR(6). Is there any way of finding out what the field size is? ---------------------------------------------------------------------- howardpc · 2013-05-15 21:10 The apparent variation arises from ambiguity (or lack of clarity) about the units of measurement. Do you want the size in characters or bytes? And if in characters, what constitutes a character? And should the field be large enough to accommodate strings in the least compressed character encoding that might be encountered... or should it set aside a fixed storage amount per anticipated character (say two, or four bytes)? Does the size allow for string metadata (length, BOM, encoding) or a trailing #0? Database implementations vary in their anwers to these questions, and the defaults they assume. ---------------------------------------------------------------------- cov · 2013-05-15 21:17 I need the size of the field. If it's defined as VARCHAR(6), then I would expectCode: [Select] fldSz:=SQLQuery1.FieldByName(sfield).Size; to return '6'. But if it returns '12', that's also okay, so long as I can ascertain whether the value I'm about to insert will fit. ---------------------------------------------------------------------- cov · 2013-05-15 21:20 Sorry, the database I'm using is Firebrd. ---------------------------------------------------------------------- Lacak2 · 2013-05-16 05:54 You have only 2 options: use TField.Size which should be CHARACTER length and TField.DataSize which should be BYTE length But, correct results are returned only when used Single Bytes Character Sets. When you start using MBCS (Unicode, UTF8 etc.) then you must do your own "calculations" of size. It is IMO not good situation and is awaiting for resolving. ---------------------------------------------------------------------- cov · 2013-05-16 10:14 Oops! I was looking at the wrong table. Code: [Select]fldSz:=SQLQuery1.FieldByName(sfield).Size; does indeed return 6, if I specify the correct table!