2001-05-23 15:26:42 +02:00
|
|
|
/*
|
|
|
|
* PROGRAM: JRD Data Definition Utility
|
2003-10-25 12:55:41 +02:00
|
|
|
* MODULE: dyn_util.epp
|
2001-05-23 15:26:42 +02:00
|
|
|
* DESCRIPTION: Dynamic data definition - utility functions
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Interbase Public
|
|
|
|
* License Version 1.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.Inprise.com/IPL.html
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an
|
|
|
|
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
|
|
|
* or implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Inprise Corporation
|
|
|
|
* and its predecessors. Portions created by Inprise Corporation are
|
|
|
|
* Copyright (C) Inprise Corporation.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
2002-02-24 17:39:31 +01:00
|
|
|
*
|
|
|
|
* 2002-02-24 Sean Leyne - Code Cleanup of old Win 3.1 port (WINDOWS_ONLY)
|
|
|
|
*
|
2001-05-23 15:26:42 +02:00
|
|
|
*/
|
|
|
|
|
2001-07-29 19:42:23 +02:00
|
|
|
#include "firebird.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "../jrd/common.h"
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "../jrd/jrd.h"
|
|
|
|
#include "../jrd/tra.h"
|
|
|
|
#include "../jrd/scl.h"
|
|
|
|
#include "../jrd/drq.h"
|
|
|
|
#include "../jrd/flags.h"
|
2003-11-08 17:40:17 +01:00
|
|
|
#include "../jrd/ibase.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
#include "../jrd/lls.h"
|
|
|
|
#include "../jrd/all.h"
|
|
|
|
#include "../jrd/met.h"
|
|
|
|
#include "../jrd/btr.h"
|
|
|
|
#include "../jrd/intl.h"
|
|
|
|
#include "../jrd/dyn.h"
|
2003-10-20 12:53:52 +02:00
|
|
|
#include "../jrd/ods.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
#include "../jrd/all_proto.h"
|
|
|
|
#include "../jrd/blb_proto.h"
|
|
|
|
#include "../jrd/cmp_proto.h"
|
|
|
|
#include "../jrd/dyn_proto.h"
|
|
|
|
#include "../jrd/dyn_md_proto.h"
|
|
|
|
#include "../jrd/dyn_ut_proto.h"
|
|
|
|
#include "../jrd/err_proto.h"
|
|
|
|
#include "../jrd/exe_proto.h"
|
|
|
|
#include "../jrd/gds_proto.h"
|
|
|
|
#include "../jrd/inf_proto.h"
|
|
|
|
#include "../jrd/intl_proto.h"
|
|
|
|
#include "../jrd/isc_f_proto.h"
|
2004-06-08 15:41:08 +02:00
|
|
|
#include "../jrd/thd.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
#include "../jrd/vio_proto.h"
|
|
|
|
|
2004-03-20 15:57:40 +01:00
|
|
|
using namespace Jrd;
|
|
|
|
|
2002-12-16 17:25:10 +01:00
|
|
|
DATABASE DB = STATIC "ODS.RDB";
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-02-13 11:11:35 +01:00
|
|
|
static const SCHAR gen_id_blr1[] = {
|
2001-05-23 15:26:42 +02:00
|
|
|
blr_version5,
|
|
|
|
blr_begin,
|
|
|
|
blr_message, 0, 1, 0,
|
|
|
|
blr_int64, 0,
|
|
|
|
blr_begin,
|
|
|
|
blr_send, 0,
|
|
|
|
blr_begin,
|
|
|
|
blr_assignment,
|
|
|
|
blr_gen_id
|
2003-11-07 09:06:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const SCHAR gen_id_blr2[] = {
|
2001-05-23 15:26:42 +02:00
|
|
|
blr_literal, blr_long, 0, 1, 0, 0, 0,
|
2003-11-07 09:06:35 +01:00
|
|
|
blr_parameter, 0, 0, 0, blr_end, blr_end, blr_end, blr_eoc
|
|
|
|
};
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-07 09:06:35 +01:00
|
|
|
static const UCHAR prot_blr[] = {
|
2001-05-23 15:26:42 +02:00
|
|
|
blr_version5,
|
|
|
|
blr_begin,
|
|
|
|
blr_message, 1, 1, 0,
|
|
|
|
blr_short, 0,
|
|
|
|
blr_message, 0, 2, 0,
|
|
|
|
blr_cstring, 32, 0,
|
|
|
|
blr_cstring, 32, 0,
|
|
|
|
blr_receive, 0,
|
|
|
|
blr_begin,
|
|
|
|
blr_send, 1,
|
|
|
|
blr_begin,
|
|
|
|
blr_assignment,
|
|
|
|
blr_prot_mask,
|
|
|
|
blr_parameter, 0, 0, 0,
|
|
|
|
blr_parameter, 0, 1, 0,
|
|
|
|
blr_parameter, 1, 0, 0,
|
|
|
|
blr_end,
|
|
|
|
blr_end,
|
|
|
|
blr_end,
|
|
|
|
blr_eoc
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-03-11 06:04:26 +01:00
|
|
|
SINT64 DYN_UTIL_gen_unique_id(thread_db* tdbb,
|
2004-03-31 19:38:53 +02:00
|
|
|
Global* gbl,
|
2001-05-23 15:26:42 +02:00
|
|
|
SSHORT id,
|
2003-11-05 10:02:33 +01:00
|
|
|
const SCHAR* generator_name,
|
2004-03-20 15:57:40 +01:00
|
|
|
jrd_req** request)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* D Y N _ U T I L _g e n _ u n i q u e _ i d
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Generate a unique id using a generator.
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
SET_TDBB(tdbb);
|
2004-03-07 08:58:55 +01:00
|
|
|
Database* dbb = tdbb->tdbb_database;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-01-03 11:59:52 +01:00
|
|
|
jrd_req* req_handle = CMP_find_request(tdbb, id, DYN_REQUESTS);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
if (!req_handle)
|
|
|
|
{
|
|
|
|
/* 32 bytes allocated for size of of a metadata name */
|
2003-11-05 10:02:33 +01:00
|
|
|
const size_t blr_size = sizeof(gen_id_blr1) + sizeof(gen_id_blr2) + 1
|
|
|
|
+ MAX_SQL_IDENTIFIER_SIZE;
|
|
|
|
SCHAR blr[blr_size];
|
|
|
|
fb_assert(strlen(generator_name) < MAX_SQL_IDENTIFIER_SIZE);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-05 10:02:33 +01:00
|
|
|
char* p = blr;
|
2001-05-23 15:26:42 +02:00
|
|
|
memcpy(p, gen_id_blr1, sizeof(gen_id_blr1));
|
|
|
|
p += sizeof(gen_id_blr1);
|
|
|
|
*p++ = strlen(generator_name);
|
|
|
|
strcpy(p, generator_name);
|
|
|
|
p += p[-1];
|
|
|
|
memcpy(p, gen_id_blr2, sizeof(gen_id_blr2));
|
|
|
|
p += sizeof(gen_id_blr2);
|
2003-11-07 09:06:35 +01:00
|
|
|
req_handle = CMP_compile2(tdbb, reinterpret_cast<const UCHAR*>(blr), TRUE);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2004-02-20 07:43:27 +01:00
|
|
|
*request = req_handle;
|
2004-07-06 07:59:40 +02:00
|
|
|
SINT64 value;
|
2001-05-23 15:26:42 +02:00
|
|
|
EXE_start(tdbb, req_handle, dbb->dbb_sys_trans);
|
|
|
|
EXE_receive(tdbb, req_handle, 0, sizeof(value), (UCHAR*)&value);
|
|
|
|
EXE_unwind(tdbb, req_handle);
|
|
|
|
*request = NULL;
|
|
|
|
|
|
|
|
if (!DYN_REQUEST(id)) {
|
2004-02-20 07:43:27 +01:00
|
|
|
DYN_REQUEST(id) = req_handle;
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-31 19:38:53 +02:00
|
|
|
void DYN_UTIL_generate_constraint_name( thread_db* tdbb, Global* gbl, TEXT* buffer)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* D Y N _ U T I L _g e n e r a t e _ c o n s t r a i n t _ n a m e
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Generate a name unique to RDB$RELATION_CONSTRAINTS.
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
SET_TDBB(tdbb);
|
2004-03-07 08:58:55 +01:00
|
|
|
Database* dbb = tdbb->tdbb_database;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-07-06 07:59:40 +02:00
|
|
|
jrd_req* request = NULL;
|
2004-03-07 08:58:55 +01:00
|
|
|
SSHORT id = -1;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
try {
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-09-09 13:07:19 +02:00
|
|
|
bool found = false;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
do {
|
|
|
|
id = drq_g_nxt_con;
|
|
|
|
sprintf(buffer, "INTEG_%" QUADFORMAT "d",
|
|
|
|
(SINT64) DYN_UTIL_gen_unique_id(tdbb,
|
|
|
|
gbl,
|
|
|
|
drq_g_nxt_con,
|
|
|
|
"RDB$CONSTRAINT_NAME",
|
2004-03-01 04:35:23 +01:00
|
|
|
&request));
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-02-20 07:43:27 +01:00
|
|
|
request = CMP_find_request(tdbb, drq_f_nxt_con, DYN_REQUESTS);
|
2001-05-23 15:26:42 +02:00
|
|
|
id = drq_f_nxt_con;
|
|
|
|
|
2003-09-09 13:07:19 +02:00
|
|
|
found = false;
|
2001-05-23 15:26:42 +02:00
|
|
|
FOR(REQUEST_HANDLE request)
|
|
|
|
FIRST 1 X IN RDB$RELATION_CONSTRAINTS
|
|
|
|
WITH X.RDB$CONSTRAINT_NAME EQ buffer
|
|
|
|
|
|
|
|
if (!DYN_REQUEST(drq_f_nxt_con))
|
|
|
|
DYN_REQUEST(drq_f_nxt_con) = request;
|
2003-09-09 13:07:19 +02:00
|
|
|
found = true;
|
2001-05-23 15:26:42 +02:00
|
|
|
END_FOR;
|
|
|
|
|
|
|
|
if (!DYN_REQUEST(drq_f_nxt_con))
|
|
|
|
DYN_REQUEST(drq_f_nxt_con) = request;
|
|
|
|
request = NULL;
|
|
|
|
} while (found);
|
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
} // try
|
2004-03-01 04:35:23 +01:00
|
|
|
catch (const std::exception& ex) {
|
|
|
|
Firebird::stuff_exception(tdbb->tdbb_status_vector, ex);
|
2002-04-04 09:10:40 +02:00
|
|
|
DYN_rundown_request(request, id);
|
2003-11-05 10:02:33 +01:00
|
|
|
DYN_error_punt(true, 131, NULL, NULL, NULL, NULL, NULL);
|
2001-12-24 03:51:06 +01:00
|
|
|
/* msg 131: "Generation of constraint name failed" */
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-31 19:38:53 +02:00
|
|
|
void DYN_UTIL_generate_field_name( thread_db* tdbb, Global* gbl, TEXT* buffer)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* D Y N _ U T I L _g e n e r a t e _ f i e l d _ n a m e
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Generate a name unique to RDB$FIELDS.
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
SET_TDBB(tdbb);
|
2004-03-07 08:58:55 +01:00
|
|
|
Database* dbb = tdbb->tdbb_database;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-07-06 07:59:40 +02:00
|
|
|
jrd_req* request = NULL;
|
2004-03-07 08:58:55 +01:00
|
|
|
SSHORT id = -1;
|
2003-09-09 13:07:19 +02:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
try {
|
2003-09-09 13:07:19 +02:00
|
|
|
|
|
|
|
bool found = false;
|
2001-12-24 03:51:06 +01:00
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
do {
|
|
|
|
id = drq_g_nxt_fld;
|
|
|
|
sprintf(buffer, "RDB$%" QUADFORMAT "d",
|
|
|
|
(SINT64) DYN_UTIL_gen_unique_id(tdbb,
|
|
|
|
gbl,
|
|
|
|
drq_g_nxt_fld,
|
|
|
|
"RDB$FIELD_NAME",
|
2004-03-01 04:35:23 +01:00
|
|
|
&request));
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-02-20 07:43:27 +01:00
|
|
|
request = CMP_find_request(tdbb, drq_f_nxt_fld, DYN_REQUESTS);
|
2001-05-23 15:26:42 +02:00
|
|
|
id = drq_f_nxt_fld;
|
|
|
|
|
2003-09-09 13:07:19 +02:00
|
|
|
found = false;
|
2001-05-23 15:26:42 +02:00
|
|
|
FOR(REQUEST_HANDLE request)
|
|
|
|
FIRST 1 X IN RDB$FIELDS WITH X.RDB$FIELD_NAME EQ buffer
|
|
|
|
|
|
|
|
if (!DYN_REQUEST(drq_f_nxt_fld))
|
|
|
|
DYN_REQUEST(drq_f_nxt_fld) = request;
|
2003-09-09 13:07:19 +02:00
|
|
|
found = true;
|
2001-05-23 15:26:42 +02:00
|
|
|
END_FOR;
|
|
|
|
|
|
|
|
if (!DYN_REQUEST(drq_f_nxt_fld))
|
|
|
|
DYN_REQUEST(drq_f_nxt_fld) = request;
|
|
|
|
request = NULL;
|
|
|
|
} while (found);
|
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
} // try
|
2004-03-01 04:35:23 +01:00
|
|
|
catch (const std::exception& ex) {
|
|
|
|
Firebird::stuff_exception(tdbb->tdbb_status_vector, ex);
|
2002-04-04 09:10:40 +02:00
|
|
|
DYN_rundown_request(request, id);
|
2003-11-05 10:02:33 +01:00
|
|
|
DYN_error_punt(true, 81, NULL, NULL, NULL, NULL, NULL);
|
2001-12-24 03:51:06 +01:00
|
|
|
/* msg 81: "Generation of field name failed" */
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DYN_UTIL_generate_field_position(
|
2004-03-11 06:04:26 +01:00
|
|
|
thread_db* tdbb,
|
2004-03-31 19:38:53 +02:00
|
|
|
Global* gbl,
|
2003-09-09 13:07:19 +02:00
|
|
|
const TEXT* relation_name,
|
2003-11-05 10:02:33 +01:00
|
|
|
SLONG* field_pos)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* D Y N _ U T I L _g e n e r a t e _ f i e l d _ p o s i t i o n
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Generate a field position if not specified
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
SLONG field_position = -1;
|
|
|
|
|
|
|
|
if (!relation_name)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SET_TDBB(tdbb);
|
2004-03-07 08:58:55 +01:00
|
|
|
Database* dbb = tdbb->tdbb_database;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-07-06 07:59:40 +02:00
|
|
|
jrd_req* request = NULL;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
try {
|
|
|
|
|
2004-02-20 07:43:27 +01:00
|
|
|
request = CMP_find_request(tdbb, drq_l_fld_pos, DYN_REQUESTS);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
FOR(REQUEST_HANDLE request)
|
|
|
|
X IN RDB$RELATION_FIELDS
|
|
|
|
WITH X.RDB$RELATION_NAME EQ relation_name
|
|
|
|
|
|
|
|
if (!DYN_REQUEST(drq_l_fld_pos))
|
|
|
|
DYN_REQUEST(drq_l_fld_pos) = request;
|
|
|
|
|
|
|
|
if (X.RDB$FIELD_POSITION.NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
field_position = MAX(X.RDB$FIELD_POSITION, field_position);
|
|
|
|
END_FOR;
|
|
|
|
|
|
|
|
*field_pos = field_position;
|
2001-12-24 03:51:06 +01:00
|
|
|
|
|
|
|
} // try
|
2004-03-01 04:35:23 +01:00
|
|
|
catch (const std::exception& ex) {
|
|
|
|
Firebird::stuff_exception(tdbb->tdbb_status_vector, ex);
|
2002-04-04 09:10:40 +02:00
|
|
|
DYN_rundown_request(request, -1);
|
2003-11-05 10:02:33 +01:00
|
|
|
DYN_error_punt(true, 162, NULL, NULL, NULL, NULL, NULL);
|
2001-12-24 03:51:06 +01:00
|
|
|
/* msg 162: "Looking up field position failed" */
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-11 06:04:26 +01:00
|
|
|
void DYN_UTIL_generate_index_name(thread_db* tdbb,
|
2004-03-31 19:38:53 +02:00
|
|
|
Global* gbl, TEXT* buffer, UCHAR verb)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* D Y N _ U T I L _g e n e r a t e _ i n d e x _ n a m e
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Generate a name unique to RDB$INDICES.
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
SET_TDBB(tdbb);
|
2004-03-07 08:58:55 +01:00
|
|
|
Database* dbb = tdbb->tdbb_database;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-07-06 07:59:40 +02:00
|
|
|
jrd_req* request = NULL;
|
2004-03-07 08:58:55 +01:00
|
|
|
SSHORT id = -1;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
try {
|
|
|
|
|
2003-09-09 13:07:19 +02:00
|
|
|
bool found = false;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
do {
|
2003-11-05 10:02:33 +01:00
|
|
|
const SCHAR* format;
|
2003-11-08 17:40:17 +01:00
|
|
|
if (verb == isc_dyn_def_primary_key)
|
2001-05-23 15:26:42 +02:00
|
|
|
format = "RDB$PRIMARY%" QUADFORMAT "d";
|
2003-11-08 17:40:17 +01:00
|
|
|
else if (verb == isc_dyn_def_foreign_key)
|
2001-05-23 15:26:42 +02:00
|
|
|
format = "RDB$FOREIGN%" QUADFORMAT "d";
|
|
|
|
else
|
|
|
|
format = "RDB$%" QUADFORMAT "d";
|
|
|
|
id = drq_g_nxt_idx;
|
|
|
|
sprintf(buffer, format,
|
|
|
|
(SINT64) DYN_UTIL_gen_unique_id(tdbb,
|
|
|
|
gbl,
|
|
|
|
drq_g_nxt_idx,
|
|
|
|
"RDB$INDEX_NAME",
|
2004-03-01 04:35:23 +01:00
|
|
|
&request));
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-02-20 07:43:27 +01:00
|
|
|
request = CMP_find_request(tdbb, drq_f_nxt_idx, DYN_REQUESTS);
|
2001-05-23 15:26:42 +02:00
|
|
|
id = drq_f_nxt_idx;
|
|
|
|
|
2003-09-09 13:07:19 +02:00
|
|
|
found = false;
|
2001-05-23 15:26:42 +02:00
|
|
|
FOR(REQUEST_HANDLE request)
|
|
|
|
FIRST 1 X IN RDB$INDICES WITH X.RDB$INDEX_NAME EQ buffer
|
|
|
|
|
|
|
|
if (!DYN_REQUEST(drq_f_nxt_idx))
|
|
|
|
DYN_REQUEST(drq_f_nxt_idx) = request;
|
2003-09-09 13:07:19 +02:00
|
|
|
found = true;
|
2001-05-23 15:26:42 +02:00
|
|
|
END_FOR;
|
|
|
|
|
|
|
|
if (!DYN_REQUEST(drq_f_nxt_idx))
|
|
|
|
DYN_REQUEST(drq_f_nxt_idx) = request;
|
|
|
|
request = NULL;
|
|
|
|
} while (found);
|
2001-12-24 03:51:06 +01:00
|
|
|
} // try
|
2004-03-01 04:35:23 +01:00
|
|
|
catch (const std::exception& ex) {
|
|
|
|
Firebird::stuff_exception(tdbb->tdbb_status_vector, ex);
|
2002-04-04 09:10:40 +02:00
|
|
|
DYN_rundown_request(request, id);
|
2003-11-05 10:02:33 +01:00
|
|
|
DYN_error_punt(true, 82, NULL, NULL, NULL, NULL, NULL);
|
2001-12-24 03:51:06 +01:00
|
|
|
/* msg 82: "Generation of index name failed" */
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-31 19:38:53 +02:00
|
|
|
void DYN_UTIL_generate_trigger_name( thread_db* tdbb, Global* gbl, TEXT* buffer)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* D Y N _ U T I L _g e n e r a t e _ t r i g g e r _ n a m e
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Generate a name unique to RDB$TRIGGERS.
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
SET_TDBB(tdbb);
|
2004-03-07 08:58:55 +01:00
|
|
|
Database* dbb = tdbb->tdbb_database;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-07-06 07:59:40 +02:00
|
|
|
jrd_req* request = NULL;
|
2004-03-07 08:58:55 +01:00
|
|
|
SSHORT id = -1;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
try {
|
2003-09-09 13:07:19 +02:00
|
|
|
|
|
|
|
bool found = false;
|
2001-12-24 03:51:06 +01:00
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
do {
|
|
|
|
id = drq_g_nxt_trg;
|
|
|
|
sprintf(buffer, "CHECK_%" QUADFORMAT "d",
|
|
|
|
(SINT64) DYN_UTIL_gen_unique_id(tdbb,
|
|
|
|
gbl,
|
|
|
|
drq_g_nxt_trg,
|
|
|
|
"RDB$TRIGGER_NAME",
|
2004-03-01 04:35:23 +01:00
|
|
|
&request));
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-02-20 07:43:27 +01:00
|
|
|
request = CMP_find_request(tdbb, drq_f_nxt_trg, DYN_REQUESTS);
|
2001-05-23 15:26:42 +02:00
|
|
|
id = drq_f_nxt_trg;
|
|
|
|
|
2003-09-09 13:07:19 +02:00
|
|
|
found = false;
|
2001-05-23 15:26:42 +02:00
|
|
|
FOR(REQUEST_HANDLE request)
|
|
|
|
FIRST 1 X IN RDB$TRIGGERS WITH X.RDB$TRIGGER_NAME EQ buffer
|
|
|
|
|
|
|
|
if (!DYN_REQUEST(drq_f_nxt_trg))
|
|
|
|
DYN_REQUEST(drq_f_nxt_trg) = request;
|
2003-09-09 13:07:19 +02:00
|
|
|
found = true;
|
2001-05-23 15:26:42 +02:00
|
|
|
END_FOR;
|
|
|
|
|
|
|
|
if (!DYN_REQUEST(drq_f_nxt_trg))
|
|
|
|
DYN_REQUEST(drq_f_nxt_trg) = request;
|
|
|
|
request = NULL;
|
|
|
|
} while (found);
|
2001-12-24 03:51:06 +01:00
|
|
|
} // try
|
2004-03-01 04:35:23 +01:00
|
|
|
catch (const std::exception& ex) {
|
|
|
|
Firebird::stuff_exception(tdbb->tdbb_status_vector, ex);
|
2002-04-04 09:10:40 +02:00
|
|
|
DYN_rundown_request(request, id);
|
2003-11-05 10:02:33 +01:00
|
|
|
DYN_error_punt(true, 83, NULL, NULL, NULL, NULL, NULL);
|
2001-12-24 03:51:06 +01:00
|
|
|
/* msg 83: "Generation of trigger name failed" */
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-11 06:04:26 +01:00
|
|
|
bool DYN_UTIL_get_prot(thread_db* tdbb,
|
2004-03-31 19:38:53 +02:00
|
|
|
Global* gbl,
|
2003-11-05 10:02:33 +01:00
|
|
|
const SCHAR* rname,
|
|
|
|
const SCHAR* fname,
|
2004-07-06 07:59:40 +02:00
|
|
|
SecurityClass::flags_t* prot_mask)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* D Y N _ U T I L _g e t _ p r o t
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Get protection mask for relation or relation_field
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
struct
|
|
|
|
{
|
2003-11-05 10:02:33 +01:00
|
|
|
SqlIdentifier relation_name;
|
|
|
|
SqlIdentifier field_name;
|
2001-05-23 15:26:42 +02:00
|
|
|
} in_msg;
|
|
|
|
|
|
|
|
SET_TDBB(tdbb);
|
|
|
|
|
2004-07-06 07:59:40 +02:00
|
|
|
jrd_req* request = CMP_find_request(tdbb, drq_l_prot_mask, DYN_REQUESTS);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
try {
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
if (!request)
|
|
|
|
{
|
2003-11-07 09:06:35 +01:00
|
|
|
request = CMP_compile2(tdbb, prot_blr, TRUE);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
gds__vtov(rname, in_msg.relation_name, sizeof(in_msg.relation_name));
|
|
|
|
gds__vtov(fname, in_msg.field_name, sizeof(in_msg.field_name));
|
|
|
|
EXE_start(tdbb, request, gbl->gbl_transaction);
|
|
|
|
EXE_send(tdbb, request, 0, sizeof(in_msg), (UCHAR*)&in_msg);
|
|
|
|
EXE_receive(tdbb, request, 1, sizeof(USHORT), (UCHAR*)prot_mask);
|
|
|
|
|
2004-03-07 08:58:55 +01:00
|
|
|
DYN_rundown_request(request, drq_l_prot_mask);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
} // try
|
2004-03-01 04:35:23 +01:00
|
|
|
catch (const std::exception& ex) {
|
|
|
|
Firebird::stuff_exception(tdbb->tdbb_status_vector, ex);
|
2004-03-11 06:47:35 +01:00
|
|
|
DYN_rundown_request(request, drq_l_prot_mask);
|
2003-11-05 10:02:33 +01:00
|
|
|
return false;
|
2001-12-24 03:51:06 +01:00
|
|
|
}
|
2003-11-05 10:02:33 +01:00
|
|
|
return true;
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-11 06:04:26 +01:00
|
|
|
void DYN_UTIL_store_check_constraints(thread_db* tdbb,
|
2004-03-31 19:38:53 +02:00
|
|
|
Global* gbl,
|
2003-11-05 10:02:33 +01:00
|
|
|
const TEXT* constraint_name,
|
|
|
|
const TEXT* trigger_name)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* D Y N _ U T I L _s t o r e _ c h e c k _ c o n s t r a i n t s
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
SET_TDBB(tdbb);
|
2004-03-07 08:58:55 +01:00
|
|
|
Database* dbb = tdbb->tdbb_database;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-07-06 07:59:40 +02:00
|
|
|
jrd_req* request = CMP_find_request(tdbb, drq_s_chk_con, DYN_REQUESTS);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
try {
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
STORE(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction)
|
|
|
|
CHK IN RDB$CHECK_CONSTRAINTS
|
|
|
|
strcpy(CHK.RDB$CONSTRAINT_NAME, constraint_name);
|
|
|
|
strcpy(CHK.RDB$TRIGGER_NAME, trigger_name);
|
|
|
|
|
|
|
|
END_STORE;
|
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
if (!DYN_REQUEST(drq_s_chk_con)) {
|
2001-05-23 15:26:42 +02:00
|
|
|
DYN_REQUEST(drq_s_chk_con) = request;
|
2001-12-24 03:51:06 +01:00
|
|
|
}
|
|
|
|
} // try
|
2004-03-01 04:35:23 +01:00
|
|
|
catch (const std::exception& ex) {
|
|
|
|
Firebird::stuff_exception(tdbb->tdbb_status_vector, ex);
|
2002-04-04 09:10:40 +02:00
|
|
|
DYN_rundown_request(request, drq_s_chk_con);
|
2003-11-05 10:02:33 +01:00
|
|
|
DYN_error_punt(true, 122, NULL, NULL, NULL, NULL, NULL);
|
2001-12-24 03:51:06 +01:00
|
|
|
/* msg 122: "STORE RDB$CHECK_CONSTRAINTS failed" */
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2003-09-09 13:07:19 +02:00
|
|
|
|