Locale setting and custom locales
Files for locale setting
Section titled “Files for locale setting”CoraDB uses following directories and files to set the locales.
- $CORADB/conf/coradb_locales.txt file: A configuration file containing the list of locales to be supported
- $CORADB/conf/coradb_locales.all.txt file: A configuration file template with the same structure as coradb_locales.txt. Contains the entire list of all the locales that the current version of CoraDB is capable of supporting without any efforts from the end user's side.
- $CORADB/locales/data directory: This contains files required to generate locale data.
- $CORADB/locales/loclib directory: contains a C header file, locale_lib_common.h and OS dependent makefile which are used in the process of creating / generating locales shared libraries.
- $CORADB/locales/data/ducet.txt file: Text file containing default universal collation information (codepoints, contractions and expansions, to be more specific) and their weights, as standardized by The Unicode Consortium, which is the starting point for the creation of collations. For more information, see http://unicode.org/reports/tr10/#Default_Unicode_Collation_Element_Table .
- $CORADB/locales/data/unicodedata.txt file: Text file containing information about each Unicode codepoint regarding casing, decomposition, normalization etc. CoraDB uses this to determine casing. For more information, see https://docs.python.org/3/library/unicodedata.html .
- $CORADB/locales/data/ldml directory: common_collations.xml and XML files, name with the convention coradb_<locale_name>.xml. common_collations.xml file contains shared collation information in all locale files, and each coradb_<locale_name>.xml file contains a locale information for the supported language.
- $CORADB/locales/data/codepages directory: contains codepage console conversion for single byte codepages(8859-1.txt , 8859-15.txt, 8859-9.txt) and codepage console conversion for double byte codepages(CP1258.txt , CP923.txt, CP936.txt , CP949.txt).
- $CORADB/bin/make_locale.sh (Linux) or %CORADB%\bin\make_locale_x64.bat (Windows): A script file used to generate shared libraries for locale data
- $CORADB/lib directory: Shared libraries for generated locales will be stored here.
Locale setting
Section titled “Locale setting”When you want to use a charset and collation of a specific language, the charset should be identical with a database which will be created newly. Supported CoraDB charsets are ISO-8859-1, EUC-KR and UTF-8 and the charset to be used is specified when creating a database.
For example, when you created a database with a locale ko_KR.utf8, you can use collations starting with "utf8_" like utf8_ja_exp. However, if you set the locale as ko_KR.euckr, you cannot use all collations which are related with other charset (see CoraDB collation).
The following is an example which used utf8_ja_exp after creating a database with en_US.utf8.
-
cd $CORADB/conf
-
cp coradb_locales.all.txt coradb_locales.txt
-
make_locale.sh # compile all configured locales
-
coradb createdb testdb en_US.utf8
-
coradb server start testdb
-
corasql -u dba testdb
-
Run below query on corasql
SET NAMES utf8;CREATE TABLE t1 (i1 INT , s1 VARCHAR(20) COLLATE utf8_ja_exp, a INT, b VARCHAR(20) COLLATE utf8_ja_exp);INSERT INTO t1 VALUES (1, 'いイ基盤',1,'いイ 繭');
For more details, see the following.
Step 1: selecting a locale
Section titled “Step 1: selecting a locale”Configure locales to use on $CORADB/conf/coradb_locales.txt. You can select all or some of locales which are supported.
CoraDB supports locales as follows: en_US, de_DE, es_ES, fr_FR, it_IT, ja_JP, km_KH, ko_KR, tr_TR, vi_VN, zh_CN, ro_RO.
The language and country for each locale are shown in the following table.
| Locale name | Language - country |
|---|---|
| en_US | English - U.S.A. |
| de_DE | German - Germany |
| es_ES | Spanish - Spain |
| fr_FR | French - France |
| it_IT | Italian - Italy |
| ja_JP | Japanese - Japan |
| km_KH | Khmer - Cambodia |
| ko_KR | Korean - Korea |
| tr_TR | Turkish - Turkey |
| vi_VN | Vietnamese - Vietnam |
| zh_CN | Chinese - China |
| ro_RO | Romanian - Romania |
Step 2: compiling locale
Section titled “Step 2: compiling locale”Once the requirements described above are met, the locales can be compiled.
Regarding the embedded locales in CoraDB, they can be used without compiling user locale library, so they can be used by skipping the step 2. But there are differences between the embedded locale and the library locale. Regarding this, see Built-in locale and library locale.
To compile the locale libraries, one must use the make_locale (.bat for Windows and .sh for Linux) utility script from command console. The file is delivered in $CORADB/bin folder so it should be resolved by $PATH environment variable. Here $CORADB, $PATH are the environment variables of Linux, %CORADB%, %PATH% are the environment variables of Windows.
make_locale.sh -h shows the usage.
make_locale.sh [options] [locale]
options ::= [-t 64] [-m debug|release]locale ::= de_DE | es_ES | fr_FR | it_IT | ja_JP | km_KH | ko_KR | tr_TR | vi_VN | zh_CN | ro_RO- options
- -t: target machine; only 64-bit (
64,x64,x86_64,64bit) is supported, and it is the default. - -m: Selects release or debug. In general, release is selected (default value: release). The debug mode is provided for developers who would like to write the locale library themselves. Selects release or debug. In general, release is selected (default value: release). The debug mode is provided for developers who would like to write the locale library themselves.
- -t: target machine; only 64-bit (
- locale: The locale name of the library to build. If locale is not specified, the build includes data from all configured locales. In this case, library file is stored in $CORADB/lib directory with the name of libcoradb_all_locales.so (.dll for Windows).
To create user defined locale shared libraries, two choices are available:
-
Creating a single lib with all locales to be supported.
make_locale.sh # build and pack all configured locales (64-bit, release) -
Creating one lib for each locale to be supported.
make_locale.sh -m release ko_KR # one library for ko_KR only
The first choice is recommended. In this scenario, some data may be shared among locales. If you choose the first one, a lib supporting all locales has less than 15 MB; in the second one, consider for each locale library from 1 MB to more than 5 MB. Also the first one is recommended because it has no runtime overhead during restarting the servers when you choose the second one.
Step 3: setting CoraDB to use a specific locale
Section titled “Step 3: setting CoraDB to use a specific locale”Only one locale can be selected as the default locale when you create DB.
In addition to the possibility of specifying a default locale, one can override the default calendar settings with the calendar settings from another locale, using the intl_date_lang system parameter.
- The locale will be in the format: <locale_name>.[utf8 | iso] (for example
tr_TR.utf8,en_US.iso88591,ko_KR.utf8) - intl_date_lang: <locale_name>. The possible values for <locale_name> are listed on Step 1: selecting a locale.
Built-in locale and library locale
Section titled “Built-in locale and library locale”Regarding the embedded locales in CoraDB, they can be used without compiling user locale library, so they can be used by skipping the step 2. But there are two differences between the embedded locale and the library locale.
- Embedded(built-in) locale(and collation) are not aware of Unicode data For instance, casing (lower, upper) of (Á, á) is not available in embedded locales. The LDML locales provide data for Unicode codepoints up to 65535.
- Also, the embedded collations deals only with ASCII range, or in case of 'utf8_tr_cs' - only ASCII and letters from Turkish alphabet. Embedded UTF-8 locales are not Unicode compatible, while compiled (LDML) locales are.
Currently, the built-in locales which can be set during creating DB are as follows:
- en_US.iso88591
- en_US.utf8
- ko_KR.utf8
- ko_KR.euckr
- ko_KR.iso88591: Will have Romanized Korean names for month, day names.
- tr_TR.utf8
- tr_TR.iso88591: Will have Romanized Turkish names for month, day names.
The order stated above is important; if no charset is defined while creating DB, the charset is the charset of the locale shown first. For example, if the locale is set as ko_KR(e.g. coradb createdb testdb ko_KR), the charset is specified as ko_KR.utf8, the first locale among the ko_KR in the above list. Locales of the other languages except the built-in locales should end with .utf8. For example, specify the locale as de_DE.utf8 for German.
The names of month and day for ko_KR.iso88591 and tr_TR.iso88591 should be Romanized. For example, "일요일" for Korean (Sunday in English) is Romanized to "Iryoil". Providing ISO-8859-1 characters only is required. For more information, see The month/day in Korean and Turkish characters for ISO-8859-1 charset.
The month/day in Korean and Turkish characters for ISO-8859-1 charset
Section titled “The month/day in Korean and Turkish characters for ISO-8859-1 charset”In Korean or Turkish which have charset UTF-8 or in Korean which have charset EUC-KR, the month/day in characters and AM/PM are encoded according to the country. However, for ISO-8859-1 charset, if the month/day in characters and AM/PM in Korean or Turkish is used as its original encoding, an unexpected behavior may occur in the server process because of its complex expression. Therefore, the name should be Romanized. The default charset of CoraDB is ISO-8859-1 and the charset can be used for Korean and Turkish. The Romanized output format is as follows:
Day in characters
| Day in characters long/short format | Long/short romanized Korean | Long/short romanized Turkish |
|---|---|---|
| Sunday / Sun | Iryoil / Il | Pazar / Pz |
| Monday / Mon | Woryoil / Wol | Pazartesi / Pt |
| Tuesday / Tue | Hwayoil / Hwa | Sali / Sa |
| Wednesday / Wed | Suyoil / Su | Carsamba / Ca |
| Thursday / Thu | Mogyoil / Mok | Persembe / Pe |
| Friday / Fri | Geumyoil / Geum | Cuma / Cu |
| Saturday / Sat | Toyoil / To | Cumartesi / Ct |
Month in characters
| Month in characters long/short format | Long/short romanized Korean (not classified) | Long/short romanized Turkish |
|---|---|---|
| January / Jan | 1wol | Ocak / Ock |
| February / Feb | 2wol | Subat / Sbt |
| March / Mar | 3wol | Mart / Mrt |
| April / Apr | 4wol | Nisan / Nsn |
| May / May | 5wol | Mayis / Mys |
| June / Jun | 6wol | Haziran / Hzr |
| July / Jul | 7wol | Temmuz / Tmz |
| August / Aug | 8wol | Agustos / Ags |
| September / Sep | 9wol | Eylul / Eyl |
| October / Oct | 10wol | Ekim / Ekm |
| November / Nov | 11wol | Kasim / Ksm |
| December / Dec | 12wol | Aralik / Arl |
AM/PM in characters
| AM/PM in characters long/short format | Romanized in Korean | Romanized in Turkish |
|---|---|---|
| AM | ojeon | AM |
| PM | ohu | PM |
Step 4: creating a database with the selected locale setting
Section titled “Step 4: creating a database with the selected locale setting”When issuing the command "coradb createdb <db_name> <locale_name.charset>", a database will be created using the settings in the variables described above.
Once the database is created a locale setting which was given to the database cannot be changed. The charset and locale name are stored in "db_root" system catalog table.
Step 5 (optional): manually verifying the locale file
Section titled “Step 5 (optional): manually verifying the locale file”The contents of locales libraries may be displayed in human readable form using the dumplocale CoraDB utility. Execute coradb dumplocale -h to output the usage. The used syntax is as follows.
coradb dumplocale [options] [language-string]
options ::= -i|--input-file <shared_lib> -d|--calendar -n|--numeric {-a |--alphabet=}{l|lower|u|upper|both} -c|--codepoint-order -w|--weight-order {-s|--start-value} <starting_codepoint> {-e|--end-value} <ending_codepoint> -k -z
language-string ::= de_DE|es_ES|fr_FR|it_IT|ja_JP|km_KH|ko_KR|tr_TR|vi_VN|zh_CN|ro_RO- dumplocale: A command which dumps the contents of locale shared library previously generated using LDML input file.
- language-string: One of de_DE, es_ES, fr_FR, it_IT, ja_JP, km_KH, ko_KR, tr_TR, vi_VN, zh_CN and ro_RO. Configures the locale language to dump the locale shared library. If it's not set, all languages which are configured on coradb_locales.txt are given.
The following are [options] for coradb dumplocale.
The name of the locale shared library file (< shared_lib>) created previously. It includes the directory path.
Dumps the calendar and date/time data. Default value: No
Dumps the number data. Default value: No
-a, --alphabet=l|lower|u|upper|both
Dumps the alphabet and case data. Default value: No
--identifier-alphabet=l|lower|u|upper
Dumps the alphabet and case data for the identifier. Default value: No
Dumps the collation data sorted by the codepoint value. Default value: No (displayed data: cp, char, weight, next-cp, char and weight)
Dumps the collation data sorted by the weight value. Default value: No (displayed data: weight, cp, char)
Specifies the dump scope. Starting codepoint for -a, --identifier-alphabet, -c, -w options. Default value: 0
Specifies the dump scope. Ending codepoint for -a, --identifier-alphabet, -c, -w options. Default value: Max value read from the locale shared library.
Dumps the data of console conversion. Default value: No
Dumps the normalization data. Default value: No
The following example shows how to dump the calendar, number formatting, alphabet and case data, alphabet and case data for the identifier, collation sorting based on the codepoint order, collation sorting based on the weight, and the data in ko_KR locale into ko_KR_dump.txt by normalizing:
% coradb dumplocale -d -n -a both -c -w -z ko_KR > ko_KR_dump.txtIt is highly recommended to redirect the console output to a file, as it can be very big data, and seeking information could prove to be difficult.
Step 6: starting CoraDB-Related processes
Section titled “Step 6: starting CoraDB-Related processes”All CoraDB-related processes should be started in an identical environmental setting. The CoraDB server, the broker, CAS, and corasql should use the locale binary file of an identical version. For example, master server.
There is no check on the compatibility of the locale used by server and CAS (client) process, so the user should make sure the LDML files used are the same.
Locale library loading is one of the first steps in CoraDB start-up. Locale (collation) information is required for initializing databases structures (indexes depends on collation). This process is performed by each CoraDB process which requires locale information: server, CAS, corasql, createdb, copydb, unload, load DB.
The process of loading a locale library is as follows.
- If no lib path is provided, CoraDB will try to load $CORADB/lib/libcoradb_<lang_name>.so file; if this file is not found, then CoraDB assumes all locales are found in a single library: $CORADB/lib/libcoradb_all_locales.so.
- If suitable locale library cannot be found or any other error occurs during loading, the CoraDB process stops.
- If collations between the database and the locale library are different, the CoraDB process cannot start. To include the newly changed collations of the locale library, firstly synchronize the database collation with the system collation by running coradb synccolldb command. Next, update from the existing database to the wanted collations of schemas and data. For more details, see Synchronization of database collations with system collations.
Synchronization of database collations with system collations
Section titled “Synchronization of database collations with system collations”CoraDB's normal operation requires that the system collation and the database collation must be the same. The system locale means that the locale which include built-in locales and library locales created through coradb_locales.txt (see Locale setting), and it includes the system collation information. The database collation information is stored on the _db_collation system catalog table.
coradb synccolldb utility checks if the database collation is the same with the system collation, and synchronize into the system collation if they are different. However, note that this utility doesn't transform the data itself stored on the database.
This utility can be used when the existing database collation should be changed after the system locale is changed. However, there are operations which the user have to do manually.
The user should do this operations before the synchronization. These operations can be done by running corasql with coradb_synccolldb_<database_name>.sql file, which is created by coradb synccolldb -c.
- Change collation using ALTER TABLE .. MODIFY statement.
- Remove any views, indexes, triggers or partitions containing the collation.
Run synchronization with coradb synccolldb. After then, do the following operations.
- Recreate views, indexes, triggers, or partitions
- Update application statements to use new collations
This utility should work only in offline mode.
synccolldb syntax is as follows.
coradb synccolldb [options] database_name- coradb: An integrated utility for the CoraDB service and database management.
- synccolldb: A command to synchronize collations of a database with collations from the system(according to contents of locales libraries and $CORADB/conf/coradb_locales.txt).
- database_name: A database name to be synchronized with collations from the system.
If [options] is omitted, synccolldb checks the collation differences between the system and the database, synchronize the database collation with the system collation, and create the coradb_synccolldb_<database_name>.sql file including the queries of objects to be dropped before the synchronization.
The following are [options] which are used on coradb synccolldb.
This option prints out the collation information which is different between the database collation and the system collation.
This option doesn't ask when updating the database collation with the system collation.
The following shows that how it works when the system collation and the database collation are different.
Firstly, make locale library about ko_KR locale.
$ echo ko_KR > $CORADB/conf/coradb_locales.txt$ make_locale.shNext, create the database.
$ coradb createdb --db-volume-size=20M --log-volume-size=20M xdb en_USCreate a schema. At this time, specify the needed collation in each table.
$ corasql -S -u dba xdb -i in.sqlCREATE TABLE dept(depname STRING PRIMARY KEY) COLLATE utf8_ko_cs_uca;CREATE TABLE emp(eid INT PRIMARY KEY, depname STRING,address STRING) COLLATE utf8_ko_cs_uca;ALTER TABLE emp ADD CONSTRAINT FOREIGN KEY (depname) REFERENCES dept(depname);Change the locale setting of the system. If you do not any values on coradb_locales.txt, the database consider that only built-in locales exist
$ echo "" > $CORADB/conf/coradb_locales.txtCheck the difference between system and database by running coradb synccolldb -c command.
$ coradb synccolldb -c xdb
--------------------------------------------------------------------------------Collation 'utf8_ko_cs_uca' (Id: 133) not found in database or changed in new system configuration.--------------------------------------------------------------------------------Collation 'utf8_gen_ci' (Id: 44) not found in database or changed in new system configuration.--------------------------------------------------------------------------------Collation 'utf8_gen_ai_ci' (Id: 37) not found in database or changed in new system configuration.--------------------------------------------------------------------------------Collation 'utf8_gen' (Id: 32) not found in database or changed in new system configuration.--------------------------------------------------------------------------------There are 4 collations in database which are not configured or are changed compared to system collations.Synchronization of system collation into database is required.Run 'coradb synccolldb -f xdb'If the indexes exist, firstly you should remove the indexes, and change the collation of each table, then recreate the indexes directly. The process to remove indexes and change the collation of tables can be executed by using coradb_synccolldb_xdb.sql file which was created by synccolldb command. On the below example, a foreign key is the index which you should recreate.
$ cat coradb_synccolldb_xdb.sql
ALTER TABLE [dept] COLLATE utf8_bin;ALTER TABLE [emp] COLLATE utf8_bin;ALTER TABLE [emp] DROP FOREIGN KEY [fk_emp_depname];ALTER TABLE [dept] MODIFY [depname] VARCHAR(1073741823) COLLATE utf8_bin;ALTER TABLE [emp] MODIFY [address] VARCHAR(1073741823) COLLATE utf8_bin;ALTER TABLE [emp] MODIFY [depname] VARCHAR(1073741823) COLLATE utf8_bin;
$ corasql -S -u dba -i coradb_synccolldb_xdb.sql xdbRemoving the obsolete collations by executing the above coradb_synccolldb_xdb.sql script file must be performed before forcing the synchronization of system collations into database.
Run coradb synccolldb command. If the option is omitted, the message is shown to ask to run this command or not; if the -f option is given, the synchronization is run without checking message.
$ coradb synccolldb xdbUpdating system collations may cause corruption of database. Continue (y/n) ?Contents of '_db_collation' system table was updated with new system collations.Recreate the dropped foreign key.
$ corasql -S -u dba xdb
ALTER TABLE emp ADD CONSTRAINT FOREIGN KEY fk_emp_depname(depname) REFERENCES dept(depname);Guide for adding locales and collations
Section titled “Guide for adding locales and collations”Most new locales and/or collations can be added by user simply by adding (or changing) a new (existing) LDML file. The LDML files format used by CoraDB are derived from generic Unicode Locale Data Markup Language (http://www.unicode.org/reports/tr35/). The tags and attributes which are specific only to CoraDB can be easily identified (they contain a "coradb" into the naming).
The best approach to add a new locale is to copy existing LDML file and tweak various setting until desired results are obtained. The filename must be formatted like coradb_<language>.xml and be placed in the folder $CORADB/locales/data/ldml. The <language> part should be a ASCII string (normally five characters) in IETF format (https://en.wikipedia.org/wiki/BCP_47). After creating the LDML file, the <language> part string must be added into CoraDB configuration file $CORADB/conf/coradb_locales.txt. Note that the order in this file is the order of generating (compiling) locale library and loading locales at start-up.
The make_locale script must be used to compile the new added locale and add its data into the CoraDB locales library (locale in $CORADB/lib/).
The LDML file is expected in UTF-8 encoding, and it is not possible to add more than one locale into the same LDML file.
Adding a new locale in LDML file requires:
- To specify calendar information (CoraDB date formats, name of months and week days in various forms, names for AM/PM day periods). CoraDB supports only Gregorian calendar (generic LDML specifies other calendar types which are not supported by CoraDB).
- To specify number settings (digit grouping symbols)
- Providing an alphabet (set of rules for how letters are upper-cased and lower-cased)
- Optionally, some collations can be added
- Also optionally, console conversion rules for Windows corasql application can be defined
LDML calendar information
Section titled “LDML calendar information”- The first part consists in providing default CoraDB formats for DATE, DATETIME, TIME, TIMESTAMP, DATETIME WITH TIME ZONE and TIMESTAMP WITH TIME ZONE data type conversion to/from string. This formats are used by functions TO_DATE, TO_TIME, TO_DATETIME, TO_TIMESTAMP, TO_CHAR, TO_DATETIME_TZ, TO_TIMESTAMP_TZ. The formats elements allowed depend on data type and are the ones used for TO_CHAR function (Date/time format 1). Only ASCII characters are allowed in the format strings. The allowed size are 30 bytes (characters) for DATE and TIME formats, 48 characters for DATETIME and TIMESTAMP formats and 70 characters for DATETIME WITH TIME ZONE and TIMESTAMP WITH TIME ZONE.
- The <months> requires to specify the names for months in both long form and abbreviated form. The allowed size are 15 (or 60 bytes) for abbreviated form and 25 characters (or 100 bytes) for normal form.
- The <days> requires week day names in both long and abbreviated form. The allowed size are 10 characters (or 40 bytes) for abbreviated form and 15 characters (or 60 bytes) for full day name.
- The <dayperiods> sub-tree requires to define the string for AM/PM format variants (according to type attribute). The allowed size is 10 characters (or 40 bytes).
The months and week-days names (in both long and abbreviated form) must be specified in Camel case format (first letter upper case, the rest in lower case). CoraDB checks only the maximum allowed size in bytes; the size in characters is computed only for full-width UTF-8 characters (4 bytes), so it would be possible to set a month name having 100 ASCII-only characters (the 25 characters limit is when each character from month name is encoded on 4 bytes in UTF-8).
LDML numbers information
Section titled “LDML numbers information”- The <symbols> tag defines the characters used as symbols for splitting decimal part from integer part in numbers and for grouping the digits. CoraDB expects only ASCII characters for these symbols. Empty of space character is not allowed. CoraDB performs grouping for 3 digits.
| Currency ISO symbol | Meaning |
|---|---|
| USD | Dollar sign |
| JPY | Japanese yen |
| GBP | British pound |
| KRW | Korean won |
| TRY | Turkish lira |
| KHR | Cambodian riel |
| CNY | Chinese renminbi |
| INR | Indian rupee |
| RUB | Russian ruble |
| AUD | Australian dollar |
| CAD | Canadian dollar |
| BRL | Brasilian real |
| RON | Romanian leu |
| EUR | Euro |
| CHF | Swiss franc |
| DKK | Danish krone |
| NOK | Norwegian krone |
| BGN | Bulgarian lev |
| VND | Vietnamese dong |
| CZK | Czech koruna |
| PLN | Polish zloty |
| SEK | Swedish krona |
| HRK | Croatian kuna |
| RSD | Serbian dinar |
LDML alphabet
Section titled “LDML alphabet”These allow to define casing rules for alphabet of the locale. The 'CoraDBAlphabetMode' attribute defines the primary source of data for characters. Normally, this should be set to "UNICODEDATAFILE", values which instructs CoraDB to use the Unicode data file ($CORADB/locales/data/unicodedata.txt).
This file must not be modified, any customization on certain characters should be done in LDML file. If such value is configured, all Unicode characters up to codepoint 65535 are loaded with casing information. The other allowed value for CoraDBAlphabetMode is "ASCII" which will lead to only ASCII character can be lower case, upper case or case-insensitive compare in matching functions.
This does not affect CoraDB's ability to support all UTF-8 4 bytes encoded Unicode characters, it just limits the casing ability for characters not included.
The casing rules are optional and apply on top of the primary source of character information (UNICODEDATAFILE or ASCII).
CoraDB allows to define upper casing rules (<u> tag) and lower casing rules (<l> tag).Each of upper and lower casing rules set consists for pairs of source-destination (<s> = source, <d> = destination). For instance, the following defines a rule that each character "A" is lower cased to "aa" (two character "a").
<l> <s>A</s> <d>aa</d></l>LDML console conversion
Section titled “LDML console conversion”In Windows, the console does not support UTF-8 encoding, so CoraDB allows to translate characters from their UTF-8 encoding to a desired encoding. After configuring console conversion for a locale, the user must set prior to starting corasql application the codepage of the console using 'chcp' command (the codepage argument must match the 'windows_codepage' attribute in LDML). Conversion will work bidirectionally (input and output in corasql), but is only limited to Unicode characters which can be converted in the configured codepage.
The <consoleconversion> element is optional and allows to instruct corasql how to print (in which character encoding) the text in interactive command. The 'type' attribute defines the conversion scheme. The allowed values are:
- ISO: is a generic scheme in which the destination codepage is a single byte charset
- ISO88591: is a predefined single byte scheme for ISO-8859-1 charset (the 'file' attribute is not required, is ignored)
- ISO88599: is a predefined single byte scheme for ISO-8859-9 charset (also the 'file' attribute is not required)
- DBCS: Double Byte Code-Set; it is a generic scheme in which the destination codepage is a double byte charset
The 'windows_codepage' is the value for Windows codepage which CoraDB automatically activates console conversion. The 'linux_charset' is corresponding value for charset part in LANG environment variable from UNIX system. It is recommended to use native CoraDB charset in Linux console.
The 'file' attribute is required only for "ISO" and "DBCS" values of 'type' attribute and is the file containing the translation information ($CORADB/locales/data/codepages/).
LDML collation
Section titled “LDML collation”Configuring a collation is the most complex task for adding LDML locale in CoraDB. Only collation having UTF-8 codeset can be configured. CoraDB allows to configure most constructs specified by UCA - Unicode Collation Algorithm (http://www.unicode.org/reports/tr10/) including contractions and expansions, but the properties for the collation are mostly controlled via the 'settings' attribute.
A LDML file can contain multiple collations. Collations can be included from external file using the 'include' tag. The 'validSubLocales' attribute of 'collations' tag is a filter allowing to control locale compilation when external collations (from external files) are included. Its values can be either a list of locales or "*" in which case the collations in sub-tree are added in all locales from which the file is included.
One collation is defined using the 'collation' tag and its sub-tree. The 'type' attribute indicates the name for the collation as it will be added in CoraDB. The 'settings' tag defines the properties of the collation:
- 'id' is the (internal) numeric identifier used by CoraDB. It is integer value in range (32 - 255) and is optional, but is strongly recommended that an explicit unassigned values is set. Please see Collation naming rules.
- 'strength' is a measure of how strings compare. See Collation properties. The allowed values are
- "quaternary": different graphic symbols of the same character compare differently, but different Unicode codepoints may compare equal.
- "tertiary": graphic symbols of the same character are equal, case-sensitive collation.
- "secondary": case insensitive collation, characters with accents compare different
- "primary": accents are ignored, all characters compare as the base character.
- 'caseLevel': special setting to enable case sensitive compare for collations having strength < tertiary. Valid values are "on" or "off".
- 'caseFirst': order of casing. Valid values are "lower", "upper" and "off". The "upper" values means upper case letters are ordered before the corresponding lower case letter.
- 'CoraDBMaxWeights': it is the number of codepoints (or last codepoint + 1) which are customized in the collation. Maximum value is 65536. Increasing this value increases the size of collation data.
- 'DUCETContractions': valid values are "use" or "ignore". When "use" - enable CoraDB to use in the collation the contractions defined by DUCET file ($CORADB/locales/data/ducet.txt) or ignoring them.
- 'TailoringContractions': same as previous but refers to the contractions defined or derived from explicit collation rules. Enabling contractions leads to a more complex collation (slower string compares).
- 'CoraDBExpansions': allowed values are "use" or "ignore" (default) and refers to usage of collation expansions from both the DUCET file and tailoring rules; This has the most influence on collation properties. Enabling it will result in a compare with multiple passes (up to collation strength) when comparing strings. Also it greatly increases collation data, with the benefit of obtaining a more "natural" sort order. See Expansion.
- 'backwards': "on" or "off": used to obtain "french" order by performing an end-to-start compare on secondary level (for accents). It has effect only when 'CoraDBExpansions' are enabled.
- 'MatchContractionBoundary': "true" or "false". This is used in collation having expansions and contractions to configure behavior at string matching when a contraction is found.
The main data for a collation is loaded from the DUCET file. After this step, the collation may be customized using "tailoring rules". These are the "<rules>" (LDML) and "<coradbrules>" (CoraDB specific).
The 'coradbrules' tag is optional and can be used to explicitly set weight values for a codepoint or a range of codepoints. The coradbrules apply after loading the primary collation data from DUCET file and before applying the UCA rules (from '<rules>' tag). Each of these rule is enclosed in '<set>' tag. If the rule refers to only one Unicode codepoint, then a '<scp>' tag is provided which contains the hexadecimal value of codepoint.
All available CoraDB collations contain this coradb-rule:
<coradbrules> <set> <scp>20</scp> <w>[0.0.0.0]</w> </set></coradbrules>This rule says that weight values (UCA defines four weight values per collation element) of the codepoints starting with 20 (which is ASCII space character) are all set to zero. Since there is no '<ecp>' tag, the only codepoint affected is 20. In CoraDB, space character compares as zero. The allowed tags inside of a '<set>' rule are:
- '<cp>': rule to set the weights for single codepoint.
- '<ch>': rule to set the weights for single character. Similar to previous one, but instead of codepoint it expects a Unicode character (in UTF-8 encoding).
- '<scp>': rule to set the weights for a range of codepoints. This is the starting codepoint.
- '<sch>': rule to set the weights for a range of characters. This is the starting character. In this context, the order of characters is given by their Unicode codepoints.
- '<ecp>': end codepoint for a range rule.
- '<ech>': end character for a range rule.
- '<w>': weight values to set (single value). The weight values are expected in hexadecimal. Each collation element has four values which are delimited by point and enclosed by square brackets([]). There can be up to 10 collation elements.
- '<wr>': starting weight values to set for a range. Optionally, there is 'step' attribute of this tag, which sets the increasing step after each codepoint. By default the step is [0001.0000.0000.0000], which means that after setting the first weight values for the starting codepoint, one value is added to primary level weight and set to the next codepoint in range, and the process is repeated until end codepoint.
Examples:
<coradbrules> <set> <!-- Rule 1 --> <scp>0</scp> <ecp>20</ecp> <w>[0.0.0.0]</w> </set>
<set> <!-- Rule 2 --> <scp>30</scp> <ecp>39</ecp> <wr step="[1.0.0.0][1.0.0.0]">[30.0.0.0][30.0.0.0]</wr> </set>
</coradbrules>The Rule 1, sets for codepoints ranging from 0 to 20 (including) the weight values 0. The Rule 2, sets for codepoints ranging from 30 to 39 (which are the digits), a set of two collation elements with increasing weights; In this example, codepoint 39 (character "9") will have the weights with two collation elements [39.0.0.0][39.0.0.0].
The '<rules>' tag is also optional but is according to LDML and UCA specifications. The meanings of sub-ordinates tags are
- '<reset>': anchor collation element. It defines the reference to which subsequent rules (up to next
<reset>) are tailored. It can be a single characters or multiple characters in which case is either a contraction or an expansion. By default, all the tailoring rules after the anchor are sort "after" (element from first rule is after the anchor, element from second rule sorts after element in first rule); if the optional attribute "before" is present, then only the first rule after the <reset> sorts before the anchor, while the second and the following rules resumes the normal "after" sort (element in second rule sorts after element in first rule). - '<p>': the character comes after (or before, if the anchor had the
beforeattribute) the previously tailored one at primary level. - '<s>': the character comes after (or before, if the anchor had the
beforeattribute) the previously tailored one at secondary level. - '<t>': the character comes after (or before, if the anchor had the
beforeattribute) the previously tailored one at tertiary level. - '<i>': the character sorts identically to previous one
- '<pc>', '<sc>', '<tc>', '<ic>': same as '<p>', '<s>', '<t>', '<i>' but applies to a range of characters
- '<x>': specifies the expansion character
- '<extend>': specifies the second character of expansion.
- '<context>': specifies the context in which a rule applies. A variant to specify contractions and expansions.
For more information on UCA tailoring with LDML rules see http://www.unicode.org/reports/tr35/tr35-collation.html.
Footnotes