From: <asf...@us...> - 2011-05-27 02:05:33
|
Revision: 53018 http://firebird.svn.sourceforge.net/firebird/?rev=53018&view=rev Author: asfernandes Date: 2011-05-27 02:05:27 +0000 (Fri, 27 May 2011) Log Message: ----------- Frontported changes of CORE-3491. Modified Paths: -------------- firebird/trunk/src/dsql/DdlNodes.epp firebird/trunk/src/dsql/DsqlCompilerScratch.cpp firebird/trunk/src/dsql/ddl.cpp firebird/trunk/src/dsql/dsql.h firebird/trunk/src/dsql/metd.epp firebird/trunk/src/dsql/parse.y Modified: firebird/trunk/src/dsql/DdlNodes.epp =================================================================== --- firebird/trunk/src/dsql/DdlNodes.epp 2011-05-27 02:00:41 UTC (rev 53017) +++ firebird/trunk/src/dsql/DdlNodes.epp 2011-05-27 02:05:27 UTC (rev 53018) @@ -754,8 +754,8 @@ notNull = legacyField->fld_not_nullable; fieldSource = legacyField->fld_source; - if (legacyField->fld_type_of_table) - typeOfTable = legacyField->fld_type_of_table->str_data; + if (legacyField->fld_type_of_table.hasData()) + typeOfTable = legacyField->fld_type_of_table.c_str(); typeOfName = legacyField->fld_type_of_name; } Modified: firebird/trunk/src/dsql/DsqlCompilerScratch.cpp =================================================================== --- firebird/trunk/src/dsql/DsqlCompilerScratch.cpp 2011-05-27 02:00:41 UTC (rev 53017) +++ firebird/trunk/src/dsql/DsqlCompilerScratch.cpp 2011-05-27 02:05:27 UTC (rev 53018) @@ -60,13 +60,13 @@ if (field->fld_type_of_name.hasData()) { - if (field->fld_type_of_table) + if (field->fld_type_of_table.hasData()) { if (field->fld_explicit_collation) { appendUChar(blr_column_name2); appendUChar(field->fld_full_domain ? blr_domain_full : blr_domain_type_of); - appendMetaString(field->fld_type_of_table->str_data); + appendMetaString(field->fld_type_of_table.c_str()); appendMetaString(field->fld_type_of_name.c_str()); appendUShort(field->fld_ttype); } @@ -74,7 +74,7 @@ { appendUChar(blr_column_name); appendUChar(field->fld_full_domain ? blr_domain_full : blr_domain_type_of); - appendMetaString(field->fld_type_of_table->str_data); + appendMetaString(field->fld_type_of_table.c_str()); appendMetaString(field->fld_type_of_name.c_str()); } } Modified: firebird/trunk/src/dsql/ddl.cpp =================================================================== --- firebird/trunk/src/dsql/ddl.cpp 2011-05-27 02:00:41 UTC (rev 53017) +++ firebird/trunk/src/dsql/ddl.cpp 2011-05-27 02:05:27 UTC (rev 53018) @@ -310,10 +310,10 @@ if (field->fld_type_of_name.hasData()) { - if (field->fld_type_of_table) + if (field->fld_type_of_table.hasData()) { dsql_rel* relation = METD_get_relation(dsqlScratch->getTransaction(), dsqlScratch, - field->fld_type_of_table->str_data); + field->fld_type_of_table.c_str()); const dsql_fld* fld = NULL; if (relation) @@ -345,7 +345,7 @@ // column @1 does not exist in table/view @2 post_607(Arg::Gds(isc_dyn_column_does_not_exist) << Arg::Str(field->fld_type_of_name) << - Arg::Str(field->fld_type_of_table->str_data)); + field->fld_type_of_table); } } else @@ -1929,7 +1929,7 @@ { dsqlScratch->appendString(isc_dyn_fld_source, field->fld_source); dsqlScratch->appendString(isc_dyn_fld_name, field->fld_type_of_name); - dsqlScratch->appendNullString(isc_dyn_rel_name, field->fld_type_of_table->str_data); + dsqlScratch->appendString(isc_dyn_rel_name, field->fld_type_of_table); } else dsqlScratch->appendString(isc_dyn_fld_source, field->fld_type_of_name); Modified: firebird/trunk/src/dsql/dsql.h =================================================================== --- firebird/trunk/src/dsql/dsql.h 2011-05-27 02:00:41 UTC (rev 53017) +++ firebird/trunk/src/dsql/dsql.h 2011-05-27 02:05:27 UTC (rev 53018) @@ -232,7 +232,7 @@ fld_collation_id(0), fld_ttype(0), fld_type_of_name(p), - fld_type_of_table(NULL), + fld_type_of_table(p), fld_explicit_collation(false), fld_not_nullable(false), fld_full_domain(false), @@ -263,7 +263,7 @@ SSHORT fld_collation_id; // ID of field's collation SSHORT fld_ttype; // ID of field's language_driver Firebird::string fld_type_of_name; // TYPE OF - dsql_str* fld_type_of_table; // TYPE OF table name + Firebird::string fld_type_of_table; // TYPE OF table name bool fld_explicit_collation; // COLLATE was explicit specified bool fld_not_nullable; // NOT NULL was explicit specified bool fld_full_domain; // Domain name without TYPE OF prefix Modified: firebird/trunk/src/dsql/metd.epp =================================================================== --- firebird/trunk/src/dsql/metd.epp 2011-05-27 02:00:41 UTC (rev 53017) +++ firebird/trunk/src/dsql/metd.epp 2011-05-27 02:05:27 UTC (rev 53018) @@ -1278,6 +1278,18 @@ if (FLD.RDB$FIELD_TYPE == blr_blob) parameter->fld_seg_length = FLD.RDB$SEGMENT_LENGTH; + if (!PR.RDB$FIELD_NAME.NULL) + { + fb_utils::exact_name(PR.RDB$FIELD_NAME); + parameter->fld_type_of_name = PR.RDB$FIELD_NAME; + } + + if (!PR.RDB$RELATION_NAME.NULL) + { + fb_utils::exact_name(PR.RDB$RELATION_NAME); + parameter->fld_type_of_table = PR.RDB$RELATION_NAME; + } + if (type == 0 && (!pr_default_value_null || (fb_utils::implicit_domain(FLD.RDB$FIELD_NAME) && !FLD.RDB$DEFAULT_VALUE.NULL))) Modified: firebird/trunk/src/dsql/parse.y =================================================================== --- firebird/trunk/src/dsql/parse.y 2011-05-27 02:00:41 UTC (rev 53017) +++ firebird/trunk/src/dsql/parse.y 2011-05-27 02:05:27 UTC (rev 53018) @@ -1826,7 +1826,7 @@ | KW_TYPE OF COLUMN symbol_column_name '.' symbol_column_name { lex.g_field = make_field(NULL); - lex.g_field->fld_type_of_table = ((dsql_str*) $4); + lex.g_field->fld_type_of_table = ((dsql_str*) $4)->str_data; lex.g_field->fld_type_of_name = ((dsql_str*) $6)->str_data; $$ = lex.g_field; } @@ -3509,7 +3509,7 @@ | KW_TYPE OF COLUMN symbol_column_name '.' symbol_column_name { lex.g_field->fld_type_of_name = ((dsql_str*) $6)->str_data; - lex.g_field->fld_type_of_table = ((dsql_str*) $4); + lex.g_field->fld_type_of_table = ((dsql_str*) $4)->str_data; } | symbol_column_name { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2011-05-27 15:29:26
|
Revision: 53026 http://firebird.svn.sourceforge.net/firebird/?rev=53026&view=rev Author: asfernandes Date: 2011-05-27 15:29:20 +0000 (Fri, 27 May 2011) Log Message: ----------- Fixed CORE-3475 - Parameters inside the CAST function are described as not nullable. Modified Paths: -------------- firebird/trunk/src/dsql/ExprNodes.cpp firebird/trunk/src/dsql/metd.epp Modified: firebird/trunk/src/dsql/ExprNodes.cpp =================================================================== --- firebird/trunk/src/dsql/ExprNodes.cpp 2011-05-27 11:31:29 UTC (rev 53025) +++ firebird/trunk/src/dsql/ExprNodes.cpp 2011-05-27 15:29:20 UTC (rev 53026) @@ -2657,6 +2657,8 @@ { parameter->par_node = dsqlSource; MAKE_desc_from_field(¶meter->par_desc, dsqlField); + if (!dsqlField->fld_full_domain) + parameter->par_desc.setNullable(true); return true; } } Modified: firebird/trunk/src/dsql/metd.epp =================================================================== --- firebird/trunk/src/dsql/metd.epp 2011-05-27 11:31:29 UTC (rev 53025) +++ firebird/trunk/src/dsql/metd.epp 2011-05-27 15:29:20 UTC (rev 53026) @@ -662,6 +662,9 @@ if (!FLX.RDB$COMPUTED_BLR.NULL) field->fld_flags |= FLD_computed; + if (FLX.RDB$NULL_FLAG.NULL || !FLX.RDB$NULL_FLAG) + field->fld_flags |= FLD_nullable; + if (FLX.RDB$SYSTEM_FLAG == 1) field->fld_flags |= FLD_system; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2011-09-25 23:28:15
|
Revision: 53472 http://firebird.svn.sourceforge.net/firebird/?rev=53472&view=rev Author: asfernandes Date: 2011-09-25 23:28:09 +0000 (Sun, 25 Sep 2011) Log Message: ----------- Fixed PSQL functions problem (missing EOS). Modified Paths: -------------- firebird/trunk/src/dsql/DdlNodes.epp firebird/trunk/src/dsql/DdlNodes.h firebird/trunk/src/dsql/DsqlCompilerScratch.cpp firebird/trunk/src/dsql/DsqlCompilerScratch.h firebird/trunk/src/dsql/parse.y Modified: firebird/trunk/src/dsql/DdlNodes.epp =================================================================== --- firebird/trunk/src/dsql/DdlNodes.epp 2011-09-24 03:18:01 UTC (rev 53471) +++ firebird/trunk/src/dsql/DdlNodes.epp 2011-09-25 23:28:09 UTC (rev 53472) @@ -774,7 +774,7 @@ ParameterClause::ParameterClause(MemoryPool& pool, dsql_fld* field, const MetaName& aCollate, dsql_nod* dflt, dsql_nod* aLegacyParameter) : TypeClause(pool, field, aCollate), - name(field->fld_name), + name(pool, field ? field->fld_name : ""), legacyDefault(dflt), legacyParameter(aLegacyParameter) { @@ -1626,42 +1626,10 @@ dsqlScratch->appendUChar(blr_begin); - if (parameters.getCount() != 0) - { - fb_assert(parameters.getCount() < size_t(MAX_USHORT / 2)); - dsqlScratch->appendUChar(blr_message); - dsqlScratch->appendUChar(0); - dsqlScratch->appendUShort(2 * parameters.getCount()); + Array<ParameterClause> returns; + returns.add(returnType); + dsqlScratch->genParameters(parameters, returns); - for (unsigned i = 0; i < parameters.getCount(); ++i) - { - ParameterClause& parameter = parameters[i]; - dsqlScratch->putDebugArgument(fb_dbg_arg_input, i, - parameter.name.c_str()); - dsqlScratch->putType(parameter, true); - - // add slot for null flag (parameter2) - dsqlScratch->appendUChar(blr_short); - dsqlScratch->appendUChar(0); - - dsqlScratch->makeVariable(parameter.legacyField, parameter.name.c_str(), - dsql_var::TYPE_INPUT, 0, (USHORT) (2 * i), 0); - } - } - - dsqlScratch->appendUChar(blr_message); - dsqlScratch->appendUChar(1); - dsqlScratch->appendUShort(2); - - dsqlScratch->putDebugArgument(fb_dbg_arg_output, 0, ""); - dsqlScratch->putType(returnType, true); - - // add slot for null flag (parameter2) - dsqlScratch->appendUChar(blr_short); - dsqlScratch->appendUChar(0); - - dsqlScratch->makeVariable(returnType.legacyField, "", dsql_var::TYPE_OUTPUT, 1, 0, 0); - if (parameters.getCount() != 0) { dsqlScratch->appendUChar(blr_receive); @@ -2421,54 +2389,8 @@ dsqlScratch->appendUChar(blr_begin); - if (parameters.getCount() != 0) - { - fb_assert(parameters.getCount() < MAX_USHORT / 2); - dsqlScratch->appendUChar(blr_message); - dsqlScratch->appendUChar(0); - dsqlScratch->appendUShort(2 * parameters.getCount()); + dsqlScratch->genParameters(parameters, returns); - for (unsigned i = 0; i < parameters.getCount(); ++i) - { - ParameterClause& parameter = parameters[i]; - dsqlScratch->putDebugArgument(fb_dbg_arg_input, i, parameter.name.c_str()); - dsqlScratch->putType(parameter, true); - - // add slot for null flag (parameter2) - dsqlScratch->appendUChar(blr_short); - dsqlScratch->appendUChar(0); - - dsqlScratch->makeVariable(parameter.legacyField, parameter.name.c_str(), - dsql_var::TYPE_INPUT, 0, (USHORT) (2 * i), 0); - } - } - - fb_assert(returns.getCount() < MAX_USHORT / 2); - dsqlScratch->appendUChar(blr_message); - dsqlScratch->appendUChar(1); - dsqlScratch->appendUShort(2 * returns.getCount() + 1); - - if (returns.getCount() != 0) - { - for (unsigned i = 0; i < returns.getCount(); ++i) - { - ParameterClause& parameter = returns[i]; - dsqlScratch->putDebugArgument(fb_dbg_arg_output, i, parameter.name.c_str()); - dsqlScratch->putType(parameter, true); - - // add slot for null flag (parameter2) - dsqlScratch->appendUChar(blr_short); - dsqlScratch->appendUChar(0); - - dsqlScratch->makeVariable(parameter.legacyField, parameter.name.c_str(), - dsql_var::TYPE_OUTPUT, 1, (USHORT) (2 * i), i); - } - } - - // add slot for EOS - dsqlScratch->appendUChar(blr_short); - dsqlScratch->appendUChar(0); - if (parameters.getCount() != 0) { dsqlScratch->appendUChar(blr_receive); Modified: firebird/trunk/src/dsql/DdlNodes.h =================================================================== --- firebird/trunk/src/dsql/DdlNodes.h 2011-09-24 03:18:01 UTC (rev 53471) +++ firebird/trunk/src/dsql/DdlNodes.h 2011-09-25 23:28:09 UTC (rev 53472) @@ -242,7 +242,7 @@ external(NULL), deterministic(false), parameters(pool), - returnType(pool, NULL, NULL), + returnType(pool, NULL, NULL, NULL, NULL), localDeclList(NULL), source(pool), body(NULL), @@ -286,7 +286,7 @@ ExternalClause* external; bool deterministic; Firebird::Array<ParameterClause> parameters; - TypeClause returnType; + ParameterClause returnType; NestConst<CompoundStmtNode> localDeclList; Firebird::string source; NestConst<StmtNode> body; Modified: firebird/trunk/src/dsql/DsqlCompilerScratch.cpp =================================================================== --- firebird/trunk/src/dsql/DsqlCompilerScratch.cpp 2011-09-24 03:18:01 UTC (rev 53471) +++ firebird/trunk/src/dsql/DsqlCompilerScratch.cpp 2011-09-25 23:28:09 UTC (rev 53472) @@ -436,6 +436,58 @@ } } +void DsqlCompilerScratch::genParameters(Array<ParameterClause>& parameters, + Array<ParameterClause>& returns) +{ + if (parameters.hasData()) + { + fb_assert(parameters.getCount() < MAX_USHORT / 2); + appendUChar(blr_message); + appendUChar(0); + appendUShort(2 * parameters.getCount()); + + for (size_t i = 0; i < parameters.getCount(); ++i) + { + ParameterClause& parameter = parameters[i]; + putDebugArgument(fb_dbg_arg_input, i, parameter.name.c_str()); + putType(parameter, true); + + // Add slot for null flag (parameter2). + appendUChar(blr_short); + appendUChar(0); + + makeVariable(parameter.legacyField, parameter.name.c_str(), + dsql_var::TYPE_INPUT, 0, (USHORT) (2 * i), 0); + } + } + + fb_assert(returns.getCount() < MAX_USHORT / 2); + appendUChar(blr_message); + appendUChar(1); + appendUShort(2 * returns.getCount() + 1); + + if (returns.hasData()) + { + for (size_t i = 0; i < returns.getCount(); ++i) + { + ParameterClause& parameter = returns[i]; + putDebugArgument(fb_dbg_arg_output, i, parameter.name.c_str()); + putType(parameter, true); + + // Add slot for null flag (parameter2). + appendUChar(blr_short); + appendUChar(0); + + makeVariable(parameter.legacyField, parameter.name.c_str(), + dsql_var::TYPE_OUTPUT, 1, (USHORT) (2 * i), i); + } + } + + // Add slot for EOS. + appendUChar(blr_short); + appendUChar(0); +} + void DsqlCompilerScratch::addCTEs(dsql_nod* with) { DEV_BLKCHK(with, dsql_type_nod); Modified: firebird/trunk/src/dsql/DsqlCompilerScratch.h =================================================================== --- firebird/trunk/src/dsql/DsqlCompilerScratch.h 2011-09-24 03:18:01 UTC (rev 53471) +++ firebird/trunk/src/dsql/DsqlCompilerScratch.h 2011-09-25 23:28:09 UTC (rev 53472) @@ -37,6 +37,7 @@ class CompoundStmtNode; class DeclareCursorNode; class DeclareVariableNode; +class ParameterClause; class TypeClause; class VariableNode; @@ -164,6 +165,9 @@ dsql_var* resolveVariable(const dsql_str* varName); void genReturn(bool eosFlag = false); + void genParameters(Firebird::Array<ParameterClause>& parameters, + Firebird::Array<ParameterClause>& returns); + void resetContextStack() { context->clear(); Modified: firebird/trunk/src/dsql/parse.y =================================================================== --- firebird/trunk/src/dsql/parse.y 2011-09-24 03:18:01 UTC (rev 53471) +++ firebird/trunk/src/dsql/parse.y 2011-09-25 23:28:09 UTC (rev 53472) @@ -2081,7 +2081,7 @@ domain_or_non_array_type collate_clause deterministic_opt { $$ = $2; - $$->returnType = TypeClause(getPool(), $<legacyField>5, toName($7)); + $$->returnType = ParameterClause(getPool(), $<legacyField>5, toName($7), NULL, NULL); $$->deterministic = ($8 != NULL); } ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2011-11-14 18:06:51
|
Revision: 53629 http://firebird.svn.sourceforge.net/firebird/?rev=53629&view=rev Author: asfernandes Date: 2011-11-14 18:06:44 +0000 (Mon, 14 Nov 2011) Log Message: ----------- Misc. Modified Paths: -------------- firebird/trunk/src/dsql/DdlNodes.epp firebird/trunk/src/dsql/node.h firebird/trunk/src/dsql/parse.y Modified: firebird/trunk/src/dsql/DdlNodes.epp =================================================================== --- firebird/trunk/src/dsql/DdlNodes.epp 2011-11-14 03:18:14 UTC (rev 53628) +++ firebird/trunk/src/dsql/DdlNodes.epp 2011-11-14 18:06:44 UTC (rev 53629) @@ -8901,19 +8901,19 @@ if (name == ownerName) { - // msg 193: "user name could not be used for SQL role" + // msg 193: "user name @1 could not be used for SQL role" status_exception::raise(Arg::Gds(ENCODE_ISC_MSG(193, DYN_MSG_FAC)) << ownerName); } if (name == NULL_ROLE) { - // msg 195: "keyword NONE could not be used as SQL role name" + // msg 195: "keyword @1 could not be used as SQL role name" status_exception::raise(Arg::Gds(ENCODE_ISC_MSG(195, DYN_MSG_FAC)) << name); } if (isItUserName(tdbb, transaction)) { - // msg 193: "user name could not be used for SQL role" + // msg 193: "user name @1 could not be used for SQL role" status_exception::raise(Arg::Gds(ENCODE_ISC_MSG(193, DYN_MSG_FAC)) << name); } Modified: firebird/trunk/src/dsql/node.h =================================================================== --- firebird/trunk/src/dsql/node.h 2011-11-14 03:18:14 UTC (rev 53628) +++ firebird/trunk/src/dsql/node.h 2011-11-14 18:06:44 UTC (rev 53629) @@ -371,9 +371,6 @@ e_mod_role_action, // 0 - drop, 1 - add e_mod_role_count, - e_del_user_name = 0, // nod_del_user - e_del_user_count, - e_user_name = 0, // nod_add(mod)_user e_user_passwd, e_user_first, Modified: firebird/trunk/src/dsql/parse.y =================================================================== --- firebird/trunk/src/dsql/parse.y 2011-11-14 03:18:14 UTC (rev 53628) +++ firebird/trunk/src/dsql/parse.y 2011-11-14 18:06:44 UTC (rev 53629) @@ -3557,34 +3557,35 @@ // these are the allowable datatypes -data_type : non_array_type - | array_type - ; +data_type + : non_array_type + | array_type + ; domain_or_non_array_type - : domain_or_non_array_type_name - | domain_or_non_array_type_name NOT KW_NULL - { lex.g_field->fld_not_nullable = true; } + : domain_or_non_array_type_name + | domain_or_non_array_type_name NOT KW_NULL + { lex.g_field->fld_not_nullable = true; } ; domain_or_non_array_type_name - : non_array_type - | domain_type + : non_array_type + | domain_type ; domain_type - : KW_TYPE OF symbol_column_name - { lex.g_field->fld_type_of_name = ((dsql_str*) $3)->str_data; } - | KW_TYPE OF COLUMN symbol_column_name '.' symbol_column_name - { - lex.g_field->fld_type_of_name = ((dsql_str*) $6)->str_data; - lex.g_field->fld_type_of_table = ((dsql_str*) $4)->str_data; - } - | symbol_column_name - { - lex.g_field->fld_type_of_name = ((dsql_str*) $1)->str_data; - lex.g_field->fld_full_domain = true; - } + : KW_TYPE OF symbol_column_name + { lex.g_field->fld_type_of_name = ((dsql_str*) $3)->str_data; } + | KW_TYPE OF COLUMN symbol_column_name '.' symbol_column_name + { + lex.g_field->fld_type_of_name = ((dsql_str*) $6)->str_data; + lex.g_field->fld_type_of_table = ((dsql_str*) $4)->str_data; + } + | symbol_column_name + { + lex.g_field->fld_type_of_name = ((dsql_str*) $1)->str_data; + lex.g_field->fld_full_domain = true; + } ; @@ -3840,122 +3841,125 @@ // numeric type -numeric_type : KW_NUMERIC prec_scale - { lex.g_field->fld_sub_type = dsc_num_type_numeric; } - | decimal_keyword prec_scale +numeric_type + : KW_NUMERIC prec_scale + { lex.g_field->fld_sub_type = dsc_num_type_numeric; } + | decimal_keyword prec_scale + { + lex.g_field->fld_sub_type = dsc_num_type_decimal; + if (lex.g_field->fld_dtype == dtype_short) { - lex.g_field->fld_sub_type = dsc_num_type_decimal; - if (lex.g_field->fld_dtype == dtype_short) - { - lex.g_field->fld_dtype = dtype_long; - lex.g_field->fld_length = sizeof (SLONG); - } - } - ; - -prec_scale : - { lex.g_field->fld_dtype = dtype_long; lex.g_field->fld_length = sizeof (SLONG); - lex.g_field->fld_precision = 9; } - | '(' signed_long_integer ')' + } + ; + +prec_scale + : // nothing + { + lex.g_field->fld_dtype = dtype_long; + lex.g_field->fld_length = sizeof (SLONG); + lex.g_field->fld_precision = 9; + } + | '(' signed_long_integer ')' + { + if ($2 < 1 || $2 > 18) + yyabandon(-842, isc_precision_err); // Precision must be between 1 and 18. + if ($2 > 9) { - if ($2 < 1 || $2 > 18) - yyabandon(-842, isc_precision_err); // Precision must be between 1 and 18. - if ($2 > 9) + if ( ( (client_dialect <= SQL_DIALECT_V5) && (db_dialect > SQL_DIALECT_V5) ) || + ( (client_dialect > SQL_DIALECT_V5) && (db_dialect <= SQL_DIALECT_V5) ) ) { - if ( ( (client_dialect <= SQL_DIALECT_V5) && (db_dialect > SQL_DIALECT_V5) ) || - ( (client_dialect > SQL_DIALECT_V5) && (db_dialect <= SQL_DIALECT_V5) ) ) - { - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-817) << - Arg::Gds(isc_ddl_not_allowed_by_db_sql_dial) << Arg::Num(db_dialect)); - } - if (client_dialect <= SQL_DIALECT_V5) - { - lex.g_field->fld_dtype = dtype_double; - lex.g_field->fld_length = sizeof (double); - } - else - { - if (client_dialect == SQL_DIALECT_V6_TRANSITION) - { - ERRD_post_warning(Arg::Warning(isc_dsql_warn_precision_ambiguous)); - ERRD_post_warning(Arg::Warning(isc_dsql_warn_precision_ambiguous1)); - ERRD_post_warning(Arg::Warning(isc_dsql_warn_precision_ambiguous2)); - } - lex.g_field->fld_dtype = dtype_int64; - lex.g_field->fld_length = sizeof (SINT64); - } + ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-817) << + Arg::Gds(isc_ddl_not_allowed_by_db_sql_dial) << Arg::Num(db_dialect)); } + if (client_dialect <= SQL_DIALECT_V5) + { + lex.g_field->fld_dtype = dtype_double; + lex.g_field->fld_length = sizeof (double); + } else { - if ($2 < 5) + if (client_dialect == SQL_DIALECT_V6_TRANSITION) { - lex.g_field->fld_dtype = dtype_short; - lex.g_field->fld_length = sizeof (SSHORT); + ERRD_post_warning(Arg::Warning(isc_dsql_warn_precision_ambiguous)); + ERRD_post_warning(Arg::Warning(isc_dsql_warn_precision_ambiguous1)); + ERRD_post_warning(Arg::Warning(isc_dsql_warn_precision_ambiguous2)); } - else - { - lex.g_field->fld_dtype = dtype_long; - lex.g_field->fld_length = sizeof (SLONG); - } + lex.g_field->fld_dtype = dtype_int64; + lex.g_field->fld_length = sizeof (SINT64); } - lex.g_field->fld_precision = (USHORT) $2; } - | '(' signed_long_integer ',' signed_long_integer ')' + else { - if ($2 < 1 || $2 > 18) - yyabandon (-842, isc_precision_err); // Precision should be between 1 and 18 - if ($4 > $2 || $4 < 0) - yyabandon (-842, isc_scale_nogt); // Scale must be between 0 and precision - if ($2 > 9) + if ($2 < 5) { - if ( ( (client_dialect <= SQL_DIALECT_V5) && (db_dialect > SQL_DIALECT_V5) ) || - ( (client_dialect > SQL_DIALECT_V5) && (db_dialect <= SQL_DIALECT_V5) ) ) - { - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-817) << - Arg::Gds(isc_ddl_not_allowed_by_db_sql_dial) << Arg::Num(db_dialect)); - } - if (client_dialect <= SQL_DIALECT_V5) - { - lex.g_field->fld_dtype = dtype_double; - lex.g_field->fld_length = sizeof (double); - } - else - { - if (client_dialect == SQL_DIALECT_V6_TRANSITION) - { - ERRD_post_warning(Arg::Warning(isc_dsql_warn_precision_ambiguous)); - ERRD_post_warning(Arg::Warning(isc_dsql_warn_precision_ambiguous1)); - ERRD_post_warning(Arg::Warning(isc_dsql_warn_precision_ambiguous2)); - } - // client_dialect >= SQL_DIALECT_V6 - lex.g_field->fld_dtype = dtype_int64; - lex.g_field->fld_length = sizeof (SINT64); - } + lex.g_field->fld_dtype = dtype_short; + lex.g_field->fld_length = sizeof (SSHORT); } else { - if ($2 < 5) + lex.g_field->fld_dtype = dtype_long; + lex.g_field->fld_length = sizeof (SLONG); + } + } + lex.g_field->fld_precision = (USHORT) $2; + } + | '(' signed_long_integer ',' signed_long_integer ')' + { + if ($2 < 1 || $2 > 18) + yyabandon (-842, isc_precision_err); // Precision should be between 1 and 18 + if ($4 > $2 || $4 < 0) + yyabandon (-842, isc_scale_nogt); // Scale must be between 0 and precision + if ($2 > 9) + { + if ( ( (client_dialect <= SQL_DIALECT_V5) && (db_dialect > SQL_DIALECT_V5) ) || + ( (client_dialect > SQL_DIALECT_V5) && (db_dialect <= SQL_DIALECT_V5) ) ) + { + ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-817) << + Arg::Gds(isc_ddl_not_allowed_by_db_sql_dial) << Arg::Num(db_dialect)); + } + if (client_dialect <= SQL_DIALECT_V5) + { + lex.g_field->fld_dtype = dtype_double; + lex.g_field->fld_length = sizeof (double); + } + else + { + if (client_dialect == SQL_DIALECT_V6_TRANSITION) { - lex.g_field->fld_dtype = dtype_short; - lex.g_field->fld_length = sizeof (SSHORT); + ERRD_post_warning(Arg::Warning(isc_dsql_warn_precision_ambiguous)); + ERRD_post_warning(Arg::Warning(isc_dsql_warn_precision_ambiguous1)); + ERRD_post_warning(Arg::Warning(isc_dsql_warn_precision_ambiguous2)); } - else - { - lex.g_field->fld_dtype = dtype_long; - lex.g_field->fld_length = sizeof (SLONG); - } + // client_dialect >= SQL_DIALECT_V6 + lex.g_field->fld_dtype = dtype_int64; + lex.g_field->fld_length = sizeof (SINT64); } - lex.g_field->fld_precision = (USHORT) $2; - lex.g_field->fld_scale = - (SSHORT) $4; } - ; + else + { + if ($2 < 5) + { + lex.g_field->fld_dtype = dtype_short; + lex.g_field->fld_length = sizeof (SSHORT); + } + else + { + lex.g_field->fld_dtype = dtype_long; + lex.g_field->fld_length = sizeof (SLONG); + } + } + lex.g_field->fld_precision = (USHORT) $2; + lex.g_field->fld_scale = - (SSHORT) $4; + } + ; -decimal_keyword : DECIMAL - | KW_DEC - ; +decimal_keyword + : DECIMAL + | KW_DEC + ; @@ -3993,7 +3997,7 @@ ; precision_opt - : + : // nothing { $$ = 0; } | '(' nonneg_short_integer ')' { $$ = $2; } @@ -4637,33 +4641,31 @@ // other clauses in the select expression -group_clause : GROUP BY group_by_list - { $$ = make_list ($3); } - | - { $$ = NULL; } - ; +group_clause + : /* nothing */ { $$ = NULL; } + | GROUP BY group_by_list { $$ = make_list ($3); } + ; -group_by_list : group_by_item - | group_by_list ',' group_by_item - { $$ = make_node (nod_list, 2, $1, $3); } - ; +group_by_list + : group_by_item + | group_by_list ',' group_by_item { $$ = make_node (nod_list, 2, $1, $3); } + ; // Except aggregate-functions are all expressions supported in group_by_item, // they are caught inside pass1.cpp -group_by_item : value - ; +group_by_item + : value + ; -having_clause : HAVING search_condition - { $$ = $2; } - | - { $$ = NULL; } - ; +having_clause + : /* nothing */ { $$ = NULL; } + | HAVING search_condition { $$ = $2; } + ; -where_clause : WHERE search_condition - { $$ = $2; } - | - { $$ = NULL; } - ; +where_clause + : /* nothing */ { $$ = NULL; } + | WHERE search_condition { $$ = $2; } + ; // PLAN clause to specify an access plan for a query @@ -5265,7 +5267,7 @@ ; escape_opt - : { $$ = NULL; } + : /* nothing */ { $$ = NULL; } | ESCAPE common_value { $$ = $2; } ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2011-11-24 00:17:35
|
Revision: 53643 http://firebird.svn.sourceforge.net/firebird/?rev=53643&view=rev Author: asfernandes Date: 2011-11-24 00:17:29 +0000 (Thu, 24 Nov 2011) Log Message: ----------- Misc. Modified Paths: -------------- firebird/trunk/src/dsql/DdlNodes.h firebird/trunk/src/dsql/ddl.cpp firebird/trunk/src/dsql/node.h firebird/trunk/src/dsql/pass1.cpp Modified: firebird/trunk/src/dsql/DdlNodes.h =================================================================== --- firebird/trunk/src/dsql/DdlNodes.h 2011-11-23 03:20:41 UTC (rev 53642) +++ firebird/trunk/src/dsql/DdlNodes.h 2011-11-24 00:17:29 UTC (rev 53643) @@ -333,8 +333,6 @@ }; - - class AlterExternalFunctionNode : public DdlNode { public: Modified: firebird/trunk/src/dsql/ddl.cpp =================================================================== --- firebird/trunk/src/dsql/ddl.cpp 2011-11-23 03:20:41 UTC (rev 53642) +++ firebird/trunk/src/dsql/ddl.cpp 2011-11-24 00:17:29 UTC (rev 53643) @@ -163,16 +163,8 @@ } #endif - // for delete & modify, get rid of the cached relation metadata - - const dsql_str* string = NULL; - SYM_TYPE sym_type; - const NOD_TYPE type = statement->getDdlNode()->nod_type; - if (string) - MET_dsql_cache_release(tdbb, sym_type, string->str_data); - if (type == nod_class_stmtnode) { fb_utils::init_status(tdbb->tdbb_status_vector); // Do the same as DYN_ddl does. @@ -828,8 +820,6 @@ * DYN string. * **************************************/ - const dsql_str* string; - switch (node->nod_type) { case nod_def_index: Modified: firebird/trunk/src/dsql/node.h =================================================================== --- firebird/trunk/src/dsql/node.h 2011-11-23 03:20:41 UTC (rev 53642) +++ firebird/trunk/src/dsql/node.h 2011-11-24 00:17:29 UTC (rev 53643) @@ -112,8 +112,6 @@ nod_natural, nod_index, nod_index_order, - nod_idx_active, - nod_idx_inactive, nod_restrict, // drop behaviour nod_cascade, nod_ref_upd_del, // referential integrity actions @@ -131,8 +129,6 @@ nod_with, nod_add_user, nod_mod_user, - nod_trg_act, - nod_trg_ext, nod_class_stmtnode, nod_class_exprnode, nod_package_name, Modified: firebird/trunk/src/dsql/pass1.cpp =================================================================== --- firebird/trunk/src/dsql/pass1.cpp 2011-11-23 03:20:41 UTC (rev 53642) +++ firebird/trunk/src/dsql/pass1.cpp 2011-11-24 00:17:29 UTC (rev 53643) @@ -4903,12 +4903,6 @@ case nod_def_computed: verb = "def_computed"; break; - case nod_idx_active: - verb = "idx_active"; - break; - case nod_idx_inactive: - verb = "idx_inactive"; - break; case nod_restrict: verb = "restrict"; break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2011-12-28 01:20:18
|
Revision: 53779 http://firebird.svn.sourceforge.net/firebird/?rev=53779&view=rev Author: asfernandes Date: 2011-12-28 01:20:11 +0000 (Wed, 28 Dec 2011) Log Message: ----------- Warning. Modified Paths: -------------- firebird/trunk/src/dsql/ExprNodes.cpp firebird/trunk/src/dsql/ExprNodes.h Modified: firebird/trunk/src/dsql/ExprNodes.cpp =================================================================== --- firebird/trunk/src/dsql/ExprNodes.cpp 2011-12-28 01:07:49 UTC (rev 53778) +++ firebird/trunk/src/dsql/ExprNodes.cpp 2011-12-28 01:20:11 UTC (rev 53779) @@ -5362,7 +5362,7 @@ } bool GenIdNode::setParameterType(DsqlCompilerScratch* dsqlScratch, - dsql_nod* node, bool forceVarChar) const + dsql_nod* node, bool forceVarChar) { return PASS1_set_parameter_type(dsqlScratch, dsqlArg, node, forceVarChar); } Modified: firebird/trunk/src/dsql/ExprNodes.h =================================================================== --- firebird/trunk/src/dsql/ExprNodes.h 2011-12-28 01:07:49 UTC (rev 53778) +++ firebird/trunk/src/dsql/ExprNodes.h 2011-12-28 01:20:11 UTC (rev 53779) @@ -574,7 +574,7 @@ virtual ValueExprNode* dsqlPass(DsqlCompilerScratch* dsqlScratch); virtual void setParameterName(dsql_par* parameter) const; virtual bool setParameterType(DsqlCompilerScratch* dsqlScratch, - dsql_nod* node, bool forceVarChar) const; + dsql_nod* node, bool forceVarChar); virtual void genBlr(DsqlCompilerScratch* dsqlScratch); virtual void make(DsqlCompilerScratch* dsqlScratch, dsc* desc); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2012-01-06 14:33:08
|
Revision: 53815 http://firebird.svn.sourceforge.net/firebird/?rev=53815&view=rev Author: asfernandes Date: 2012-01-06 14:33:01 +0000 (Fri, 06 Jan 2012) Log Message: ----------- Improvement CORE-3343 - RETURNING clause is not supported in positioned (WHERE CURRENT OF) UPDATE and DELETE statements. Modified Paths: -------------- firebird/trunk/src/dsql/StmtNodes.cpp firebird/trunk/src/dsql/parse.y Modified: firebird/trunk/src/dsql/StmtNodes.cpp =================================================================== --- firebird/trunk/src/dsql/StmtNodes.cpp 2012-01-06 11:25:17 UTC (rev 53814) +++ firebird/trunk/src/dsql/StmtNodes.cpp 2012-01-06 14:33:01 UTC (rev 53815) @@ -1900,7 +1900,16 @@ if (cursor && dsqlScratch->isPsql()) { node->dsqlContext = dsqlPassCursorContext(dsqlScratch, cursor, relation); + + // Process old context values. + dsqlScratch->context->push(node->dsqlContext); + ++dsqlScratch->scopeLevel; + node->statement = dsqlProcessReturning(dsqlScratch, dsqlReturning, statement); + + --dsqlScratch->scopeLevel; + dsqlScratch->context->pop(); + return SavepointEncloseNode::make(getPool(), dsqlScratch, node); } @@ -1936,11 +1945,11 @@ PASS1_limit(dsqlScratch, temp->nod_arg[Dsql::e_rows_length], temp->nod_arg[Dsql::e_rows_skip], rse); } - - if (dsqlReturning || statement) - rseNod->nod_flags |= NOD_SELECT_EXPR_SINGLETON; } + if (dsqlReturning || statement) + rseNod->nod_flags |= NOD_SELECT_EXPR_SINGLETON; + node->dsqlRse = rseNod; node->dsqlRelation = ExprNode::as<RseNode>(rseNod)->dsqlStreams->nod_arg[0]; @@ -5397,8 +5406,18 @@ for (ptr = new_values.begin(); ptr != new_values.end(); ++ptr) *ptr = PASS1_node_psql(dsqlScratch, *ptr, false); - node->statement2 = dsqlProcessReturning(dsqlScratch, dsqlReturning, statement2); + dsqlScratch->context->pop(); + dsql_ctx* oldContext = node->dsqlContext; + dsql_ctx* modContext = dsqlGetContext(node->dsqlRelation); + + dsqlScratch->context->push(oldContext); // process old context values + ++dsqlScratch->scopeLevel; + + node->statement2 = ReturningProcessor(dsqlScratch, oldContext, modContext).process( + dsqlReturning, statement2); + + --dsqlScratch->scopeLevel; dsqlScratch->context->pop(); // Recreate list of assignments. @@ -5444,9 +5463,15 @@ // Generate record selection expression dsql_nod* rseNod; + dsql_ctx* old_context; if (cursor) + { rseNod = dsqlPassCursorReference(dsqlScratch, cursor, relation); + + dsql_nod* temp = ExprNode::as<RseNode>(rseNod)->dsqlStreams->nod_arg[0]; + old_context = ExprNode::as<RelationSourceNode>(temp)->dsqlContext; + } else { RseNode* rse = FB_NEW(pool) RseNode(pool); @@ -5461,7 +5486,7 @@ dsql_nod* temp = MAKE_node(Dsql::nod_list, 1); rse->dsqlStreams = temp; temp->nod_arg[0] = PASS1_node_psql(dsqlScratch, relation, false); - dsql_ctx* old_context = dsqlGetContext(temp->nod_arg[0]); + old_context = dsqlGetContext(temp->nod_arg[0]); if ((temp = dsqlBoolean)) rse->dsqlWhere = PASS1_node_psql(dsqlScratch, temp, false); @@ -5477,12 +5502,12 @@ PASS1_limit(dsqlScratch, temp->nod_arg[Dsql::e_rows_length], temp->nod_arg[Dsql::e_rows_skip], rse); } + } - if (dsqlReturning || statement2) - { - node->statement2 = ReturningProcessor( - dsqlScratch, old_context, mod_context).process(dsqlReturning, statement2); - } + if (dsqlReturning || statement2) + { + node->statement2 = ReturningProcessor(dsqlScratch, old_context, mod_context).process( + dsqlReturning, statement2); } node->dsqlRse = rseNod; Modified: firebird/trunk/src/dsql/parse.y =================================================================== --- firebird/trunk/src/dsql/parse.y 2012-01-06 11:25:17 UTC (rev 53814) +++ firebird/trunk/src/dsql/parse.y 2012-01-06 14:33:01 UTC (rev 53815) @@ -4967,11 +4967,12 @@ ; delete_positioned - : KW_DELETE FROM table_name cursor_clause + : KW_DELETE FROM table_name cursor_clause returning_clause { EraseNode* node = newNode<EraseNode>(); node->dsqlRelation = $3; node->dsqlCursor = $4; + node->dsqlReturning = $5; $$ = node; } ; @@ -5001,12 +5002,13 @@ ; update_positioned - : UPDATE table_name SET assignments cursor_clause + : UPDATE table_name SET assignments cursor_clause returning_clause { ModifyNode* node = newNode<ModifyNode>(); node->dsqlRelation = $2; node->statement = $4; node->dsqlCursor = $5; + node->dsqlReturning = $6; $$ = node; } ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2012-01-19 17:31:09
|
Revision: 53894 http://firebird.svn.sourceforge.net/firebird/?rev=53894&view=rev Author: asfernandes Date: 2012-01-19 17:30:58 +0000 (Thu, 19 Jan 2012) Log Message: ----------- Fixed CORE-3737 - EXECUTE BLOCK parameters definitions are not respected and may cause wrong behavior related to character sets. Modified Paths: -------------- firebird/trunk/src/dsql/DsqlCompilerScratch.cpp firebird/trunk/src/dsql/ExprNodes.cpp firebird/trunk/src/dsql/StmtNodes.cpp Modified: firebird/trunk/src/dsql/DsqlCompilerScratch.cpp =================================================================== --- firebird/trunk/src/dsql/DsqlCompilerScratch.cpp 2012-01-19 15:34:03 UTC (rev 53893) +++ firebird/trunk/src/dsql/DsqlCompilerScratch.cpp 2012-01-19 17:30:58 UTC (rev 53894) @@ -320,10 +320,24 @@ // Check for a default value, borrowed from define_domain dsql_nod* node = hostParam ? hostParam->dsqlDef->legacyDefault : NULL; - if (node || (!field->fld_full_domain && !field->fld_not_nullable)) + if (variable->type == dsql_var::TYPE_INPUT) { + // Assign EXECUTE BLOCK's input parameter to its correspondent internal variable. + appendUChar(blr_assignment); + appendUChar(blr_parameter2); + appendUChar(variable->msgNumber); + appendUShort(variable->msgItem); + appendUShort(variable->msgItem + 1); + + appendUChar(blr_variable); + appendUShort(variable->number); + } + else if (node || (!field->fld_full_domain && !field->fld_not_nullable)) + { + appendUChar(blr_assignment); + if (node) { fb_assert(node->nod_type == Dsql::nod_def_default); Modified: firebird/trunk/src/dsql/ExprNodes.cpp =================================================================== --- firebird/trunk/src/dsql/ExprNodes.cpp 2012-01-19 15:34:03 UTC (rev 53893) +++ firebird/trunk/src/dsql/ExprNodes.cpp 2012-01-19 17:30:58 UTC (rev 53894) @@ -10741,7 +10741,13 @@ void VariableNode::genBlr(DsqlCompilerScratch* dsqlScratch) { - if (dsqlVar->type == dsql_var::TYPE_INPUT) + bool execBlock = (dsqlScratch->flags & DsqlCompilerScratch::FLAG_BLOCK) && + !(dsqlScratch->flags & + (DsqlCompilerScratch::FLAG_PROCEDURE | + DsqlCompilerScratch::FLAG_TRIGGER | + DsqlCompilerScratch::FLAG_FUNCTION)); + + if (dsqlVar->type == dsql_var::TYPE_INPUT && !execBlock) { dsqlScratch->appendUChar(blr_parameter2); dsqlScratch->appendUChar(dsqlVar->msgNumber); @@ -10750,6 +10756,7 @@ } else { + // If this is an EXECUTE BLOCK input parameter, use the internal variable. dsqlScratch->appendUChar(blr_variable); dsqlScratch->appendUShort(dsqlVar->number); } Modified: firebird/trunk/src/dsql/StmtNodes.cpp =================================================================== --- firebird/trunk/src/dsql/StmtNodes.cpp 2012-01-19 15:34:03 UTC (rev 53893) +++ firebird/trunk/src/dsql/StmtNodes.cpp 2012-01-19 17:30:58 UTC (rev 53894) @@ -3799,7 +3799,7 @@ ParameterClause& parameter = parameters[i]; dsqlScratch->makeVariable(parameter.legacyField, parameter.name.c_str(), - dsql_var::TYPE_INPUT, 0, (USHORT) (2 * i), 0); + dsql_var::TYPE_INPUT, 0, (USHORT) (2 * i), i); } returnsPos = dsqlScratch->variables.getCount(); @@ -3810,7 +3810,7 @@ ParameterClause& parameter = returns[i]; dsqlScratch->makeVariable(parameter.legacyField, parameter.name.c_str(), - dsql_var::TYPE_OUTPUT, 1, (USHORT) (2 * i), i); + dsql_var::TYPE_OUTPUT, 1, (USHORT) (2 * i), parameters.getCount() + i); } } @@ -3869,42 +3869,37 @@ dsqlScratch->appendUChar(blr_begin); - for (unsigned i = 0; i < returnsPos; ++i) + if (subRoutine) { - const dsql_var* variable = dsqlScratch->variables[i]; - const dsql_fld* field = variable->field; + // This validation is needed only for subroutines. Standard EXECUTE BLOCK moves input + // parameters to variables and are then validated. - if (field->fld_full_domain || field->fld_not_nullable) + for (unsigned i = 0; i < returnsPos; ++i) { - dsqlScratch->appendUChar(blr_assignment); + const dsql_var* variable = dsqlScratch->variables[i]; + const dsql_fld* field = variable->field; - // ASF: Validation of execute block input parameters is different than procedure - // parameters, because we can't generate messages using the domains due to the - // connection charset influence. So to validate, we cast them and assign to null. - if (!subRoutine) + if (field->fld_full_domain || field->fld_not_nullable) { - dsqlScratch->appendUChar(blr_cast); - dsqlScratch->putDtype(field, true); + dsqlScratch->appendUChar(blr_assignment); + dsqlScratch->appendUChar(blr_parameter2); + dsqlScratch->appendUChar(0); + dsqlScratch->appendUShort(variable->msgItem); + dsqlScratch->appendUShort(variable->msgItem + 1); + dsqlScratch->appendUChar(blr_null); } - - dsqlScratch->appendUChar(blr_parameter2); - dsqlScratch->appendUChar(0); - dsqlScratch->appendUShort(variable->msgItem); - dsqlScratch->appendUShort(variable->msgItem + 1); - dsqlScratch->appendUChar(blr_null); } } - for (Array<dsql_var*>::const_iterator i = dsqlScratch->outputVariables.begin(); - i != dsqlScratch->outputVariables.end(); - ++i) - { + Array<dsql_var*>& variables = subRoutine ? dsqlScratch->outputVariables : dsqlScratch->variables; + + for (Array<dsql_var*>::const_iterator i = variables.begin(); i != variables.end(); ++i) dsqlScratch->putLocalVariable(*i, 0, NULL); - } dsqlScratch->setPsql(true); - dsqlScratch->putLocalVariables(localDeclList, USHORT(returns.getCount())); + dsqlScratch->putLocalVariables(localDeclList, + USHORT((subRoutine ? 0 : parameters.getCount()) + returns.getCount())); dsqlScratch->loopLevel = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2012-02-06 20:10:16
|
Revision: 53983 http://firebird.svn.sourceforge.net/firebird/?rev=53983&view=rev Author: asfernandes Date: 2012-02-06 20:10:07 +0000 (Mon, 06 Feb 2012) Log Message: ----------- Refactor COMMIT and ROLLBACK commands. Modified Paths: -------------- firebird/trunk/src/dsql/Nodes.h firebird/trunk/src/dsql/StmtNodes.h firebird/trunk/src/dsql/node.h firebird/trunk/src/dsql/parse.y firebird/trunk/src/dsql/pass1.cpp Modified: firebird/trunk/src/dsql/Nodes.h =================================================================== --- firebird/trunk/src/dsql/Nodes.h 2012-02-06 04:49:29 UTC (rev 53982) +++ firebird/trunk/src/dsql/Nodes.h 2012-02-06 20:10:07 UTC (rev 53983) @@ -839,6 +839,7 @@ { TYPE_ASSIGNMENT, TYPE_BLOCK, + TYPE_COMMIT_ROLLBACK, TYPE_COMPOUND_STMT, TYPE_CONTINUE_LEAVE, TYPE_CURSOR_STMT, Modified: firebird/trunk/src/dsql/StmtNodes.h =================================================================== --- firebird/trunk/src/dsql/StmtNodes.h 2012-02-06 04:49:29 UTC (rev 53982) +++ firebird/trunk/src/dsql/StmtNodes.h 2012-02-06 20:10:07 UTC (rev 53983) @@ -158,6 +158,57 @@ }; +class CommitRollbackNode : public TypedNode<DsqlOnlyStmtNode, StmtNode::TYPE_COMMIT_ROLLBACK> +{ +public: + enum Command + { + CMD_COMMIT, + CMD_ROLLBACK + }; + +public: + explicit CommitRollbackNode(MemoryPool& pool, Command aCommand, bool aRetain) + : TypedNode<DsqlOnlyStmtNode, StmtNode::TYPE_COMMIT_ROLLBACK>(pool), + command(aCommand), + retain(aRetain) + { + } + +public: + virtual void print(Firebird::string& text, Firebird::Array<dsql_nod*>& nodes) const + { + text = "CommitRollbackNode"; + } + + virtual CommitRollbackNode* dsqlPass(DsqlCompilerScratch* dsqlScratch) + { + switch (command) + { + case CMD_COMMIT: + dsqlScratch->getStatement()->setType(retain ? + DsqlCompiledStatement::TYPE_COMMIT_RETAIN : DsqlCompiledStatement::TYPE_COMMIT); + break; + + case CMD_ROLLBACK: + dsqlScratch->getStatement()->setType(retain ? + DsqlCompiledStatement::TYPE_ROLLBACK_RETAIN : DsqlCompiledStatement::TYPE_ROLLBACK); + break; + } + + return this; + } + + virtual void genBlr(DsqlCompilerScratch* dsqlScratch) + { + } + +private: + Command command; + bool retain; +}; + + class CompoundStmtNode : public TypedNode<StmtNode, StmtNode::TYPE_COMPOUND_STMT> // blr_begin { public: Modified: firebird/trunk/src/dsql/node.h =================================================================== --- firebird/trunk/src/dsql/node.h 2012-02-06 04:49:29 UTC (rev 53982) +++ firebird/trunk/src/dsql/node.h 2012-02-06 20:10:07 UTC (rev 53983) @@ -55,8 +55,6 @@ // to an expression node. nod_unknown_type = 0, - nod_commit, - nod_rollback, nod_trans, nod_def_default, nod_del_default, @@ -102,7 +100,6 @@ nod_table_lock, nod_lock_mode, nod_reserve, - nod_retain, nod_def_computed, nod_plan_expr, nod_plan_item, Modified: firebird/trunk/src/dsql/parse.y =================================================================== --- firebird/trunk/src/dsql/parse.y 2012-02-06 04:49:29 UTC (rev 53982) +++ firebird/trunk/src/dsql/parse.y 2012-02-06 20:10:07 UTC (rev 53983) @@ -710,8 +710,8 @@ %type <boolVal> check_opt %type <legacyNode> column_list column_name column_parens column_parens_opt column_select -%type <legacyNode> column_singleton commit -%type <stmtNode> complex_proc_statement +%type <legacyNode> column_singleton +%type <stmtNode> commit complex_proc_statement %type <legacyNode> computed_by computed_clause constant constraint_index_opt %type <boolVal> conditional %type <legacyNode> constraint_name_opt correlation_name @@ -812,7 +812,7 @@ %type not_named_param(<execStatementNode>) not_named_params_list(<execStatementNode>) %type <stmtNode> open_cursor -%type <legacyNode> optional_retain +%type <boolVal> optional_retain %type optional_savepoint opt_snapshot optional_work %type <legacyNode> order_clause order_item order_list %type <boolVal> order_direction @@ -842,7 +842,8 @@ %type <returningClause> returning_clause %type <ddlNode> rexception_clause %type <legacyNode> role_admin_option role_grantee role_grantee_list -%type <legacyNode> role_name role_name_list rollback rows_clause +%type <legacyNode> role_name role_name_list rows_clause +%type <stmtNode> rollback %type <ddlNode> role_clause rtable_clause %type <ddlNode> rview_clause %type <nullableIntVal> revoke_admin @@ -993,7 +994,7 @@ // ASF: ALTER SEQUENCE is defined here cause it's treated as DML. | ALTER SEQUENCE alter_sequence_clause { $$ = makeClassNode($3); } | comment { $$ = makeClassNode($1); } - | commit + | commit { $$ = makeClassNode($1); } | create { $$ = makeClassNode($1); } | create_or_alter { $$ = makeClassNode($1); } | declare { $$ = makeClassNode($1); } @@ -1006,7 +1007,7 @@ | exec_block { $$ = makeClassNode($1); } | recreate { $$ = makeClassNode($1); } | revoke - | rollback + | rollback { $$ = makeClassNode($1); } | savepoint | select | set @@ -4097,12 +4098,12 @@ commit : COMMIT optional_work optional_retain - { $$ = make_node (nod_commit, e_commit_count, $3); } + { $$ = newNode<CommitRollbackNode>(CommitRollbackNode::CMD_COMMIT, $3); } ; rollback : ROLLBACK optional_work optional_retain - { $$ = make_node (nod_rollback, e_rollback_count, $3); } + { $$ = newNode<CommitRollbackNode>(CommitRollbackNode::CMD_ROLLBACK, $3); } ; optional_work @@ -4111,8 +4112,8 @@ ; optional_retain - : /* nothing */ { $$ = NULL; } - | RETAIN opt_snapshot { $$ = make_node(nod_retain, 0, NULL); } + : /* nothing */ { $$ = false; } + | RETAIN opt_snapshot { $$ = true; } ; opt_snapshot Modified: firebird/trunk/src/dsql/pass1.cpp =================================================================== --- firebird/trunk/src/dsql/pass1.cpp 2012-02-06 04:49:29 UTC (rev 53982) +++ firebird/trunk/src/dsql/pass1.cpp 2012-02-06 20:10:07 UTC (rev 53983) @@ -908,26 +908,6 @@ } return input; - case nod_commit: - if ((input->nod_arg[e_commit_retain]) && - (input->nod_arg[e_commit_retain]->nod_type == nod_retain)) - { - dsqlScratch->getStatement()->setType(DsqlCompiledStatement::TYPE_COMMIT_RETAIN); - } - else - dsqlScratch->getStatement()->setType(DsqlCompiledStatement::TYPE_COMMIT); - return input; - - case nod_rollback: - if ((input->nod_arg[e_rollback_retain]) && - (input->nod_arg[e_rollback_retain]->nod_type == nod_retain)) - { - dsqlScratch->getStatement()->setType(DsqlCompiledStatement::TYPE_ROLLBACK_RETAIN); - } - else - dsqlScratch->getStatement()->setType(DsqlCompiledStatement::TYPE_ROLLBACK); - return input; - case nod_list: { node = MAKE_node(input->nod_type, input->nod_count); @@ -4717,12 +4697,6 @@ verb = "natural"; break; // SKIDDER: some more missing node types - case nod_commit: - verb = "commit"; - break; - case nod_rollback: - verb = "rollback"; - break; case nod_trans: verb = "trans"; break; @@ -4783,9 +4757,6 @@ case nod_reserve: verb = "reserve"; break; - case nod_retain: - verb = "retain"; - break; case nod_def_computed: verb = "def_computed"; break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2012-02-06 20:10:56
|
Revision: 53984 http://firebird.svn.sourceforge.net/firebird/?rev=53984&view=rev Author: asfernandes Date: 2012-02-06 20:10:50 +0000 (Mon, 06 Feb 2012) Log Message: ----------- Refactor SET TRANSACTION command. Modified Paths: -------------- firebird/trunk/src/dsql/Nodes.h firebird/trunk/src/dsql/StmtNodes.cpp firebird/trunk/src/dsql/StmtNodes.h firebird/trunk/src/dsql/dsql.cpp firebird/trunk/src/dsql/gen.cpp firebird/trunk/src/dsql/gen_proto.h firebird/trunk/src/dsql/node.h firebird/trunk/src/dsql/parse.y firebird/trunk/src/dsql/pass1.cpp Modified: firebird/trunk/src/dsql/Nodes.h =================================================================== --- firebird/trunk/src/dsql/Nodes.h 2012-02-06 20:10:07 UTC (rev 53983) +++ firebird/trunk/src/dsql/Nodes.h 2012-02-06 20:10:50 UTC (rev 53984) @@ -873,6 +873,7 @@ TYPE_SAVEPOINT_ENCLOSE, TYPE_SELECT, TYPE_SET_GENERATOR, + TYPE_SET_TRANSACTION, TYPE_STALL, TYPE_STORE, TYPE_SUSPEND, Modified: firebird/trunk/src/dsql/StmtNodes.cpp =================================================================== --- firebird/trunk/src/dsql/StmtNodes.cpp 2012-02-06 20:10:07 UTC (rev 53983) +++ firebird/trunk/src/dsql/StmtNodes.cpp 2012-02-06 20:10:50 UTC (rev 53984) @@ -7401,6 +7401,117 @@ //-------------------- +SetTransactionNode* SetTransactionNode::dsqlPass(DsqlCompilerScratch* dsqlScratch) +{ + dsqlScratch->getStatement()->setType(DsqlCompiledStatement::TYPE_START_TRANS); + + // Generate tpb for set transaction. Use blr string of dsqlScratch. + // If a value is not specified, default is not stuffed, let the engine handle it. + + fb_assert(dsqlScratch->getBlrData().getCount() == 0); + + // Find out isolation level - if specified. This is required for + // specifying the correct lock level in reserving clause. + const USHORT lockLevel = isoLevel.specified && isoLevel.value == ISO_LEVEL_CONSISTENCY ? + isc_tpb_protected : isc_tpb_shared; + + // Stuff some version info. + dsqlScratch->appendUChar(isc_tpb_version1); + + if (readOnly.specified) + dsqlScratch->appendUChar(readOnly.value ? isc_tpb_read : isc_tpb_write); + + if (wait.specified) + dsqlScratch->appendUChar(wait.value ? isc_tpb_wait : isc_tpb_nowait); + + if (isoLevel.specified) + { + if (isoLevel.value == ISO_LEVEL_CONCURRENCY) + dsqlScratch->appendUChar(isc_tpb_concurrency); + else if (isoLevel.value == ISO_LEVEL_CONSISTENCY) + dsqlScratch->appendUChar(isc_tpb_consistency); + else + { + dsqlScratch->appendUChar(isc_tpb_read_committed); + + if (isoLevel.value == ISO_LEVEL_READ_COMMITTED_REC_VERSION) + dsqlScratch->appendUChar(isc_tpb_rec_version); + else + dsqlScratch->appendUChar(isc_tpb_no_rec_version); + } + } + + if (noAutoUndo.specified) + dsqlScratch->appendUChar(isc_tpb_no_auto_undo); + + if (ignoreLimbo.specified) + dsqlScratch->appendUChar(isc_tpb_ignore_limbo); + + if (restartRequests.specified) + dsqlScratch->appendUChar(isc_tpb_restart_requests); + + if (lockTimeout.specified) + { + dsqlScratch->appendUChar(isc_tpb_lock_timeout); + dsqlScratch->appendUChar(2); + dsqlScratch->appendUShort(lockTimeout.value); + } + + if (reserveList.specified) + { + const dsql_nod* const* temp = reserveList.value->nod_arg; + for (const dsql_nod* const* end = temp + reserveList.value->nod_count; temp != end; ++temp) + genTableLock(dsqlScratch, *temp, lockLevel); + } + + if (dsqlScratch->getBlrData().getCount() > 1) // 1 -> isc_tpb_version1 + { + // Store DYN data in the statement. + dsqlScratch->getStatement()->setDdlData(dsqlScratch->getBlrData()); + } + + return this; +} + +// Generate tpb for table lock. +// If lock level is specified, it overrrides the transaction lock level. +void SetTransactionNode::genTableLock(DsqlCompilerScratch* dsqlScratch, const dsql_nod* tblLock, + USHORT lockLevel) +{ + if (!tblLock || tblLock->nod_type != Dsql::nod_table_lock) + return; + + const dsql_nod* tblNames = tblLock->nod_arg[Dsql::e_lock_tables]; + SSHORT flags = 0; + + if (tblLock->nod_arg[Dsql::e_lock_mode]) + flags = tblLock->nod_arg[Dsql::e_lock_mode]->nod_flags; + + if (flags & NOD_PROTECTED) + lockLevel = isc_tpb_protected; + else if (flags & NOD_SHARED) + lockLevel = isc_tpb_shared; + + const USHORT lockMode = (flags & NOD_WRITE) ? isc_tpb_lock_write : isc_tpb_lock_read; + + const dsql_nod* const* ptr = tblNames->nod_arg; + for (const dsql_nod* const* const end = ptr + tblNames->nod_count; ptr != end; ++ptr) + { + const RelationSourceNode* relNode = ExprNode::as<RelationSourceNode>(*ptr); + + if (!relNode) + continue; + + dsqlScratch->appendUChar(lockMode); + dsqlScratch->appendNullString(relNode->dsqlName.c_str()); // stuff table name + dsqlScratch->appendUChar(lockLevel); + } +} + + +//-------------------- + + StmtNode* UpdateOrInsertNode::dsqlPass(DsqlCompilerScratch* dsqlScratch) { thread_db* tdbb = JRD_get_thread_data(); // necessary? Modified: firebird/trunk/src/dsql/StmtNodes.h =================================================================== --- firebird/trunk/src/dsql/StmtNodes.h 2012-02-06 20:10:07 UTC (rev 53983) +++ firebird/trunk/src/dsql/StmtNodes.h 2012-02-06 20:10:50 UTC (rev 53984) @@ -1421,6 +1421,50 @@ }; +class SetTransactionNode : public TypedNode<DsqlOnlyStmtNode, StmtNode::TYPE_SET_TRANSACTION> +{ +public: + enum + { + ISO_LEVEL_CONCURRENCY, + ISO_LEVEL_CONSISTENCY, + ISO_LEVEL_READ_COMMITTED_REC_VERSION, + ISO_LEVEL_READ_COMMITTED_NO_REC_VERSION + }; + +public: + explicit SetTransactionNode(MemoryPool& pool) + : TypedNode<DsqlOnlyStmtNode, StmtNode::TYPE_SET_TRANSACTION>(pool) + { + } + +public: + virtual void print(Firebird::string& text, Firebird::Array<dsql_nod*>& nodes) const + { + text = "SetTransactionNode"; + } + + virtual SetTransactionNode* dsqlPass(DsqlCompilerScratch* dsqlScratch); + + virtual void genBlr(DsqlCompilerScratch* dsqlScratch) + { + } + +private: + void genTableLock(DsqlCompilerScratch* dsqlScratch, const dsql_nod* tblLock, USHORT lockLevel); + +public: + Nullable<bool> readOnly; + Nullable<bool> wait; + Nullable<unsigned> isoLevel; + Nullable<bool> noAutoUndo; + Nullable<bool> ignoreLimbo; + Nullable<bool> restartRequests; + Nullable<USHORT> lockTimeout; + Nullable<dsql_nod*> reserveList; +}; + + class UpdateOrInsertNode : public TypedNode<DsqlOnlyStmtNode, StmtNode::TYPE_UPDATE_OR_INSERT> { public: Modified: firebird/trunk/src/dsql/dsql.cpp =================================================================== --- firebird/trunk/src/dsql/dsql.cpp 2012-02-06 20:10:07 UTC (rev 53983) +++ firebird/trunk/src/dsql/dsql.cpp 2012-02-06 20:10:50 UTC (rev 53984) @@ -1601,13 +1601,8 @@ request = FB_NEW(statement->getPool()) DsqlTransactionRequest(scratch); request->req_traced = false; trace.setStatement(request); + return request; // Stop here for statements not requiring code generation. - if (statementType == DsqlCompiledStatement::TYPE_START_TRANS) - GEN_start_transaction(scratch, node); - - // Stop here for statements not requiring code generation. - return request; - case DsqlCompiledStatement::TYPE_CREATE_DB: case DsqlCompiledStatement::TYPE_DDL: request = FB_NEW(statement->getPool()) DsqlDdlRequest(scratch); Modified: firebird/trunk/src/dsql/gen.cpp =================================================================== --- firebird/trunk/src/dsql/gen.cpp 2012-02-06 20:10:07 UTC (rev 53983) +++ firebird/trunk/src/dsql/gen.cpp 2012-02-06 20:10:50 UTC (rev 53984) @@ -66,7 +66,6 @@ static void gen_plan(DsqlCompilerScratch*, const dsql_nod*); static void gen_select(DsqlCompilerScratch*, dsql_nod*); -static void gen_table_lock(DsqlCompilerScratch*, const dsql_nod*, USHORT); static void gen_union(DsqlCompilerScratch*, const dsql_nod*); @@ -360,179 +359,6 @@ /** - GEN_start_transaction - - @brief Generate tpb for set transaction. Use blr string of dsqlScratch. - If a value is not specified, default is not STUFF'ed, let the - engine handle it. - Do not allow an option to be specified more than once. - - - @param dsqlScratch - @param tran_node - - **/ -void GEN_start_transaction( DsqlCompilerScratch* dsqlScratch, const dsql_nod* tran_node) -{ - SSHORT count = tran_node->nod_count; - - if (!count) - return; - - const dsql_nod* node = tran_node->nod_arg[0]; - - if (!node) - return; - - // Find out isolation level - if specified. This is required for - // specifying the correct lock level in reserving clause. - - USHORT lock_level = isc_tpb_shared; - - if (count = node->nod_count) - { - while (count--) - { - const dsql_nod* ptr = node->nod_arg[count]; - - if (!ptr || ptr->nod_type != nod_isolation) - continue; - - lock_level = (ptr->nod_flags & NOD_CONSISTENCY) ? isc_tpb_protected : isc_tpb_shared; - } - } - - - bool sw_access = false, sw_wait = false, sw_isolation = false, - sw_reserve = false, sw_lock_timeout = false; - int misc_flags = 0; - - // Stuff some version info. - if (count = node->nod_count) - dsqlScratch->appendUChar(isc_tpb_version1); - - while (count--) - { - const dsql_nod* ptr = node->nod_arg[count]; - - if (!ptr) - continue; - - switch (ptr->nod_type) - { - case nod_access: - if (sw_access) - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << - Arg::Gds(isc_dsql_dup_option)); - - sw_access = true; - if (ptr->nod_flags & NOD_READ_ONLY) - dsqlScratch->appendUChar(isc_tpb_read); - else - dsqlScratch->appendUChar(isc_tpb_write); - break; - - case nod_wait: - if (sw_wait) - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << - Arg::Gds(isc_dsql_dup_option)); - - sw_wait = true; - if (ptr->nod_flags & NOD_NO_WAIT) - dsqlScratch->appendUChar(isc_tpb_nowait); - else - dsqlScratch->appendUChar(isc_tpb_wait); - break; - - case nod_isolation: - if (sw_isolation) - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << - Arg::Gds(isc_dsql_dup_option)); - - sw_isolation = true; - - if (ptr->nod_flags & NOD_CONCURRENCY) - dsqlScratch->appendUChar(isc_tpb_concurrency); - else if (ptr->nod_flags & NOD_CONSISTENCY) - dsqlScratch->appendUChar(isc_tpb_consistency); - else - { - dsqlScratch->appendUChar(isc_tpb_read_committed); - - if (ptr->nod_count && ptr->nod_arg[0] && ptr->nod_arg[0]->nod_type == nod_version) - { - if (ptr->nod_arg[0]->nod_flags & NOD_VERSION) - dsqlScratch->appendUChar(isc_tpb_rec_version); - else - dsqlScratch->appendUChar(isc_tpb_no_rec_version); - } - else - dsqlScratch->appendUChar(isc_tpb_no_rec_version); - } - break; - - case nod_reserve: - { - if (sw_reserve) - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << - Arg::Gds(isc_dsql_dup_option)); - - sw_reserve = true; - const dsql_nod* reserve = ptr->nod_arg[0]; - - if (reserve) - { - const dsql_nod* const* temp = reserve->nod_arg; - for (const dsql_nod* const* end = temp + reserve->nod_count; temp < end; temp++) - { - gen_table_lock(dsqlScratch, *temp, lock_level); - } - } - } - break; - - case nod_tra_misc: - if (misc_flags & ptr->nod_flags) - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << - Arg::Gds(isc_dsql_dup_option)); - - misc_flags |= ptr->nod_flags; - if (ptr->nod_flags & NOD_NO_AUTO_UNDO) - dsqlScratch->appendUChar(isc_tpb_no_auto_undo); - else if (ptr->nod_flags & NOD_IGNORE_LIMBO) - dsqlScratch->appendUChar(isc_tpb_ignore_limbo); - else if (ptr->nod_flags & NOD_RESTART_REQUESTS) - dsqlScratch->appendUChar(isc_tpb_restart_requests); - break; - - case nod_lock_timeout: - if (sw_lock_timeout) - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << - Arg::Gds(isc_dsql_dup_option)); - - sw_lock_timeout = true; - if (ptr->nod_count == 1 && ExprNode::is<LiteralNode>(ptr->nod_arg[0])) - { - const int lck_timeout = (int) ExprNode::as<LiteralNode>(ptr->nod_arg[0])->getSlong(); - dsqlScratch->appendUChar(isc_tpb_lock_timeout); - dsqlScratch->appendUChar(2); - dsqlScratch->appendUShort(lck_timeout); - } - break; - - default: - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << - Arg::Gds(isc_dsql_tran_err)); - } - } - - // Store DYN data in the statement. - dsqlScratch->getStatement()->setDdlData(dsqlScratch->getBlrData()); -} - - -/** - GEN_statement @brief Generate blr for an arbitrary expression. @@ -1098,55 +924,6 @@ /** - gen_table_lock - - @brief Generate tpb for table lock. - If lock level is specified, it overrrides the transaction lock level. - - - @param dsqlScratch - @param tbl_lock - @param lock_level - - **/ -static void gen_table_lock( DsqlCompilerScratch* dsqlScratch, const dsql_nod* tbl_lock, USHORT lock_level) -{ - if (!tbl_lock || tbl_lock->nod_type != nod_table_lock) - return; - - const dsql_nod* tbl_names = tbl_lock->nod_arg[e_lock_tables]; - SSHORT flags = 0; - - if (tbl_lock->nod_arg[e_lock_mode]) - flags = tbl_lock->nod_arg[e_lock_mode]->nod_flags; - - if (flags & NOD_PROTECTED) - lock_level = isc_tpb_protected; - else if (flags & NOD_SHARED) - lock_level = isc_tpb_shared; - - const USHORT lock_mode = (flags & NOD_WRITE) ? isc_tpb_lock_write : isc_tpb_lock_read; - - const dsql_nod* const* ptr = tbl_names->nod_arg; - for (const dsql_nod* const* const end = ptr + tbl_names->nod_count; ptr < end; ptr++) - { - const RelationSourceNode* relNode = ExprNode::as<RelationSourceNode>(*ptr); - - if (!relNode) - continue; - - dsqlScratch->appendUChar(lock_mode); - - // stuff table name - dsqlScratch->appendNullString(relNode->dsqlName.c_str()); - - dsqlScratch->appendUChar(lock_level); - } -} - - -/** - gen_union @brief Generate a union of substreams. Modified: firebird/trunk/src/dsql/gen_proto.h =================================================================== --- firebird/trunk/src/dsql/gen_proto.h 2012-02-06 20:10:07 UTC (rev 53983) +++ firebird/trunk/src/dsql/gen_proto.h 2012-02-06 20:10:50 UTC (rev 53984) @@ -33,7 +33,6 @@ void GEN_rse(Jrd::DsqlCompilerScratch*, const Jrd::dsql_nod*); void GEN_return(Jrd::DsqlCompilerScratch*, const Firebird::Array<Jrd::dsql_nod*>& variables, bool, bool); void GEN_sort(Jrd::DsqlCompilerScratch*, Jrd::dsql_nod*); -void GEN_start_transaction(Jrd::DsqlCompilerScratch*, const Jrd::dsql_nod*); void GEN_statement(Jrd::DsqlCompilerScratch*, Jrd::dsql_nod*); void GEN_stuff_context(Jrd::DsqlCompilerScratch*, const Jrd::dsql_ctx*); Modified: firebird/trunk/src/dsql/node.h =================================================================== --- firebird/trunk/src/dsql/node.h 2012-02-06 20:10:07 UTC (rev 53983) +++ firebird/trunk/src/dsql/node.h 2012-02-06 20:10:50 UTC (rev 53984) @@ -55,7 +55,6 @@ // to an expression node. nod_unknown_type = 0, - nod_trans, nod_def_default, nod_del_default, nod_def_domain, @@ -93,13 +92,8 @@ nod_array, nod_not_null, nod_collate, - nod_access, - nod_wait, - nod_isolation, - nod_version, nod_table_lock, nod_lock_mode, - nod_reserve, nod_def_computed, nod_plan_expr, nod_plan_item, @@ -118,8 +112,6 @@ nod_for_update, // FOR UPDATE clause nod_label, // label support nod_rows, // ROWS support - nod_tra_misc, - nod_lock_timeout, nod_with, nod_class_stmtnode, nod_class_exprnode, @@ -310,28 +302,11 @@ NOD_UNION_ALL = 1, // nod_list NOD_UNION_RECURSIVE = 2, - NOD_READ_ONLY = 1, // nod_access - NOD_READ_WRITE = 2, - - NOD_WAIT = 1, // nod_wait - NOD_NO_WAIT = 2, - - NOD_VERSION = 1, // nod_version - NOD_NO_VERSION = 2, - - NOD_CONCURRENCY = 1, // nod_isolation - NOD_CONSISTENCY = 2, - NOD_READ_COMMITTED = 4, - NOD_SHARED = 1, // nod_lock_mode NOD_PROTECTED = 2, NOD_READ = 4, NOD_WRITE = 8, - NOD_NO_AUTO_UNDO = 1, // nod_tra_misc - NOD_IGNORE_LIMBO = 2, - NOD_RESTART_REQUESTS = 4, - NOD_NULLS_FIRST = 1, // nod_order NOD_NULLS_LAST = 2, Modified: firebird/trunk/src/dsql/parse.y =================================================================== --- firebird/trunk/src/dsql/parse.y 2012-02-06 20:10:07 UTC (rev 53983) +++ firebird/trunk/src/dsql/parse.y 2012-02-06 20:10:50 UTC (rev 53984) @@ -670,11 +670,12 @@ Jrd::ErrorHandlerNode* errorHandlerNode; Jrd::ExecStatementNode* execStatementNode; Jrd::MergeNode* mergeNode; + Jrd::SetTransactionNode* setTransactionNode; Jrd::DeclareSubProcNode* declareSubProcNode; Jrd::DeclareSubFuncNode* declareSubFuncNode; } -%type <legacyNode> access_mode access_type alias_list +%type <legacyNode> access_type alias_list %type <legacyNode> alter_column_name %type <legacyNode> alter_data_type_or_domain %type <legacyNode> alter_op alter_ops @@ -777,7 +778,7 @@ %type <legacyNode> ins_column_list ins_column_parens %type <legacyNode> ins_column_parens_opt integer_keyword %type <stmtNode> insert -%type <legacyNode> iso_mode isolation_mode +%type <uintVal> iso_mode isolation_mode %type input_parameters(<parametersClause>) input_proc_parameter(<parametersClause>) %type input_proc_parameters(<parametersClause>) @@ -789,7 +790,7 @@ %type <legacyNode> label_opt limit_clause %type <stmtNode> local_declaration local_declaration_item %type <compoundStmtNode> local_declaration_list local_declarations -%type <legacyNode> lock_clause lock_mode lock_type lock_wait +%type <legacyNode> lock_clause lock_mode lock_type %type <stringPtr> lastname_opt %type <int32Val> long_integer @@ -834,7 +835,8 @@ %type <ddlNode> recreate recreate_clause replace_clause replace_exception_clause replace_view_clause %type <legacyNode> referential_action referential_constraint -%type <legacyNode> referential_trigger_action release_savepoint +%type <legacyNode> referential_trigger_action +%type <stmtNode> release_savepoint %type <legacyNode> restr_list restr_option %type <int32Val> return_mechanism %type <legacyNode> rev_admin_option rev_grant_option revoke @@ -848,18 +850,21 @@ %type <ddlNode> rview_clause %type <nullableIntVal> revoke_admin -%type <legacyNode> savepoint scroll_opt search_condition searched_case +%type <stmtNode> savepoint set_savepoint +%type <legacyNode> scroll_opt search_condition searched_case %type <valueIfNode> searched_when_clause %type sec_shadow_files(<dbFilesClause>) %type <legacyNode> select select_expr -%type <legacyNode> select_expr_body select_item select_items select_list set set_generator -%type <legacyNode> set_savepoint set_statistics set_transaction +%type <legacyNode> select_expr_body select_item select_items select_list %type <createShadowNode> shadow_clause %type <legacyNode> simple_case simple_UDF_name %type <legacyNode> simple_column_name simple_package_name simple_proc_name simple_table_name -%type <stmtNode> simple_proc_statement singleton_select +%type <stmtNode> set_generator simple_proc_statement singleton_select +%type <setTransactionNode> set_transaction +%type <ddlNode> set_statistics %type <legacyNode> simple_type simple_when_clause skip_clause -%type <legacyNode> snap_shot statement +%type <uintVal> snap_shot +%type <legacyNode> statement %type <legacyNode> string_length_opt %type <legacyNode> symbol_UDF_call_name symbol_UDF_name symbol_blob_subtype_name symbol_character_set_name %type <legacyNode> symbol_collation_name symbol_column_name symbol_constraint_name symbol_cursor_name @@ -880,22 +885,25 @@ %type <legacyNode> table_constraint table_constraint_definition %type <legacyNode> table_list table_lock table_name table_or_alias_list table_primary -%type <legacyNode> table_proc table_proc_inputs table_reference table_subquery tbl_reserve_options -%type <legacyNode> top tra_misc_options tra_timeout tran_opt tran_opt_list tran_opt_list_m +%type <legacyNode> table_proc table_proc_inputs table_reference table_subquery +%type <legacyNode> top +%type tran_option(<setTransactionNode>) tran_option_list(<setTransactionNode>) +%type tran_option_list_opt(<setTransactionNode>) %type <uintVal> time_precision_opt timestamp_precision_opt -%type <legacyNode> u_constant u_numeric_constant udf_data_type undo_savepoint +%type <legacyNode> u_constant u_numeric_constant udf_data_type %type <createAlterFunctionNode> udf_decl_clause %type <legacyNode> unique_constraint update_column_name %type <boolVal> unique_opt -%type <stmtNode> update update_or_insert update_positioned update_searched +%type <stmtNode> undo_savepoint update update_or_insert update_positioned update_searched %type <legacyNode> update_or_insert_matching_opt update_rule %type <legacyNode> user_grantee user_grantee_list %type <int32Val> unsigned_short_integer %type <legacyNode> valid_symbol_name value common_value common_value_list common_value_list_opt value_list value_list_opt var_decl_opt %type <stmtNode> var_declaration_item -%type <legacyNode> variable varying_keyword version_mode +%type <legacyNode> variable varying_keyword +%type <uintVal> version_mode %type <legacyArray> variable_list %type <createAlterViewNode> view_clause @@ -1008,9 +1016,11 @@ | recreate { $$ = makeClassNode($1); } | revoke | rollback { $$ = makeClassNode($1); } - | savepoint + | savepoint { $$ = makeClassNode($1); } | select - | set + | set_transaction { $$ = makeClassNode($1); } + | set_generator { $$ = makeClassNode($1); } + | set_statistics { $$ = makeClassNode($1); } | update { $$ = makeClassNode($1); } | update_or_insert { $$ = makeClassNode($1); } ; @@ -4024,26 +4034,18 @@ ; -// SET statements -set - : set_transaction - | set_generator - | set_statistics - ; - - set_generator : SET GENERATOR symbol_generator_name TO signed_long_integer - { $$ = makeClassNode(newNode<SetGeneratorNode>(toName($3), MAKE_const_slong($5))); } + { $$ = newNode<SetGeneratorNode>(toName($3), MAKE_const_slong($5)); } | SET GENERATOR symbol_generator_name TO NUMBER64BIT { - $$ = makeClassNode(newNode<SetGeneratorNode>(toName($3), - MAKE_constant((dsql_str*) $5, CONSTANT_SINT64))); + $$ = newNode<SetGeneratorNode>(toName($3), + MAKE_constant((dsql_str*) $5, CONSTANT_SINT64)); } | SET GENERATOR symbol_generator_name TO '-' NUMBER64BIT { - $$ = makeClassNode(newNode<SetGeneratorNode>(toName($3), - makeClassNode(newNode<NegateNode>(MAKE_constant((dsql_str*) $6, CONSTANT_SINT64))))); + $$ = newNode<SetGeneratorNode>(toName($3), + makeClassNode(newNode<NegateNode>(MAKE_constant((dsql_str*) $6, CONSTANT_SINT64)))); } ; @@ -4062,7 +4064,7 @@ UserSavepointNode* node = newNode<UserSavepointNode>(); node->command = UserSavepointNode::CMD_SET; node->name = toName($2); - $$ = makeClassNode(node); + $$ = node; } ; @@ -4072,7 +4074,7 @@ UserSavepointNode* node = newNode<UserSavepointNode>(); node->command = ($4 ? UserSavepointNode::CMD_RELEASE_ONLY : UserSavepointNode::CMD_RELEASE); node->name = toName($3); - $$ = makeClassNode(node); + $$ = node; } ; @@ -4087,7 +4089,7 @@ UserSavepointNode* node = newNode<UserSavepointNode>(); node->command = UserSavepointNode::CMD_ROLLBACK; node->name = toName($5); - $$ = makeClassNode(node); + $$ = node; } ; @@ -4122,42 +4124,49 @@ ; set_transaction - : SET TRANSACTION tran_opt_list_m - { $$ = make_node (nod_trans, 1, make_list ($3)); } + : SET TRANSACTION + { $$ = newNode<SetTransactionNode>(); } + tran_option_list_opt($3) + { $$ = $3; } ; -tran_opt_list_m - : /* nothing */ { $$ = NULL; } - | tran_opt_list +tran_option_list_opt($setTransactionNode) + : // nothing + | tran_option_list($setTransactionNode) ; -tran_opt_list - : tran_opt - | tran_opt_list tran_opt - { $$ = make_node (nod_list, (int) 2, $1, $2); } +tran_option_list($setTransactionNode) + : tran_option($setTransactionNode) + | tran_option_list tran_option($setTransactionNode) ; -tran_opt - : access_mode - | lock_wait - | isolation_mode - | tra_misc_options - | tra_timeout - | tbl_reserve_options - ; - -access_mode +tran_option($setTransactionNode) + // access mode : READ ONLY - { $$ = make_flag_node (nod_access, NOD_READ_ONLY, (int) 0, NULL); } + { setClause($setTransactionNode->readOnly, "READ {ONLY | WRITE}", true); } | READ WRITE - { $$ = make_flag_node (nod_access, NOD_READ_WRITE, (int) 0, NULL); } - ; - -lock_wait - : WAIT - { $$ = make_flag_node (nod_wait, NOD_WAIT, (int) 0, NULL); } + { setClause($setTransactionNode->readOnly, "READ {ONLY | WRITE}", false); } + // wait mode + | WAIT + { setClause($setTransactionNode->wait, "[NO] WAIT", true); } | NO WAIT - { $$ = make_flag_node (nod_wait, NOD_NO_WAIT, (int) 0, NULL); } + { setClause($setTransactionNode->wait, "[NO] WAIT", false); } + // isolation mode + | isolation_mode + { setClause($setTransactionNode->isoLevel, "ISOLATION LEVEL", $1); } + // misc options + | NO AUTO UNDO + { setClause($setTransactionNode->noAutoUndo, "NO AUTO UNDO", true); } + | KW_IGNORE LIMBO + { setClause($setTransactionNode->ignoreLimbo, "IGNORE LIMBO", true); } + | RESTART REQUESTS + { setClause($setTransactionNode->restartRequests, "RESTART REQUESTS", true); } + // timeout + | LOCK TIMEOUT nonneg_short_integer + { setClause($setTransactionNode->lockTimeout, "LOCK TIMEOUT", (USHORT) $3); } + // reserve options + | RESERVING restr_list + { setClause($setTransactionNode->reserveList, "RESERVING", $2); } ; isolation_mode @@ -4167,47 +4176,22 @@ iso_mode : snap_shot - { $$ = $1;} - | READ UNCOMMITTED version_mode - { $$ = make_flag_node (nod_isolation, NOD_READ_COMMITTED, 1, $3); } - | READ COMMITTED version_mode - { $$ = make_flag_node (nod_isolation, NOD_READ_COMMITTED, 1, $3); } + | READ UNCOMMITTED version_mode { $$ = $3; } + | READ COMMITTED version_mode { $$ = $3; } ; snap_shot - : SNAPSHOT - { $$ = make_flag_node (nod_isolation, NOD_CONCURRENCY, 0, NULL); } - | SNAPSHOT TABLE - { $$ = make_flag_node (nod_isolation, NOD_CONSISTENCY, 0, NULL); } - | SNAPSHOT TABLE STABILITY - { $$ = make_flag_node (nod_isolation, NOD_CONSISTENCY, 0, NULL); } + : SNAPSHOT { $$ = SetTransactionNode::ISO_LEVEL_CONCURRENCY; } + | SNAPSHOT TABLE { $$ = SetTransactionNode::ISO_LEVEL_CONSISTENCY; } + | SNAPSHOT TABLE STABILITY { $$ = SetTransactionNode::ISO_LEVEL_CONSISTENCY; } ; version_mode - : /* nothing */ { $$ = NULL; } - | VERSION { $$ = make_flag_node (nod_version, NOD_VERSION, 0, NULL); } - | NO VERSION { $$ = make_flag_node (nod_version, NOD_NO_VERSION, 0, NULL); } + : /* nothing */ { $$ = SetTransactionNode::ISO_LEVEL_READ_COMMITTED_NO_REC_VERSION; } + | VERSION { $$ = SetTransactionNode::ISO_LEVEL_READ_COMMITTED_REC_VERSION; } + | NO VERSION { $$ = SetTransactionNode::ISO_LEVEL_READ_COMMITTED_NO_REC_VERSION; } ; -tra_misc_options - : NO AUTO UNDO - { $$ = make_flag_node(nod_tra_misc, NOD_NO_AUTO_UNDO, 0, NULL); } - | KW_IGNORE LIMBO - { $$ = make_flag_node(nod_tra_misc, NOD_IGNORE_LIMBO, 0, NULL); } - | RESTART REQUESTS - { $$ = make_flag_node(nod_tra_misc, NOD_RESTART_REQUESTS, 0, NULL); } - ; - -tra_timeout - : LOCK TIMEOUT nonneg_short_integer - { $$ = make_node(nod_lock_timeout, 1, MAKE_const_slong($3)); } - ; - -tbl_reserve_options - : RESERVING restr_list - { $$ = make_node (nod_reserve, 1, make_list ($2)); } - ; - lock_type : /* nothing */ { $$ = NULL; } | KW_SHARED { $$ = (dsql_nod*) NOD_SHARED; } @@ -4222,12 +4206,12 @@ restr_list : restr_option | restr_list ',' restr_option - { $$ = make_node (nod_list, (int) 2, $1, $3); } + { $$ = make_node(nod_list, (int) 2, $1, $3); } ; restr_option : table_list table_lock - { $$ = make_node (nod_table_lock, (int) 2, make_list ($1), $2); } + { $$ = make_node(nod_table_lock, (int) 2, make_list($1), $2); } ; table_lock @@ -4240,13 +4224,13 @@ table_list : simple_table_name | table_list ',' simple_table_name - { $$ = make_node (nod_list, (int) 2, $1, $3); } + { $$ = make_node(nod_list, (int) 2, $1, $3); } ; set_statistics : SET STATISTICS INDEX symbol_index_name - { $$ = makeClassNode(newNode<SetStatisticsNode>(toName($4))); } + { $$ = newNode<SetStatisticsNode>(toName($4)); } ; comment Modified: firebird/trunk/src/dsql/pass1.cpp =================================================================== --- firebird/trunk/src/dsql/pass1.cpp 2012-02-06 20:10:07 UTC (rev 53983) +++ firebird/trunk/src/dsql/pass1.cpp 2012-02-06 20:10:50 UTC (rev 53984) @@ -948,10 +948,6 @@ } break; - case nod_trans: - dsqlScratch->getStatement()->setType(DsqlCompiledStatement::TYPE_START_TRANS); - return input; - default: ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-901) << Arg::Gds(isc_dsql_command_err) << @@ -4697,9 +4693,6 @@ verb = "natural"; break; // SKIDDER: some more missing node types - case nod_trans: - verb = "trans"; - break; case nod_def_default: verb = "def_default"; break; @@ -4736,27 +4729,12 @@ case nod_user_group: verb = "user_group"; break; - case nod_access: - verb = "access"; - break; - case nod_wait: - verb = "wait"; - break; - case nod_isolation: - verb = "isolation"; - break; - case nod_version: - verb = "version"; - break; case nod_table_lock: verb = "table_lock"; break; case nod_lock_mode: verb = "lock_mode"; break; - case nod_reserve: - verb = "reserve"; - break; case nod_def_computed: verb = "def_computed"; break; @@ -4818,14 +4796,6 @@ trace_line("%s\"\n", string->str_data); return; - case nod_tra_misc: - verb = "tra_misc"; - break; - - case nod_lock_timeout: - verb = "lock_timeout"; // maybe show the timeout value? - break; - case nod_with: verb = "with"; break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2012-02-10 03:06:28
|
Revision: 53997 http://firebird.svn.sourceforge.net/firebird/?rev=53997&view=rev Author: asfernandes Date: 2012-02-10 03:06:22 +0000 (Fri, 10 Feb 2012) Log Message: ----------- Cleanup. Modified Paths: -------------- firebird/trunk/src/dsql/make.cpp firebird/trunk/src/dsql/node.h Modified: firebird/trunk/src/dsql/make.cpp =================================================================== --- firebird/trunk/src/dsql/make.cpp 2012-02-09 07:38:51 UTC (rev 53996) +++ firebird/trunk/src/dsql/make.cpp 2012-02-10 03:06:22 UTC (rev 53997) @@ -345,17 +345,7 @@ } -/** - - MAKE_desc - - @brief Make a descriptor from input node. - This function can modify node->nod_flags to add NOD_COMP_DIALECT - - @param desc - @param node - - **/ +// Make a descriptor from input node. void MAKE_desc(DsqlCompilerScratch* dsqlScratch, dsc* desc, dsql_nod* node) { dsc desc1; Modified: firebird/trunk/src/dsql/node.h =================================================================== --- firebird/trunk/src/dsql/node.h 2012-02-09 07:38:51 UTC (rev 53996) +++ firebird/trunk/src/dsql/node.h 2012-02-10 03:06:22 UTC (rev 53997) @@ -170,11 +170,6 @@ e_idx_fields, e_idx_count, - e_drl_name = 0, // relation support - e_drl_elements, - e_drl_ext_file, // external file - e_drl_count, - e_dft_default = 0, // nod_def_default e_dft_default_source, e_dft_count, @@ -240,12 +235,6 @@ e_lock_tables = 0, // e_lock_mode, - e_commit_retain = 0, // - e_commit_count, - - e_rollback_retain = 0, // - e_rollback_count, - // computed field e_cmp_expr = 0, @@ -314,9 +303,6 @@ REF_ACTION_SET_DEFAULT = 2, REF_ACTION_SET_NULL = 4, REF_ACTION_NONE = 8, - // Node flag indicates that this node has a different type or result - // depending on the SQL dialect. - NOD_COMP_DIALECT = 16, // nod_...2, see MAKE_desc NOD_SELECT_EXPR_SINGLETON = 1, // nod_select_expr NOD_SELECT_EXPR_VALUE = 2, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2012-02-10 03:07:04
|
Revision: 53998 http://firebird.svn.sourceforge.net/firebird/?rev=53998&view=rev Author: asfernandes Date: 2012-02-10 03:06:57 +0000 (Fri, 10 Feb 2012) Log Message: ----------- Refactor SELECT. Modified Paths: -------------- firebird/trunk/src/dsql/StmtNodes.cpp firebird/trunk/src/dsql/StmtNodes.h firebird/trunk/src/dsql/gen.cpp firebird/trunk/src/dsql/node.h firebird/trunk/src/dsql/parse.y firebird/trunk/src/dsql/pass1.cpp firebird/trunk/src/dsql/pass1_proto.h Modified: firebird/trunk/src/dsql/StmtNodes.cpp =================================================================== --- firebird/trunk/src/dsql/StmtNodes.cpp 2012-02-10 03:06:22 UTC (rev 53997) +++ firebird/trunk/src/dsql/StmtNodes.cpp 2012-02-10 03:06:57 UTC (rev 53998) @@ -1166,8 +1166,7 @@ DsqlContextStack* const baseContext = dsqlScratch->context; DsqlContextStack temp; dsqlScratch->context = &temp; - const dsql_nod* select = dsqlRse; - dsqlRse = PASS1_rse(dsqlScratch, select->nod_arg[Dsql::e_select_expr], select->nod_arg[Dsql::e_select_lock]); + dsqlRse = PASS1_rse(dsqlScratch, dsqlSelect->dsqlExpr, dsqlSelect->dsqlWithLock); dsqlScratch->context->clear(); dsqlScratch->context = baseContext; @@ -4295,14 +4294,14 @@ ForNode* node = FB_NEW(getPool()) ForNode(getPool()); node->dsqlCursor = dsqlCursor; - node->dsqlSelect = PASS1_statement(dsqlScratch, dsqlSelect); + node->dsqlSelect = dsqlSelect->dsqlPass(dsqlScratch); if (dsqlCursor) { DeclareCursorNode* cursor = StmtNode::as<DeclareCursorNode>(dsqlCursor); fb_assert(cursor->dsqlCursorType != DeclareCursorNode::CUR_TYPE_NONE); PASS1_cursor_name(dsqlScratch, cursor->dsqlName, DeclareCursorNode::CUR_TYPE_ALL, false); - cursor->dsqlRse = node->dsqlSelect; + cursor->dsqlSelect = node->dsqlSelect; cursor->cursorNumber = dsqlScratch->cursorNumber++; dsqlScratch->cursors.push(cursor); } @@ -4332,7 +4331,6 @@ void ForNode::print(string& text, Array<dsql_nod*>& nodes) const { text = "ForNode"; - nodes.add(dsqlSelect); nodes.add(dsqlCursor); nodes.add(dsqlLabel); } @@ -4354,12 +4352,12 @@ if (!statement || dsqlForceSingular) dsqlScratch->appendUChar(blr_singular); - GEN_rse(dsqlScratch, dsqlSelect); + GEN_rse(dsqlScratch, dsqlSelect->dsqlRse); dsqlScratch->appendUChar(blr_begin); // Build body of FOR loop - dsql_nod* list = ExprNode::as<RseNode>(dsqlSelect)->dsqlSelectList; + dsql_nod* list = ExprNode::as<RseNode>(dsqlSelect->dsqlRse)->dsqlSelectList; if (dsqlInto) { @@ -4859,12 +4857,10 @@ dsql_nod* select_expr = MAKE_node(Dsql::nod_select_expr, Dsql::e_sel_count); select_expr->nod_arg[Dsql::e_sel_query_spec] = querySpecNod; - dsql_nod* select = MAKE_node(Dsql::nod_select, Dsql::e_select_count); - select->nod_arg[Dsql::e_select_expr] = select_expr; - // build a FOR SELECT node ForNode* forNode = FB_NEW(pool) ForNode(pool); - forNode->dsqlSelect = select; + forNode->dsqlSelect = FB_NEW(pool) SelectNode(pool); + forNode->dsqlSelect->dsqlExpr = select_expr; forNode->statement = FB_NEW(pool) CompoundStmtNode(pool); forNode = forNode->dsqlPass(dsqlScratch); @@ -4874,9 +4870,9 @@ // Get the already processed relations. source = ExprNode::as<RseNode>(ExprNode::as<RseNode>( - forNode->dsqlSelect)->dsqlStreams->nod_arg[0])->dsqlStreams->nod_arg[0]; + forNode->dsqlSelect->dsqlRse)->dsqlStreams->nod_arg[0])->dsqlStreams->nod_arg[0]; target = ExprNode::as<RseNode>(ExprNode::as<RseNode>( - forNode->dsqlSelect)->dsqlStreams->nod_arg[0])->dsqlStreams->nod_arg[1]; + forNode->dsqlSelect->dsqlRse)->dsqlStreams->nod_arg[0])->dsqlStreams->nod_arg[1]; DsqlContextStack usingCtxs; dsqlGetContexts(usingCtxs, source); @@ -6987,9 +6983,35 @@ return node; } -SelectNode* SelectNode::dsqlPass(DsqlCompilerScratch* /*dsqlScratch*/) +SelectNode* SelectNode::dsqlPass(DsqlCompilerScratch* dsqlScratch) { - return this; + SelectNode* node = FB_NEW(getPool()) SelectNode(getPool()); + + const DsqlContextStack::iterator base(*dsqlScratch->context); + node->dsqlRse = PASS1_rse(dsqlScratch, dsqlExpr, dsqlWithLock); + dsqlScratch->context->clear(base); + + if (dsqlForUpdate) + { + dsqlScratch->getStatement()->setType(DsqlCompiledStatement::TYPE_SELECT_UPD); + dsqlScratch->getStatement()->addFlags(DsqlCompiledStatement::FLAG_NO_BATCH); + } + else + { + // If there is a union without ALL or order by or a select distinct buffering is OK even if + // stored procedure occurs in the select list. In these cases all of stored procedure is + // executed under savepoint for open cursor. + + RseNode* rseNode = ExprNode::as<RseNode>(node->dsqlRse); + + if (rseNode->dsqlOrder || rseNode->dsqlDistinct) + { + dsqlScratch->getStatement()->setFlags( + dsqlScratch->getStatement()->getFlags() & ~DsqlCompiledStatement::FLAG_NO_BATCH); + } + } + + return node; } void SelectNode::print(string& text, Array<dsql_nod*>& /*nodes*/) const @@ -6997,8 +7019,155 @@ text = "SelectNode"; } -void SelectNode::genBlr(DsqlCompilerScratch* /*dsqlScratch*/) +// Generate BLR for a SELECT statement. +void SelectNode::genBlr(DsqlCompilerScratch* dsqlScratch) { + RseNode* const rse = ExprNode::as<RseNode>(dsqlRse); + fb_assert(rse); + + DsqlCompiledStatement* const statement = dsqlScratch->getStatement(); + + // Set up parameter for things in the select list. + const dsql_nod* list = rse->dsqlSelectList; + dsql_nod* const* ptr = list->nod_arg; + for (const dsql_nod* const* const end = ptr + list->nod_count; ptr != end; ++ptr) + { + dsql_par* parameter = MAKE_parameter(statement->getReceiveMsg(), true, true, 0, *ptr); + parameter->par_node = *ptr; + MAKE_desc(dsqlScratch, ¶meter->par_desc, *ptr); + } + + // Set up parameter to handle EOF. + + dsql_par* const parameterEof = MAKE_parameter(statement->getReceiveMsg(), false, false, 0, NULL); + statement->setEof(parameterEof); + parameterEof->par_desc.dsc_dtype = dtype_short; + parameterEof->par_desc.dsc_scale = 0; + parameterEof->par_desc.dsc_length = sizeof(SSHORT); + + // Save DBKEYs for possible update later. + + GenericMap<NonPooled<dsql_par*, dsql_ctx*> > paramContexts(*getDefaultMemoryPool()); + dsql_ctx* context; + + if (statement->getType() == DsqlCompiledStatement::TYPE_SELECT_UPD && !rse->dsqlDistinct) + { + list = rse->dsqlStreams; + dsql_nod* const* ptr2 = list->nod_arg; + for (const dsql_nod* const* const end2 = ptr2 + list->nod_count; ptr2 != end2; ++ptr2) + { + dsql_nod* const item = *ptr2; + RelationSourceNode* relNode; + + if (item && (relNode = ExprNode::as<RelationSourceNode>(item))) + { + context = relNode->dsqlContext; + const dsql_rel* const relation = context->ctx_relation; + + if (relation) + { + // Set up dbkey. + dsql_par* parameter = MAKE_parameter( + statement->getReceiveMsg(), false, false, 0, NULL); + + parameter->par_dbkey_relname = relation->rel_name; + paramContexts.put(parameter, context); + + parameter->par_desc.dsc_dtype = dtype_text; + parameter->par_desc.dsc_ttype() = ttype_binary; + parameter->par_desc.dsc_length = relation->rel_dbkey_length; + + // Set up record version - for post v33 databases. + + parameter = MAKE_parameter(statement->getReceiveMsg(), false, false, 0, NULL); + parameter->par_rec_version_relname = relation->rel_name; + paramContexts.put(parameter, context); + + parameter->par_desc.dsc_dtype = dtype_text; + parameter->par_desc.dsc_ttype() = ttype_binary; + parameter->par_desc.dsc_length = relation->rel_dbkey_length / 2; + } + } + } + } + + // Generate definitions for the messages. + + GEN_port(dsqlScratch, statement->getReceiveMsg()); + dsql_msg* message = statement->getSendMsg(); + if (message->msg_parameter) + GEN_port(dsqlScratch, message); + else + statement->setSendMsg(NULL); + + // If there is a send message, build a RECEIVE. + + if ((message = statement->getSendMsg()) != NULL) + { + dsqlScratch->appendUChar(blr_receive); + dsqlScratch->appendUChar(message->msg_number); + } + + // Generate FOR loop. + + message = statement->getReceiveMsg(); + + dsqlScratch->appendUChar(blr_for); + dsqlScratch->appendUChar(blr_stall); + GEN_rse(dsqlScratch, dsqlRse); + + dsqlScratch->appendUChar(blr_send); + dsqlScratch->appendUChar(message->msg_number); + dsqlScratch->appendUChar(blr_begin); + + // Build body of FOR loop. + + SSHORT constant; + dsc constant_desc; + constant_desc.makeShort(0, &constant); + + // Add invalid usage here. + + dsqlScratch->appendUChar(blr_assignment); + constant = 1; + LiteralNode::genConstant(dsqlScratch, &constant_desc, false); + GEN_parameter(dsqlScratch, statement->getEof()); + + for (size_t i = 0; i < message->msg_parameters.getCount(); ++i) + { + dsql_par* const parameter = message->msg_parameters[i]; + + if (parameter->par_node) + { + dsqlScratch->appendUChar(blr_assignment); + GEN_expr(dsqlScratch, parameter->par_node); + GEN_parameter(dsqlScratch, parameter); + } + + if (parameter->par_dbkey_relname.hasData() && paramContexts.get(parameter, context)) + { + dsqlScratch->appendUChar(blr_assignment); + dsqlScratch->appendUChar(blr_dbkey); + GEN_stuff_context(dsqlScratch, context); + GEN_parameter(dsqlScratch, parameter); + } + + if (parameter->par_rec_version_relname.hasData() && paramContexts.get(parameter, context)) + { + dsqlScratch->appendUChar(blr_assignment); + dsqlScratch->appendUChar(blr_record_version); + GEN_stuff_context(dsqlScratch, context); + GEN_parameter(dsqlScratch, parameter); + } + } + + dsqlScratch->appendUChar(blr_end); + dsqlScratch->appendUChar(blr_send); + dsqlScratch->appendUChar(message->msg_number); + dsqlScratch->appendUChar(blr_assignment); + constant = 0; + LiteralNode::genConstant(dsqlScratch, &constant_desc, false); + GEN_parameter(dsqlScratch, statement->getEof()); } SelectNode* SelectNode::pass1(thread_db* tdbb, CompilerScratch* csb) Modified: firebird/trunk/src/dsql/StmtNodes.h =================================================================== --- firebird/trunk/src/dsql/StmtNodes.h 2012-02-10 03:06:22 UTC (rev 53997) +++ firebird/trunk/src/dsql/StmtNodes.h 2012-02-10 03:06:57 UTC (rev 53998) @@ -36,6 +36,7 @@ class CompoundStmtNode; class ExecBlockNode; class RelationSourceNode; +class SelectNode; typedef Firebird::Pair<Firebird::NonPooled<dsql_nod*, Firebird::Array<dsql_nod*>*> > ReturningClause; @@ -327,6 +328,7 @@ dsqlCursorType(aDsqlCursorType), dsqlScroll(false), dsqlName(aDsqlName), + dsqlSelect(NULL), dsqlRse(NULL), rse(NULL), refs(NULL), @@ -349,6 +351,7 @@ USHORT dsqlCursorType; bool dsqlScroll; Firebird::MetaName dsqlName; + SelectNode* dsqlSelect; dsql_nod* dsqlRse; NestConst<RseNode> rse; NestConst<ValueListNode> refs; @@ -874,7 +877,7 @@ virtual const StmtNode* execute(thread_db* tdbb, jrd_req* request, ExeState* exeState) const; public: - dsql_nod* dsqlSelect; + SelectNode* dsqlSelect; Firebird::Array<dsql_nod*>* dsqlInto; dsql_nod* dsqlCursor; dsql_nod* dsqlLabel; @@ -1274,6 +1277,10 @@ public: explicit SelectNode(MemoryPool& pool) : TypedNode<StmtNode, StmtNode::TYPE_SELECT>(pool), + dsqlExpr(NULL), + dsqlForUpdate(false), + dsqlWithLock(false), + dsqlRse(NULL), statements(pool) { } @@ -1289,6 +1296,10 @@ virtual const StmtNode* execute(thread_db* tdbb, jrd_req* request, ExeState* exeState) const; public: + dsql_nod* dsqlExpr; + bool dsqlForUpdate; + bool dsqlWithLock; + dsql_nod* dsqlRse; Firebird::Array<NestConst<StmtNode> > statements; }; Modified: firebird/trunk/src/dsql/gen.cpp =================================================================== --- firebird/trunk/src/dsql/gen.cpp 2012-02-10 03:06:22 UTC (rev 53997) +++ firebird/trunk/src/dsql/gen.cpp 2012-02-10 03:06:57 UTC (rev 53998) @@ -65,7 +65,6 @@ using namespace Firebird; static void gen_plan(DsqlCompilerScratch*, const dsql_nod*); -static void gen_select(DsqlCompilerScratch*, dsql_nod*); static void gen_union(DsqlCompilerScratch*, const dsql_nod*); @@ -323,8 +322,6 @@ { case DsqlCompiledStatement::TYPE_SELECT: case DsqlCompiledStatement::TYPE_SELECT_UPD: - gen_select(scratch, node); - break; case DsqlCompiledStatement::TYPE_EXEC_BLOCK: case DsqlCompiledStatement::TYPE_SELECT_BLOCK: GEN_statement(scratch, node); @@ -724,170 +721,6 @@ } -/** - - gen_select - - @brief Generate BLR for a SELECT statement. - - - @param dsqlScratch - @param rse - - **/ -static void gen_select(DsqlCompilerScratch* dsqlScratch, dsql_nod* rseNod) -{ - dsql_ctx* context; - - RseNode* const rse = ExprNode::as<RseNode>(rseNod); - fb_assert(rse); - - DsqlCompiledStatement* const statement = dsqlScratch->getStatement(); - - // Set up parameter for things in the select list - const dsql_nod* list = rse->dsqlSelectList; - dsql_nod* const* ptr = list->nod_arg; - for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr++) - { - dsql_par* parameter = MAKE_parameter(statement->getReceiveMsg(), true, true, 0, *ptr); - parameter->par_node = *ptr; - MAKE_desc(dsqlScratch, ¶meter->par_desc, *ptr); - } - - // Set up parameter to handle EOF - - dsql_par* const parameter_eof = - MAKE_parameter(statement->getReceiveMsg(), false, false, 0, NULL); - statement->setEof(parameter_eof); - parameter_eof->par_desc.dsc_dtype = dtype_short; - parameter_eof->par_desc.dsc_scale = 0; - parameter_eof->par_desc.dsc_length = sizeof(SSHORT); - - // Save DBKEYs for possible update later - - GenericMap<NonPooled<dsql_par*, dsql_ctx*> > paramContexts(*getDefaultMemoryPool()); - - if (statement->getType() == DsqlCompiledStatement::TYPE_SELECT_UPD && !rse->dsqlDistinct) - { - list = rse->dsqlStreams; - dsql_nod* const* ptr2 = list->nod_arg; - for (const dsql_nod* const* const end2 = ptr2 + list->nod_count; ptr2 < end2; ptr2++) - { - dsql_nod* const item = *ptr2; - RelationSourceNode* relNode; - - if (item && (relNode = ExprNode::as<RelationSourceNode>(item))) - { - context = relNode->dsqlContext; - const dsql_rel* const relation = context->ctx_relation; - - if (relation) - { - // Set up dbkey - dsql_par* parameter = - MAKE_parameter(statement->getReceiveMsg(), false, false, 0, NULL); - - parameter->par_dbkey_relname = relation->rel_name; - paramContexts.put(parameter, context); - - parameter->par_desc.dsc_dtype = dtype_text; - parameter->par_desc.dsc_ttype() = ttype_binary; - parameter->par_desc.dsc_length = relation->rel_dbkey_length; - - // Set up record version - for post v33 databases - - parameter = MAKE_parameter(statement->getReceiveMsg(), false, false, 0, NULL); - parameter->par_rec_version_relname = relation->rel_name; - paramContexts.put(parameter, context); - - parameter->par_desc.dsc_dtype = dtype_text; - parameter->par_desc.dsc_ttype() = ttype_binary; - parameter->par_desc.dsc_length = relation->rel_dbkey_length / 2; - } - } - } - } - - // Generate definitions for the messages - - GEN_port(dsqlScratch, statement->getReceiveMsg()); - dsql_msg* message = statement->getSendMsg(); - if (message->msg_parameter) - GEN_port(dsqlScratch, message); - else - statement->setSendMsg(NULL); - - // If there is a send message, build a RECEIVE - - if ((message = statement->getSendMsg()) != NULL) - { - dsqlScratch->appendUChar(blr_receive); - dsqlScratch->appendUChar(message->msg_number); - } - - // Generate FOR loop - - message = statement->getReceiveMsg(); - - dsqlScratch->appendUChar(blr_for); - dsqlScratch->appendUChar(blr_stall); - GEN_rse(dsqlScratch, rseNod); - - dsqlScratch->appendUChar(blr_send); - dsqlScratch->appendUChar(message->msg_number); - dsqlScratch->appendUChar(blr_begin); - - // Build body of FOR loop - - SSHORT constant; - dsc constant_desc; - constant_desc.makeShort(0, &constant); - - // Add invalid usage here - - dsqlScratch->appendUChar(blr_assignment); - constant = 1; - LiteralNode::genConstant(dsqlScratch, &constant_desc, false); - GEN_parameter(dsqlScratch, statement->getEof()); - - for (size_t i = 0; i < message->msg_parameters.getCount(); ++i) - { - dsql_par* const parameter = message->msg_parameters[i]; - - if (parameter->par_node) - { - dsqlScratch->appendUChar(blr_assignment); - GEN_expr(dsqlScratch, parameter->par_node); - GEN_parameter(dsqlScratch, parameter); - } - - if (parameter->par_dbkey_relname.hasData() && paramContexts.get(parameter, context)) - { - dsqlScratch->appendUChar(blr_assignment); - dsqlScratch->appendUChar(blr_dbkey); - GEN_stuff_context(dsqlScratch, context); - GEN_parameter(dsqlScratch, parameter); - } - - if (parameter->par_rec_version_relname.hasData() && paramContexts.get(parameter, context)) - { - dsqlScratch->appendUChar(blr_assignment); - dsqlScratch->appendUChar(blr_record_version); - GEN_stuff_context(dsqlScratch, context); - GEN_parameter(dsqlScratch, parameter); - } - } - - dsqlScratch->appendUChar(blr_end); - dsqlScratch->appendUChar(blr_send); - dsqlScratch->appendUChar(message->msg_number); - dsqlScratch->appendUChar(blr_assignment); - constant = 0; - LiteralNode::genConstant(dsqlScratch, &constant_desc, false); - GEN_parameter(dsqlScratch, statement->getEof()); -} - - // Generate a sort clause. void GEN_sort(DsqlCompilerScratch* dsqlScratch, dsql_nod* list) { Modified: firebird/trunk/src/dsql/node.h =================================================================== --- firebird/trunk/src/dsql/node.h 2012-02-10 03:06:22 UTC (rev 53997) +++ firebird/trunk/src/dsql/node.h 2012-02-10 03:06:57 UTC (rev 53998) @@ -109,7 +109,6 @@ nod_mod_field_name, nod_mod_field_type, nod_mod_field_pos, - nod_for_update, // FOR UPDATE clause nod_label, // label support nod_rows, // ROWS support nod_with, @@ -132,14 +131,6 @@ * entries. These include nod_udf and nod_collate. */ enum node_args { - e_select_expr = 0, // nod_select - e_select_update, - e_select_lock, - e_select_count, - - e_fpd_list = 0, // nod_for_update - e_fpd_count, - e_ary_array = 0, // nod_array e_ary_indices, e_ary_count, Modified: firebird/trunk/src/dsql/parse.y =================================================================== --- firebird/trunk/src/dsql/parse.y 2012-02-10 03:06:22 UTC (rev 53997) +++ firebird/trunk/src/dsql/parse.y 2012-02-10 03:06:57 UTC (rev 53998) @@ -670,6 +670,7 @@ Jrd::ErrorHandlerNode* errorHandlerNode; Jrd::ExecStatementNode* execStatementNode; Jrd::MergeNode* mergeNode; + Jrd::SelectNode* selectNode; Jrd::SetTransactionNode* setTransactionNode; Jrd::DeclareSubProcNode* declareSubProcNode; Jrd::DeclareSubFuncNode* declareSubFuncNode; @@ -756,7 +757,8 @@ %type <stmtNode> fetch_cursor %type <legacyNode> first_clause -%type <legacyNode> float_type for_update_clause for_update_list from_clause +%type <legacyNode> float_type for_update_list from_clause +%type <boolVal> for_update_clause %type <legacyNode> from_list %type <ddlNode> filter_decl_clause %type <stmtNode> for_select full_proc_block full_proc_block_body @@ -790,7 +792,8 @@ %type <legacyNode> label_opt limit_clause %type <stmtNode> local_declaration local_declaration_item %type <compoundStmtNode> local_declaration_list local_declarations -%type <legacyNode> lock_clause lock_mode lock_type +%type <boolVal> lock_clause +%type <legacyNode> lock_mode lock_type %type <stringPtr> lastname_opt %type <int32Val> long_integer @@ -854,11 +857,12 @@ %type <legacyNode> scroll_opt search_condition searched_case %type <valueIfNode> searched_when_clause %type sec_shadow_files(<dbFilesClause>) -%type <legacyNode> select select_expr +%type <legacyNode> select_expr %type <legacyNode> select_expr_body select_item select_items select_list %type <createShadowNode> shadow_clause %type <legacyNode> simple_case simple_UDF_name %type <legacyNode> simple_column_name simple_package_name simple_proc_name simple_table_name +%type <selectNode> select %type <stmtNode> set_generator simple_proc_statement singleton_select %type <setTransactionNode> set_transaction %type <ddlNode> set_statistics @@ -1017,7 +1021,7 @@ | revoke | rollback { $$ = makeClassNode($1); } | savepoint { $$ = makeClassNode($1); } - | select + | select { $$ = makeClassNode($1); } | set_transaction { $$ = makeClassNode($1); } | set_generator { $$ = makeClassNode($1); } | set_statistics { $$ = makeClassNode($1); } @@ -2422,7 +2426,7 @@ DeclareCursorNode* node = newNode<DeclareCursorNode>(toName($1), DeclareCursorNode::CUR_TYPE_EXPLICIT); node->dsqlScroll = $2 != NULL; - node->dsqlRse = $6; + node->dsqlSelect = $6; $$ = node; } ; @@ -4320,22 +4324,28 @@ select : select_expr for_update_clause lock_clause - { $$ = make_node(nod_select, (int) e_select_count, $1, $2, $3); } + { + SelectNode* node = newNode<SelectNode>(); + node->dsqlExpr = $1; + node->dsqlForUpdate = $2; + node->dsqlWithLock = $3; + $$ = node; + } ; for_update_clause - : /* nothing */ { $$ = NULL; } - | FOR UPDATE for_update_list { $$ = make_node(nod_for_update, (int) e_fpd_count, $3); } + : /* nothing */ { $$ = false; } + | FOR UPDATE for_update_list { $$ = true; /* for_update_list is ignored */ } ; for_update_list - : /* nothing */ { $$ = make_node(nod_flag, 0, NULL); } + : /* nothing */ { $$ = NULL; } | OF column_list { $$ = $2; } ; lock_clause - : /* nothing */ { $$ = NULL; } - | WITH LOCK { $$ = make_node(nod_flag, 0, NULL); } + : /* nothing */ { $$ = false; } + | WITH LOCK { $$ = true; } ; Modified: firebird/trunk/src/dsql/pass1.cpp =================================================================== --- firebird/trunk/src/dsql/pass1.cpp 2012-02-10 03:06:22 UTC (rev 53997) +++ firebird/trunk/src/dsql/pass1.cpp 2012-02-10 03:06:57 UTC (rev 53998) @@ -196,10 +196,10 @@ static dsql_nod* pass1_field(DsqlCompilerScratch*, dsql_nod*, const bool, dsql_nod*); static dsql_nod* pass1_group_by_list(DsqlCompilerScratch*, dsql_nod*, dsql_nod*); static dsql_nod* pass1_make_derived_field(DsqlCompilerScratch*, thread_db*, dsql_nod*); -static dsql_nod* pass1_rse(DsqlCompilerScratch*, dsql_nod*, dsql_nod*, dsql_nod*, dsql_nod*, USHORT); -static dsql_nod* pass1_rse_impl(DsqlCompilerScratch*, dsql_nod*, dsql_nod*, dsql_nod*, dsql_nod*, USHORT); +static dsql_nod* pass1_rse(DsqlCompilerScratch*, dsql_nod*, dsql_nod*, dsql_nod*, bool, USHORT); +static dsql_nod* pass1_rse_impl(DsqlCompilerScratch*, dsql_nod*, dsql_nod*, dsql_nod*, bool, USHORT); static dsql_nod* pass1_sel_list(DsqlCompilerScratch*, dsql_nod*, bool); -static dsql_nod* pass1_union(DsqlCompilerScratch*, dsql_nod*, dsql_nod*, dsql_nod*, dsql_nod*, USHORT); +static dsql_nod* pass1_union(DsqlCompilerScratch*, dsql_nod*, dsql_nod*, dsql_nod*, bool, USHORT); static void pass1_union_auto_cast(DsqlCompilerScratch*, dsql_nod*, const dsc&, SSHORT, bool in_select_list = false); static dsql_nod* pass1_variable(DsqlCompilerScratch*, dsql_nod*); @@ -724,7 +724,7 @@ const DsqlContextStack::iterator base(*dsqlScratch->context); - dsql_nod* rseNod = PASS1_rse(dsqlScratch, input, NULL); + dsql_nod* rseNod = PASS1_rse(dsqlScratch, input, false); RseNode* rse = ExprNode::as<RseNode>(rseNod); SubQueryNode* subQueryNode = FB_NEW(*tdbb->getDefaultPool()) SubQueryNode(*tdbb->getDefaultPool(), @@ -825,31 +825,17 @@ } -/** - - PASS1_rse - - @brief Compile a record selection expression, - bumping up the statement scope level - everytime an rse is seen. The scope - level controls parsing of aliases. - - - @param dsqlScratch - @param input - @param update_lock - - **/ -dsql_nod* PASS1_rse(DsqlCompilerScratch* dsqlScratch, dsql_nod* input, dsql_nod* update_lock) +// Compile a record selection expression, bumping up the statement scope level everytime an rse is +// seen. The scope level controls parsing of aliases. +dsql_nod* PASS1_rse(DsqlCompilerScratch* dsqlScratch, dsql_nod* input, bool updateLock) { DEV_BLKCHK(dsqlScratch, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); - DEV_BLKCHK(update_lock, dsql_type_nod); fb_assert(input->nod_type == nod_select_expr); dsqlScratch->scopeLevel++; - dsql_nod* node = pass1_rse(dsqlScratch, input, NULL, NULL, update_lock, 0); + dsql_nod* node = pass1_rse(dsqlScratch, input, NULL, NULL, updateLock, 0); dsqlScratch->scopeLevel--; return node; @@ -922,32 +908,6 @@ return node; } - case nod_select: - { - node = PASS1_rse(dsqlScratch, input->nod_arg[e_select_expr], input->nod_arg[e_select_lock]); - - if (input->nod_arg[e_select_update]) - { - dsqlScratch->getStatement()->setType(DsqlCompiledStatement::TYPE_SELECT_UPD); - dsqlScratch->getStatement()->addFlags(DsqlCompiledStatement::FLAG_NO_BATCH); - break; - } - - // If there is a union without ALL or order by or a select distinct - // buffering is OK even if stored procedure occurs in the select - // list. In these cases all of stored procedure is executed under - // savepoint for open cursor. - - RseNode* rseNode = ExprNode::as<RseNode>(node); - - if (rseNode->dsqlOrder || rseNode->dsqlDistinct) - { - dsqlScratch->getStatement()->setFlags(dsqlScratch->getStatement()->getFlags() & - ~DsqlCompiledStatement::FLAG_NO_BATCH); - } - } - break; - default: ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-901) << Arg::Gds(isc_dsql_command_err) << @@ -1596,7 +1556,7 @@ rse = pass1_union(dsqlScratch, union_expr, NULL, NULL, NULL, 0); } else - rse = PASS1_rse(dsqlScratch, input, NULL); + rse = PASS1_rse(dsqlScratch, input, false); USHORT minOuterJoin = MAX_USHORT; @@ -1783,7 +1743,7 @@ dsqlScratch->resetCTEAlias(alias->str_data); - rse = PASS1_rse(dsqlScratch, input, NULL); + rse = PASS1_rse(dsqlScratch, input, false); // Finish off by cleaning up contexts and put them into derivedContext // so create view (ddl) can deal with it. @@ -3020,24 +2980,9 @@ } -/** - - pass1_rse - - @brief wrapper for pass1_rse_impl - substitute recursive CTE alias (if needed) - and call pass1_rse_impl - - @param dsqlScratch - @param input - @param order - @param rows - @param update_lock - @param flags - - **/ +// Wrapper for pass1_rse_impl. Substitute recursive CTE alias (if needed) and call pass1_rse_impl. static dsql_nod* pass1_rse( DsqlCompilerScratch* dsqlScratch, dsql_nod* input, dsql_nod* order, - dsql_nod* rows, dsql_nod* update_lock, USHORT flags) + dsql_nod* rows, bool updateLock, USHORT flags) { string save_alias; const bool isRecursive = (input->nod_flags & NOD_SELECT_EXPR_RECURSIVE); @@ -3050,7 +2995,7 @@ dsqlScratch->recursiveCtx->ctx_alias = *dsqlScratch->getNextCTEAlias(); } - dsql_nod* ret = pass1_rse_impl(dsqlScratch, input, order, rows, update_lock, flags); + dsql_nod* ret = pass1_rse_impl(dsqlScratch, input, order, rows, updateLock, flags); if (isRecursive) dsqlScratch->recursiveCtx->ctx_alias = save_alias; @@ -3059,25 +3004,10 @@ } -/** - - pass1_rse_impl - - @brief Compile a record selection expression. - The input node may either be a "select_expression" - or a "list" (an implicit union) or a "query specification". - - - @param dsqlScratch - @param input - @param order - @param rows - @param update_lock - @param flags - - **/ +// Compile a record selection expression. The input node may either be a "select_expression" +// or a "list" (an implicit union) or a "query specification". static dsql_nod* pass1_rse_impl( DsqlCompilerScratch* dsqlScratch, dsql_nod* input, dsql_nod* order, - dsql_nod* rows, dsql_nod* update_lock, USHORT flags) + dsql_nod* rows, bool updateLock, USHORT flags) { DEV_BLKCHK(dsqlScratch, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); @@ -3099,10 +3029,8 @@ if (node_with) dsqlScratch->addCTEs(node_with); - dsql_nod* ret = - pass1_rse(dsqlScratch, input->nod_arg[e_sel_query_spec], - input->nod_arg[e_sel_order], input->nod_arg[e_sel_rows], - update_lock, viewFlags); + dsql_nod* ret = pass1_rse(dsqlScratch, input->nod_arg[e_sel_query_spec], + input->nod_arg[e_sel_order], input->nod_arg[e_sel_rows], updateLock, viewFlags); if (node_with) { @@ -3122,7 +3050,7 @@ else if (input->nod_type == nod_list) { fb_assert(input->nod_count > 1); - return pass1_union(dsqlScratch, input, order, rows, update_lock, flags); + return pass1_union(dsqlScratch, input, order, rows, updateLock, flags); } RseNode* inputRse = ExprNode::as<RseNode>(input); @@ -3136,7 +3064,7 @@ dsql_nod* rseNod = MAKE_node(nod_class_exprnode, 1); rseNod->nod_arg[0] = reinterpret_cast<dsql_nod*>(rse); - if (update_lock) + if (updateLock) rse->flags |= RseNode::FLAG_WRITELOCK; dsql_nod* list = rse->dsqlStreams = PASS1_node_psql(dsqlScratch, inputRse->dsqlFrom, false); @@ -3145,7 +3073,7 @@ RelationSourceNode* relNode; const dsql_rel* relation; - if (update_lock && + if (updateLock && (list->nod_count != 1 || !(relNode = ExprNode::as<RelationSourceNode>(list->nod_arg[0])) || !(relation = relNode->dsqlContext->ctx_relation) || (relation->rel_flags & REL_view) || (relation->rel_flags & REL_external))) @@ -3237,7 +3165,7 @@ (rse->dsqlOrder && AggregateFinder::find(dsqlScratch, false, rse->dsqlOrder))) { // dimitr: don't allow WITH LOCK for aggregates - if (update_lock) + if (updateLock) { ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << // Token unknown @@ -3308,7 +3236,7 @@ // sub-selects a new context number should be generated if (inputRse->dsqlDistinct) { - if (update_lock) + if (updateLock) { ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << // Token unknown @@ -3677,26 +3605,10 @@ } -/** - - pass1_union - - @brief Handle a UNION of substreams, generating - a mapping of all the fields and adding an - implicit PROJECT clause to ensure that all - the records returned are unique. - - - @param dsqlScratch - @param input - @param order_list - @param rows - @param update_lock - @param flags - - **/ +// Handle a UNION of substreams, generating a mapping of all the fields and adding an implicit +// PROJECT clause to ensure that all the records returned are unique. static dsql_nod* pass1_union( DsqlCompilerScratch* dsqlScratch, dsql_nod* input, dsql_nod* order_list, - dsql_nod* rows, dsql_nod* update_lock, USHORT flags) + dsql_nod* rows, bool updateLock, USHORT flags) { DEV_BLKCHK(dsqlScratch, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); @@ -3741,7 +3653,7 @@ for (const dsql_nod* const* const end = ptr + input->nod_count; ptr < end; ++ptr, ++uptr) { dsqlScratch->scopeLevel++; - *uptr = pass1_rse(dsqlScratch, *ptr, NULL, NULL, NULL, 0); + *uptr = pass1_rse(dsqlScratch, *ptr, NULL, NULL, false, 0); dsqlScratch->scopeLevel--; while (*(dsqlScratch->context) != base) @@ -3911,7 +3823,7 @@ // PROJECT on all the select items unless UNION ALL was specified. if (!(input->nod_flags & NOD_UNION_ALL)) { - if (update_lock) + if (updateLock) { ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << // Token unknown @@ -3922,7 +3834,7 @@ unionRse->dsqlDistinct = union_items; } - if (update_lock) + if (updateLock) unionRse->flags |= RseNode::FLAG_WRITELOCK; dsql_nod* unionRseNod = MAKE_node(nod_class_exprnode, 1); @@ -4765,9 +4677,6 @@ case nod_mod_field_pos: verb = "mod_field_pos"; break; - case nod_for_update: - verb = "for_update"; - break; case nod_label: verb = "label"; Modified: firebird/trunk/src/dsql/pass1_proto.h =================================================================== --- firebird/trunk/src/dsql/pass1_proto.h 2012-02-10 03:06:22 UTC (rev 53997) +++ firebird/trunk/src/dsql/pass1_proto.h 2012-02-10 03:06:57 UTC (rev 53998) @@ -50,7 +50,7 @@ Jrd::dsql_nod*, Jrd::dsql_nod*); void PASS1_put_args_on_stack(Jrd::DsqlCompilerScratch*, Jrd::dsql_nod*, Jrd::DsqlNodStack&); Jrd::dsql_nod* PASS1_relation(Jrd::DsqlCompilerScratch*, Jrd::dsql_nod*); -Jrd::dsql_nod* PASS1_rse(Jrd::DsqlCompilerScratch*, Jrd::dsql_nod*, Jrd::dsql_nod*); +Jrd::dsql_nod* PASS1_rse(Jrd::DsqlCompilerScratch*, Jrd::dsql_nod*, bool); bool PASS1_set_parameter_type(Jrd::DsqlCompilerScratch*, Jrd::dsql_nod*, Jrd::dsql_nod*, bool); Jrd::dsql_nod* PASS1_sort(Jrd::DsqlCompilerScratch*, Jrd::dsql_nod*, Jrd::dsql_nod*); Jrd::dsql_nod* PASS1_statement(Jrd::DsqlCompilerScratch*, Jrd::dsql_nod*); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2012-02-20 02:02:11
|
Revision: 54025 http://firebird.svn.sourceforge.net/firebird/?rev=54025&view=rev Author: asfernandes Date: 2012-02-20 02:02:04 +0000 (Mon, 20 Feb 2012) Log Message: ----------- Remove legacy statements residuals. Modified Paths: -------------- firebird/trunk/src/dsql/DdlNodes.epp firebird/trunk/src/dsql/DsqlCompilerScratch.h firebird/trunk/src/dsql/Nodes.h firebird/trunk/src/dsql/PackageNodes.epp firebird/trunk/src/dsql/Parser.cpp firebird/trunk/src/dsql/Parser.h firebird/trunk/src/dsql/StmtNodes.cpp firebird/trunk/src/dsql/StmtNodes.h firebird/trunk/src/dsql/ddl.cpp firebird/trunk/src/dsql/ddl_proto.h firebird/trunk/src/dsql/dsql.cpp firebird/trunk/src/dsql/dsql.h firebird/trunk/src/dsql/gen.cpp firebird/trunk/src/dsql/gen_proto.h firebird/trunk/src/dsql/node.h firebird/trunk/src/dsql/parse.y firebird/trunk/src/dsql/pass1.cpp firebird/trunk/src/dsql/pass1_proto.h Modified: firebird/trunk/src/dsql/DdlNodes.epp =================================================================== --- firebird/trunk/src/dsql/DdlNodes.epp 2012-02-19 10:36:54 UTC (rev 54024) +++ firebird/trunk/src/dsql/DdlNodes.epp 2012-02-20 02:02:04 UTC (rev 54025) @@ -296,9 +296,6 @@ 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); @@ -6112,9 +6109,6 @@ actionNode->statements.add(exceptionNode); - dsql_nod* actionNod = MAKE_node(Dsql::nod_class_stmtnode, 1); - actionNod->nod_arg[0] = reinterpret_cast<dsql_nod*>(actionNode); - // Generate the trigger blr. dsqlScratch->getBlrData().clear(); @@ -6152,7 +6146,7 @@ GEN_expr(dsqlScratch, condition); // Generate the action statement for the trigger. - GEN_statement(dsqlScratch, PASS1_statement(dsqlScratch, actionNod)); + Node::doDsqlPass(dsqlScratch, actionNode)->genBlr(dsqlScratch); dsqlScratch->appendUChar(blr_end); // of if (as there's no ELSE branch) dsqlScratch->appendUChar(blr_end); // of begin Modified: firebird/trunk/src/dsql/DsqlCompilerScratch.h =================================================================== --- firebird/trunk/src/dsql/DsqlCompilerScratch.h 2012-02-19 10:36:54 UTC (rev 54024) +++ firebird/trunk/src/dsql/DsqlCompilerScratch.h 2012-02-20 02:02:04 UTC (rev 54025) @@ -119,8 +119,7 @@ virtual bool isDdlDyn() { - return (statement->getType() == DsqlCompiledStatement::TYPE_DDL || statement->getDdlNode()) && - !(flags & FLAG_BLOCK); + return statement->isDdl() && !(flags & FLAG_BLOCK); } public: Modified: firebird/trunk/src/dsql/Nodes.h =================================================================== --- firebird/trunk/src/dsql/Nodes.h 2012-02-19 10:36:54 UTC (rev 54024) +++ firebird/trunk/src/dsql/Nodes.h 2012-02-20 02:02:04 UTC (rev 54025) @@ -106,6 +106,16 @@ { } + // Compile a parsed statement into something more interesting. + template <typename T> + static T* doDsqlPass(DsqlCompilerScratch* dsqlScratch, T* node) + { + if (!node) + return NULL; + + return node->dsqlPass(dsqlScratch); + } + virtual void print(Firebird::string& text, Firebird::Array<dsql_nod*>& nodes) const = 0; virtual Node* dsqlPass(DsqlCompilerScratch* /*dsqlScratch*/) @@ -945,36 +955,21 @@ return type == T::TYPE; } - template <typename T, typename LegacyType> static T* as(LegacyType* node) + template <typename T, typename T2> static T* as(T2* node) { - StmtNode* obj = T::fromLegacy(node); - return obj ? obj->as<T>() : NULL; + return node ? node->as<T>() : NULL; } - template <typename T, typename LegacyType> static const T* as(const LegacyType* node) + template <typename T, typename T2> static const T* as(const T2* node) { - const StmtNode* obj = T::fromLegacy(node); - return obj ? obj->as<T>() : NULL; + return node ? node->as<T>() : NULL; } - template <typename T, typename LegacyType> static bool is(const LegacyType* node) + template <typename T, typename T2> static bool is(const T2* node) { - const StmtNode* obj = T::fromLegacy(node); - return obj ? obj->is<T>() : false; + return node && node->is<T>(); } - static const StmtNode* fromLegacy(const StmtNode* node) - { - return node; - } - - static StmtNode* fromLegacy(StmtNode* node) - { - return node; - } - - static StmtNode* fromLegacy(const dsql_nod* node); - // Allocate and assign impure space for various nodes. template <typename T> static void doPass2(thread_db* tdbb, CompilerScratch* csb, T** node, StmtNode* parentStmt) Modified: firebird/trunk/src/dsql/PackageNodes.epp =================================================================== --- firebird/trunk/src/dsql/PackageNodes.epp 2012-02-19 10:36:54 UTC (rev 54024) +++ firebird/trunk/src/dsql/PackageNodes.epp 2012-02-20 02:02:04 UTC (rev 54025) @@ -411,7 +411,6 @@ itemScratch->clientDialect = dsqlScratch->clientDialect; itemScratch->package = name; - itemStatement->setDdlNode(MAKE_node(nod_class_stmtnode, 1)); switch ((*items)[i].type) { @@ -421,7 +420,6 @@ functionNames.add(fun->name); fun->alter = true; fun->package = name; - itemStatement->getDdlNode()->nod_arg[0] = (dsql_nod*) fun; fun->dsqlPass(itemScratch); } break; @@ -432,7 +430,6 @@ procedureNames.add(proc->name); proc->alter = true; proc->package = name; - itemStatement->getDdlNode()->nod_arg[0] = (dsql_nod*) proc; proc->dsqlPass(itemScratch); } break; @@ -768,7 +765,6 @@ itemScratch->clientDialect = dsqlScratch->clientDialect; itemScratch->package = name; - itemStatement->setDdlNode(MAKE_node(nod_class_stmtnode, 1)); switch ((*arrays[i])[j].type) { @@ -779,7 +775,6 @@ fun->create = true; if (arrays[i] == items) fun->alter = true; - itemStatement->getDdlNode()->nod_arg[0] = (dsql_nod*) fun; fun->dsqlPass(itemScratch); } break; @@ -791,7 +786,6 @@ proc->create = true; if (arrays[i] == items) proc->alter = true; - itemStatement->getDdlNode()->nod_arg[0] = (dsql_nod*) proc; proc->dsqlPass(itemScratch); } break; Modified: firebird/trunk/src/dsql/Parser.cpp =================================================================== --- firebird/trunk/src/dsql/Parser.cpp 2012-02-19 10:36:54 UTC (rev 54024) +++ firebird/trunk/src/dsql/Parser.cpp 2012-02-20 02:02:04 UTC (rev 54025) @@ -91,7 +91,7 @@ } -dsql_nod* Parser::parse() +Node* Parser::parse() { if (parseAux() != 0) return NULL; Modified: firebird/trunk/src/dsql/Parser.h =================================================================== --- firebird/trunk/src/dsql/Parser.h 2012-02-19 10:36:54 UTC (rev 54024) +++ firebird/trunk/src/dsql/Parser.h 2012-02-20 02:02:04 UTC (rev 54025) @@ -128,7 +128,7 @@ ~Parser(); public: - dsql_nod* parse(); + Node* parse(); const Firebird::string& getTransformedString() const { @@ -271,8 +271,6 @@ ParameterNode* make_parameter(); dsql_nod* make_node(Dsql::nod_t type, int count, ...); dsql_nod* makeClassNode(ExprNode* node); - dsql_nod* makeClassNode(DdlNode* node); - dsql_nod* makeClassNode(StmtNode* node); dsql_nod* make_flag_node(Dsql::nod_t type, SSHORT flag, int count, ...); // end - defined in parse.y @@ -285,7 +283,7 @@ Firebird::string transformedString; Firebird::GenericMap<Firebird::NonPooled<dsql_str*, StrMark> > strMarks; bool stmt_ambiguous; - dsql_nod* DSQL_parse; + Node* DSQL_parse; // These value/posn are taken from the lexer YYSTYPE yylval; Modified: firebird/trunk/src/dsql/StmtNodes.cpp =================================================================== --- firebird/trunk/src/dsql/StmtNodes.cpp 2012-02-19 10:36:54 UTC (rev 54024) +++ firebird/trunk/src/dsql/StmtNodes.cpp 2012-02-20 02:02:04 UTC (rev 54025) @@ -72,8 +72,8 @@ static StmtNode* dsqlNullifyReturning(DsqlCompilerScratch*, StmtNode* input, bool returnList); static void dsqlFieldAppearsOnce(const Array<dsql_nod*>&, const char*); static Array<dsql_nod*>* dsqlPassArray(DsqlCompilerScratch*, Array<dsql_nod*>*); -static dsql_ctx* dsqlPassCursorContext(DsqlCompilerScratch*, const dsql_nod*, const dsql_nod*); -static dsql_nod* dsqlPassCursorReference(DsqlCompilerScratch*, const dsql_nod*, dsql_nod*); +static dsql_ctx* dsqlPassCursorContext(DsqlCompilerScratch*, const MetaName&, const dsql_nod*); +static dsql_nod* dsqlPassCursorReference(DsqlCompilerScratch*, const MetaName&, dsql_nod*); static dsql_nod* dsqlPassHiddenVariable(DsqlCompilerScratch* dsqlScratch, dsql_nod* expr); static StmtNode* dsqlProcessReturning(DsqlCompilerScratch*, ReturningClause*, StmtNode*); static void dsqlSetParameterName(dsql_nod*, const dsql_nod*, const dsql_rel*); @@ -228,16 +228,6 @@ namespace Jrd { -StmtNode* StmtNode::fromLegacy(const dsql_nod* node) -{ - return node && node->nod_type == Dsql::nod_class_stmtnode ? - reinterpret_cast<StmtNode*>(node->nod_arg[0]) : NULL; -} - - -//-------------------- - - StmtNode* SavepointEncloseNode::make(MemoryPool& pool, DsqlCompilerScratch* dsqlScratch, StmtNode* node) { if (dsqlScratch->errorHandlers) @@ -1430,9 +1420,7 @@ void DeclareSubFuncNode::genBlr(DsqlCompilerScratch* dsqlScratch) { - dsql_nod* nod = MAKE_node(Dsql::nod_class_stmtnode, 1); - nod->nod_arg[0] = reinterpret_cast<dsql_nod*>(dsqlBlock); - GEN_request(blockScratch, nod); + GEN_request(blockScratch, dsqlBlock); dsqlScratch->appendUChar(blr_subfunc_decl); dsqlScratch->appendNullString(name.c_str()); @@ -1699,9 +1687,7 @@ void DeclareSubProcNode::genBlr(DsqlCompilerScratch* dsqlScratch) { - dsql_nod* nod = MAKE_node(Dsql::nod_class_stmtnode, 1); - nod->nod_arg[0] = reinterpret_cast<dsql_nod*>(dsqlBlock); - GEN_request(blockScratch, nod); + GEN_request(blockScratch, dsqlBlock); dsqlScratch->appendUChar(blr_subproc_decl); dsqlScratch->appendNullString(name.c_str()); @@ -1892,14 +1878,13 @@ { thread_db* tdbb = JRD_get_thread_data(); //necessary? - const dsql_nod* cursor = dsqlCursor; dsql_nod* relation = dsqlRelation; EraseNode* node = FB_NEW(getPool()) EraseNode(getPool()); - if (cursor && dsqlScratch->isPsql()) + if (dsqlCursorName.hasData() && dsqlScratch->isPsql()) { - node->dsqlContext = dsqlPassCursorContext(dsqlScratch, cursor, relation); + node->dsqlContext = dsqlPassCursorContext(dsqlScratch, dsqlCursorName, relation); // Process old context values. dsqlScratch->context->push(node->dsqlContext); @@ -1913,14 +1898,14 @@ return SavepointEncloseNode::make(getPool(), dsqlScratch, node); } - dsqlScratch->getStatement()->setType( - cursor ? DsqlCompiledStatement::TYPE_DELETE_CURSOR : DsqlCompiledStatement::TYPE_DELETE); + dsqlScratch->getStatement()->setType(dsqlCursorName.hasData() ? + DsqlCompiledStatement::TYPE_DELETE_CURSOR : DsqlCompiledStatement::TYPE_DELETE); // Generate record selection expression. dsql_nod* rseNod; - if (cursor) - rseNod = dsqlPassCursorReference(dsqlScratch, cursor, relation); + if (dsqlCursorName.hasData()) + rseNod = dsqlPassCursorReference(dsqlScratch, dsqlCursorName, relation); else { RseNode* rse = FB_NEW(getPool()) RseNode(getPool()); @@ -4298,12 +4283,11 @@ if (dsqlCursor) { - DeclareCursorNode* cursor = StmtNode::as<DeclareCursorNode>(dsqlCursor); - fb_assert(cursor->dsqlCursorType != DeclareCursorNode::CUR_TYPE_NONE); - PASS1_cursor_name(dsqlScratch, cursor->dsqlName, DeclareCursorNode::CUR_TYPE_ALL, false); - cursor->dsqlSelect = node->dsqlSelect; - cursor->cursorNumber = dsqlScratch->cursorNumber++; - dsqlScratch->cursors.push(cursor); + fb_assert(dsqlCursor->dsqlCursorType != DeclareCursorNode::CUR_TYPE_NONE); + PASS1_cursor_name(dsqlScratch, dsqlCursor->dsqlName, DeclareCursorNode::CUR_TYPE_ALL, false); + dsqlCursor->dsqlSelect = node->dsqlSelect; + dsqlCursor->cursorNumber = dsqlScratch->cursorNumber++; + dsqlScratch->cursors.push(dsqlCursor); } node->dsqlInto = dsqlPassArray(dsqlScratch, dsqlInto); @@ -4331,7 +4315,6 @@ void ForNode::print(string& text, Array<dsql_nod*>& nodes) const { text = "ForNode"; - nodes.add(dsqlCursor); nodes.add(dsqlLabel); } @@ -5361,15 +5344,14 @@ new_values.add(assign->dsqlAsgnTo); } - dsql_nod* cursor = dsqlCursor; dsql_nod* relation = dsqlRelation; dsql_nod** ptr; ModifyNode* node = FB_NEW(pool) ModifyNode(pool); - if (cursor && dsqlScratch->isPsql()) + if (dsqlCursorName.hasData() && dsqlScratch->isPsql()) { - node->dsqlContext = dsqlPassCursorContext(dsqlScratch, cursor, relation); + node->dsqlContext = dsqlPassCursorContext(dsqlScratch, dsqlCursorName, relation); if (isUpdateSqlCompliant) { @@ -5433,8 +5415,8 @@ return node; } - dsqlScratch->getStatement()->setType( - cursor ? DsqlCompiledStatement::TYPE_UPDATE_CURSOR : DsqlCompiledStatement::TYPE_UPDATE); + dsqlScratch->getStatement()->setType(dsqlCursorName.hasData() ? + DsqlCompiledStatement::TYPE_UPDATE_CURSOR : DsqlCompiledStatement::TYPE_UPDATE); node->dsqlRelation = PASS1_node_psql(dsqlScratch, relation, false); dsql_ctx* mod_context = dsqlGetContext(node->dsqlRelation); @@ -5457,9 +5439,9 @@ dsql_nod* rseNod; dsql_ctx* old_context; - if (cursor) + if (dsqlCursorName.hasData()) { - rseNod = dsqlPassCursorReference(dsqlScratch, cursor, relation); + rseNod = dsqlPassCursorReference(dsqlScratch, dsqlCursorName, relation); dsql_nod* temp = ExprNode::as<RseNode>(rseNod)->dsqlStreams->nod_arg[0]; old_context = ExprNode::as<RelationSourceNode>(temp)->dsqlContext; @@ -8198,18 +8180,16 @@ } // Turn a cursor reference into a record selection expression. -static dsql_ctx* dsqlPassCursorContext( DsqlCompilerScratch* dsqlScratch, const dsql_nod* cursor, +static dsql_ctx* dsqlPassCursorContext(DsqlCompilerScratch* dsqlScratch, const MetaName& cursor, const dsql_nod* relation_name) { DEV_BLKCHK(dsqlScratch, dsql_type_req); - DEV_BLKCHK(cursor, dsql_type_nod); DEV_BLKCHK(relation_name, dsql_type_nod); const MetaName& relName = ExprNode::as<RelationSourceNode>(relation_name)->dsqlName; - const MetaName& cursorName = StmtNode::as<DeclareCursorNode>(cursor)->dsqlName; // this function must throw an error if no cursor was found - const DeclareCursorNode* node = PASS1_cursor_name(dsqlScratch, cursorName, + const DeclareCursorNode* node = PASS1_cursor_name(dsqlScratch, cursor, DeclareCursorNode::CUR_TYPE_ALL, true); fb_assert(node); @@ -8220,7 +8200,7 @@ { // cursor with DISTINCT is not updatable ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-510) << - Arg::Gds(isc_dsql_cursor_update_err) << cursorName); + Arg::Gds(isc_dsql_cursor_update_err) << cursor); } const dsql_nod* temp = rse->dsqlStreams; @@ -8249,7 +8229,7 @@ ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-504) << Arg::Gds(isc_dsql_cursor_err) << Arg::Gds(isc_dsql_cursor_rel_ambiguous) << Arg::Str(relName) << - cursorName); + cursor); } else context = candidate; @@ -8259,7 +8239,7 @@ { // cursor with aggregation is not updatable ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-510) << - Arg::Gds(isc_dsql_cursor_update_err) << cursorName); + Arg::Gds(isc_dsql_cursor_update_err) << cursor); } // note that UnionSourceNode and joins will cause the error below, // as well as derived tables. Some cases deserve fixing in the future @@ -8270,18 +8250,17 @@ { ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-504) << Arg::Gds(isc_dsql_cursor_err) << - Arg::Gds(isc_dsql_cursor_rel_not_found) << Arg::Str(relName) << cursorName); + Arg::Gds(isc_dsql_cursor_rel_not_found) << Arg::Str(relName) << cursor); } return context; } // Turn a cursor reference into a record selection expression. -static dsql_nod* dsqlPassCursorReference( DsqlCompilerScratch* dsqlScratch, const dsql_nod* cursor, +static dsql_nod* dsqlPassCursorReference(DsqlCompilerScratch* dsqlScratch, const MetaName& cursor, dsql_nod* relation_name) { DEV_BLKCHK(dsqlScratch, dsql_type_req); - DEV_BLKCHK(cursor, dsql_type_nod); DEV_BLKCHK(relation_name, dsql_type_nod); thread_db* tdbb = JRD_get_thread_data(); @@ -8289,16 +8268,14 @@ // Lookup parent dsqlScratch - const MetaName& cursorName = StmtNode::as<DeclareCursorNode>(cursor)->dsqlName; + dsql_req* const* symbol = dsqlScratch->getAttachment()->dbb_cursors.get(cursor.c_str()); - dsql_req* const* symbol = dsqlScratch->getAttachment()->dbb_cursors.get(cursorName.c_str()); - if (!symbol) { // cursor is not found ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-504) << Arg::Gds(isc_dsql_cursor_err) << - Arg::Gds(isc_dsql_cursor_not_found) << cursorName); + Arg::Gds(isc_dsql_cursor_not_found) << cursor); } dsql_req* parent = *symbol; @@ -8313,7 +8290,7 @@ { // cursor is not updatable ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-510) << - Arg::Gds(isc_dsql_cursor_update_err) << cursorName); + Arg::Gds(isc_dsql_cursor_update_err) << cursor); } dsqlScratch->getStatement()->setParentRequest(parent); Modified: firebird/trunk/src/dsql/StmtNodes.h =================================================================== --- firebird/trunk/src/dsql/StmtNodes.h 2012-02-19 10:36:54 UTC (rev 54024) +++ firebird/trunk/src/dsql/StmtNodes.h 2012-02-20 02:02:04 UTC (rev 54025) @@ -493,7 +493,7 @@ dsqlPlan(NULL), dsqlSort(NULL), dsqlRows(NULL), - dsqlCursor(NULL), + dsqlCursorName(pool), dsqlReturning(NULL), dsqlRse(NULL), dsqlContext(NULL), @@ -523,7 +523,7 @@ dsql_nod* dsqlPlan; dsql_nod* dsqlSort; dsql_nod* dsqlRows; - dsql_nod* dsqlCursor; + Firebird::MetaName dsqlCursorName; ReturningClause* dsqlReturning; dsql_nod* dsqlRse; dsql_ctx* dsqlContext; @@ -879,7 +879,7 @@ public: SelectNode* dsqlSelect; Firebird::Array<dsql_nod*>* dsqlInto; - dsql_nod* dsqlCursor; + DeclareCursorNode* dsqlCursor; dsql_nod* dsqlLabel; bool dsqlForceSingular; NestConst<StmtNode> stall; @@ -1081,7 +1081,7 @@ dsqlPlan(NULL), dsqlSort(NULL), dsqlRows(NULL), - dsqlCursor(NULL), + dsqlCursorName(pool), dsqlReturning(NULL), dsqlRseFlags(0), dsqlRse(NULL), @@ -1117,7 +1117,7 @@ dsql_nod* dsqlPlan; dsql_nod* dsqlSort; dsql_nod* dsqlRows; - dsql_nod* dsqlCursor; + Firebird::MetaName dsqlCursorName; ReturningClause* dsqlReturning; USHORT dsqlRseFlags; dsql_nod* dsqlRse; Modified: firebird/trunk/src/dsql/ddl.cpp =================================================================== --- firebird/trunk/src/dsql/ddl.cpp 2012-02-19 10:36:54 UTC (rev 54024) +++ firebird/trunk/src/dsql/ddl.cpp 2012-02-20 02:02:04 UTC (rev 54025) @@ -120,84 +120,10 @@ ///const int DEFAULT_BLOB_SEGMENT_SIZE = 80; // bytes -void DDL_execute(dsql_req* request) -{ -/************************************** - * - * D D L _ e x e c u t e - * - ************************************** - * - * Functional description - * Call access method layered service DYN - * to interpret dyn string and perform - * metadata updates. - * - **************************************/ - thread_db* tdbb = JRD_get_thread_data(); - - const DsqlCompiledStatement* statement = request->getStatement(); - -#ifdef DSQL_DEBUG - if (DSQL_debug & 4) - { - dsql_trace("Output DYN string for DDL:"); - PRETTY_print_dyn(statement->getDdlData().begin(), gds__trace_printer, NULL, 0); - } -#endif - - const NOD_TYPE type = statement->getDdlNode()->nod_type; - - fb_assert(type == nod_class_stmtnode); - - fb_utils::init_status(tdbb->tdbb_status_vector); - - // run all statements under savepoint control - { // scope - AutoSavePoint savePoint(tdbb, request->req_transaction); - - DdlNode* ddlNode = reinterpret_cast<DdlNode*>(statement->getDdlNode()->nod_arg[0]); - ddlNode->executeDdl(tdbb, statement->getDdlScratch(), request->req_transaction); - - savePoint.release(); // everything is ok - } - - JRD_autocommit_ddl(tdbb, request->req_transaction); -} - - -void DDL_generate(DsqlCompilerScratch* dsqlScratch, dsql_nod* node) -{ -/************************************** - * - * D D L _ g e n e r a t e - * - ************************************** - * - * Functional description - * Generate the DYN string for a - * metadata update. Done during the - * prepare phase. - * - **************************************/ - - if (dsqlScratch->getAttachment()->dbb_read_only) - { - ERRD_post(Arg::Gds(isc_read_only_database)); - return; - } - - dsqlScratch->getStatement()->setDdlNode(node); -} - - -// -// Determine whether ids or names should be referenced -// when generating blr for fields and relations. -// +// Determine whether ids or names should be referenced when generating blr for fields and relations. bool DDL_ids(const DsqlCompilerScratch* scratch) { - return !scratch->getStatement()->getDdlNode(); + return !scratch->getStatement()->isDdl(); } @@ -405,7 +331,7 @@ const dsql_str* dfl_charset = NULL; - if (dsqlScratch->getStatement()->getDdlNode() || + if (dsqlScratch->getStatement()->isDdl() || (dsqlScratch->flags & ( DsqlCompilerScratch::FLAG_FUNCTION | DsqlCompilerScratch::FLAG_PROCEDURE | DsqlCompilerScratch::FLAG_TRIGGER))) Modified: firebird/trunk/src/dsql/ddl_proto.h =================================================================== --- firebird/trunk/src/dsql/ddl_proto.h 2012-02-19 10:36:54 UTC (rev 54024) +++ firebird/trunk/src/dsql/ddl_proto.h 2012-02-20 02:02:04 UTC (rev 54025) @@ -31,11 +31,8 @@ // the DSQL module itself. namespace Jrd { - class dsql_req; class DsqlCompilerScratch; class dsql_fld; - class dsql_nod; - class dsql_str; }; const USHORT blr_dtypes[] = { @@ -63,8 +60,6 @@ blr_bool // dtype_boolean }; -void DDL_execute(Jrd::dsql_req*); -void DDL_generate(Jrd::DsqlCompilerScratch*, Jrd::dsql_nod*); bool DDL_ids(const Jrd::DsqlCompilerScratch*); void DDL_reset_context_stack(Jrd::DsqlCompilerScratch*); void DDL_resolve_intl_type(Jrd::DsqlCompilerScratch*, Jrd::dsql_fld*, const Firebird::MetaName&); Modified: firebird/trunk/src/dsql/dsql.cpp =================================================================== --- firebird/trunk/src/dsql/dsql.cpp 2012-02-19 10:36:54 UTC (rev 54024) +++ firebird/trunk/src/dsql/dsql.cpp 2012-02-20 02:02:04 UTC (rev 54025) @@ -138,8 +138,9 @@ class DsqlDdlRequest : public dsql_req { public: - explicit DsqlDdlRequest(DsqlCompilerScratch* scratch) - : dsql_req(scratch) + explicit DsqlDdlRequest(DsqlCompilerScratch* scratch, DdlNode* aNode) + : dsql_req(scratch), + node(aNode) { } @@ -147,6 +148,9 @@ ULONG inBlrLength, const UCHAR* inBlr, ULONG inMsgLength, const UCHAR* inMsg, ULONG outBlrLength, const UCHAR* const outBlr, ULONG outMsgLength, UCHAR* outMsg, bool singleton); + + private: + DdlNode* node; }; class DsqlTransactionRequest : public dsql_req @@ -897,7 +901,20 @@ bool singleton) { TraceDSQLExecute trace(req_dbb->dbb_attachment, this); - DDL_execute(this); + + const DsqlCompiledStatement* statement = getStatement(); + + fb_utils::init_status(tdbb->tdbb_status_vector); + + // run all statements under savepoint control + { // scope + AutoSavePoint savePoint(tdbb, req_transaction); + node->executeDdl(tdbb, statement->getDdlScratch(), req_transaction); + savePoint.release(); // everything is ok + } + + JRD_autocommit_ddl(tdbb, req_transaction); + trace.finish(false, res_successful); } @@ -1528,7 +1545,7 @@ scratch->getAttachment()->dbb_db_SQL_dialect, parserVersion, text, textLength, tdbb->getAttachment()->att_charset); - dsql_nod* node = parser.parse(); + Node* node = parser.parse(); if (!node) { @@ -1585,7 +1602,7 @@ statement->setType(DsqlCompiledStatement::TYPE_SELECT); - node = PASS1_statement(scratch, node); + node = Node::doDsqlPass(scratch, node); fb_assert(node); const DsqlCompiledStatement::Type statementType = statement->getType(); @@ -1604,7 +1621,12 @@ case DsqlCompiledStatement::TYPE_CREATE_DB: case DsqlCompiledStatement::TYPE_DDL: - request = FB_NEW(statement->getPool()) DsqlDdlRequest(scratch); + if (scratch->getAttachment()->dbb_read_only) + ERRD_post(Arg::Gds(isc_read_only_database)); + + request = FB_NEW(statement->getPool()) DsqlDdlRequest(scratch, + static_cast<DdlNode*>(node)); + break; default: @@ -1633,7 +1655,8 @@ else statement->addFlags(DsqlCompiledStatement::FLAG_BLR_VERSION4); - GEN_request(scratch, node); + if (!statement->isDdl()) + GEN_request(scratch, static_cast<DmlNode*>(node)); // Create the messages buffers for (size_t i = 0; i < scratch->ports.getCount(); ++i) Modified: firebird/trunk/src/dsql/dsql.h =================================================================== --- firebird/trunk/src/dsql/dsql.h 2012-02-19 10:36:54 UTC (rev 54024) +++ firebird/trunk/src/dsql/dsql.h 2012-02-20 02:02:04 UTC (rev 54025) @@ -428,7 +428,6 @@ type(TYPE_SELECT), flags(0), ddlData(p), - ddlNode(NULL), sendMsg(NULL), receiveMsg(NULL), eof(NULL), @@ -459,9 +458,10 @@ const Firebird::HalfStaticArray<UCHAR, 1024>& getDdlData() const { return ddlData; } void setDdlData(Firebird::HalfStaticArray<UCHAR, 1024>& value) { ddlData = value; } - dsql_nod* getDdlNode() { return ddlNode; } - const dsql_nod* getDdlNode() const { return ddlNode; } - void setDdlNode(dsql_nod* value) { ddlNode = value; } + bool isDdl() const + { + return type == TYPE_DDL || type == TYPE_CREATE_DB; + } dsql_msg* getSendMsg() { return sendMsg; } const dsql_msg* getSendMsg() const { return sendMsg; } @@ -502,7 +502,6 @@ ULONG flags; // generic flag Firebird::RefStrPtr sqlText; Firebird::HalfStaticArray<UCHAR, 1024> ddlData; - dsql_nod* ddlNode; // Store metadata statement dsql_msg* sendMsg; // Message to be sent to start request dsql_msg* receiveMsg; // Per record message to be received dsql_par* eof; // End of file parameter Modified: firebird/trunk/src/dsql/gen.cpp =================================================================== --- firebird/trunk/src/dsql/gen.cpp 2012-02-19 10:36:54 UTC (rev 54024) +++ firebird/trunk/src/dsql/gen.cpp 2012-02-20 02:02:04 UTC (rev 54025) @@ -271,28 +271,11 @@ } -/** - - GEN_request - - @brief Generate complete blr for a dsqlScratch. - - - @param dsqlScratch - @param node - - **/ -void GEN_request(DsqlCompilerScratch* scratch, dsql_nod* node) +// Generate complete blr for a dsqlScratch. +void GEN_request(DsqlCompilerScratch* scratch, DmlNode* node) { DsqlCompiledStatement* statement = scratch->getStatement(); - if (statement->getType() == DsqlCompiledStatement::TYPE_CREATE_DB || - statement->getType() == DsqlCompiledStatement::TYPE_DDL) - { - DDL_generate(scratch, node); - return; - } - if (statement->getFlags() & DsqlCompiledStatement::FLAG_BLR_VERSION4) scratch->appendUChar(blr_version4); else @@ -304,7 +287,7 @@ // to avoid breaking of savepoint logic statement->setSendMsg(NULL); statement->setReceiveMsg(NULL); - GEN_statement(scratch, node); + node->genBlr(scratch); } else { @@ -324,7 +307,7 @@ case DsqlCompiledStatement::TYPE_SELECT_UPD: case DsqlCompiledStatement::TYPE_EXEC_BLOCK: case DsqlCompiledStatement::TYPE_SELECT_BLOCK: - GEN_statement(scratch, node); + node->genBlr(scratch); break; default: { @@ -342,7 +325,7 @@ statement->setReceiveMsg(NULL); else GEN_port(scratch, message); - GEN_statement(scratch, node); + node->genBlr(scratch); } } @@ -356,47 +339,6 @@ /** - GEN_statement - - @brief Generate blr for an arbitrary expression. - - - @param dsqlScratch - @param node - - **/ -void GEN_statement( DsqlCompilerScratch* dsqlScratch, dsql_nod* node) -{ - dsql_nod** ptr; - const dsql_nod* const* end; - - switch (node->nod_type) - { - case nod_class_stmtnode: - { - DmlNode* dmlNode = reinterpret_cast<DmlNode*>(node->nod_arg[0]); - dmlNode->genBlr(dsqlScratch); - } - return; - - case nod_list: - dsqlScratch->appendUChar(blr_begin); - for (ptr = node->nod_arg, end = ptr + node->nod_count; ptr < end; ptr++) - GEN_statement(dsqlScratch, *ptr); - dsqlScratch->appendUChar(blr_end); - return; - - default: - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-901) << - Arg::Gds(isc_dsql_internal_err) << - // gen.c: node not supported - Arg::Gds(isc_node_err)); - } -} - - -/** - GEN_descriptor @brief Generate a blr descriptor from an internal descriptor. Modified: firebird/trunk/src/dsql/gen_proto.h =================================================================== --- firebird/trunk/src/dsql/gen_proto.h 2012-02-19 10:36:54 UTC (rev 54024) +++ firebird/trunk/src/dsql/gen_proto.h 2012-02-20 02:02:04 UTC (rev 54025) @@ -29,11 +29,10 @@ void GEN_hidden_variables(Jrd::DsqlCompilerScratch* dsqlScratch); void GEN_parameter(Jrd::DsqlCompilerScratch*, const Jrd::dsql_par*); void GEN_port(Jrd::DsqlCompilerScratch*, Jrd::dsql_msg*); -void GEN_request(Jrd::DsqlCompilerScratch*, Jrd::dsql_nod*); +void GEN_request(Jrd::DsqlCompilerScratch*, Jrd::DmlNode*); void GEN_rse(Jrd::DsqlCompilerScratch*, const Jrd::dsql_nod*); void GEN_return(Jrd::DsqlCompilerScratch*, const Firebird::Array<Jrd::dsql_nod*>& variables, bool, bool); void GEN_sort(Jrd::DsqlCompilerScratch*, Jrd::dsql_nod*); -void GEN_statement(Jrd::DsqlCompilerScratch*, Jrd::dsql_nod*); void GEN_stuff_context(Jrd::DsqlCompilerScratch*, const Jrd::dsql_ctx*); #endif // DSQL_GEN_PROTO_H Modified: firebird/trunk/src/dsql/node.h =================================================================== --- firebird/trunk/src/dsql/node.h 2012-02-19 10:36:54 UTC (rev 54024) +++ firebird/trunk/src/dsql/node.h 2012-02-20 02:02:04 UTC (rev 54025) @@ -109,7 +109,6 @@ nod_label, // label support nod_rows, // ROWS support nod_with, - nod_class_stmtnode, nod_class_exprnode, nod_package_name, nod_package_obj, Modified: firebird/trunk/src/dsql/parse.y =================================================================== --- firebird/trunk/src/dsql/parse.y 2012-02-19 10:36:54 UTC (rev 54024) +++ firebird/trunk/src/dsql/parse.y 2012-02-20 02:02:04 UTC (rev 54025) @@ -632,6 +632,7 @@ Jrd::dsql_fld* legacyField; Firebird::Array<Jrd::dsql_nod*>* legacyArray; Jrd::ReturningClause* returningClause; + Firebird::MetaName* metaNamePtr; Firebird::PathName* pathNamePtr; Firebird::string* stringPtr; TEXT* textPtr; @@ -667,6 +668,7 @@ Jrd::ValueIfNode* valueIfNode; Jrd::CompoundStmtNode* compoundStmtNode; Jrd::CursorStmtNode* cursorStmtNode; + Jrd::DeclareCursorNode* declCursorNode; Jrd::ErrorHandlerNode* errorHandlerNode; Jrd::ExecStatementNode* execStatementNode; Jrd::MergeNode* mergeNode; @@ -719,8 +721,9 @@ %type <legacyNode> constraint_name_opt correlation_name %type <ddlNode> create create_clause create_user_clause %type <legacyNode> cross_join -%type <legacyNode> cursor_clause cursor_def %type <ddlNode> create_or_alter +%type <metaNamePtr> cursor_clause +%type <declCursorNode> cursor_def %type <stmtNode> cursor_declaration_item continue cursor_statement %type <legacyNode> data_type data_type_or_domain @@ -868,7 +871,7 @@ %type <ddlNode> set_statistics %type <legacyNode> simple_type simple_when_clause skip_clause %type <uintVal> snap_shot -%type <legacyNode> statement +%type <node> statement %type <legacyNode> string_length_opt %type <legacyNode> symbol_UDF_call_name symbol_UDF_name symbol_blob_subtype_name symbol_character_set_name %type <legacyNode> symbol_collation_name symbol_column_name symbol_constraint_name symbol_cursor_name @@ -890,7 +893,7 @@ %type <legacyNode> table_constraint table_constraint_definition %type <legacyNode> table_list table_lock table_name table_or_alias_list table_primary %type <legacyNode> table_proc table_proc_inputs table_reference table_subquery -%type <legacyNode> top +%type top %type tran_option(<setTransactionNode>) tran_option_list(<setTransactionNode>) %type tran_option_list_opt(<setTransactionNode>) %type <uintVal> time_precision_opt timestamp_precision_opt @@ -1002,31 +1005,31 @@ ; statement - : alter { $$ = makeClassNode($1); } + : alter { $$ = $1; } // ASF: ALTER SEQUENCE is defined here cause it's treated as DML. - | ALTER SEQUENCE alter_sequence_clause { $$ = makeClassNode($3); } - | comment { $$ = makeClassNode($1); } - | commit { $$ = makeClassNode($1); } - | create { $$ = makeClassNode($1); } - | create_or_alter { $$ = makeClassNode($1); } - | declare { $$ = makeClassNode($1); } - | delete { $$ = makeClassNode($1); } - | drop { $$ = makeClassNode($1); } - | grant { $$ = makeClassNode($1); } - | insert { $$ = makeClassNode($1); } - | merge { $$ = makeClassNode($1); } - | exec_procedure { $$ = makeClassNode($1); } - | exec_block { $$ = makeClassNode($1); } - | recreate { $$ = makeClassNode($1); } - | revoke { $$ = makeClassNode($1); } - | rollback { $$ = makeClassNode($1); } - | savepoint { $$ = makeClassNode($1); } - | select { $$ = makeClassNode($1); } - | set_transaction { $$ = makeClassNode($1); } - | set_generator { $$ = makeClassNode($1); } - | set_statistics { $$ = makeClassNode($1); } - | update { $$ = makeClassNode($1); } - | update_or_insert { $$ = makeClassNode($1); } + | ALTER SEQUENCE alter_sequence_clause { $$ = $3; } + | comment { $$ = $1; } + | commit { $$ = $1; } + | create { $$ = $1; } + | create_or_alter { $$ = $1; } + | declare { $$ = $1; } + | delete { $$ = $1; } + | drop { $$ = $1; } + | grant { $$ = $1; } + | insert { $$ = $1; } + | merge { $$ = $1; } + | exec_procedure { $$ = $1; } + | exec_block { $$ = $1; } + | recreate { $$ = $1; } + | revoke { $$ = $1; } + | rollback { $$ = $1; } + | savepoint { $$ = $1; } + | select { $$ = $1; } + | set_transaction { $$ = $1; } + | set_generator { $$ = $1; } + | set_statistics { $$ = $1; } + | update { $$ = $1; } + | update_or_insert { $$ = $1; } ; @@ -2857,11 +2860,7 @@ : // nothing { $$ = NULL; } | AS CURSOR symbol_cursor_name - { - DeclareCursorNode* node = newNode<DeclareCursorNode>(toName($3), - DeclareCursorNode::CUR_TYPE_FOR); - $$ = makeClassNode(node); - } + { $$ = newNode<DeclareCursorNode>(toName($3), DeclareCursorNode::CUR_TYPE_FOR); } ; excp_hndl_statements @@ -5001,7 +5000,7 @@ { EraseNode* node = newNode<EraseNode>(); node->dsqlRelation = $3; - node->dsqlCursor = $4; + node->dsqlCursorName = *$4; node->dsqlReturning = $5; $$ = node; } @@ -5037,7 +5036,7 @@ ModifyNode* node = newNode<ModifyNode>(); node->dsqlRelation = $2; node->statement = $4; - node->dsqlCursor = $5; + node->dsqlCursorName = *$5; node->dsqlReturning = $6; $$ = node; } @@ -5084,7 +5083,7 @@ cursor_clause : WHERE CURRENT OF symbol_cursor_name - { $$ = makeClassNode(newNode<DeclareCursorNode>(toName($4))); } + { $$ = newNode<MetaName>(toName($4)); } ; @@ -6833,17 +6832,7 @@ return make_node(nod_class_exprnode, 1, reinterpret_cast<dsql_nod*>(node)); } -dsql_nod* Parser::makeClassNode(DdlNode* node) -{ - return make_node(nod_class_stmtnode, 1, reinterpret_cast<dsql_nod*>(node)); -} -dsql_nod* Parser::makeClassNode(StmtNode* node) -{ - return make_node(nod_class_stmtnode, 1, reinterpret_cast<dsql_nod*>(node)); -} - - dsql_nod* Parser::make_flag_node(NOD_TYPE type, SSHORT flag, int count, ...) { /************************************** Modified: firebird/trunk/src/dsql/pass1.cpp =================================================================== --- firebird/trunk/src/dsql/pass1.cpp 2012-02-19 10:36:54 UTC (rev 54024) +++ firebird/trunk/src/dsql/pass1.cpp 2012-02-20 02:02:04 UTC (rev 54025) @@ -804,7 +804,6 @@ return node; default: - fb_assert(input->nod_type != nod_class_stmtnode); break; } @@ -842,93 +841,6 @@ } -/** - - PASS1_statement - - @brief Compile a parsed statement into something more interesting. - - - @param dsqlScratch - @param input - - **/ -dsql_nod* PASS1_statement(DsqlCompilerScratch* dsqlScratch, dsql_nod* input) -{ - if (!input) - return NULL; - - DEV_BLKCHK(dsqlScratch, dsql_type_req); - DEV_BLKCHK(input, dsql_type_nod); - -#ifdef DSQL_DEBUG - if (DSQL_debug & 2) - { - dsql_trace("Node tree at DSQL pass1 entry:"); - DSQL_pretty(input, 0); - } -#endif - - dsql_nod* node = NULL; - const DsqlContextStack::iterator base(*dsqlScratch->context); - - // Dispatch on node type. Fall thru on easy ones - - switch (input->nod_type) - { - case nod_def_index: - case nod_def_constraint: - case nod_def_domain: - dsqlScratch->getStatement()->setType(DsqlCompiledStatement::TYPE_DDL); - return input; - - case nod_class_stmtnode: - node = reinterpret_cast<dsql_nod*>( - reinterpret_cast<Node*>(input->nod_arg[0])->dsqlPass(dsqlScratch)); - if (node != input->nod_arg[0]) - { - input = MAKE_node(input->nod_type, input->nod_count); - input->nod_arg[0] = node; - } - return input; - - case nod_list: - { - node = MAKE_node(input->nod_type, input->nod_count); - const dsql_nod** ptr2 = const_cast<const dsql_nod**>(node->nod_arg); - dsql_nod* const* ptr = input->nod_arg; - for (const dsql_nod* const* const end = ptr + input->nod_count; ptr < end; ptr++) - { - DEV_BLKCHK(*ptr, dsql_type_nod); - *ptr2++ = PASS1_statement(dsqlScratch, *ptr); - DEV_BLKCHK(*(ptr2 - 1), dsql_type_nod); - } - return node; - } - - default: - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-901) << - Arg::Gds(isc_dsql_command_err) << - // Unsupported DSQL construct - Arg::Gds(isc_dsql_construct_err)); - break; - } - - // Finish off by cleaning up contexts - dsqlScratch->context->clear(base); - -#ifdef DSQL_DEBUG - if (DSQL_debug & 1) - { - dsql_trace("Node tree at DSQL pass1 exit:"); - DSQL_pretty(node, 0); - } -#endif - - return node; -} - - // Check for ambiguity in a field reference. The list with contexts where the field was found is // checked and the necessary message is build from it. void PASS1_ambiguity_check(DsqlCompilerScratch* dsqlScratch, @@ -4699,7 +4611,6 @@ break; case nod_class_exprnode: - case nod_class_stmtnode: reinterpret_cast<Node*>(node->nod_arg[0])->print(verb, subNodes); ptr = subNodes.begin(); end = subNodes.end(); Modified: firebird/trunk/src/dsql/pass1_proto.h =================================================================== --- firebird/trunk/src/dsql/pass1_proto.h 2012-02-19 10:36:54 UTC (rev 54024) +++ firebird/trunk/src/dsql/pass1_proto.h 2012-02-20 02:02:04 UTC (rev 54025) @@ -53,6 +53,5 @@ Jrd::dsql_nod* PASS1_rse(Jrd::DsqlCompilerScratch*, Jrd::dsql_nod*, bool); bool PASS1_set_parameter_type(Jrd::DsqlCompilerScratch*, Jrd::dsql_nod*, Jrd::dsql_nod*, bool); Jrd::dsql_nod* PASS1_sort(Jrd::DsqlCompilerScratch*, Jrd::dsql_nod*, Jrd::dsql_nod*); -Jrd::dsql_nod* PASS1_statement(Jrd::DsqlCompilerScratch*, Jrd::dsql_nod*); #endif // DSQL_PASS1_PROTO_H This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ro...@us...> - 2012-02-23 07:17:22
|
Revision: 54035 http://firebird.svn.sourceforge.net/firebird/?rev=54035&view=rev Author: robocop Date: 2012-02-23 07:17:12 +0000 (Thu, 23 Feb 2012) Log Message: ----------- Kill variable shadowing. Modified Paths: -------------- firebird/trunk/src/dsql/ExprNodes.cpp firebird/trunk/src/dsql/ExprNodes.h firebird/trunk/src/dsql/Nodes.h Modified: firebird/trunk/src/dsql/ExprNodes.cpp =================================================================== --- firebird/trunk/src/dsql/ExprNodes.cpp 2012-02-23 04:53:56 UTC (rev 54034) +++ firebird/trunk/src/dsql/ExprNodes.cpp 2012-02-23 07:17:12 UTC (rev 54035) @@ -3986,7 +3986,7 @@ for (UCHAR i = 0; i < streamCount; ++i) { const USHORT n = csb->csb_blr_reader.getByte(); - node->streamList.add(csb->csb_rpt[n].csb_stream); + node->internalStreamList.add(csb->csb_rpt[n].csb_stream); } node->arg = PAR_parse_value(tdbb, csb); @@ -4003,7 +4003,7 @@ SortedStreamList argStreams; arg->jrdStreamsCollector(argStreams); - for (USHORT* i = streamList.begin(); i != streamList.end(); ++i) + for (USHORT* i = internalStreamList.begin(); i != internalStreamList.end(); ++i) { const USHORT n = *i; @@ -4037,7 +4037,7 @@ { arg->findDependentFromStreams(optRet, streamList); - for (USHORT* i = this->streamList.begin(); i != this->streamList.end(); ++i) + for (USHORT* i = internalStreamList.begin(); i != internalStreamList.end(); ++i) { int derivedStream = *i; @@ -4059,7 +4059,7 @@ { DerivedExprNode* node = FB_NEW(*tdbb->getDefaultPool()) DerivedExprNode(*tdbb->getDefaultPool()); node->arg = copier.copy(tdbb, arg); - node->streamList = streamList; + node->internalStreamList = internalStreamList; if (copier.remap) { @@ -4069,7 +4069,7 @@ csb->dump("\t%d: %d -> %d\n", i, *i, copier.remap[*i]); #endif - for (USHORT* i = node->streamList.begin(); i != node->streamList.end(); ++i) + for (USHORT* i = node->internalStreamList.begin(); i != node->internalStreamList.end(); ++i) *i = copier.remap[*i]; } @@ -4087,13 +4087,13 @@ csb->dump("\n"); #endif - for (USHORT* i = streamList.begin(); i != streamList.end(); ++i) + for (USHORT* i = internalStreamList.begin(); i != internalStreamList.end(); ++i) { CMP_mark_variant(csb, *i); CMP_expand_view_nodes(tdbb, csb, *i, stack, blr_dbkey, true); } - streamList.clear(); + internalStreamList.clear(); #ifdef CMP_DEBUG for (ExprValueNodeStack::iterator i(stack); i.hasData(); ++i) @@ -4102,7 +4102,7 @@ #endif for (ValueExprNodeStack::iterator i(stack); i.hasData(); ++i) - streamList.add(i.object()->as<RecordKeyNode>()->recStream); + internalStreamList.add(i.object()->as<RecordKeyNode>()->recStream); return ValueExprNode::pass1(tdbb, csb); } @@ -4122,7 +4122,7 @@ { dsc* value = NULL; - for (const USHORT* i = streamList.begin(); i != streamList.end(); ++i) + for (const USHORT* i = internalStreamList.begin(); i != internalStreamList.end(); ++i) { if (request->req_rpb[*i].rpb_number.isValid()) { @@ -5217,7 +5217,7 @@ derivedNode->arg = sub; for (ValueExprNodeStack::iterator i(stack); i.hasData(); ++i) - derivedNode->streamList.add(i.object()->as<RecordKeyNode>()->recStream); + derivedNode->internalStreamList.add(i.object()->as<RecordKeyNode>()->recStream); sub = derivedNode; } Modified: firebird/trunk/src/dsql/ExprNodes.h =================================================================== --- firebird/trunk/src/dsql/ExprNodes.h 2012-02-23 04:53:56 UTC (rev 54034) +++ firebird/trunk/src/dsql/ExprNodes.h 2012-02-23 07:17:12 UTC (rev 54035) @@ -388,7 +388,7 @@ explicit DerivedExprNode(MemoryPool& pool) : TypedNode<ValueExprNode, ExprNode::TYPE_DERIVED_EXPR>(pool), arg(NULL), - streamList(pool) + internalStreamList(pool) { addChildNode(arg); } @@ -431,7 +431,7 @@ public: NestConst<ValueExprNode> arg; - Firebird::Array<USHORT> streamList; + Firebird::Array<StreamType> internalStreamList; }; Modified: firebird/trunk/src/dsql/Nodes.h =================================================================== --- firebird/trunk/src/dsql/Nodes.h 2012-02-23 04:53:56 UTC (rev 54034) +++ firebird/trunk/src/dsql/Nodes.h 2012-02-23 07:17:12 UTC (rev 54035) @@ -66,6 +66,8 @@ const int OPT_STATIC_ITEMS = 16; +typedef USHORT StreamType; // for now + typedef Firebird::HalfStaticArray<UCHAR, OPT_STATIC_ITEMS> StreamList; typedef Firebird::SortedArray<int> SortedStreamList; typedef UCHAR stream_array_t[MAX_STREAMS + 1]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2012-02-25 19:56:45
|
Revision: 54046 http://firebird.svn.sourceforge.net/firebird/?rev=54046&view=rev Author: asfernandes Date: 2012-02-25 19:56:37 +0000 (Sat, 25 Feb 2012) Log Message: ----------- 1) Make a new kind of Node (TransactionNode). 2) Make main parser statement return requests instead of nodes. 3) Some related cleanup (ddlData, ddlScratch). 4) Added dsqlPass to dsql_req and children, to get rid of ugly logic in prepareStatement. Modified Paths: -------------- firebird/trunk/src/dsql/DsqlCompilerScratch.h firebird/trunk/src/dsql/Nodes.h firebird/trunk/src/dsql/Parser.cpp firebird/trunk/src/dsql/Parser.h firebird/trunk/src/dsql/StmtNodes.cpp firebird/trunk/src/dsql/StmtNodes.h firebird/trunk/src/dsql/dsql.cpp firebird/trunk/src/dsql/dsql.h firebird/trunk/src/dsql/parse.y Modified: firebird/trunk/src/dsql/DsqlCompilerScratch.h =================================================================== --- firebird/trunk/src/dsql/DsqlCompilerScratch.h 2012-02-25 13:55:04 UTC (rev 54045) +++ firebird/trunk/src/dsql/DsqlCompilerScratch.h 2012-02-25 19:56:37 UTC (rev 54046) @@ -46,17 +46,19 @@ class DsqlCompilerScratch : public BlrWriter { public: - static const unsigned FLAG_IN_AUTO_TRANS_BLOCK = 0x001; - static const unsigned FLAG_RETURNING_INTO = 0x002; - static const unsigned FLAG_METADATA_SAVED = 0x004; - static const unsigned FLAG_PROCEDURE = 0x008; - static const unsigned FLAG_TRIGGER = 0x010; - static const unsigned FLAG_BLOCK = 0x020; - static const unsigned FLAG_RECURSIVE_CTE = 0x040; - static const unsigned FLAG_UPDATE_OR_INSERT = 0x080; - static const unsigned FLAG_MERGE = 0x100; - static const unsigned FLAG_FUNCTION = 0x200; - static const unsigned FLAG_SUB_ROUTINE = 0x400; + static const unsigned FLAG_IN_AUTO_TRANS_BLOCK = 0x0001; + static const unsigned FLAG_RETURNING_INTO = 0x0002; + static const unsigned FLAG_METADATA_SAVED = 0x0004; + static const unsigned FLAG_PROCEDURE = 0x0008; + static const unsigned FLAG_TRIGGER = 0x0010; + static const unsigned FLAG_BLOCK = 0x0020; + static const unsigned FLAG_RECURSIVE_CTE = 0x0040; + static const unsigned FLAG_UPDATE_OR_INSERT = 0x0080; + static const unsigned FLAG_MERGE = 0x0100; + static const unsigned FLAG_FUNCTION = 0x0200; + static const unsigned FLAG_SUB_ROUTINE = 0x0400; + static const unsigned FLAG_INTERNAL_REQUEST = 0x0800; + static const unsigned FLAG_AMBIGUOUS_STMT = 0x1000; public: DsqlCompilerScratch(MemoryPool& p, dsql_dbb* aDbb, jrd_tra* aTransaction, Modified: firebird/trunk/src/dsql/Nodes.h =================================================================== --- firebird/trunk/src/dsql/Nodes.h 2012-02-25 13:55:04 UTC (rev 54045) +++ firebird/trunk/src/dsql/Nodes.h 2012-02-25 19:56:37 UTC (rev 54046) @@ -225,6 +225,25 @@ }; +class TransactionNode : public Node +{ +public: + explicit TransactionNode(MemoryPool& pool) + : Node(pool) + { + } + +public: + virtual TransactionNode* dsqlPass(DsqlCompilerScratch* dsqlScratch) + { + Node::dsqlPass(dsqlScratch); + return this; + } + + virtual void execute(thread_db* tdbb, dsql_req* request, jrd_tra** transaction) const = 0; +}; + + class DmlNode : public Node { public: @@ -239,7 +258,7 @@ explicit DmlNode(MemoryPool& pool, Kind aKind) : Node(pool), - kind(aKind) + kind(aKind) { } @@ -851,7 +870,6 @@ { TYPE_ASSIGNMENT, TYPE_BLOCK, - TYPE_COMMIT_ROLLBACK, TYPE_COMPOUND_STMT, TYPE_CONTINUE_LEAVE, TYPE_CURSOR_STMT, @@ -885,7 +903,6 @@ TYPE_SAVEPOINT_ENCLOSE, TYPE_SELECT, TYPE_SET_GENERATOR, - TYPE_SET_TRANSACTION, TYPE_STALL, TYPE_STORE, TYPE_SUSPEND, Modified: firebird/trunk/src/dsql/Parser.cpp =================================================================== --- firebird/trunk/src/dsql/Parser.cpp 2012-02-25 13:55:04 UTC (rev 54045) +++ firebird/trunk/src/dsql/Parser.cpp 2012-02-25 19:56:37 UTC (rev 54046) @@ -91,10 +91,13 @@ } -Node* Parser::parse() +dsql_req* Parser::parse() { if (parseAux() != 0) + { + fb_assert(false); return NULL; + } transformString(lex.start, lex.end - lex.start, transformedString); Modified: firebird/trunk/src/dsql/Parser.h =================================================================== --- firebird/trunk/src/dsql/Parser.h 2012-02-25 13:55:04 UTC (rev 54045) +++ firebird/trunk/src/dsql/Parser.h 2012-02-25 19:56:37 UTC (rev 54046) @@ -128,7 +128,7 @@ ~Parser(); public: - Node* parse(); + dsql_req* parse(); const Firebird::string& getTransformedString() const { @@ -283,7 +283,7 @@ Firebird::string transformedString; Firebird::GenericMap<Firebird::NonPooled<dsql_str*, StrMark> > strMarks; bool stmt_ambiguous; - Node* DSQL_parse; + dsql_req* DSQL_parse; // These value/posn are taken from the lexer YYSTYPE yylval; Modified: firebird/trunk/src/dsql/StmtNodes.cpp =================================================================== --- firebird/trunk/src/dsql/StmtNodes.cpp 2012-02-25 13:55:04 UTC (rev 54045) +++ firebird/trunk/src/dsql/StmtNodes.cpp 2012-02-25 19:56:37 UTC (rev 54046) @@ -6776,42 +6776,8 @@ UserSavepointNode* UserSavepointNode::dsqlPass(DsqlCompilerScratch* dsqlScratch) { - DsqlCompiledStatement* statement = dsqlScratch->getStatement(); - - // ASF: It should never enter in this IF, because the grammar does not allow it. - if (dsqlScratch->flags & DsqlCompilerScratch::FLAG_BLOCK) // blocks, procedures and triggers - { - const char* cmd = NULL; - - switch (command) - { - //case CMD_NOTHING: - case CMD_SET: - cmd = "SAVEPOINT"; - break; - case CMD_RELEASE: - cmd = "RELEASE"; - break; - case CMD_RELEASE_ONLY: - cmd = "RELEASE ONLY"; - break; - case CMD_ROLLBACK: - cmd = "ROLLBACK"; - break; - default: - cmd = "UNKNOWN"; - fb_assert(false); - } - - ERRD_post( - Arg::Gds(isc_sqlerr) << Arg::Num(-104) << - // Token unknown - Arg::Gds(isc_token_err) << - Arg::Gds(isc_random) << Arg::Str(cmd)); - } - - statement->setType(DsqlCompiledStatement::TYPE_SAVEPOINT); - + fb_assert(!(dsqlScratch->flags & DsqlCompilerScratch::FLAG_BLOCK)); + dsqlScratch->getStatement()->setType(DsqlCompiledStatement::TYPE_SAVEPOINT); return this; } @@ -7616,14 +7582,18 @@ } if (dsqlScratch->getBlrData().getCount() > 1) // 1 -> isc_tpb_version1 - { - // Store DYN data in the statement. - dsqlScratch->getStatement()->setDdlData(dsqlScratch->getBlrData()); - } + tpb.add(dsqlScratch->getBlrData().begin(), dsqlScratch->getBlrData().getCount()); return this; } +void SetTransactionNode::execute(thread_db* tdbb, dsql_req* request, jrd_tra** transaction) const +{ + JRD_start_transaction(tdbb, &request->req_transaction, request->req_dbb->dbb_attachment, + tpb.getCount(), tpb.begin()); + *transaction = request->req_transaction; +} + // Generate tpb for table lock. // If lock level is specified, it overrrides the transaction lock level. void SetTransactionNode::genTableLock(DsqlCompilerScratch* dsqlScratch, const dsql_nod* tblLock, Modified: firebird/trunk/src/dsql/StmtNodes.h =================================================================== --- firebird/trunk/src/dsql/StmtNodes.h 2012-02-25 13:55:04 UTC (rev 54045) +++ firebird/trunk/src/dsql/StmtNodes.h 2012-02-25 19:56:37 UTC (rev 54046) @@ -159,7 +159,7 @@ }; -class CommitRollbackNode : public TypedNode<DsqlOnlyStmtNode, StmtNode::TYPE_COMMIT_ROLLBACK> +class CommitRollbackNode : public TransactionNode { public: enum Command @@ -170,7 +170,7 @@ public: explicit CommitRollbackNode(MemoryPool& pool, Command aCommand, bool aRetain) - : TypedNode<DsqlOnlyStmtNode, StmtNode::TYPE_COMMIT_ROLLBACK>(pool), + : TransactionNode(pool), command(aCommand), retain(aRetain) { @@ -200,8 +200,36 @@ return this; } - virtual void genBlr(DsqlCompilerScratch* dsqlScratch) + virtual void execute(thread_db* tdbb, dsql_req* request, jrd_tra** transaction) const { + if (retain) + { + switch (command) + { + case CMD_COMMIT: + JRD_commit_retaining(tdbb, request->req_transaction); + break; + + case CMD_ROLLBACK: + JRD_rollback_retaining(tdbb, request->req_transaction); + break; + } + } + else + { + switch (command) + { + case CMD_COMMIT: + JRD_commit_transaction(tdbb, request->req_transaction); + break; + + case CMD_ROLLBACK: + JRD_rollback_transaction(tdbb, request->req_transaction); + break; + } + + *transaction = NULL; + } } private: @@ -1432,7 +1460,7 @@ }; -class SetTransactionNode : public TypedNode<DsqlOnlyStmtNode, StmtNode::TYPE_SET_TRANSACTION> +class SetTransactionNode : public TransactionNode { public: enum @@ -1445,7 +1473,8 @@ public: explicit SetTransactionNode(MemoryPool& pool) - : TypedNode<DsqlOnlyStmtNode, StmtNode::TYPE_SET_TRANSACTION>(pool) + : TransactionNode(pool), + tpb(pool) { } @@ -1457,9 +1486,7 @@ virtual SetTransactionNode* dsqlPass(DsqlCompilerScratch* dsqlScratch); - virtual void genBlr(DsqlCompilerScratch* dsqlScratch) - { - } + virtual void execute(thread_db* tdbb, dsql_req* request, jrd_tra** transaction) const; private: void genTableLock(DsqlCompilerScratch* dsqlScratch, const dsql_nod* tblLock, USHORT lockLevel); @@ -1473,6 +1500,7 @@ Nullable<bool> restartRequests; Nullable<USHORT> lockTimeout; Nullable<dsql_nod*> reserveList; + Firebird::UCharBuffer tpb; }; Modified: firebird/trunk/src/dsql/dsql.cpp =================================================================== --- firebird/trunk/src/dsql/dsql.cpp 2012-02-25 13:55:04 UTC (rev 54045) +++ firebird/trunk/src/dsql/dsql.cpp 2012-02-25 19:56:37 UTC (rev 54046) @@ -115,57 +115,6 @@ isc_info_req_update_count, isc_info_req_delete_count, isc_info_req_select_count, isc_info_req_insert_count }; - - class DsqlDmlRequest : public dsql_req - { - public: - explicit DsqlDmlRequest(DsqlCompilerScratch* scratch) - : dsql_req(scratch) - { - } - - virtual void execute(thread_db* tdbb, jrd_tra** traHandle, - ULONG inBlrLength, const UCHAR* inBlr, ULONG inMsgLength, const UCHAR* inMsg, - ULONG outBlrLength, const UCHAR* const outBlr, ULONG outMsgLength, UCHAR* outMsg, - bool singleton); - - virtual void setCursor(thread_db* tdbb, const TEXT* name); - - virtual ISC_STATUS fetch(thread_db* tdbb, ULONG blrLength, const UCHAR* blr, - ULONG msgLength, UCHAR* msgBuffer); - }; - - class DsqlDdlRequest : public dsql_req - { - public: - explicit DsqlDdlRequest(DsqlCompilerScratch* scratch, DdlNode* aNode) - : dsql_req(scratch), - node(aNode) - { - } - - virtual void execute(thread_db* tdbb, jrd_tra** traHandle, - ULONG inBlrLength, const UCHAR* inBlr, ULONG inMsgLength, const UCHAR* inMsg, - ULONG outBlrLength, const UCHAR* const outBlr, ULONG outMsgLength, UCHAR* outMsg, - bool singleton); - - private: - DdlNode* node; - }; - - class DsqlTransactionRequest : public dsql_req - { - public: - explicit DsqlTransactionRequest(DsqlCompilerScratch* scratch) - : dsql_req(scratch) - { - } - - virtual void execute(thread_db* tdbb, jrd_tra** traHandle, - ULONG inBlrLength, const UCHAR* inBlr, ULONG inMsgLength, const UCHAR* inMsg, - ULONG outBlrLength, const UCHAR* const outBlr, ULONG outMsgLength, UCHAR* outMsg, - bool singleton); - }; } // namespace @@ -204,8 +153,10 @@ DsqlCompilerScratch* scratch = FB_NEW(pool) DsqlCompilerScratch(pool, database, NULL, statement); - dsql_req* const request = FB_NEW(pool) DsqlDmlRequest(scratch); + dsql_req* const request = FB_NEW(pool) DsqlDmlRequest(pool, NULL); request->req_dbb = database; + request->req_transaction = scratch->getTransaction(); + request->statement = scratch->getStatement(); return request; } @@ -754,14 +705,108 @@ } +void DsqlDmlRequest::dsqlPass(thread_db* tdbb, DsqlCompilerScratch* scratch, + ntrace_result_t* traceResult) +{ + node = Node::doDsqlPass(scratch, node); + + if (scratch->clientDialect > SQL_DIALECT_V5) + scratch->getStatement()->addFlags(DsqlCompiledStatement::FLAG_BLR_VERSION5); + else + scratch->getStatement()->addFlags(DsqlCompiledStatement::FLAG_BLR_VERSION4); + + GEN_request(scratch, node); + + // Create the messages buffers + for (size_t i = 0; i < scratch->ports.getCount(); ++i) + { + dsql_msg* message = scratch->ports[i]; + + // Allocate buffer for message + const ULONG newLen = message->msg_length + FB_DOUBLE_ALIGN - 1; + + message->msg_buffer_number = req_msg_buffers.getCount(); + req_msg_buffers.grow(message->msg_buffer_number + 1); + + UCHAR*& msgBuffer = req_msg_buffers[message->msg_buffer_number]; + fb_assert(!msgBuffer); + + msgBuffer = FB_NEW(*tdbb->getDefaultPool()) UCHAR[newLen]; + msgBuffer = (UCHAR*) FB_ALIGN((U_IPTR) msgBuffer, FB_DOUBLE_ALIGN); + } + + // have the access method compile the statement + +#ifdef DSQL_DEBUG + if (DSQL_debug & 64) + { + dsql_trace("Resulting BLR code for DSQL:"); + gds__trace_raw("Statement:\n"); + gds__trace_raw(statement->getSqlText()->c_str(), statement->getSqlText()->length()); + gds__trace_raw("\nBLR:\n"); + fb_print_blr(scratch->getBlrData().begin(), + (ULONG) scratch->getBlrData().getCount(), + gds__trace_printer, 0, 0); + } +#endif + + ISC_STATUS_ARRAY localStatus; + MOVE_CLEAR(localStatus, sizeof(localStatus)); + + // check for warnings + if (tdbb->tdbb_status_vector[2] == isc_arg_warning) + { + // save a status vector + memcpy(localStatus, tdbb->tdbb_status_vector, sizeof(ISC_STATUS_ARRAY)); + } + + ISC_STATUS status = FB_SUCCESS; + + try + { + JRD_compile(tdbb, scratch->getAttachment()->dbb_attachment, &req_request, + scratch->getBlrData().getCount(), scratch->getBlrData().begin(), + statement->getSqlText(), + scratch->getDebugData().getCount(), scratch->getDebugData().begin(), + (scratch->flags & DsqlCompilerScratch::FLAG_INTERNAL_REQUEST)); + } + catch (const Exception&) + { + status = tdbb->tdbb_status_vector[1]; + *traceResult = (status == isc_no_priv ? res_unauthorized : res_failed); + } + + // restore warnings (if there are any) + if (localStatus[2] == isc_arg_warning) + { + size_t indx, len, warning; + + // find end of a status vector + PARSE_STATUS(tdbb->tdbb_status_vector, indx, warning); + if (indx) + --indx; + + // calculate length of saved warnings + PARSE_STATUS(localStatus, len, warning); + len -= 2; + + if ((len + indx - 1) < ISC_STATUS_LENGTH) + memcpy(&tdbb->tdbb_status_vector[indx], &localStatus[2], sizeof(ISC_STATUS) * len); + } + + // free blr memory + scratch->getBlrData().free(); + + if (status) + status_exception::raise(tdbb->tdbb_status_vector); +} + // Execute a dynamic SQL statement. void DsqlDmlRequest::execute(thread_db* tdbb, jrd_tra** traHandle, ULONG inBlrLength, const UCHAR* inBlr, ULONG inMsgLength, const UCHAR* inMsg, ULONG outBlrLength, const UCHAR* const outBlr, ULONG outMsgLength, UCHAR* outMsg, bool singleton) { - const DsqlCompiledStatement* statement = getStatement(); - // If there is no data required, just start the request const dsql_msg* message = statement->getSendMsg(); @@ -894,6 +939,30 @@ trace.finish(have_cursor, res_successful); } +void DsqlDdlRequest::dsqlPass(thread_db* tdbb, DsqlCompilerScratch* scratch, + ntrace_result_t* traceResult) +{ + this->scratch = scratch; + + node = Node::doDsqlPass(scratch, node); + + if (scratch->getAttachment()->dbb_read_only) + ERRD_post(Arg::Gds(isc_read_only_database)); + + if ((scratch->flags & DsqlCompilerScratch::FLAG_AMBIGUOUS_STMT) && + scratch->getAttachment()->dbb_db_SQL_dialect != scratch->clientDialect) + { + ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-817) << + Arg::Gds(isc_ddl_not_allowed_by_db_sql_dial) << + Arg::Num(scratch->getAttachment()->dbb_db_SQL_dialect)); + } + + if (scratch->clientDialect > SQL_DIALECT_V5) + scratch->getStatement()->addFlags(DsqlCompiledStatement::FLAG_BLR_VERSION5); + else + scratch->getStatement()->addFlags(DsqlCompiledStatement::FLAG_BLR_VERSION4); +} + // Execute a dynamic SQL statement. void DsqlDdlRequest::execute(thread_db* tdbb, jrd_tra** traHandle, ULONG inBlrLength, const UCHAR* inBlr, ULONG inMsgLength, const UCHAR* inMsg, @@ -902,14 +971,12 @@ { TraceDSQLExecute trace(req_dbb->dbb_attachment, this); - const DsqlCompiledStatement* statement = getStatement(); - fb_utils::init_status(tdbb->tdbb_status_vector); // run all statements under savepoint control { // scope AutoSavePoint savePoint(tdbb, req_transaction); - node->executeDdl(tdbb, statement->getDdlScratch(), req_transaction); + node->executeDdl(tdbb, scratch, req_transaction); savePoint.release(); // everything is ok } @@ -918,43 +985,20 @@ trace.finish(false, res_successful); } + +void DsqlTransactionRequest::dsqlPass(thread_db* tdbb, DsqlCompilerScratch* scratch, + ntrace_result_t* /*traceResult*/) +{ + node = Node::doDsqlPass(scratch, node); +} + // Execute a dynamic SQL statement. void DsqlTransactionRequest::execute(thread_db* tdbb, jrd_tra** traHandle, ULONG inBlrLength, const UCHAR* inBlr, ULONG inMsgLength, const UCHAR* inMsg, ULONG outBlrLength, const UCHAR* const outBlr, ULONG outMsgLength, UCHAR* outMsg, bool singleton) { - const DsqlCompiledStatement* statement = getStatement(); - - switch (statement->getType()) - { - case DsqlCompiledStatement::TYPE_START_TRANS: - JRD_start_transaction(tdbb, &req_transaction, req_dbb->dbb_attachment, - statement->getDdlData().getCount(), statement->getDdlData().begin()); - *traHandle = req_transaction; - break; - - case DsqlCompiledStatement::TYPE_COMMIT: - JRD_commit_transaction(tdbb, req_transaction); - *traHandle = NULL; - break; - - case DsqlCompiledStatement::TYPE_COMMIT_RETAIN: - JRD_commit_retaining(tdbb, req_transaction); - break; - - case DsqlCompiledStatement::TYPE_ROLLBACK: - JRD_rollback_transaction(tdbb, req_transaction); - *traHandle = NULL; - break; - - case DsqlCompiledStatement::TYPE_ROLLBACK_RETAIN: - JRD_rollback_retaining(tdbb, req_transaction); - break; - - default: - fb_assert(false); - } + node->execute(tdbb, this, traHandle); } @@ -1535,6 +1579,9 @@ transaction, statement); scratch->clientDialect = clientDialect; + if (isInternalRequest) + scratch->flags |= DsqlCompilerScratch::FLAG_INTERNAL_REQUEST; + dsql_req* request = NULL; try @@ -1545,17 +1592,10 @@ scratch->getAttachment()->dbb_db_SQL_dialect, parserVersion, text, textLength, tdbb->getAttachment()->att_charset); - Node* node = parser.parse(); + request = parser.parse(); - if (!node) - { - // CVC: Apparently, Parser::parse won't return if the command is incomplete, - // because yyerror() will call ERRD_post(). - // This may be a special case, but we don't know about positions here. - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << - // Unexpected end of command - Arg::Gds(isc_command_end_err)); - } + if (parser.isStmtAmbiguous()) + scratch->flags |= DsqlCompilerScratch::FLAG_AMBIGUOUS_STMT; string transformedText = parser.getTransformedString(); SSHORT charSetId = database->dbb_attachment->att_charset; @@ -1602,162 +1642,25 @@ statement->setType(DsqlCompiledStatement::TYPE_SELECT); - node = Node::doDsqlPass(scratch, node); - fb_assert(node); + if (request->req_traced) + trace.setStatement(request); - const DsqlCompiledStatement::Type statementType = statement->getType(); - - switch (statementType) + ntrace_result_t traceResult = res_successful; + try { - case DsqlCompiledStatement::TYPE_COMMIT: - case DsqlCompiledStatement::TYPE_COMMIT_RETAIN: - case DsqlCompiledStatement::TYPE_ROLLBACK: - case DsqlCompiledStatement::TYPE_ROLLBACK_RETAIN: - case DsqlCompiledStatement::TYPE_START_TRANS: - request = FB_NEW(statement->getPool()) DsqlTransactionRequest(scratch); - request->req_traced = false; - trace.setStatement(request); - return request; // Stop here for statements not requiring code generation. + request->req_dbb = scratch->getAttachment(); + request->req_transaction = scratch->getTransaction(); + request->statement = scratch->getStatement(); - case DsqlCompiledStatement::TYPE_CREATE_DB: - case DsqlCompiledStatement::TYPE_DDL: - if (scratch->getAttachment()->dbb_read_only) - ERRD_post(Arg::Gds(isc_read_only_database)); - - request = FB_NEW(statement->getPool()) DsqlDdlRequest(scratch, - static_cast<DdlNode*>(node)); - - break; - - default: - request = FB_NEW(statement->getPool()) DsqlDmlRequest(scratch); - break; + request->dsqlPass(tdbb, scratch, &traceResult); } - - request->req_traced = true; - trace.setStatement(request); - - if (statementType == DsqlCompiledStatement::TYPE_DDL) + catch (const Exception&) { - if (parser.isStmtAmbiguous() && - scratch->getAttachment()->dbb_db_SQL_dialect != clientDialect) - { - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-817) << - Arg::Gds(isc_ddl_not_allowed_by_db_sql_dial) << - Arg::Num(scratch->getAttachment()->dbb_db_SQL_dialect)); - } - - statement->setDdlScratch(scratch); + trace.prepare(traceResult); + throw; } + trace.prepare(traceResult); - if (clientDialect > SQL_DIALECT_V5) - statement->addFlags(DsqlCompiledStatement::FLAG_BLR_VERSION5); - else - statement->addFlags(DsqlCompiledStatement::FLAG_BLR_VERSION4); - - if (!statement->isDdl()) - GEN_request(scratch, static_cast<DmlNode*>(node)); - - // Create the messages buffers - for (size_t i = 0; i < scratch->ports.getCount(); ++i) - { - dsql_msg* message = scratch->ports[i]; - - // Allocate buffer for message - const ULONG newLen = message->msg_length + FB_DOUBLE_ALIGN - 1; - - message->msg_buffer_number = request->req_msg_buffers.getCount(); - request->req_msg_buffers.grow(message->msg_buffer_number + 1); - - UCHAR*& msgBuffer = request->req_msg_buffers[message->msg_buffer_number]; - fb_assert(!msgBuffer); - - msgBuffer = FB_NEW(*tdbb->getDefaultPool()) UCHAR[newLen]; - msgBuffer = (UCHAR*) FB_ALIGN((U_IPTR) msgBuffer, FB_DOUBLE_ALIGN); - } - - // stop here for ddl statements - - if (statementType == DsqlCompiledStatement::TYPE_CREATE_DB || - statementType == DsqlCompiledStatement::TYPE_DDL) - { - // Notify Trace API manager about new DDL request cooked. - trace.prepare(res_successful); - return request; - } - - // have the access method compile the statement - -#ifdef DSQL_DEBUG - if (DSQL_debug & 64) - { - dsql_trace("Resulting BLR code for DSQL:"); - gds__trace_raw("Statement:\n"); - gds__trace_raw(text, textLength); - gds__trace_raw("\nBLR:\n"); - fb_print_blr(scratch->getBlrData().begin(), - (ULONG) scratch->getBlrData().getCount(), - gds__trace_printer, 0, 0); - } -#endif - - ISC_STATUS_ARRAY localStatus; - MOVE_CLEAR(localStatus, sizeof(localStatus)); - - // check for warnings - if (tdbb->tdbb_status_vector[2] == isc_arg_warning) - { - // save a status vector - memcpy(localStatus, tdbb->tdbb_status_vector, sizeof(ISC_STATUS_ARRAY)); - } - - ISC_STATUS status = FB_SUCCESS; - - try - { - JRD_compile(tdbb, - scratch->getAttachment()->dbb_attachment, - &request->req_request, - scratch->getBlrData().getCount(), - scratch->getBlrData().begin(), - statement->getSqlText(), - scratch->getDebugData().getCount(), - scratch->getDebugData().begin(), - isInternalRequest); - } - catch (const Firebird::Exception&) - { - status = tdbb->tdbb_status_vector[1]; - trace.prepare(status == isc_no_priv ? res_unauthorized : res_failed); - } - - // restore warnings (if there are any) - if (localStatus[2] == isc_arg_warning) - { - size_t indx, len, warning; - - // find end of a status vector - PARSE_STATUS(tdbb->tdbb_status_vector, indx, warning); - if (indx) - --indx; - - // calculate length of saved warnings - PARSE_STATUS(localStatus, len, warning); - len -= 2; - - if ((len + indx - 1) < ISC_STATUS_LENGTH) - memcpy(&tdbb->tdbb_status_vector[indx], &localStatus[2], sizeof(ISC_STATUS) * len); - } - - // free blr memory - scratch->getBlrData().free(); - - if (status) - Firebird::status_exception::raise(tdbb->tdbb_status_vector); - - // Notify Trace API manager about new request cooked. - trace.prepare(res_successful); - return request; } catch (const Firebird::Exception&) @@ -1830,16 +1733,15 @@ } statement->setSqlText(NULL); - statement->getDdlData().free(); // free blr memory } -dsql_req::dsql_req(DsqlCompilerScratch* scratch) - : req_pool(scratch->getStatement()->getPool()), - statement(scratch->getStatement()), +dsql_req::dsql_req(MemoryPool& pool) + : req_pool(pool), + statement(NULL), cursors(req_pool), - req_dbb(scratch->getAttachment()), - req_transaction(scratch->getTransaction()), + req_dbb(NULL), + req_transaction(NULL), req_msg_buffers(req_pool), req_cursor(req_pool), req_user_descs(req_pool), Modified: firebird/trunk/src/dsql/dsql.h =================================================================== --- firebird/trunk/src/dsql/dsql.h 2012-02-25 13:55:04 UTC (rev 54045) +++ firebird/trunk/src/dsql/dsql.h 2012-02-25 19:56:37 UTC (rev 54046) @@ -71,6 +71,9 @@ class Attachment; class Database; class DsqlCompilerScratch; + class DdlNode; + class StmtNode; + class TransactionNode; class jrd_tra; class jrd_req; class blb; @@ -427,7 +430,6 @@ : PermanentStorage(p), type(TYPE_SELECT), flags(0), - ddlData(p), sendMsg(NULL), receiveMsg(NULL), eof(NULL), @@ -435,8 +437,7 @@ recVersion(NULL), parentRecVersion(NULL), parentDbKey(NULL), - parentRequest(NULL), - ddlScratch(NULL) + parentRequest(NULL) { } @@ -454,10 +455,6 @@ const Firebird::RefStrPtr& getSqlText() const { return sqlText; } void setSqlText(Firebird::RefString* value) { sqlText = value; } - Firebird::HalfStaticArray<UCHAR, 1024>& getDdlData() { return ddlData; } - const Firebird::HalfStaticArray<UCHAR, 1024>& getDdlData() const { return ddlData; } - void setDdlData(Firebird::HalfStaticArray<UCHAR, 1024>& value) { ddlData = value; } - bool isDdl() const { return type == TYPE_DDL || type == TYPE_CREATE_DB; @@ -494,14 +491,10 @@ dsql_req* getParentRequest() const { return parentRequest; } void setParentRequest(dsql_req* value) { parentRequest = value; } - DsqlCompilerScratch* getDdlScratch() const { return ddlScratch; } - void setDdlScratch(DsqlCompilerScratch* value) { ddlScratch = value; } - private: Type type; // Type of statement ULONG flags; // generic flag Firebird::RefStrPtr sqlText; - Firebird::HalfStaticArray<UCHAR, 1024> ddlData; dsql_msg* sendMsg; // Message to be sent to start request dsql_msg* receiveMsg; // Per record message to be received dsql_par* eof; // End of file parameter @@ -510,7 +503,6 @@ dsql_par* parentRecVersion; // parent record version dsql_par* parentDbKey; // Parent database key for current of dsql_req* parentRequest; // Source request, if cursor update - DsqlCompilerScratch* ddlScratch; // DSQL scratch for DDL statements }; class dsql_req : public pool_alloc<dsql_type_req> @@ -520,7 +512,7 @@ static const unsigned FLAG_EMBEDDED = 0x02; public: - explicit dsql_req(DsqlCompilerScratch* scratch); + explicit dsql_req(MemoryPool& pool); public: MemoryPool& getPool() @@ -538,6 +530,9 @@ return statement; } + virtual void dsqlPass(thread_db* tdbb, DsqlCompilerScratch* scratch, + ntrace_result_t* traceResult) = 0; + virtual void execute(thread_db* tdbb, jrd_tra** traHandle, ULONG inBlrLength, const UCHAR* inBlr, ULONG inMsgLength, const UCHAR* inMsg, ULONG outBlrLength, const UCHAR* const outBlr, ULONG outMsgLength, UCHAR* outMsg, @@ -552,9 +547,9 @@ private: MemoryPool& req_pool; - const DsqlCompiledStatement* statement; public: + const DsqlCompiledStatement* statement; Firebird::Array<DsqlCompiledStatement*> cursors; // Cursor update statements dsql_dbb* req_dbb; // DSQL attachment @@ -584,6 +579,79 @@ friend class Firebird::MemoryPool; }; +class DsqlDmlRequest : public dsql_req +{ +public: + explicit DsqlDmlRequest(MemoryPool& pool, StmtNode* aNode) + : dsql_req(pool), + node(aNode) + { + req_traced = true; + } + + virtual void dsqlPass(thread_db* tdbb, DsqlCompilerScratch* scratch, + ntrace_result_t* traceResult); + + virtual void execute(thread_db* tdbb, jrd_tra** traHandle, + ULONG inBlrLength, const UCHAR* inBlr, ULONG inMsgLength, const UCHAR* inMsg, + ULONG outBlrLength, const UCHAR* const outBlr, ULONG outMsgLength, UCHAR* outMsg, + bool singleton); + + virtual void setCursor(thread_db* tdbb, const TEXT* name); + + virtual ISC_STATUS fetch(thread_db* tdbb, ULONG blrLength, const UCHAR* blr, + ULONG msgLength, UCHAR* msgBuffer); + +private: + StmtNode* node; +}; + +class DsqlDdlRequest : public dsql_req +{ +public: + explicit DsqlDdlRequest(MemoryPool& pool, DdlNode* aNode) + : dsql_req(pool), + node(aNode), + scratch(NULL) + { + req_traced = true; + } + + virtual void dsqlPass(thread_db* tdbb, DsqlCompilerScratch* scratch, + ntrace_result_t* traceResult); + + virtual void execute(thread_db* tdbb, jrd_tra** traHandle, + ULONG inBlrLength, const UCHAR* inBlr, ULONG inMsgLength, const UCHAR* inMsg, + ULONG outBlrLength, const UCHAR* const outBlr, ULONG outMsgLength, UCHAR* outMsg, + bool singleton); + +private: + DdlNode* node; + DsqlCompilerScratch* scratch; +}; + +class DsqlTransactionRequest : public dsql_req +{ +public: + explicit DsqlTransactionRequest(MemoryPool& pool, TransactionNode* aNode) + : dsql_req(pool), + node(aNode) + { + req_traced = false; + } + + virtual void dsqlPass(thread_db* tdbb, DsqlCompilerScratch* scratch, + ntrace_result_t* traceResult); + + virtual void execute(thread_db* tdbb, jrd_tra** traHandle, + ULONG inBlrLength, const UCHAR* inBlr, ULONG inMsgLength, const UCHAR* inMsg, + ULONG outBlrLength, const UCHAR* const outBlr, ULONG outMsgLength, UCHAR* outMsg, + bool singleton); + +private: + TransactionNode* node; +}; + //! Implicit (NATURAL and USING) joins class ImplicitJoin : public pool_alloc<dsql_type_imp_join> { Modified: firebird/trunk/src/dsql/parse.y =================================================================== --- firebird/trunk/src/dsql/parse.y 2012-02-25 13:55:04 UTC (rev 54045) +++ firebird/trunk/src/dsql/parse.y 2012-02-25 19:56:37 UTC (rev 54046) @@ -645,6 +645,7 @@ Jrd::BoolExprNode* boolExprNode; Jrd::StmtNode* stmtNode; Jrd::DdlNode* ddlNode; + Jrd::TransactionNode* traNode; Jrd::CreateCollationNode* createCollationNode; Jrd::CreateDomainNode* createDomainNode; Jrd::AlterDomainNode* alterDomainNode; @@ -676,6 +677,7 @@ Jrd::SetTransactionNode* setTransactionNode; Jrd::DeclareSubProcNode* declareSubProcNode; Jrd::DeclareSubFuncNode* declareSubFuncNode; + Jrd::dsql_req* dsqlReq; } %type <legacyNode> access_type alias_list @@ -712,10 +714,10 @@ %type <legacyNode> column_constraint column_constraint_clause %type <legacyNode> column_constraint_def column_constraint_list column_def %type <boolVal> check_opt - %type <legacyNode> column_list column_name column_parens column_parens_opt column_select %type <legacyNode> column_singleton -%type <stmtNode> commit complex_proc_statement +%type <traNode> commit +%type <stmtNode> complex_proc_statement %type <legacyNode> computed_by computed_clause constant constraint_index_opt %type <boolVal> conditional %type <legacyNode> constraint_name_opt correlation_name @@ -744,6 +746,8 @@ %type <ddlNode> declare declare_clause drop drop_clause %type <legacyStr> db_name ddl_desc %type db_alter_clause(<alterDatabaseNode>) +%type <ddlNode> ddl_statement +%type <stmtNode> dml_statement %type <legacyNode> event_argument_opt %type <ddlNode> exception_clause @@ -851,7 +855,7 @@ %type <ddlNode> revoke rexception_clause %type <legacyNode> role_admin_option role_grantee role_grantee_list %type <legacyNode> role_name role_name_list rows_clause -%type <stmtNode> rollback +%type <traNode> rollback %type <ddlNode> role_clause rtable_clause %type <ddlNode> rview_clause %type <nullableIntVal> revoke_admin @@ -871,7 +875,7 @@ %type <ddlNode> set_statistics %type <legacyNode> simple_type simple_when_clause skip_clause %type <uintVal> snap_shot -%type <node> statement +%type <dsqlReq> statement %type <legacyNode> string_length_opt %type <legacyNode> symbol_UDF_call_name symbol_UDF_name symbol_blob_subtype_name symbol_character_set_name %type <legacyNode> symbol_collation_name symbol_column_name symbol_constraint_name symbol_cursor_name @@ -897,6 +901,7 @@ %type tran_option(<setTransactionNode>) tran_option_list(<setTransactionNode>) %type tran_option_list_opt(<setTransactionNode>) %type <uintVal> time_precision_opt timestamp_precision_opt +%type <traNode> tra_statement %type <legacyNode> u_constant u_numeric_constant udf_data_type %type <createAlterFunctionNode> udf_decl_clause @@ -998,41 +1003,51 @@ // list of possible statements top - : statement - { DSQL_parse = $1; } - | statement ';' - { DSQL_parse = $1; } + : statement { DSQL_parse = $1; } + | statement ';' { DSQL_parse = $1; } ; statement - : alter { $$ = $1; } + : dml_statement { $$ = newNode<DsqlDmlRequest>($1); } + | ddl_statement { $$ = newNode<DsqlDdlRequest>($1); } + | tra_statement { $$ = newNode<DsqlTransactionRequest>($1); } + ; + +dml_statement // ASF: ALTER SEQUENCE is defined here cause it's treated as DML. - | ALTER SEQUENCE alter_sequence_clause { $$ = $3; } - | comment { $$ = $1; } - | commit { $$ = $1; } - | create { $$ = $1; } - | create_or_alter { $$ = $1; } - | declare { $$ = $1; } + : ALTER SEQUENCE alter_sequence_clause { $$ = $3; } | delete { $$ = $1; } - | drop { $$ = $1; } - | grant { $$ = $1; } | insert { $$ = $1; } | merge { $$ = $1; } | exec_procedure { $$ = $1; } | exec_block { $$ = $1; } - | recreate { $$ = $1; } - | revoke { $$ = $1; } - | rollback { $$ = $1; } | savepoint { $$ = $1; } | select { $$ = $1; } - | set_transaction { $$ = $1; } | set_generator { $$ = $1; } - | set_statistics { $$ = $1; } | update { $$ = $1; } | update_or_insert { $$ = $1; } ; +ddl_statement + : alter { $$ = $1; } + | comment { $$ = $1; } + | create { $$ = $1; } + | create_or_alter { $$ = $1; } + | declare { $$ = $1; } + | drop { $$ = $1; } + | grant { $$ = $1; } + | recreate { $$ = $1; } + | revoke { $$ = $1; } + | set_statistics { $$ = $1; } + ; +tra_statement + : set_transaction { $$ = $1; } + | commit { $$ = $1; } + | rollback { $$ = $1; } + ; + + // GRANT statement grant This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2012-03-18 21:37:22
|
Revision: 54192 http://firebird.svn.sourceforge.net/firebird/?rev=54192&view=rev Author: asfernandes Date: 2012-03-18 21:37:13 +0000 (Sun, 18 Mar 2012) Log Message: ----------- Refactor DDL nodes removing references to non-value/-rse dsql_nod. Modified Paths: -------------- firebird/trunk/src/dsql/DdlNodes.epp firebird/trunk/src/dsql/DdlNodes.h firebird/trunk/src/dsql/DsqlCompilerScratch.cpp firebird/trunk/src/dsql/StmtNodes.cpp 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 Modified: firebird/trunk/src/dsql/DdlNodes.epp =================================================================== --- firebird/trunk/src/dsql/DdlNodes.epp 2012-03-18 04:48:39 UTC (rev 54191) +++ firebird/trunk/src/dsql/DdlNodes.epp 2012-03-18 21:37:13 UTC (rev 54192) @@ -94,7 +94,7 @@ 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); + const ValueSourceClause* clause, 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, @@ -293,7 +293,7 @@ // 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) + const ValueSourceClause* clause, string& source, BlrWriter::BlrData& value) { // Get the table node and set up correct context. DDL_reset_context_stack(dsqlScratch); @@ -319,7 +319,7 @@ PASS1_make_context(dsqlScratch, relation); - dsql_nod* input = PASS1_node(dsqlScratch, node->nod_arg[Dsql::e_cmp_expr]); + dsql_nod* input = PASS1_node(dsqlScratch, clause->value); // Try to calculate size of the computed field. The calculated size // may be ignored, but it will catch self references. @@ -369,9 +369,7 @@ 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.assign(sourceStr->str_data, sourceStr->str_length); + source = clause->source; value.assign(dsqlScratch->getBlrData()); } @@ -977,10 +975,10 @@ ParameterClause::ParameterClause(MemoryPool& pool, dsql_fld* field, const MetaName& aCollate, - dsql_nod* dflt, dsql_nod* aLegacyParameter) + ValueSourceClause* aDefaultClause, dsql_nod* aLegacyParameter) : TypeClause(pool, field, aCollate), name(pool, field ? field->fld_name : ""), - legacyDefault(dflt), + defaultClause(aDefaultClause), legacyParameter(aLegacyParameter) { } @@ -1377,11 +1375,10 @@ { ParameterClause& parameter = parameters[i]; - if (parameter.legacyDefault) + if (parameter.defaultClause) { hasDefaultParams = true; - parameter.legacyDefault->nod_arg[e_dft_default] = - PASS1_node(dsqlScratch, parameter.legacyDefault->nod_arg[e_dft_default]); + parameter.defaultClause->value = PASS1_node(dsqlScratch, parameter.defaultClause->value); } else if (hasDefaultParams) { @@ -1849,15 +1846,13 @@ // It was writing in RDB$FIELDS, but that would require special support // for packaged functions signature verification. - if (parameter.legacyDefault) + if (parameter.defaultClause) { ARG.RDB$DEFAULT_VALUE.NULL = FALSE; ARG.RDB$DEFAULT_SOURCE.NULL = FALSE; - dsql_str* defaultString = - (dsql_str*) parameter.legacyDefault->nod_arg[e_dft_default_source]; - const string defaultSource(defaultString->str_data, defaultString->str_length); - attachment->storeMetaDataBlob(tdbb, transaction, &ARG.RDB$DEFAULT_SOURCE, defaultSource); + attachment->storeMetaDataBlob(tdbb, transaction, &ARG.RDB$DEFAULT_SOURCE, + parameter.defaultClause->source); dsqlScratch->getBlrData().clear(); @@ -1866,7 +1861,7 @@ else dsqlScratch->appendUChar(blr_version5); - GEN_expr(dsqlScratch, parameter.legacyDefault->nod_arg[e_dft_default]); + GEN_expr(dsqlScratch, parameter.defaultClause->value); dsqlScratch->appendUChar(blr_eoc); @@ -2298,11 +2293,10 @@ { ParameterClause& parameter = parameters[i]; - if (parameter.legacyDefault) + if (parameter.defaultClause) { hasDefaultParams = true; - parameter.legacyDefault->nod_arg[e_dft_default] = - PASS1_node(dsqlScratch, parameter.legacyDefault->nod_arg[e_dft_default]); + parameter.defaultClause->value = PASS1_node(dsqlScratch, parameter.defaultClause->value); } else if (hasDefaultParams) { @@ -2677,15 +2671,13 @@ // It was writing in RDB$FIELDS, but that would require special support // for packaged procedures signature verification. - PRM.RDB$DEFAULT_VALUE.NULL = !parameter.legacyDefault; - PRM.RDB$DEFAULT_SOURCE.NULL = !parameter.legacyDefault; + PRM.RDB$DEFAULT_VALUE.NULL = !parameter.defaultClause; + PRM.RDB$DEFAULT_SOURCE.NULL = !parameter.defaultClause; - if (parameter.legacyDefault) + if (parameter.defaultClause) { - dsql_str* defaultString = - (dsql_str*) parameter.legacyDefault->nod_arg[e_dft_default_source]; - const string defaultSource(defaultString->str_data, defaultString->str_length); - attachment->storeMetaDataBlob(tdbb, transaction, &PRM.RDB$DEFAULT_SOURCE, defaultSource); + attachment->storeMetaDataBlob(tdbb, transaction, &PRM.RDB$DEFAULT_SOURCE, + parameter.defaultClause->source); dsqlScratch->getBlrData().clear(); @@ -2694,7 +2686,7 @@ else dsqlScratch->appendUChar(blr_version5); - GEN_expr(dsqlScratch, parameter.legacyDefault->nod_arg[e_dft_default]); + GEN_expr(dsqlScratch, parameter.defaultClause->value); dsqlScratch->appendUChar(blr_eoc); @@ -3796,7 +3788,7 @@ const dsql_nod* elements = nameType.legacyField->fld_ranges; const USHORT dims = elements ? elements->nod_count / 2 : 0; - if (nameType.legacyDefault && dims != 0) + if (nameType.defaultClause && dims != 0) { // Default value is not allowed for array type in domain %s status_exception::raise(Arg::PrivateDyn(226) << nameType.name); @@ -3816,7 +3808,7 @@ storeGlobalField(tdbb, transaction, nameType.name, nameType); - if (nameType.legacyDefault || check || notNull) + if (nameType.defaultClause || check || notNull) { AutoCacheRequest request(tdbb, drq_m_fld, DYN_REQUESTS); @@ -3825,19 +3817,16 @@ WITH FLD.RDB$FIELD_NAME EQ nameType.name.c_str() { MODIFY FLD - if (nameType.legacyDefault) + if (nameType.defaultClause) { - dsql_str* defaultString = - (dsql_str*) nameType.legacyDefault->nod_arg[e_dft_default_source]; - const string defaultSource(defaultString->str_data, defaultString->str_length); - FLD.RDB$DEFAULT_SOURCE.NULL = FALSE; - attachment->storeMetaDataBlob(tdbb, transaction, &FLD.RDB$DEFAULT_SOURCE, defaultSource); + attachment->storeMetaDataBlob(tdbb, transaction, &FLD.RDB$DEFAULT_SOURCE, + nameType.defaultClause->source); dsqlScratch->getBlrData().clear(); dsqlScratch->appendUChar(dsqlScratch->isVersion4() ? blr_version4 : blr_version5); - dsql_nod* node = PASS1_node(dsqlScratch, nameType.legacyDefault->nod_arg[e_dft_default]); + dsql_nod* node = PASS1_node(dsqlScratch, nameType.defaultClause->value); GEN_expr(dsqlScratch, node); @@ -3850,11 +3839,9 @@ if (check) { - dsql_str* checkString = (dsql_str*) check->nod_arg[e_cnstr_source]; - const string checkSource(checkString->str_data, checkString->str_length); - FLD.RDB$VALIDATION_SOURCE.NULL = FALSE; - attachment->storeMetaDataBlob(tdbb, transaction, &FLD.RDB$VALIDATION_SOURCE, checkSource); + attachment->storeMetaDataBlob(tdbb, transaction, &FLD.RDB$VALIDATION_SOURCE, + check->source); dsqlScratch->getBlrData().clear(); dsqlScratch->appendUChar(dsqlScratch->isVersion4() ? blr_version4 : blr_version5); @@ -3867,7 +3854,7 @@ // -- chrisj 1999-08-20 ++dsqlScratch->contextNumber; - dsql_nod* node = PASS1_node(dsqlScratch, check->nod_arg[e_cnstr_condition]); + dsql_nod* node = PASS1_node(dsqlScratch, check->value); GEN_expr(dsqlScratch, node); @@ -4368,7 +4355,7 @@ // Get the attributes of the domain, and set any occurances of // keyword VALUE to the correct type, length, scale, etc. - if (!METD_get_domain(dsqlScratch->getTransaction(), &localField, name.c_str())) + if (!METD_get_domain(dsqlScratch->getTransaction(), &localField, name)) { // Specified domain or source field does not exist status_exception::raise( @@ -4381,11 +4368,9 @@ dsqlScratch->domainValue.dsc_length = localField.fld_length; dsqlScratch->domainValue.dsc_scale = localField.fld_scale; - dsql_str* checkString = (dsql_str*) setConstraint->nod_arg[e_cnstr_source]; - const string checkSource(checkString->str_data, checkString->str_length); - FLD.RDB$VALIDATION_SOURCE.NULL = FALSE; - attachment->storeMetaDataBlob(tdbb, transaction, &FLD.RDB$VALIDATION_SOURCE, checkSource); + attachment->storeMetaDataBlob(tdbb, transaction, &FLD.RDB$VALIDATION_SOURCE, + setConstraint->source); dsqlScratch->getBlrData().clear(); dsqlScratch->appendUChar(dsqlScratch->isVersion4() ? blr_version4 : blr_version5); @@ -4398,7 +4383,7 @@ // -- chrisj 1999-08-20 ++dsqlScratch->contextNumber; - dsql_nod* node = PASS1_node(dsqlScratch, setConstraint->nod_arg[e_cnstr_condition]); + dsql_nod* node = PASS1_node(dsqlScratch, setConstraint->value); GEN_expr(dsqlScratch, node); @@ -4417,17 +4402,14 @@ status_exception::raise(Arg::PrivateDyn(226) << name); } - dsql_str* defaultString = - (dsql_str*) setDefault->nod_arg[e_dft_default_source]; - const string defaultSource(defaultString->str_data, defaultString->str_length); - FLD.RDB$DEFAULT_SOURCE.NULL = FALSE; - attachment->storeMetaDataBlob(tdbb, transaction, &FLD.RDB$DEFAULT_SOURCE, defaultSource); + attachment->storeMetaDataBlob(tdbb, transaction, &FLD.RDB$DEFAULT_SOURCE, + setDefault->source); dsqlScratch->getBlrData().clear(); dsqlScratch->appendUChar(dsqlScratch->isVersion4() ? blr_version4 : blr_version5); - dsql_nod* node = PASS1_node(dsqlScratch, setDefault->nod_arg[e_dft_default]); + dsql_nod* node = PASS1_node(dsqlScratch, setDefault->value); GEN_expr(dsqlScratch, node); @@ -5087,7 +5069,7 @@ : DdlNode(p), dsqlNode(aDsqlNode), name(p, ExprNode::as<RelationSourceNode>(aDsqlNode)->dsqlName), - elements(p) + clauses(p) { } @@ -5413,9 +5395,10 @@ } void RelationNode::defineField(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, - jrd_tra* transaction, const dsql_nod* element, SSHORT position, const dsql_nod* pkCols) + jrd_tra* transaction, const AddColumnClause* clause, SSHORT position, + const ObjectsArray<MetaName>* pkCols) { - dsql_fld* field = (dsql_fld*) element->nod_arg[Dsql::e_dfl_field]; + dsql_fld* field = clause->field; // Add the field to the relation being defined for parsing purposes. @@ -5443,29 +5426,21 @@ ObjectsArray<Constraint> constraints; bool notNullFlag = false; - if (element->nod_arg[Dsql::e_dfl_identity]) + if (clause->identity) notNullFlag = true; // identity columns are implicitly not null - if (element->nod_arg[Dsql::e_dfl_constraint]) + for (ObjectsArray<AddConstraintClause>::const_iterator ptr = clause->constraints.begin(); + ptr != clause->constraints.end(); ++ptr) { - const dsql_nod* node = element->nod_arg[Dsql::e_dfl_constraint]; - const dsql_nod* const* const endPtr = node->nod_arg + node->nod_count; - - for (const dsql_nod* const* ptr = node->nod_arg; ptr != endPtr; ++ptr) - { - if ((*ptr)->nod_type == Dsql::nod_rel_constraint) - makeConstraint(tdbb, dsqlScratch, transaction, *ptr, constraints, ¬NullFlag); - } + makeConstraint(tdbb, dsqlScratch, transaction, &*ptr, constraints, ¬NullFlag); } if (!notNullFlag && pkCols) { // Let's see if the field appears in a "primary_key (a, b, c)" relation constraint. - for (int i = 0; !notNullFlag && i < pkCols->nod_count; ++i) + for (int i = 0; !notNullFlag && i < pkCols->getCount(); ++i) { - const dsql_str* pkFieldName = (dsql_str*) pkCols->nod_arg[i]->nod_arg[Dsql::e_fln_name]; - - if (field->fld_name == pkFieldName->str_data) + if (field->fld_name == (*pkCols)[i].c_str()) notNullFlag = true; } } @@ -5478,44 +5453,34 @@ if (position >= 0) fieldDefinition.position = position; - MetaName collationName; - - if (element->nod_arg[Dsql::e_dfl_collate]) - collationName = ((dsql_str*) element->nod_arg[Dsql::e_dfl_collate])->str_data; - - const dsql_nod* domainNode = element->nod_arg[Dsql::e_dfl_domain]; - - if (domainNode) + if (clause->domain.hasData()) { - const dsql_nod* node1 = domainNode->nod_arg[Dsql::e_dom_name]; - const dsql_str* domainName = (dsql_str*) node1->nod_arg[Dsql::e_fln_name]; - // Get the domain information. - if (!METD_get_domain(transaction, field, domainName->str_data)) + if (!METD_get_domain(transaction, field, clause->domain)) { // Specified domain or source field does not exist status_exception::raise( Arg::Gds(isc_sqlerr) << Arg::Num(-607) << Arg::Gds(isc_dsql_command_err) << - Arg::Gds(isc_dsql_domain_not_found) << domainName->str_data); + Arg::Gds(isc_dsql_domain_not_found) << clause->domain); } - fieldDefinition.fieldSource = domainName->str_data; + fieldDefinition.fieldSource = clause->domain; } else { string computedSource; BlrWriter::BlrData computedValue; - if (element->nod_arg[e_dfl_computed]) + if (clause->computed) { field->fld_flags |= FLD_computed; - defineComputed(dsqlScratch, dsqlNode, field, element->nod_arg[e_dfl_computed], + defineComputed(dsqlScratch, dsqlNode, field, clause->computed, computedSource, computedValue); } - TypeClause fieldType(*tdbb->getDefaultPool(), field, collationName); + TypeClause fieldType(*tdbb->getDefaultPool(), field, clause->collate); fieldType.resolve(dsqlScratch); // Generate a domain. @@ -5535,10 +5500,10 @@ Arg::Gds(isc_dsql_type_not_supp_ext_tab) << typeName << name << field->fld_name); } - if (collationName.hasData()) - DDL_resolve_intl_type(dsqlScratch, field, collationName); + if (clause->collate.hasData()) + DDL_resolve_intl_type(dsqlScratch, field, clause->collate); - if (element->nod_arg[Dsql::e_dfl_identity]) + if (clause->identity) { dsc desc; MET_get_domain(tdbb, fieldDefinition.fieldSource, &desc, NULL); @@ -5557,9 +5522,9 @@ BlrWriter::BlrData defaultValue; - if (element->nod_arg[Dsql::e_dfl_default]) + if (clause->defaultValue) { - if (defineDefault(tdbb, dsqlScratch, field, element->nod_arg[Dsql::e_dfl_default], + if (defineDefault(tdbb, dsqlScratch, field, clause->defaultValue, fieldDefinition.defaultSource, defaultValue) && notNullFlag) { @@ -5572,7 +5537,7 @@ fieldDefinition.defaultValue = defaultValue; - if (element->nod_arg[Dsql::e_dfl_collate]) + if (clause->collate.hasData()) fieldDefinition.collationId = field->fld_collation_id; fieldDefinition.store(tdbb, transaction); @@ -5598,9 +5563,9 @@ // 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) + dsql_fld* /*field*/, const ValueSourceClause* clause, string& source, BlrWriter::BlrData& value) { - dsql_nod* input = PASS1_node(dsqlScratch, node->nod_arg[Dsql::e_dft_default]); + dsql_nod* input = PASS1_node(dsqlScratch, clause->value); // Generate the blr expression. @@ -5612,9 +5577,7 @@ dsqlScratch->appendUChar(blr_eoc); // Generate the source text. - const dsql_str* sourceStr = (dsql_str*) node->nod_arg[Dsql::e_dft_default_source]; - fb_assert(sourceStr->str_length <= MAX_USHORT); - source.assign(sourceStr->str_data, sourceStr->str_length); + source = clause->source; value.assign(dsqlScratch->getBlrData()); @@ -5623,80 +5586,53 @@ // Make a constraint object from a legacy node. void RelationNode::makeConstraint(thread_db* /*tdbb*/, DsqlCompilerScratch* dsqlScratch, - jrd_tra* transaction, const dsql_nod* node, ObjectsArray<Constraint>& constraints, bool* notNull) + jrd_tra* transaction, const AddConstraintClause* clause, ObjectsArray<Constraint>& constraints, + bool* notNull) { - const dsql_str* string = (dsql_str*) node->nod_arg[Dsql::e_rct_name]; - dsql_nod* constraintNode = node->nod_arg[Dsql::e_rct_type]; - - switch (constraintNode->nod_type) + switch (clause->constraintType) { - case Dsql::nod_not_null: - case Dsql::nod_primary: + case AddConstraintClause::CTYPE_NOT_NULL: + case AddConstraintClause::CTYPE_PK: if (notNull && !*notNull) { *notNull = true; Constraint& constraint = constraints.add(); constraint.type = Constraint::TYPE_NOT_NULL; - if (string && constraintNode->nod_type == Dsql::nod_not_null) - constraint.name = string->str_data; + if (clause->constraintType == AddConstraintClause::CTYPE_NOT_NULL) + constraint.name = clause->name; } - if (constraintNode->nod_type == Dsql::nod_not_null) + if (clause->constraintType == AddConstraintClause::CTYPE_NOT_NULL) break; - // nod_primary falls into + // AddConstraintClause::CTYPE_PK falls into - case Dsql::nod_unique: + case AddConstraintClause::CTYPE_UNIQUE: { Constraint& constraint = constraints.add(); - constraint.type = constraintNode->nod_type == Dsql::nod_primary ? + constraint.type = clause->constraintType == AddConstraintClause::CTYPE_PK ? Constraint::TYPE_PK : Constraint::TYPE_UNIQUE; - if (string) - constraint.name = string->str_data; - - const dsql_nod* index = constraintNode->nod_arg[Dsql::e_pri_index]; - fb_assert(index); - - string = (dsql_str*) index->nod_arg[Dsql::e_idx_name]; - constraint.indexName = (string ? string->str_data : constraint.name.c_str()); - - if (index->nod_arg[Dsql::e_idx_asc_dsc]) - constraint.descending = true; - - const dsql_nod* columns = constraintNode->nod_arg[Dsql::e_pri_columns]; - if (columns) - { - const dsql_nod* const* ptr = columns->nod_arg; - - for (const dsql_nod* const* const end = ptr + columns->nod_count; ptr < end; ++ptr) - { - const dsql_str* fieldName = (dsql_str*) (*ptr)->nod_arg[Dsql::e_fln_name]; - constraint.columns.add(fieldName->str_data); - } - } - + constraint.name = clause->name; + constraint.indexName = clause->indexName; + constraint.descending = clause->descending; + constraint.columns = clause->columns; break; } - case Dsql::nod_foreign: + case AddConstraintClause::CTYPE_FK: { Constraint& constraint = constraints.add(); constraint.type = Constraint::TYPE_FK; - if (string) - constraint.name = string->str_data; + constraint.name = clause->name; + constraint.columns = clause->columns; + constraint.refRelation = clause->refRelation; + constraint.refColumns = clause->refColumns; - dsql_nod* columns = constraintNode->nod_arg[Dsql::e_for_columns]; - RelationSourceNode* refRelationNode = ExprNode::as<RelationSourceNode>( - constraintNode->nod_arg[Dsql::e_for_reftable]); - - constraint.refRelation = refRelationNode->dsqlName; - // If there is a referenced table name but no referenced field names, the // primary key of the referenced table designates the referenced fields. - dsql_nod* refColumns = constraintNode->nod_arg[Dsql::e_for_refcolumns]; - if (!refColumns) + if (clause->refColumns.isEmpty()) { - refColumns = METD_get_primary_key(transaction, refRelationNode->dsqlName); + dsql_nod* refColumns = METD_get_primary_key(transaction, clause->refRelation); // If there is NEITHER an explicitly referenced field name, NOR does // the referenced table have a primary key to serve as the implicitly @@ -5711,9 +5647,19 @@ Arg::Gds(isc_dsql_command_err) << Arg::Gds(isc_reftable_requires_pk)); } + else + { + const dsql_nod* const* ptr = refColumns->nod_arg; + + for (const dsql_nod* const* const end = ptr + refColumns->nod_count; ptr != end; ++ptr) + { + const dsql_str* fieldName = (dsql_str*) (*ptr)->nod_arg[Dsql::e_fln_name]; + constraint.refColumns.add(fieldName->str_data); + } + } } - if (refColumns && columns->nod_count != refColumns->nod_count) + if (constraint.refColumns.getCount() != constraint.columns.getCount()) { // Foreign key field count does not match primary key. status_exception::raise( @@ -5724,61 +5670,26 @@ // Define the foreign key index and the triggers that may be needed // for referential integrity action. + constraint.indexName = clause->indexName; + constraint.descending = clause->descending; - const dsql_nod* index = constraintNode->nod_arg[Dsql::e_for_index]; - fb_assert(index); - - string = (dsql_str*) index->nod_arg[Dsql::e_idx_name]; - constraint.indexName = (string ? string->str_data : constraint.name.c_str()); - - if (index->nod_arg[Dsql::e_idx_asc_dsc]) - constraint.descending = true; - - if (columns) + if (clause->refAction) { - const dsql_nod* const* ptr = columns->nod_arg; - - for (const dsql_nod* const* const end = ptr + columns->nod_count; ptr < end; ++ptr) + if (clause->refAction->updateAction != 0) { - const dsql_str* fieldName = (dsql_str*) (*ptr)->nod_arg[Dsql::e_fln_name]; - constraint.columns.add(fieldName->str_data); - } - } - - if (refColumns) - { - const dsql_nod* const* ptr = refColumns->nod_arg; - - for (const dsql_nod* const* const end = ptr + refColumns->nod_count; ptr < end; ++ptr) - { - const dsql_str* fieldName = (dsql_str*) (*ptr)->nod_arg[Dsql::e_fln_name]; - constraint.refColumns.add(fieldName->str_data); - } - } - - if (constraintNode->nod_arg[Dsql::e_for_action]) - { - dsql_nod* forActionNode = constraintNode->nod_arg[Dsql::e_for_action]; - fb_assert(forActionNode->nod_type == Dsql::nod_ref_upd_del); - - dsql_nod* refUpdActionNode = forActionNode->nod_arg[Dsql::e_ref_upd]; - if (refUpdActionNode) - { - fb_assert(refUpdActionNode->nod_type == Dsql::nod_ref_trig_action); - - switch (refUpdActionNode->nod_flags) + switch (clause->refAction->updateAction) { - case REF_ACTION_CASCADE: + case RefActionClause::ACTION_CASCADE: constraint.refUpdateAction = RI_ACTION_CASCADE; defineUpdateCascadeTrigger(dsqlScratch, constraint); break; - case REF_ACTION_SET_DEFAULT: + case RefActionClause::ACTION_SET_DEFAULT: constraint.refUpdateAction = RI_ACTION_DEFAULT; defineSetDefaultTrigger(dsqlScratch, constraint, true); break; - case REF_ACTION_SET_NULL: + case RefActionClause::ACTION_SET_NULL: constraint.refUpdateAction = RI_ACTION_NULL; defineSetNullTrigger(dsqlScratch, constraint, true); break; @@ -5787,30 +5698,27 @@ fb_assert(0); // fall into - case REF_ACTION_NONE: + case RefActionClause::ACTION_NONE: constraint.refUpdateAction = RI_ACTION_NONE; break; } } - dsql_nod* refDelActionNode = forActionNode->nod_arg[Dsql::e_ref_del]; - if (refDelActionNode) + if (clause->refAction->deleteAction != 0) { - fb_assert(refDelActionNode->nod_type == Dsql::nod_ref_trig_action); - - switch (refDelActionNode->nod_flags) + switch (clause->refAction->deleteAction) { - case REF_ACTION_CASCADE: + case RefActionClause::ACTION_CASCADE: constraint.refDeleteAction = RI_ACTION_CASCADE; defineDeleteCascadeTrigger(dsqlScratch, constraint); break; - case REF_ACTION_SET_DEFAULT: + case RefActionClause::ACTION_SET_DEFAULT: constraint.refDeleteAction = RI_ACTION_DEFAULT; defineSetDefaultTrigger(dsqlScratch, constraint, false); break; - case REF_ACTION_SET_NULL: + case RefActionClause::ACTION_SET_NULL: constraint.refDeleteAction = RI_ACTION_NULL; defineSetNullTrigger(dsqlScratch, constraint, false); break; @@ -5819,7 +5727,7 @@ fb_assert(0); // fall into - case REF_ACTION_NONE: + case RefActionClause::ACTION_NONE: constraint.refDeleteAction = RI_ACTION_NONE; break; } @@ -5829,14 +5737,12 @@ break; } - case Dsql::nod_def_constraint: + case AddConstraintClause::CTYPE_CHECK: { Constraint& constraint = constraints.add(); constraint.type = Constraint::TYPE_CHECK; - if (string) - constraint.name = string->str_data; - - defineCheckConstraint(dsqlScratch, constraint, constraintNode); + constraint.name = clause->name; + defineCheckConstraint(dsqlScratch, constraint, clause->check); break; } } @@ -6079,18 +5985,18 @@ // Generate triggers to implement the CHECK clause, either at the field or table level. void RelationNode::defineCheckConstraint(DsqlCompilerScratch* dsqlScratch, Constraint& constraint, - dsql_nod* node) + const ValueSourceClause* clause) { // Create the INSERT trigger. - defineCheckConstraintTrigger(dsqlScratch, constraint, node, PRE_STORE_TRIGGER); + defineCheckConstraintTrigger(dsqlScratch, constraint, clause, PRE_STORE_TRIGGER); // Create the UPDATE trigger. - defineCheckConstraintTrigger(dsqlScratch, constraint, node, PRE_MODIFY_TRIGGER); + defineCheckConstraintTrigger(dsqlScratch, constraint, clause, PRE_MODIFY_TRIGGER); } // Define a check constraint trigger. void RelationNode::defineCheckConstraintTrigger(DsqlCompilerScratch* dsqlScratch, - Constraint& constraint, dsql_nod* node, FB_UINT64 triggerType) + Constraint& constraint, const ValueSourceClause* clause, FB_UINT64 triggerType) { thread_db* tdbb = JRD_get_thread_data(); MemoryPool& pool = *tdbb->getDefaultPool(); @@ -6135,7 +6041,7 @@ // Generate the condition for firing the trigger. - NotBoolNode* notNode = FB_NEW(pool) NotBoolNode(pool, node->nod_arg[Dsql::e_cnstr_condition]); + NotBoolNode* notNode = FB_NEW(pool) NotBoolNode(pool, clause->value); dsql_nod* condition = MAKE_node(Dsql::nod_class_exprnode, 1); condition->nod_arg[0] = reinterpret_cast<dsql_nod*>(notNode); @@ -6161,7 +6067,7 @@ trigger.systemFlag = fb_sysflag_check_constraint; trigger.relationName = name; trigger.type = triggerType; - trigger.source = ((dsql_str*) node->nod_arg[Dsql::e_cnstr_source])->str_data; + trigger.source = clause->source; trigger.blrData = blrWriter.getBlrData(); } @@ -6210,29 +6116,26 @@ // Search the parse tree to find the column - for (const dsql_nod* const* ptr = elements.begin(); ptr != elements.end(); ++ptr) + for (const Clause* const* ptr = clauses.begin(); ptr != clauses.end(); ++ptr) { - const dsql_nod* elem = *ptr; - - if (elem->nod_type != Dsql::nod_def_field) + if ((*ptr)->type != Clause::TYPE_ADD_COLUMN) continue; - const dsql_fld* field = (dsql_fld*) elem->nod_arg[Dsql::e_dfl_field]; - if (*column != field->fld_name) + const AddColumnClause* clause = static_cast<const AddColumnClause*>(*ptr); + + if (*column != clause->field->fld_name) continue; // Now we have the right column in the parse tree. case (1) above - dsql_nod* default_node = elem->nod_arg[Dsql::e_dfl_default]; - if (default_node) + if (clause->defaultValue) { // case (1-a) above: There is a column level default - fb_assert(default_node->nod_type == Dsql::nod_def_default); dsqlScratch->getBlrData().clear(); dsqlScratch->getDebugData().clear(); - GEN_expr(dsqlScratch, default_node->nod_arg[Dsql::e_dft_default]); + GEN_expr(dsqlScratch, clause->defaultValue->value); foundDefault = true; searchForDefault = false; @@ -6242,23 +6145,13 @@ } else { - const TEXT* domainName; - const dsql_str* domainNameStr; - const dsql_nod* tmpNode; - - const dsql_nod* domainNode = elem->nod_arg[Dsql::e_dfl_domain]; - if (!domainNode || - !(tmpNode = domainNode->nod_arg[Dsql::e_dom_name]) || - !(domainNameStr = (dsql_str*) tmpNode->nod_arg[Dsql::e_fln_name]) || - !(domainName = domainNameStr->str_data)) - { + if (!clause->domain.hasData()) break; - } // case: (1-b): Domain name is available. Column level default // is not declared. So get the domain default. const USHORT defaultLen = METD_get_domain_default(dsqlScratch->getTransaction(), - domainName, &foundDefault, defaultVal, sizeof(defaultVal)); + clause->domain, &foundDefault, defaultVal, sizeof(defaultVal)); searchForDefault = false; @@ -6607,22 +6500,22 @@ storePrivileges(tdbb, transaction, name, obj_relation, ALL_PRIVILEGES); ObjectsArray<Constraint> constraints; - const dsql_nod* pkCols = findPkColumns(); + const ObjectsArray<MetaName>* pkCols = findPkColumns(); SSHORT position = 0; - for (const dsql_nod* const* i = elements.begin(); i != elements.end(); ++i) + for (const Clause* const* i = clauses.begin(); i != clauses.end(); ++i) { - const dsql_nod* element = *i; - - switch (element->nod_type) + switch ((*i)->type) { - case Dsql::nod_def_field: - defineField(tdbb, dsqlScratch, transaction, element, position, pkCols); + case Clause::TYPE_ADD_COLUMN: + defineField(tdbb, dsqlScratch, transaction, + static_cast<const AddColumnClause*>(*i), position, pkCols); ++position; break; - case Dsql::nod_rel_constraint: - makeConstraint(tdbb, dsqlScratch, transaction, element, constraints); + case Clause::TYPE_ADD_CONSTRAINT: + makeConstraint(tdbb, dsqlScratch, transaction, + static_cast<const AddConstraintClause*>(*i), constraints); break; default: @@ -6651,17 +6544,16 @@ // Starting from the elements in a table definition, locate the PK columns if given in a // separate table constraint declaration. -const dsql_nod* CreateRelationNode::findPkColumns() +const ObjectsArray<MetaName>* CreateRelationNode::findPkColumns() { - for (const dsql_nod* const* i = elements.begin(); i != elements.end(); ++i) + for (const Clause* const* i = clauses.begin(); i != clauses.end(); ++i) { - const dsql_nod* element = *i; - - if (element->nod_type == Dsql::nod_rel_constraint) + if ((*i)->type == Clause::TYPE_ADD_CONSTRAINT) { - const dsql_nod* node = element->nod_arg[Dsql::e_rct_type]; - if (node->nod_type == Dsql::nod_primary) - return node->nod_arg[Dsql::e_pri_columns]; + const AddConstraintClause* clause = static_cast<const AddConstraintClause*>(*i); + + if (clause->constraintType == AddConstraintClause::CTYPE_PK) + return &clause->columns; } } @@ -6709,53 +6601,49 @@ ObjectsArray<Constraint> constraints; - for (const dsql_nod* const* i = elements.begin(); i != elements.end(); ++i) + for (const Clause* const* i = clauses.begin(); i != clauses.end(); ++i) { - const dsql_nod* element = *i; - - switch (element->nod_type) + switch ((*i)->type) { - case Dsql::nod_def_field: - defineField(tdbb, dsqlScratch, transaction, element, -1, NULL); + case Clause::TYPE_ADD_COLUMN: + defineField(tdbb, dsqlScratch, transaction, + static_cast<const AddColumnClause*>(*i), -1, NULL); break; - case Dsql::nod_mod_field_type: - modifyField(tdbb, dsqlScratch, transaction, element); + case Clause::TYPE_ALTER_COL_TYPE: + modifyField(tdbb, dsqlScratch, transaction, + static_cast<const AlterColTypeClause*>(*i)); break; - case Dsql::nod_mod_field_name: + case Clause::TYPE_ALTER_COL_NAME: { - const dsql_nod* oldField = element->nod_arg[e_mod_fld_name_orig_name]; - MetaName oldFieldName = ((dsql_str*) oldField->nod_arg[e_fln_name])->str_data; - const dsql_nod* newField = element->nod_arg[e_mod_fld_name_new_name]; - MetaName newFieldName = ((dsql_str*) newField->nod_arg[e_fln_name])->str_data; - + const AlterColNameClause* clause = static_cast<const AlterColNameClause*>(*i); AutoRequest request; bool found = false; FOR(REQUEST_HANDLE request TRANSACTION_HANDLE transaction) RFL IN RDB$RELATION_FIELDS - WITH RFL.RDB$FIELD_NAME EQ oldFieldName.c_str() AND + WITH RFL.RDB$FIELD_NAME EQ clause->fromName.c_str() AND RFL.RDB$RELATION_NAME EQ name.c_str() { found = true; MODIFY RFL - checkViewDependency(tdbb, transaction, name, oldFieldName); - checkSpTrigDependency(tdbb, transaction, name, oldFieldName); + checkViewDependency(tdbb, transaction, name, clause->fromName); + checkSpTrigDependency(tdbb, transaction, name, clause->fromName); - if (!fieldExists(tdbb, transaction, name, newFieldName)) + if (!fieldExists(tdbb, transaction, name, clause->toName)) { - strcpy(RFL.RDB$FIELD_NAME, newFieldName.c_str()); + strcpy(RFL.RDB$FIELD_NAME, clause->toName.c_str()); AlterDomainNode::modifyLocalFieldIndex(tdbb, transaction, name, - oldFieldName, newFieldName); + clause->fromName, clause->toName); } else { // msg 205: Cannot rename field %s to %s. A field with that name // already exists in table %s. status_exception::raise( - Arg::PrivateDyn(205) << oldFieldName << newFieldName << name); + Arg::PrivateDyn(205) << clause->fromName << clause->toName << name); } END_MODIFY } @@ -6764,41 +6652,38 @@ if (!found) { // msg 176: "column %s does not exist in table/view %s" - status_exception::raise(Arg::PrivateDyn(176) << oldFieldName << name); + status_exception::raise(Arg::PrivateDyn(176) << clause->fromName << name); } break; } - case Dsql::nod_mod_field_null_flag: + case Clause::TYPE_ALTER_COL_NULL: { + const AlterColNullClause* clause = static_cast<const AlterColNullClause*>(*i); + //// FIXME: This clause allows inconsistencies like setting a field with a //// not null CONSTRAINT as nullable, or setting a field based on a not null //// domain as nullable (while ISQL shows it as not null). - const dsql_nod* fieldNode = element->nod_arg[e_mod_fld_null_flag_field]; - MetaName fieldName = ((dsql_str*) fieldNode->nod_arg[e_fln_name])->str_data; - bool flag = ExprNode::as<LiteralNode>( - element->nod_arg[e_mod_fld_null_flag_value])->getSlong() != 0; - AutoRequest request; bool found = false; FOR(REQUEST_HANDLE request TRANSACTION_HANDLE transaction) RFL IN RDB$RELATION_FIELDS - WITH RFL.RDB$FIELD_NAME EQ fieldName.c_str() AND + WITH RFL.RDB$FIELD_NAME EQ clause->name.c_str() AND RFL.RDB$RELATION_NAME EQ name.c_str() { found = true; MODIFY RFL - if (!flag && !RFL.RDB$GENERATOR_NAME.NULL) + if (!clause->notNullFlag && !RFL.RDB$GENERATOR_NAME.NULL) { // msg 274: Identity column @1 of table @2 cannot be changed to NULLable - status_exception::raise(Arg::PrivateDyn(274) << fieldName << name); + status_exception::raise(Arg::PrivateDyn(274) << clause->name << name); } - RFL.RDB$NULL_FLAG = SSHORT(flag); + RFL.RDB$NULL_FLAG = SSHORT(clause->notNullFlag); END_MODIFY } END_FOR @@ -6806,20 +6691,17 @@ if (!found) { // msg 176: "column %s does not exist in table/view %s" - status_exception::raise(Arg::PrivateDyn(176) << fieldName << name); + status_exception::raise(Arg::PrivateDyn(176) << clause->name << name); } break; } - case Dsql::nod_mod_field_pos: + case Clause::TYPE_ALTER_COL_POS: { - const dsql_nod* fieldNode = element->nod_arg[e_mod_fld_pos_orig_name]; - MetaName fieldName = ((dsql_str*) fieldNode->nod_arg[e_fln_name])->str_data; - const dsql_nod* posNode = element->nod_arg[e_mod_fld_pos_new_position]; - + const AlterColPosClause* clause = static_cast<const AlterColPosClause*>(*i); // CVC: Since now the parser accepts pos=1..N, let's subtract one here. - const SSHORT pos = (SSHORT) ExprNode::as<LiteralNode>(posNode)->getSlong() - 1; + const SSHORT pos = clause->newPos - 1; AutoRequest request; bool found = false; @@ -6827,7 +6709,7 @@ FOR(REQUEST_HANDLE request TRANSACTION_HANDLE transaction) RFL IN RDB$RELATION_FIELDS - WITH RFL.RDB$FIELD_NAME EQ fieldName.c_str() AND + WITH RFL.RDB$FIELD_NAME EQ clause->name.c_str() AND RFL.RDB$RELATION_NAME EQ name.c_str() { found = true; @@ -6838,16 +6720,16 @@ if (!found) { // msg 176: "column %s does not exist in table/view %s" - status_exception::raise(Arg::PrivateDyn(176) << fieldName << name); + status_exception::raise(Arg::PrivateDyn(176) << clause->name << name); } if (pos != oldPos) - modifyLocalFieldPosition(tdbb, transaction, name, fieldName, pos, oldPos); + modifyLocalFieldPosition(tdbb, transaction, name, clause->name, pos, oldPos); break; } - case Dsql::nod_del_field: + case Clause::TYPE_DROP_COLUMN: { // Fix for bug 8054: // [CASCADE | RESTRICT] syntax is available in IB4.5, but not @@ -6856,10 +6738,9 @@ // Option CASCADE causes an error: unsupported DSQL construct. // Option RESTRICT is default behaviour. - const dsql_nod* fieldNode = element->nod_arg[0]; - MetaName fieldName = ((dsql_str*) fieldNode->nod_arg[e_fln_name])->str_data; + const DropColumnClause* clause = static_cast<const DropColumnClause*>(*i); - if ((element->nod_arg[1])->nod_type == nod_cascade) + if (clause->cascade) { // Unsupported DSQL construct status_exception::raise( @@ -6868,18 +6749,18 @@ Arg::Gds(isc_dsql_construct_err)); } - fb_assert((element->nod_arg[1])->nod_type == nod_restrict); - deleteLocalField(tdbb, transaction, name, fieldName); + deleteLocalField(tdbb, transaction, name, clause->name); break; } - case Dsql::nod_rel_constraint: - makeConstraint(tdbb, dsqlScratch, transaction, element, constraints); + case Clause::TYPE_ADD_CONSTRAINT: + makeConstraint(tdbb, dsqlScratch, transaction, + static_cast<const AddConstraintClause*>(*i), constraints); break; - case Dsql::nod_delete_rel_constraint: + case Clause::TYPE_DROP_CONSTRAINT: { - MetaName constraintName = ((dsql_str*) element->nod_arg[0])->str_data; + const MetaName& constraintName = static_cast<const DropConstraintClause *>(*i)->name; AutoCacheRequest request(tdbb, drq_e_rel_con, DYN_REQUESTS); bool found = false; @@ -6959,11 +6840,11 @@ // Anything to Blob // Anything to Array void AlterRelationNode::modifyField(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, - jrd_tra* transaction, const dsql_nod* element) + jrd_tra* transaction, const AlterColTypeClause* clause) { Attachment* const attachment = transaction->tra_attachment; - dsql_fld* field = (dsql_fld*) element->nod_arg[Dsql::e_mod_fld_type_field]; + dsql_fld* field = clause->field; // Add the field to the relation being defined for parsing purposes. bool permanent = false; @@ -6987,9 +6868,6 @@ try { - dsql_nod* domainNode = element->nod_arg[Dsql::e_mod_fld_type_dom_name]; - dsql_nod* computedNode = element->nod_arg[Dsql::e_mod_fld_type_computed]; - dsql_nod* defaultNode = element->nod_arg[Dsql::e_mod_fld_type_default]; bool found = false; AutoRequest request; @@ -7006,7 +6884,7 @@ bool isView = !REL.RDB$VIEW_BLR.NULL; - if (!isView && (!FLD.RDB$COMPUTED_BLR.NULL != (computedNode != NULL))) + if (!isView && (!FLD.RDB$COMPUTED_BLR.NULL != (clause->computed != NULL))) { // Cannot add or remove COMPUTED from column @1 status_exception::raise(Arg::PrivateDyn(249) << field->fld_name); @@ -7038,71 +6916,71 @@ string computedSource; BlrWriter::BlrData computedValue; - if (computedNode) + if (clause->computed) { - defineComputed(dsqlScratch, dsqlNode, field, computedNode, computedSource, + defineComputed(dsqlScratch, dsqlNode, field, clause->computed, computedSource, computedValue); } - if (defaultNode) + if (clause->defaultValue) { MODIFY RFR - if (defaultNode->nod_type == nod_def_default) + if (!RFR.RDB$GENERATOR_NAME.NULL) { - if (!RFR.RDB$GENERATOR_NAME.NULL) - { - // msg 275: Identity column @1 of table @2 cannot have default value - status_exception::raise(Arg::PrivateDyn(275) << field->fld_name << name); - } + // msg 275: Identity column @1 of table @2 cannot have default value + status_exception::raise(Arg::PrivateDyn(275) << field->fld_name << name); + } - if (hasDimensions) - { - // msg 225: "Default value is not allowed for array type in field %s" - status_exception::raise(Arg::PrivateDyn(225) << field->fld_name); - } + if (hasDimensions) + { + // msg 225: "Default value is not allowed for array type in field %s" + status_exception::raise(Arg::PrivateDyn(225) << field->fld_name); + } - if (computedNode) - { - // msg 233: "Local column %s is computed, cannot set a default value" - status_exception::raise(Arg::PrivateDyn(233) << field->fld_name); - } + if (clause->computed) + { + // msg 233: "Local column %s is computed, cannot set a default value" + status_exception::raise(Arg::PrivateDyn(233) << field->fld_name); + } - string defaultSource; - BlrWriter::BlrData defaultValue; + string defaultSource; + BlrWriter::BlrData defaultValue; - defineDefault(tdbb, dsqlScratch, field, defaultNode, defaultSource, defaultValue); + defineDefault(tdbb, dsqlScratch, field, clause->defaultValue, + defaultSource, defaultValue); - RFR.RDB$DEFAULT_SOURCE.NULL = FALSE; - attachment->storeMetaDataBlob(tdbb, transaction, - &RFR.RDB$DEFAULT_SOURCE, defaultSource); + RFR.RDB$DEFAULT_SOURCE.NULL = FALSE; + attachment->storeMetaDataBlob(tdbb, transaction, + &RFR.RDB$DEFAULT_SOURCE, defaultSource); - RFR.RDB$DEFAULT_VALUE.NULL = FALSE; - attachment->storeBinaryBlob(tdbb, transaction, - &RFR.RDB$DEFAULT_VALUE, defaultValue); - } - else if (defaultNode->nod_type == nod_del_default) + RFR.RDB$DEFAULT_VALUE.NULL = FALSE; + attachment->storeBinaryBlob(tdbb, transaction, + &RFR.RDB$DEFAULT_VALUE, defaultValue); + END_MODIFY + } + else if (clause->dropDefault) + { + MODIFY RFR + if (RFR.RDB$DEFAULT_VALUE.NULL) { - if (RFR.RDB$DEFAULT_VALUE.NULL) + if (FLD.RDB$DEFAULT_VALUE.NULL) { - if (FLD.RDB$DEFAULT_VALUE.NULL) - { - // msg 229: "Local column %s doesn't have a default" - status_exception::raise(Arg::PrivateDyn(229) << field->fld_name); - } - else - { - // msg 230: "Local column %s default belongs to domain %s" - status_exception::raise( - Arg::PrivateDyn(230) << - field->fld_name << MetaName(FLD.RDB$FIELD_NAME)); - } + // msg 229: "Local column %s doesn't have a default" + status_exception::raise(Arg::PrivateDyn(229) << field->fld_name); } else { - RFR.RDB$DEFAULT_SOURCE.NULL = TRUE; - RFR.RDB$DEFAULT_VALUE.NULL = TRUE; + // msg 230: "Local column %s default belongs to domain %s" + status_exception::raise( + Arg::PrivateDyn(230) << + field->fld_name << MetaName(FLD.RDB$FIELD_NAME)); } } + else + { + RFR.RDB$DEFAULT_SOURCE.NULL = TRUE; + RFR.RDB$DEFAULT_VALUE.NULL = TRUE; + } END_MODIFY } else @@ -7112,13 +6990,12 @@ MetaName newDomainName; dyn_fld newDom; - if (domainNode) + if (clause->domain.hasData()) { // Case a1: Internal domain -> domain. // Case a2: Domain -> domain. - const dsql_nod* node1 = domainNode->nod_arg[Dsql::e_dom_name]; - newDomainName = ((dsql_str*) node1->nod_arg[Dsql::e_fln_name])->str_data; + newDomainName = clause->domain; if (fb_utils::implicit_domain(newDomainName.c_str())) { @@ -7128,7 +7005,7 @@ } // Get the domain information. - if (!METD_get_domain(dsqlScratch->getTransaction(), field, newDomainName.c_str())) + if (!METD_get_domain(dsqlScratch->getTransaction(), field, newDomainName)) { // Specified domain or source field does not exist. status_exception::raise( @@ -7156,10 +7033,10 @@ // If COMPUTED was specified but the type wasn't, we use the type of // the computed expression. - if (computedNode && field->fld_dtype == dtype_unknown) + if (clause->computed && field->fld_dtype == dtype_unknown) { dsc desc; - MAKE_desc(dsqlScratch, &desc, computedNode); + MAKE_desc(dsqlScratch, &desc, clause->computed->value); field->fld_dtype = desc.dsc_dtype; field->fld_length = desc.dsc_length; @@ -7197,7 +7074,7 @@ storeGlobalField(tdbb, transaction, newDomainName, type); } - if (!computedNode && !isView) + if (!clause->computed && !isView) { if (newDomainName.hasData()) newDom.dyn_fld_source = newDomainName; @@ -7221,7 +7098,7 @@ RFR.RDB$FIELD_SOURCE.NULL = FALSE; strcpy(RFR.RDB$FIELD_SOURCE, newDomainName.c_str()); - if (computedNode) + if (clause->computed) { RFR.RDB$UPDATE_FLAG.NULL = FALSE; RFR.RDB$UPDATE_FLAG = 1; @@ -7232,7 +7109,7 @@ } } - if (computedNode) + if (clause->computed) { // We can alter FLD directly here because if we are setting a computed expression, // it means the field already was computed. And if it was, it should be the @@ -8906,10 +8783,10 @@ definition.unique = unique; definition.descending = descending; - if (legacyDef->nod_type == Dsql::nod_list) + if (columns) { - const dsql_nod* const* ptr = legacyDef->nod_arg; - const dsql_nod* const* const end = ptr + legacyDef->nod_count; + const dsql_nod* const* ptr = columns->nod_arg; + const dsql_nod* const* const end = ptr + columns->nod_count; for (; ptr != end; ++ptr) { @@ -8917,12 +8794,12 @@ column = ((dsql_str*) (*ptr)->nod_arg[1])->str_data; } } - else if (legacyDef->nod_type == Dsql::nod_def_computed) + else if (computed) { string computedSource; BlrWriter::BlrData computedValue; - defineComputed(dsqlScratch, legacyRelation, NULL, legacyDef, computedSource, computedValue); + defineComputed(dsqlScratch, legacyRelation, NULL, computed, computedSource, computedValue); attachment->storeMetaDataBlob(tdbb, transaction, &definition.expressionSource, computedSource); Modified: firebird/trunk/src/dsql/DdlNodes.h =================================================================== --- firebird/trunk/src/dsql/DdlNodes.h 2012-03-18 04:48:39 UTC (rev 54191) +++ firebird/trunk/src/dsql/DdlNodes.h 2012-03-18 21:37:13 UTC (rev 54192) @@ -41,6 +41,19 @@ class CompoundStmtNode; +struct ValueSourceClause +{ + ValueSourceClause(MemoryPool& p) + : value(NULL), + source(p) + { + } + + dsql_nod* value; + Firebird::string source; +}; + + class DbFileClause { public: @@ -130,14 +143,14 @@ { public: ParameterClause(MemoryPool& pool, dsql_fld* field, const Firebird::MetaName& aCollate, - dsql_nod* dflt, dsql_nod* aLegacyParameter); + ValueSourceClause* aDefaultClause, dsql_nod* aLegacyParameter); public: void print(Firebird::string& text) const; public: Firebird::MetaName name; - dsql_nod* legacyDefault; + ValueSourceClause* defaultClause; dsql_nod* legacyParameter; Nullable<int> udfMechanism; }; @@ -764,7 +777,7 @@ public: ParameterClause nameType; bool notNull; - dsql_nod* check; + ValueSourceClause* check; }; @@ -806,8 +819,8 @@ Firebird::MetaName name; bool dropConstraint; bool dropDefault; - dsql_nod* setConstraint; - dsql_nod* setDefault; + ValueSourceClause* setConstraint; + ValueSourceClause* setDefault; Firebird::MetaName renameTo; Firebird::AutoPtr<TypeClause> type; Nullable<bool> notNullFlag; // true = NOT NULL / false = NULL @@ -1072,6 +1085,187 @@ Firebird::ObjectsArray<BlrWriter> blrWritersHolder; }; + struct Clause : public PermanentStorage + { + enum Type + { + TYPE_ADD_CONSTRAINT, + TYPE_ADD_COLUMN, + TYPE_ALTER_COL_NAME, + TYPE_ALTER_COL_NULL, + TYPE_ALTER_COL_POS, + TYPE_ALTER_COL_TYPE, + TYPE_DROP_COLUMN, + TYPE_DROP_CONSTRAINT + }; + + explicit Clause(MemoryPool& p, Type aType) + : PermanentStorage(p), + type(aType) + { + } + + const Type type; + }; + + struct RefActionClause + { + static const unsigned ACTION_CASCADE = 1; + static const unsigned ACTION_SET_DEFAULT = 2; + static const unsigned ACTION_SET_NULL = 3; + static const unsigned ACTION_NONE = 4; + + RefActionClause(MemoryPool& p, unsigned aUpdateAction, unsigned aDeleteAction) + : updateAction(aUpdateAction), + deleteAction(aDeleteAction) + { + } + + unsigned updateAction; + unsigned deleteAction; + }; + + struct AddConstraintClause : public Clause + { + enum ConstraintType + { + CTYPE_NOT_NULL, + CTYPE_PK, + CTYPE_FK, + CTYPE_UNIQUE, + CTYPE_CHECK + }; + + AddConstraintClause(MemoryPool& p) + : Clause(p, TYPE_ADD_CONSTRAINT), + name(p), + constraintType(CTYPE_NOT_NULL), + columns(p), + indexName(p), + descending(false), + refRelation(p), + refColumns(p), + refAction(NULL), + check(NULL) + { + } + + Firebird::MetaName name; + ConstraintType constraintType; + Firebird::ObjectsArray<Firebird::MetaName> columns; + Firebird::MetaName indexName; + bool descending; + Firebird::MetaName refRelation; + Firebird::ObjectsArray<Firebird::MetaName> refColumns; + RefActionClause* refAction; + ValueSourceClause* check; + }; + + struct AddColumnClause : public Clause + { + explicit AddColumnClause(MemoryPool& p) + : Clause(p, TYPE_ADD_COLUMN), + field(NULL), + defaultValue(NULL), + constraints(p), + collate(p), + domain(p), + computed(NULL), + identity(false) + { + } + + dsql_fld* field; + ValueSourceClause* defaultValue; + Firebird::ObjectsArray<AddConstraintClause> constraints; + Firebird::MetaName collate; + Firebird::MetaName domain; + ValueSourceClause* computed; + bool identity; + }; + + struct AlterColNameClause : public Clause + { + explicit AlterColNameClause(MemoryPool& p) + : Clause(p, TYPE_ALTER_COL_NAME), + fromName(p), + toName(p) + { + } + + Firebird::MetaName fromName; + Firebird::MetaName toName; + }; + + struct AlterColNullClause : public Clause + { + explicit AlterColNullClause(MemoryPool& p) + : Clause(p, TYPE_ALTER_COL_NULL), + name(p), + notNullFlag(false) + { + } + + Firebird::MetaName name; + bool notNullFlag; + }; + + struct AlterColPosClause : public Clause + { + explicit AlterColPosClause(MemoryPool& p) + : Clause(p, TYPE_ALTER_COL_POS), + name(p), + newPos(0) + { + } + + Firebird::MetaName name; + SSHORT newPos; + }; + + struct AlterColTypeClause : public Clause + { + explicit AlterColTypeClause(MemoryPool& p) + : Clause(p, TYPE_ALTER_COL_TYPE), + field(NULL), + domain(p), + defaultValue(NULL), + dropDefault(false), + computed(NULL) + { + } + + dsql_fld* field; + Firebird::MetaName domain; + ValueSourceClause* defaultValue; + bool dropDefault; + ValueSourceClause* computed; + }; + + struct DropColumnClause : public Clause + { + explicit DropColumnClause(MemoryPool& p) + : Clause(p, TYPE_DROP_COLUMN), + name(p), + cascade(false) + { + } + + Firebird::MetaName name; + bool cascade; + }; + + struct DropConstraintClause : public Clause + { + explicit DropConstraintClause(MemoryPool& p) + : Clause(p, TYPE_DROP_CONSTRAINT), + name(p) + { + } + + Firebird::MetaName name; + }; + RelationNode(MemoryPool& p, dsql_nod* aDsqlNode); static void deleteLocalField(thread_db* tdbb, jrd_tra* transaction, @@ -1079,17 +1273,19 @@ protected: void defineField(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction, - const dsql_nod* element, SSHORT position, const dsql_nod* pkcols); + const AddColumnClause* clause, SSHORT position, + const Firebird::ObjectsArray<Firebird::MetaName>* pkcols); bool defineDefault(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, dsql_fld* field, - dsql_nod* node, Firebird::string& source, BlrWriter::BlrData& value); + const ValueSourceClause* clause, Firebird::string& source, BlrWriter::BlrData& value); void makeConstraint(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction, - const dsql_nod* node, Firebird::ObjectsArray<Constraint>& constraints, bool* notNull = NULL); + const AddConstraintClause* clause, Firebird::ObjectsArray<Constraint>& constraints, + bool* notNull = NULL); void defineConstraint(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction, Constraint& constraint); void defineCheckConstraint(DsqlCompilerScratch* dsqlScratch, Constraint& constraint, - dsql_nod* node); + const ValueSourceClause* clause); void defineCheckConstraintTrigger(DsqlCompilerScratch* dsqlScratch, Constraint& constraint, - dsql_nod* node, FB_UINT64 triggerType); + const ValueSourceClause* clause, FB_UINT64 triggerType); void defineSetDefaultTrigger(DsqlCompilerScratch* dsqlScratch, Constraint& constraint, bool onUpdate); void defineSetNullTrigger(DsqlCompilerScratch* dsqlScratch, Constraint& constraint, @@ -1105,7 +1301,7 @@ public: dsql_nod* dsqlNode; Firebird::MetaName name; - Firebird::Array<dsql_nod*> elements; + Firebird::Array<Clause*> clauses; }; @@ -1131,7 +1327,7 @@ } private: - const dsql_nod* findPkColumns(); + const Firebird::ObjectsArray<Firebird::MetaName>* findPkColumns(); public: const Firebird::PathName* externalFile; @@ -1159,7 +1355,7 @@ private: void modifyField(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction, - const dsql_nod* element); + const AlterColTypeClause* clause); }; @@ -1291,7 +1487,8 @@ unique(false), descending(false), legacyRelation(NULL), - legacyDef(NULL) + columns(NULL), + computed(NULL) { } @@ -1314,7 +1511,8 @@ bool unique; bool descending; dsql_nod* legacyRelation; - dsql_nod* legacyDef; + dsql_nod* columns; + ValueSourceClause* computed; }; Modified: firebird/trunk/src/dsql/DsqlCompilerScratch.cpp =================================================================== --- firebird/trunk/src/dsql/DsqlCompilerScratch.cpp 2012-03-18 04:48:39 UTC (rev 54191) +++ firebird/trunk/src/dsql/DsqlCompilerScratch.cpp 2012-03-18 21:37:13 UTC (rev 54192) @@ -317,7 +317,7 @@ //field->fld_dtype = dtype; // Check for a default value, borrowed from define_domain - dsql_nod* node = hostParam ? hostParam->dsqlDef->legacyDefault : NULL; + ValueSourceClause* node = hostParam ? hostParam->dsqlDef->defaultClause : NULL; if (variable->type == dsql_var::TYPE_INPUT) { @@ -339,10 +339,8 @@ if (node) { - fb_assert(node->nod_type == Dsql::nod_def_default); PsqlChanger psqlChanger(this, false); - node = PASS1_node(this, node->nod_arg[Dsql::e_dft_default]); - GEN_expr(this, node); + GEN_expr(this, PASS1_node(this, node->value)); } else appendUChar(blr_null); // Initialize variable to NULL Modified: firebird/trunk/src/dsql/StmtNodes.cpp =================================================================== --- firebird/trunk/src/dsql/StmtNodes.cpp 2012-03-18 04:48:39 UTC (rev 54191) +++ firebird/trunk/src/dsql/StmtNodes.cpp 2012-03-18 21:37:13 UTC (rev 54192) @@ -1401,7 +1401,7 @@ for (const ParameterClause* param = paramArray.begin(); param != paramArray.end(); ++param) { - if (param->legacyDefault) + if (param->defaultClause) defaultFound = true; else if (defaultFound) { @@ -1446,10 +1446,10 @@ { dsqlScratch->appendNullString(param->name.c_str()); - if (param->legacyDefault) + if (param->defaultClause) { dsqlScratch->appendUChar(1); - GEN_expr(dsqlScratch, param->legacyDefault->nod_arg[Dsql::e_dft_default]); + GEN_expr(dsqlScratch, param->defaultClause->value); } else dsqlScratch->appendUChar(0); @@ -1661,7 +1661,7 @@ for (const ParameterClause* param = paramArray.begin(); param != paramArray.end(); ++param) { - if (param->legacyDefault) + if (param->defaultClause) { if (dsqlProcedure->prc_def_count == 0) dsqlProcedure->prc_def_count = paramArray.end() - param; @@ -1715,10 +1715,10 @@ { dsqlScratch->appendNullString(param->name.c_str()); - if (param->legacyDefault) + if (param->defaultClause) { dsqlScratch->appendUChar(1); - GEN_expr(dsqlScratch, param->legacyDefault->nod_arg[Dsql::e_dft_default]); + GEN_expr(dsqlScratch, param->defaultClause->value); } else dsqlScratch->appendUChar(0); @@ -3667,11 +3667,8 @@ newParam.legacyParameter = PASS1_node(dsqlScratch, newParam.legacyParameter); - if (newParam.legacyDefault) - { - newParam.legacyDefault->nod_arg[Dsql::e_dft_default] = - PASS1_node(dsqlScratch, newParam.legacyDefault->nod_arg[Dsql::e_dft_default]); - } + if (newParam.defaultClause) + newParam.defaultClause->value = PASS1_node(dsqlScratch, newParam.defaultClause->value); newParam.resolve(dsqlScratch); newParam.legacyField->fld_id = param - parameters.begin(); Modified: firebird/trunk/src/dsql/ddl.cpp =================================================================== --- firebird/trunk/src/dsql/ddl.cpp 2012-03-18 04:48:39 UTC (rev 54191) +++ firebird/trunk/src/dsql/ddl.cpp 2012-03-18 21:37:13 UTC (rev 54192) @@ -209,7 +209,7 @@ } else { - if (!METD_get_domain(dsqlScratch->getTransaction(), field, field->fld_type_of_name.c_str())) + if (!METD_get_domain(dsqlScratch->getTransaction(), field, field->fld_type_of_name)) { // Specified domain or source field does not exist post_607(Arg::Gds(isc_dsql_domain_not_found) << Arg::Str(field->fld_type_of_name)); Modified: firebird/trunk/src/dsql/metd.epp =================================================================== --- firebird/trunk/src/dsql/metd.epp 2012-03-18 04:48:39 UTC (rev 54191) +++ firebird/trunk/src/dsql/metd.epp 2012-03-18 21:37:13 UTC (rev 54192) @@ -620,7 +620,7 @@ } -bool METD_get_domain(jrd_tra* transaction, dsql_fld* field, const char* name) // UTF-8 +bool METD_get_domain(jrd_tra* transaction, dsql_fld* field, const MetaName& name) // UTF-8 { /************************************** * @@ -641,7 +641,7 @@ AutoCacheRequest handle(tdbb, irq_domain, IRQ_REQUESTS); FOR(REQUEST_HANDLE handle TRANSACTION_HANDLE transaction) - FLX IN RDB$FIELDS WITH FLX.RDB$FIELD_NAME EQ name + FLX IN RDB$FIELDS WITH FLX.RDB$FIELD_NAME EQ name.c_str() { found = true; field->fld_length = FLX.RDB$FIELD_LENGTH; @@ -680,7 +680,7 @@ } -USHORT METD_get_domain_default(jrd_tra* transaction, const TEXT* domain_name, bool* has_default, +USHORT METD_get_domain_default(jrd_tra* transaction, const MetaName& domain_name, bool* has_default, UCHAR* buffer, USHORT buff_length) { /************************************************************* @@ -705,7 +705,7 @@ AutoCacheRequest handle(tdbb, irq_domain_2, IRQ_REQUESTS); FOR(REQUEST_HANDLE handle TRANSACTION_HANDLE transaction) - FLD IN RDB$FIELDS WITH FLD.RDB$FIELD_NAME EQ domain_name + FLD IN RDB$FIELDS WITH FLD.RDB$FIELD_NAME EQ domain_name.c_str() { bid* blob_id; if (!FLD.RDB$DEFAULT_VALUE.NULL) Modified: firebird/trunk/src/dsql/metd_proto.h =================================================================== --- firebird/trunk/src/dsql/metd_proto.h 2012-03-18 04:48:39 UTC (rev 54191) +++ firebird/trunk/src/dsql/metd_proto.h 2012-03-18 21:37:13 UTC (rev 54192) @@ -58... [truncated message content] |
From: <asf...@us...> - 2012-03-18 22:22:21
|
Revision: 54193 http://firebird.svn.sourceforge.net/firebird/?rev=54193&view=rev Author: asfernandes Date: 2012-03-18 22:22:14 +0000 (Sun, 18 Mar 2012) Log Message: ----------- Refactor nod_def_index. Modified Paths: -------------- firebird/trunk/src/dsql/DdlNodes.epp firebird/trunk/src/dsql/DdlNodes.h firebird/trunk/src/dsql/node.h firebird/trunk/src/dsql/parse.y firebird/trunk/src/dsql/pass1.cpp Modified: firebird/trunk/src/dsql/DdlNodes.epp =================================================================== --- firebird/trunk/src/dsql/DdlNodes.epp 2012-03-18 21:37:13 UTC (rev 54192) +++ firebird/trunk/src/dsql/DdlNodes.epp 2012-03-18 22:22:14 UTC (rev 54193) @@ -5613,8 +5613,7 @@ constraint.type = clause->constraintType == AddConstraintClause::CTYPE_PK ? Constraint::TYPE_PK : Constraint::TYPE_UNIQUE; constraint.name = clause->name; - constraint.indexName = clause->indexName; - constraint.descending = clause->descending; + constraint.index = clause->index; constraint.columns = clause->columns; break; } @@ -5670,8 +5669,7 @@ // Define the foreign key index and the triggers that may be needed // for referential integrity action. - constraint.indexName = clause->indexName; - constraint.descending = clause->descending; + constraint.index = clause->index; if (clause->refAction) { @@ -5805,17 +5803,17 @@ isc_dyn_def_primary_key : (constraint.type == Constraint::TYPE_FK ? isc_dyn_def_foreign_key : 0)); definition.unique = constraint.type != Constraint::TYPE_FK; - if (constraint.descending) + if (constraint.index->descending) definition.descending = true; definition.columns = constraint.columns; definition.refRelation = constraint.refRelation; definition.refColumns = constraint.refColumns; - CreateIndexNode::store(tdbb, transaction, constraint.indexName, definition, + CreateIndexNode::store(tdbb, transaction, constraint.index->name, definition, &referredIndexName); CRT.RDB$INDEX_NAME.NULL = FALSE; - strcpy(CRT.RDB$INDEX_NAME, constraint.indexName.c_str()); + strcpy(CRT.RDB$INDEX_NAME, constraint.index->name.c_str()); checkForeignKeyTempScope(tdbb, transaction, name, referredIndexName); @@ -5862,7 +5860,7 @@ IDS IN RDB$INDEX_SEGMENTS CROSS RFR IN RDB$RELATION_FIELDS CROSS FLX IN RDB$FIELDS - WITH IDS.RDB$INDEX_NAME EQ constraint.indexName.c_str() AND + WITH IDS.RDB$INDEX_NAME EQ constraint.index->name.c_str() AND RFR.RDB$RELATION_NAME EQ name.c_str() AND RFR.RDB$FIELD_NAME EQ IDS.RDB$FIELD_NAME AND FLX.RDB$FIELD_NAME EQ RFR.RDB$FIELD_SOURCE @@ -5887,7 +5885,7 @@ FOR(REQUEST_HANDLE request TRANSACTION_HANDLE transaction) IDS IN RDB$INDEX_SEGMENTS - WITH IDS.RDB$INDEX_NAME EQ constraint.indexName.c_str() + WITH IDS.RDB$INDEX_NAME EQ constraint.index->name.c_str() { ++allCount; } Modified: firebird/trunk/src/dsql/DdlNodes.h =================================================================== --- firebird/trunk/src/dsql/DdlNodes.h 2012-03-18 21:37:13 UTC (rev 54192) +++ firebird/trunk/src/dsql/DdlNodes.h 2012-03-18 22:22:14 UTC (rev 54193) @@ -1019,6 +1019,18 @@ Firebird::MetaName baseField; }; + struct IndexConstraintClause + { + IndexConstraintClause(MemoryPool& p) + : name(p), + descending(false) + { + } + + Firebird::MetaName name; + bool descending; + }; + struct Constraint : public PermanentStorage { enum Type { TYPE_CHECK, TYPE_NOT_NULL, TYPE_PK, TYPE_UNIQUE, TYPE_FK }; @@ -1061,8 +1073,7 @@ type(TYPE_CHECK), // Just something to initialize. Do not assume it. name(p), columns(p), - indexName(p), - descending(false), + index(NULL), refRelation(p), refColumns(p), refUpdateAction(RI_RESTRICT), @@ -1075,8 +1086,7 @@ Constraint::Type type; Firebird::MetaName name; Firebird::ObjectsArray<Firebird::MetaName> columns; - Firebird::MetaName indexName; - bool descending; + IndexConstraintClause* index; Firebird::MetaName refRelation; Firebird::ObjectsArray<Firebird::MetaName> refColumns; const char* refUpdateAction; @@ -1141,8 +1151,7 @@ name(p), constraintType(CTYPE_NOT_NULL), columns(p), - indexName(p), - descending(false), + index(NULL), refRelation(p), refColumns(p), refAction(NULL), @@ -1153,8 +1162,7 @@ Firebird::MetaName name; ConstraintType constraintType; Firebird::ObjectsArray<Firebird::MetaName> columns; - Firebird::MetaName indexName; - bool descending; + IndexConstraintClause* index; Firebird::MetaName refRelation; Firebird::ObjectsArray<Firebird::MetaName> refColumns; RefActionClause* refAction; Modified: firebird/trunk/src/dsql/node.h =================================================================== --- firebird/trunk/src/dsql/node.h 2012-03-18 21:37:13 UTC (rev 54192) +++ firebird/trunk/src/dsql/node.h 2012-03-18 22:22:14 UTC (rev 54193) @@ -55,7 +55,6 @@ // to an expression node. nod_unknown_type = 0, - nod_def_index, nod_references, nod_proc_obj, nod_trig_obj, @@ -128,13 +127,6 @@ e_sel_columns, // List with alias names from derived table columns e_sel_count, - e_idx_unique = 0, // nod_def_index - e_idx_asc_dsc, - e_idx_name, - e_idx_table, - e_idx_fields, - e_idx_count, - e_coll_target = 0, // Not a DSQL_NOD nod_collate e_coll_source, e_coll_count, Modified: firebird/trunk/src/dsql/parse.y =================================================================== --- firebird/trunk/src/dsql/parse.y 2012-03-18 21:37:13 UTC (rev 54192) +++ firebird/trunk/src/dsql/parse.y 2012-03-18 22:22:14 UTC (rev 54193) @@ -663,6 +663,7 @@ Jrd::RelationNode* relationNode; Jrd::RelationNode::AddColumnClause* addColumnClause; Jrd::RelationNode::RefActionClause* refActionClause; + Jrd::RelationNode::IndexConstraintClause* indexConstraintClause; Jrd::CreateRelationNode* createRelationNode; Jrd::CreateAlterViewNode* createAlterViewNode; Jrd::CreateIndexNode* createIndexNode; @@ -724,7 +725,8 @@ %type <legacyNode> column_singleton %type <traNode> commit %type <stmtNode> complex_proc_statement -%type <legacyNode> computed_by computed_clause constant constraint_index_opt +%type <legacyNode> computed_by computed_clause constant +%type <indexConstraintClause> constraint_index_opt %type <boolVal> conditional %type <legacyNode> constraint_name_opt correlation_name %type <ddlNode> create create_clause create_user_clause @@ -2118,27 +2120,19 @@ } } - const dsql_nod* index = $5; - constraint.indexName = toName(index->nod_arg[Dsql::e_idx_name]); - constraint.descending = index->nod_arg[Dsql::e_idx_asc_dsc] != NULL; + constraint.index = $5; } | UNIQUE constraint_index_opt { RelationNode::AddConstraintClause& constraint = $addColumnClause->constraints.add(); constraint.constraintType = RelationNode::AddConstraintClause::CTYPE_UNIQUE; - - const dsql_nod* index = $2; - constraint.indexName = toName(index->nod_arg[Dsql::e_idx_name]); - constraint.descending = index->nod_arg[Dsql::e_idx_asc_dsc] != NULL; + constraint.index = $2; } | PRIMARY KEY constraint_index_opt { RelationNode::AddConstraintClause& constraint = $addColumnClause->constraints.add(); constraint.constraintType = RelationNode::AddConstraintClause::CTYPE_PK; - - const dsql_nod* index = $3; - constraint.indexName = toName(index->nod_arg[Dsql::e_idx_name]); - constraint.descending = index->nod_arg[Dsql::e_idx_asc_dsc] != NULL; + constraint.index = $3; } ; @@ -2170,9 +2164,7 @@ constraint.columns.add(fieldName->str_data); } - const dsql_nod* index = $3; - constraint.indexName = toName(index->nod_arg[Dsql::e_idx_name]); - constraint.descending = index->nod_arg[Dsql::e_idx_asc_dsc] != NULL; + constraint.index = $3; $relationNode->clauses.add(&constraint); } @@ -2190,9 +2182,7 @@ constraint.columns.add(fieldName->str_data); } - const dsql_nod* index = $4; - constraint.indexName = toName(index->nod_arg[Dsql::e_idx_name]); - constraint.descending = index->nod_arg[Dsql::e_idx_asc_dsc] != NULL; + constraint.index = $4; $relationNode->clauses.add(&constraint); } @@ -2225,9 +2215,7 @@ } } - const dsql_nod* index = $8; - constraint.indexName = toName(index->nod_arg[Dsql::e_idx_name]); - constraint.descending = index->nod_arg[Dsql::e_idx_asc_dsc] != NULL; + constraint.index = $8; $relationNode->clauses.add(&constraint); } @@ -2242,11 +2230,13 @@ constraint_index_opt : // nothing - { $$ = make_node (nod_def_index, (int) e_idx_count, NULL, NULL, NULL, NULL, NULL); } + { $$ = newNode<RelationNode::IndexConstraintClause>(); } | 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); + RelationNode::IndexConstraintClause* clause = $$ = + newNode<RelationNode::IndexConstraintClause>(); + clause->descending = $2; + clause->name = toName($4); } /*** | NO INDEX Modified: firebird/trunk/src/dsql/pass1.cpp =================================================================== --- firebird/trunk/src/dsql/pass1.cpp 2012-03-18 21:37:13 UTC (rev 54192) +++ firebird/trunk/src/dsql/pass1.cpp 2012-03-18 22:22:14 UTC (rev 54193) @@ -4431,9 +4431,6 @@ case nod_collate: verb = "collate"; break; - case nod_def_index: - verb = "define index"; - break; case nod_delete: verb = "delete"; break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2012-03-25 18:21:28
|
Revision: 54242 http://firebird.svn.sourceforge.net/firebird/?rev=54242&view=rev Author: asfernandes Date: 2012-03-25 18:21:21 +0000 (Sun, 25 Mar 2012) Log Message: ----------- Make column_select a SubQueryNode instead of nod_select_expr directly. Modified Paths: -------------- firebird/trunk/src/dsql/ExprNodes.cpp firebird/trunk/src/dsql/parse.y firebird/trunk/src/dsql/pass1.cpp Modified: firebird/trunk/src/dsql/ExprNodes.cpp =================================================================== --- firebird/trunk/src/dsql/ExprNodes.cpp 2012-03-25 17:21:28 UTC (rev 54241) +++ firebird/trunk/src/dsql/ExprNodes.cpp 2012-03-25 18:21:21 UTC (rev 54242) @@ -9046,11 +9046,20 @@ ExprNode::print(text, nodes); } -ValueExprNode* SubQueryNode::dsqlPass(DsqlCompilerScratch* /*dsqlScratch*/) +ValueExprNode* SubQueryNode::dsqlPass(DsqlCompilerScratch* dsqlScratch) { - // This node is created after dsqlPass and should never be called. - fb_assert(false); - return this; + const DsqlContextStack::iterator base(*dsqlScratch->context); + + dsql_nod* rseNod = PASS1_rse(dsqlScratch, dsqlRse, false); + RseNode* rse = ExprNode::as<RseNode>(rseNod); + + SubQueryNode* node = FB_NEW(getPool()) SubQueryNode(getPool(), blrOp, rseNod, + rse->dsqlSelectList->nod_arg[0], MAKE_class_node(FB_NEW(getPool()) NullNode(getPool()))); + + // Finish off by cleaning up contexts. + dsqlScratch->context->clear(base); + + return node; } void SubQueryNode::setParameterName(dsql_par* parameter) const Modified: firebird/trunk/src/dsql/parse.y =================================================================== --- firebird/trunk/src/dsql/parse.y 2012-03-25 17:21:28 UTC (rev 54241) +++ firebird/trunk/src/dsql/parse.y 2012-03-25 18:21:21 UTC (rev 54242) @@ -4629,8 +4629,8 @@ column_singleton : column_select { - $$ = $1; - $$->nod_flags |= NOD_SELECT_EXPR_SINGLETON; + $1->nod_flags |= NOD_SELECT_EXPR_SINGLETON; + $$ = makeClassNode(newNode<SubQueryNode>(blr_via, $1)); } ; Modified: firebird/trunk/src/dsql/pass1.cpp =================================================================== --- firebird/trunk/src/dsql/pass1.cpp 2012-03-25 17:21:28 UTC (rev 54241) +++ firebird/trunk/src/dsql/pass1.cpp 2012-03-25 18:21:21 UTC (rev 54242) @@ -707,29 +707,9 @@ Arg::Gds(isc_dsql_command_err)); case nod_select_expr: - { - if (input->nod_flags & NOD_SELECT_EXPR_DERIVED) - return pass1_derived_table(dsqlScratch, input, NULL); + fb_assert(input->nod_flags & NOD_SELECT_EXPR_DERIVED); + return pass1_derived_table(dsqlScratch, input, NULL); - const DsqlContextStack::iterator base(*dsqlScratch->context); - - dsql_nod* rseNod = PASS1_rse(dsqlScratch, input, false); - RseNode* rse = ExprNode::as<RseNode>(rseNod); - - SubQueryNode* subQueryNode = FB_NEW(*tdbb->getDefaultPool()) SubQueryNode(*tdbb->getDefaultPool(), - blr_via, rseNod, rse->dsqlSelectList->nod_arg[0], MAKE_node(nod_class_exprnode, 1)); - subQueryNode->dsqlValue2->nod_arg[0] = reinterpret_cast<dsql_nod*>( - FB_NEW(*tdbb->getDefaultPool()) NullNode(*tdbb->getDefaultPool())); - - node = MAKE_node(nod_class_exprnode, 1); - node->nod_arg[0] = reinterpret_cast<dsql_nod*>(subQueryNode); - - // Finish off by cleaning up contexts - dsqlScratch->context->clear(base); - - return node; - } - // access plan node types case nod_plan_item: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hv...@us...> - 2012-03-30 13:49:03
|
Revision: 54286 http://firebird.svn.sourceforge.net/firebird/?rev=54286&view=rev Author: hvlad Date: 2012-03-30 13:48:54 +0000 (Fri, 30 Mar 2012) Log Message: ----------- Fixed issue reported by Thomas Steinmaurer in fb-devel : trace often put in log line Statement 0, <unknown, bug?> Modified Paths: -------------- firebird/trunk/src/dsql/dsql.cpp firebird/trunk/src/dsql/dsql.h Modified: firebird/trunk/src/dsql/dsql.cpp =================================================================== --- firebird/trunk/src/dsql/dsql.cpp 2012-03-30 13:08:45 UTC (rev 54285) +++ firebird/trunk/src/dsql/dsql.cpp 2012-03-30 13:48:54 UTC (rev 54286) @@ -1536,6 +1536,14 @@ ULONG textLength, const TEXT* text, USHORT clientDialect, USHORT parserVersion, bool isInternalRequest) { + if (text && textLength == 0) + { + size_t sqlLength = strlen(text); + if (sqlLength > MAX_USHORT) + sqlLength = MAX_USHORT; + textLength = static_cast<USHORT>(sqlLength); + } + TraceDSQLPrepare trace(database->dbb_attachment, transaction, textLength, text); if (clientDialect > SQL_DIALECT_CURRENT) @@ -1544,13 +1552,6 @@ Arg::Gds(isc_wish_list)); } - if (text && textLength == 0) - { - size_t sqlLength = strlen(text); - if (sqlLength > MAX_USHORT) - sqlLength = MAX_USHORT; - textLength = static_cast<USHORT>(sqlLength); - } if (!text || textLength == 0) { @@ -1645,8 +1646,8 @@ statement->setType(DsqlCompiledStatement::TYPE_SELECT); - if (request->req_traced) - trace.setStatement(request); + request->req_traced = true; + trace.setStatement(request); ntrace_result_t traceResult = res_successful; try @@ -1656,6 +1657,20 @@ request->statement = scratch->getStatement(); request->dsqlPass(tdbb, scratch, &traceResult); + + // don't trace preudo-statements (without requests associated) + switch (statement->getType()) + { + case DsqlCompiledStatement::TYPE_COMMIT: + case DsqlCompiledStatement::TYPE_COMMIT_RETAIN: + case DsqlCompiledStatement::TYPE_ROLLBACK: + case DsqlCompiledStatement::TYPE_ROLLBACK_RETAIN: + case DsqlCompiledStatement::TYPE_START_TRANS: + request->req_traced = false; + break; + default: + request->req_traced = true; + } } catch (const Exception&) { @@ -1748,6 +1763,7 @@ req_msg_buffers(req_pool), req_cursor(req_pool), req_user_descs(req_pool), + req_traced(false), req_interface(NULL) { } Modified: firebird/trunk/src/dsql/dsql.h =================================================================== --- firebird/trunk/src/dsql/dsql.h 2012-03-30 13:08:45 UTC (rev 54285) +++ firebird/trunk/src/dsql/dsql.h 2012-03-30 13:48:54 UTC (rev 54286) @@ -585,7 +585,6 @@ : dsql_req(pool), node(aNode) { - req_traced = true; } virtual void dsqlPass(thread_db* tdbb, DsqlCompilerScratch* scratch, @@ -613,7 +612,6 @@ node(aNode), scratch(NULL) { - req_traced = true; } virtual void dsqlPass(thread_db* tdbb, DsqlCompilerScratch* scratch, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2012-04-08 04:15:16
|
Revision: 54336 http://firebird.svn.sourceforge.net/firebird/?rev=54336&view=rev Author: asfernandes Date: 2012-04-08 04:15:09 +0000 (Sun, 08 Apr 2012) Log Message: ----------- Refactored nod_order. Modified Paths: -------------- firebird/trunk/src/dsql/ExprNodes.cpp firebird/trunk/src/dsql/ExprNodes.h firebird/trunk/src/dsql/Nodes.h firebird/trunk/src/dsql/Visitors.h firebird/trunk/src/dsql/gen.cpp firebird/trunk/src/dsql/node.h firebird/trunk/src/dsql/parse.y firebird/trunk/src/dsql/pass1.cpp Modified: firebird/trunk/src/dsql/ExprNodes.cpp =================================================================== --- firebird/trunk/src/dsql/ExprNodes.cpp 2012-04-07 18:25:44 UTC (rev 54335) +++ firebird/trunk/src/dsql/ExprNodes.cpp 2012-04-08 04:15:09 UTC (rev 54336) @@ -7296,6 +7296,43 @@ //-------------------- +OrderNode::OrderNode(MemoryPool& pool, dsql_nod* aDsqlValue) + : TypedNode<ValueExprNode, ExprNode::TYPE_ORDER>(pool), + dsqlValue(aDsqlValue), + descending(false), + nullsPlacement(NULLS_DEFAULT) +{ + addChildNode(dsqlValue); +} + +void OrderNode::print(string& text, Array<dsql_nod*>& nodes) const +{ + text = "OrderNode"; + ExprNode::print(text, nodes); +} + +OrderNode* OrderNode::dsqlPass(DsqlCompilerScratch* dsqlScratch) +{ + OrderNode* node = FB_NEW(getPool()) OrderNode(getPool(), PASS1_node(dsqlScratch, dsqlValue)); + node->descending = descending; + node->nullsPlacement = nullsPlacement; + return node; +} + +bool OrderNode::dsqlMatch(const ExprNode* other, bool ignoreMapCast) const +{ + if (!ExprNode::dsqlMatch(other, ignoreMapCast)) + return false; + + const OrderNode* o = other->as<OrderNode>(); + + return o && descending == o->descending && nullsPlacement == o->nullsPlacement; +} + + +//-------------------- + + OverNode::OverNode(MemoryPool& pool, dsql_nod* aAggExpr, dsql_nod* aPartition, dsql_nod* aOrder) : TypedNode<ValueExprNode, ExprNode::TYPE_OVER>(pool), dsqlAggExpr(aAggExpr), Modified: firebird/trunk/src/dsql/ExprNodes.h =================================================================== --- firebird/trunk/src/dsql/ExprNodes.h 2012-04-07 18:25:44 UTC (rev 54335) +++ firebird/trunk/src/dsql/ExprNodes.h 2012-04-08 04:15:09 UTC (rev 54336) @@ -952,6 +952,61 @@ }; +class OrderNode : public TypedNode<ValueExprNode, ExprNode::TYPE_ORDER> +{ +public: + enum NullsPlacement + { + NULLS_DEFAULT, + NULLS_FIRST, + NULLS_LAST + }; + + OrderNode(MemoryPool& pool, dsql_nod* aDsqlValue); + + virtual void print(Firebird::string& text, Firebird::Array<dsql_nod*>& nodes) const; + virtual OrderNode* dsqlPass(DsqlCompilerScratch* dsqlScratch); + virtual bool dsqlMatch(const ExprNode* other, bool ignoreMapCast) const; + + virtual void setParameterName(dsql_par* /*parameter*/) const + { + fb_assert(false); + } + + virtual void genBlr(DsqlCompilerScratch* /*dsqlScratch*/) + { + fb_assert(false); + } + + virtual void make(DsqlCompilerScratch* /*dsqlScratch*/, dsc* /*desc*/) + { + fb_assert(false); + } + + virtual void getDesc(thread_db* /*tdbb*/, CompilerScratch* /*csb*/, dsc* /*desc*/) + { + fb_assert(false); + } + + virtual ValueExprNode* copy(thread_db* /*tdbb*/, NodeCopier& /*copier*/) const + { + fb_assert(false); + return NULL; + } + + virtual dsc* execute(thread_db* /*tdbb*/, jrd_req* /*request*/) const + { + fb_assert(false); + return NULL; + } + +public: + dsql_nod* dsqlValue; + bool descending; + NullsPlacement nullsPlacement; +}; + + // OVER is used only in DSQL. In the engine, normal aggregate functions are used in partitioned // maps. class OverNode : public TypedNode<ValueExprNode, ExprNode::TYPE_OVER> Modified: firebird/trunk/src/dsql/Nodes.h =================================================================== --- firebird/trunk/src/dsql/Nodes.h 2012-04-07 18:25:44 UTC (rev 54335) +++ firebird/trunk/src/dsql/Nodes.h 2012-04-08 04:15:09 UTC (rev 54336) @@ -394,6 +394,7 @@ TYPE_MAP, TYPE_NEGATE, TYPE_NULL, + TYPE_ORDER, TYPE_OVER, TYPE_PARAMETER, TYPE_RECORD_KEY, Modified: firebird/trunk/src/dsql/Visitors.h =================================================================== --- firebird/trunk/src/dsql/Visitors.h 2012-04-07 18:25:44 UTC (rev 54335) +++ firebird/trunk/src/dsql/Visitors.h 2012-04-08 04:15:09 UTC (rev 54336) @@ -374,10 +374,6 @@ break; } - case nod_order: - ret |= visit(&node->nod_arg[e_order_field]); - break; - case nod_list: { T2 ptr = node->nod_arg; Modified: firebird/trunk/src/dsql/gen.cpp =================================================================== --- firebird/trunk/src/dsql/gen.cpp 2012-04-07 18:25:44 UTC (rev 54335) +++ firebird/trunk/src/dsql/gen.cpp 2012-04-08 04:15:09 UTC (rev 54336) @@ -672,27 +672,20 @@ dsql_nod* const* ptr = list->nod_arg; for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr++) { - dsql_nod* nulls_placement = (*ptr)->nod_arg[e_order_nulls]; + const OrderNode* orderNode = ExprNode::as<OrderNode>(*ptr); - if (nulls_placement) + switch (orderNode->nullsPlacement) { - switch (ExprNode::as<LiteralNode>(nulls_placement)->getSlong()) - { - case NOD_NULLS_FIRST: - dsqlScratch->appendUChar(blr_nullsfirst); - break; - case NOD_NULLS_LAST: - dsqlScratch->appendUChar(blr_nullslast); - break; - } + case OrderNode::NULLS_FIRST: + dsqlScratch->appendUChar(blr_nullsfirst); + break; + case OrderNode::NULLS_LAST: + dsqlScratch->appendUChar(blr_nullslast); + break; } - if ((*ptr)->nod_arg[e_order_flag]) - dsqlScratch->appendUChar(blr_descending); - else - dsqlScratch->appendUChar(blr_ascending); - - GEN_expr(dsqlScratch, (*ptr)->nod_arg[e_order_field]); + dsqlScratch->appendUChar((orderNode->descending ? blr_descending : blr_ascending)); + GEN_expr(dsqlScratch, orderNode->dsqlValue); } } Modified: firebird/trunk/src/dsql/node.h =================================================================== --- firebird/trunk/src/dsql/node.h 2012-04-07 18:25:44 UTC (rev 54335) +++ firebird/trunk/src/dsql/node.h 2012-04-08 04:15:09 UTC (rev 54336) @@ -67,7 +67,6 @@ nod_all, // ALL privileges nod_execute, // EXECUTE privilege nod_procedure_name, - nod_order, nod_flag, nod_user_name, nod_user_group, @@ -97,12 +96,7 @@ * entries. These include nod_udf. */ enum node_args { - e_order_field = 0, // nod_order - e_order_flag, - e_order_nulls, - e_order_count, - - e_lock_tables = 0, // + e_lock_tables = 0, e_lock_mode, e_label_name = 0, @@ -138,10 +132,7 @@ NOD_SHARED = 1, // nod_lock_mode NOD_PROTECTED = 2, NOD_READ = 4, - NOD_WRITE = 8, - - NOD_NULLS_FIRST = 1, // nod_order - NOD_NULLS_LAST = 2 + NOD_WRITE = 8 }; } // namespace Modified: firebird/trunk/src/dsql/parse.y =================================================================== --- firebird/trunk/src/dsql/parse.y 2012-04-07 18:25:44 UTC (rev 54335) +++ firebird/trunk/src/dsql/parse.y 2012-04-08 04:15:09 UTC (rev 54336) @@ -625,6 +625,7 @@ FB_UINT64 uint64Val; BaseNullable<FB_UINT64> nullableUint64Val; UCHAR blrOp; + Jrd::OrderNode::NullsPlacement nullsPlacement; Jrd::ComparativeBoolNode::DsqlFlag cmpBoolFlag; Jrd::dsql_nod* legacyNode; Jrd::dsql_str* legacyStr; @@ -840,7 +841,8 @@ %type <legacyNode> national_character_type natural_join %type <legacyNode> non_array_type %type <legacyNode> non_charset_simple_type non_reserved_word non_role_grantee_list -%type <legacyNode> nulls_clause nulls_placement numeric_type +%type <nullsPlacement> nulls_clause nulls_placement +%type <legacyNode> numeric_type %type <int32Val> neg_short_integer nonneg_short_integer %type named_param(<execStatementNode>) named_params_list(<execStatementNode>) %type not_named_param(<execStatementNode>) not_named_params_list(<execStatementNode>) @@ -5022,8 +5024,10 @@ order_item : value order_direction nulls_clause { - $$ = make_node (nod_order, (int) e_order_count, - $1, ($2 ? make_node(nod_flag, 0, NULL) : NULL), $3); + OrderNode* node = newNode<OrderNode>($1); + node->descending = $2; + node->nullsPlacement = $3; + $$ = makeClassNode(node); } ; @@ -5034,13 +5038,13 @@ ; nulls_clause - : /* nothing */ { $$ = NULL; } + : /* nothing */ { $$ = OrderNode::NULLS_DEFAULT; } | NULLS nulls_placement { $$ = $2; } ; nulls_placement - : FIRST { $$ = MAKE_const_slong(NOD_NULLS_FIRST); } - | LAST { $$ = MAKE_const_slong(NOD_NULLS_LAST); } + : FIRST { $$ = OrderNode::NULLS_FIRST; } + | LAST { $$ = OrderNode::NULLS_LAST; } ; // ROWS clause Modified: firebird/trunk/src/dsql/pass1.cpp =================================================================== --- firebird/trunk/src/dsql/pass1.cpp 2012-04-07 18:25:44 UTC (rev 54335) +++ firebird/trunk/src/dsql/pass1.cpp 2012-04-08 04:15:09 UTC (rev 54336) @@ -338,10 +338,6 @@ switch (node->nod_type) { - case nod_order: - fb_assert(false); - return true; - default: return visitChildren(node); } @@ -2907,6 +2903,9 @@ DEV_BLKCHK(input, dsql_type_nod); DEV_BLKCHK(selectList, dsql_type_nod); + thread_db* tdbb = JRD_get_thread_data(); + MemoryPool& pool = *tdbb->getDefaultPool(); + if (input->nod_type != nod_list) { ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << @@ -2932,33 +2931,30 @@ for (int sortloop = 0; sortloop < input->nod_count; sortloop++) { DEV_BLKCHK(input->nod_arg[sortloop], dsql_type_nod); - dsql_nod* node1 = input->nod_arg[sortloop]; - if (node1->nod_type != nod_order) + OrderNode* node1 = ExprNode::as<OrderNode>(input->nod_arg[sortloop]); + if (!node1) { ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << Arg::Gds(isc_dsql_command_err) << // invalid ORDER BY clause Arg::Gds(isc_order_by_err)); } - dsql_nod* node2 = MAKE_node(nod_order, e_order_count); - node2->nod_arg[e_order_flag] = node1->nod_arg[e_order_flag]; // asc/desc flag - node2->nod_arg[e_order_nulls] = node1->nod_arg[e_order_nulls]; // nulls first/last flag // get node of value to be ordered by - node1 = node1->nod_arg[e_order_field]; + dsql_nod* orderValue = node1->dsqlValue; - const CollateNode* collateNode = ExprNode::as<CollateNode>(node1); + const CollateNode* collateNode = ExprNode::as<CollateNode>(orderValue); if (collateNode) { // substitute CollateNode with its argument (real value) - node1 = collateNode->dsqlArg; + orderValue = collateNode->dsqlArg; } FieldNode* field; LiteralNode* literal; - if ((field = ExprNode::as<FieldNode>(node1))) + if ((field = ExprNode::as<FieldNode>(orderValue))) { dsql_nod* aliasNode = NULL; @@ -2971,9 +2967,9 @@ aliasNode = PASS1_lookup_alias(dsqlScratch, field->dsqlName, selectList, true); } - node1 = aliasNode ? aliasNode : field->internalDsqlPass(dsqlScratch, NULL); + orderValue = aliasNode ? aliasNode : field->internalDsqlPass(dsqlScratch, NULL); } - else if ((literal = ExprNode::as<LiteralNode>(node1)) && literal->litDesc.dsc_dtype == dtype_long) + else if ((literal = ExprNode::as<LiteralNode>(orderValue)) && literal->litDesc.dsc_dtype == dtype_long) { const ULONG position = literal->getSlong(); @@ -2985,21 +2981,24 @@ } // substitute ordinal with appropriate field - node1 = PASS1_node_psql(dsqlScratch, selectList->nod_arg[position - 1], false); + orderValue = PASS1_node_psql(dsqlScratch, selectList->nod_arg[position - 1], false); } else - node1 = PASS1_node_psql(dsqlScratch, node1, false); + orderValue = PASS1_node_psql(dsqlScratch, orderValue, false); if (collateNode) { // Finally apply collation order, if necessary. - node1 = MAKE_class_node( - CollateNode::pass1Collate(dsqlScratch, node1, collateNode->collation)); + orderValue = MAKE_class_node( + CollateNode::pass1Collate(dsqlScratch, orderValue, collateNode->collation)); } + OrderNode* node2 = FB_NEW(pool) OrderNode(pool, orderValue); + node2->descending = node1->descending; + node2->nullsPlacement = node1->nullsPlacement; + // store actual value to be ordered by - node2->nod_arg[e_order_field] = node1; - *ptr2++ = node2; + *ptr2++ = MAKE_class_node(node2); } return node; @@ -3170,8 +3169,8 @@ for (const dsql_nod* const* const end = ptr + order_list->nod_count; ptr < end; ptr++, uptr++) { - dsql_nod* order1 = *ptr; - const dsql_nod* position = order1->nod_arg[e_order_field]; + OrderNode* order1 = ExprNode::as<OrderNode>(*ptr); + const dsql_nod* position = order1->dsqlValue; const CollateNode* collateNode = ExprNode::as<CollateNode>(position); if (collateNode) @@ -3198,18 +3197,17 @@ } // make a new order node pointing at the Nth item in the select list. - dsql_nod* order2 = MAKE_node(nod_order, e_order_count); - *uptr = order2; - order2->nod_arg[e_order_field] = union_items->nod_arg[number - 1]; - order2->nod_arg[e_order_flag] = order1->nod_arg[e_order_flag]; + OrderNode* order2 = FB_NEW(pool) OrderNode(pool, union_items->nod_arg[number - 1]); + *uptr = MAKE_class_node(order2); + order2->descending = order1->descending; if (collateNode) { - order2->nod_arg[e_order_field] = MAKE_class_node(CollateNode::pass1Collate( - dsqlScratch, order2->nod_arg[e_order_field], collateNode->collation)); + order2->dsqlValue = MAKE_class_node(CollateNode::pass1Collate( + dsqlScratch, order2->dsqlValue, collateNode->collation)); } - order2->nod_arg[e_order_nulls] = order1->nod_arg[e_order_nulls]; + order2->nullsPlacement = order1->nullsPlacement; } unionRse->dsqlOrder = sort; @@ -3763,9 +3761,6 @@ case nod_list: verb = "list"; break; - case nod_order: - verb = "order"; - break; case nod_procedure_name: verb = "procedure name"; break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2012-05-04 15:33:00
|
Revision: 54448 http://firebird.svn.sourceforge.net/firebird/?rev=54448&view=rev Author: asfernandes Date: 2012-05-04 15:32:49 +0000 (Fri, 04 May 2012) Log Message: ----------- Make usage of dsqlChildNodes consistent. Modified Paths: -------------- firebird/trunk/src/dsql/AggNodes.cpp firebird/trunk/src/dsql/DdlNodes.epp firebird/trunk/src/dsql/ExprNodes.cpp Modified: firebird/trunk/src/dsql/AggNodes.cpp =================================================================== --- firebird/trunk/src/dsql/AggNodes.cpp 2012-05-04 07:07:08 UTC (rev 54447) +++ firebird/trunk/src/dsql/AggNodes.cpp 2012-05-04 15:32:49 UTC (rev 54448) @@ -106,10 +106,7 @@ AutoSetRestore<bool> autoIgnoreSubSelects(&visitor.ignoreSubSelects, true); for (NodeRef** i = dsqlChildNodes.begin(); i != dsqlChildNodes.end(); ++i) - { - if (*i) - visitor.visit((*i)->getExpr()); - } + visitor.visit((*i)->getExpr()); localDeepestLevel = visitor.deepestLevel; } @@ -138,7 +135,7 @@ AutoSetRestore<USHORT> autoDeepestLevel(&visitor.deepestLevel, localDeepestLevel); for (NodeRef** i = dsqlChildNodes.begin(); i != dsqlChildNodes.end(); ++i) - aggregate |= *i && visitor.visit((*i)->getExpr()); + aggregate |= visitor.visit((*i)->getExpr()); } return aggregate; @@ -153,7 +150,7 @@ FieldFinder fieldFinder(visitor.checkScopeLevel, visitor.matchType); for (NodeRef** i = dsqlChildNodes.begin(); i != dsqlChildNodes.end(); ++i) - found |= *i && visitor.visit((*i)->getExpr()); + found |= visitor.visit((*i)->getExpr()); if (!fieldFinder.getField()) { @@ -202,7 +199,7 @@ // an higher one then it's a invalid aggregate, because // aggregate-functions from the same context can't // be part of each other. - if (*i && Aggregate2Finder::find(visitor.context->ctx_scope_level, + if (Aggregate2Finder::find(visitor.context->ctx_scope_level, FIELD_MATCH_TYPE_EQUAL, false, (*i)->getExpr())) { // Nested aggregate functions are not allowed @@ -236,10 +233,7 @@ } for (NodeRef** i = dsqlChildNodes.begin(); i != dsqlChildNodes.end(); ++i) - { - if (*i) - (*i)->remap(visitor); - } + (*i)->remap(visitor); return this; } @@ -276,7 +270,7 @@ for (NodeRef** i = dsqlChildNodes.begin(); i != dsqlChildNodes.end(); ++i) { - if (*i && (*i)->getExpr()) + if (**i) ++count; } @@ -285,7 +279,7 @@ for (NodeRef** i = dsqlChildNodes.begin(); i != dsqlChildNodes.end(); ++i) { - if (*i) + if (**i) GEN_expr(dsqlScratch, (*i)->getExpr()); } } Modified: firebird/trunk/src/dsql/DdlNodes.epp =================================================================== --- firebird/trunk/src/dsql/DdlNodes.epp 2012-05-04 07:07:08 UTC (rev 54447) +++ firebird/trunk/src/dsql/DdlNodes.epp 2012-05-04 15:32:49 UTC (rev 54448) @@ -8294,7 +8294,7 @@ for (NodeRef** i = input->dsqlChildNodes.begin(); i != input->dsqlChildNodes.end(); ++i) { - if (*i && (*i)->getExpr()) + if (**i) temp.add((*i)->getExpr()); } Modified: firebird/trunk/src/dsql/ExprNodes.cpp =================================================================== --- firebird/trunk/src/dsql/ExprNodes.cpp 2012-05-04 07:07:08 UTC (rev 54447) +++ firebird/trunk/src/dsql/ExprNodes.cpp 2012-05-04 15:32:49 UTC (rev 54448) @@ -125,7 +125,7 @@ for (const NodeRef* const* i = dsqlChildNodes.begin(); i != dsqlChildNodes.end(); ++i, ++j) { - if (!*i != !*j || !PASS1_node_match((*i)->getExpr(), (*j)->getExpr(), ignoreMapCast)) + if (!**i != !**j || !PASS1_node_match((*i)->getExpr(), (*j)->getExpr(), ignoreMapCast)) return false; } @@ -7287,7 +7287,7 @@ { Array<NodeRef*>& exprChildren = aggExpr->dsqlChildNodes; for (NodeRef** i = exprChildren.begin(); i != exprChildren.end(); ++i) - aggregate |= *i && visitor.visit((*i)->getExpr()); + aggregate |= visitor.visit((*i)->getExpr()); } else aggregate |= visitor.visit(aggExpr); @@ -7369,7 +7369,7 @@ for (NodeRef** i = exprChildren.begin(); i != exprChildren.end(); ++i) { - if (*i && Aggregate2Finder::find(visitor.context->ctx_scope_level, FIELD_MATCH_TYPE_EQUAL, + if (Aggregate2Finder::find(visitor.context->ctx_scope_level, FIELD_MATCH_TYPE_EQUAL, true, (*i)->getExpr())) { ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << @@ -7391,10 +7391,7 @@ Array<NodeRef*>& exprChildren = aggNode->dsqlChildNodes; for (NodeRef** i = exprChildren.begin(); i != exprChildren.end(); ++i) - { - if (*i) - (*i)->remap(visitor); - } + (*i)->remap(visitor); } if (partition) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2012-05-20 19:28:59
|
Revision: 54517 http://firebird.svn.sourceforge.net/firebird/?rev=54517&view=rev Author: asfernandes Date: 2012-05-20 19:28:52 +0000 (Sun, 20 May 2012) Log Message: ----------- Fixed problems with views WITH CHECK OPTION. Also change its triggers as asked for opinions in fb-devel. Modified Paths: -------------- firebird/trunk/src/dsql/DdlNodes.epp firebird/trunk/src/dsql/DdlNodes.h firebird/trunk/src/dsql/ExprNodes.cpp firebird/trunk/src/dsql/dsql.h Modified: firebird/trunk/src/dsql/DdlNodes.epp =================================================================== --- firebird/trunk/src/dsql/DdlNodes.epp 2012-05-20 10:00:52 UTC (rev 54516) +++ firebird/trunk/src/dsql/DdlNodes.epp 2012-05-20 19:28:52 UTC (rev 54517) @@ -7960,23 +7960,11 @@ Arg::Gds(isc_col_name_err)); } - RecordSourceNode* querySpecNod = selectExpr->querySpec; - -#if 0 //// FIXME: - if (querySpecNod->nod_type == Dsql::nod_list) - { - // Only one table allowed for VIEW WITH CHECK OPTION - status_exception::raise( - Arg::Gds(isc_sqlerr) << Arg::Num(-607) << - Arg::Gds(isc_dsql_command_err) << - Arg::Gds(isc_table_view_err)); - } -#endif - - RseNode* querySpec = ExprNode::as<RseNode>(querySpecNod); + RseNode* querySpec = selectExpr->querySpec->as<RseNode>(); fb_assert(querySpec); - if (querySpec->dsqlFrom->items.getCount() != 1) + if (querySpec->dsqlFrom->items.getCount() != 1 || + !querySpec->dsqlFrom->items[0]->is<ProcedureSourceNode>()) { // Only one table allowed for VIEW WITH CHECK OPTION status_exception::raise( @@ -8003,7 +7991,7 @@ Arg::Gds(isc_distinct_err)); } - createCheckTriggers(tdbb, dsqlScratch, items); + createCheckTrigger(tdbb, dsqlScratch, items); } DDL_reset_context_stack(dsqlScratch); @@ -8017,46 +8005,21 @@ MET_dsql_cache_release(tdbb, SYM_relation, name); } -// Generate triggers to implement the WITH CHECK OPTION clause for a VIEW. -void CreateAlterViewNode::createCheckTriggers(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, +// Generate a trigger to implement the WITH CHECK OPTION clause for a VIEW. +void CreateAlterViewNode::createCheckTrigger(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, ValueListNode* items) { MemoryPool& pool = *tdbb->getDefaultPool(); // Specify that the trigger should abort if the condition is not met. - CompoundStmtNode* actionNode = FB_NEW(pool) CompoundStmtNode(pool); - ExceptionNode* exceptionNode = FB_NEW(pool) ExceptionNode(pool, CHECK_CONSTRAINT_EXCEPTION); exceptionNode->exception->type = ExceptionItem::GDS_CODE; - actionNode->statements.add(exceptionNode); + // Create the trigger - PRE_MODIFY_TRIGGER | PRE_STORE_TRIGGER. See parse.y/trigger_type_suffix. + TriggerType triggerType = TriggerType(((1 << 1) | (2 << 3)) - 1); - // Create the UPDATE trigger. - - BoolExprNode* baseAndNode = NULL; - RelationSourceNode* baseRelation = NULL; - defineUpdateAction(dsqlScratch, &baseAndNode, &baseRelation, items); - fb_assert(baseAndNode); - fb_assert(baseRelation); - - RseNode* rse = FB_NEW(pool) RseNode(pool); - rse->dsqlWhere = baseAndNode; - rse->dsqlStreams = FB_NEW(pool) RecSourceListNode(pool, 1); - rse->dsqlStreams->items[0] = baseRelation; - - createCheckTrigger(tdbb, dsqlScratch, rse, items, actionNode, PRE_MODIFY_TRIGGER); - createCheckTrigger(tdbb, dsqlScratch, NULL, items, actionNode, PRE_STORE_TRIGGER); -} - -// Define a trigger for a VIEW WITH CHECK OPTION. -void CreateAlterViewNode::createCheckTrigger(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, - RseNode* rse, ValueListNode* items, CompoundStmtNode* actions, TriggerType triggerType) -{ - MemoryPool& pool = *tdbb->getDefaultPool(); - AutoSetRestore<bool> autoCheckConstraintTrigger(&dsqlScratch->checkConstraintTrigger, true); - RecordSourceNode* querySpecNod = selectExpr->querySpec; RelationSourceNode* relationNode = dsqlNode; // Generate the trigger blr. @@ -8067,83 +8030,84 @@ dsqlScratch->appendUChar(blr_begin); - // Create the "OLD" and "NEW" contexts for the trigger -- the new one could be a dummy place - // holder to avoid resolving fields to that context but prevent relations referenced in - // the trigger actions from referencing the predefined "1" context. + DDL_reset_context_stack(dsqlScratch); - dsql_ctx* savContext = NULL; - dsql_ctx* context = NULL; + ++dsqlScratch->contextNumber; // OLD context - if (dsqlScratch->contextNumber) - { - // If an alias is specified for the single base table involved, - // save and then add the context. + RseNode* querySpec = selectExpr->querySpec->as<RseNode>(); + fb_assert(querySpec); - context = dsqlScratch->context->object(); + // ASF: We'll now map the view's base table into the trigger's NEW context. - if (context->ctx_alias.hasData()) - { - savContext = FB_NEW(pool) dsql_ctx(pool); - *savContext = *context; - } - } + dsql_ctx* newContext; - DDL_reset_context_stack(dsqlScratch); + { /// scope + ProcedureSourceNode* sourceNode = querySpec->dsqlFrom->items[0]->as<ProcedureSourceNode>(); + AutoSetRestore<string> autoAlias(&relationNode->alias, sourceNode->alias); - string tempAlias = relationNode->alias; + if (relationNode->alias.isEmpty()) + relationNode->alias = sourceNode->dsqlName.identifier.c_str(); - relationNode->alias = OLD_CONTEXT; - dsql_ctx* oldContext = PASS1_make_context(dsqlScratch, relationNode); - oldContext->ctx_flags |= CTX_system; + newContext = PASS1_make_context(dsqlScratch, relationNode); + newContext->ctx_flags |= CTX_system | CTX_view_with_check; + } - relationNode->alias = NEW_CONTEXT; - dsql_ctx* newContext = PASS1_make_context(dsqlScratch, relationNode); - newContext->ctx_flags |= CTX_system; + // Replace the view's field names by the base table field names. Save the original names + // to restore after the condition processing. - relationNode->alias = tempAlias; + dsql_fld* field = newContext->ctx_relation->rel_fields; + ObjectsArray<string> savedNames; - if (savContext) + // ASF: rel_fields entries are in reverse order. + for (NestConst<ValueExprNode>* ptr = items->items.end(); + ptr-- != items->items.begin(); + field = field->fld_next) { - savContext->ctx_context = dsqlScratch->contextNumber++; - context->ctx_scope_level = dsqlScratch->scopeLevel; - dsqlScratch->context->push(savContext); - } + ValueExprNode* valueNode = *ptr; + DsqlAliasNode* aliasNode; - // Generate the condition for firing the trigger. + if ((aliasNode = valueNode->as<DsqlAliasNode>())) + valueNode = aliasNode->value; - RseNode* querySpec = querySpecNod->as<RseNode>(); - fb_assert(querySpec); + FieldNode* fieldNode = valueNode->as<FieldNode>(); + fb_assert(fieldNode); - if (triggerType == PRE_MODIFY_TRIGGER) - { - dsqlScratch->appendUChar(blr_for); + savedNames.add(field->fld_name); - rse->dsqlStreams->items[0] = doDsqlPass(dsqlScratch, rse->dsqlStreams->items[0]); - rse->dsqlWhere = doDsqlPass(dsqlScratch, rse->dsqlWhere); + dsql_fld* queryField = fieldNode->dsqlField; - GEN_expr(dsqlScratch, rse); - - replaceFieldNames(querySpec->dsqlWhere.getObject(), items, viewFields, false, NEW_CONTEXT); + field->fld_name = queryField->fld_name; + field->fld_dtype = queryField->fld_dtype; + field->fld_scale = queryField->fld_scale; + field->fld_sub_type = queryField->fld_sub_type; + field->fld_length = queryField->fld_length; + field->fld_flags = queryField->fld_flags; + field->fld_character_set_id = queryField->fld_character_set_id; + field->fld_collation_id = queryField->fld_collation_id; } - else if (triggerType == PRE_STORE_TRIGGER) - replaceFieldNames(querySpec->dsqlWhere.getObject(), items, viewFields, true, NEW_CONTEXT); - else - fb_assert(false); - NestConst<BoolExprNode> condition = querySpec->dsqlWhere; - dsqlScratch->appendUChar(blr_if); - GEN_expr(dsqlScratch, doDsqlPass(dsqlScratch, condition)); - dsqlScratch->appendUChar(blr_begin); - dsqlScratch->appendUChar(blr_end); - // Generate the action statements for the trigger. + // Process the condition for firing the trigger. + NestConst<BoolExprNode> condition = doDsqlPass(dsqlScratch, querySpec->dsqlWhere); - NestConst<StmtNode>* ptr = actions->statements.begin(); + // Restore the field names. This must happen before the condition's BLR generation. - for (const NestConst<StmtNode>* const end = actions->statements.end(); ptr != end; ++ptr) - (*ptr)->dsqlPass(dsqlScratch)->genBlr(dsqlScratch); + field = newContext->ctx_relation->rel_fields; + for (ObjectsArray<string>::iterator i = savedNames.begin(); i != savedNames.end(); ++i) + { + field->fld_name = *i; + field = field->fld_next; + } + + GEN_expr(dsqlScratch, condition); + dsqlScratch->appendUChar(blr_begin); + dsqlScratch->appendUChar(blr_end); + + // Generate the action statement for the trigger. + exceptionNode->dsqlPass(dsqlScratch)->genBlr(dsqlScratch); + dsqlScratch->appendUChar(blr_end); // of begin dsqlScratch->appendUChar(blr_eoc); @@ -8157,212 +8121,7 @@ trigger.store(tdbb, dsqlScratch, dsqlScratch->getTransaction()); } -// Define an action statement which, given a view definition, will map an update to a record from -// a view of a single relation into the base relation. -void CreateAlterViewNode::defineUpdateAction(DsqlCompilerScratch* dsqlScratch, - BoolExprNode** baseAndNode, RelationSourceNode** baseRelation, ValueListNode* items) -{ - thread_db* tdbb = JRD_get_thread_data(); - MemoryPool& pool = *tdbb->getDefaultPool(); - // Check whether this is an updatable view definition. - - RseNode* querySpec = selectExpr->querySpec->as<RseNode>(); - RecSourceListNode* fromList = NULL; - - if (!querySpec || !(fromList = querySpec->dsqlFrom) || fromList->items.getCount() != 1) - { - // The caller seems throwing proper errors for all the above conditions. - // But just in case it doesn't, here we have the final attempt to prevent the bad things. - fb_assert(false); - } - - // Use the relation referenced in the select statement for rse. - - RelationSourceNode* relationNode = FB_NEW(pool) RelationSourceNode(pool, - fromList->items[0]->as<ProcedureSourceNode>()->dsqlName.identifier); - relationNode->alias = TEMP_CONTEXT; - - *baseRelation = relationNode; - - // Get the list of values and fields to compare to -- if there is no list of fields, get all - // fields in the base relation that are not computed. - - ValueListNode* valuesNode = viewFields; - ValueListNode* fieldsNode = querySpec->dsqlSelectList; - - if (!fieldsNode) - { - const dsql_rel* relation = METD_get_relation(dsqlScratch->getTransaction(), - dsqlScratch, name); - fieldsNode = FB_NEW(pool) ValueListNode(pool, 0u); - - for (const dsql_fld* field = relation->rel_fields; field; field = field->fld_next) - { - if (!(field->fld_flags & FLD_computed)) - fieldsNode->add(MAKE_field_name(field->fld_name.c_str())); - } - } - - if (!valuesNode) - valuesNode = fieldsNode; - - // Generate the list of assignments to fields in the base relation. - - NestConst<ValueExprNode>* ptr = fieldsNode->items.begin(); - const NestConst<ValueExprNode>* const end = fieldsNode->items.end(); - NestConst<ValueExprNode>* ptr2 = valuesNode->items.begin(); - const NestConst<ValueExprNode>* const end2 = valuesNode->items.end(); - int andArg = 0; - - BinaryBoolNode* andNode = FB_NEW(pool) BinaryBoolNode(pool, blr_and); - - for (; (ptr < end) && (ptr2 < end2); ptr++, ptr2++) - { - ValueExprNode* fieldNod = *ptr; - DsqlAliasNode* aliasNode; - - if ((aliasNode = ExprNode::as<DsqlAliasNode>(fieldNod))) - fieldNod = aliasNode->value; - - FieldNode* fieldNode = ExprNode::as<FieldNode>(fieldNod); - - // Generate the actual comparisons. - - if (fieldNode) - { - fieldNode->dsqlQualifier = TEMP_CONTEXT; - - FieldNode* oldValueNode = FB_NEW(pool) FieldNode(pool); - oldValueNode->dsqlName = (*ptr2)->as<FieldNode>()->dsqlName; - oldValueNode->dsqlQualifier = OLD_CONTEXT; - - ComparativeBoolNode* eqlNode = FB_NEW(pool) ComparativeBoolNode(pool, - blr_eql, oldValueNode, fieldNod); - - BinaryBoolNode* andNode2 = FB_NEW(pool) BinaryBoolNode(pool, blr_and, - FB_NEW(pool) MissingBoolNode(pool, oldValueNode), - FB_NEW(pool) MissingBoolNode(pool, fieldNod)); - - BinaryBoolNode* orNode = FB_NEW(pool) BinaryBoolNode(pool, blr_or, eqlNode, andNode2); - - if (andArg == 0) - { - ++andArg; - andNode->arg1 = orNode; - } - else if (andArg == 1) - { - ++andArg; - andNode->arg2 = orNode; - } - else - andNode = FB_NEW(pool) BinaryBoolNode(pool, blr_and, andNode, orNode); - } - } - - if (andArg == 0) - { - andNode->arg1 = querySpec->dsqlWhere; - replaceFieldNames(andNode->arg1.getObject(), items, NULL, false, TEMP_CONTEXT); - } - else if (andArg == 1) - { - andNode->arg2 = querySpec->dsqlWhere; - replaceFieldNames(andNode->arg2.getObject(), items, NULL, false, TEMP_CONTEXT); - } - else - { - replaceFieldNames(querySpec->dsqlWhere.getObject(), items, NULL, false, TEMP_CONTEXT); - andNode = FB_NEW(pool) BinaryBoolNode(pool, blr_and, andNode, querySpec->dsqlWhere); - } - - *baseAndNode = andNode; -} - -// Given an input node tree, find any field name nodes and replace them according to the mapping -// provided. This is used to create view WITH CHECK OPTION. -void CreateAlterViewNode::replaceFieldNames(ExprNode* input, ValueListNode* searchFields, - ValueListNode* replaceFields, bool nullThem, const char* contextName) -{ - thread_db* tdbb = JRD_get_thread_data(); - - if (!input) - return; - - Array<ExprNode*> temp; - - for (NodeRef** i = input->dsqlChildNodes.begin(); i != input->dsqlChildNodes.end(); ++i) - { - if (**i) - temp.add((*i)->getExpr()); - } - - for (ExprNode** ptr = temp.begin(); ptr != temp.end(); ++ptr) - { - ExprNode*& ptrNode = *ptr; - - if (!ptrNode) - continue; - - if (ptrNode->as<SelectExprNode>()) - { - // No subqueries permitted for VIEW WITH CHECK OPTION - status_exception::raise( - Arg::Gds(isc_sqlerr) << Arg::Num(-607) << - Arg::Gds(isc_dsql_command_err) << - Arg::Gds(isc_subquery_err)); - } - - FieldNode* fieldNode = ptrNode->as<FieldNode>(); - - if (fieldNode) - { - // Found a field node, check if it needs to be replaced. - - NestConst<ValueExprNode>* search = searchFields->items.begin(); - const NestConst<ValueExprNode>* const end = searchFields->items.end(); - NestConst<ValueExprNode>* replace = NULL; - - if (replaceFields) - replace = replaceFields->items.begin(); - - bool found = false; - - for (; search < end; ++search, replace += (replaceFields ? 1 : 0)) - { - FieldNode* replaceField = replace ? (*replace)->as<FieldNode>() : NULL; - - MetaName replaceName(replaceFields ? replaceField->dsqlName : ""); - - const dsql_fld* field = (*search)->as<FieldNode>()->dsqlField; - - if (field->fld_name == fieldNode->dsqlName.c_str()) - { - found = true; - - if (replaceFields) - fieldNode->dsqlName = replaceField->dsqlName; - - fieldNode->dsqlQualifier = contextName; - } - - if (nullThem && replaceFields && fieldNode->dsqlName == replaceName) - found = true; - } - - if (nullThem && !found) - ptrNode = FB_NEW(*tdbb->getDefaultPool()) NullNode(*tdbb->getDefaultPool()); - } - else - { - // Recursively go through the input tree looking for field name nodes. - replaceFieldNames(ptrNode, searchFields, replaceFields, nullThem, contextName); - } - } -} - - //---------------------- Modified: firebird/trunk/src/dsql/DdlNodes.h =================================================================== --- firebird/trunk/src/dsql/DdlNodes.h 2012-05-20 10:00:52 UTC (rev 54516) +++ firebird/trunk/src/dsql/DdlNodes.h 2012-05-20 19:28:52 UTC (rev 54517) @@ -1447,13 +1447,7 @@ } private: - void createCheckTriggers(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, ValueListNode* items); - void createCheckTrigger(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, - RseNode* rse, ValueListNode* items, CompoundStmtNode* actions, TriggerType triggerType); - void defineUpdateAction(DsqlCompilerScratch* dsqlScratch, BoolExprNode** baseAndNode, - RelationSourceNode** baseRelation, ValueListNode* items); - static void replaceFieldNames(ExprNode* input, ValueListNode* searchFields, - ValueListNode* replaceFields, bool nullThem, const char* contextName); + void createCheckTrigger(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, ValueListNode* items); public: bool create; Modified: firebird/trunk/src/dsql/ExprNodes.cpp =================================================================== --- firebird/trunk/src/dsql/ExprNodes.cpp 2012-05-20 10:00:52 UTC (rev 54516) +++ firebird/trunk/src/dsql/ExprNodes.cpp 2012-05-20 19:28:52 UTC (rev 54517) @@ -4991,16 +4991,21 @@ } } - if (dsqlQualifier.hasData() && !field) + if ((context->ctx_flags & CTX_view_with_check) && !field) { + node = FB_NEW(*tdbb->getDefaultPool()) NullNode(*tdbb->getDefaultPool()); + node->line = line; + node->column = column; + } + else if (dsqlQualifier.hasData() && !field) + { // If a qualifier was present and we didn't find // a matching field then we should stop searching. // Column unknown error will be raised at bottom of function. done = true; break; } - - if (field || usingField) + else if (field || usingField) { // Intercept any reference to a field with datatype that // did not exist prior to V6 and post an error @@ -9512,7 +9517,7 @@ dsqlScratch->appendUChar(blr_literal); dsqlScratch->appendUChar(blr_long); dsqlScratch->appendUChar(0); - dsqlScratch->appendUShort(LONG_POS_MAX & 0xffff); // avoid warning + dsqlScratch->appendUShort(LONG_POS_MAX & 0xFFFF); dsqlScratch->appendUShort(LONG_POS_MAX >> 16); } } Modified: firebird/trunk/src/dsql/dsql.h =================================================================== --- firebird/trunk/src/dsql/dsql.h 2012-05-20 10:00:52 UTC (rev 54516) +++ firebird/trunk/src/dsql/dsql.h 2012-05-20 19:28:52 UTC (rev 54517) @@ -62,9 +62,8 @@ #include "../jrd/EngineInterface.h" // Context aliases used in triggers -const char* const OLD_CONTEXT = "OLD"; -const char* const NEW_CONTEXT = "NEW"; -const char* const TEMP_CONTEXT = "TEMP"; +const char* const OLD_CONTEXT = "OLD"; +const char* const NEW_CONTEXT = "NEW"; namespace Jrd { @@ -745,11 +744,12 @@ // Flag values for ctx_flags -const USHORT CTX_outer_join = 0x01; // reference is part of an outer join -const USHORT CTX_system = 0x02; // Context generated by system (NEW/OLD in triggers, check-constraint, RETURNING) -const USHORT CTX_null = 0x04; // Fields of the context should be resolved to NULL constant -const USHORT CTX_returning = 0x08; // Context generated by RETURNING -const USHORT CTX_recursive = 0x10; // Context has secondary number (ctx_recursive) generated for recursive UNION +const USHORT CTX_outer_join = 0x01; // reference is part of an outer join +const USHORT CTX_system = 0x02; // Context generated by system (NEW/OLD in triggers, check-constraint, RETURNING) +const USHORT CTX_null = 0x04; // Fields of the context should be resolved to NULL constant +const USHORT CTX_returning = 0x08; // Context generated by RETURNING +const USHORT CTX_recursive = 0x10; // Context has secondary number (ctx_recursive) generated for recursive UNION +const USHORT CTX_view_with_check = 0x20; // Context of WITH CHECK OPTION view's triggers //! Aggregate/union map block to map virtual fields to their base //! TMN: NOTE! This datatype should definitely be renamed! This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2012-07-20 02:42:04
|
Revision: 54733 http://firebird.svn.sourceforge.net/firebird/?rev=54733&view=rev Author: asfernandes Date: 2012-07-20 02:41:58 +0000 (Fri, 20 Jul 2012) Log Message: ----------- Fixed CORE-3893 - Cannot restore tpcc database in FB 3.0. Modified Paths: -------------- firebird/trunk/src/dsql/BlrWriter.cpp firebird/trunk/src/dsql/BlrWriter.h firebird/trunk/src/dsql/DdlNodes.h firebird/trunk/src/dsql/DsqlCompilerScratch.h firebird/trunk/src/dsql/StmtNodes.cpp firebird/trunk/src/dsql/ddl.cpp firebird/trunk/src/dsql/dsql.cpp firebird/trunk/src/dsql/dsql.h Modified: firebird/trunk/src/dsql/BlrWriter.cpp =================================================================== --- firebird/trunk/src/dsql/BlrWriter.cpp 2012-07-19 07:49:24 UTC (rev 54732) +++ firebird/trunk/src/dsql/BlrWriter.cpp 2012-07-20 02:41:58 UTC (rev 54733) @@ -137,11 +137,6 @@ debugData.add(col >> 8); ULONG offset = (blrData.getCount() - baseOffset); - - // for DDL statements we store BLR's length at the first 2 bytes - if (isDdlDyn()) - offset -= 2; - debugData.add(offset); debugData.add(offset >> 8); } Modified: firebird/trunk/src/dsql/BlrWriter.h =================================================================== --- firebird/trunk/src/dsql/BlrWriter.h 2012-07-19 07:49:24 UTC (rev 54732) +++ firebird/trunk/src/dsql/BlrWriter.h 2012-07-20 02:41:58 UTC (rev 54733) @@ -141,9 +141,6 @@ virtual bool isVersion4() = 0; -protected: - virtual bool isDdlDyn() = 0; - private: BlrData blrData; DebugData debugData; Modified: firebird/trunk/src/dsql/DdlNodes.h =================================================================== --- firebird/trunk/src/dsql/DdlNodes.h 2012-07-19 07:49:24 UTC (rev 54732) +++ firebird/trunk/src/dsql/DdlNodes.h 2012-07-20 02:41:58 UTC (rev 54733) @@ -1072,12 +1072,6 @@ return dsqlScratch->isVersion4(); } - protected: - virtual bool isDdlDyn() - { - return false; - } - private: DsqlCompilerScratch* dsqlScratch; }; Modified: firebird/trunk/src/dsql/DsqlCompilerScratch.h =================================================================== --- firebird/trunk/src/dsql/DsqlCompilerScratch.h 2012-07-19 07:49:24 UTC (rev 54732) +++ firebird/trunk/src/dsql/DsqlCompilerScratch.h 2012-07-20 02:41:58 UTC (rev 54733) @@ -62,6 +62,7 @@ static const unsigned FLAG_SUB_ROUTINE = 0x0400; static const unsigned FLAG_INTERNAL_REQUEST = 0x0800; static const unsigned FLAG_AMBIGUOUS_STMT = 0x1000; + static const unsigned FLAG_DDL = 0x2000; public: DsqlCompilerScratch(MemoryPool& p, dsql_dbb* aDbb, jrd_tra* aTransaction, @@ -122,11 +123,6 @@ { } - virtual bool isDdlDyn() - { - return statement->isDdl() && !(flags & FLAG_BLOCK); - } - public: virtual bool isVersion4() { Modified: firebird/trunk/src/dsql/StmtNodes.cpp =================================================================== --- firebird/trunk/src/dsql/StmtNodes.cpp 2012-07-19 07:49:24 UTC (rev 54732) +++ firebird/trunk/src/dsql/StmtNodes.cpp 2012-07-20 02:41:58 UTC (rev 54733) @@ -1388,6 +1388,7 @@ dsqlScratch->getAttachment(), dsqlScratch->getTransaction(), statement); blockScratch->clientDialect = dsqlScratch->clientDialect; blockScratch->flags |= DsqlCompilerScratch::FLAG_FUNCTION | DsqlCompilerScratch::FLAG_SUB_ROUTINE; + blockScratch->flags |= dsqlScratch->flags & DsqlCompilerScratch::FLAG_DDL; dsqlBlock = dsqlBlock->dsqlPass(blockScratch); @@ -1643,6 +1644,7 @@ dsqlScratch->getAttachment(), dsqlScratch->getTransaction(), statement); blockScratch->clientDialect = dsqlScratch->clientDialect; blockScratch->flags |= DsqlCompilerScratch::FLAG_PROCEDURE | DsqlCompilerScratch::FLAG_SUB_ROUTINE; + blockScratch->flags |= dsqlScratch->flags & DsqlCompilerScratch::FLAG_DDL; dsqlBlock = dsqlBlock->dsqlPass(blockScratch); Modified: firebird/trunk/src/dsql/ddl.cpp =================================================================== --- firebird/trunk/src/dsql/ddl.cpp 2012-07-19 07:49:24 UTC (rev 54732) +++ firebird/trunk/src/dsql/ddl.cpp 2012-07-20 02:41:58 UTC (rev 54733) @@ -121,7 +121,7 @@ // Determine whether ids or names should be referenced when generating blr for fields and relations. bool DDL_ids(const DsqlCompilerScratch* scratch) { - return !scratch->getStatement()->isDdl(); + return !(scratch->flags & DsqlCompilerScratch::FLAG_DDL); } @@ -328,13 +328,8 @@ const dsql_str* dfl_charset = NULL; - if (dsqlScratch->getStatement()->isDdl() || - (dsqlScratch->flags & ( - DsqlCompilerScratch::FLAG_FUNCTION | DsqlCompilerScratch::FLAG_PROCEDURE | - DsqlCompilerScratch::FLAG_TRIGGER))) - { + if (dsqlScratch->flags & DsqlCompilerScratch::FLAG_DDL) dfl_charset = METD_get_default_charset(dsqlScratch->getTransaction()); - } else { USHORT charSet = dsqlScratch->getAttachment()->dbb_attachment->att_charset; Modified: firebird/trunk/src/dsql/dsql.cpp =================================================================== --- firebird/trunk/src/dsql/dsql.cpp 2012-07-19 07:49:24 UTC (rev 54732) +++ firebird/trunk/src/dsql/dsql.cpp 2012-07-20 02:41:58 UTC (rev 54733) @@ -939,6 +939,8 @@ { internalScratch = scratch; + scratch->flags |= DsqlCompilerScratch::FLAG_DDL; + node = Node::doDsqlPass(scratch, node); if (scratch->getAttachment()->dbb_read_only) Modified: firebird/trunk/src/dsql/dsql.h =================================================================== --- firebird/trunk/src/dsql/dsql.h 2012-07-19 07:49:24 UTC (rev 54732) +++ firebird/trunk/src/dsql/dsql.h 2012-07-20 02:41:58 UTC (rev 54733) @@ -458,11 +458,6 @@ const Firebird::RefStrPtr& getSqlText() const { return sqlText; } void setSqlText(Firebird::RefString* value) { sqlText = value; } - bool isDdl() const - { - return type == TYPE_DDL || type == TYPE_CREATE_DB; - } - dsql_msg* getSendMsg() { return sendMsg; } const dsql_msg* getSendMsg() const { return sendMsg; } void setSendMsg(dsql_msg* value) { sendMsg = value; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <di...@us...> - 2012-11-17 15:31:27
|
Revision: 57363 http://firebird.svn.sourceforge.net/firebird/?rev=57363&view=rev Author: dimitr Date: 2012-11-17 15:31:21 +0000 (Sat, 17 Nov 2012) Log Message: ----------- Fixed CORE-3979: Server crashes while unwinding changes in an autonomous transaction. Modified Paths: -------------- firebird/trunk/src/dsql/StmtNodes.cpp firebird/trunk/src/dsql/StmtNodes.h Modified: firebird/trunk/src/dsql/StmtNodes.cpp =================================================================== --- firebird/trunk/src/dsql/StmtNodes.cpp 2012-11-17 15:17:15 UTC (rev 57362) +++ firebird/trunk/src/dsql/StmtNodes.cpp 2012-11-17 15:31:21 UTC (rev 57363) @@ -3401,33 +3401,40 @@ InAutonomousTransactionNode* InAutonomousTransactionNode::pass2(thread_db* tdbb, CompilerScratch* csb) { - savNumberOffset = CMP_impure(csb, sizeof(SLONG)); + impureOffset = CMP_impure(csb, sizeof(Impure)); doPass2(tdbb, csb, action.getAddress(), this); return this; } const StmtNode* InAutonomousTransactionNode::execute(thread_db* tdbb, jrd_req* request, ExeState* /*exeState*/) const { - Jrd::Attachment* attachment = request->req_attachment; - SLONG* savNumber = request->getImpure<SLONG>(savNumberOffset); + Database* const dbb = tdbb->getDatabase(); + Jrd::Attachment* const attachment = tdbb->getAttachment(); + + Impure* const impure = request->getImpure<Impure>(impureOffset); if (request->req_operation == jrd_req::req_evaluate) { - fb_assert(tdbb->getTransaction() == request->req_transaction); + jrd_tra* const org_transaction = request->req_transaction; + fb_assert(tdbb->getTransaction() == org_transaction); - request->req_auto_trans.push(request->req_transaction); - request->req_transaction = TRA_start(tdbb, request->req_transaction->tra_flags, - request->req_transaction->tra_lock_timeout, - request->req_transaction); - tdbb->setTransaction(request->req_transaction); + jrd_tra* const transaction = TRA_start(tdbb, org_transaction->tra_flags, + org_transaction->tra_lock_timeout, + org_transaction); - VIO_start_save_point(tdbb, request->req_transaction); - *savNumber = request->req_transaction->tra_save_point->sav_number; + TRA_attach_request(transaction, request); + tdbb->setTransaction(transaction); + request->req_auto_trans.push(org_transaction); + impure->traNumber = transaction->tra_number; + + VIO_start_save_point(tdbb, transaction); + impure->savNumber = transaction->tra_save_point->sav_number; + if (!(attachment->att_flags & ATT_no_db_triggers)) { // run ON TRANSACTION START triggers - EXE_execute_db_triggers(tdbb, request->req_transaction, jrd_req::req_trigger_trans_start); + EXE_execute_db_triggers(tdbb, transaction, jrd_req::req_trigger_trans_start); } return action; @@ -3436,6 +3443,11 @@ jrd_tra* transaction = request->req_transaction; fb_assert(transaction && transaction != attachment->getSysTransaction()); + if (!impure->traNumber) + return parentStmt; + + fb_assert(transaction->tra_number == impure->traNumber); + switch (request->req_operation) { case jrd_req::req_return: @@ -3502,10 +3514,8 @@ } catch (const Exception&) { - if (tdbb->getDatabase()->dbb_flags & DBB_bugcheck) - { + if (dbb->dbb_flags & DBB_bugcheck) throw; - } } } @@ -3516,7 +3526,7 @@ // undo all savepoints up to our one for (const Savepoint* save_point = transaction->tra_save_point; - save_point && *savNumber <= save_point->sav_number; + save_point && impure->savNumber <= save_point->sav_number; save_point = transaction->tra_save_point) { ++transaction->tra_save_point->sav_verb_count; @@ -3527,10 +3537,8 @@ } catch (const Exception&) { - if (tdbb->getDatabase()->dbb_flags & DBB_bugcheck) - { + if (dbb->dbb_flags & DBB_bugcheck) throw; - } } } break; @@ -3539,9 +3547,12 @@ fb_assert(false); } - request->req_transaction = request->req_auto_trans.pop(); - tdbb->setTransaction(request->req_transaction); + impure->traNumber = impure->savNumber = 0; + transaction = request->req_auto_trans.pop(); + TRA_attach_request(transaction, request); + tdbb->setTransaction(transaction); + return parentStmt; } Modified: firebird/trunk/src/dsql/StmtNodes.h =================================================================== --- firebird/trunk/src/dsql/StmtNodes.h 2012-11-17 15:17:15 UTC (rev 57362) +++ firebird/trunk/src/dsql/StmtNodes.h 2012-11-17 15:31:21 UTC (rev 57363) @@ -710,11 +710,17 @@ class InAutonomousTransactionNode : public TypedNode<StmtNode, StmtNode::TYPE_IN_AUTO_TRANS> { + struct Impure + { + TraNumber traNumber; + SLONG savNumber; + }; + public: explicit InAutonomousTransactionNode(MemoryPool& pool) : TypedNode<StmtNode, StmtNode::TYPE_IN_AUTO_TRANS>(pool), action(NULL), - savNumberOffset(0) + impureOffset(0) { } @@ -730,7 +736,7 @@ public: NestConst<StmtNode> action; - SLONG savNumberOffset; + SLONG impureOffset; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2012-12-05 14:31:43
|
Revision: 57450 http://firebird.svn.sourceforge.net/firebird/?rev=57450&view=rev Author: asfernandes Date: 2012-12-05 14:31:35 +0000 (Wed, 05 Dec 2012) Log Message: ----------- Get rid of g_field_name hack. Modified Paths: -------------- firebird/trunk/src/dsql/Parser.h firebird/trunk/src/dsql/parse.y Modified: firebird/trunk/src/dsql/Parser.h =================================================================== --- firebird/trunk/src/dsql/Parser.h 2012-12-05 04:06:14 UTC (rev 57449) +++ firebird/trunk/src/dsql/Parser.h 2012-12-05 14:31:35 UTC (rev 57450) @@ -79,7 +79,6 @@ { // This is, in fact, parser state. Not used in lexer itself dsql_fld* g_field; - FieldNode* g_field_name; int dsql_debug; // Actual lexer state begins from here Modified: firebird/trunk/src/dsql/parse.y =================================================================== --- firebird/trunk/src/dsql/parse.y 2012-12-05 04:06:14 UTC (rev 57449) +++ firebird/trunk/src/dsql/parse.y 2012-12-05 14:31:35 UTC (rev 57450) @@ -1776,7 +1776,6 @@ column_def_name : simple_column_name { - lex.g_field_name = $1; lex.g_field = make_field ($1); $$ = lex.g_field; } @@ -1873,7 +1872,7 @@ RelationNode::AddConstraintClause& constraint = $addColumnClause->constraints.add(); constraint.constraintType = RelationNode::AddConstraintClause::CTYPE_FK; - constraint.columns.add(lex.g_field_name->dsqlName); + constraint.columns.add($addColumnClause->field->fld_name); constraint.refRelation = toName($2); constraint.refAction = $4; @@ -3459,7 +3458,6 @@ alter_col_name : simple_column_name { - lex.g_field_name = $1; lex.g_field = make_field ($1); $$ = lex.g_field; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |