From: <asf...@us...> - 2011-11-27 19:08:15
|
Revision: 53645 http://firebird.svn.sourceforge.net/firebird/?rev=53645&view=rev Author: asfernandes Date: 2011-11-27 19:08:06 +0000 (Sun, 27 Nov 2011) Log Message: ----------- Refactored CREATE FILTER and CREATE INDEX. Modified Paths: -------------- firebird/trunk/builds/win32/msvc10/engine.vcxproj firebird/trunk/builds/win32/msvc10/engine.vcxproj.filters firebird/trunk/builds/win32/msvc8/engine.vcproj firebird/trunk/builds/win32/msvc9/engine.vcproj firebird/trunk/builds/win32/preprocess.bat firebird/trunk/lang_helpers/gds_codes.ftn firebird/trunk/lang_helpers/gds_codes.pas firebird/trunk/src/dsql/DdlNodes.epp firebird/trunk/src/dsql/DdlNodes.h firebird/trunk/src/dsql/ddl.cpp firebird/trunk/src/dsql/metd.epp firebird/trunk/src/dsql/metd_proto.h firebird/trunk/src/dsql/node.h firebird/trunk/src/dsql/parse.y firebird/trunk/src/dsql/pass1.cpp firebird/trunk/src/include/gen/codetext.h firebird/trunk/src/include/gen/iberror.h firebird/trunk/src/include/gen/msgs.h firebird/trunk/src/include/gen/sql_code.h firebird/trunk/src/include/gen/sql_state.h firebird/trunk/src/jrd/dyn.epp firebird/trunk/src/jrd/dyn.h firebird/trunk/src/msgs/facilities2.sql firebird/trunk/src/msgs/messages2.sql firebird/trunk/src/msgs/system_errors2.sql Removed Paths: ------------- firebird/trunk/src/jrd/dyn_def.epp firebird/trunk/src/jrd/dyn_df_proto.h Modified: firebird/trunk/builds/win32/msvc10/engine.vcxproj =================================================================== --- firebird/trunk/builds/win32/msvc10/engine.vcxproj 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/builds/win32/msvc10/engine.vcxproj 2011-11-27 19:08:06 UTC (rev 53645) @@ -25,7 +25,6 @@ <ClCompile Include="..\..\..\gen\jrd\dfw.cpp" /> <ClCompile Include="..\..\..\gen\jrd\dpm.cpp" /> <ClCompile Include="..\..\..\gen\jrd\dyn.cpp" /> - <ClCompile Include="..\..\..\gen\jrd\dyn_def.cpp" /> <ClCompile Include="..\..\..\gen\jrd\dyn_util.cpp" /> <ClCompile Include="..\..\..\gen\jrd\fun.cpp" /> <ClCompile Include="..\..\..\gen\jrd\Function.cpp" /> @@ -217,7 +216,6 @@ <ClInclude Include="..\..\..\src\jrd\dpm_proto.h" /> <ClInclude Include="..\..\..\src\jrd\drq.h" /> <ClInclude Include="..\..\..\src\jrd\dyn.h" /> - <ClInclude Include="..\..\..\src\jrd\dyn_df_proto.h" /> <ClInclude Include="..\..\..\src\jrd\dyn_proto.h" /> <ClInclude Include="..\..\..\src\jrd\dyn_ut_proto.h" /> <ClInclude Include="..\..\..\src\jrd\ErrorImpl.h" /> @@ -348,7 +346,6 @@ <None Include="..\..\..\src\jrd\dfw.epp" /> <None Include="..\..\..\src\jrd\dpm.epp" /> <None Include="..\..\..\src\jrd\dyn.epp" /> - <None Include="..\..\..\src\jrd\dyn_def.epp" /> <None Include="..\..\..\src\jrd\dyn_util.epp" /> <None Include="..\..\..\src\jrd\fun.epp" /> <None Include="..\..\..\src\jrd\Function.epp" /> Modified: firebird/trunk/builds/win32/msvc10/engine.vcxproj.filters =================================================================== --- firebird/trunk/builds/win32/msvc10/engine.vcxproj.filters 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/builds/win32/msvc10/engine.vcxproj.filters 2011-11-27 19:08:06 UTC (rev 53645) @@ -414,9 +414,6 @@ <ClCompile Include="..\..\..\gen\jrd\dyn.cpp"> <Filter>JRD files\GPRE cpp</Filter> </ClCompile> - <ClCompile Include="..\..\..\gen\jrd\dyn_def.cpp"> - <Filter>JRD files\GPRE cpp</Filter> - </ClCompile> <ClCompile Include="..\..\..\gen\jrd\dyn_util.cpp"> <Filter>JRD files\GPRE cpp</Filter> </ClCompile> @@ -677,9 +674,6 @@ <ClInclude Include="..\..\..\src\jrd\dyn.h"> <Filter>Header files</Filter> </ClInclude> - <ClInclude Include="..\..\..\src\jrd\dyn_df_proto.h"> - <Filter>Header files</Filter> - </ClInclude> <ClInclude Include="..\..\..\src\jrd\dyn_proto.h"> <Filter>Header files</Filter> </ClInclude> @@ -1012,9 +1006,6 @@ <None Include="..\..\..\src\jrd\dyn.epp"> <Filter>JRD files\GPRE files</Filter> </None> - <None Include="..\..\..\src\jrd\dyn_def.epp"> - <Filter>JRD files\GPRE files</Filter> - </None> <None Include="..\..\..\src\jrd\dyn_util.epp"> <Filter>JRD files\GPRE files</Filter> </None> Modified: firebird/trunk/builds/win32/msvc8/engine.vcproj =================================================================== --- firebird/trunk/builds/win32/msvc8/engine.vcproj 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/builds/win32/msvc8/engine.vcproj 2011-11-27 19:08:06 UTC (rev 53645) @@ -727,10 +727,6 @@ > </File> <File - RelativePath="..\..\..\gen\jrd\dyn_def.cpp" - > - </File> - <File RelativePath="..\..\..\gen\jrd\dyn_del.cpp" > </File> @@ -783,10 +779,6 @@ > </File> <File - RelativePath="..\..\..\src\jrd\dyn_def.epp" - > - </File> - <File RelativePath="..\..\..\src\jrd\dyn_del.epp" > </File> @@ -1032,10 +1024,6 @@ > </File> <File - RelativePath="..\..\..\src\jrd\dyn_df_proto.h" - > - </File> - <File RelativePath="..\..\..\src\jrd\dyn_dl_proto.h" > </File> Modified: firebird/trunk/builds/win32/msvc9/engine.vcproj =================================================================== --- firebird/trunk/builds/win32/msvc9/engine.vcproj 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/builds/win32/msvc9/engine.vcproj 2011-11-27 19:08:06 UTC (rev 53645) @@ -727,10 +727,6 @@ > </File> <File - RelativePath="..\..\..\gen\jrd\dyn_def.cpp" - > - </File> - <File RelativePath="..\..\..\gen\jrd\dyn_util.cpp" > </File> @@ -779,10 +775,6 @@ > </File> <File - RelativePath="..\..\..\src\jrd\dyn_def.epp" - > - </File> - <File RelativePath="..\..\..\src\jrd\dyn_util.epp" > </File> @@ -1024,10 +1016,6 @@ > </File> <File - RelativePath="..\..\..\src\jrd\dyn_df_proto.h" - > - </File> - <File RelativePath="..\..\..\src\jrd\dyn_proto.h" > </File> Modified: firebird/trunk/builds/win32/preprocess.bat =================================================================== --- firebird/trunk/builds/win32/preprocess.bat 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/builds/win32/preprocess.bat 2011-11-27 19:08:06 UTC (rev 53645) @@ -67,7 +67,7 @@ @for %%i in (array, blob) do @call :PREPROCESS yvalve %%i @for %%i in (metd, DdlNodes, PackageNodes) do @call :PREPROCESS dsql %%i -gds_cxx @for %%i in (gpre_meta) do @call :PREPROCESS gpre/std %%i -@for %%i in (dfw, dpm, dyn, dyn_def, dyn_util, fun, grant, ini, met, pcmet, scl, Function) do @call :PREPROCESS jrd %%i -gds_cxx +@for %%i in (dfw, dpm, dyn, dyn_util, fun, grant, ini, met, pcmet, scl, Function) do @call :PREPROCESS jrd %%i -gds_cxx @for %%i in (stats) do @call :PREPROCESS utilities %%i @goto :EOF @@ -81,7 +81,7 @@ @for %%i in (metd) do @call :PREPROCESS dsql %%i -gds_cxx @for %%i in (DdlNodes, PackageNodes) do @call :PREPROCESS dsql %%i -gds_cxx @for %%i in (gpre_meta) do @call :PREPROCESS gpre/std %%i -@for %%i in (dfw, dpm, dyn, dyn_def, dyn_util, fun, grant, ini, met, pcmet, scl, Function) do @call :PREPROCESS jrd %%i -gds_cxx +@for %%i in (dfw, dpm, dyn, dyn_util, fun, grant, ini, met, pcmet, scl, Function) do @call :PREPROCESS jrd %%i -gds_cxx @for %%i in (codes) do @call :PREPROCESS misc %%i @for %%i in (build_file) do @call :PREPROCESS msgs %%i @for %%i in (help, meta, proc, show) do @call :PREPROCESS qli %%i Modified: firebird/trunk/lang_helpers/gds_codes.ftn =================================================================== --- firebird/trunk/lang_helpers/gds_codes.ftn 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/lang_helpers/gds_codes.ftn 2011-11-27 19:08:06 UTC (rev 53645) @@ -2138,6 +2138,10 @@ PARAMETER (GDS__dsql_alter_database_failed = 336397313) INTEGER*4 GDS__dsql_create_shadow_failed PARAMETER (GDS__dsql_create_shadow_failed = 336397314) + INTEGER*4 GDS__dsql_create_filter_failed + PARAMETER (GDS__dsql_create_filter_failed = 336397315) + INTEGER*4 GDS__dsql_create_index_failed + PARAMETER (GDS__dsql_create_index_failed = 336397316) INTEGER*4 GDS__gsec_cant_open_db PARAMETER (GDS__gsec_cant_open_db = 336723983) INTEGER*4 GDS__gsec_switches_error Modified: firebird/trunk/lang_helpers/gds_codes.pas =================================================================== --- firebird/trunk/lang_helpers/gds_codes.pas 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/lang_helpers/gds_codes.pas 2011-11-27 19:08:06 UTC (rev 53645) @@ -1076,6 +1076,8 @@ gds_dsql_alter_index_failed = 336397312; gds_dsql_alter_database_failed = 336397313; gds_dsql_create_shadow_failed = 336397314; + gds_dsql_create_filter_failed = 336397315; + gds_dsql_create_index_failed = 336397316; gds_gsec_cant_open_db = 336723983; gds_gsec_switches_error = 336723984; gds_gsec_no_op_spec = 336723985; Modified: firebird/trunk/src/dsql/DdlNodes.epp =================================================================== --- firebird/trunk/src/dsql/DdlNodes.epp 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/src/dsql/DdlNodes.epp 2011-11-27 19:08:06 UTC (rev 53645) @@ -34,6 +34,7 @@ #include "../jrd/jrd.h" #include "../jrd/msg_encode.h" #include "../jrd/obj.h" +#include "../jrd/ods.h" #include "../jrd/tra.h" #include "../common/os/path_utils.h" #include "../jrd/IntlManager.h" @@ -92,6 +93,8 @@ static void checkViewDependency(thread_db* tdbb, jrd_tra* transaction, const MetaName& relationName, const MetaName& fieldName); static void clearPermanentField(dsql_rel* relation, bool permanent); +static void defineComputed(DsqlCompilerScratch* dsqlScratch, dsql_nod* relation, dsql_fld* field, + dsql_nod* node, string& source, BlrWriter::BlrData& value); static void deleteKeyConstraint(thread_db* tdbb, jrd_tra* transaction, const MetaName& relationName, const MetaName& constraintName, const MetaName& indexName); static void defineFile(thread_db* tdbb, jrd_tra* transaction, SLONG shadowNumber, bool manualShadow, @@ -286,6 +289,94 @@ } } +// Define a COMPUTED BY clause, for a field or an index. +void defineComputed(DsqlCompilerScratch* dsqlScratch, dsql_nod* relation, dsql_fld* field, + dsql_nod* node, string& source, BlrWriter::BlrData& value) +{ + AutoSetRestore2<dsql_nod*, DsqlCompiledStatement> autoDdlNode(dsqlScratch->getStatement(), + &DsqlCompiledStatement::getDdlNode, &DsqlCompiledStatement::setDdlNode, node); + + // Get the table node and set up correct context. + DDL_reset_context_stack(dsqlScratch); + + // Save the size of the field if it is specified. + dsc saveDesc; + saveDesc.dsc_dtype = 0; + + if (field && field->fld_dtype) + { + fb_assert(field->fld_dtype <= MAX_UCHAR); + saveDesc.dsc_dtype = (UCHAR) field->fld_dtype; + saveDesc.dsc_length = field->fld_length; + fb_assert(field->fld_scale <= MAX_SCHAR); + saveDesc.dsc_scale = (SCHAR) field->fld_scale; + saveDesc.dsc_sub_type = field->fld_sub_type; + + field->fld_dtype = 0; + field->fld_length = 0; + field->fld_scale = 0; + field->fld_sub_type = 0; + } + + PASS1_make_context(dsqlScratch, relation); + + dsql_nod* input = PASS1_node(dsqlScratch, node->nod_arg[Dsql::e_cmp_expr]); + + // Try to calculate size of the computed field. The calculated size + // may be ignored, but it will catch self references. + dsc desc; + MAKE_desc(dsqlScratch, &desc, input); + + // Generate the blr expression. + + dsqlScratch->getBlrData().clear(); + dsqlScratch->getDebugData().clear(); + dsqlScratch->appendUChar(dsqlScratch->isVersion4() ? blr_version4 : blr_version5); + + GEN_expr(dsqlScratch, input); + dsqlScratch->appendUChar(blr_eoc); + + if (saveDesc.dsc_dtype) + { + // Restore the field size/type overrides. + field->fld_dtype = saveDesc.dsc_dtype; + field->fld_length = saveDesc.dsc_length; + field->fld_scale = saveDesc.dsc_scale; + + if (field->fld_dtype <= dtype_any_text) + { + field->fld_character_set_id = DSC_GET_CHARSET(&saveDesc); + field->fld_collation_id= DSC_GET_COLLATE(&saveDesc); + } + else + field->fld_sub_type = saveDesc.dsc_sub_type; + } + else if (field) + { + // Use size calculated. + field->fld_dtype = desc.dsc_dtype; + field->fld_length = desc.dsc_length; + field->fld_scale = desc.dsc_scale; + + if (field->fld_dtype <= dtype_any_text) + { + field->fld_character_set_id = DSC_GET_CHARSET(&desc); + field->fld_collation_id = DSC_GET_COLLATE(&desc); + } + else + field->fld_sub_type = desc.dsc_sub_type; + } + + DDL_reset_context_stack(dsqlScratch); + + // Generate the source text. + const dsql_str* sourceStr = (dsql_str*) node->nod_arg[Dsql::e_cmp_text]; + fb_assert(sourceStr->str_length <= MAX_USHORT); + source = string(sourceStr->str_data, sourceStr->str_length); + + value.assign(dsqlScratch->getBlrData()); +} + // Delete a record from RDB$RELATION_CONSTRAINTS based on a constraint name. // // On deleting from RDB$RELATION_CONSTRAINTS, 2 system triggers fire: @@ -5357,7 +5448,7 @@ { field->fld_flags |= FLD_computed; - defineComputed(tdbb, dsqlScratch, field, element->nod_arg[e_dfl_computed], + defineComputed(dsqlScratch, dsqlNode, field, element->nod_arg[e_dfl_computed], computedSource, computedValue); } @@ -5443,94 +5534,6 @@ clearPermanentField(relation, permanent); } -// Define a COMPUTED BY clause. -void RelationNode::defineComputed(thread_db* /*tdbb*/, DsqlCompilerScratch* dsqlScratch, - dsql_fld* field, dsql_nod* node, string& source, BlrWriter::BlrData& value) -{ - AutoSetRestore2<dsql_nod*, DsqlCompiledStatement> autoDdlNode(dsqlScratch->getStatement(), - &DsqlCompiledStatement::getDdlNode, &DsqlCompiledStatement::setDdlNode, node); - - // Get the table node and set up correct context. - DDL_reset_context_stack(dsqlScratch); - - // Save the size of the field if it is specified. - dsc saveDesc; - saveDesc.dsc_dtype = 0; - - if (field && field->fld_dtype) - { - fb_assert(field->fld_dtype <= MAX_UCHAR); - saveDesc.dsc_dtype = (UCHAR) field->fld_dtype; - saveDesc.dsc_length = field->fld_length; - fb_assert(field->fld_scale <= MAX_SCHAR); - saveDesc.dsc_scale = (SCHAR) field->fld_scale; - saveDesc.dsc_sub_type = field->fld_sub_type; - - field->fld_dtype = 0; - field->fld_length = 0; - field->fld_scale = 0; - field->fld_sub_type = 0; - } - - PASS1_make_context(dsqlScratch, dsqlNode); - - dsql_nod* input = PASS1_node(dsqlScratch, node->nod_arg[Dsql::e_cmp_expr]); - - // Try to calculate size of the computed field. The calculated size - // may be ignored, but it will catch self references. - dsc desc; - MAKE_desc(dsqlScratch, &desc, input); - - // Generate the blr expression. - - dsqlScratch->getBlrData().clear(); - dsqlScratch->getDebugData().clear(); - dsqlScratch->appendUChar(dsqlScratch->isVersion4() ? blr_version4 : blr_version5); - - GEN_expr(dsqlScratch, input); - dsqlScratch->appendUChar(blr_eoc); - - if (saveDesc.dsc_dtype) - { - // Restore the field size/type overrides. - field->fld_dtype = saveDesc.dsc_dtype; - field->fld_length = saveDesc.dsc_length; - field->fld_scale = saveDesc.dsc_scale; - - if (field->fld_dtype <= dtype_any_text) - { - field->fld_character_set_id = DSC_GET_CHARSET(&saveDesc); - field->fld_collation_id= DSC_GET_COLLATE(&saveDesc); - } - else - field->fld_sub_type = saveDesc.dsc_sub_type; - } - else if (field) - { - // Use size calculated. - field->fld_dtype = desc.dsc_dtype; - field->fld_length = desc.dsc_length; - field->fld_scale = desc.dsc_scale; - - if (field->fld_dtype <= dtype_any_text) - { - field->fld_character_set_id = DSC_GET_CHARSET(&desc); - field->fld_collation_id = DSC_GET_COLLATE(&desc); - } - else - field->fld_sub_type = desc.dsc_sub_type; - } - - DDL_reset_context_stack(dsqlScratch); - - // Generate the source text. - const dsql_str* sourceStr = (dsql_str*) node->nod_arg[Dsql::e_cmp_text]; - fb_assert(sourceStr->str_length <= MAX_USHORT); - source = string(sourceStr->str_data, sourceStr->str_length); - - value.assign(dsqlScratch->getBlrData()); -} - // Define a DEFAULT clause. Return true for DEFAULT NULL. bool RelationNode::defineDefault(thread_db* /*tdbb*/, DsqlCompilerScratch* dsqlScratch, dsql_fld* /*field*/, dsql_nod* node, string& source, BlrWriter::BlrData& value) @@ -6985,7 +6988,10 @@ BlrWriter::BlrData computedValue; if (computedNode) - defineComputed(tdbb, dsqlScratch, field, computedNode, computedSource, computedValue); + { + defineComputed(dsqlScratch, dsqlNode, field, computedNode, computedSource, + computedValue); + } if (defaultNode) { @@ -8631,8 +8637,8 @@ if (keyLength) { - keyLength += ((length + STUFF_COUNT - 1) / (unsigned) STUFF_COUNT) * - (STUFF_COUNT + 1); + keyLength += ((length + Ods::STUFF_COUNT - 1) / (unsigned) Ods::STUFF_COUNT) * + (Ods::STUFF_COUNT + 1); } else keyLength = length; @@ -8844,6 +8850,61 @@ } +void CreateIndexNode::print(string& text, Array<dsql_nod*>& /*nodes*/) const +{ + text.printf( + "CreateIndexNode\n" + " name: '%s'\n", + name.c_str()); +} + +// Define an index. +void CreateIndexNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction) +{ + Attachment* attachment = transaction->tra_attachment; + + // run all statements under savepoint control + AutoSavePoint savePoint(tdbb, transaction); + + executeDdlTrigger(tdbb, dsqlScratch, transaction, DTW_BEFORE, DDL_TRIGGER_CREATE_INDEX, name); + + CreateIndexNode::Definition definition; + definition.type = isc_dyn_def_idx; + definition.relation = ExprNode::as<RelationSourceNode>(legacyRelation)->dsqlName; + definition.unique = unique; + definition.descending = descending; + + if (legacyDef->nod_type == Dsql::nod_list) + { + const dsql_nod* const* ptr = legacyDef->nod_arg; + const dsql_nod* const* const end = ptr + legacyDef->nod_count; + + for (; ptr != end; ++ptr) + { + MetaName& column = definition.columns.add(); + column = ((dsql_str*) (*ptr)->nod_arg[1])->str_data; + } + } + else if (legacyDef->nod_type == Dsql::nod_def_computed) + { + string computedSource; + BlrWriter::BlrData computedValue; + + defineComputed(dsqlScratch, legacyRelation, NULL, legacyDef, computedSource, computedValue); + + attachment->storeMetaDataBlob(tdbb, transaction, &definition.expressionSource, + computedSource); + attachment->storeBinaryBlob(tdbb, transaction, &definition.expressionBlr, computedValue); + } + + store(tdbb, transaction, name, definition); + + executeDdlTrigger(tdbb, dsqlScratch, transaction, DTW_AFTER, DDL_TRIGGER_CREATE_INDEX, name); + + savePoint.release(); // everything is ok +} + + //---------------------- @@ -9009,6 +9070,69 @@ //---------------------- +void CreateFilterNode::print(string& text, Array<dsql_nod*>& /*nodes*/) const +{ + text.printf( + "CreateFilterNode\n" + " name: '%s'\n", + name.c_str()); +} + +// Define a blob filter. +void CreateFilterNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction) +{ + // run all statements under savepoint control + AutoSavePoint savePoint(tdbb, transaction); + + ///executeDdlTrigger(tdbb, dsqlScratch, transaction, DTW_BEFORE, DDL_TRIGGER_DECLARE_FILTER, name); + + AutoCacheRequest request(tdbb, drq_s_filters, DYN_REQUESTS); + + STORE(REQUEST_HANDLE request TRANSACTION_HANDLE transaction) + X IN RDB$FILTERS + { + strcpy(X.RDB$FUNCTION_NAME, name.c_str()); + X.RDB$SYSTEM_FLAG = 0; + moduleName.copyTo(X.RDB$MODULE_NAME, sizeof(X.RDB$MODULE_NAME)); + entryPoint.copyTo(X.RDB$ENTRYPOINT, sizeof(X.RDB$ENTRYPOINT)); + + if (inputFilter->name.hasData()) + { + if (!METD_get_type(transaction, inputFilter->name, "RDB$FIELD_SUB_TYPE", &X.RDB$INPUT_SUB_TYPE)) + { + status_exception::raise( + Arg::Gds(isc_sqlerr) << Arg::Num(-204) << + Arg::Gds(isc_dsql_datatype_err) << + Arg::Gds(isc_dsql_blob_type_unknown) << inputFilter->name); + } + } + else + X.RDB$INPUT_SUB_TYPE = inputFilter->number; + + if (outputFilter->name.hasData()) + { + if (!METD_get_type(transaction, outputFilter->name, "RDB$FIELD_SUB_TYPE", &X.RDB$OUTPUT_SUB_TYPE)) + { + status_exception::raise( + Arg::Gds(isc_sqlerr) << Arg::Num(-204) << + Arg::Gds(isc_dsql_datatype_err) << + Arg::Gds(isc_dsql_blob_type_unknown) << outputFilter->name); + } + } + else + X.RDB$OUTPUT_SUB_TYPE = outputFilter->number; + } + END_STORE + + ///executeDdlTrigger(tdbb, dsqlScratch, transaction, DTW_AFTER, DDL_TRIGGER_DECLARE_FILTER, name); + + savePoint.release(); // everything is ok +} + + +//---------------------- + + void DropFilterNode::print(string& text, Array<dsql_nod*>& /*nodes*/) const { text.printf( Modified: firebird/trunk/src/dsql/DdlNodes.h =================================================================== --- firebird/trunk/src/dsql/DdlNodes.h 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/src/dsql/DdlNodes.h 2011-11-27 19:08:06 UTC (rev 53645) @@ -1084,8 +1084,6 @@ void storePrivileges(thread_db* tdbb, jrd_tra* transaction); void defineField(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction, const dsql_nod* element, SSHORT position, const dsql_nod* pkcols); - void defineComputed(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, dsql_fld* field, - dsql_nod* node, Firebird::string& source, BlrWriter::BlrData& value); bool defineDefault(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, dsql_fld* field, dsql_nod* node, Firebird::string& source, BlrWriter::BlrData& value); void makeConstraint(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction, @@ -1266,7 +1264,7 @@ }; -class CreateIndexNode +class CreateIndexNode : public DdlNode { public: struct Definition @@ -1290,8 +1288,37 @@ Firebird::ObjectsArray<Firebird::MetaName> refColumns; }; +public: + CreateIndexNode(MemoryPool& p, const Firebird::MetaName& aName) + : DdlNode(p), + name(p, aName), + unique(false), + descending(false), + legacyRelation(NULL), + legacyDef(NULL) + { + } + +public: static void store(thread_db* tdbb, jrd_tra* transaction, Firebird::MetaName& name, const Definition& definition, Firebird::MetaName* referredIndexName = NULL); + +public: + virtual void print(Firebird::string& text, Firebird::Array<dsql_nod*>& nodes) const; + virtual void execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction); + +protected: + virtual void putErrorPrefix(Firebird::Arg::StatusVector& statusVector) + { + statusVector << Firebird::Arg::Gds(isc_dsql_create_index_failed) << name; + } + +public: + Firebird::MetaName name; + bool unique; + bool descending; + dsql_nod* legacyRelation; + dsql_nod* legacyDef; }; @@ -1373,6 +1400,57 @@ }; +class CreateFilterNode : public DdlNode +{ +public: + struct NameNumber + { + NameNumber(MemoryPool& p, const Firebird::MetaName& aName) + : name(p, aName), + number(0) + { + } + + NameNumber(MemoryPool& p, SSHORT aNumber) + : name(p), + number(aNumber) + { + } + + Firebird::MetaName name; + SSHORT number; + }; + +public: + CreateFilterNode(MemoryPool& p, const Firebird::MetaName& aName) + : DdlNode(p), + name(p, aName), + inputFilter(NULL), + outputFilter(NULL), + entryPoint(p), + moduleName(p) + { + } + +public: + virtual void print(Firebird::string& text, Firebird::Array<dsql_nod*>& nodes) const; + virtual void execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction); + +protected: + virtual void putErrorPrefix(Firebird::Arg::StatusVector& statusVector) + { + statusVector << Firebird::Arg::Gds(isc_dsql_create_filter_failed) << name; + } + +public: + Firebird::MetaName name; + NameNumber* inputFilter; + NameNumber* outputFilter; + Firebird::string entryPoint; + Firebird::string moduleName; +}; + + class DropFilterNode : public DdlNode { public: Modified: firebird/trunk/src/dsql/ddl.cpp =================================================================== --- firebird/trunk/src/dsql/ddl.cpp 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/src/dsql/ddl.cpp 2011-11-27 19:08:06 UTC (rev 53645) @@ -115,10 +115,6 @@ static void assign_field_length(dsql_fld*, USHORT); -static void define_computed(DsqlCompilerScratch*, dsql_nod*, dsql_fld*, dsql_nod*); -static void define_filter(DsqlCompilerScratch*); -static SSHORT getBlobFilterSubType(DsqlCompilerScratch* dsqlScratch, const dsql_nod* node); -static void define_index(DsqlCompilerScratch*); static void generate_dyn(DsqlCompilerScratch*, dsql_nod*); static void grant_revoke(DsqlCompilerScratch*); static void modify_privilege(DsqlCompilerScratch* dsqlScratch, NOD_TYPE type, SSHORT option, @@ -352,7 +348,7 @@ { SSHORT blob_sub_type; if (!METD_get_type(dsqlScratch->getTransaction(), - reinterpret_cast<const dsql_str*>(field->fld_sub_type_name), + reinterpret_cast<const dsql_str*>(field->fld_sub_type_name)->str_data, "RDB$FIELD_SUB_TYPE", &blob_sub_type)) { ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-204) << @@ -587,226 +583,6 @@ } -static void define_computed(DsqlCompilerScratch* dsqlScratch, - dsql_nod* relation_node, - dsql_fld* field, - dsql_nod* node) -{ -/************************************** - * - * d e f i n e _ c o m p u t e d - * - ************************************** - * - * Function - * Create the ddl to define a computed field - * or an expression index. - * - **************************************/ - - DsqlCompiledStatement* statement = dsqlScratch->getStatement(); - dsql_nod* const saved_ddl_node = statement->getDdlNode(); - statement->setDdlNode(node); - - // Get the table node & set up correct context - DDL_reset_context_stack(dsqlScratch); - - dsc save_desc; - // Save the size of the field if it is specified - save_desc.dsc_dtype = 0; - - if (field && field->fld_dtype) - { - fb_assert(field->fld_dtype <= MAX_UCHAR); - save_desc.dsc_dtype = (UCHAR) field->fld_dtype; - save_desc.dsc_length = field->fld_length; - fb_assert(field->fld_scale <= MAX_SCHAR); - save_desc.dsc_scale = (SCHAR) field->fld_scale; - save_desc.dsc_sub_type = field->fld_sub_type; - - field->fld_dtype = 0; - field->fld_length = 0; - field->fld_scale = 0; - field->fld_sub_type = 0; - } - - PASS1_make_context(dsqlScratch, relation_node); - - dsql_nod* input = PASS1_node(dsqlScratch, node->nod_arg[e_cmp_expr]); - - // try to calculate size of the computed field. The calculated size - // may be ignored, but it will catch self references - dsc desc; - MAKE_desc(dsqlScratch, &desc, input); - - // generate the blr expression - - dsqlScratch->beginBlr(isc_dyn_fld_computed_blr); - GEN_expr(dsqlScratch, input); - dsqlScratch->endBlr(); - - if (save_desc.dsc_dtype) - { - // restore the field size/type overrides - field->fld_dtype = save_desc.dsc_dtype; - field->fld_length = save_desc.dsc_length; - field->fld_scale = save_desc.dsc_scale; - if (field->fld_dtype <= dtype_any_text) - { - field->fld_character_set_id = DSC_GET_CHARSET(&save_desc); - field->fld_collation_id= DSC_GET_COLLATE(&save_desc); - } - else - field->fld_sub_type = save_desc.dsc_sub_type; - } - else if (field) - { - // use size calculated - field->fld_dtype = desc.dsc_dtype; - field->fld_length = desc.dsc_length; - field->fld_scale = desc.dsc_scale; - if (field->fld_dtype <= dtype_any_text) - { - field->fld_character_set_id = DSC_GET_CHARSET(&desc); - field->fld_collation_id= DSC_GET_COLLATE(&desc); - } - else - field->fld_sub_type = desc.dsc_sub_type; - } - - statement->setType(DsqlCompiledStatement::TYPE_DDL); - statement->setDdlNode(saved_ddl_node); - DDL_reset_context_stack(dsqlScratch); - - // generate the source text - const dsql_str* source = (dsql_str*) node->nod_arg[e_cmp_text]; - fb_assert(source->str_length <= MAX_USHORT); - dsqlScratch->appendString(isc_dyn_fld_computed_source, source->str_data, - (USHORT) source->str_length); -} - - -static SSHORT getBlobFilterSubType(DsqlCompilerScratch* dsqlScratch, const dsql_nod* node) -{ -/******************************************* - * - * g e t B l o b F i l t e r S u b T y p e - * - ******************************************* - * - * Function - * get sub_type value from LiteralNode. - * - **************************************/ - const LiteralNode* literal = ExprNode::as<LiteralNode>(node); - fb_assert(literal); - - switch (literal->litDesc.dsc_dtype) - { - case dtype_long: - return (SSHORT) literal->getSlong(); - case dtype_text: - break; - default: - fb_assert(false); - return 0; - } - - // fall thru for dtype_text - const dsql_str* type_name = reinterpret_cast<const dsql_str*>(node->nod_arg[0]); - SSHORT blob_sub_type; - if (!METD_get_type(dsqlScratch->getTransaction(), type_name, "RDB$FIELD_SUB_TYPE", &blob_sub_type)) - { - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-204) << - Arg::Gds(isc_dsql_datatype_err) << - Arg::Gds(isc_dsql_blob_type_unknown) << Arg::Str(type_name->str_data)); - } - return blob_sub_type; -} - -static void define_filter(DsqlCompilerScratch* dsqlScratch) -{ -/************************************** - * - * d e f i n e _ f i l t e r - * - ************************************** - * - * Function - * define a filter to the database. - * - **************************************/ - DsqlCompiledStatement* statement = dsqlScratch->getStatement(); - const dsql_nod* filter_node = statement->getDdlNode(); - const dsql_nod* const* ptr = filter_node->nod_arg; - - dsqlScratch->appendNullString(isc_dyn_def_filter, ((dsql_str*) (ptr[e_filter_name]))->str_data); - dsqlScratch->appendNumber(isc_dyn_filter_in_subtype, - getBlobFilterSubType(dsqlScratch, ptr[e_filter_in_type])); - dsqlScratch->appendNumber(isc_dyn_filter_out_subtype, - getBlobFilterSubType(dsqlScratch, ptr[e_filter_out_type])); - dsqlScratch->appendNullString(isc_dyn_func_entry_point, - ((dsql_str*) (ptr[e_filter_entry_pt]))->str_data); - dsqlScratch->appendNullString(isc_dyn_func_module_name, - ((dsql_str*) (ptr[e_filter_module]))->str_data); - - dsqlScratch->appendUChar(isc_dyn_end); -} - - -static void define_index(DsqlCompilerScratch* dsqlScratch) -{ -/************************************** - * - * d e f i n e _ i n d e x - * - ************************************** - * - * Function - * Generate ddl to create an index. - * - **************************************/ - DsqlCompiledStatement* statement = dsqlScratch->getStatement(); - - dsqlScratch->appendUChar(isc_dyn_begin); - - const dsql_nod* ddl_node = statement->getDdlNode(); - dsql_nod* relation_node = (dsql_nod*) ddl_node->nod_arg[e_idx_table]; - const MetaName& relation_name = ExprNode::as<RelationSourceNode>(relation_node)->dsqlName; - dsql_nod* field_list = ddl_node->nod_arg[e_idx_fields]; - const dsql_str* index_name = (dsql_str*) ddl_node->nod_arg[e_idx_name]; - - dsqlScratch->appendNullString(isc_dyn_def_idx, index_name->str_data); - dsqlScratch->appendNullString(isc_dyn_rel_name, relation_name.c_str()); - - // go through the fields list, making an index segment for each field, - // unless we have a computation, in which case generate an expression index - - if (field_list->nod_type == nod_list) - { - const dsql_nod* const* ptr = field_list->nod_arg; - const dsql_nod* const* const end = ptr + field_list->nod_count; - for (; ptr < end; ptr++) - dsqlScratch->appendNullString(isc_dyn_fld_name, ((dsql_str*) (*ptr)->nod_arg[1])->str_data); - } - else if (field_list->nod_type == nod_def_computed) - define_computed(dsqlScratch, relation_node, NULL, field_list); - - // check for a unique index - - if (ddl_node->nod_arg[e_idx_unique]) { - dsqlScratch->appendNumber(isc_dyn_idx_unique, 1); - } - - if (ddl_node->nod_arg[e_idx_asc_dsc]) { - dsqlScratch->appendNumber(isc_dyn_idx_type, 1); - } - - dsqlScratch->appendUChar(isc_dyn_end); // of define index - dsqlScratch->appendUChar(isc_dyn_end); // of begin -} - - static void generate_dyn(DsqlCompilerScratch* dsqlScratch, dsql_nod* node) { /************************************** @@ -822,19 +598,11 @@ **************************************/ switch (node->nod_type) { - case nod_def_index: - define_index(dsqlScratch); - break; - case nod_grant: case nod_revoke: grant_revoke(dsqlScratch); break; - case nod_def_filter: - define_filter(dsqlScratch); - break; - case nod_add_user: define_user(dsqlScratch, isc_dyn_user_add); break; Modified: firebird/trunk/src/dsql/metd.epp =================================================================== --- firebird/trunk/src/dsql/metd.epp 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/src/dsql/metd.epp 2011-11-27 19:08:06 UTC (rev 53645) @@ -1524,7 +1524,7 @@ } -bool METD_get_type(jrd_tra* transaction, const dsql_str* name, const char* field, SSHORT* value) +bool METD_get_type(jrd_tra* transaction, const MetaName& name, const char* field, SSHORT* value) { /************************************** * @@ -1546,7 +1546,7 @@ FOR(REQUEST_HANDLE handle TRANSACTION_HANDLE transaction) X IN RDB$TYPES WITH - X.RDB$FIELD_NAME EQ field AND X.RDB$TYPE_NAME EQ name->str_data; + X.RDB$FIELD_NAME EQ field AND X.RDB$TYPE_NAME EQ name.c_str(); { found = true; *value = X.RDB$TYPE; Modified: firebird/trunk/src/dsql/metd_proto.h =================================================================== --- firebird/trunk/src/dsql/metd_proto.h 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/src/dsql/metd_proto.h 2011-11-27 19:08:06 UTC (rev 53645) @@ -67,7 +67,7 @@ Jrd::dsql_prc* METD_get_procedure(Jrd::jrd_tra*, Jrd::DsqlCompilerScratch*, const Firebird::QualifiedName&); Jrd::dsql_rel* METD_get_relation(Jrd::jrd_tra*, Jrd::DsqlCompilerScratch*, const Firebird::MetaName&); -bool METD_get_type(Jrd::jrd_tra*, const Jrd::dsql_str*, const char*, SSHORT*); +bool METD_get_type(Jrd::jrd_tra*, const Firebird::MetaName&, const char*, SSHORT*); Jrd::dsql_rel* METD_get_view_base(Jrd::jrd_tra*, Jrd::DsqlCompilerScratch*, const char* view_name, Jrd::MetaNamePairMap& fields); Jrd::dsql_rel* METD_get_view_relation(Jrd::jrd_tra*, Jrd::DsqlCompilerScratch*, const char* view_name, Modified: firebird/trunk/src/dsql/node.h =================================================================== --- firebird/trunk/src/dsql/node.h 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/src/dsql/node.h 2011-11-27 19:08:06 UTC (rev 53645) @@ -66,7 +66,6 @@ nod_del_field, nod_def_index, nod_def_constraint, - nod_def_filter, nod_grant, nod_revoke, nod_rel_constraint, @@ -268,13 +267,6 @@ e_rollback_retain = 0, // e_rollback_count, - e_filter_name = 0, // - e_filter_in_type, - e_filter_out_type, - e_filter_entry_pt, - e_filter_module, - e_filter_count, - // computed field e_cmp_expr = 0, Modified: firebird/trunk/src/dsql/parse.y =================================================================== --- firebird/trunk/src/dsql/parse.y 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/src/dsql/parse.y 2011-11-27 19:08:06 UTC (rev 53645) @@ -649,6 +649,7 @@ Jrd::CreateAlterProcedureNode* createAlterProcedureNode; Jrd::CreateAlterTriggerNode* createAlterTriggerNode; Jrd::CreateAlterPackageNode* createAlterPackageNode; + Jrd::CreateFilterNode::NameNumber* filterNameNumber; Jrd::CreateSequenceNode* createSequenceNode; Jrd::CreateShadowNode* createShadowNode; Firebird::Array<Jrd::CreateAlterPackageNode::Item>* packageItems; @@ -690,7 +691,8 @@ %type <compoundStmtNode> assignments %type <legacyStr> admin_opt -%type <legacyNode> blob_filter_subtype blob_io blob_segsize blob_subtype blob_subtype_io +%type <legacyNode> blob_io blob_segsize blob_subtype blob_subtype_io +%type <filterNameNumber> blob_filter_subtype %type <legacyNode> blob_subtype_value_io blob_type %type <stmtNode> breakleave @@ -724,18 +726,19 @@ %type <dbFileClause> db_file %type db_file_list(<dbFilesClause>) %type <legacyNode> ddl_subname -%type <legacyNode> decimal_keyword declare declare_clause +%type <legacyNode> decimal_keyword %type <legacyNode> decode_pairs def_computed default_par_opt default_value %type <stmtNode> delete delete_positioned delete_searched %type <legacyNode> delete_rule delimiter_opt derived_column_list derived_table %type <legacyNode> deterministic_opt distinct_clause %type <legacyNode> domain_default domain_default_opt domain_or_non_array_type %type <legacyNode> domain_or_non_array_type_name domain_type drop_behaviour -%type <ddlNode> drop drop_clause +%type <ddlNode> declare declare_clause drop drop_clause %type <legacyStr> db_name ddl_desc %type db_alter_clause(<alterDatabaseNode>) -%type <legacyNode> event_argument_opt exception_clause +%type <legacyNode> event_argument_opt +%type <ddlNode> exception_clause %type err(<exceptionArray>) errors(<exceptionArray>) %type <stmtNode> excp_hndl_statement exec_procedure exec_function %type <compoundStmtNode> excp_hndl_statements @@ -749,9 +752,10 @@ %type <stmtNode> fetch_cursor %type <legacyNode> file1 -%type <legacyNode> filter_clause_io filter_decl_clause first_clause +%type <legacyNode> filter_clause_io first_clause %type <legacyNode> float_type for_update_clause for_update_list from_clause %type <legacyNode> from_list +%type <ddlNode> filter_decl_clause %type <stmtNode> for_select full_proc_block full_proc_block_body %type <legacyStr> firstname_opt %type file_clause(<dbFileClause>) file_desc(<dbFileClause>) file_desc1(<dbFileClause>) @@ -807,7 +811,8 @@ %type <stmtNode> open_cursor %type <legacyNode> optional_retain %type optional_savepoint opt_snapshot optional_work -%type <legacyNode> order_clause order_direction order_item order_list +%type <legacyNode> order_clause order_item order_list +%type <boolVal> order_direction %type output_parameters(<parametersClause>) output_proc_parameter(<parametersClause>) %type output_proc_parameters(<parametersClause>) @@ -833,9 +838,9 @@ %type return_value1(<createAlterFunctionNode>) return_value(<createAlterFunctionNode>) %type <returningClause> returning_clause %type <ddlNode> rexception_clause -%type <legacyNode> role_admin_option role_clause role_grantee role_grantee_list +%type <legacyNode> role_admin_option role_grantee role_grantee_list %type <legacyNode> role_name role_name_list rollback rows_clause -%type <ddlNode> rtable_clause +%type <ddlNode> role_clause rtable_clause %type <ddlNode> rview_clause %type <legacyStr> revoke_admin @@ -877,7 +882,8 @@ %type <legacyNode> u_constant u_numeric_constant udf_data_type undo_savepoint %type <createAlterFunctionNode> udf_decl_clause -%type <legacyNode> unique_constraint unique_opt update_column_name +%type <legacyNode> unique_constraint update_column_name +%type <boolVal> unique_opt %type <stmtNode> update update_or_insert update_positioned update_searched %type <legacyNode> update_or_insert_matching_opt update_rule %type <legacyNode> user_grantee user_grantee_list @@ -989,6 +995,7 @@ | create_or_alter { $$ = makeClassNode($1); } | declare + { $$ = makeClassNode($1); } | delete { $$ = makeClassNode($1); } | drop @@ -1209,7 +1216,7 @@ declare_clause : FILTER filter_decl_clause { $$ = $2; } - | EXTERNAL FUNCTION udf_decl_clause { $$ = makeClassNode($3); } + | EXTERNAL FUNCTION udf_decl_clause { $$ = $3; } ; udf_decl_clause @@ -1289,16 +1296,25 @@ filter_decl_clause - : symbol_filter_name INPUT_TYPE blob_filter_subtype OUTPUT_TYPE blob_filter_subtype - ENTRY_POINT sql_string MODULE_NAME sql_string - { $$ = make_node (nod_def_filter, (int) e_filter_count, $1, $3, $5, $7, $9); } + : symbol_filter_name + INPUT_TYPE blob_filter_subtype + OUTPUT_TYPE blob_filter_subtype + ENTRY_POINT sql_string MODULE_NAME sql_string + { + CreateFilterNode* node = newNode<CreateFilterNode>(toName($1)); + node->inputFilter = $3; + node->outputFilter = $5; + node->entryPoint = toString($7); + node->moduleName = toString($9); + $$ = node; + } ; blob_filter_subtype : symbol_blob_subtype_name - { $$ = MAKE_constant((dsql_str*) $1, CONSTANT_STRING); } + { $$ = newNode<CreateFilterNode::NameNumber>(toName($1)); } | signed_short_integer - { $$ = MAKE_const_slong($1); } + { $$ = newNode<CreateFilterNode::NameNumber>($1); } ; // CREATE metadata operations @@ -1309,9 +1325,16 @@ create_clause : EXCEPTION exception_clause - { $$ = $2; } + { $$ = makeClassNode($2); } | unique_opt order_direction INDEX symbol_index_name ON simple_table_name index_definition - { $$ = make_node (nod_def_index, (int) e_idx_count, $1, $2, $4, $6, $7); } + { + CreateIndexNode* node = newNode<CreateIndexNode>(toName($4)); + node->unique = $1; + node->descending = $2; + node->legacyRelation = $6; + node->legacyDef = $7; + $$ = makeClassNode(node); + } | FUNCTION function_clause { $$ = makeClassNode($2); } | PROCEDURE procedure_clause @@ -1335,7 +1358,7 @@ | SHADOW shadow_clause { $$ = makeClassNode($2); } | ROLE role_clause - { $$ = $2; } + { $$ = makeClassNode($2); } | COLLATION collation_clause { $$ = makeClassNode($2); } | USER create_user_clause @@ -1394,7 +1417,7 @@ exception_clause : symbol_exception_name sql_string - { $$ = makeClassNode(newNode<CreateAlterExceptionNode>(toName($1), toString($2))); } + { $$ = newNode<CreateAlterExceptionNode>(toName($1), toString($2)); } ; rexception_clause @@ -1431,8 +1454,8 @@ // CREATE INDEX unique_opt - : /* nothing */ { $$ = NULL; } - | UNIQUE { $$ = make_node (nod_unique, 0, NULL); } + : /* nothing */ { $$ = false; } + | UNIQUE { $$ = true; } ; index_definition @@ -1558,7 +1581,7 @@ // CREATE ROLE role_clause - : symbol_role_name { $$ = makeClassNode(newNode<CreateRoleNode>(toName($1))); } + : symbol_role_name { $$ = newNode<CreateRoleNode>(toName($1)); } ; @@ -1973,15 +1996,19 @@ { $$ = make_node (nod_foreign, (int) e_for_count, $3, $5, $6, $7, $8); } ; -constraint_index_opt : USING order_direction INDEX symbol_index_name - { $$ = make_node (nod_def_index, (int) e_idx_count, NULL, $2, $4, NULL, NULL); } +constraint_index_opt + : USING order_direction INDEX symbol_index_name + { + $$ = make_node (nod_def_index, (int) e_idx_count, + NULL, ($2 ? make_node(nod_flag, 0, NULL) : NULL), $4, NULL, NULL); + } /* - | NO INDEX - { $$ = NULL; } + | NO INDEX + { $$ = NULL; } */ - | - { $$ = make_node (nod_def_index, (int) e_idx_count, NULL, NULL, NULL, NULL, NULL); } - ; + | + { $$ = make_node (nod_def_index, (int) e_idx_count, NULL, NULL, NULL, NULL, NULL); } + ; referential_trigger_action: update_rule @@ -4742,13 +4769,16 @@ order_item : value order_direction nulls_clause - { $$ = make_node (nod_order, (int) e_order_count, $1, $2, $3); } + { + $$ = make_node (nod_order, (int) e_order_count, + $1, ($2 ? make_node(nod_flag, 0, NULL) : NULL), $3); + } ; order_direction - : /* nothing */ { $$ = NULL; } - | ASC { $$ = NULL; } - | DESC { $$ = make_node(nod_flag, 0, NULL); } + : /* nothing */ { $$ = false; } + | ASC { $$ = false; } + | DESC { $$ = true; } ; nulls_clause Modified: firebird/trunk/src/dsql/pass1.cpp =================================================================== --- firebird/trunk/src/dsql/pass1.cpp 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/src/dsql/pass1.cpp 2011-11-27 19:08:06 UTC (rev 53645) @@ -895,7 +895,6 @@ case nod_def_constraint: case nod_grant: case nod_revoke: - case nod_def_filter: case nod_def_domain: case nod_add_user: case nod_mod_user: @@ -4741,9 +4740,6 @@ case nod_def_field: verb = "define field"; break; - case nod_def_filter: - verb = "define filter"; - break; case nod_def_index: verb = "define index"; break; Modified: firebird/trunk/src/include/gen/codetext.h =================================================================== --- firebird/trunk/src/include/gen/codetext.h 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/src/include/gen/codetext.h 2011-11-27 19:08:06 UTC (rev 53645) @@ -1065,6 +1065,8 @@ {"dsql_alter_index_failed", 336397312}, {"dsql_alter_database_failed", 336397313}, {"dsql_create_shadow_failed", 336397314}, + {"dsql_create_filter_failed", 336397315}, + {"dsql_create_index_failed", 336397316}, {"gsec_cant_open_db", 336723983}, {"gsec_switches_error", 336723984}, {"gsec_no_op_spec", 336723985}, Modified: firebird/trunk/src/include/gen/iberror.h =================================================================== --- firebird/trunk/src/include/gen/iberror.h 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/src/include/gen/iberror.h 2011-11-27 19:08:06 UTC (rev 53645) @@ -1099,6 +1099,8 @@ const ISC_STATUS isc_dsql_alter_index_failed = 336397312L; const ISC_STATUS isc_dsql_alter_database_failed = 336397313L; const ISC_STATUS isc_dsql_create_shadow_failed = 336397314L; +const ISC_STATUS isc_dsql_create_filter_failed = 336397315L; +const ISC_STATUS isc_dsql_create_index_failed = 336397316L; const ISC_STATUS isc_gsec_cant_open_db = 336723983L; const ISC_STATUS isc_gsec_switches_error = 336723984L; const ISC_STATUS isc_gsec_no_op_spec = 336723985L; @@ -1200,7 +1202,7 @@ const ISC_STATUS isc_trace_switch_param_miss = 337182758L; const ISC_STATUS isc_trace_param_act_notcompat = 337182759L; const ISC_STATUS isc_trace_mandatory_switch_miss = 337182760L; -const ISC_STATUS isc_err_max = 1144; +const ISC_STATUS isc_err_max = 1146; #else /* c definitions */ @@ -2269,6 +2271,8 @@ #define isc_dsql_alter_index_failed 336397312L #define isc_dsql_alter_database_failed 336397313L #define isc_dsql_create_shadow_failed 336397314L +#define isc_dsql_create_filter_failed 336397315L +#define isc_dsql_create_index_failed 336397316L #define isc_gsec_cant_open_db 336723983L #define isc_gsec_switches_error 336723984L #define isc_gsec_no_op_spec 336723985L @@ -2370,7 +2374,7 @@ #define isc_trace_switch_param_miss 337182758L #define isc_trace_param_act_notcompat 337182759L #define isc_trace_mandatory_switch_miss 337182760L -#define isc_err_max 1144 +#define isc_err_max 1146 #endif Modified: firebird/trunk/src/include/gen/msgs.h =================================================================== --- firebird/trunk/src/include/gen/msgs.h 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/src/include/gen/msgs.h 2011-11-27 19:08:06 UTC (rev 53645) @@ -1068,6 +1068,8 @@ {336397312, "ALTER INDEX @1 failed"}, /* dsql_alter_index_failed */ {336397313, "ALTER DATABASE failed"}, /* dsql_alter_database_failed */ {336397314, "CREATE SHADOW @1 failed"}, /* dsql_create_shadow_failed */ + {336397315, "DECLARE FILTER @1 failed"}, /* dsql_create_filter_failed */ + {336397316, "CREATE INDEX @1 failed"}, /* dsql_create_index_failed */ {336723983, "unable to open database"}, /* gsec_cant_open_db */ {336723984, "error in switch specifications"}, /* gsec_switches_error */ {336723985, "no operation specified"}, /* gsec_no_op_spec */ Modified: firebird/trunk/src/include/gen/sql_code.h =================================================================== --- firebird/trunk/src/include/gen/sql_code.h 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/src/include/gen/sql_code.h 2011-11-27 19:08:06 UTC (rev 53645) @@ -1064,6 +1064,8 @@ {336397312, -901}, /* 1024 dsql_alter_index_failed */ {336397313, -901}, /* 1025 dsql_alter_database_failed */ {336397314, -901}, /* 1026 dsql_create_shadow_failed */ + {336397315, -901}, /* 1027 dsql_create_filter_failed */ + {336397316, -901}, /* 1028 dsql_create_index_failed */ {336723983, -901}, /* 15 gsec_cant_open_db */ {336723984, -901}, /* 16 gsec_switches_error */ {336723985, -901}, /* 17 gsec_no_op_spec */ Modified: firebird/trunk/src/include/gen/sql_state.h =================================================================== --- firebird/trunk/src/include/gen/sql_state.h 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/src/include/gen/sql_state.h 2011-11-27 19:08:06 UTC (rev 53645) @@ -1064,6 +1064,8 @@ {336397312, "42000"}, // 1024 dsql_alter_index_failed {336397313, "42000"}, // 1025 dsql_alter_database_failed {336397314, "42000"}, // 1026 dsql_create_shadow_failed + {336397315, "42000"}, // 1027 dsql_create_filter_failed + {336397316, "42000"}, // 1028 dsql_create_index_failed {336723983, "00000"}, // 15 gsec_cant_open_db {336723984, "00000"}, // 16 gsec_switches_error {336723985, "00000"}, // 17 gsec_no_op_spec Modified: firebird/trunk/src/jrd/dyn.epp =================================================================== --- firebird/trunk/src/jrd/dyn.epp 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/src/jrd/dyn.epp 2011-11-27 19:08:06 UTC (rev 53645) @@ -63,7 +63,6 @@ #include "../jrd/cmp_proto.h" #include "../jrd/dpm_proto.h" #include "../jrd/dyn_proto.h" -#include "../jrd/dyn_df_proto.h" #include "../jrd/err_proto.h" #include "../jrd/exe_proto.h" #include "../yvalve/gds_proto.h" @@ -374,14 +373,6 @@ break; ***/ - case isc_dyn_def_filter: - DYN_define_filter(gbl, ptr); - break; - - case isc_dyn_def_idx: - DYN_define_index(gbl, ptr, relation_name); - break; - case isc_dyn_user: dyn_user(gbl, ptr); break; @@ -561,123 +552,6 @@ } -USHORT DYN_put_blr_blob(Global* gbl, const UCHAR** ptr, bid* blob_id) -{ -/************************************** - * - * D Y N _ p u t _ b l r _ b l o b - * - ************************************** - * - * Functional description - * Write out a blr blob. - * - **************************************/ - thread_db* tdbb = JRD_get_thread_data(); - - const UCHAR *p = *ptr; - USHORT length = *p++; - length |= (*p++) << 8; - - if (!length) - { - *ptr = p; - return length; - } - - try { - blb* blob = BLB_create(tdbb, gbl->gbl_transaction, blob_id); - BLB_put_segment(tdbb, blob, p, length); - BLB_close(tdbb, blob); - } - catch (const Exception& ex) - { - stuff_exception(tdbb->tdbb_status_vector, ex); - DYN_error_punt(true, 106); - // msg 106: "Create metadata blob failed" - } - - *ptr = p + length; - - return length; -} - -USHORT DYN_put_text_blob(Global* gbl, const UCHAR** ptr, bid* blob_id) -{ -/************************************** - * - * D Y N _ p u t _ t e x t _ b l o b - * - ************************************** - * - * Functional description - * Write out a text blob. - * - **************************************/ - thread_db* tdbb = JRD_get_thread_data(); - - const UCHAR* p = *ptr; - USHORT length = *p++; - length |= (*p++) << 8; - - if (!length) - { - *ptr = p; - return length; - } - - const UCHAR* const end = p + length; - - try { - UCharBuffer bpb; - const size_t convSize = 15; - bpb.resize(convSize); - - UCHAR* bpbPtr = bpb.begin(); - *bpbPtr++ = isc_bpb_version1; - - *bpbPtr++ = isc_bpb_source_type; - *bpbPtr++ = 2; - put_vax_short(bpbPtr, isc_blob_text); - bpbPtr += 2; - *bpbPtr++ = isc_bpb_source_interp; - *bpbPtr++ = 1; - *bpbPtr++ = tdbb->getCharSet(); - - *bpbPtr++ = isc_bpb_target_type; - *bpbPtr++ = 2; - put_vax_short(bpbPtr, isc_blob_text); - bpbPtr += 2; - *bpbPtr++ = isc_bpb_target_interp; - *bpbPtr++ = 1; - *bpbPtr++ = CS_METADATA; - fb_assert(size_t(bpbPtr - bpb.begin()) <= convSize); - - // set the array count to the number of bytes we used - bpb.shrink(bpbPtr - bpb.begin()); - - blb* blob = BLB_create2(tdbb, gbl->gbl_transaction, blob_id, bpb.getCount(), bpb.begin()); - - for (; p < end; p += TEXT_BLOB_LENGTH) - { - length = (p + TEXT_BLOB_LENGTH <= end) ? TEXT_BLOB_LENGTH : end - p; - BLB_put_segment(tdbb, blob, p, length); - } - BLB_close(tdbb, blob); - } - catch (const Exception& ex) - { - stuff_exception(tdbb->tdbb_status_vector, ex); - DYN_error_punt(true, 106); - // msg 106: "Create metadata blob failed" - } - - *ptr = end; - - return length; -} - - static void grant( Global* gbl, const UCHAR** ptr) { /************************************** Modified: firebird/trunk/src/jrd/dyn.h =================================================================== --- firebird/trunk/src/jrd/dyn.h 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/src/jrd/dyn.h 2011-11-27 19:08:06 UTC (rev 53645) @@ -33,30 +33,25 @@ const char* const ALL_PRIVILEGES = "SIUDR"; // all applicable grant/revoke privileges const char* const ALL_PROC_PRIVILEGES = "X"; // all applicable grant/revoke privileges for a procedure const int DYN_MSG_FAC = 8; -const int STUFF_COUNT = 4; // Is this the same value defined in ods.h??? -const int TEXT_BLOB_LENGTH = 512; +///const int STUFF_COUNT = 4; // Is this the same value defined in ods.h??? #define GET_STRING(from, to) DYN_get_string(from, to, sizeof(to)) -#define GET_BYTES(from, to) DYN_get_string(from, to, sizeof(to)) namespace Jrd { -struct bid; class jrd_tra; class thread_db; class Global { public: - Global(jrd_tra* t, const Firebird::string& aSqlText) //, const UCHAR* dyn, size_t length) - : gbl_transaction(t),// gbl_length(length), gbl_end(dyn + length) + Global(jrd_tra* t, const Firebird::string& aSqlText) + : gbl_transaction(t), sqlText(aSqlText) { } jrd_tra* const gbl_transaction; - //size_t gbl_length; // length of BLR stream - //const UCHAR* const gbl_end; // end of BLR sream Firebird::string sqlText; }; @@ -114,8 +109,6 @@ USHORT DYN_get_string(const UCHAR**, TEXT*, size_t); bool DYN_is_it_sql_role(Jrd::jrd_tra*, const Firebird::MetaName&, Firebird::MetaName&, Jrd::thread_db*); -USHORT DYN_put_blr_blob(Jrd::Global*, const UCHAR**, Jrd::bid*); -USHORT DYN_put_text_blob(Jrd::Global*, const UCHAR**, Jrd::bid*); void DYN_unsupported_verb(); Deleted: firebird/trunk/src/jrd/dyn_def.epp =================================================================== --- firebird/trunk/src/jrd/dyn_def.epp 2011-11-24 03:20:18 UTC (rev 53644) +++ firebird/trunk/src/jrd/dyn_def.epp 2011-11-27 19:08:06 UTC (rev 53645) @@ -1,266 +0,0 @@ -/* - * PROGRAM: JRD Data Definition Utility - * MODULE: dyn_define.epp - * DESCRIPTION: Dynamic data definition DYN_define_<x> - * - * 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): ______________________________________. - * - * 23-May-2001 Claudio Valderrama - Forbid zero length identifiers, - * they are not ANSI SQL compliant. - * 2001.10.08 Claudio Valderrama: Add case isc_dyn_system_flag to - * DYN_define_trigger() in order to receive values for special triggers - * as defined in constants.h. - * 2001.10.08 Ann Harrison: Changed dyn_create_index so it doesn't consider - * simple unique indexes when finding a "referred index", but only - * indexes that support unique constraints or primary keys. - * 26-Sep-2001 Paul Beach - External File Directory Config. Parameter - * 2002-02-24 Sean Leyne - Code Cleanup of old Win 3.1 port (WINDOWS_ONLY) - * 2002.08.10 Dmitry Yemanov: ALTER VIEW - * - * 2002.10.29 Sean Leyne - Removed obsolete "Netware" port - * - * 2004.01.16 Vlad Horsun: added support for default parameters - */ - -#include "firebird.h" -#include "dyn_consts.h" -#include "../common/classes/fb_string.h" -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -#include "../common/common.h" -#include "../jrd/jrd.h" -#include "../jrd/ods.h" -#include "../jrd/tra.h" -#include "../jrd/scl.h" -#include "../jrd/drq.h" -#include "../jrd/req.h" -#include "../jrd/flags.h" -#include "../jrd/ibase.h" -#include "../jrd/lls.h" -#include "../jrd/met.h" -#include "../jrd/btr.h" -#include "../jrd/ini.h" -#include "../jrd/intl.h" -#include "../jrd/dyn.h" -#include "../common/gdsassert.h" -#include "../jrd/blb_proto.h" -#include "../jrd/cmp_proto.h" -#include "../jrd/dyn_proto.h" -#include "../jrd/dyn_df_proto.h" -#include "../jrd/dyn_ut_proto.h" -#include "../jrd/err_proto.h" -#include "../jrd/exe_proto.h" -#include "../yvalve/gds_proto.h" -#include "../jrd/inf_proto.h" -#include "../jrd/intl_proto.h" -#include "../common/isc_f_proto.h" -#include "../jrd/met_proto.h" -#include "../jrd/vio_proto.h" -#include "../jrd/scl_proto.h" -#include "../common/gdsassert.h" -#include "../common/os/path_utils.h" -#include "../common/utils_proto.h" -#include "../jrd/IntlManager.h" -#include "../common/IntlUtil.h" -#include "../dsql/DdlNodes.h" - -using MsgFormat::SafeArg; - -using namespace Jrd; -using namespace Firebird; - - -DATABASE DB = STATIC "ODS.RDB"; - - -void DYN_define_filter( Global* gbl, const UCHAR** ptr) -{ -/************************************** - * - * D Y N _ d e f i n e _ f i l t e r - * - ************************************** - * - * Functional description - * Define a blob filter. - * - **************************************/ - - thread_db* tdbb = JRD_get_thread_data(); - - Firebird::MetaName filter_name; - GET_STRING(ptr, filter_name); - - AutoCacheRequest request(tdbb, drq_s_filters, DYN_REQUESTS); - - bool b_ending_store = false; - - try { - - STORE(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) - X IN RDB$FILTERS USING - strcpy(X.RDB$FUNCTION_NAME, filter_name.c_str()); - X.RDB$OUTPUT_SUB_TYPE.NULL = TRUE; - X.RDB$INPUT_SUB_TYPE.NULL = TRUE; - X.RDB$MODULE_NAME.NULL = TRUE; - X.RDB$ENTRYPOINT.NULL = TRUE; - X.RDB$SYSTEM_FLAG = 0; - X.RDB$SYSTEM_FLAG.NULL = FALSE; - { - UCHAR verb; - while ((verb = *(*ptr)++) != isc_dyn_end) - { - switch (verb) - { - case isc_dyn_filter_in_subtype: - X.RDB$INPUT_SUB_TYPE = (SSHORT)DYN_get_number(ptr); - X.RDB$INPUT_SUB_TYPE.NULL = FALSE; - break; - - case isc_dyn_filter_out_subtype: - X.RDB$OUTPUT_SUB_TYPE = (SSHORT)DYN_get_number(ptr); - X.RDB$OUTPUT_SUB_TYPE.NULL = FALSE; - break; - - case isc_dyn_func_module_name: - GET_STRING(ptr, X.RDB$MODULE_NAME); - X.RDB$MODULE_NAME.NULL = FALSE; - break; - - case isc_dyn_func_entry_point: - GET_STRING(ptr, X.RDB$ENTRYPOINT); - X.RDB$ENTRYPOINT.NULL = FALSE; - break; - - default: - DYN_unsupported_verb(); - } - } - } - END_STORE - } - catch (const Firebird::Exception& ex) - { - Firebird::stuff_exception(tdbb->tdbb_status_vector, ex); - if (b_ending_store) - { - DYN_error_punt(true, 7); - // msg 7: "DEFINE BLOB FILTER failed" - } - throw; - } -} - - -void DYN_define_index(Global* gbl, const UCHAR** ptr, const Firebird::MetaName* relation_name) -{ -/************************************** - * - * D Y N _ d e f i n e _ i n d e x - * - ************************************** - * - * Functional description - * Execute a dynamic ddl statement that creates an index. - * - **************************************/ - thread_db* tdbb = JRD_get_thread_data(); - const UCHAR index_type = isc_dyn_def_idx; - Firebird::MetaName index_name; - UCHAR verb; - Firebird::MetaName trigger_name; - - GET_STRING(ptr, index_name); - - if (index_name.isEmpty()) - DYN_UTIL_generate_index_name(tdbb, gbl->gbl_transaction, index_name, index_type); - - DdlNode::executeDdlTrigger(tdbb, gbl->gbl_transaction, DdlNode::DTW_BEFORE, - DDL_TRIGGER_CREATE_INDEX, index_name, gbl->sqlText); - - try - { - DYN_UTIL_check_unique_name(tdbb, gbl->gbl_transaction, index_name, obj_index); - } - catch (const Exception& ex) - { - stuff_exception(tdbb->tdbb_status_vector, ex); - DYN_error_punt(true, 21); // msg 21: "STORE RDB$INDICES failed" - } - - try - { - CreateIndexNode::Definition definition; - definition.type = index_type; - - if (rel... [truncated message content] |