How to read data using SQLGetData from a block, forward-only cursor (ODBC)

Hi there.  I am trying to read data a small number of rows of data from either a Microsoft Access or Microsoft SQL Server (whichever is being used) as quickly as possible.  I have connected to the database using the ODBC API's and have run a select
statement using a forward-only, read-only cursor.  I can use either SQLFetch or SQLExtendedFetch (with a rowset size of 1) to retrieve each successive row and then use SQLGetData to retrieve the data from each column into my local variables.  This
all works fine.
My goal is to see if I can improve performance incrementally by using SQLExtendedFetch with a rowset size greater than 1 (block cursor).  However, I cannot figure out how to move to the first of the rowset returned so that I can call SQLGetData to retrieve
each column.  If I were using a cursor type that was not forward-only, I would use SQLSetPos to do this.  However, using those other cursor types are slower and the whole point of the exercise is to see how fast I can read this data.  I can
successfully read the data using a block forward only cursor if I bind each column to an array in advance of the call to SQLExtendedFetch.  However, that has several drawbacks and is documented to be slower for small numbers of rows.  I really
want to see what kind of speed I can achieve using a block, forward-only, read-only cursor using SQLGetData to get each column.
Here is the test stub that I created:
' Create a SELECT statement to retrieve the entire collection.
selectString = "SELECT [Year] FROM REAssessmentRolls"
' Create a result set using the existing read/write connection. The read/write connection is used rather than
' the read-only connection because it will reflect the most recent changes made to the database by this running
' instance of the application without having to call RefreshReadCache.
If (clsODBCDatabase.HandleDbcError(SQLAllocStmt(gDatabase.ReadWriteDbc, selectStmt), gDatabase.ReadWriteDbc, errorBoxTitle) <> enumODBCSQLAPIResult.SQL_SUCCESS) Then
GoTo LoadExit
End If
Call clsODBCDatabase.HandleStmtError(SQLSetStmtOption(selectStmt, SQL_CONCURRENCY, SQL_CONCUR_READ_ONLY), selectStmt, errorBoxTitle)
Call clsODBCDatabase.HandleStmtError(SQLSetStmtOption(selectStmt, SQL_CURSOR_TYPE, SQL_CURSOR_FORWARD_ONLY), selectStmt, errorBoxTitle)
Call clsODBCDatabase.HandleStmtError(SQLSetStmtOption(selectStmt, SQL_ROWSET_SIZE, MAX_ROWSET_SIZE), selectStmt, errorBoxTitle)
If (clsODBCDatabase.HandleStmtError(SQLExecDirect(selectStmt, selectString, Len(selectString)), selectStmt, errorBoxTitle) <> enumODBCSQLAPIResult.SQL_SUCCESS) Then
GoTo LoadExit
End If
' Cursor through result set. Each time we fetch data we get a SET of rows.
sqlResult = clsODBCDatabase.HandleStmtError(SQLExtendedFetch(selectStmt, SQL_FETCH_NEXT, 0, rowsFetched, rowStatus(0)), selectStmt, errorBoxTitle)
Do While (sqlResult = enumODBCSQLAPIResult.SQL_SUCCESS)
' Read all rows in the row set
For row = 1 To rowsFetched
If rowStatus(row - 1) = SQL_ROW_SUCCESS Then
sqlResult = clsODBCDatabase.HandleStmtError(SQLSetPos(selectStmt, row, SQL_POSITION, SQL_LOCK_NO_CHANGE), selectStmt, errorBoxTitle)
Call clsODBCDatabase.SQLGetShortField(selectStmt, 1, assessmentRollYear(row - 1))
Console.WriteLine(assessmentRollYear(row - 1).ToString)
End If
Next
' If the rowset we just retrieved contains the maximum number of rows allowed, there could be more data.
If rowsFetched = MAX_ROWSET_SIZE Then ' there could be more data
sqlResult = clsODBCDatabase.HandleStmtError(SQLExtendedFetch(selectStmt, SQL_FETCH_NEXT, 0, rowsFetched, rowStatus(0)), selectStmt, errorBoxTitle)
Else
Exit Do ' no more rowsets
End If
Loop ' Do While (sqlResult = enumODBCSQLAPIResult.SQL_SUCCESS)
The test fails on the call to SQLSetPos.  The error message I get is "Invalid cursor position; no keyset defined".  I have tried passing SET_POSITION and also SET_REFRESH.  Same error.  There has to be a way to do this!
Thank you for your help!
Thank You! - Andy

