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

Extract and show DDL triggers types

This commit is contained in:
asfernandes 2009-12-05 15:08:18 +00:00
parent 1c58056186
commit 03db7c025f
3 changed files with 42 additions and 17 deletions

View File

@ -93,8 +93,6 @@ static void list_package_bodies();
static void list_package_headers();
static void list_views();
extern const char* trigger_action(int);
static const char* const Procterm = "^"; // TXNN: script use only
/* Maybe 512 would be really enough as Print_buffer size, but
@ -1687,7 +1685,7 @@ static void list_all_triggers()
isqlGlob.printf("CREATE TRIGGER %s %s%s %s POSITION %d %s",
SQL_identifier, NEWLINE,
(TRG.RDB$TRIGGER_INACTIVE ? "INACTIVE" : "ACTIVE"),
trigger_action (TRG.RDB$TRIGGER_TYPE), TRG.RDB$TRIGGER_SEQUENCE,
SHOW_trigger_action(TRG.RDB$TRIGGER_TYPE).c_str(), TRG.RDB$TRIGGER_SEQUENCE,
NEWLINE);
if (!TRG.RDB$TRIGGER_SOURCE.NULL)
@ -1747,7 +1745,7 @@ static void list_all_triggers()
isqlGlob.printf("CREATE TRIGGER %s FOR %s %s%s %s POSITION %d %s",
SQL_identifier, SQL_identifier2, NEWLINE,
(TRG.RDB$TRIGGER_INACTIVE ? "INACTIVE" : "ACTIVE"),
trigger_action (TRG.RDB$TRIGGER_TYPE), TRG.RDB$TRIGGER_SEQUENCE,
SHOW_trigger_action(TRG.RDB$TRIGGER_TYPE).c_str(), TRG.RDB$TRIGGER_SEQUENCE,
NEWLINE);
if (!TRG.RDB$TRIGGER_SOURCE.NULL)

View File

@ -62,6 +62,7 @@
#include <ctype.h>
#endif
using Firebird::string;
using MsgFormat::SafeArg;
@ -247,14 +248,13 @@ inline int TRIGGER_ACTION_SUFFIX(int value, int slot)
return ((value + 1) >> (slot * 2 - 1)) & 3;
}
const char* trigger_action(int type)
const string SHOW_trigger_action(SINT64 type)
{
static char buffer[256];
switch (type & TRIGGER_TYPE_MASK)
{
case TRIGGER_TYPE_DML:
{
char buffer[256];
int prefix = TRIGGER_ACTION_PREFIX(type);
strcpy(buffer, Trigger_prefix_types[prefix]);
int suffix = TRIGGER_ACTION_SUFFIX(type, 1);
@ -270,17 +270,41 @@ const char* trigger_action(int type)
strcat(buffer, " OR ");
strcat(buffer, Trigger_suffix_types[suffix]);
}
return buffer;
}
break;
case TRIGGER_TYPE_DB:
sprintf(buffer, "ON %s", Db_trigger_types[type & ~TRIGGER_TYPE_DB]);
break;
default:
buffer[0] = '\0';
fb_assert(false);
}
return buffer;
case TRIGGER_TYPE_DB:
return string("ON ") + Db_trigger_types[type & ~TRIGGER_TYPE_DB];
case TRIGGER_TYPE_DDL:
{
bool first = true;
string buffer = Trigger_prefix_types[type & 1];
for (SINT64 pos = 1; pos < 64; ++pos)
{
if (((1LL << pos) & TRIGGER_TYPE_MASK) || (type & (1LL << pos)) == 0)
continue;
if (first)
first = false;
else
buffer += " OR";
buffer += " ";
if (pos < FB_NELEM(DDL_TRIGGER_ACTION_NAMES))
buffer += DDL_TRIGGER_ACTION_NAMES[pos];
else
buffer += "<unknown>";
}
return buffer;
}
default:
fb_assert(false);
return "";
}
}
@ -4767,7 +4791,7 @@ static processing_state show_trigger(const SCHAR* object, bool show_source, bool
isqlGlob.printf("%s, Sequence: %d, Type: %s, %s%s",
TRG.RDB$TRIGGER_NAME,
TRG.RDB$TRIGGER_SEQUENCE,
trigger_action (TRG.RDB$TRIGGER_TYPE),
SHOW_trigger_action(TRG.RDB$TRIGGER_TYPE).c_str(),
(TRG.RDB$TRIGGER_INACTIVE ? "Inactive" : "Active"),
NEWLINE);

View File

@ -24,6 +24,8 @@
#ifndef ISQL_SHOW_PROTO_H
#define ISQL_SHOW_PROTO_H
#include "../common/classes/fb_string.h"
void SHOW_comments(bool force);
bool SHOW_dbb_parameters (FB_API_HANDLE, SCHAR*, const SCHAR*, USHORT, bool, const char*);
processing_state SHOW_grants (const SCHAR*, const SCHAR*, USHORT);
@ -33,6 +35,7 @@ void SHOW_grant_roles2 (const SCHAR*, bool*, const TEXT*, bool);
void SHOW_print_metadata_text_blob(FILE*, ISC_QUAD*, bool escape_squote = false);
processing_state SHOW_metadata(const SCHAR* const*, SCHAR**);
void SHOW_read_owner();
const Firebird::string SHOW_trigger_action(SINT64);
#endif // ISQL_SHOW_PROTO_H