Using ENCODE/DECODE on a field in MySQL on Form Applications

Hi All,

I am looking for a way to tell SC to use MySQL’s ENCODE() function on a form field “Credit Card Number” when I insert or update a record. Conversely, I also need to be able to use MySQL’s DECODE() function when retrieving a record with the “Credit Card Field.”

Any advice?

Unlike some of the other application types, Forms in SC seem to be tightly structured and don’t allow me to modify the SQL query manually.

Perhaps there’s some other method that I’m missing.

Thanks

Jim

Hi, anyone? Thanks

If you are forced to use MYSQL functions, a workaround could be:

onNavigate Event:

$query = "
	SELECT 
	  DECODE(credit_card_field)
	FROM 
          table
	WHERE 
          id={id}";
	
sc_lookup(rs, $query);
{credit_card_field} =  {rs[0][0]};

onBeforeInsert and onBeforeUpdate Events:

$query = "
	SELECT 
	  ENCODE({credit_card_field})
	FROM 
          DUAL";
	
sc_lookup(rs, $query);
{credit_card_field} =  {rs[0][0]};

Thanks, Giu! That’s the workaround I ended up using… I was hoping there was a cleaner way to use MySQL functions … like on the Edit Fields page allowing the user to “force value” the wrapping of the field in a function.

Appreciate your help!

Jim