Subject Re: [firebird-support] Character set not preserved in view columns
Author Helen Borrie
At 08:38 PM 18/04/2007, you wrote:
>hi everyone,
>
>i am using FB 1.5.2.4731 SS (although the same happens with embedded)
>and i have the following problem:
>when i generate the view with a column which concatenates varchar
>columns from a table, the character set is not preserved. i am aware
>that it makes sense that FB will not guess the character set, but i
>don't know if this can be specified in some way.
>
>Example:
>
>SET SQL DIALECT 3;
>SET NAMES WIN1250;
>DEFAULT CHARACTER SET WIN1250;

DEFAULT CHARACTER SET X is not a statement, it is an optional clause
of the CREATE DATABASE statement. If you do not specify a default
character set for your database then it will be character set NONE
and any derived fields you create will be NONE....

Also, the SET... commands are not dynamic SQL statements, they are
isql commands to enable you to set up CLIENT connection attributes
inside an isql session in an interactive way. They work only in isql
(although some are available to the precompiler in embedded
applications via ESQL: the precompiler will convert them into calls
to macros encapsulating the appropriate API function calls).


>CREATE TABLE CUSTOMER (
> FIRST_NAME VARCHAR(128) CHARACTER SET WIN1250,
> LAST_NAME VARCHAR(128) CHARACTER SET WIN1250
>);
>
>CREATE VIEW V_CUSTOMERS(FULL_NAME)
>AS select c.first_name || ' ' || c.last_name
>from customer c;
>
>although first_name and last_name in CUSTOMER have win1250 character
>set specified, full_name in V_CUSTOMERS doesn't.

Correct.

>my questions:
>1. should FB use the default character set for the view column

YES

>, or is it my misunderstanding of how default charset works?

YES

>2. how can i specify the charset for the view column

Try this:

CREATE VIEW V_CUSTOMERS(FULL_NAME)
AS select
cast (first_name || ' ' || last_name as varchar(257) character set win1250)
from customer;

>(i modified the generated system domain for full_name column
>manually and that works)?

Can't tell what that means.

>i suppose that i could modify the view column domain by changing some
>entries in metadata tables,

Hmmm, you shouldn't consider changing the metadata tables at all.

>but is there some declarative way to do it within the view definition?

Yes, see above. But it usually makes more sense to define your
database with the appropriate default character set for the data you
are going to store and create (unless you have some special reason not to).

>3. does this behave the same in 2.0.* ?

In this respect, yes. But a lot has changed around character sets in v.2.0....

./heLen