package com.sysu.admin.utils;

public class SqlUtil {

    public static String ArrayToInSql(String before, String col, String[] ids){
        StringBuilder sb = new StringBuilder();
        if(ids != null && ids.length > 0){
            sb.append(before).append(" ").append(col);
            sb.append(" IN (");
            for(int i = 0; i < ids.length; i++){
                sb.append("'");
                sb.append(ids[i]);
                sb.append("'");
                if(i != ids.length - 1){ //不是最后一个元素，加上逗号
                    sb.append(",");
                }
            }
            sb.append(")");
        }
        return sb.toString();
    }

    public static String ArrayToInSql(String before, String col, Number[] ids){
        StringBuilder sb = new StringBuilder();
        if(ids != null && ids.length > 0){
            sb.append(before).append(" ").append(col);
            sb.append(" IN (");
            for(int i = 0; i < ids.length; i++){
                sb.append(ids[i]);
                if(i != ids.length - 1){ //不是最后一个元素，加上逗号
                    sb.append(",");
                }
            }
            sb.append(")");
        }
        return sb.toString();
    }

}
