8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 18:03:04 +01:00

-Fix bug #223126 (Misplaced collation when extracting metadadata with isql)

-Fix bug #223513 (Ambiguity between tables and views)
-Fix bug #518349 (isql show mangles relationship)
-Remove V33 stuff
This commit is contained in:
brodsom 2004-04-23 18:39:04 +00:00
parent 835ce12bb2
commit 7cecfdcb7e
3 changed files with 572 additions and 729 deletions

View File

@ -19,7 +19,7 @@
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
* $Id: extract.epp,v 1.29 2004-04-21 00:18:48 brodsom Exp $
* $Id: extract.epp,v 1.30 2004-04-23 18:39:04 brodsom Exp $
* Revision 1.3 2000/11/22 17:07:25 patrickgriffin
* In get_procedure_args change comment style from // to c style
*
@ -64,7 +64,6 @@ DATABASE DB = EXTERN COMPILETIME "yachts.lnk";
extern USHORT major_ods;
extern USHORT minor_ods;
extern bool V33;
static void list_all_grants();
static processing_state list_all_grants2(bool, const SCHAR*);
@ -331,8 +330,6 @@ int EXTRACT_list_table(const SCHAR* relation_name,
**************************************/
bool first = true;
SSHORT collation;
SSHORT char_set_id;
SSHORT i;
SCHAR char_sets[86];
SSHORT subtype;
@ -349,6 +346,9 @@ int EXTRACT_list_table(const SCHAR* relation_name,
REL.RDB$RELATION_NAME EQ relation_name
SORTED BY RFR.RDB$FIELD_POSITION, RFR.RDB$FIELD_NAME
SSHORT collation = 0;
SSHORT char_set_id = 0;
if (first)
{
first = false;
@ -400,12 +400,12 @@ int EXTRACT_list_table(const SCHAR* relation_name,
sprintf (Print_buffer, "%s ", fb_utils::fb_exact_name(RFR.RDB$FIELD_NAME));
ISQL_printf (Out, Print_buffer);
/*
** Check first for computed fields, then domains.
** If this is a known domain, then just print the domain rather than type
** Domains won't have length, array, or blob definitions, but they
** may have not null, default and check overriding their definitions
*/
/*
** Check first for computed fields, then domains.
** If this is a known domain, then just print the domain rather than type
** Domains won't have length, array, or blob definitions, but they
** may have not null, default and check overriding their definitions
*/
if (!FLD.RDB$COMPUTED_BLR.NULL)
{
@ -427,13 +427,14 @@ int EXTRACT_list_table(const SCHAR* relation_name,
sprintf (Print_buffer, "%s", FLD.RDB$FIELD_NAME);
ISQL_printf (Out, Print_buffer);
// International character sets
// Print only the character set
if ((FLD.RDB$FIELD_TYPE == FCHAR || FLD.RDB$FIELD_TYPE == VARCHAR)
&& !RFR.RDB$COLLATION_ID.NULL && RFR.RDB$COLLATION_ID)
{
char_sets[0] = '\0';
collation = RFR.RDB$COLLATION_ID;
ISQL_get_character_sets (FLD.RDB$CHARACTER_SET_ID, collation,
true, char_sets);
char_set_id = FLD.RDB$CHARACTER_SET_ID;
ISQL_get_character_sets (FLD.RDB$CHARACTER_SET_ID, 0, true, char_sets);
if (char_sets[0])
ISQL_printf (Out, char_sets);
}
@ -553,13 +554,11 @@ int EXTRACT_list_table(const SCHAR* relation_name,
// Override rdb$fields id with relation_fields if present
collation = 0;
if (!RFR.RDB$COLLATION_ID.NULL)
collation = RFR.RDB$COLLATION_ID;
else if (!FLD.RDB$COLLATION_ID.NULL)
collation = FLD.RDB$COLLATION_ID;
char_set_id = 0;
if (!FLD.RDB$CHARACTER_SET_ID.NULL)
char_set_id = FLD.RDB$CHARACTER_SET_ID;
if ((char_set_id != default_char_set_id) || collation)
@ -581,14 +580,13 @@ int EXTRACT_list_table(const SCHAR* relation_name,
SHOW_print_metadata_text_blob (Out, &RFR.RDB$DEFAULT_SOURCE);
}
/* The null flag is either 1 or null (for nullable) . if there is
** a constraint name, print that too. Domains cannot have named
** constraints. The column name is in rdb$trigger_name in
** rdb$check_constraints. We hope we get at most one row back.
*/
/* The null flag is either 1 or null (for nullable) . if there is
** a constraint name, print that too. Domains cannot have named
** constraints. The column name is in rdb$trigger_name in
** rdb$check_constraints. We hope we get at most one row back.
*/
if (RFR.RDB$NULL_FLAG == 1)
if (RFR.RDB$NULL_FLAG == 1)
{
FOR RCO IN RDB$RELATION_CONSTRAINTS CROSS
CON IN RDB$CHECK_CONSTRAINTS WITH
@ -622,36 +620,19 @@ int EXTRACT_list_table(const SCHAR* relation_name,
ISQL_printf (Out, " NOT NULL");
}
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 && intchar)
// Handle collations after defaults
if (collation)
{
collation = 0;
if (!RFR.RDB$COLLATION_ID.NULL)
collation = RFR.RDB$COLLATION_ID;
else if (!FLD.RDB$COLLATION_ID.NULL)
collation = FLD.RDB$COLLATION_ID;
char_set_id = 0;
if (!FLD.RDB$CHARACTER_SET_ID.NULL)
char_set_id = FLD.RDB$CHARACTER_SET_ID;
if (collation)
{
char_sets[0] = '\0';
ISQL_get_character_sets (char_set_id, collation, true, char_sets);
if (char_sets[0])
ISQL_printf (Out, char_sets);
}
char_sets[0] = '\0';
ISQL_get_character_sets (char_set_id, collation, true, char_sets);
if (char_sets[0])
ISQL_printf (Out, char_sets);
}
END_FOR
ON_ERROR
if (!V33)
{
ISQL_errmsg(gds_status);
return (SSHORT) FINI_ERROR;
}
ISQL_errmsg(gds_status);
return (SSHORT) FINI_ERROR;
END_ERROR;
// Do primary and unique keys only. references come later
@ -897,11 +878,8 @@ static void get_procedure_args(char* proc_name)
}
END_FOR
ON_ERROR
if (!V33)
{
ISQL_errmsg(gds_status);
return;
}
ISQL_errmsg(gds_status);
return;
END_ERROR;
// If there was at least one param, close parens
@ -1160,11 +1138,8 @@ static void list_all_procs()
ISQL_printf (Out, Print_buffer);
END_FOR
ON_ERROR
if (!V33)
{
ISQL_errmsg(gds_status);
return;
}
ISQL_errmsg(gds_status);
return;
END_ERROR;
/* This query gets the procedure name and the source. We then nest a query
@ -1504,11 +1479,8 @@ static void list_create_db()
ISQL_printf (Out, Print_buffer);
END_FOR
ON_ERROR
if (!V33)
{
ISQL_errmsg(gds_status);
return;
}
ISQL_errmsg(gds_status);
return;
END_ERROR;
if (nodb)
@ -1697,11 +1669,8 @@ static void list_create_db()
END_FOR
ON_ERROR
if (!V33)
{
ISQL_errmsg(gds_status);
return;
}
ISQL_errmsg(gds_status);
return;
END_ERROR;
ISQL_printf(Out, NEWLINE);
@ -1969,8 +1938,8 @@ static void list_domain_table(const SCHAR* table_name,
order is the default for the character set being used, then no collation
order will be shown ( because it isn't needed ).
If the collation id is 0, then the default for the character set is
being used so there is no need to retrieve the collation information.*/
If the collation id is 0, then the default for the character set is
being used so there is no need to retrieve the collation information.*/
if (!FLD.RDB$COLLATION_ID.NULL && FLD.RDB$COLLATION_ID != 0)
{

View File

@ -206,9 +206,6 @@ XSQLDA** global_sqldap;
USHORT dialect_spoken = 0;
USHORT requested_SQL_dialect = SQL_DIALECT_V6;
bool connecting_to_pre_v6_server = false;
bool V45 = false;
bool V4 = false;
bool V33 = false;
USHORT major_ods = 0;
USHORT minor_ods = 0;
SCHAR server_version[256];
@ -1015,7 +1012,7 @@ SSHORT ISQL_get_field_length(const TEXT* field_name)
*
**************************************
*
* Retrieve character or field length of V4 character types.
* Retrieve character or field length of character types.
*
**************************************/
@ -1027,40 +1024,28 @@ SSHORT ISQL_get_field_length(const TEXT* field_name)
};
SSHORT l = 0;
if (V33) {
FOR FLD IN RDB$FIELDS WITH
FLD.RDB$FIELD_NAME EQ field_name
FOR FLD IN RDB$FIELDS WITH
FLD.RDB$FIELD_NAME EQ field_name
if (FLD.RDB$CHARACTER_LENGTH.NULL)
l = FLD.RDB$FIELD_LENGTH;
END_FOR
ON_ERROR
ISQL_errmsg(isc_status);
return 0;
END_ERROR;
}
else {
FOR FLD IN RDB$FIELDS WITH
FLD.RDB$FIELD_NAME EQ field_name
if (FLD.RDB$CHARACTER_LENGTH.NULL)
l = FLD.RDB$FIELD_LENGTH;
else
l = FLD.RDB$CHARACTER_LENGTH;
END_FOR
ON_ERROR
ISQL_errmsg(isc_status);
return 0;
END_ERROR;
}
else
l = FLD.RDB$CHARACTER_LENGTH;
END_FOR
ON_ERROR
ISQL_errmsg(isc_status);
return 0;
END_ERROR;
return l;
}
void ISQL_get_character_sets(SSHORT char_set_id,
SSHORT collation,
bool collate_only,
TEXT* string)
void ISQL_get_character_sets(
SSHORT char_set_id,
SSHORT collation,
bool collate_only,
TEXT* string)
{
/**************************************
*
@ -1084,7 +1069,7 @@ void ISQL_get_character_sets(SSHORT char_set_id,
return;
};
if (!V33 && collation) {
if (collation) {
FOR FIRST 1 COL IN RDB$COLLATIONS CROSS
CST IN RDB$CHARACTER_SETS WITH
COL.RDB$CHARACTER_SET_ID EQ CST.RDB$CHARACTER_SET_ID AND
@ -1123,7 +1108,7 @@ void ISQL_get_character_sets(SSHORT char_set_id,
}
#endif
}
else if (!V33) {
else {
FOR FIRST 1 CST IN RDB$CHARACTER_SETS WITH
CST.RDB$CHARACTER_SET_ID EQ char_set_id
SORTED BY CST.RDB$CHARACTER_SET_NAME
@ -1141,8 +1126,7 @@ void ISQL_get_character_sets(SSHORT char_set_id,
END_ERROR;
#ifdef DEV_BUILD
if (!found) {
sprintf(Print_buffer,
"ISQL_get_character_set: charset %d not found.\n",
sprintf(Print_buffer, "ISQL_get_character_set: charset %d not found.\n",
char_set_id);
STDERROUT(Print_buffer, 1);
}
@ -2614,9 +2598,7 @@ static processing_state create_db(const TEXT* statement,
ISQL_errmsg(isc_status);
if (D__trans)
COMMIT_TRANS(&D__trans);
if (isc_start_transaction(isc_status, &D__trans, 1, &DB,
(V4) ? 5 : 0,
(V4) ? default_tpb : NULL))
if (isc_start_transaction(isc_status, &D__trans, 1, &DB, 5, default_tpb))
ISQL_errmsg(isc_status);
}
@ -2863,16 +2845,6 @@ static processing_state drop_db()
*
**************************************/
if (global_Db_name[0]) {
if (!V4) {
TEXT* errbuf = (TEXT*) ISQL_ALLOC((SLONG) MSG_LENGTH);
if (errbuf) {
gds__msg_format(NULL, ISQL_MSG_FAC, SERVER_TOO_OLD, MSG_LENGTH,
errbuf, NULL, NULL, NULL, NULL, NULL);
STDERROUT(errbuf, 1);
ISQL_FREE(errbuf);
}
return (FAIL);
}
if (isc_drop_database(isc_status, &DB)) {
ISQL_errmsg(isc_status);
return (FAIL);
@ -4187,7 +4159,7 @@ void ISQL_get_version(bool call_by_create_db)
*
* Functional description
* finds out if the database we just attached to is
* V4, V3.3 or earlier, as well as other info.
* V4 or newer as well as other info.
*
**************************************/
static const UCHAR db_version_info[] = {
@ -4217,8 +4189,6 @@ void ISQL_get_version(bool call_by_create_db)
char bad_dialect_buf[512];
bool print_warning = false;
V4 = false;
V33 = false;
dialect_spoken = 0;
if (isc_database_info(isc_status, &DB, sizeof(db_version_info),
@ -4343,13 +4313,12 @@ void ISQL_get_version(bool call_by_create_db)
p += length;
}
if (major_ods >= ODS_VERSION8) {
V4 = true;
if (major_ods >= ODS_VERSION9)
V45 = true;
if (major_ods < ODS_VERSION8) {
TEXT message[100];
sprintf(message,
"This version of ISQL needs IB 4.0 or newer\n");
ISQL_printf(Out, message);
}
else if (major_ods == ODS_VERSION7 && minor_ods == ODS_CURRENT7)
V33 = true;
/* If the remote server did not respond to our request for
"dialects spoken", then we can assume it can only speak
@ -5085,27 +5054,6 @@ static processing_state newdb(TEXT* dbname,
}
}
if (!V4 && !V33) {
gds__msg_format(NULL, ISQL_MSG_FAC, SERVER_TOO_OLD, MSG_LENGTH,
errbuf, NULL, NULL, NULL, NULL, NULL);
STDERROUT(errbuf, 1);
isc_detach_database(isc_status, &DB);
DB = 0;
global_Db_name[0] = '\0';
global_Stmt = 0;
if (save_database)
ISQL_FREE(save_database);
if (local_psw)
ISQL_FREE(local_psw);
if (local_usr)
ISQL_FREE(local_usr);
if (dpb_buffer)
ISQL_FREE(dpb_buffer);
if (errbuf)
ISQL_FREE(errbuf);
return FAIL;
}
/* CVC: We do not require those pesky transactions for -x or -a options.
Metadata extraction works exclusively with default transaction gds__trans. */
@ -5118,8 +5066,7 @@ static processing_state newdb(TEXT* dbname,
ISQL_errmsg(isc_status);
if (D__trans)
COMMIT_TRANS(&D__trans);
if (isc_start_transaction(isc_status, &D__trans, 1, &DB,
(V4) ? 5 : 0, (V4) ? default_tpb : NULL))
if (isc_start_transaction(isc_status, &D__trans, 1, &DB, 5, default_tpb))
ISQL_errmsg(isc_status);
}
@ -6353,8 +6300,7 @@ static int process_statement(const TEXT* string,
// No need to start a default transaction unless there is no current one
if (!D__trans)
if (isc_start_transaction(isc_status, &D__trans, 1, &DB,
(V4) ? 5 : 0, (V4) ? default_tpb : NULL))
if (isc_start_transaction(isc_status, &D__trans, 1, &DB, 5, default_tpb))
{
ISQL_errmsg(isc_status);
}

File diff suppressed because it is too large Load Diff