Richard Morse wrote:

On 30 Jan 2004, at 08:48 AM, ashish srivastava wrote:

Is it possible to get the names of the columns which a user has selected? I mean suppose a user writes a query as :

select ename,deptno,sal from emp;

then can we print the column name(ENAME,DEPTNO,SAL) ?


Look at the DBI docs, under the statement properties, for the 'NAME_lc' and 'NAME_uc' properties. Without looking at the docs (yes, I'm lazy), I think it works something like this:

One minor change, because those properties return a reference to an array.


my $db = DBI->connect(...);
my $sth = $db->prepare("select ename, deptno, sal from emp");
$sth->execute();
print join("\t", $sth->{'NAME_lc'}), "\n"; # the lowercase form of the

change "$sth->{'NAME_lc'}" to "@{$sth->{'NAME_lc'}}" to get the names.


names
while(my $row = $sth->fetchrow_arrayref) {
    print join("\t", @$row), "\n";
}
$sth->finish();
$db->disconnect();

HTH,
Ricky

Otherwise it's exactly like that.


Rhesa

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to