protected String getWhereClause(
      InsertOrUpdateStatement insertOrUpdateStatement, Database database) {
    StringBuffer where = new StringBuffer();

    String[] pkColumns = insertOrUpdateStatement.getPrimaryKey().split(",");

    for (String thisPkColumn : pkColumns) {
      where
          .append(
              database.escapeColumnName(
                  insertOrUpdateStatement.getSchemaName(),
                  insertOrUpdateStatement.getTableName(),
                  thisPkColumn))
          .append(" = ");
      Object newValue = insertOrUpdateStatement.getColumnValues().get(thisPkColumn);
      if (newValue == null || newValue.toString().equals("NULL")) {
        where.append("NULL");
      } else if (newValue instanceof String && database.shouldQuoteValue(((String) newValue))) {
        where.append("'").append(database.escapeStringForDatabase((String) newValue)).append("'");
      } else if (newValue instanceof Date) {
        where.append(database.getDateLiteral(((Date) newValue)));
      } else if (newValue instanceof Boolean) {
        if (((Boolean) newValue)) {
          where.append(
              TypeConverterFactory.getInstance()
                  .findTypeConverter(database)
                  .getBooleanType()
                  .getTrueBooleanValue());
        } else {
          where.append(
              TypeConverterFactory.getInstance()
                  .findTypeConverter(database)
                  .getBooleanType()
                  .getFalseBooleanValue());
        }
      } else {
        where.append(newValue);
      }

      where.append(" AND ");
    }

    where.delete(where.lastIndexOf(" AND "), where.lastIndexOf(" AND ") + " AND ".length());
    return where.toString();
  }
 // Copied from liquibase.sqlgenerator.core.InsertOrUpdateGeneratorMySQL
 private String convertToString(Object newValue, Database database) {
   String sqlString;
   if (newValue == null
       || newValue.toString().equals("")
       || newValue.toString().equalsIgnoreCase("NULL")) {
     sqlString = "NULL";
   } else if (newValue instanceof String
       && !looksLikeFunctionCall(((String) newValue), database)) {
     sqlString = "'" + database.escapeStringForDatabase(newValue.toString()) + "'";
   } else if (newValue instanceof Date) {
     sqlString = database.getDateLiteral(((Date) newValue));
   } else if (newValue instanceof Boolean) {
     if (((Boolean) newValue)) {
       sqlString = DataTypeFactory.getInstance().getTrueBooleanValue(database);
     } else {
       sqlString = DataTypeFactory.getInstance().getFalseBooleanValue(database);
     }
   } else {
     sqlString = newValue.toString();
   }
   return sqlString;
 }