Hi Apelkey,
Thank you for your question. 
I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated. 
Thank you for your understanding and support.
Regards,
Charlie Liao
TechNet Community Support

Similar Messages

  • How to read data simultaneo​usly from different cdaq modules?

    Is there a way to synchronize input from separate cdaq modules?
    I need to read a voltage on an NI-9219 analog input channel and a
    frequency on an NI-9211 channel.  As far as I can tell a single "task" can
    only read input from channels on one module. Is there a way to build a task that reads data from multiple modules?
    Seems to me that buffered input is useless when multiple tasks are employed. With multiple tasks you get arrays of data that are sequential, not simultaneous. Is this correct? I'm thinking that the only way to
    get synchronized readings is to read each channel individually inside a
    loop. But this restricts the program to low speed data
    acquisition with  measurements that are spaced unevenly. Right?
    I want to create a data file with three columns: time, voltage,
    frequency. What's the best way to get these readings at the same
    instant?
    Referrence to a help document or tutorial would be great.
     thanks! 

    Synchronizing measurements of different types using separate cDAQ modules can be done by making sure that the physical channels for each module IO control are selected (and separated by commas). Please review the following Developer Zone article illustrating how this can be accomplished. Cheers
    1. NI-DAQmx: NI CompactDAQ Module Synchronization:  http://zone.ni.com/devzone/cda/epd/p/id/5259
    Regards,
    Ali M
    Applications Engineer
    National Instruments

  • How to read data from a router by using labview

    I am a  beginner labview. How to read data from a router by using labview ? 

    What kind of data are you trying to read?
    Does the router behave like a webserver that you log into?  If so, search the forums for threads discussing HTML.

  • How to read data from a connected modem

    any one can help me? how to read data from a connected modem. The modem received real-time data from other server. The data is in text format. I can see this text when I used hyperterminal for dial up and the data is accumulated such as:
    @aa1235678
    @bb2135647
    @cc5214367
    since it is real-time data, I want to read one line each time instantly when it arrives.

    You need to use the Java Communications API. (http://java.sun.com/products/javacomm/index.html)

  • How to read data from a zipped MS Access file?

    How to read data from a zipped MS Access file?

    RPJ,
    You do not need to use the Close Zip File.vi when you unzip a folder.  This VI is used when you are creating a zip folder.
    As for examples, I found a couple of ActiveX based MS Access examples.  These programs look to be pretty basic.  For more in depth example I would search Microsoft Developers Network
    http://zone.ni.com/devzone/cda/epd/p/id/2188
    http://zone.ni.com/devzone/cda/epd/p/id/1694
    Regards,
    Jon S.
    National Instruments
    LabVIEW R&D

  • How to read data from an internal table into a real table?

    Hello experts,
    I'm relatively new to ABAP and I'm trying to figure out how to read data from an internal table into a table that I created.  I'm trying to use the RRW3_GET_QUERY_VIEW_DATA function module to read data from a multiprovider.  I'm trying to read data from the e_cell_data and e_axis_data tables into a table that I've already created.  Please see code below.
    TABLES MULTITAB.
    DATA:
      query_name TYPE RSZCOMPID,
      s_cubename TYPE RSINFOPROV,
      t_cell_data TYPE RRWS_T_CELL,
      t_axis_data TYPE RRWS_THX_AXIS_DATA,
      t_axis_info TYPE RRWS_THX_AXIS_INFO,
      wa_t_cell_data like line of t_cell_data,
      wa_t_axis_data like line of t_axis_data,
      w_corp_tab like line of t_cell_data.
    s_cubename = 'CORP_MPO1'.
    query_name = 'Z_corp_test'.
        CALL FUNCTION 'RRW3_GET_QUERY_VIEW_DATA'
           EXPORTING
             i_infoprovider           = s_cubename
             i_query                  = query_name
            i_t_parameter            = query_string_tab
           IMPORTING
             e_cell_data              = t_cell_data
             e_axis_data              = t_axis_data
             e_axis_info              = t_axis_info.
    If anyone has any information to help me, I would greatly appreciate it.  Thanks.

    Hi,
    <li>Once you call the function module RRW3_GET_QUERY_VIEW_DATA, lets say data is available in the corresponding tables e_cell_data e_axis_data which you have mentioned.
    <li>Modify your internal table defined for other purpose, with data from e_cell_data e_axis_data like below.
    LOOP AT t_cell_data INTO wa_t_cell_data.
      "Get the required data from t_cell_data.
      MOVE-CORRESPONDING wa_t_cell_data TO it_ur_tab.
      "Modify your internal table wih data
      MODIFY it_ur_tab TRANSPORTING <field1> <field2> <field3>.
    ENDLOOP.
    LOOP AT t_axis_data INTO wa_t_axis_data.
      "Get the required data from t_cell_data.
      MOVE-CORRESPONDING wa_t_axis_data TO it_ur_tab.
      "Modify your internal table wih data
      MODIFY it_ur_tab TRANSPORTING <field1> <field2> <field3>.
    ENDLOOP.
    Thanks
    Venkat.O

  • How to read data directly from clusters

    hi all,
    how to read data directly from clusters
    Thanx in advance,
    amruta.

    Using macro:
    RP-IMP-C2-B2.
    RP-IMP-C2-B1.
    RP-IMP-C2-ZL.
    ....etc.
    For TM cluster, U also can use BAPIs like HR_TIME_RESULTS_GET
    More details see SAP HR course 350(HR Programming)

  • How to read data from a CLUSTER STRUCTURE not cluster table.

    Hi,
    how to read data from a CLUSTER STRUCTURE not cluster table.
    regards,
    Usha.

    Hello,
    A structre doesnt contain data.. so u cannot read from it. U need to find out table of that structure and read data from it.
    Regards,
    Mansi.

  • How to read data from a file that was formatted by excel?

    Hi everyone, I'm familiar with java.io and the ability to read from files, can anyone tell me how to read data from a file that was formatted by excel? Or at least give me some web references so that I can learn about it?

    http://jakarta.apache.org/poi/hssf/index.html
    HSSF stands for Horrible Spreadsheet Format, but it still works!

  • How to read data from itab

    can someone help me with this....
    how to read data.....and move it to internal table....
    the requirement is as:
    <b>Get the Participant details in an internal table IT_FINAL_PAR</b>
    •     Loop through IT_PA0002 and move Personnel number (PERNR), Personnel ID Number (PERID), Last name  (NACHN), First name (VORNA), Gender Key (GESCH), Date of Birth (GBDAT) into a final internal table for Participant data IT_FINAL_PAR.
          Read the internal table IT_PA0006 to get the corresponding House Number and Street 
    (STRAS), City (ORT01), Postal code (PSTLZ), State (STATE), 2nd address line (LOCAT) by comparing Personnel Number (PERNR)and move those retrieved field values to the final internal table for Participant data IT_FINAL_PAR.

    Hi,
      you could try the following:
    * work areas
    data: W_PA0002 like line of IT_PA0002[],
          W_PA0006 like line of IT_PA0006[],
          W_FINAL_PAR like line of IT_FINAL_PAR[].
    loop at IT_PA0002 into W_PA0002.
      clear W_FINAL_PAR.
    * move values from IT_PA0002
      W_FINAL_PAR-PERNR = W_PA0002-PERNR.
      W_FINAL_PAR-PERID = W_PA0002-PERID.
    * read address values from IT_PA0006
      read table IT_PA0006 into W_PA0006 with key pernr = W_PA0002-pernr.
      if sy-subrc = 0.
    * move fields from IT_PA0006
        W_FINAL_PAR-STRAS = W_PA0006-STRAS.
      endif.
      append W_FINAL_PAR to IT_FINAL_PAR.
    endloop.

  • Help me,  How to read data from USB ???

    Help me, How to read data from USB ???

    If its a disk on key or some portable hard drive than once its connected to the usb and recognized by the system you can access it through java like you would access your hard drive.

  • How to read line number text from PDF using plugin?

    Hi, I would like to know how to read line number text from PDF using plugin?
    Thanks in advance.

    Ok, some background reading of the PDF Reference will help you understand why this is so difficult. PDF files are not organised into lines. It is best to think of each word or character on the page as being a graphic with its own position. The human eye sees lines where a series of graphics (words) are roughly in the same horizontal region.
    In the general case it is difficult or even impossible to answer this. You may have columns with different spacing (but the PDF stores no information on what is a column). You may have subscripts and superscripts. You may have text in graphics coinciding with other text. Commonly, there may be titles, headings or page numbers which are just ordinary text and might count as lines.
    That said, what you need to do is extract the text on the page and its positions. The WordFinder APIs are the way to do that. Now, sort all the words out, using the Y coordinates and size to try and guess what makes a "line". Now you are in a position to find the text (divided into words, not strings) and report the "line number" you have estimated.

  • JTable, how to read Data from it when enter is pressed

    How to read Data from JTable on Return or lost focus from cell.
    Also please tell me which listener I should should.
    thx for help

    You should read the tutorial about tables, cell editors and models.
    Also you should not [url http://forum.java.sun.com/thread.jsp?thread=472677&forum=57&message=2186815]crosspost
    Mike

  • A relative synced my iphone with his laptop without me knowing. It had a passcode on the phone but the sync still worked. I have since found out he is quite IT knowledgeable and has been known to track other peoples phones.  How is this data useful to him

    A relative synced my iphone with his laptop without me knowing. It had a passcode on the phone but the sync still worked. I have since found out he is quite IT knowledgeable and has been known to track other peoples phones that he wants to know information about.  How is my data useful to him and can he restore this data on another iPhone and run it parallel to mine? I have had people send me messages which I have not received. These have been screen shot to me later including time and I have just not got them. I had 4 weeks worth of messages go missing from my phone..I know that he synced my phone because his work laptops I'd came up in my settings. Also if the above can be done can he change the settings on my actual phone and access my location without placing tracking software on my phone.  Can someone please help here as I can't restore a backup to my phone for obvious reasons and refuse to change my number because of this loser.

    Connect the device to the computer.
    In iTunes, select the content desired to sync.
    Sync.
    This is all described in the User's Guide, reading it may be a good place to start.

  • How to read data after select multiple record by checkbox,

    hi experts
    i  m using simple report with check box , and itab whcih contain records
    how to read data after select multiple record by checkbox,
    thanks

    Hi Prashant,
       Try using this logic.This Code displays the list with check boxes. When you check a checkbox and press a button say 'Select All' or 'De Select all' or 'Display'. It will read the data of those records.
    DATA :
      fs_flight TYPE type_s_flight,
      fs_flight1 TYPE type_s_flight1.
    * Internal tables to hold Flight  Details                             *
    DATA :
      t_flight LIKE
      STANDARD TABLE
            OF fs_flight,
      t_flight1 LIKE
       STANDARD TABLE
             OF fs_flight1.
    SET PF-STATUS 'SELECT' .
    PERFORM selection.
    PERFORM displaybasic .
    *                      AT USER COMMAND EVENT                          *
    AT USER-COMMAND.
      PERFORM selectall .
    *&      Form  SELECTION
    *      Select query to reteive data from SPFLI table
    *  There are no interface parameters to be passed to this subroutine.
    FORM selection .
      SELECT  carrid                       " Airline Code
              connid                       " Flight Connection Number                  
        FROM  spfli
        INTO TABLE t_flight.
      DESCRIBE TABLE t_flight LINES w_lines .
    ENDFORM.                               " SELECTION
    *&      Form  DISPLAYBASIC
    *      Display the basic list with SPFLI data
    *  There are no interface parameters to be passed to this subroutine.
    FORM displaybasic .
      LOOP AT t_flight INTO fs_flight.
        WRITE :
             w_check AS CHECKBOX,
             w_mark,
             fs_flight-carrid UNDER text-001,
             fs_flight-connid UNDER text-002.
      ENDLOOP.                             " LOOP AT T_FLIGHT..
      CLEAR fs_flight-carrid .
      CLEAR fs_flight-connid.
    ENDFORM.                               " DISPLAYBASIC
    *&      Form  SELECTALL
    *      To check all the checkboxes with a 'selectall' push button
    *  There are no interface parameters to be passed to this subroutine.
    FORM selectall .
      CASE sy-ucomm.
        WHEN 'SELECT_ALL'.
          w_check = 'X'.
          w_line = 4 .
          DO w_lines TIMES.
            READ LINE w_line .
            MODIFY LINE w_line FIELD VALUE w_check .
            ADD 1 TO w_line .
          ENDDO.                           " DO W_LINES TIMES
          CLEAR w_line.
        WHEN 'DESELECTAL'.
          w_check = space.
          w_line = 4 .
          DO w_lines TIMES.
            READ LINE w_line FIELD VALUE w_mark .
            IF w_mark = space .
              MODIFY LINE w_line FIELD VALUE w_check .
            ENDIF.                         " IF W_MARK = SPACE
            ADD 1 TO w_line .
          ENDDO.                           " DO W_LINES TIMES
        WHEN 'DISPLAY'.
    IF sy-lilli BETWEEN 4 AND w_lines .
        DO w_lines TIMES.
          READ LINE w_num FIELD VALUE w_check INTO w_check
                                     fs_flight-carrid INTO fs_flight-carrid
                                     fs_flight-connid INTO fs_flight-connid.
          IF sy-subrc = 0.
            IF w_check = 'X'
              SELECT  carrid
                      connid
                      fldate               " Flight date
                      seatsmax             " Maximum capacity in economy
                      seatsocc             " Occupied seats in economy class
                FROM  sflight
                INTO  TABLE t_flight1
               WHERE  carrid = fs_flight-carrid
                 AND  connid = fs_flight-connid.
              LOOP AT t_flight1 INTO fs_flight1.
                WRITE :
                  / fs_flight-carrid UNDER text-001,
                    fs_flight-connid UNDER text-002,
                    fs_flight1-fldate UNDER text-007,
                    fs_flight1-seatsmax UNDER text-008,
                    fs_flight1-seatsocc UNDER text-009.
              ENDLOOP.
            ENDIF.                         " IF SY-SUBRC = 0
          ENDIF.                           " IF W_CHECK = 'X'.
          ADD 1 TO w_num.
        ENDDO.                             " DO W_LINES TIMES
        CLEAR w_check.
        w_num = 0.
      ELSE .
        MESSAGE 'INVALID CURSOR POSITION ' TYPE 'E' .
      ENDIF.                               " IF SY-LILLI BETWEEN..
    ENDCASE.                             " CASE SY-UCOMM
    ENDFORM.                               " SELECTALL
    Much Regards,
    Amuktha.

Maybe you are looking for