Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > DBI and fetchhasref

Reply
Thread Tools

DBI and fetchhasref

 
 
Peter.Kramer
Guest
Posts: n/a
 
      07-12-2005
hi there
I'm wondering why I cant get all resulst in my hasref in this statement:


--
select r.resourcesize, a.samaccountname

from aduser a
(
select * from resourcesize
where ts = (select max(ts) from resourcesize where server = 'xyz')
) r

where a.samaccountname = r.samaccountname(+)
----

What I get is an hasref and all data from table "a" and all fields of table
"r" but no data of table "r".
I assume, that the sub select is the problem.

result:
$hash->{SAMACCOUNTNAME} = "tiger"
$hash->{RESOURCESIZE} = ""

When I execute the script in SQL Plus all Data is availible!

$hash->{SAMACCOUNTNAME} = "tiger"
$hash->{RESOURCESIZE} = "1234"

I'm using Active State Perl 5.8.4 with DBD-Oracle and Oracle 9i


 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      07-12-2005
Peter.Kramer wrote:
> I'm wondering why I cant get all resulst in my hasref in this statement:


"Hashref". Not "hasref".

> --
> select r.resourcesize, a.samaccountname
>
> from aduser a
> (
> select * from resourcesize
> where ts = (select max(ts) from resourcesize where server = 'xyz')
> ) r
>
> where a.samaccountname = r.samaccountname(+)
> ----
>
> What I get is an hasref and all data from table "a" and all fields of table
> "r" but no data of table "r".
> I assume, that the sub select is the problem.
>
> result:
> $hash->{SAMACCOUNTNAME} = "tiger"
> $hash->{RESOURCESIZE} = ""
>
> When I execute the script in SQL Plus all Data is availible!
>
> $hash->{SAMACCOUNTNAME} = "tiger"
> $hash->{RESOURCESIZE} = "1234"
>
> I'm using Active State Perl 5.8.4 with DBD-Oracle and Oracle 9i


>From the lack of code posted, I gather you believe there is something

