-- Test: TEST003
-- Functionality: This tests the exposure of UCS2 and disabling of 
--                UNICODE as a character set name, new translation 
--                names, and TERMINAL_CHARSET.
-- Expected files:   EXPECTED003
-- Tables created:   t001, t002
-- Limitations: None
--
-- @@@ START COPYRIGHT @@@
--
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements.  See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership.  The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License.  You may obtain a copy of the License at
--
--   http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied.  See the License for the
-- specific language governing permissions and limitations
-- under the License.
--
-- @@@ END COPYRIGHT @@@

obey TEST003(clnup);

log LOG003 clear;

--test the exposure of UCS2 and disabling of UNICODE 
--as a character set name.

--positive
--Table columns can be created to be associated with character set UCS2.
create table t002(c char(10) character set UCS2);

--INVOKE and SHOWDDL work for tables with columns associated with UCS2.
invoke t002;
showddl t002;

--negative
--Table columns can not be created to be assocated with UNICODE.
create table t003(c char(10) character set UNICODE);


?section dml

--positive
insert into t002 values(_ucs2'qwer');
update t002 set c = _UCS2'xxxx' where c = _UCS2'qwer';
delete from t002 where c = _UCS2'asdf';
select _UCS2'ucs2', _ISO88591'iso88591', c from t002;

--negative
insert into t002 values(_UNICODE'asdf');

--VARNCHAR disallowed
create table t004(c varnchar(10));


-------------------------------
--test translation name changes
-------------------------------

create table t001(c char(10));
insert into t001 values(x'4e');

?section dml
--New valid name. Case insensitive
select translate(_kanji'asdf' using KANJITOISO88591) from (values(1))x;
select translate(_ksc5601'1234' using KSC5601TOISO88591) from (values(1))x;
select translate(_UCS2'asdf' using UCS2TOISO88591) from (values(1))x;
insert into t002 
  select translate(c using iso88591ToUCS2) from t001 
     where c = x'4e';

--old name not allowed
insert into t001 values(translate(_UCS2'qwer' using UToL1));
insert into t001 values(translate(_UCS2'ewrt' using UNICODE_TO_ISO88591));
insert into t002 values(translate('asdf' using ISO88591TOUCS2));
insert into t002 values(translate('qwer' using L1ToU));
insert into t002 values(translate('ewrt' using ISO88591_TO_UNICODE));

-------------------------------
--test TERMINAL_CHARSETS 
-------------------------------

set terminal_charset iso88591;

-- the following should fail
set terminal_charset iso88592;
set terminal_charset ucs2;
set terminal_charset sjis;
set terminal_charset x0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789;

-- the default is ucs2. this is a no-op.
control query default national_charset 'ucs2';

--test CQD NATIONAL_CHARSET (should fail)
-------------------------------
control query default national_charset 'ios88591';

-- an invalid sqlci command, exercise the single-byte version of StoreSyntaxError()
bad_sqlci_cmd 1;

?section clnup
drop table t001;
drop table t002;

log;

