ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Base64 Encode e decode

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Base64 Encode e decode

    HI all,

    I was trying the systools function base64 encode and decode but I have a little problem with the decode...

    here's a test case:

    Code:
    Create Table Testbase64(Rowid Int Not Null Generated Always As Identity (Start With 1, Increment By 1, No
    Cache), Fieldutf8 Varchar(4096) ccsid 1208 Not Null With Default, Fieldbase64 Varchar(4096) ccsid 1208 Not Null With Default);
    
    Insert Into Testbase64(Fieldutf8) Values ('Test base 64');
    
    Update Testbase64
    Set Fieldbase64 = Systools.Base64encode(Fieldutf8)
    Where Rowid = 1;
    
    Select *From testbase64;
    This is the result:
    1 Test base 64 VGVzdCBiYXNlIDY0
    Checking the result with the site: https://www.base64encode.org/

    it seems the same.

    Now I want to decode it, it seems simple, but I can't return to 'Test base 64'.

    What I'm doing wrong?
    Code:
     Update Testbase64
    Set Fieldutf8 = Systools.Base64decode(Fieldbase64)
    Where Rowid = 1;
    Many thanks

  • #2
    I found the solution obviously is simply after I found it... I was trying from Run Sql script of Ibm Acs, but if make a simple SQLRPGLE it works perfectly...

    Code:
    **FREE                                                             
    Ctl-Opt DftActGrp(*No)                                             
            ActGrp(*StgMdl)                                            
            StgMdl(*TeraSpace)                                         
            BndDir( 'QC2LE' : 'AL400MNUV2')                            
            DatFmt(*Iso) TimFmt(*Iso)                                  
            Alwnull(*UsrCtl)                                           
            Option(*SrcStmt:*NoDebugIo :*NoUnRef)                      
            Debug;                                                     
    
    Dcl-Pr DspLongMsg ExtPgm('QUILNGTX');                              
      Text      Char(16773100) const options(*varsize);                
      Length    Int(10)     const;                                     
      Msgid     Char(7)     const;                                     
      Qualmsgf  Char(20)    const;                                     
      ErrorCode Char(32767) options(*varsize);                         
    End-Pr;                                                            
    
    Dcl-Ds ErrorCode qualified;                                        
      bytesProv  Int(10) inz(0);                                       
      bytesAvail Int(10) inz(0);                                       
    End-Ds;                                                            
    
    Dcl-S FieldIn   Varchar(4096) CcsId(1208);                                
    Dcl-S FieldOut  Varchar(4096) CcsId(1208);                                
    
    FieldIn = 'The Answer my friend is blowing in the wind';                  
    DspLongMsg( FieldIn :%Len(FieldIn) :*blanks :*blanks : ErrorCode );       
    
    Exec Sql Set :FieldOut = Systools.Base64Encode(:FieldIn);                 
    DspLongMsg( FieldOut :%Len(FieldOut) :*blanks :*blanks : ErrorCode );     
    
    Exec Sql Set :FieldIn = Systools.Base64Decode(:FieldOut);                 
    DspLongMsg( FieldIn :%Len(FieldIn) :*blanks :*blanks : ErrorCode );       
    
    *InLr = *On;
    Why it doesn't works in my interactive sql?

    Bye

    Comment


    • #3
      'Run SQL Scripts' shouldn't be "interactive SQL" exactly, though it can make sense to think of it that way. To use "interactive SQL" specifically, use the STRSQL command in a terminal session. See if it all works there.
      Tom

      There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

      Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

      Comment

      Working...
      X