1

We are handling a legacy code which based on Team Developer 2005.1

There is a query like

  !!CB!! 70
Set sSqlCommand = '
            SELECT  name, value
            INTO    :sName, :sValue
            FROM    av_system_settings
            WHERE   name LIKE \'Company_\%\''
If NOT SqlPrepareAndExecute( hSqlMain, sSqlCommand )
    Return FALSE
Loop
    If SqlFetchNext( hSqlMain, nFetch )
    ...

Here the into variable :sName, :sValue are Strings but it always have empty value although the record has been looped correctly through SqlFetchNext

The into variable on other place are all fine. Just not working here one place.

Have run out of brain on this... Any idea? Guys :)

Zhe Yang
  • 45
  • 5

2 Answers2

1
  1. For testing, you can use SqlImmediate(sSqlCommand ) instead of sqlprepareandexecute( ). If sName and sValue have value after executing sqlImmediate means sql working fine.
  2. Make sure SqlConnect() function returns true value. If it returns false then make sure database creditionals are correct.
  3. If the sValue variable need to hold Long data then please have a look on SqlSetLongBindDatatype ( ) function.

  4. Check the value of sql handle hsqlMain, if it have a postive value or one it means that handle connected properly. Otherwise if the handle value is null or zero, it means handle not connected.

  5. Try to use SqlFetchRow ( hsqlMain, nRow, nFetch ) and increment the value of nRow by 1 till function return false or the value of nFetch becomes FETCH_EOF.

    Set nRow = 0 While (TRUE) If not SqlFetchRow( hsqlMain, nRow, nFetch ) Break Set nRow = nRow + 1

Chandralal
  • 559
  • 2
  • 11
  • 26
  • 1
    It turns out that the issue was caused by case #3 in answer: the data field is longer than 254 but `String` variable type were used with INTO... After changing them to `Long String`, it's working now. Thanks! – Zhe Yang Jan 20 '18 at 08:32
  • Glad it helped!. Please, consider accepting the best answer. – Chandralal Jan 23 '18 at 14:21
0

Check nFetch after SqlFetchNext to be sure a record was found.

If nFetch = FETCH_Ok , a record was found. So try calling SqlVarSetup(hSqlMain) before the SqlFetchNext , so the into vars have context. Also try qualifying the into vars e.g. :hWndForm.frmTest.sName .

If nFetch = FETCH_EOF , no record was found .

Steve Leighton
  • 790
  • 5
  • 15