SQL query

English! place to talk about development, programming and coding
Post Reply
jj99
Znuny newbie
Posts: 36
Joined: 11 Apr 2013, 16:31
Znuny Version: 2.3.4
Company: Student

SQL query

Post by jj99 »

Hi I follow the OTRS developer manual for using sql queries inside the modules.

I run the following query but I only get first value from result.

Code: Select all

my $SQL = "SELECT id FROM roles ";

$Self->{DBObject}->Prepare(SQL => $SQL, Limit => 15);

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

if I check the size of @Row array I get one but in reality I have many roles created in roles table.

Can some one tell me whats missing ?
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: SQL query

Post by reneeb »

You have to fetch the roles in a loop:

Code: Select all

my $SQL = "SELECT id FROM roles ";

$Self->{DBObject}->Prepare(SQL => $SQL, Limit => 15);

my @RoleIDs;
while ( my @Row = $Self->{DBObject}->FetchrowArray() ) {
    push @RoleIDs, $Row[0];
}
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
jj99
Znuny newbie
Posts: 36
Joined: 11 Apr 2013, 16:31
Znuny Version: 2.3.4
Company: Student

Re: SQL query

Post by jj99 »

thank u . I realized my error. yes u are right.
Post Reply