wrong with Perl and/or DBD-Oracle, rather than something wrong with
your code? That's mighty arrogant of you. You'll forgive me if I tend
not to believe you. Please post a short-but-complete script that
demonstrates the problem you're having. Have you seen the posting
guidelines for this newsgroup? Please read them, and follow at least 2
particulars:
Speak Perl, not English. (Show us, in Perl, what your variable
contains, don't try to tell us what you think it contains).
Post the aforementioned short-but-complete script.

Paul Lalli

 
Reply With Quote
 
 
 
 
Peter.Kramer
Guest
Posts: n/a
 
      07-13-2005

"Paul Lalli" <> schrieb im Newsbeitrag
news: oups.com...
> Peter.Kramer wrote:
>> I'm wondering why I cant get all resulst in my hasref in this statement:

>
> "Hashref". Not "hasref".
>
>> --
>> select r.resourcesize, a.samaccountname
>>
>> from aduser a
>> (
>> select * from resourcesize
>> where ts = (select max(ts) from resourcesize where server = 'xyz')
>> ) r
>>
>> where a.samaccountname = r.samaccountname(+)
>> ----
>>
>> What I get is an hasref and all data from table "a" and all fields of
>> table
>> "r" but no data of table "r".
>> I assume, that the sub select is the problem.
>>
>> result:
>> $hash->{SAMACCOUNTNAME} = "tiger"
>> $hash->{RESOURCESIZE} = ""
>>
>> When I execute the script in SQL Plus all Data is availible!
>>
>> $hash->{SAMACCOUNTNAME} = "tiger"
>> $hash->{RESOURCESIZE} = "1234"
>>
>> I'm using Active State Perl 5.8.4 with DBD-Oracle and Oracle 9i

>
>>From the lack of code posted, I gather you believe there is something

> wrong with Perl and/or DBD-Oracle, rather than something wrong with
> your code? That's mighty arrogant of you. You'll forgive me if I tend
> not to believe you. Please post a short-but-complete script that
> demonstrates the problem you're having. Have you seen the posting
> guidelines for this newsgroup? Please read them, and follow at least 2
> particulars:
> Speak Perl, not English. (Show us, in Perl, what your variable
> contains, don't try to tell us what you think it contains).
> Post the aforementioned short-but-complete script.
>
> Paul Lalli
>


Here the complete Code.
But as I said, when I copy the sql statement to sql+ i see all expected
data. Its not the first time that I use DBI, but the first time I use a sub
select.
I assume a problem with perl because of the sql+ experience

schnipp:
---
use DBI;
my $sizelimit =0;
my $sizelimitmail =0;


my $dbh=DBI->connect("DBI:Oracle:$database","user","pass") or die "no
connect\n";

my $sql ="
select
resourcesize R,a.samaccountname USR,displayname,
department,m.sizemb Mailboxsize, floor((resourcesize)/(1024)) rsize,
a.EXTENSIONATTRIBUTE9 Kostenstelle

from btrsammdba.aduser a, btrsammdba.mailboxsize m,
(
select * from btrsammdba.resourcesize
where ts = (select max(ts) from btrsammdba.resourcesize where server =
'BMAIZ-FILEN02')
) r

where a.samaccountname = r.samaccountname(+)
and a.samaccountname = m.samaccountname(+)

and a.EXTENSIONATTRIBUTE9 is not null
and a.EXTENSIONATTRIBUTE3 is null
and m.sizemb > '$sizelimitmail'

order by a.EXTENSIONATTRIBUTE9,resourcesize desc


";


print "\n$query\n";


print "creating query.... ";
my $sth = $dbh->prepare($sql, $attr) or return undef;
$sth->execute;
print "...created\n";

print $DBI::errstr."\n";
while( my $href= $sth->fetchrow_hashref)
{

foreach my $key (keys %$href)
{
print "$key -> $href->{$key}\n"; # here is no value in rsize
}
}


 
Reply With Quote
 
Bob Smith
Guest
Posts: n/a
 
      07-14-2005
Peter.Kramer wrote:

>
> "Paul Lalli" <> schrieb im Newsbeitrag
> news: oups.com...
>> Peter.Kramer wrote:
>>> I'm wondering why I cant get all resulst in my hasref in this statement:

>>
>> "Hashref". Not "hasref".
>>
>>> --
>>> select r.resourcesize, a.samaccountname
>>>
>>> from aduser a
>>> (
>>> select * from resourcesize
>>> where ts = (select max(ts) from resourcesize where server = 'xyz')
>>> ) r
>>>
>>> where a.samaccountname = r.samaccountname(+)
>>> ----
>>>
>>> What I get is an hasref and all data from table "a" and all fields of
>>> table
>>> "r" but no data of table "r".
>>> I assume, that the sub select is the problem.
>>>
>>> result:
>>> $hash->{SAMACCOUNTNAME} = "tiger"
>>> $hash->{RESOURCESIZE} = ""
>>>
>>> When I execute the script in SQL Plus all Data is availible!
>>>
>>> $hash->{SAMACCOUNTNAME} = "tiger"
>>> $hash->{RESOURCESIZE} = "1234"
>>>
>>> I'm using Active State Perl 5.8.4 with DBD-Oracle and Oracle 9i

>>
>>>From the lack of code posted, I gather you believe there is something

>> wrong with Perl and/or DBD-Oracle, rather than something wrong with
>> your code? That's mighty arrogant of you. You'll forgive me if I tend
>> not to believe you. Please post a short-but-complete script that
>> demonstrates the problem you're having. Have you seen the posting
>> guidelines for this newsgroup? Please read them, and follow at least 2
>> particulars:
>> Speak Perl, not English. (Show us, in Perl, what your variable
>> contains, don't try to tell us what you think it contains).
>> Post the aforementioned short-but-complete script.
>>
>> Paul Lalli
>>

>
> Here the complete Code.
> But as I said, when I copy the sql statement to sql+ i see all expected
> data. Its not the first time that I use DBI, but the first time I use a
> sub select.
> I assume a problem with perl because of the sql+ experience
>
> schnipp:
> ---
> use DBI;
> my $sizelimit =0;
> my $sizelimitmail =0;
>
>
> my $dbh=DBI->connect("DBI:Oracle:$database","user","pass") or die "no
> connect\n";
>
> my $sql ="
> select
> resourcesize R,a.samaccountname USR,displayname,
> department,m.sizemb Mailboxsize, floor((resourcesize)/(1024)) rsize,
> a.EXTENSIONATTRIBUTE9 Kostenstelle
>
> from btrsammdba.aduser a, btrsammdba.mailboxsize m,
> (
> select * from btrsammdba.resourcesize
> where ts = (select max(ts) from btrsammdba.resourcesize where server =
> 'BMAIZ-FILEN02')
> ) r
>
> where a.samaccountname = r.samaccountname(+)
> and a.samaccountname = m.samaccountname(+)
>
> and a.EXTENSIONATTRIBUTE9 is not null
> and a.EXTENSIONATTRIBUTE3 is null
> and m.sizemb > '$sizelimitmail'
>
> order by a.EXTENSIONATTRIBUTE9,resourcesize desc
>
>
> ";
>
>
> print "\n$query\n";
>
>
> print "creating query.... ";
> my $sth = $dbh->prepare($sql, $attr) or return undef;
> $sth->execute;
> print "...created\n";
>
> print $DBI::errstr."\n";
> while( my $href= $sth->fetchrow_hashref)
> {
>
> foreach my $key (keys %$href)
> {
> print "$key -> $href->{$key}\n"; # here is no value in rsize
> }
> }

hmm, I don't know, are you sure that the field you call resourcesize is
populated?

what about the floor function, what fieldtype is resourcesize, ?
--
http://www.kolumbus.fi/bob.smith
 
Reply With Quote
 
Peter.Kramer
Guest
Posts: n/a
 
      07-15-2005

"Bob Smith" <> schrieb im Newsbeitrag
news:db5b0h$aol$...
> Peter.Kramer wrote:
>
>>
>> "Paul Lalli" <> schrieb im Newsbeitrag
>> news: oups.com...
>>> Peter.Kramer wrote:
>>>> I'm wondering why I cant get all resulst in my hasref in this
>>>> statement:
>>>
>>> "Hashref". Not "hasref".
>>>
>>>> --
>>>> select r.resourcesize, a.samaccountname
>>>>
>>>> from aduser a
>>>> (
>>>> select * from resourcesize
>>>> where ts = (select max(ts) from resourcesize where server = 'xyz')
>>>> ) r
>>>>
>>>> where a.samaccountname = r.samaccountname(+)
>>>> ----
>>>>
>>>> What I get is an hasref and all data from table "a" and all fields of
>>>> table
>>>> "r" but no data of table "r".
>>>> I assume, that the sub select is the problem.
>>>>
>>>> result:
>>>> $hash->{SAMACCOUNTNAME} = "tiger"
>>>> $hash->{RESOURCESIZE} = ""
>>>>
>>>> When I execute the script in SQL Plus all Data is availible!
>>>>
>>>> $hash->{SAMACCOUNTNAME} = "tiger"
>>>> $hash->{RESOURCESIZE} = "1234"
>>>>
>>>> I'm using Active State Perl 5.8.4 with DBD-Oracle and Oracle 9i
>>>
>>>>From the lack of code posted, I gather you believe there is something
>>> wrong with Perl and/or DBD-Oracle, rather than something wrong with
>>> your code? That's mighty arrogant of you. You'll forgive me if I tend
>>> not to believe you. Please post a short-but-complete script that
>>> demonstrates the problem you're having. Have you seen the posting
>>> guidelines for this newsgroup? Please read them, and follow at least 2
>>> particulars:
>>> Speak Perl, not English. (Show us, in Perl, what your variable
>>> contains, don't try to tell us what you think it contains).
>>> Post the aforementioned short-but-complete script.
>>>
>>> Paul Lalli
>>>

>>
>> Here the complete Code.
>> But as I said, when I copy the sql statement to sql+ i see all expected
>> data. Its not the first time that I use DBI, but the first time I use a
>> sub select.
>> I assume a problem with perl because of the sql+ experience
>>
>> schnipp:
>> ---
>> use DBI;
>> my $sizelimit =0;
>> my $sizelimitmail =0;
>>
>>
>> my $dbh=DBI->connect("DBI:Oracle:$database","user","pass") or die "no
>> connect\n";
>>
>> my $sql ="
>> select
>> resourcesize R,a.samaccountname USR,displayname,
>> department,m.sizemb Mailboxsize, floor((resourcesize)/(1024)) rsize,
>> a.EXTENSIONATTRIBUTE9 Kostenstelle
>>
>> from btrsammdba.aduser a, btrsammdba.mailboxsize m,
>> (
>> select * from btrsammdba.resourcesize
>> where ts = (select max(ts) from btrsammdba.resourcesize where server
>> =
>> 'BMAIZ-FILEN02')
>> ) r
>>
>> where a.samaccountname = r.samaccountname(+)
>> and a.samaccountname = m.samaccountname(+)
>>
>> and a.EXTENSIONATTRIBUTE9 is not null
>> and a.EXTENSIONATTRIBUTE3 is null
>> and m.sizemb > '$sizelimitmail'
>>
>> order by a.EXTENSIONATTRIBUTE9,resourcesize desc
>>
>>
>> ";
>>
>>
>> print "\n$query\n";
>>
>>
>> print "creating query.... ";
>> my $sth = $dbh->prepare($sql, $attr) or return undef;
>> $sth->execute;
>> print "...created\n";
>>
>> print $DBI::errstr."\n";
>> while( my $href= $sth->fetchrow_hashref)
>> {
>>
>> foreach my $key (keys %$href)
>> {
>> print "$key -> $href->{$key}\n"; # here is no value in rsize
>> }
>> }

> hmm, I don't know, are you sure that the field you call resourcesize is
> populated?
>
> what about the floor function, what fieldtype is resourcesize, ?
> --
> http://www.kolumbus.fi/bob.smith


Yes I'm sure, when I use a sql statemnet that has no sub select all adta is
presented well.
the floor function works proper as well, the data type is NUMBER(38,0)


 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      07-15-2005
Peter.Kramer <> wrote:


[snip 120 lines of full-quote including .sig]

[snip 3 lines of new text]


Please learn how to compose a proper followup.


--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DBI Mysql storing DBI:binary, trouble with character 26 Jerome Hauss Ruby 0 10-13-2004 03:04 PM
DBI and DBI::Oracle packages configuration ulloa Perl 1 07-22-2004 05:52 PM
ANN: PLD RPMs of rake and ruby-dbi and a plea to packagers Aredridel Ruby 9 02-27-2004 11:05 AM
DBI problem : How can I load quickly one huge table with DBI ??. Vincent Le-Texier Perl Misc 3 09-13-2003 03:43 AM
Mason, DBI, and DBI::Pg Asby Perl Misc 0 07-24-2003 09:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57