<commit_before>package com.smart.framework.helper;

import com.smart.framework.annotation.Table;
import com.smart.framework.util.ArrayUtil;
import com.smart.framework.util.FileUtil;
import com.smart.framework.util.MapUtil;
import com.smart.framework.util.StringUtil;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SQLHelper {

    private static final Properties sqlProperties = FileUtil.loadPropFile("sql.properties");

    public static String getSQL(String key) {
        String value = "";
        if (sqlProperties.containsKey(key)) {
            value = sqlProperties.getProperty(key);
        } else {
            System.err.println("Can not get property [" + key + "] in sql.properties file.");
        }
        return value;
    }

    public static String generateSelectSQL(Class<?> cls, String condition, Object... params) {
        StringBuilder sql = new StringBuilder("select * from ").append(getTable(cls));
        sql.append(generateWhere(condition, params));
        return sql.toString();
    }

    public static String generateInsertSQL(Class<?> cls, Map<String, Object> fieldMap) {
        StringBuilder sql = new StringBuilder("insert into ").append(getTable(cls));
        if (MapUtil.isNotEmpty(fieldMap)) {
            int i = 0;
            StringBuilder columns = new StringBuilder(" ");
            StringBuilder values = new StringBuilder(" values ");
            for (Map.Entry<String, ?> fieldEntry : fieldMap.entrySet()) {
                String columnName = StringUtil.camelhumpToUnderline(fieldEntry.getKey());
                Object columnValue = fieldEntry.getValue();
                if (i == 0) {
                    columns.append("(").append(columnName);
                    values.append("('").append(columnValue).append("'");
                } else if (i == fieldMap.size() - 1) {
                    columns.append(", ").append(columnName).append(")");
                    values.append(", '").append(columnValue).append("')");
                } else {
                    columns.append(", ").append(columnName);
                    values.append(", '").append(columnValue).append("'");
                }
                i++;
            }
            sql.append(columns).append(values);
        }
        return sql.toString();
    }

    public static String generateDeleteSQL(Class<?> cls, String condition, Object... params) {
        StringBuilder sql = new StringBuilder("delete from ").append(getTable(cls));
        sql.append(generateWhere(condition, params));
        return sql.toString();
    }

    public static String generateUpdateSQL(Class<?> cls, Map<String, Object> fieldMap, String condition, Object... params) {
        StringBuilder sql = new StringBuilder("update ").append(getTable(cls));
        if (MapUtil.isNotEmpty(fieldMap)) {
            sql.append(" set ");
            int i = 0;
            for (Map.Entry<String, ?> fieldEntry : fieldMap.entrySet()) {
                String columnName = StringUtil.camelhumpToUnderline(fieldEntry.getKey());<commit_msg>【B】修复：当只有一列时，生成的 insert 语句错误<commit_after>package com.smart.framework.helper;

import com.smart.framework.annotation.Table;
import com.smart.framework.util.ArrayUtil;
import com.smart.framework.util.FileUtil;
import com.smart.framework.util.MapUtil;
import com.smart.framework.util.StringUtil;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SQLHelper {

    private static final Properties sqlProperties = FileUtil.loadPropFile("sql.properties");

    public static String getSQL(String key) {
        String value = "";
        if (sqlProperties.containsKey(key)) {
            value = sqlProperties.getProperty(key);
        } else {
            System.err.println("Can not get property [" + key + "] in sql.properties file.");
        }
        return value;
    }

    public static String generateSelectSQL(Class<?> cls, String condition, Object... params) {
        StringBuilder sql = new StringBuilder("select * from ").append(getTable(cls));
        sql.append(generateWhere(condition, params));
        return sql.toString();
    }

    public static String generateInsertSQL(Class<?> cls, Map<String, Object> fieldMap) {
        StringBuilder sql = new StringBuilder("insert into ").append(getTable(cls));
        if (MapUtil.isNotEmpty(fieldMap)) {
            int i = 0;
            StringBuilder columns = new StringBuilder(" ");
            StringBuilder values = new StringBuilder(" values ");
            for (Map.Entry<String, Object> fieldEntry : fieldMap.entrySet()) {
                String columnName = StringUtil.camelhumpToUnderline(fieldEntry.getKey());
                Object columnValue = fieldEntry.getValue();
                if (i == 0) {
                    columns.append("(").append(columnName);
                    values.append("('").append(columnValue).append("'");
                } else {
                    columns.append(", ").append(columnName);
                    values.append(", '").append(columnValue).append("'");
                }
                if (i == fieldMap.size() - 1) {
                    columns.append(")");
                    values.append(")");
                }
                i++;
            }
            sql.append(columns).append(values);
        }
        return sql.toString();
    }

    public static String generateDeleteSQL(Class<?> cls, String condition, Object... params) {
        StringBuilder sql = new StringBuilder("delete from ").append(getTable(cls));
        sql.append(generateWhere(condition, params));
        return sql.toString();
    }

    public static String generateUpdateSQL(Class<?> cls, Map<String, Object> fieldMap, String condition, Object... params) {
        StringBuilder sql = new StringBuilder("update ").append(getTable(cls));
        if (MapUtil.isNotEmpty(fieldMap)) {
            sql.append(" set ");
            int i = 0;
            for (Map.Entry<String, ?> fieldEntry : fieldMap.entrySet()) {
                String columnName = StringUtil.camelhumpToUnderline(fieldEntry.getKey());
{'fraction_non_alphanumeric': 0.12992253066494514, 'fraction_numerical': 0.0012911555842479018, 'mean_word_length': 2.4542920847268674, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3951998', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1597, 'n_words': 361}