例如 sql
select 'operator_scenic_staytime_day', t.citycode, countycode, sceniccode, uuid, scenicname, sceniclevel, maxload, sceniclogo, staytime, people_num, format_time, updatetime, create_time from operator_scenic_staytime_day t where countycode = '130724' AND scenicname != 'xxxx';
'operator_scenic_staytime_day' 为表的名字grooy 代码:
import com.intellij.database.model.DasTable SEP = ", " QUOTE = "\'" NEWLINE = System.getProperty("line.separator") KEYWORDS_LOWERCASE = com.intellij.database.util.DbSqlUtil.areKeywordsLowerCase(PROJECT) KW_INSERT_INTO = KEYWORDS_LOWERCASE ? "insert into " : "INSERT INTO " KW_VALUES = KEYWORDS_LOWERCASE ? ") values (" : ") VALUES (" KW_NULL = KEYWORDS_LOWERCASE ? "null" : "NULL" def record(columns, dataRow) { OUT.append(KW_INSERT_INTO) if (TABLE == null) { // 第一列 作为 表的名字! OUT.append(FORMATTER.format(dataRow, columns[0])) } else { OUT.append(TABLE.getParent().getName()).append(".").append(TABLE.getName()) } OUT.append(" (") columns.eachWithIndex { column, idx -> if(idx == 0){ // 排除第一列 return; } OUT.append(column.name()).append(idx != columns.size() - 1 ? SEP : "") } OUT.append(KW_VALUES) columns.eachWithIndex { column, idx -> if(idx == 0){ // 排除第一列 return; } def value = dataRow.value(column) def skipQuote = value.toString().isNumber() || value == null def stringValue = value != null ? FORMATTER.format(dataRow, column) : KW_NULL if (DIALECT.getDbms().isMysql()) stringValue = stringValue.replace("\\", "\\\\") OUT.append(skipQuote ? "": QUOTE).append(stringValue.replace(QUOTE, QUOTE + QUOTE)) .append(skipQuote ? "": QUOTE).append(idx != columns.size() - 1 ? SEP : "") } OUT.append(");").append(NEWLINE) } ROWS.each { row -> record(COLUMNS, row) }