473,395 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Getting FieldNames from DBI Module

Hi,

I am using DBI module to interact with MS-Access Database. I need to know in DBI module, is there any similar method as 'FieldNames()' from Win32::ODBC to get the Field names from MS-Access table.

Thanks in Advance,
Freedolen
May 14 '07 #1
3 1484
miller
1,089 Expert 1GB
Well, assuming that MS-Access supports the standard SQL commands for queries, then just describe the table.

Expand|Select|Wrap|Line Numbers
  1. sub descTableCols {
  2.     my $tablename = shift;
  3.  
  4.     my @columns = ();
  5.     my $sth = $dbh->prepare(q{DESC } . $tablename);
  6.     $sth->execute or die $dbh->errstr;
  7.     while (my $hashref = $sth->fetchrow_hashref) {
  8.         push @columns, $hashref->{Field};
  9.     }
  10.     $sth->finish; undef $sth;
  11.  
  12.     return @columns;
  13. }
  14.  
- Miller
May 14 '07 #2
Hi Miller,

Thanks for your work, but MS-Access doesn't supports 'DESC' statement. It throws error message as "Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.".

I have Googled and got the following coding to get the column names from table. But beyond this i need to know is there any one liner available in DBI as 'FieldNames()' in ODBC to get the column names.

Expand|Select|Wrap|Line Numbers
  1. my $colsth = $dbh->column_info('','',$tablename,'');
  2. my @colnames = ();
  3. my $col_name = "";
  4. while(my (undef, undef, undef, $col_name) = $colsth->fetchrow_array)
  5. {
  6.      push (@colnames, $col_name);
  7. }
  8. print @colnames;
  9.  
--Freedolen
May 15 '07 #3
miller
1,089 Expert 1GB
I have Googled and got the following coding to get the column names from table. But beyond this i need to know is there any one liner available in DBI as 'FieldNames()' in ODBC to get the column names.
Not that I know of, No.

- Miller
May 15 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Josep | last post by:
Hi, I'd like to poll a database and get the table contents, as well as the field names from that table. I've been to php.net but this time I cannot find something helpful. I can get the data,...
7
by: | last post by:
How do I get to the fieldnames of a table in a recordset? I have a recordset which I output into HTML. And on data from certian columns I need to perform different actions. I would like to...
4
by: Little PussyCat | last post by:
Hello, I have had a request, one of our tables is used as a report and I have been asked that all fieldnames for months have dashes in them, like Jan-05 instead of Jan05 and so on... Now what...
1
by: Jay Balapa | last post by:
Hello, Iam creating a query page, in which a Drop Down List will have collection of fieldnames. Is there a elegant way of doing it? Currently Iam opening up a datareader and using...
3
by: Eych | last post by:
I have a module which has a function that returns values from a table. e.g. GetFromUsersTable(userID,"UserName") GetFromUsersTable(userID,"UserDept") etc. depending on the userID passed, it...
6
by: Miles Keaton | last post by:
Is there a simple way to list fieldnames in a table, from PHP? When on the command-line, I just do \d tablename But how to get the fieldnames from PHP commands? ...
7
by: MLH | last post by:
I use this to list table fieldnames to the debug window. Can it be modified to perform similar objective for saved query objects? Would it be best to trash this completely and write a procedure...
6
by: Gerrit | last post by:
Hello, I try to display the fieldnames and the primary key of a table, with this code: using System; using System.Collections.Generic; using System.Text; using System.Data; using...
2
by: john | last post by:
In the query builder I made an edit-query in which I have linked table A to table B on IDnr. For every record that matches I want 5 fields of table A to get the values of corresponding fields in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.