From: Patrick J. P. G. <pat...@us...> - 2001-01-08 16:07:06
|
Update of /cvsroot/firebird/interbase/isql In directory usw-pr-cvs1:/tmp/cvs-serv21807/interbase/isql Modified Files: extra_proto.h extract.e isql.e isql_proto.h show.e Log Message: [ Bug #127473 ] ISQL Always ignores charset NONE in metadata extraction. This patch will change ISQL Extract and Show commands to display the character set definition for all fields: 1) Not using the database default character set 2) With an explicit definition for collation. This patch also changes the ISQL COPY command (only available in development builds) to list every character set definition. ...pat Index: extra_proto.h =================================================================== RCS file: /cvsroot/firebird/interbase/isql/extra_proto.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -r1.1.1.1 -r1.2 *** extra_proto.h 2000/08/03 20:49:18 1.1.1.1 --- extra_proto.h 2001/01/08 16:07:18 1.2 *************** *** 26,30 **** extern SSHORT EXTRACT_ddl (int, SCHAR *); ! extern SSHORT EXTRACT_list_table (SCHAR *, SCHAR *, SSHORT); extern void EXTRACT_list_view (SCHAR *); --- 26,30 ---- extern SSHORT EXTRACT_ddl (int, SCHAR *); ! extern SSHORT EXTRACT_list_table (SCHAR *, SCHAR *, SSHORT, SSHORT); extern void EXTRACT_list_view (SCHAR *); Index: extract.e =================================================================== RCS file: /cvsroot/firebird/interbase/isql/extract.e,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** extract.e 2000/12/08 16:59:33 1.4 --- extract.e 2001/01/08 16:07:18 1.5 *************** *** 59,68 **** static void list_all_grants (void); static void list_all_procs (void); ! static void list_all_tables (SSHORT); static void list_all_triggers (void); static void list_check (void); static void list_create_db (void); ! static void list_domain_table (SCHAR *); ! static void list_domains (void); static void list_exception (void); static void list_filters (void); --- 59,68 ---- static void list_all_grants (void); static void list_all_procs (void); ! static void list_all_tables (SSHORT,SSHORT); static void list_all_triggers (void); static void list_check (void); static void list_create_db (void); ! static void list_domain_table (SCHAR *,SSHORT); ! static void list_domains (SSHORT); static void list_exception (void); static void list_filters (void); *************** *** 121,124 **** --- 121,125 ---- USHORT did_attach = FALSE; USHORT did_start = FALSE; + SSHORT default_char_set_id; if (!DB) *************** *** 180,187 **** } /* If a table name was passed, extract only that table and domains */ if (*tabname) { ! if (EXTRACT_list_table (tabname, NULL, 1)) { gds__msg_format (NULL_PTR, ISQL_MSG_FAC, NOT_FOUND, sizeof (errbuf), --- 181,190 ---- } + default_char_set_id = ISQL_get_default_char_set_id (); + /* If a table name was passed, extract only that table and domains */ if (*tabname) { ! if (EXTRACT_list_table (tabname, NULL, 1, default_char_set_id)) { gds__msg_format (NULL_PTR, ISQL_MSG_FAC, NOT_FOUND, sizeof (errbuf), *************** *** 196,201 **** list_filters(); list_functions(); ! list_domains(); ! list_all_tables (flag); list_index (); list_foreign (); --- 199,204 ---- list_filters(); list_functions(); ! list_domains(default_char_set_id); ! list_all_tables (flag,default_char_set_id); list_index (); list_foreign (); *************** *** 232,236 **** SCHAR *relation_name, SCHAR *new_name, ! SSHORT domain_flag) { /************************************** --- 235,240 ---- SCHAR *relation_name, SCHAR *new_name, ! SSHORT domain_flag, ! SSHORT default_char_set_id) { /************************************** *************** *** 249,254 **** --- 253,301 ---- * new_name -- Name of a new name for a replacement table * domain_flag -- extract needed domains before the table + * default_char_set_id -- character set def to supress + * + **************************************/ + /************************************** + * default_char_set_id warrents special + * consideration. If the metadata for a + * table is being extracted when there is + * really no need to redundantly and repeatedly + * list the databases default character set + * for every field. + * + * At the same time there is a need to list + * the character set NONE when it is not + * the default character set for the database. + * + * EXCEPT! If the metadata is being extracted + * with the intention of coping that tables structure + * into another database, and it is not possible + * to know the default character set for the + * target database, then list every fields + * character set. This includes the character + * set NONE. + * + * Fields with no character set definition will + * not have any character set listed. + * + * Use -1 as the default_char_set_id + * in this case. + * + * POTENTIAL TRAP! Consider the following: + * When copying a table from one database + * to another how should fields using the + * default character set be handled? + * + * If both databases have the same default + * character set, then there is no problem + * or confusion. + * + * If the databases have different default + * character sets then should fields using + * the default is the source database use + * the default of the target database? * **************************************/ + USHORT first; SSHORT collation, char_set_id; *************** *** 277,281 **** /* Do we need to print domains */ if (domain_flag) ! list_domain_table (relation_name); ISQL_blankterm (REL.RDB$OWNER_NAME); --- 324,328 ---- /* Do we need to print domains */ if (domain_flag) ! list_domain_table (relation_name,default_char_set_id); ISQL_blankterm (REL.RDB$OWNER_NAME); *************** *** 467,471 **** if ((FLD.RDB$FIELD_TYPE == FCHAR || FLD.RDB$FIELD_TYPE == VARCHAR || FLD.RDB$FIELD_TYPE == BLOB) && ! !FLD.RDB$CHARACTER_SET_ID.NULL && FLD.RDB$CHARACTER_SET_ID) { char_sets [0] = '\0'; --- 514,518 ---- if ((FLD.RDB$FIELD_TYPE == FCHAR || FLD.RDB$FIELD_TYPE == VARCHAR || FLD.RDB$FIELD_TYPE == BLOB) && ! !FLD.RDB$CHARACTER_SET_ID.NULL) { char_sets [0] = '\0'; *************** *** 482,490 **** if (!FLD.RDB$CHARACTER_SET_ID.NULL) char_set_id = FLD.RDB$CHARACTER_SET_ID; ! ! ISQL_get_character_sets (char_set_id, 0, FALSE, char_sets); if (char_sets [0]) ISQL_printf (Out, char_sets); ! intchar = 1; } } --- 529,538 ---- if (!FLD.RDB$CHARACTER_SET_ID.NULL) char_set_id = FLD.RDB$CHARACTER_SET_ID; ! if ((char_set_id != default_char_set_id) || collation) ! ISQL_get_character_sets (char_set_id, 0, FALSE, char_sets); if (char_sets [0]) ISQL_printf (Out, char_sets); ! if (!char_set_id) ! intchar = 1; } } *************** *** 1185,1189 **** static void list_all_tables ( ! SSHORT flag) { /************************************** --- 1233,1238 ---- static void list_all_tables ( ! SSHORT flag, ! SSHORT default_char_set_id) { /************************************** *************** *** 1217,1221 **** if (flag || !strncmp (REL.RDB$SECURITY_CLASS, "SQL$", 4)) ! EXTRACT_list_table (REL.RDB$RELATION_NAME, NULL, 0); END_FOR ON_ERROR --- 1266,1270 ---- if (flag || !strncmp (REL.RDB$SECURITY_CLASS, "SQL$", 4)) ! EXTRACT_list_table (REL.RDB$RELATION_NAME, NULL, 0,default_char_set_id); END_FOR ON_ERROR *************** *** 1759,1763 **** static void list_domain_table ( ! SCHAR *table_name) { /************************************** --- 1808,1813 ---- static void list_domain_table ( ! SCHAR *table_name, ! SSHORT default_char_set_id) { /************************************** *************** *** 1772,1775 **** --- 1822,1826 ---- * * Parameters: table_name == only extract domains for this table + * default_char_set_id -- character set def to supress * **************************************/ *************** *** 1898,1902 **** { char_sets[0] = 0; ! ISQL_get_character_sets (FLD.RDB$CHARACTER_SET_ID, FALSE, FALSE, char_sets); if (char_sets[0]) ISQL_printf (Out, char_sets); --- 1949,1955 ---- { char_sets[0] = 0; ! if ((FLD.RDB$CHARACTER_SET_ID != default_char_set_id) || ! (!FLD.RDB$COLLATION_ID.NULL && FLD.RDB$COLLATION_ID != 0)) ! ISQL_get_character_sets (FLD.RDB$CHARACTER_SET_ID, FALSE, FALSE, char_sets); if (char_sets[0]) ISQL_printf (Out, char_sets); *************** *** 1946,1950 **** } ! static void list_domains (void) { /************************************** --- 1999,2005 ---- } ! static void list_domains ( ! SSHORT default_char_set_id ! ) { /************************************** *************** *** 1957,1961 **** * List domains * ! * Parameters: none * **************************************/ --- 2012,2017 ---- * List domains * ! * Parameters: ! * default_char_set_id -- character set def to supress * **************************************/ *************** *** 2085,2089 **** { char_sets[0] = 0; ! ISQL_get_character_sets (FLD.RDB$CHARACTER_SET_ID, FALSE, FALSE, char_sets); if (char_sets[0]) ISQL_printf (Out, char_sets); --- 2141,2147 ---- { char_sets[0] = 0; ! if ((FLD.RDB$CHARACTER_SET_ID != default_char_set_id) || ! (!FLD.RDB$COLLATION_ID.NULL && FLD.RDB$COLLATION_ID != 0)) ! ISQL_get_character_sets (FLD.RDB$CHARACTER_SET_ID, FALSE, FALSE, char_sets); if (char_sets[0]) ISQL_printf (Out, char_sets); Index: isql.e =================================================================== RCS file: /cvsroot/firebird/interbase/isql/isql.e,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** isql.e 2000/12/08 16:59:33 1.6 --- isql.e 2001/01/08 16:07:18 1.7 *************** *** 974,977 **** --- 974,1020 ---- #endif + SSHORT ISQL_get_default_char_set_id () + { + /************************************* + * + * I S Q L _ g e t _ d e f a u l t _ c h a r _ s e t _ i d + * + ************************************** + * + * Functional description + * Return the database default character set + * id. + * + * -1 if the value can not be determined. + * + **************************************/ + SSHORT default_char_set_id; + + /* What is the default character set for this database? + There are three states: + 1. There is no entry available in RDB$DATABASE + Then - NONE + 2. The entry in RDB$DATABASE does not exist in + RDB$CHARACTER_SETS + Then - -1 to cause all character set defs to show + 3. An entry in RDB$CHARACTER_SETS + Then - RDB$CHARACTER_SET_ID + */ + default_char_set_id = 0; + FOR FIRST 1 EXT IN RDB$DATABASE + WITH EXT.RDB$CHARACTER_SET_NAME NOT MISSING; + + default_char_set_id = -1; + + FOR FIRST 1 CHI IN RDB$CHARACTER_SETS + WITH CHI.RDB$CHARACTER_SET_NAME = EXT.RDB$CHARACTER_SET_NAME + + default_char_set_id = CHI.RDB$CHARACTER_SET_ID; + + END_FOR; + END_FOR; + return (default_char_set_id); + } + #ifdef GUI_TOOLS int ISQL_extract ( *************** *** 1071,1075 **** void ISQL_build_table_list ( void **tbl_list, ! IB_FILE *ipf, IB_FILE *opf, IB_FILE *sf) --- 1114,1118 ---- void ISQL_build_table_list ( void **tbl_list, ! IB_FILE *ipf, IB_FILE *opf, IB_FILE *sf) *************** *** 1441,1445 **** #endif } ! else if (!V33 && char_set_id) { FOR FIRST 1 CST IN RDB$CHARACTER_SETS WITH --- 1484,1488 ---- #endif } ! else if (!V33) { FOR FIRST 1 CST IN RDB$CHARACTER_SETS WITH *************** *** 2957,2961 **** ISQL_make_upper (source); ! if (EXTRACT_list_table (source, destination, domain_flag)) { gds__msg_format (NULL_PTR, ISQL_MSG_FAC, NOT_FOUND, sizeof (errbuf), --- 3000,3004 ---- ISQL_make_upper (source); ! if (EXTRACT_list_table (source, destination, domain_flag,-1)) { gds__msg_format (NULL_PTR, ISQL_MSG_FAC, NOT_FOUND, sizeof (errbuf), Index: isql_proto.h =================================================================== RCS file: /cvsroot/firebird/interbase/isql/isql_proto.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -r1.1.1.1 -r1.2 *** isql_proto.h 2000/08/03 20:49:22 1.1.1.1 --- isql_proto.h 2001/01/08 16:07:18 1.2 *************** *** 68,71 **** --- 68,72 ---- USHORT, TEXT *); + extern SSHORT ISQL_get_default_char_set_id (void); extern void ISQL_get_default_source (TEXT *, TEXT *, Index: show.e =================================================================== RCS file: /cvsroot/firebird/interbase/isql/show.e,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** show.e 2000/12/08 16:59:33 1.3 --- show.e 2001/01/08 16:07:18 1.4 *************** *** 1837,1841 **** --- 1837,1844 ---- SSHORT collation, char_set_id; TEXT char_sets [86]; /* CHARACTER SET <name31> COLLATE <name31> */ + SSHORT default_char_set_id; + default_char_set_id = ISQL_get_default_char_set_id (); + /* If there is a relation_name, this is a real column, look up collation */ /* in rdb$relation_fields */ *************** *** 1886,1890 **** char_sets [0] = 0; ! ISQL_get_character_sets (char_set_id, collation, FALSE, char_sets); if (char_sets [0]) ISQL_printf(Out, char_sets); --- 1889,1894 ---- char_sets [0] = 0; ! if ((char_set_id != default_char_set_id) || collation) ! ISQL_get_character_sets (char_set_id, collation, FALSE, char_sets); if (char_sets [0]) ISQL_printf(Out, char_sets); |