stykalin / toggle-oracle-uuid-plugin

MIT License
1 stars 0 forks source link

Incorrect Oracle Guid conversion #1

Open egidioadf opened 2 weeks ago

egidioadf commented 2 weeks ago

When converting the value "AF7565DDB6C649A1840E6008432D7D92" to Guid, the plugin is converting it to "af7565dd-b6c6-49a1-840e-6008432d7d92", but the correct value would be: DD6575AF-C6B6-A149-840E-6008432D7D92 as we can see on the website:

https://robobunny.com/cgi-bin/guid

image

image

stykalin commented 2 weeks ago

Thank you for your interest in the plugin and for your feedback.

Firstly, I would like to clarify that the plugin is not related to the website https://robobunny.com/cgi-bin/guid. Its main purpose is to convert UUID values to a hyphenated format, which is used in JVM languages. The case of the input does not matter in this context.

However, I understand that it would be useful to add additional conversion formats, such as the one you mentioned. Thank you for direction. I will consider this idea and may implement additional options for selecting the desired format in future updates.

In the meantime, I recommend using the shortcut Ctrl + Shift + U in IntelliJ products to toggle case for words at the caret or selected block. This is a temporary workaround until the plugin is updated.

Thank you for taking the time to share your suggestions.

egidioadf commented 2 weeks ago

I understand that the plugin is not related to the site, I cited the site to exemplify that I use it on a daily basis to perform the conversion, when I found your plugin I saw that it could speed up my work a lot.

In databases where I have permission I use two functions directly in Oracle, but in databases where I only have Select permission I use the site for conversion.

The shortcut you mentioned doesn't work for me because it only switches between upper and lower case, what I need is the conversion from Guid to Raw and vice versa. Thank you for your reply and if there is an update to the plugin for this format, it would be very useful.

Here are the functions I use in Oracle.

CREATE FUNCTION FC_GUID_TO_RAW(p_guid VARCHAR2) RETURN RAW IS
    v_raw RAW(16);
BEGIN
    -- Convert the GUID string to a RAW format considering endianness
    v_raw := HEXTORAW(
              SUBSTR(p_guid, 7, 2) ||
              SUBSTR(p_guid, 5, 2) ||
              SUBSTR(p_guid, 3, 2) ||
              SUBSTR(p_guid, 1, 2) ||
              SUBSTR(p_guid, 12, 2) ||
              SUBSTR(p_guid, 10, 2) ||
              SUBSTR(p_guid, 17, 2) ||
              SUBSTR(p_guid, 15, 2) ||
              SUBSTR(p_guid, 20, 4) ||
              SUBSTR(p_guid, 25)
            );

    RETURN v_raw;
END FC_GUID_TO_RAW;
/
CREATE FUNCTION FC_RAW_TO_GUID(p_raw RAW) RETURN VARCHAR2 IS
    v_hex VARCHAR2(32);
BEGIN
    -- Convert RAW to hexadecimal
    v_hex := RAWTOHEX(p_raw);

    -- Format hexadecimal to GUID format using little-endian and big-endian as appropriate
    RETURN SUBSTR(v_hex, 7, 2) ||
           SUBSTR(v_hex, 5, 2) ||
           SUBSTR(v_hex, 3, 2) ||
           SUBSTR(v_hex, 1, 2) || '-' ||
           SUBSTR(v_hex, 11, 2) ||
           SUBSTR(v_hex, 9, 2) || '-' ||
           SUBSTR(v_hex, 15, 2) ||
           SUBSTR(v_hex, 13, 2) || '-' ||
           SUBSTR(v_hex, 17, 4) || '-' ||
           SUBSTR(v_hex, 21);
END FC_RAW_TO_GUID;
/