2001-05-23 15:26:42 +02:00
|
|
|
/*
|
|
|
|
* PROGRAM: JRD Access Method
|
2004-01-28 08:50:41 +01:00
|
|
|
* MODULE: ini.epp
|
2001-05-23 15:26:42 +02:00
|
|
|
* DESCRIPTION: Metadata initialization / population
|
|
|
|
*
|
|
|
|
* 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): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
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>
|
2004-03-22 12:38:23 +01:00
|
|
|
#include "../jrd/common.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
#include "../jrd/flags.h"
|
|
|
|
#include "../jrd/jrd.h"
|
|
|
|
#include "../jrd/val.h"
|
2003-11-08 17:40:17 +01:00
|
|
|
#include "../jrd/ibase.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
#include "../jrd/ods.h"
|
|
|
|
#include "../jrd/btr.h"
|
2001-07-29 19:42:23 +02:00
|
|
|
#include "gen/ids.h"
|
2009-11-28 17:39:54 +01:00
|
|
|
#include "../jrd/intl.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
#include "../jrd/tra.h"
|
|
|
|
#include "../jrd/trig.h"
|
|
|
|
#include "../jrd/intl.h"
|
|
|
|
#include "../jrd/dflt.h"
|
|
|
|
#include "../jrd/ini.h"
|
|
|
|
#include "../jrd/idx.h"
|
|
|
|
#include "../jrd/gdsassert.h"
|
|
|
|
#include "../jrd/blb_proto.h"
|
|
|
|
#include "../jrd/cch_proto.h"
|
|
|
|
#include "../jrd/cmp_proto.h"
|
|
|
|
#include "../jrd/dfw_proto.h"
|
|
|
|
#include "../jrd/dpm_proto.h"
|
|
|
|
#include "../jrd/err_proto.h"
|
|
|
|
#include "../jrd/exe_proto.h"
|
|
|
|
#include "../jrd/gds_proto.h"
|
|
|
|
#include "../jrd/idx_proto.h"
|
|
|
|
#include "../jrd/ini_proto.h"
|
|
|
|
#include "../jrd/jrd_proto.h"
|
|
|
|
#include "../jrd/met_proto.h"
|
|
|
|
#include "../jrd/obj.h"
|
|
|
|
#include "../jrd/acl.h"
|
|
|
|
#include "../jrd/irq.h"
|
2008-01-16 10:07:24 +01:00
|
|
|
#include "../jrd/IntlManager.h"
|
2009-06-26 13:18:45 +02:00
|
|
|
#include "../jrd/constants.h"
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-03-20 15:57:40 +01:00
|
|
|
using namespace Jrd;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
DATABASE DB = FILENAME "ODS.RDB";
|
|
|
|
|
2001-07-12 08:32:05 +02:00
|
|
|
#define PAD(string, field) jrd_vtof ((char*)(string), field, sizeof (field))
|
2008-11-13 10:42:13 +01:00
|
|
|
const int FB_MAX_ACL_SIZE = 4096;
|
2009-06-26 13:18:45 +02:00
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-11-27 07:59:21 +01:00
|
|
|
static void add_index_set(Database*);
|
2005-05-28 00:45:31 +02:00
|
|
|
static void add_security_to_sys_rel(thread_db*, const Firebird::MetaName&,
|
2005-05-12 20:28:04 +02:00
|
|
|
const TEXT*, const UCHAR*, const SSHORT);
|
2004-03-20 15:57:40 +01:00
|
|
|
static void store_generator(thread_db*, const gen*, jrd_req**);
|
|
|
|
static void store_global_field(thread_db*, const gfld*, jrd_req**);
|
2004-03-11 06:04:26 +01:00
|
|
|
static void store_intlnames(thread_db*, Database*);
|
2004-03-20 15:57:40 +01:00
|
|
|
static void store_message(thread_db*, const trigger_msg*, jrd_req**);
|
2009-10-22 16:50:23 +02:00
|
|
|
static void store_relation_field(thread_db*, const int*, const int*, int, jrd_req**);
|
2004-03-20 15:57:40 +01:00
|
|
|
static void store_trigger(thread_db*, const jrd_trg*, jrd_req**);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
|
2009-11-08 10:13:35 +01:00
|
|
|
// This is the table used in defining triggers; note that
|
|
|
|
// RDB$TRIGGER_0 was first changed to RDB$TRIGGER_7 to make it easier to
|
|
|
|
// upgrade a database to support field-level grant. It has since been
|
|
|
|
// changed to RDB$TRIGGER_9 to handle SQL security on relations whose
|
|
|
|
// name is > 27 characters
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-12-03 09:19:24 +01:00
|
|
|
static const jrd_trg triggers[] =
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_1", (UCHAR) nam_user_privileges,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger3), trigger3,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_8", (UCHAR) nam_user_privileges,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_ERASE, sizeof(trigger2), trigger2,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_9", (UCHAR) nam_user_privileges,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_STORE, sizeof(trigger1), trigger1,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_2", (UCHAR) nam_trgs,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger4), trigger4,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_3", (UCHAR) nam_trgs,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_ERASE, sizeof(trigger4), trigger4,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_4", (UCHAR) nam_relations,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_STORE, sizeof(trigger5), trigger5,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_5", (UCHAR) nam_relations,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger6), trigger6,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_6", (UCHAR) nam_gens,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_STORE, sizeof(trigger7), trigger7,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_26", (UCHAR) nam_rel_constr,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_STORE, sizeof(trigger26), trigger26,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_25", (UCHAR) nam_rel_constr,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger25),
|
2001-12-24 03:51:06 +01:00
|
|
|
trigger25, 0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_10", (UCHAR) nam_rel_constr,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_ERASE, sizeof(trigger10), trigger10,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_11", (UCHAR) nam_rel_constr,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.POST_ERASE, sizeof(trigger11),
|
2001-12-24 03:51:06 +01:00
|
|
|
trigger11, 0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_12", (UCHAR) nam_ref_constr,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_STORE, sizeof(trigger12), trigger12,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_13", (UCHAR) nam_ref_constr,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger13),
|
2001-12-24 03:51:06 +01:00
|
|
|
trigger13, 0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_14", (UCHAR) nam_chk_constr,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger14),
|
2001-12-24 03:51:06 +01:00
|
|
|
trigger14, 0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_15", (UCHAR) nam_chk_constr,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_ERASE, sizeof(trigger15), trigger15,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_16", (UCHAR) nam_chk_constr,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.POST_ERASE, sizeof(trigger16),
|
2001-12-24 03:51:06 +01:00
|
|
|
trigger16, 0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_17", (UCHAR) nam_i_segments,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_ERASE, sizeof(trigger17), trigger17,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_18", (UCHAR) nam_i_segments,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger18),
|
2001-12-24 03:51:06 +01:00
|
|
|
trigger18, 0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_19", (UCHAR) nam_indices,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_ERASE, sizeof(trigger19), trigger19,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_20", (UCHAR) nam_indices,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger20),
|
2001-12-24 03:51:06 +01:00
|
|
|
trigger20, 0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_21", (UCHAR) nam_trgs,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_ERASE, sizeof(trigger21), trigger21,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_22", (UCHAR) nam_trgs,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger22),
|
2001-12-24 03:51:06 +01:00
|
|
|
trigger22, 0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_23", (UCHAR) nam_r_fields,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_ERASE, sizeof(trigger23), trigger23,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_24", (UCHAR) nam_r_fields,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger24),
|
2001-12-24 03:51:06 +01:00
|
|
|
trigger24, 0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_27", (UCHAR) nam_r_fields,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.POST_ERASE, sizeof(trigger27),
|
2001-12-24 03:51:06 +01:00
|
|
|
trigger27, 0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_28", (UCHAR) nam_procedures,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_STORE, sizeof(trigger28), trigger28,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_29", (UCHAR) nam_procedures,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger29),
|
2001-12-24 03:51:06 +01:00
|
|
|
trigger29, 0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_30", (UCHAR) nam_exceptions,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_STORE, sizeof(trigger30), trigger30,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_0 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_31", (UCHAR) nam_user_privileges,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger31),
|
2001-12-24 03:51:06 +01:00
|
|
|
trigger31, 0, ODS_8_1 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_32", (UCHAR) nam_user_privileges,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_ERASE, sizeof(trigger31), trigger31,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_1 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_33", (UCHAR) nam_user_privileges,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_STORE, sizeof(trigger31), trigger31,
|
2001-12-24 03:51:06 +01:00
|
|
|
0, ODS_8_1 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_34", (UCHAR) nam_rel_constr,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.POST_ERASE, sizeof(trigger34),
|
2001-12-24 03:51:06 +01:00
|
|
|
trigger34, TRG_ignore_perm, ODS_8_1 },
|
2003-08-04 01:26:51 +02:00
|
|
|
{ "RDB$TRIGGER_35", (UCHAR) nam_chk_constr,
|
2001-05-23 15:26:42 +02:00
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.POST_ERASE, sizeof(trigger35),
|
2001-12-24 03:51:06 +01:00
|
|
|
trigger35, TRG_ignore_perm, ODS_8_1 },
|
2005-12-08 14:52:11 +01:00
|
|
|
{ "RDB$TRIGGER_36", (UCHAR) nam_fields,
|
|
|
|
RDB$TRIGGERS.RDB$TRIGGER_TYPE.PRE_MODIFY, sizeof(trigger36),
|
|
|
|
trigger36, 0, ODS_11_0 },
|
2001-12-24 03:51:06 +01:00
|
|
|
{ 0, 0, 0, 0, 0, 0 }
|
2001-05-23 15:26:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-11-08 10:13:35 +01:00
|
|
|
// this table is used in defining messages for system triggers
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-01-28 08:50:41 +01:00
|
|
|
static const trigger_msg trigger_messages[] =
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2001-12-24 03:51:06 +01:00
|
|
|
{ "RDB$TRIGGER_9", 0, "grant_obj_notfound", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_9", 1, "grant_fld_notfound", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_9", 2, "grant_nopriv", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_9", 3, "nonsql_security_rel", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_9", 4, "nonsql_security_fld", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_9", 5, "grant_nopriv_on_base", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_1", 0, "existing_priv_mod", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_2", 0, "systrig_update", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_3", 0, "systrig_update", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_5", 0, "not_rel_owner", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_24", 1, "cnstrnt_fld_rename", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_23", 1, "cnstrnt_fld_del", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_22", 1, "check_trig_update", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_21", 1, "check_trig_del", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_20", 1, "integ_index_mod", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_20", 2, "integ_index_deactivate", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_20", 3, "integ_deactivate_primary", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_19", 1, "integ_index_del", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_18", 1, "integ_index_seg_mod", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_17", 1, "integ_index_seg_del", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_15", 1, "check_cnstrnt_del", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_14", 1, "check_cnstrnt_update", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_13", 1, "ref_cnstrnt_update", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_12", 1, "ref_cnstrnt_notfound", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_12", 2, "foreign_key_notfound", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_10", 1, "primary_key_ref", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_10", 2, "primary_key_notnull", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_25", 1, "rel_cnstrnt_update", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_26", 1, "constaint_on_view", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_26", 2, "invld_cnstrnt_type", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_26", 3, "primary_key_exists", ODS_8_0 },
|
|
|
|
{ "RDB$TRIGGER_31", 0, "no_write_user_priv", ODS_8_1 },
|
|
|
|
{ "RDB$TRIGGER_32", 0, "no_write_user_priv", ODS_8_1 },
|
|
|
|
{ "RDB$TRIGGER_33", 0, "no_write_user_priv", ODS_8_1 },
|
2005-12-08 14:52:11 +01:00
|
|
|
{ "RDB$TRIGGER_24", 2, "integ_index_seg_mod", ODS_11_0 },
|
|
|
|
{ "RDB$TRIGGER_36", 1, "integ_index_seg_mod", ODS_11_0 },
|
2001-12-24 03:51:06 +01:00
|
|
|
{ 0, 0, 0, 0 }
|
2001-05-23 15:26:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-12-03 09:19:24 +01:00
|
|
|
void INI_format(const TEXT* owner, const TEXT* charset)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* I N I _ f o r m a t
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Initialize system relations in the database.
|
|
|
|
* The full complement of metadata should be
|
|
|
|
* stored here.
|
|
|
|
*
|
|
|
|
**************************************/
|
2004-05-22 16:28:54 +02:00
|
|
|
thread_db* tdbb = JRD_get_thread_data();
|
2007-12-03 16:46:39 +01:00
|
|
|
Database* dbb = tdbb->getDatabase();
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-11-08 10:13:35 +01:00
|
|
|
// Uppercase owner name
|
2005-05-12 20:28:04 +02:00
|
|
|
Firebird::MetaName string(owner ? owner : "");
|
|
|
|
string.upper7();
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-11-08 10:13:35 +01:00
|
|
|
// Uppercase charset name
|
2005-05-12 20:28:04 +02:00
|
|
|
Firebird::MetaName string2(charset ? charset : "");
|
|
|
|
string2.upper7();
|
2003-01-23 04:33:53 +01:00
|
|
|
|
2004-01-28 08:50:41 +01:00
|
|
|
int n;
|
2006-07-17 19:44:18 +02:00
|
|
|
const int* fld;
|
2005-05-28 00:45:31 +02:00
|
|
|
|
2009-11-08 10:13:35 +01:00
|
|
|
// Make sure relations exist already
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2006-07-17 19:44:18 +02:00
|
|
|
for (const int* relfld = relfields; relfld[RFLD_R_NAME]; relfld = fld + 1)
|
|
|
|
{
|
|
|
|
if (relfld[RFLD_R_TYPE] == rel_persistent)
|
|
|
|
{
|
|
|
|
DPM_create_relation(tdbb, MET_relation(tdbb, relfld[RFLD_R_ID]));
|
|
|
|
}
|
|
|
|
|
2006-07-18 04:45:35 +02:00
|
|
|
for (fld = relfld + RFLD_RPT; fld[RFLD_F_NAME]; fld += RFLD_F_LENGTH)
|
|
|
|
;
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2009-11-08 10:13:35 +01:00
|
|
|
// Store RELATIONS and RELATION_FIELDS
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-03-20 15:57:40 +01:00
|
|
|
jrd_req* handle1 = NULL;
|
|
|
|
jrd_req* handle2 = NULL;
|
2006-07-17 19:44:18 +02:00
|
|
|
for (const int* relfld = relfields; relfld[RFLD_R_NAME]; relfld = fld + 1)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2008-12-20 09:12:19 +01:00
|
|
|
for (n = 0, fld = relfld + RFLD_RPT; fld[RFLD_F_NAME]; fld += RFLD_F_LENGTH)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2009-10-22 16:50:23 +02:00
|
|
|
const int* pFld = fld;
|
|
|
|
const int* pRelFld = relfld;
|
|
|
|
store_relation_field(tdbb, pFld, pRelFld, n, &handle2);
|
|
|
|
n++;
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
STORE(REQUEST_HANDLE handle1) X IN RDB$RELATIONS
|
|
|
|
X.RDB$RELATION_ID = relfld[RFLD_R_ID];
|
|
|
|
PAD(names[relfld[RFLD_R_NAME]], X.RDB$RELATION_NAME);
|
|
|
|
X.RDB$FIELD_ID = n;
|
|
|
|
X.RDB$FORMAT = 0;
|
|
|
|
X.RDB$SYSTEM_FLAG = RDB_system;
|
2008-05-06 11:03:33 +02:00
|
|
|
X.RDB$SYSTEM_FLAG.NULL = FALSE;
|
2001-05-23 15:26:42 +02:00
|
|
|
X.RDB$DBKEY_LENGTH = 8;
|
|
|
|
X.RDB$OWNER_NAME.NULL = TRUE;
|
2006-07-17 19:44:18 +02:00
|
|
|
X.RDB$RELATION_TYPE = relfld[RFLD_R_TYPE];
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2005-05-12 20:28:04 +02:00
|
|
|
if (string.length())
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2005-05-12 20:28:04 +02:00
|
|
|
PAD(string.c_str(), X.RDB$OWNER_NAME);
|
2001-05-23 15:26:42 +02:00
|
|
|
X.RDB$OWNER_NAME.NULL = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
END_STORE;
|
|
|
|
}
|
|
|
|
|
2004-08-21 11:39:37 +02:00
|
|
|
CMP_release(tdbb, handle1);
|
|
|
|
CMP_release(tdbb, handle2);
|
2001-05-23 15:26:42 +02:00
|
|
|
handle1 = handle2 = NULL;
|
|
|
|
|
2009-11-08 10:13:35 +01:00
|
|
|
// Store global FIELDS
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-05-06 11:03:33 +02:00
|
|
|
for (const gfld* gfield = gfields; gfield->gfld_name; gfield++)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
store_global_field(tdbb, gfield, &handle1);
|
|
|
|
}
|
|
|
|
|
2004-08-21 11:39:37 +02:00
|
|
|
CMP_release(tdbb, handle1);
|
2001-05-23 15:26:42 +02:00
|
|
|
handle1 = NULL;
|
|
|
|
|
2008-01-16 10:07:24 +01:00
|
|
|
// Store DATABASE record
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
STORE(REQUEST_HANDLE handle1) X IN RDB$DATABASE
|
|
|
|
X.RDB$RELATION_ID = (int) USER_DEF_REL_INIT_ID;
|
2003-01-23 04:33:53 +01:00
|
|
|
X.RDB$CHARACTER_SET_NAME.NULL = TRUE;
|
2009-11-28 02:44:42 +01:00
|
|
|
if (string2.hasData())
|
2009-11-27 07:59:21 +01:00
|
|
|
{
|
2005-05-28 00:45:31 +02:00
|
|
|
PAD (string2.c_str(), X.RDB$CHARACTER_SET_NAME);
|
2003-01-23 04:33:53 +01:00
|
|
|
X.RDB$CHARACTER_SET_NAME.NULL = FALSE;
|
|
|
|
}
|
2009-11-27 07:59:21 +01:00
|
|
|
else
|
|
|
|
{
|
2003-01-23 04:33:53 +01:00
|
|
|
PAD (DEFAULT_DB_CHARACTER_SET_NAME, X.RDB$CHARACTER_SET_NAME);
|
|
|
|
X.RDB$CHARACTER_SET_NAME.NULL = FALSE;
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
END_STORE
|
|
|
|
|
2004-08-21 11:39:37 +02:00
|
|
|
CMP_release(tdbb, handle1);
|
2001-05-23 15:26:42 +02:00
|
|
|
handle1 = NULL;
|
|
|
|
|
2008-01-16 10:07:24 +01:00
|
|
|
// Store ADMIN_ROLE record
|
|
|
|
|
|
|
|
STORE(REQUEST_HANDLE handle1) X IN RDB$ROLES
|
|
|
|
PAD (ADMIN_ROLE, X.RDB$ROLE_NAME);
|
|
|
|
X.RDB$ROLE_NAME.NULL = FALSE;
|
|
|
|
if (string.length()) {
|
|
|
|
PAD (string.c_str(), X.RDB$OWNER_NAME);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PAD (SYSDBA_USER_NAME, X.RDB$OWNER_NAME);
|
|
|
|
}
|
|
|
|
X.RDB$OWNER_NAME.NULL = FALSE;
|
|
|
|
X.RDB$DESCRIPTION.NULL = TRUE;
|
|
|
|
X.RDB$SYSTEM_FLAG = ROLE_FLAG_DBO; // Mark it as privileged role
|
|
|
|
X.RDB$SYSTEM_FLAG.NULL = FALSE;
|
|
|
|
END_STORE
|
|
|
|
|
|
|
|
CMP_release(tdbb, handle1);
|
|
|
|
handle1 = NULL;
|
|
|
|
|
|
|
|
// Create indices for system relations
|
2009-11-27 07:59:21 +01:00
|
|
|
add_index_set(dbb);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-01-16 10:07:24 +01:00
|
|
|
// Create parameter types
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
handle1 = NULL;
|
|
|
|
|
2004-01-28 08:50:41 +01:00
|
|
|
for (const rtyp* type = types; type->rtyp_name; ++type)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2008-01-16 10:07:24 +01:00
|
|
|
// this STORE should be compatible with two below,
|
|
|
|
// as they use the same compiled request
|
2001-05-23 15:26:42 +02:00
|
|
|
STORE(REQUEST_HANDLE handle1) X IN RDB$TYPES
|
|
|
|
PAD(names[type->rtyp_field], X.RDB$FIELD_NAME);
|
|
|
|
PAD(type->rtyp_name, X.RDB$TYPE_NAME);
|
|
|
|
X.RDB$TYPE = type->rtyp_value;
|
|
|
|
X.RDB$SYSTEM_FLAG = RDB_system;
|
2008-05-06 11:03:33 +02:00
|
|
|
X.RDB$SYSTEM_FLAG.NULL = FALSE;
|
2001-05-23 15:26:42 +02:00
|
|
|
END_STORE;
|
|
|
|
}
|
|
|
|
|
2008-01-16 10:07:24 +01:00
|
|
|
for (const IntlManager::CharSetDefinition* charSet = IntlManager::defaultCharSets;
|
|
|
|
charSet->name; ++charSet)
|
|
|
|
{
|
|
|
|
// this STORE should be compatible with one above and below,
|
|
|
|
// as they use the same compiled request
|
|
|
|
STORE(REQUEST_HANDLE handle1) X IN RDB$TYPES
|
|
|
|
PAD(names[nam_charset_name], X.RDB$FIELD_NAME);
|
|
|
|
PAD(charSet->name, X.RDB$TYPE_NAME);
|
|
|
|
X.RDB$TYPE = charSet->id;
|
|
|
|
X.RDB$SYSTEM_FLAG = RDB_system;
|
2008-05-06 11:03:33 +02:00
|
|
|
X.RDB$SYSTEM_FLAG.NULL = FALSE;
|
2008-01-16 10:07:24 +01:00
|
|
|
END_STORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const IntlManager::CharSetAliasDefinition* alias = IntlManager::defaultCharSetAliases;
|
|
|
|
alias->name; ++alias)
|
|
|
|
{
|
|
|
|
// this STORE should be compatible with two above,
|
|
|
|
// as they use the same compiled request
|
|
|
|
STORE(REQUEST_HANDLE handle1) X IN RDB$TYPES
|
|
|
|
PAD(names[nam_charset_name], X.RDB$FIELD_NAME);
|
|
|
|
PAD(alias->name, X.RDB$TYPE_NAME);
|
|
|
|
X.RDB$TYPE = alias->charSetId;
|
|
|
|
X.RDB$SYSTEM_FLAG = RDB_system;
|
2008-05-06 11:03:33 +02:00
|
|
|
X.RDB$SYSTEM_FLAG.NULL = FALSE;
|
2008-01-16 10:07:24 +01:00
|
|
|
END_STORE;
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-01-16 10:07:24 +01:00
|
|
|
CMP_release(tdbb, handle1);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-01-16 10:07:24 +01:00
|
|
|
// Store symbols for international character sets & collations
|
2001-05-23 15:26:42 +02:00
|
|
|
store_intlnames(tdbb, dbb);
|
|
|
|
|
2008-01-16 10:07:24 +01:00
|
|
|
// Create generators to be used by system triggers
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
handle1 = NULL;
|
2004-01-28 08:50:41 +01:00
|
|
|
for (const gen* generator = generators; generator->gen_name; generator++)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
store_generator(tdbb, generator, &handle1);
|
|
|
|
}
|
2004-08-21 11:39:37 +02:00
|
|
|
CMP_release(tdbb, handle1);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-01-16 10:07:24 +01:00
|
|
|
// Adjust the value of the hidden generator RDB$GENERATORS
|
2005-11-25 15:23:15 +01:00
|
|
|
DPM_gen_id(tdbb, 0, true, FB_NELEM(generators) - 1);
|
|
|
|
|
2009-11-08 10:13:35 +01:00
|
|
|
// store system-defined triggers
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
handle1 = NULL;
|
2004-01-28 08:50:41 +01:00
|
|
|
for (const jrd_trg* trigger = triggers; trigger->trg_relation; ++trigger)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
store_trigger(tdbb, trigger, &handle1);
|
|
|
|
}
|
2004-08-21 11:39:37 +02:00
|
|
|
CMP_release(tdbb, handle1);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-11-08 10:13:35 +01:00
|
|
|
// store trigger messages to go with triggers
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
handle1 = NULL;
|
2009-11-27 07:59:21 +01:00
|
|
|
for (const trigger_msg* message = trigger_messages; message->trigmsg_name; ++message)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
store_message(tdbb, message, &handle1);
|
|
|
|
}
|
2004-08-21 11:39:37 +02:00
|
|
|
CMP_release(tdbb, handle1);
|
|
|
|
|
2008-03-18 14:04:05 +01:00
|
|
|
DFW_perform_system_work(tdbb);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-11-08 10:13:35 +01:00
|
|
|
// Add security on RDB$ROLES system table
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-11-13 10:42:13 +01:00
|
|
|
UCHAR buffer[FB_MAX_ACL_SIZE];
|
2003-10-29 11:53:47 +01:00
|
|
|
UCHAR* acl = buffer;
|
2001-05-23 15:26:42 +02:00
|
|
|
*acl++ = ACL_version;
|
|
|
|
*acl++ = ACL_id_list;
|
|
|
|
*acl++ = id_person;
|
2005-05-28 00:45:31 +02:00
|
|
|
|
2005-05-12 20:28:04 +02:00
|
|
|
USHORT length = string.length();
|
2006-06-02 11:20:52 +02:00
|
|
|
if (length > MAX_UCHAR)
|
|
|
|
length = MAX_UCHAR;
|
2008-12-20 09:12:19 +01:00
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
*acl++ = (UCHAR)length;
|
|
|
|
if (length)
|
|
|
|
{
|
2006-06-02 11:20:52 +02:00
|
|
|
const TEXT* p_1 = string.c_str();
|
2006-02-23 06:08:26 +01:00
|
|
|
memcpy(acl, p_1, length);
|
|
|
|
acl += length;
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
*acl++ = ACL_end;
|
|
|
|
*acl++ = ACL_priv_list;
|
|
|
|
*acl++ = priv_protect;
|
|
|
|
*acl++ = priv_control;
|
|
|
|
*acl++ = priv_delete;
|
|
|
|
*acl++ = priv_write;
|
|
|
|
*acl++ = priv_read;
|
|
|
|
*acl++ = ACL_end;
|
|
|
|
*acl++ = ACL_id_list;
|
|
|
|
*acl++ = ACL_end;
|
|
|
|
*acl++ = ACL_priv_list;
|
|
|
|
*acl++ = priv_read;
|
|
|
|
*acl++ = ACL_end;
|
|
|
|
*acl++ = ACL_end;
|
|
|
|
length = acl - buffer;
|
|
|
|
|
2003-10-29 11:53:47 +01:00
|
|
|
add_security_to_sys_rel(tdbb, string, "RDB$ROLES", buffer, length);
|
2006-06-02 11:20:52 +02:00
|
|
|
add_security_to_sys_rel(tdbb, string, "RDB$PAGES", buffer, length);
|
|
|
|
// DFW writes here
|
|
|
|
add_security_to_sys_rel(tdbb, string, "RDB$FORMATS", buffer, length);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-03 09:19:24 +01:00
|
|
|
USHORT INI_get_trig_flags(const TEXT* trig_name)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/*********************************************
|
|
|
|
*
|
|
|
|
* I N I _ g e t _ t r i g _ f l a g s
|
|
|
|
*
|
|
|
|
*********************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Return the trigger flags for a system trigger.
|
|
|
|
*
|
|
|
|
**************************************/
|
2003-12-03 09:19:24 +01:00
|
|
|
for (const jrd_trg* trig = triggers; trig->trg_length > 0; trig++)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
if (!strcmp(trig->trg_name, trig_name))
|
|
|
|
{
|
|
|
|
return (trig->trg_flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-09 10:40:31 +02:00
|
|
|
void INI_init(thread_db* tdbb)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* I N I _ i n i t
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Initialize in memory meta data. Assume that all meta data
|
|
|
|
* fields exist in the database even if this is not the case.
|
|
|
|
* Do not fill in the format length or the address in each
|
|
|
|
* format descriptor.
|
|
|
|
*
|
|
|
|
**************************************/
|
2008-07-09 10:40:31 +02:00
|
|
|
SET_TDBB(tdbb);
|
|
|
|
Database* const dbb = tdbb->getDatabase();
|
2001-05-23 15:26:42 +02:00
|
|
|
CHECK_DBB(dbb);
|
|
|
|
|
2006-07-17 19:44:18 +02:00
|
|
|
const int* fld;
|
|
|
|
for (const int* relfld = relfields; relfld[RFLD_R_NAME]; relfld = fld + 1)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2004-01-28 08:50:41 +01:00
|
|
|
jrd_rel* relation = MET_relation(tdbb, relfld[RFLD_R_ID]);
|
2001-05-23 15:26:42 +02:00
|
|
|
relation->rel_flags |= REL_system;
|
2005-05-12 20:28:04 +02:00
|
|
|
relation->rel_name = names[relfld[RFLD_R_NAME]];
|
2004-01-28 08:50:41 +01:00
|
|
|
int n = 0;
|
2008-12-20 09:12:19 +01:00
|
|
|
for (fld = relfld + RFLD_RPT; fld[RFLD_F_NAME]; fld += RFLD_F_LENGTH)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
2009-11-08 10:13:35 +01:00
|
|
|
// Set a flag if their is a trigger on the relation. Later we may need to compile it.
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-01-28 08:50:41 +01:00
|
|
|
for (const jrd_trg* trigger = triggers; trigger->trg_relation; trigger++)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
if (relation->rel_name == names[trigger->trg_relation])
|
|
|
|
{
|
|
|
|
relation->rel_flags |= REL_sys_triggers;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-02 08:35:34 +01:00
|
|
|
vec<jrd_fld*>* fields = vec<jrd_fld*>::newVector(*dbb->dbb_permanent, n);
|
2004-01-28 08:50:41 +01:00
|
|
|
relation->rel_fields = fields;
|
2005-12-02 08:35:34 +01:00
|
|
|
vec<jrd_fld*>::iterator itr = fields->begin();
|
2004-03-30 06:10:52 +02:00
|
|
|
Format* format = Format::newFormat(*dbb->dbb_permanent, n);
|
2004-01-28 08:50:41 +01:00
|
|
|
relation->rel_current_format = format;
|
2005-12-02 08:35:34 +01:00
|
|
|
vec<Format*>* formats = vec<Format*>::newVector(*dbb->dbb_permanent, 1);
|
2004-01-28 08:50:41 +01:00
|
|
|
relation->rel_formats = formats;
|
2001-12-24 03:51:06 +01:00
|
|
|
(*formats)[0] = format;
|
2004-03-30 06:10:52 +02:00
|
|
|
Format::fmt_desc_iterator desc = format->fmt_desc.begin();
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-12-20 09:12:19 +01:00
|
|
|
for (fld = relfld + RFLD_RPT; fld[RFLD_F_NAME]; fld += RFLD_F_LENGTH, ++desc, ++itr)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2004-05-31 04:34:35 +02:00
|
|
|
const gfld* gfield = &gfields[fld[RFLD_F_ID]];
|
2001-05-23 15:26:42 +02:00
|
|
|
desc->dsc_length = gfield->gfld_length;
|
2008-02-20 14:17:54 +01:00
|
|
|
if (gfield->gfld_dtype == dtype_varying)
|
2008-02-21 14:11:32 +01:00
|
|
|
{
|
|
|
|
fb_assert(desc->dsc_length <= MAX_USHORT - sizeof(USHORT));
|
2008-02-20 14:17:54 +01:00
|
|
|
desc->dsc_length += sizeof(USHORT);
|
2008-02-21 14:11:32 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
desc->dsc_dtype = gfield->gfld_dtype;
|
2009-11-28 17:39:54 +01:00
|
|
|
|
|
|
|
if (desc->isText())
|
|
|
|
{
|
|
|
|
if (gfield->gfld_sub_type & dsc_text_type_metadata)
|
|
|
|
desc->dsc_sub_type = CS_METADATA;
|
|
|
|
else
|
|
|
|
desc->dsc_sub_type = CS_NONE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
desc->dsc_sub_type = gfield->gfld_sub_type;
|
|
|
|
|
2005-06-10 04:01:39 +02:00
|
|
|
if (desc->dsc_dtype == dtype_blob && desc->dsc_sub_type == isc_blob_text)
|
2005-05-28 00:45:31 +02:00
|
|
|
desc->dsc_scale = CS_METADATA; // blob charset
|
|
|
|
|
2005-05-12 20:28:04 +02:00
|
|
|
jrd_fld* field = FB_NEW(*dbb->dbb_permanent) jrd_fld(*dbb->dbb_permanent);
|
2004-01-03 11:59:52 +01:00
|
|
|
*itr = field;
|
2004-05-31 04:34:35 +02:00
|
|
|
field->fld_name = names[fld[RFLD_F_NAME]];
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-09 10:40:31 +02:00
|
|
|
void INI_init2(thread_db* tdbb)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* I N I _ i n i t 2
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Re-initialize in memory meta data. Fill in
|
|
|
|
* format 0 based on the minor ODS version of
|
|
|
|
* the database when it was created.
|
|
|
|
*
|
|
|
|
**************************************/
|
2008-07-09 10:40:31 +02:00
|
|
|
SET_TDBB(tdbb);
|
|
|
|
Database* const dbb = tdbb->getDatabase();
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-12-31 06:36:12 +01:00
|
|
|
const USHORT major_version = dbb->dbb_ods_version;
|
2009-11-18 13:02:00 +01:00
|
|
|
const USHORT minor_version = dbb->dbb_minor_version;
|
2005-12-02 08:35:34 +01:00
|
|
|
vec<jrd_rel*>* vector = dbb->dbb_relations;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2006-07-17 19:44:18 +02:00
|
|
|
const int* fld;
|
|
|
|
for (const int* relfld = relfields; relfld[RFLD_R_NAME]; relfld = fld + 1)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2009-11-18 13:02:00 +01:00
|
|
|
if (relfld[RFLD_R_ODS] > ENCODE_ODS(major_version, minor_version))
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2009-11-08 10:13:35 +01:00
|
|
|
// free the space allocated for RDB$ROLES
|
|
|
|
|
2004-01-28 08:50:41 +01:00
|
|
|
const USHORT id = relfld[RFLD_R_ID];
|
2005-12-02 08:35:34 +01:00
|
|
|
jrd_rel* relation = (*vector)[id];
|
2001-12-24 03:51:06 +01:00
|
|
|
delete relation->rel_current_format;
|
|
|
|
delete relation->rel_formats;
|
|
|
|
delete relation->rel_fields;
|
|
|
|
(*vector)[id] = NULL;
|
2001-05-23 15:26:42 +02:00
|
|
|
fld = relfld + RFLD_RPT;
|
|
|
|
while (fld[RFLD_F_NAME])
|
|
|
|
{
|
|
|
|
fld += RFLD_F_LENGTH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-01-28 08:50:41 +01:00
|
|
|
jrd_rel* relation = MET_relation(tdbb, relfld[RFLD_R_ID]);
|
2004-03-30 06:10:52 +02:00
|
|
|
Format* format = relation->rel_current_format;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-01-28 08:50:41 +01:00
|
|
|
int n = 0;
|
2008-12-20 09:12:19 +01:00
|
|
|
for (fld = relfld + RFLD_RPT; fld[RFLD_F_NAME]; fld += RFLD_F_LENGTH)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2009-11-18 13:02:00 +01:00
|
|
|
if (ENCODE_ODS(major_version, minor_version) >= fld[RFLD_F_ODS])
|
2009-10-22 16:50:23 +02:00
|
|
|
n++;
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
relation->rel_fields->resize(n);
|
2006-02-23 06:08:26 +01:00
|
|
|
format->fmt_count = n; // We are using less than the allocated members.
|
2001-05-23 15:26:42 +02:00
|
|
|
format->fmt_length = (USHORT)FLAG_BYTES(n);
|
2004-03-30 06:10:52 +02:00
|
|
|
Format::fmt_desc_iterator desc = format->fmt_desc.begin();
|
2008-12-20 09:12:19 +01:00
|
|
|
for (fld = relfld + RFLD_RPT; fld[RFLD_F_NAME]; fld += RFLD_F_LENGTH, ++desc)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
if (n-- > 0)
|
|
|
|
{
|
2009-11-27 07:57:17 +01:00
|
|
|
format->fmt_length = (USHORT) MET_align(&(*desc), format->fmt_length);
|
2004-01-21 08:18:30 +01:00
|
|
|
desc->dsc_address = (UCHAR*) (IPTR) format->fmt_length;
|
2001-05-23 15:26:42 +02:00
|
|
|
format->fmt_length += desc->dsc_length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-27 07:59:21 +01:00
|
|
|
static void add_index_set(Database* dbb)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* a d d _ i n d e x _ s e t
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
2004-01-28 08:50:41 +01:00
|
|
|
* Add system indices. If update_ods is true we are performing
|
2001-05-23 15:26:42 +02:00
|
|
|
* an ODS update, and only add the indices marked as newer than
|
|
|
|
* ODS (major_version,minor_version).
|
|
|
|
*
|
|
|
|
**************************************/
|
2005-05-12 20:28:04 +02:00
|
|
|
Firebird::MetaName string;
|
2004-03-28 11:10:30 +02:00
|
|
|
index_desc idx;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-05-22 16:28:54 +02:00
|
|
|
thread_db* tdbb = JRD_get_thread_data();
|
2004-03-20 15:57:40 +01:00
|
|
|
jrd_req* handle1 = NULL;
|
|
|
|
jrd_req* handle2 = NULL;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-12-03 09:19:24 +01:00
|
|
|
for (int n = 0; n < SYSTEM_INDEX_COUNT; n++)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2003-12-03 09:19:24 +01:00
|
|
|
const ini_idx_t* index = &indices[n];
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
STORE(REQUEST_HANDLE handle1) X IN RDB$INDICES
|
2004-01-28 08:50:41 +01:00
|
|
|
jrd_rel* relation = MET_relation(tdbb, index->ini_idx_relid);
|
2005-05-12 20:28:04 +02:00
|
|
|
PAD(relation->rel_name.c_str(), X.RDB$RELATION_NAME);
|
|
|
|
string.printf("RDB$INDEX_%d", index->ini_idx_index_id);
|
|
|
|
PAD(string.c_str(), X.RDB$INDEX_NAME);
|
2003-08-06 18:30:49 +02:00
|
|
|
X.RDB$UNIQUE_FLAG = index->ini_idx_flags & idx_unique;
|
2001-05-23 15:26:42 +02:00
|
|
|
X.RDB$SEGMENT_COUNT = index->ini_idx_segment_count;
|
2009-11-27 07:59:21 +01:00
|
|
|
if (index->ini_idx_flags & idx_descending)
|
|
|
|
{
|
2003-08-06 18:30:49 +02:00
|
|
|
X.RDB$INDEX_TYPE.NULL = FALSE;
|
|
|
|
X.RDB$INDEX_TYPE = 1;
|
2004-01-28 08:50:41 +01:00
|
|
|
}
|
|
|
|
else {
|
2003-08-06 18:30:49 +02:00
|
|
|
X.RDB$INDEX_TYPE.NULL = TRUE;
|
2004-01-28 08:50:41 +01:00
|
|
|
}
|
2009-12-03 13:52:10 +01:00
|
|
|
X.RDB$SYSTEM_FLAG = RDB_system;
|
2008-05-06 11:03:33 +02:00
|
|
|
X.RDB$SYSTEM_FLAG.NULL = FALSE;
|
2001-05-23 15:26:42 +02:00
|
|
|
X.RDB$INDEX_INACTIVE = 0;
|
|
|
|
|
2009-11-08 10:13:35 +01:00
|
|
|
// Store each segment for the index
|
2004-03-28 11:10:30 +02:00
|
|
|
index_desc::idx_repeat* tail = idx.idx_rpt;
|
2008-12-20 09:12:19 +01:00
|
|
|
for (USHORT position = 0; position < index->ini_idx_segment_count; position++, tail++)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2008-12-20 09:12:19 +01:00
|
|
|
const ini_idx_t::ini_idx_segment_t* segment = &index->ini_idx_segment[position];
|
2001-05-23 15:26:42 +02:00
|
|
|
STORE(REQUEST_HANDLE handle2) Y IN RDB$INDEX_SEGMENTS
|
2005-12-02 08:35:34 +01:00
|
|
|
jrd_fld* field = (*relation->rel_fields)[segment->ini_idx_rfld_id];
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
Y.RDB$FIELD_POSITION = position;
|
|
|
|
PAD(X.RDB$INDEX_NAME, Y.RDB$INDEX_NAME);
|
2005-05-12 20:28:04 +02:00
|
|
|
PAD(field->fld_name.c_str(), Y.RDB$FIELD_NAME);
|
2001-05-23 15:26:42 +02:00
|
|
|
tail->idx_field = segment->ini_idx_rfld_id;
|
|
|
|
tail->idx_itype = segment->ini_idx_type;
|
2004-08-12 02:31:29 +02:00
|
|
|
tail->idx_selectivity = 0;
|
2001-05-23 15:26:42 +02:00
|
|
|
END_STORE;
|
|
|
|
}
|
|
|
|
idx.idx_count = index->ini_idx_segment_count;
|
2003-08-06 18:30:49 +02:00
|
|
|
idx.idx_flags = index->ini_idx_flags;
|
2004-08-16 14:28:43 +02:00
|
|
|
SelectivityList selectivity(*tdbb->getDefaultPool());
|
2009-09-04 08:11:55 +02:00
|
|
|
IDX_create_index(tdbb, relation, &idx, string.c_str(), NULL, dbb->dbb_sys_trans, selectivity);
|
2001-05-23 15:26:42 +02:00
|
|
|
X.RDB$INDEX_ID = idx.idx_id + 1;
|
|
|
|
END_STORE;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (handle1) {
|
2004-08-21 11:39:37 +02:00
|
|
|
CMP_release(tdbb, handle1);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
if (handle2) {
|
2004-08-21 11:39:37 +02:00
|
|
|
CMP_release(tdbb, handle2);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-29 11:53:47 +01:00
|
|
|
// The caller used an UCHAR* to store the acl, it was converted to TEXT* to
|
|
|
|
// be passed to this function, only to be converted to UCHAR* to be passed
|
|
|
|
// to BLB_put_segment. Therefore, "acl" was changed to UCHAR* as param.
|
2004-03-11 06:04:26 +01:00
|
|
|
static void add_security_to_sys_rel(thread_db* tdbb,
|
2005-05-12 20:28:04 +02:00
|
|
|
const Firebird::MetaName& user_name,
|
2003-10-29 11:53:47 +01:00
|
|
|
const TEXT* rel_name,
|
|
|
|
const UCHAR* acl,
|
|
|
|
const SSHORT acl_length)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* a d d _ s e c u r i t y _ t o _ s y s _ r e l
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
*
|
2005-05-28 00:45:31 +02:00
|
|
|
* Add security to system relations. Only the owner of the
|
2001-05-23 15:26:42 +02:00
|
|
|
* database has SELECT/INSERT/UPDATE/DELETE privileges on
|
|
|
|
* any system relations. Any other users only has SELECT
|
|
|
|
* privilege.
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
TEXT sec_class_name[100];
|
2005-05-12 20:28:04 +02:00
|
|
|
Firebird::MetaName default_class;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
SET_TDBB(tdbb);
|
2007-12-03 16:46:39 +01:00
|
|
|
Database* dbb = tdbb->getDatabase();
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-03-28 11:10:30 +02:00
|
|
|
strcpy(sec_class_name, SQL_SECCLASS_PREFIX);
|
2001-05-23 15:26:42 +02:00
|
|
|
strcat(sec_class_name, rel_name);
|
|
|
|
|
2004-01-21 08:18:30 +01:00
|
|
|
bid blob_id_1;
|
|
|
|
blb* blob = BLB_create(tdbb, dbb->dbb_sys_trans, &blob_id_1);
|
2003-10-29 11:53:47 +01:00
|
|
|
BLB_put_segment(tdbb, blob, acl, acl_length);
|
2001-05-23 15:26:42 +02:00
|
|
|
BLB_close(tdbb, blob);
|
|
|
|
|
2004-01-21 08:18:30 +01:00
|
|
|
bid blob_id_2;
|
|
|
|
blob = BLB_create(tdbb, dbb->dbb_sys_trans, &blob_id_2);
|
2003-10-29 11:53:47 +01:00
|
|
|
BLB_put_segment(tdbb, blob, acl, acl_length);
|
2001-05-23 15:26:42 +02:00
|
|
|
BLB_close(tdbb, blob);
|
|
|
|
|
2006-05-04 02:02:58 +02:00
|
|
|
default_class.printf("%s%" SQUADFORMAT, DEFAULT_CLASS,
|
2008-12-20 09:12:19 +01:00
|
|
|
DPM_gen_id(tdbb, MET_lookup_generator(tdbb, DEFAULT_CLASS), false, 1));
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-08-26 13:03:31 +02:00
|
|
|
jrd_req* handle1 = NULL;
|
2004-02-24 06:34:44 +01:00
|
|
|
|
2003-12-03 09:19:24 +01:00
|
|
|
for (int cnt = 0; cnt < 6; cnt++)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
STORE(REQUEST_HANDLE handle1) PRIV IN RDB$USER_PRIVILEGES
|
2004-08-21 11:39:37 +02:00
|
|
|
switch (cnt)
|
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
case 0:
|
2005-05-12 20:28:04 +02:00
|
|
|
strcpy(PRIV.RDB$USER, user_name.c_str());
|
2001-05-23 15:26:42 +02:00
|
|
|
PRIV.RDB$PRIVILEGE[0] = 'S';
|
|
|
|
PRIV.RDB$GRANT_OPTION = 1;
|
|
|
|
break;
|
|
|
|
case 1:
|
2005-05-12 20:28:04 +02:00
|
|
|
strcpy(PRIV.RDB$USER, user_name.c_str());
|
2001-05-23 15:26:42 +02:00
|
|
|
PRIV.RDB$PRIVILEGE[0] = 'I';
|
|
|
|
PRIV.RDB$GRANT_OPTION = 1;
|
|
|
|
break;
|
|
|
|
case 2:
|
2005-05-12 20:28:04 +02:00
|
|
|
strcpy(PRIV.RDB$USER, user_name.c_str());
|
2001-05-23 15:26:42 +02:00
|
|
|
PRIV.RDB$PRIVILEGE[0] = 'U';
|
|
|
|
PRIV.RDB$GRANT_OPTION = 1;
|
|
|
|
break;
|
|
|
|
case 3:
|
2005-05-12 20:28:04 +02:00
|
|
|
strcpy(PRIV.RDB$USER, user_name.c_str());
|
2001-05-23 15:26:42 +02:00
|
|
|
PRIV.RDB$PRIVILEGE[0] = 'D';
|
|
|
|
PRIV.RDB$GRANT_OPTION = 1;
|
|
|
|
break;
|
|
|
|
case 4:
|
2005-05-12 20:28:04 +02:00
|
|
|
strcpy(PRIV.RDB$USER, user_name.c_str());
|
2001-05-23 15:26:42 +02:00
|
|
|
PRIV.RDB$PRIVILEGE[0] = 'R';
|
|
|
|
PRIV.RDB$GRANT_OPTION = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strcpy(PRIV.RDB$USER, "PUBLIC");
|
|
|
|
PRIV.RDB$PRIVILEGE[0] = 'S';
|
|
|
|
PRIV.RDB$GRANT_OPTION = 0;
|
|
|
|
break;
|
|
|
|
}
|
2005-05-12 20:28:04 +02:00
|
|
|
strcpy(PRIV.RDB$GRANTOR, user_name.c_str());
|
2001-05-23 15:26:42 +02:00
|
|
|
PRIV.RDB$PRIVILEGE[1] = 0;
|
|
|
|
strcpy(PRIV.RDB$RELATION_NAME, rel_name);
|
|
|
|
PRIV.RDB$FIELD_NAME.NULL = TRUE;
|
|
|
|
PRIV.RDB$USER_TYPE = obj_user;
|
|
|
|
PRIV.RDB$OBJECT_TYPE = obj_relation;
|
|
|
|
END_STORE;
|
|
|
|
}
|
2005-05-28 00:45:31 +02:00
|
|
|
|
2004-08-26 13:03:31 +02:00
|
|
|
CMP_release(tdbb, handle1);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
handle1 = NULL;
|
|
|
|
|
|
|
|
STORE(REQUEST_HANDLE handle1)
|
|
|
|
CLS IN RDB$SECURITY_CLASSES
|
2008-12-20 09:12:19 +01:00
|
|
|
jrd_vtof((char*)sec_class_name, CLS.RDB$SECURITY_CLASS, sizeof(CLS.RDB$SECURITY_CLASS));
|
2001-05-23 15:26:42 +02:00
|
|
|
CLS.RDB$ACL = blob_id_1;
|
|
|
|
END_STORE;
|
|
|
|
|
2004-08-21 11:39:37 +02:00
|
|
|
CMP_release(tdbb, handle1);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
handle1 = NULL;
|
|
|
|
|
|
|
|
STORE(REQUEST_HANDLE handle1)
|
|
|
|
CLS IN RDB$SECURITY_CLASSES
|
2008-12-20 09:12:19 +01:00
|
|
|
jrd_vtof(default_class.c_str(), CLS.RDB$SECURITY_CLASS, sizeof(CLS.RDB$SECURITY_CLASS));
|
2001-05-23 15:26:42 +02:00
|
|
|
CLS.RDB$ACL = blob_id_2;
|
|
|
|
END_STORE;
|
|
|
|
|
2004-08-21 11:39:37 +02:00
|
|
|
CMP_release(tdbb, handle1);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
handle1 = NULL;
|
|
|
|
|
|
|
|
FOR(REQUEST_HANDLE handle1) REL IN RDB$RELATIONS
|
|
|
|
WITH REL.RDB$RELATION_NAME EQ rel_name
|
|
|
|
MODIFY REL USING
|
|
|
|
REL.RDB$DEFAULT_CLASS.NULL = FALSE;
|
2008-12-20 09:12:19 +01:00
|
|
|
jrd_vtof(default_class.c_str(), REL.RDB$DEFAULT_CLASS, sizeof(REL.RDB$DEFAULT_CLASS));
|
2001-05-23 15:26:42 +02:00
|
|
|
END_MODIFY;
|
|
|
|
|
|
|
|
END_FOR;
|
|
|
|
|
2004-08-21 11:39:37 +02:00
|
|
|
CMP_release(tdbb, handle1);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-08-29 09:37:17 +02:00
|
|
|
|
2004-03-20 15:57:40 +01:00
|
|
|
static void store_generator(thread_db* tdbb, const gen* generator, jrd_req** handle)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* s t o r e _ g e n e r a t o r
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
2005-05-28 00:45:31 +02:00
|
|
|
* Store the passed generator according to
|
2001-05-23 15:26:42 +02:00
|
|
|
* the information in the generator block.
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
SET_TDBB(tdbb);
|
2007-12-03 16:46:39 +01:00
|
|
|
Database* dbb = tdbb->getDatabase();
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
STORE(REQUEST_HANDLE * handle) X IN RDB$GENERATORS
|
|
|
|
PAD(generator->gen_name, X.RDB$GENERATOR_NAME);
|
|
|
|
X.RDB$GENERATOR_ID = generator->gen_id;
|
|
|
|
X.RDB$SYSTEM_FLAG = RDB_system;
|
2008-05-06 11:03:33 +02:00
|
|
|
X.RDB$SYSTEM_FLAG.NULL = FALSE;
|
2004-10-30 07:23:31 +02:00
|
|
|
if (generator->gen_description)
|
|
|
|
{
|
2008-06-27 10:44:40 +02:00
|
|
|
blb* blob = BLB_create(tdbb, dbb->dbb_sys_trans, &X.RDB$DESCRIPTION);
|
2004-10-30 07:23:31 +02:00
|
|
|
BLB_put_segment(tdbb,
|
|
|
|
blob,
|
|
|
|
reinterpret_cast<const UCHAR*>(generator->gen_description),
|
|
|
|
strlen(generator->gen_description));
|
|
|
|
BLB_close(tdbb, blob);
|
|
|
|
X.RDB$DESCRIPTION.NULL = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
X.RDB$DESCRIPTION.NULL = TRUE;
|
|
|
|
}
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
END_STORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-20 15:57:40 +01:00
|
|
|
static void store_global_field(thread_db* tdbb, const gfld* gfield, jrd_req** handle)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* s t o r e _ g l o b a l _ f i e l d
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
2005-05-28 00:45:31 +02:00
|
|
|
* Store a global field according to the
|
2001-05-23 15:26:42 +02:00
|
|
|
* passed information.
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
SET_TDBB(tdbb);
|
2007-12-03 16:46:39 +01:00
|
|
|
Database* dbb = tdbb->getDatabase();
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
STORE(REQUEST_HANDLE * handle) X IN RDB$FIELDS
|
2004-01-21 08:18:30 +01:00
|
|
|
PAD(names[(USHORT)gfield->gfld_name], X.RDB$FIELD_NAME);
|
2001-05-23 15:26:42 +02:00
|
|
|
X.RDB$FIELD_LENGTH = gfield->gfld_length;
|
|
|
|
X.RDB$FIELD_SCALE = 0;
|
|
|
|
X.RDB$SYSTEM_FLAG = RDB_system;
|
2008-05-06 11:03:33 +02:00
|
|
|
X.RDB$SYSTEM_FLAG.NULL = FALSE;
|
2001-05-23 15:26:42 +02:00
|
|
|
X.RDB$FIELD_SUB_TYPE.NULL = TRUE;
|
|
|
|
X.RDB$CHARACTER_SET_ID.NULL = TRUE;
|
|
|
|
X.RDB$COLLATION_ID.NULL = TRUE;
|
|
|
|
X.RDB$SEGMENT_LENGTH.NULL = TRUE;
|
2009-11-28 17:39:54 +01:00
|
|
|
X.RDB$CHARACTER_LENGTH.NULL = TRUE;
|
2001-05-23 15:26:42 +02:00
|
|
|
if (gfield->gfld_dflt_blr)
|
|
|
|
{
|
2008-06-27 10:44:40 +02:00
|
|
|
blb* blob = BLB_create(tdbb, dbb->dbb_sys_trans, &X.RDB$DEFAULT_VALUE);
|
2001-05-23 15:26:42 +02:00
|
|
|
BLB_put_segment(tdbb,
|
|
|
|
blob,
|
2003-12-03 09:19:24 +01:00
|
|
|
gfield->gfld_dflt_blr,
|
2001-05-23 15:26:42 +02:00
|
|
|
gfield->gfld_dflt_len);
|
|
|
|
BLB_close(tdbb, blob);
|
|
|
|
X.RDB$DEFAULT_VALUE.NULL = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
X.RDB$DEFAULT_VALUE.NULL = TRUE;
|
|
|
|
}
|
|
|
|
switch (gfield->gfld_dtype)
|
|
|
|
{
|
|
|
|
case dtype_timestamp:
|
|
|
|
X.RDB$FIELD_TYPE = (int) blr_timestamp;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_sql_time:
|
|
|
|
X.RDB$FIELD_TYPE = (int) blr_sql_time;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_sql_date:
|
|
|
|
X.RDB$FIELD_TYPE = (int) blr_sql_date;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_short:
|
|
|
|
case dtype_long:
|
|
|
|
case dtype_int64:
|
|
|
|
if (gfield->gfld_dtype == dtype_short)
|
|
|
|
X.RDB$FIELD_TYPE = (int) blr_short;
|
|
|
|
else if (gfield->gfld_dtype == dtype_long)
|
|
|
|
X.RDB$FIELD_TYPE = (int) blr_long;
|
|
|
|
else
|
2007-02-12 11:01:45 +01:00
|
|
|
{
|
|
|
|
// Workaround to allow fld_counter domain
|
|
|
|
// in dialect 1 databases
|
|
|
|
if (dbb->dbb_flags & DBB_DB_SQL_dialect_3)
|
|
|
|
X.RDB$FIELD_TYPE = (int) blr_int64;
|
|
|
|
else
|
|
|
|
X.RDB$FIELD_TYPE = (int) blr_double;
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
if ((gfield->gfld_sub_type == dsc_num_type_numeric) ||
|
|
|
|
(gfield->gfld_sub_type == dsc_num_type_decimal))
|
|
|
|
{
|
|
|
|
X.RDB$FIELD_SUB_TYPE.NULL = FALSE;
|
|
|
|
X.RDB$FIELD_SUB_TYPE = gfield->gfld_sub_type;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_double:
|
|
|
|
X.RDB$FIELD_TYPE = (int) blr_double;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_text:
|
|
|
|
case dtype_varying:
|
|
|
|
if (gfield->gfld_dtype == dtype_text)
|
|
|
|
{
|
|
|
|
X.RDB$FIELD_TYPE = (int) blr_text;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
X.RDB$FIELD_TYPE = (int) blr_varying;
|
|
|
|
}
|
2008-05-06 11:03:33 +02:00
|
|
|
switch (gfield->gfld_sub_type)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2008-05-06 11:03:33 +02:00
|
|
|
case dsc_text_type_metadata:
|
2001-05-23 15:26:42 +02:00
|
|
|
X.RDB$CHARACTER_SET_ID.NULL = FALSE;
|
|
|
|
X.RDB$CHARACTER_SET_ID = CS_METADATA;
|
|
|
|
X.RDB$COLLATION_ID.NULL = FALSE;
|
|
|
|
X.RDB$COLLATION_ID = COLLATE_NONE;
|
|
|
|
X.RDB$FIELD_SUB_TYPE.NULL = FALSE;
|
|
|
|
X.RDB$FIELD_SUB_TYPE = gfield->gfld_sub_type;
|
2009-11-28 17:39:54 +01:00
|
|
|
X.RDB$CHARACTER_LENGTH.NULL = FALSE;
|
|
|
|
X.RDB$CHARACTER_LENGTH = X.RDB$FIELD_LENGTH / METADATA_BYTES_PER_CHAR;
|
2008-05-06 11:03:33 +02:00
|
|
|
break;
|
|
|
|
case dsc_text_type_ascii:
|
2006-07-18 09:08:52 +02:00
|
|
|
X.RDB$CHARACTER_SET_ID.NULL = FALSE;
|
|
|
|
X.RDB$CHARACTER_SET_ID = CS_ASCII;
|
|
|
|
X.RDB$COLLATION_ID.NULL = FALSE;
|
|
|
|
X.RDB$COLLATION_ID = COLLATE_NONE;
|
|
|
|
X.RDB$FIELD_SUB_TYPE.NULL = FALSE;
|
|
|
|
X.RDB$FIELD_SUB_TYPE = gfield->gfld_sub_type;
|
2008-05-06 11:03:33 +02:00
|
|
|
break;
|
|
|
|
case dsc_text_type_fixed:
|
2003-09-19 15:56:48 +02:00
|
|
|
X.RDB$CHARACTER_SET_ID.NULL = FALSE;
|
|
|
|
X.RDB$CHARACTER_SET_ID = CS_BINARY;
|
|
|
|
X.RDB$COLLATION_ID.NULL = FALSE;
|
|
|
|
X.RDB$COLLATION_ID = COLLATE_NONE;
|
|
|
|
X.RDB$FIELD_SUB_TYPE.NULL = FALSE;
|
|
|
|
X.RDB$FIELD_SUB_TYPE = gfield->gfld_sub_type;
|
2008-05-06 11:03:33 +02:00
|
|
|
break;
|
|
|
|
default:
|
2001-05-23 15:26:42 +02:00
|
|
|
X.RDB$CHARACTER_SET_ID.NULL = FALSE;
|
|
|
|
X.RDB$CHARACTER_SET_ID = CS_NONE;
|
|
|
|
X.RDB$COLLATION_ID.NULL = FALSE;
|
|
|
|
X.RDB$COLLATION_ID = COLLATE_NONE;
|
2008-05-06 11:03:33 +02:00
|
|
|
break;
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_blob:
|
|
|
|
X.RDB$FIELD_TYPE = (int) blr_blob;
|
|
|
|
X.RDB$FIELD_SUB_TYPE.NULL = FALSE;
|
|
|
|
X.RDB$SEGMENT_LENGTH.NULL = FALSE;
|
|
|
|
X.RDB$FIELD_SUB_TYPE = gfield->gfld_sub_type;
|
|
|
|
X.RDB$SEGMENT_LENGTH = 80;
|
2004-04-29 19:48:39 +02:00
|
|
|
if (gfield->gfld_sub_type == isc_blob_text)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
X.RDB$CHARACTER_SET_ID.NULL = FALSE;
|
|
|
|
X.RDB$CHARACTER_SET_ID = CS_METADATA;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(FALSE);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-12-20 09:12:19 +01:00
|
|
|
|
2009-12-03 13:52:10 +01:00
|
|
|
// Acknowledge not NULL sys fields
|
2008-05-06 11:03:33 +02:00
|
|
|
X.RDB$NULL_FLAG.NULL = FALSE;
|
2009-12-03 13:52:10 +01:00
|
|
|
X.RDB$NULL_FLAG = !gfield->gfld_nullable;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
END_STORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-11 06:04:26 +01:00
|
|
|
static void store_intlnames(thread_db* tdbb, Database* dbb)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
2005-05-28 00:45:31 +02:00
|
|
|
* s t o r e _ i n t l n a m e s
|
2001-05-23 15:26:42 +02:00
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Store symbolic names & information for international
|
|
|
|
* character sets & collations.
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
SET_TDBB(tdbb);
|
|
|
|
|
2004-03-20 15:57:40 +01:00
|
|
|
jrd_req* handle = NULL;
|
2008-01-16 10:07:24 +01:00
|
|
|
|
|
|
|
for (const IntlManager::CharSetDefinition* charSet = IntlManager::defaultCharSets;
|
|
|
|
charSet->name; ++charSet)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
STORE(REQUEST_HANDLE handle) X IN RDB$CHARACTER_SETS USING
|
2008-01-16 10:07:24 +01:00
|
|
|
PAD(charSet->name, X.RDB$CHARACTER_SET_NAME);
|
|
|
|
PAD(charSet->name, X.RDB$DEFAULT_COLLATE_NAME);
|
|
|
|
X.RDB$CHARACTER_SET_ID = charSet->id;
|
|
|
|
X.RDB$BYTES_PER_CHARACTER = charSet->maxBytes;
|
2001-05-23 15:26:42 +02:00
|
|
|
X.RDB$SYSTEM_FLAG = RDB_system;
|
2008-05-06 11:03:33 +02:00
|
|
|
X.RDB$SYSTEM_FLAG.NULL = FALSE;
|
2001-05-23 15:26:42 +02:00
|
|
|
END_STORE;
|
|
|
|
}
|
|
|
|
|
2004-08-21 11:39:37 +02:00
|
|
|
CMP_release(tdbb, handle);
|
2001-05-23 15:26:42 +02:00
|
|
|
handle = NULL;
|
|
|
|
|
2008-01-16 10:07:24 +01:00
|
|
|
for (const IntlManager::CollationDefinition* collation = IntlManager::defaultCollations;
|
|
|
|
collation->name; ++collation)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
STORE(REQUEST_HANDLE handle) X IN RDB$COLLATIONS USING
|
2008-01-16 10:07:24 +01:00
|
|
|
PAD(collation->name, X.RDB$COLLATION_NAME);
|
2006-09-17 22:06:36 +02:00
|
|
|
|
2008-01-16 10:07:24 +01:00
|
|
|
if (collation->baseName)
|
2006-09-17 22:06:36 +02:00
|
|
|
{
|
|
|
|
X.RDB$BASE_COLLATION_NAME.NULL = false;
|
2008-01-16 10:07:24 +01:00
|
|
|
PAD(collation->baseName, X.RDB$BASE_COLLATION_NAME);
|
2006-09-17 22:06:36 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
X.RDB$BASE_COLLATION_NAME.NULL = true;
|
|
|
|
|
2008-01-16 10:07:24 +01:00
|
|
|
X.RDB$CHARACTER_SET_ID = collation->charSetId;
|
|
|
|
X.RDB$COLLATION_ID = collation->collationId;
|
2001-05-23 15:26:42 +02:00
|
|
|
X.RDB$SYSTEM_FLAG = RDB_system;
|
2008-05-06 11:03:33 +02:00
|
|
|
X.RDB$SYSTEM_FLAG.NULL = FALSE;
|
2008-01-16 10:07:24 +01:00
|
|
|
X.RDB$COLLATION_ATTRIBUTES = collation->attributes;
|
2007-04-06 04:10:10 +02:00
|
|
|
|
2008-01-16 10:07:24 +01:00
|
|
|
if (collation->specificAttributes)
|
2007-04-06 04:10:10 +02:00
|
|
|
{
|
2008-06-27 10:44:40 +02:00
|
|
|
blb* blob = BLB_create(tdbb, dbb->dbb_sys_trans, &X.RDB$SPECIFIC_ATTRIBUTES);
|
2007-04-06 04:10:10 +02:00
|
|
|
BLB_put_segment(tdbb,
|
|
|
|
blob,
|
2008-01-16 10:07:24 +01:00
|
|
|
reinterpret_cast<const UCHAR*>(collation->specificAttributes),
|
|
|
|
strlen(collation->specificAttributes));
|
2007-04-06 04:10:10 +02:00
|
|
|
BLB_close(tdbb, blob);
|
|
|
|
X.RDB$SPECIFIC_ATTRIBUTES.NULL = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
X.RDB$SPECIFIC_ATTRIBUTES.NULL = TRUE;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
END_STORE;
|
|
|
|
}
|
|
|
|
|
2004-08-21 11:39:37 +02:00
|
|
|
CMP_release(tdbb, handle);
|
2001-05-23 15:26:42 +02:00
|
|
|
handle = NULL;
|
|
|
|
}
|
|
|
|
|
2008-12-20 09:12:19 +01:00
|
|
|
|
2004-03-20 15:57:40 +01:00
|
|
|
static void store_message(thread_db* tdbb, const trigger_msg* message, jrd_req** handle)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* s t o r e _ m e s s a g e
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Store system trigger messages.
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
SET_TDBB(tdbb);
|
2007-12-03 16:46:39 +01:00
|
|
|
Database* dbb = tdbb->getDatabase();
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-11-08 10:13:35 +01:00
|
|
|
// store the trigger
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
STORE(REQUEST_HANDLE * handle) X IN RDB$TRIGGER_MESSAGES
|
|
|
|
PAD(message->trigmsg_name, X.RDB$TRIGGER_NAME);
|
|
|
|
X.RDB$MESSAGE_NUMBER = message->trigmsg_number;
|
|
|
|
PAD(message->trigmsg_text, X.RDB$MESSAGE);
|
|
|
|
END_STORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-11 06:04:26 +01:00
|
|
|
static void store_relation_field(thread_db* tdbb,
|
2006-07-17 19:44:18 +02:00
|
|
|
const int* fld,
|
|
|
|
const int* relfld,
|
2001-05-23 15:26:42 +02:00
|
|
|
int field_id,
|
2009-10-22 16:50:23 +02:00
|
|
|
jrd_req** handle)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* s t o r e _ r e l a t i o n _ f i e l d
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
2005-05-28 00:45:31 +02:00
|
|
|
* Store a local field according to the
|
2001-05-23 15:26:42 +02:00
|
|
|
* passed information.
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
SET_TDBB(tdbb);
|
2007-12-03 16:46:39 +01:00
|
|
|
Database* dbb = tdbb->getDatabase();
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
STORE(REQUEST_HANDLE * handle) X IN RDB$RELATION_FIELDS
|
2009-10-22 16:50:23 +02:00
|
|
|
const gfld* gfield = &gfields[fld[RFLD_F_ID]];
|
2001-05-23 15:26:42 +02:00
|
|
|
PAD(names[relfld[RFLD_R_NAME]], X.RDB$RELATION_NAME);
|
|
|
|
PAD(names[fld[RFLD_F_NAME]], X.RDB$FIELD_NAME);
|
|
|
|
PAD(names[gfield->gfld_name], X.RDB$FIELD_SOURCE);
|
|
|
|
X.RDB$FIELD_POSITION = field_id;
|
|
|
|
X.RDB$FIELD_ID = field_id;
|
|
|
|
X.RDB$SYSTEM_FLAG = RDB_system;
|
2008-05-06 11:03:33 +02:00
|
|
|
X.RDB$SYSTEM_FLAG.NULL = FALSE;
|
2001-05-23 15:26:42 +02:00
|
|
|
X.RDB$UPDATE_FLAG = fld[RFLD_F_UPDATE];
|
|
|
|
END_STORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-20 15:57:40 +01:00
|
|
|
static void store_trigger(thread_db* tdbb, const jrd_trg* trigger, jrd_req** handle)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* s t o r e _ t r i g g e r
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
2005-05-28 00:45:31 +02:00
|
|
|
* Store the trigger according to the
|
2001-05-23 15:26:42 +02:00
|
|
|
* information in the trigger block.
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
SET_TDBB(tdbb);
|
2007-12-03 16:46:39 +01:00
|
|
|
Database* dbb = tdbb->getDatabase();
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-11-08 10:13:35 +01:00
|
|
|
// indicate that the relation format needs revising
|
2003-12-03 09:19:24 +01:00
|
|
|
dsc desc;
|
2009-11-28 20:39:23 +01:00
|
|
|
desc.makeText(strlen(names[trigger->trg_relation]), CS_METADATA,
|
|
|
|
(UCHAR*) names[trigger->trg_relation]);
|
2008-06-27 10:44:40 +02:00
|
|
|
DFW_post_system_work(tdbb, dfw_update_format, &desc, 0);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-11-08 10:13:35 +01:00
|
|
|
// store the trigger
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
STORE(REQUEST_HANDLE * handle) X IN RDB$TRIGGERS
|
|
|
|
PAD(trigger->trg_name, X.RDB$TRIGGER_NAME);
|
|
|
|
PAD(names[trigger->trg_relation], X.RDB$RELATION_NAME);
|
|
|
|
X.RDB$TRIGGER_SEQUENCE = 0;
|
|
|
|
X.RDB$SYSTEM_FLAG = RDB_system;
|
2008-05-06 11:03:33 +02:00
|
|
|
X.RDB$SYSTEM_FLAG.NULL = FALSE;
|
2001-05-23 15:26:42 +02:00
|
|
|
X.RDB$TRIGGER_TYPE = trigger->trg_type;
|
|
|
|
X.RDB$FLAGS = trigger->trg_flags;
|
2008-06-27 10:44:40 +02:00
|
|
|
blb* blob = BLB_create(tdbb, dbb->dbb_sys_trans, &X.RDB$TRIGGER_BLR);
|
2008-12-20 09:12:19 +01:00
|
|
|
BLB_put_segment(tdbb, blob, trigger->trg_blr, trigger->trg_length);
|
2001-05-23 15:26:42 +02:00
|
|
|
BLB_close(tdbb, blob);
|
|
|
|
END_STORE;
|
2001-07-12 08:32:05 +02:00
|
|
|
}
|