WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ODBC
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

ODBC SQLDescribeCol Example

Keywords:   ODBC SQLDescribeCol Example

#DefineFunction udfBinary32Parameter(value)
   x=BinaryAlloc(32)                    ; Get some space
   BinaryEODSet(x,32)                   ; Set EndOfBuffer
   BinaryPoke4 (x,0,value)              ; Poke the wanted value at the first place
   Return x                             ; Return with Bufferaddress
#EndFunction

#DefineFunction odbcColNames(hstmt)
; Gets the names of all Columns of an Sql-Statement as a Tab-seperated List.
   ResultList=""
   numcols   = qNumRsltCol(hstmt)       ;How many Columns do we have
   cDLL      = qSpecial(1,0,0,0,0)
   For ColNr=1 to numCols               ;Look at every Col
	   handle  = qSpecial(2,hstmt,0,0,0) ;long:handle,         = true statement handle
	   ; ColNr by for-loop               ;long:nCol,           = column number
	   cColName   = BinaryAlloc(128)     ;lpbinary:cColName,   = string to return Column Name
	   ; fix 128                         ;long:128,            = Maximum length of Column Name
	   nLength  =udfBinary32Parameter(0) ;lpbinary:nLength,    = Actual length returned
	   nColType =udfBinary32Parameter(0) ;lpbinary:nColType,   = Column Type, i.e. 1=SQL_CHAR
	   nColDef  =udfBinary32Parameter(0) ;lpbinary:nColDef,    = Precision or Size of Data
	   nColScale=udfBinary32Parameter(0) ;lpbinary:nColScale,  = Scale
	   nColNull =udfBinary32Parameter(2) ;lpbinary:nColNull)   = can column contain Null Values
	   BinaryEODSet(cColName,128)        ;Set End of NameBuffer
	   x= DllCall(cDLL, long:"SQLDescribeCol",long:handle,long:ColNr,lpbinary:cColName,long:128,lpbinary:nLength,lpbinary:nColType,lpbinary:nColDef,lpbinary:nColScale,lpbinary:nColNull)
	   name=BinaryPeekStr(cColName,0,BinaryEodGet(cColName))
	   ResultList = StrCat(ResultList,Name,@Tab)            ; Put the Name at the end of the Liste
	   cColName   = BinaryFree(cColName) ;Free all Buffers
	   nColScale  = BinaryFree(nColScale)
	   nLength    = BinaryFree(nLength)
	   nColNull   = BinaryFree(nColNull)
	   nColType   = BinaryFree(nColType)
	   nColDef    = BinaryFree(nColDef)
	Next ColNr
   Return ResultList                    ;Return with List of Columnnames
#EndFunction

Article ID:   W15410
File Created: 2017:07:28:13:58:32
Last Updated: 2003:05:13:11:27:32