Welcome, Guest
Username: Password: Remember me
This public forum is meant for questions and discussions about Visual FoxPro
  • Page:
  • 1

TOPIC:

aCountInfo and SqlExec 23 Apr 2020 18:18 #14182

  • kevclark64
  • kevclark64's Avatar
  • Topic Author


  • Posts: 126
  • I noticed an interesting thing going on with aCountInfo and SqlExec. Normally, I would have code like this:
    local aCountInfo[2]
    if sqlexec(connhandle,"select statement","dbfname",aCountInfo)>0 then
    	if aCountInfo[2]>0 then
    		//if I reach here then I have retrieved at least one record
    	endif
    endif 

    But when I run this in XSharp the aCountInfo array is changed by the SqlExec function from a one-dimensional array of [2] to a 2-dimensional array of [1,2]. So, now the original code gives an out of range error on aCountInfo[2] and has to be changed to:
    if aCountInfo[1][2]>0 then
    	//if I reach here then I have retrieved at least one record
    endif

    Please Log in or Create an account to join the conversation.

    aCountInfo and SqlExec 23 Apr 2020 19:48 #14183

    • robert
    • robert's Avatar


  • Posts: 3595
  • Matt
    According to the Vfp docs this is how it works.
    However vfp’s weird array implementation allows you to access elements in a 2 dimensional array with a single index .

    In most other languages aInfo[2] is the second row of the multi dimensional array and not the 2nd element of row 1.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    aCountInfo and SqlExec 24 Apr 2020 03:58 #14187

    • FoxProMatt
    • FoxProMatt's Avatar



    Robert - you addressed your reply to "Matt", but the message came from Kevin Clark, not me.

    Please Log in or Create an account to join the conversation.

    aCountInfo and SqlExec 24 Apr 2020 11:31 #14189

    • mainhatten
    • mainhatten's Avatar


  • Posts: 199
  • Kevin,

    did you verify in vfp with disp memo like aCountInfo ?

    regards
    Thomas

    Kevin Clark wrote: I noticed an interesting thing going on with aCountInfo and SqlExec. Normally, I would have code like this:

    local aCountInfo[2]
    if sqlexec(connhandle,"select statement","dbfname",aCountInfo)>0 then
    	if aCountInfo[2]>0 then
    		//if I reach here then I have retrieved at least one record
    	endif
    endif 

    But when I run this in XSharp the aCountInfo array is changed by the SqlExec function from a one-dimensional array of [2] to a 2-dimensional array of [1,2]. So, now the original code gives an out of range error on aCountInfo[2] and has to be changed to:
    if aCountInfo[1][2]>0 then
    	//if I reach here then I have retrieved at least one record
    endif

    Please Log in or Create an account to join the conversation.

    aCountInfo and SqlExec 24 Apr 2020 11:46 #14191

    • robert
    • robert's Avatar


  • Posts: 3595
  • Thomas,

    I did verify this during development and VFP also has a 2 dimensional array.
    It lists the elements as (1,1) (cursorname) and (1,2) (# of records)

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    aCountInfo and SqlExec 25 Apr 2020 11:20 #14229

    • mainhatten
    • mainhatten's Avatar


  • Posts: 199
  • robert wrote: I did verify this during development and VFP also has a 2 dimensional array.
    It lists the elements as (1,1) (cursorname) and (1,2) (# of records)

    Hi Robert,

    Guessed you had - we both know the reason, as SQLExec can return more than 1 cursor, one row is intended fr each returned cursor although I don't remember any real code place where code returned multiple cursors. In theory such an option makes sense if you reuse server side stage table(s) to filter/generate return cursors based on particular set of data, in practice building/debugging single statements gives better dev speed ;-)

    My comment was meant as a nudge to verify own assumptions plus a reminder (or hint for those testing fox first time) how easy fox max such things even if you do not work in developer edition with debugger - the runtime often is enough.

    Seems I was tooooo subtle ;-)

    regards
    thomas

    Please Log in or Create an account to join the conversation.

    Last edit: by mainhatten.
    • Page:
    • 1