@Override
  public boolean doWrite(ColumnTypeHelper helper, WriteRowsEvent event) {

    /*
    if (helper.position<=120619669)
    	LOGGER.info("begin");
    else if 	(helper.position>=123198439) {
    	LOGGER.info("end");
    	return true;
    }
    */

    boolean doOne = false;
    String[] sqls = null;
    int index = 0;
    doBeforeWrite(helper, event);
    for (int i = 0; i < tables.size(); i++) {
      ITableReplicator rep = tables.get(i);
      if (notEqualS(helper.databaseName, masterDb.dbname)) continue;
      if (notEqualS(helper.tableName, rep.getMasterTableName())) continue;
      String[] rowsqls = null;
      try {
        rowsqls = getInsertSql(helper, event, rep);
      } catch (Exception e) {
        mailAndLog(Infos.Create + Infos.DoInsert + Infos.Failed, e.getMessage());
        return false;
      }
      if (sqls == null) {
        sqls = new String[tables.size() * event.getRows().size() * 4 + 1];
        sqls[0] = getStatusUpdateSql(helper);
      }
      for (int r = 0; r < rowsqls.length; r++) {
        if ((rowsqls[r] == null) || (rowsqls[r].isEmpty())) continue;
        sqls[++index] = rowsqls[r];
        doOne = true;
      }
    }

    if (!doOne || !logSql(sqls)) {
      autoSetPosition(helper);
      return true;
    }

    String[] errInfo = new String[1];
    if (doInsert(sqls, errInfo)) {
      this.slaveDb.binlog = this.getBinLogName(helper);
      this.slaveDb.pos = helper.position;
      this.slaveDb.tablepos = helper.tableMapPos;
      if (Tags.Verbose) LOGGER.info(Infos.DoInsert + Infos.OK);
      return true;
    }
    String sInfo = getWarning(sqls, errInfo);
    mailAndLog(Infos.DoInsert + Infos.Failed, sInfo);
    rollBackToTableEvent(helper);
    return false;
  }
 private String[] getInsertSql(ColumnTypeHelper helper, WriteRowsEvent event, ITableReplicator rep)
     throws UnsupportedEncodingException {
   RDBSchnauzer table = (RDBSchnauzer) rep;
   if (rep.isMergeTable() && slaveDb.isMySQL()) {
     return getInsertUpdateSql(helper, event, table);
   } else if (rep.isMergeTable() && slaveDb.isSQLServer()) {
     return getInsUpSqlSql(helper, event, table);
   } else if (this.slaveDb.isSQLServer2000()) {
     return getSql2000Sql(helper, event, table);
   } else {
     return getCommInsertSql(helper, event, table);
   }
 }
 private String getWhereStr(ITableReplicator rep, List<Column> columns, ColumnTypeHelper helper)
     throws UnsupportedEncodingException {
   String sql = "";
   int[] indexs = rep.getKeyFieldIndexs();
   byte[] unsigntags = rep.getUnsignedTags();
   int pos = 0;
   for (int i = 0; i < indexs.length; i++) {
     pos = indexs[i];
     if (!sql.isEmpty()) sql += " and ";
     sql +=
         rep.getIDName(i)
             + "="
             + helper.getColStr(
                 pos, columns.get(pos), unsigntags[pos], rep.getFullFields().get(pos));
   }
   return sql;
 }