If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > get data type of a column

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-08-10, 04:30
bubbles_j bubbles_j is offline
Registered User
 
Join Date: Sep 2010
Posts: 5
Question get data type of a column

Hi,

Im a newbie. I would like to know how can we get the data type of a column in c++.

I know DESCRIBE SELECT <column name> FROM <tablename>;

How about if writing it in c++ code?



Thanks
Reply With Quote
  #2 (permalink)  
Old 09-08-10, 05:50
Mathew_paul Mathew_paul is offline
Registered User
 
Join Date: Oct 2007
Posts: 200
which nexcerf

i don't know i helps or not just another way

describe select * from tabname


regds
Paul
Reply With Quote
  #3 (permalink)  
Old 09-08-10, 06:01
bubbles_j bubbles_j is offline
Registered User
 
Join Date: Sep 2010
Posts: 5
thanks for the reply.

i have here the code:

*_pSession << "DESCRIBE SELECT COLNAME FROM TABNAME", into(info), now;


my prob is I dont know what type variable 'info' will be. that will hold the results after executing that statement.
Reply With Quote
  #4 (permalink)  
Old 09-08-10, 08:48
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by bubbles_j View Post
thanks for the reply.

i have here the code:

*_pSession << "DESCRIBE SELECT COLNAME FROM TABNAME", into(info), now;


my prob is I dont know what type variable 'info' will be. that will hold the results after executing that statement.
You cannot DESCRIBE an inline statement: it must refer to a prepared statement. The information you are looking for is in the SYSCAT.COLUMNS catalog view:
Code:
select typename, length, scale from syscat.columns
where tabname = 'MYTABLE' and colname = 'MYCOLUMN'
Reply With Quote
  #5 (permalink)  
Old 09-08-10, 09:08
Mathew_paul Mathew_paul is offline
Registered User
 
Join Date: Oct 2007
Posts: 200
trailfes project

yes i thought of that option too from syscat.columns but wht if user is not a superuser and everything is revoked from public, user cannot access system tables

regds
Paul
Reply With Quote
  #6 (permalink)  
Old 09-08-10, 21:19
bubbles_j bubbles_j is offline
Registered User
 
Join Date: Sep 2010
Posts: 5
I have tried to execute the statement given by n_i but it returned nothing.
Reply With Quote
  #7 (permalink)  
Old 09-08-10, 23:07
bubbles_j bubbles_j is offline
Registered User
 
Join Date: Sep 2010
Posts: 5
oh! n_i was right. I have missed to identify the tabschema. Thanks!

I have one more question, is the typename a string? because i encountered an assertion error after I executed the statement.


Here is my code:

Code:
*_pSession << "SELECT typename FROM syscat.columns WHERE tabschema='SAMPLE' and tabname='MYTABLE' and colname='MYCOLUMN'", into(name), now;
where 'name' is a string variable.
This variable 'name' is supposed to hold the result after you execute the statement.
Reply With Quote
  #8 (permalink)  
Old 09-08-10, 23:13
bubbles_j bubbles_j is offline
Registered User
 
Join Date: Sep 2010
Posts: 5
Sorry my bad.


I found the error.. The code a pasted above works fine. Thanks for the help!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On