ubbase64 – manage blobs

NAME

ubbase64 – store and retrieve a blob in a table using base64 encoding

SYNOPSIS

ubbase64 –function get|put –attribute <attribute> –key <key> –match <match> {–format html|textarea} <table>

DESCRIPTION

ubbase64 is used to store and retrieve BLOBs (binary large objects) in a Unibase table.

Typically this is used to store random text and images, but can be used for anything.

The table to be used for storage needs to have a specific format. Two attributes, the first being the index attribute and the second an attribute of that is used to store the base64 encoded BLOB. This storage attribute can be any suitable lenght. Typically this will be 60-100 characters for small blobs but may be 1000+ for large blobs. Wasted space will be attribute size / 2 on average.

e.g.

: note
noteNumber, 6
note, 60
>
noteNumber
>
>
>

A separate table is normally used to hold meta information about the note.

Unibase guarantees the order of data stored so there is no need to be more specific about the indexes.

To store a BLOB you must specify the function as put and the attribute to store the BLOB in, the key in the table, the match value, and the table name.

When storing data ubbase64 reads stdin for data.

To retrieve a blob use the function get along with the other attributes.

The retrieved BLOB is output on stdout.

ubbase64 can also format a text BLOB so that it is suitable for display in html (–format html) or for use in a textarea input (–format textarea).

If no –format option is given then ubbase64 will return the original object.

ARGUMENTS

FlagArgumentDescriptionRequired
–attribute<text>database attribute used to save BLOBYes
–functionget|put get (retrieve) or put (save)Yes
–formathtml|textareahtml or textarea. Used for editing in Unibase forms (prompts)
No
–jsonoutput as JSON array. Each record is in the format {“key”: “…”, “data”: “…”}No
–key<text> name of key to matchYes
–keyvalueoutput is Tcl key/value list {{key} {data}}No
–match<text> value to matchNo
–miniHTMLminify HTML. If the output format is HTML (or XML) this will remove whitespace after ‘>’ and before ‘<‘. Whitespace is the characters \n, space, and tab.
Note this is not perfect as white space following > is valid if the element is inline. Expect this to improve over time.
No
–newlineadd a newline character after each extracted record.
This can help with readability when searching for a large number of entries.
No
–replace<tcl replacement pattern>pattern to replace search pattern.
Tcl regexps are different to standard regexps primarily in the grouping syntax – ( … ) instead of \( …\) and the standard use of alternative patterns (egrep style).
No
–search<tcl regular expression>search for text pattern in blobNo
–updateupdate blob with replacement patternNo

Examples

  • Retrieve the description
    • ubbase64 –function get –key style_id –attribute descriptionHTML –match 006407 styleDescriptionHTML
  • Retrieve and minifi the HTML
    • ubbase64 –function get –key style_id –attribute descriptionHTML –match 006407 –minHTML styleDescriptionHTML
  • Retrieve all descriptions
    • ubbase64 –function get –key style_id –attribute descriptionHTML styleDescriptionHTML
  • Retrieve all descriptions with an html link
    • ubbase64 –function get –key style_id –attribute descriptionHTML –search ‘<a href=[^>]*>[^<]*</a>’ styleDescriptionHTML
  • Find all descriptions with links and remove the link element but preserve the link text (note the ( ) around the text to be saved)
    • ubbase64 –function get –key style_id –attribute descriptionHTML –search ‘<a href=[^>]*>([^<]*)</a>’ –replace ‘\1’ –newline –keyvalue styleDescriptionHTML
  • Do the same and update the description
    • ubbase64 –function get –key style_id –attribute descriptionHTML –search ‘<a href=[^>]>([^<])</a>’ –replace ‘\1’ –update –newline styleDescriptionHTML