Menu

#428 (ok 3.3) Use hex for (var)binary fields

closed-accepted
None
1
2010-03-07
2008-11-18
No

Hi,

Could you use hex for (var)binary fields, both when displaying and editing them?
Currently you're showing them as text, but those fields most likely don't contain valid UTF-8 characters.

Discussion

  • Maarten

    Maarten - 2009-08-20

    I've added this feature because we wanted to view and insert UUIDs as binary. I couldn't commit it to svn (no account/permission?), so here's the patch:
    http://www.mediafire.com/?sharekey=5b2f3f8cf8374a2d07258ee67c679e4ae04e75f6e8ebb871

    The setting is adjustable in the display table options and can be switched on by default using the DisplayBinaryAsHex config option

     
  • Marc Delisle

    Marc Delisle - 2009-08-20

    patch from maatendieleman

     
  • Marc Delisle

    Marc Delisle - 2009-08-20
    • labels: 509122 -->
     
  • Marc Delisle

    Marc Delisle - 2009-08-20

    Moved to Patches

     
  • Marc Delisle

    Marc Delisle - 2009-09-03
    • assigned_to: nobody --> lem9
     
  • Marc Delisle

    Marc Delisle - 2009-09-03

    Hello Maarten,
    in browse mode your patch works fine, however when editing, showing hex may bring a problem if the user changes the hex values.

     
  • Maarten

    Maarten - 2009-09-05

    Not 100% sure what you mean, browsing as well as editing in hex is the sole purpose of this patch. If you have binary values exceeding the encoding range of your character set (most likely utf-8), the browser cannot display them correctly thus changing the actual value when 're-saving' such a record even when you haven't actually changed the data yourself. This is by all means very very bad. Editing and saving binary values in hex format keeps the value 'as-is' at all times and makes it possible to copy-paste binary-hex values to and from the database (and other records) which is not possible when displaying binary data in any character encoding that cannot handle such values (this includes utf-8).

    So 'changing the hex values' is exactly what you want, if the user is incapable of editing hex values correctly then they shouldn't be using a database administration tool with binary fields in the first place :) But they could also just switch the 'show binary as hex' option off (in the table options) to display and edit the binary values as usual.

    Hope this clarifies things!

     
  • Marc Delisle

    Marc Delisle - 2009-09-05

    Ok, here is what I tested. My config is
    $cfg['ProtectBinary'] = false;
    I have a table with a VARBINARY field. I put the value abc in it. Now when I tick the new option, it shows 616263. If I edit this, changing 63 by 64 because I'm editing in hex and I want the field to contain abd, the result is that my field now contains 363136323634.

     
  • Maarten

    Maarten - 2009-09-05

    Then most likely there is a problem with your installation (other version that interferes with this patch maybe?). When 'display binary as hex' is on, in edit mode, the patch sets the default function for binary fields to UNHEX which turns the hex value into binary. It appears that your installation doesn't set the function to UNHEX which makes it put in the hex value as the true binary value.

    The default function is set in tbl_change.php on line 543 based on the field variable of 'display_binary_as_hex' which is set on line 443 after detecting that the field is binary.
    (not sure if the line numbers match on your end, but it's easy to spot)

     
  • Marc Delisle

    Marc Delisle - 2009-09-05

    Ok, with the default value of
    $cfg['ShowFunctionFields'] = true;
    this works; the problem happens if this is set to false, or if the user chooses not to display the Function column. In these cases, the UNHEX() is not applied.

     
  • Marc Delisle

    Marc Delisle - 2009-09-05

    Merged in subversion, thanks.

     
  • Marc Delisle

    Marc Delisle - 2009-09-05
    • priority: 5 --> 1
    • summary: Use hex for (var)binary fields --> (ok 3.3) Use hex for (var)binary fields
    • status: open --> open-accepted
     
  • Maarten

    Maarten - 2009-09-06

    Great! Thanks.

     
  • Olaf van der Spek

    Could "Show binary contents as HEX" be enabled by default?
    Otherwise you're still showing invalid UTF-8 (and useless data).

     
  • Maarten

    Maarten - 2010-01-15

    You can use this config option in config.inc.php to enable it by default:
    $cfg['DisplayBinaryAsHex'] = true;

     
  • Olaf van der Spek

    I'm asking for that to be done by default. ;)

     
  • Marc Delisle

    Marc Delisle - 2010-01-19

    Thanks Olaf. In fact I had forgotten to define this in config.default.php. Now defined with true value.

     
  • Marc Delisle

    Marc Delisle - 2010-03-07
    • status: open-accepted --> closed-accepted
     
MongoDB Logo MongoDB