Text (uni)coding issue

Monte Goulding monte at appisle.net
Sat Aug 26 18:23:58 EDT 2017


Howdy Andrew

There’s a few things to deal with here.

- you need to know your database encoding (let’s assume UTF-8)

- you need to get values out of your database in a way that gives you the binary data rather than strings that the engine has assumed  were in native encoding. Use:

local tCursor
put "SELECT * FROM promosRedeemed" into tSql
put revQueryDatabase(sDbId, tSql) into tCursor
local tResults
repeat until revQueryIsAtEnd(tCursor)
      repeat for each item tColumn in revDatabaseColumnNames(tCursor)
           local tValue
           get revDatabaseColumnNamed(tCursor, tColumn, “tValue”)
           put textDecode(tValue,”UTF-8”) into tValue
           replace return with “ -=- “ in tValue  // ACCOUNTS FOR LINE BREAKS IN DATA
           put tValue  & tab after tResults
      end repeat
      put return into the last char of tResults
      revMoveToNextRecord tCursor
end repeat
revCloseCursor tCursor

- you need to write this file in an encoding you know so you can decode it when you download:

put "redemption-log_" & the seconds & ".txt" into tFileName
put textEncode(tResults, “UTF-8”) into url (“binfile:” & specialFolderPath("home") & "/public_html/server/apps/iot/logs/" & tFileName)

- you need to read the file and decode from the encoding you know it is in:

put textDecode(url (“binfile:” & <local path>), “UTF-8”) into tResults

Disclaimer: this code has just been written into an email client untested so may have some errors.

Cheers

Monte



More information about the use-livecode mailing list