Dave,
As no one is answering so far, i give it a shot. Excuses for the long mail
as a result of this.
It is the way I do this to describe the columns in the result set.
I do not know how you have defined your PR for the APIs, but mine are:
*********************************************************************
* Function Prototype GET NUMBER OF RESULT COLUMNS
*
* SQLRETURN SQLNumResultCols (SQLHSTMT hstmt,
* SQLINTEGER *ColumnCnt);
*********************************************************************
* Return value = 0 (OK) or -1 (error) or -2 (invalid handle)
DSQLNumCols PR 10I 0 ExtProc('SQLNumResultCols')
* Handle of the SQL statement
D 10I 0 VALUE
* Number of columns in resultset
D 5I 0
*********************************************************************
* Function Prototype RETRIEVE DESCRIPTON OF A COLUMN
*
* SQLRETURN SQLDescribeCol (SQLHSTMT hstmt,
* SQLSMALLINT column number,
* SQLCHAR *column name,
* SQLSMALLINT size name buffer,
* SQLSMALLINT *name length,
* SQLSMALLINT *data type,
* SQLUINTEGER *column size,
* SQLSMALLINT *decimals,
* SQLSMALLINT *nullable);
*********************************************************************
* Return value = 0 or 1 (OK) or -1 (error) or -2 (invalid handle)
DSQLDescCol PR 10I 0 ExtProc('SQLDescribeCol')
* Handle of the SQL statement
D 10I 0 VALUE
* Numberr of column in resultset
D 5I 0 VALUE
* Column name
D 30
* Length of the Name buffer
D 5I 0 VALUE
* Name length
D 5I 0
* Data type
D 5I 0
* Column size (precision)
D 10U 0
* Number of decimals (scale)
D 5I 0
* Indication of NULL
D 5I 0
In a *SRVPGM I have the following procedure (incomplete code, beware:
**************************************************************************
* CLIDescribe - Place the SQL CLI Describtion into Definition array
**************************************************************************
P CLIDescribe B EXPORT
*
D CLIDescribe PI 1152
D RunResult 5
D StmtHandle 10I 0 CONST
D InSQLDAPtr *
*
D ColDef S 10U 0 INZ
D DtaType S 5I 0 INZ
D FldNmLen S 5I 0 INZ(%len(NameFld))
D NameFld S 30 INZ
D NamePtr S * INZ(%addr(NameFld))
D Nullable S 5I 0 INZ
D ValNum S 10I 0 INZ
D NumValPtr S * INZ(%addr(ValNum))
D RtnLen S 5I 0 INZ
D Scale S 5I 0 INZ
*
C Eval SQLDAPtr = InSQLDAPtr
C Eval RtnCode = SQLNumCols(StmtHandle:
C NbrColumns)
*
C For SQLIx = 1 TO NbrColumns
C Eval RtnCode = SQLDescCol(StmtHandle:SQLIx:
C NameFld:FldNmLen:RtnLen:
C DtaType:ColDef:Scale:
C Nullable)
*
C If RtnCode <> SQL_OK
C Leave
C EndIf
*
C If Label = ' '
C Eval FldName(SQLIx) = %str(NamePtr:RtnLen)
C Else
C Eval FldName(SQLIx) = %str(LabelPtr:LenBuf)
C EndIf
*
C Eval FldLength(SQLIx) = ColDef
C Eval FldDecPos(SQLIx) = Scale
*
C Select
C When DtaType = SQL_CHAR
*
C If Nullable = SQL_NULLABLE
C Eval FldType(SQLIx) = CharFixNul
C Else
C Eval FldType(SQLIx) = CharFix
C EndIf
*
C When DtaType = SQL_DECIMAL
*
C If Nullable = SQL_NULLABLE
C Eval FldType(SQLIx) = PackedNull
C Else
C Eval FldType(SQLIx) = Packed
C EndIf
*
repeat for other data types
*
C EndSl
*
C EndFor
*
C Eval RunResult = ChkRtnCde(RtnCode)
C Eval SQLD = NbrColumns
C Eval InSQLDAPtr = SQLDAPtr
*
C Return DefTableDS
*
P CLIDescribe E
The returned parameter is defined :
D DefTableDS DS
D DefTable 36 DIM(SQL_NUM)
D FldType 5I 0 OVERLAY(DefTable:1)
D FldLength 5I 0 OVERLAY(DefTable:3)
D FldDecPos 5I 0 OVERLAY(DefTable:5)
D FldName 30 OVERLAY(DefTable:7)
I do not know, why things are coded as they are, but it is in sync with the
way I handled embedded SQL.
Hope this is helpful.
With regards,
Carel Teijgeler
*********** REPLY SEPARATOR ***********
On 30-10-2007 at 13:01 Dave.Zastrow@xxxxxxxxxxxxxxxxxx wrote:
Is it possible to use the information from SQLNumResultCols and
SQLDescribeCol to bind to the columns of a result set?
I would like to be able to build a framework which would give me the
ability to do the column binding at runtime. I think that SQLDescribeCol
gives me almost everything I need. The 'gotcha' appears to be that I have
to pass a pointer to the variable which will hold the data for the column.
And I'm not bright enough to figure out how to do that.
Any and all help would be appreciated.
I suppose I should mention I'm trying to do this in RPG IV on V5R4.
Thanks,
Dave Zastrow
Programmer/Analyst II
Duncan Aviation
Information Services
402.479.4155
===========================================================================
=====
This email message is for the sole use of the intended recipient (s) and
may contain
confidential and privileged information. Any unauthorized review, use,
disclosure or distribution
is prohibited. If you are not the intended recipient, please contact the
sender by reply email
and destroy all copies of the original message.
===========================================================================
=====
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.503 / Virus Database: 269.15.15/1101 - Release Date:
31-10-2007 10:06
As an Amazon Associate we earn from qualifying purchases.