package it.integry.integrywmsnative.core.utility;

import java.text.SimpleDateFormat;
import java.util.Date;

public class UtilityDB {

    public static String valueToString(Object value) {
        String valueString;
        SimpleDateFormat dateFormatFile = new SimpleDateFormat("yyyy-MM-dd");

        if (value == null) {
            valueString = "NULL";
        } else {

            valueString = value.toString();

            if(value instanceof String) {
                if(UtilityString.isNullOrEmpty((String) value)){
                    valueString = "NULL";
                } else {
                    valueString = "'" + valueString.replaceAll("'","''") + "'";
                }
            } else if (value instanceof Date){
                valueString = "'" + dateFormatFile.format(value) + "'";
            } else if (value instanceof Integer) {

            } else {
                valueString = null;
            }
        }
        return valueString;
    }

}
