private String[] getInsertUpdateSql( ColumnTypeHelper helper, WriteRowsEvent event, RDBSchnauzer rep) throws UnsupportedEncodingException { List<Row> rows = event.getRows(); BitColumn bCol = event.getUsedColumns().clone(); String InsertSql = rep.getInsertFields(bCol); String[] sql = new String[rows.size()]; rep.setUsedColumn(bCol); byte[] unsigntags = rep.getUnsignedTags(); String rowSql = ""; if (Tags.Verbose) LOGGER.info(rows.size() + Infos.Row); int index = 0; String cuid = ""; for (int j = 0; j < rows.size(); j++) { rowSql = ""; Row row = rows.get(j); List<Column> columns = row.getColumns(); if (!rep.needReplicate(columns)) continue; cuid = getCuid(rep); rowSql = InsertSql + "(" + helper.getValueStr(columns, bCol, unsigntags, rep.getFullFields()) + rep.getDefStr() + cuid + ")"; rowSql += " ON duplicate KEY UPDATE " + helper.getUpdataStr(columns, rep.getColumnNames(), unsigntags, rep.getFullFields()); sql[index++] = rowSql; } return sql; }
private String[] getCommInsertSql(ColumnTypeHelper helper, WriteRowsEvent event, RDBSchnauzer rep) throws UnsupportedEncodingException { List<Row> rows = event.getRows(); BitColumn bCol = event.getUsedColumns().clone(); String[] sql = new String[1]; sql[0] = rep.getInsertFields(bCol); rep.setUsedColumn(bCol); byte[] unsigntags = rep.getUnsignedTags(); String sqlValue = ""; if (Tags.Verbose) LOGGER.info(rows.size() + Infos.Row); String cuid = ""; for (int j = 0; j < rows.size(); j++) { Row row = rows.get(j); List<Column> columns = row.getColumns(); if (!rep.needReplicate(columns)) continue; if (!sqlValue.isEmpty()) sqlValue += ","; cuid = getCuid(rep); sqlValue += "(" + helper.getValueStr(columns, bCol, unsigntags, rep.getFullFields()) + rep.getDefStr() + cuid + ")"; } if (sqlValue.isEmpty()) { sql[0] = ""; return sql; } sql[0] += sqlValue; return sql; }
private String[] getInsUpSqlSql(ColumnTypeHelper helper, WriteRowsEvent event, RDBSchnauzer rep) throws UnsupportedEncodingException { List<Row> rows = event.getRows(); BitColumn bCol = event.getUsedColumns().clone(); String InsertSql = rep.getInsertFields(bCol); String sIfExistPre = " set nocount off if not exists(select 1 from " + rep.getSlaveTableName() + " where "; String updatePre = " UPDATE " + rep.getSlaveTableName() + " SET "; String[] sql = new String[rows.size() * 4]; rep.setUsedColumn(bCol); byte[] unsigntags = rep.getUnsignedTags(); String rowSql = ""; if (Tags.Verbose) LOGGER.info(rows.size() + Infos.Row); int index = 0; for (int j = 0; j < rows.size(); j++) { rowSql = ""; Row row = rows.get(j); List<Column> columns = row.getColumns(); if (!rep.needReplicate(columns)) continue; rowSql = sIfExistPre + getWhereStr(rep, columns, helper) + ") "; String cuid = getCuid(rep); rowSql += InsertSql + "(" + helper.getValueStr(columns, bCol, unsigntags, rep.getFullFields()) + rep.getDefStr() + cuid + ")"; rowSql += " else "; rowSql += updatePre + helper.getUpdataStr(columns, rep.getColumnNames(), unsigntags, rep.getFullFields()) + " where " + getWhereStr(rep, columns, helper) + " "; sql[index++] = rowSql; } return sql; }