DBObject Issue!

English! place to talk about development, programming and coding
Post Reply
artjoms15
Znuny advanced
Posts: 121
Joined: 30 Aug 2011, 10:48
Znuny Version: 3.3.8 && 4.0.9
Real Name: Artjoms Petrovs
Location: Latvia

DBObject Issue!

Post by artjoms15 »

Hello OTRS Developers. I found one issue, while playing with DBObject. It seems, that it is impossible to run another SQL statement or run any function, which operates with DBObject while fetching rows from a result, cause it causes the loop to break. Don' t know, maybe someone has solved this issue, or is it just a bareable defect of OTRS framework.
Hmm.. a small example follows:

Code: Select all

my $SQL   = "SELECT configitem.configitem_number, configitem.last_version_id FROM configitem where configitem.class_id = (select general_catalog.id from general_catalog where general_catalog.name = 'Access Rights (UserCard)')";

    $Self->{DBObject}->Prepare( SQL => $SQL );
	
    while ( my @Row = $Self->{DBObject}->FetchrowArray() ) {

       my $ConfigItem = $Self->{ConfigItemObject}->ConfigItemGet(
           ConfigItemID => $ConfigItemID,
       );

   }
The execution stops after the first row is looked through, although the SQL-result returns like xxx rows :(
if I replace ConfigItemGet with writing to log, then it loops all the entries in the result

Thanks in Advance!!!
Ar cieņu / Kind regards,
----------------------------------------
Artjoms Petrovs
Sistēmu analītiķis/Programmētājs /
Systems Analyst/Programmer
artjoms15
Znuny advanced
Posts: 121
Joined: 30 Aug 2011, 10:48
Znuny Version: 3.3.8 && 4.0.9
Real Name: Artjoms Petrovs
Location: Latvia

Re: DBObject Issue!

Post by artjoms15 »

Hmm, I' ve found a workaround, but a nasty one!

It is possible to create an array, that holds all the query results, and after that t is possible to parse the values of an array. (Possible problems: Out of memory issue with large datasets)

Code: Select all

while ( my @Row = $Self->{DBObject}->FetchrowArray() ) {
        $Counter++;
        my $Col1 = $Counter;
        my $Col2 = $Row[0];
        my $Col3 = $Row[1];
        
        push @Data, [
            $Col1,
            $Col2,
            $Col3,
        ];
}	
foreach my $Rrr (@Data) {
	my @Row = @$Rrr;
                #execute the code in here, considering that $Row is a result of a query
...
}
I will keep this solution for a moment, but I hope that someone could at least explain WHY the execution is stopping all the time,when another call is ade to a DBObject

Smile,
A.
Ar cieņu / Kind regards,
----------------------------------------
Artjoms Petrovs
Sistēmu analītiķis/Programmētājs /
Systems Analyst/Programmer
Post Reply