CTD2.1: SQLGetCursorList

Post your TD Mobile tools and samples or ask for them.
th4416

CTD2.1: SQLGetCursorList

Post by th4416 » 20 Apr 2011, 13:09

Hi,
i need a function, which get´s a list of all connecting users (SQLBase 11.5.3 6932).
i found any samples, but every source get the same results. (look screenshot)
Unbenannt.jpg
my main problem is, that i don't know,
- how i should use CStructGetxxx and
- how to split the buffer-result (maybe the length are changed?).

My be its a unicode-problem?

There the soucre from Thomas Althammer, i found in the web:

Code: Select all

Function: SQLGetCursorList
   Description:
   Returns
      Number:
   Parameters
      Number: p_hServer
      Receive Number: r_naCursor[*]
      Receive Number: r_naProcess[*]
      Receive String: r_saDatabase[*]
      Receive String: r_saUser[*]
      Receive String: r_saClient[*]
   Static Variables
   Local variables
      Boolean: bOk
      Number: nCounter
      Number: hBuffer
      String: sBuffer
      Number: nBufferOffset
      Number: nBufferLength
      String: sEntry
      Number: nCursor
      Number: nProcess
      String: sDatabase
      String: sUser
      String: sClient
   Actions
      If p_hServer = 0
         Set bOk = FALSE
      Else
         Set hBuffer = CStructAllocFarMem( 8192 )
         If sqlgsi( p_hServer, SQLGCUR | SQLXGSI, hBuffer, 8192, nBufferLength ) = 0
            Call SalStrSetBufferLength( sBuffer, nBufferLength )
            Call CStructCopyFromFarMem( hBuffer, sBuffer, nBufferLength )
            ! ignore header size
            Set nBufferOffset = nBufferOffset + 4 + 8
            ! read records one by one
            While nBufferOffset < nBufferLength
               Call SalStrSetBufferLength( sDatabase, 9 )
               Call SalStrSetBufferLength( sUser, 19 )
               Call SalStrSetBufferLength( sClient, 13 )
               ! extract record information
               Set nCursor = CStructGetByte( sBuffer, nBufferOffset + 68 )
               Set nProcess = CStructGetByte( sBuffer, nBufferOffset + 17 )
               Call CStructGetString( sBuffer, nBufferOffset + 40, 9, sDatabase )
               Call CStructGetString( sBuffer, nBufferOffset + 21, 19, sUser )
               Call CStructGetString( sBuffer, nBufferOffset + 70, 13, sClient )
               ! add to list
               If sDatabase != '' 
                  Set r_naCursor[nCounter] = nCursor
                  Set r_naProcess[nCounter] = nProcess
                  Set r_saDatabase[nCounter] = sDatabase
                  Set r_saUser[nCounter] = sUser
                  Set r_saClient[nCounter] = sClient
                  !
                  Set nCounter = nCounter + 1
               !
               Set nBufferOffset = nBufferOffset + 104
            !
            Set bOk = TRUE
         Else
            Set bOk = FALSE
         Call CStructFreeFarMem( hBuffer )
      !
      If bOk
         Return nCounter 
      Else
         Return -1
Thanks alot for help

regards

Thomas
You do not have the required permissions to view the files attached to this post.

Rainer Ebert

CTD2.1: SQLGetCursorList

Post by Rainer Ebert » 20 Apr 2011, 16:09

Hi,

note that the length of the database name has changed from 10 to 18 some with SQLBase 8. So If you have a SQLBase version up to 7.5, the database name length is 10 and if you have a SQLBase version 8 or higher, the database name length is 18.

In your implementation you will only geht the first 8192 byte of process information from SQLBase.
I would recommend to change this to 64000 to get most of the information as possible (TD or better said the CStruct implementation has a limitation to 64kB).

Here's some sample code:

Code: Select all

If nSqlBaseVersion >= 8
   Set nDBLenOffset = 8
Else
   Set nDBLenOffset = 0

Set nOffset = 12
While nOffset < nLength
   ! Process ID
   Set nOffset = nOffset + 17
   Set nPID = CStructGetByte( sProcesses, nOffset )
   ! Isolation Level
   Set nOffset = nOffset + 1
   Set nRecordLength = 3
   Call SalStrSetBufferLength( sIsolation, nRecordLength )
   Call CStructGetString( sProcesses, nOffset, nRecordLength, sIsolation )
   ! User Name
   Set nOffset = nOffset + 3
   Set nRecordLength = 19
   Call SalStrSetBufferLength( sUser, nRecordLength )
   Call CStructGetString( sProcesses, nOffset, nRecordLength, sUser )
   ! Database Name
   Set nOffset = nOffset + 19
   Set nRecordLength = 10 + nDBLenOffset
   Call SalStrSetBufferLength( sDb, nRecordLength )
   Call CStructGetString( sProcesses, nOffset, nRecordLength, sDb )
   ! Offset to Beginning of next information
   Set nOffset = nOffset + 12 + nDBLenOffset
Regards,
Rainer

th4416

CTD2.1: SQLGetCursorList

Post by th4416 » 20 Apr 2011, 17:15

Hi Rainer,
thanks for your answer.
I tested it with the longer bufferlenght for the dbname and the 64kb, but the results were similar.
bummer
Unbenannt.jpg
regards
Thomas
You do not have the required permissions to view the files attached to this post.

FRBhote
India
Posts: 2205
Joined: 09 Mar 2017, 05:32
Location: Hyderabad, India

CTD2.1: SQLGetCursorList

Post by FRBhote » 21 Apr 2011, 06:27

Program by Thomas Koller attached.
You do not have the required permissions to view the files attached to this post.

Return to “Tools & Samples”

Who is online

Users browsing this forum: [Ccbot] and 0 guests