4343#include " ../common/StatusArg.h"
4444#include " ../jrd/constants.h"
4545#include " ../common/utils_proto.h"
46+ #include < optional>
4647
4748using namespace Firebird ;
4849
@@ -163,18 +164,20 @@ void iscArrayLookupBoundsImpl(Why::YAttachment* attachment,
163164 name
164165 from system.rdb$sql.parse_unqualified_names(rdb$get_context('SYSTEM', 'SEARCH_PATH'))
165166 )
166- select fd.rdb$lower_bound,
167+ select cast(sp.rn as integer) rn,
168+ fd.rdb$lower_bound,
167169 fd.rdb$upper_bound
168170 from search_path sp
169171 join system.rdb$field_dimensions fd
170172 on fd.rdb$schema_name = sp.name
171173 where fd.rdb$field_name = ?
172- order by sp.rn
173- rows 1
174+ order by sp.rn,
175+ fd.rdb$dimension
174176 )""" ;
175177
176178 constexpr auto sqlNoSchemas = R"""(
177- select fd.rdb$lower_bound,
179+ select 0 rn,
180+ fd.rdb$lower_bound,
178181 fd.rdb$upper_bound
179182 from rdb$field_dimensions fd
180183 where fd.rdb$field_name = ?
@@ -189,6 +192,7 @@ void iscArrayLookupBoundsImpl(Why::YAttachment* attachment,
189192 inputMessage.clear ();
190193
191194 FB_MESSAGE (OutputMessage, CheckStatusWrapper,
195+ (FB_INTEGER, rn)
192196 (FB_INTEGER, lowerBound)
193197 (FB_INTEGER, upperBound)
194198 ) outputMessage (&statusWrapper, MasterInterfacePtr ());
@@ -201,8 +205,15 @@ void iscArrayLookupBoundsImpl(Why::YAttachment* attachment,
201205 outputMessage.getMetadata (), nullptr , 0 ));
202206 status.check ();
203207
208+ std::optional<SLONG> lastRn;
209+
204210 while (resultSet->fetchNext (&statusWrapper, outputMessage.getData ()) == IStatus::RESULT_OK)
205211 {
212+ if (lastRn.has_value () && lastRn.value () != outputMessage->rn )
213+ break ;
214+
215+ lastRn = outputMessage->rn ;
216+
206217 tail->array_bound_lower = outputMessage->lowerBoundNull ? 0 : outputMessage->lowerBound ;
207218 tail->array_bound_upper = outputMessage->upperBoundNull ? 0 : outputMessage->upperBound ;
208219 ++tail;
0 commit comments