• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

Boolean Fields

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

  • Boolean Fields

    What is the best way to handle boolean fields? Usually we create a one character field and put Y or N in the field. Auto Code doesn't seem to have a way to identify those fields as boolean. Is there a parameter in vvOut that I can use to identify these fields as boolean so that execSQLtoJSON will treat them that way?

  • #2
    Probably your best approach on the back-end would be to modify the SQL statement to use a case clause to convert your Y/N values into boolean true/false equivalents. The execSQLtoJSON procedure will recognize the 'true' and 'false' strings as booleans and thus not encapsulate them in quotes on the response.

    For example, in the Valence VVUSERS file there is a VVACTIV flag set to '1' or '0' to indicate enabled or disabled users, respectively. If I wanted to return that as a boolean value to the front-end I could do something like this in my RPG program:
    Code:
    stmt='select vvloginid, '
                'case when vvactiv=''1'' then ''true'' '+
                                        'else ''false'' end as active '+    
          'from vvusers '+                                          
         'order by vvloginid';                                      
    vvOut_execSQLtoJSON(vvout:stmt);
    This would return a JSON response that looks something like this:

    HTML Code:
    {"dataRoot":[{"VVLOGINID":"USER1","ACTIVE":false},{"VVLOGINID":"USER2","ACTIVE":true},{"VVLOGINID":"USER3","ACTIVE":true},{"VVLOGINID":"USER4","ACTIVE":false}],"totalCount":4}
    That said, I like your idea of being able to flag a field in AutoCode as boolean, so it would make the SQL statement adjustments for you accordingly. I've added this to our feature request list for Valence 5.1.

    Comment

    Working...
    X