Not sure. You might not need to change anything. Or you might need to use
https://en.wikipedia.org/wiki/Left-to-right_mark
and maybe https://en.wikipedia.org/wiki/Right-to-left_mark (but I think not.)
For example
write(x);
write("\!n");
write("1",x,"\!U200E2");
/*:
واتساب ويب
1واتساب ويب2
\!U200E is JMP's representation of the Unicode Left-to-Right mark. You'd be adding that character to the string to make it print the way you expect, but it will mess up string compares later (maybe...who knows without testing...)
I still don't know the rules. Interested to know the answer too!
edit: when I said "you might not have to change anything" I meant some parsers might be perfectly happy with the text, which is probably laid out in exactly the character order you need in memory. I know it looks out of order when displayed, but that might not be how the SQL parser sees it.
more: from https://en.wikipedia.org/wiki/Bidirectional_text --
Unicode bidi support
The Unicode standard calls for characters to be ordered 'logically', i.e. in the sequence they are intended to be interpreted, as opposed to 'visually', the sequence they appear. This distinction is relevant for bidi support because at any bidi transition, the visual presentation ceases to be the 'logical' one. Thus, in order to offer bidi support, Unicode prescribes an algorithm for how to convert the logical sequence of characters into the correct visual presentation. For this purpose, the Unicode encoding standard divides all its characters into one of four types: 'strong', 'weak', 'neutral', and 'explicit formatting'.
Craige