Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
Is it possible to build SQL statements including 'XOR' condition with jQuery QueryBuilder

I want to get an SQL statement using the jQuery QueryBuilder plugin. Everything works exactly as I want when using the default conditions 'AND' and 'OR'. However, when I try to use the 'XOR' condition I get an error (see below).

This is my code for the QueryBuilder:

$(document).ready(function () {
  var options = {
    allow_empty: true,

    filters: [
      {
        id: "name",
        label: "Name",
        type: "string",
        default_value: "Noah",
        size: 30,
        unique: true,
      },
    ],

    /* XOR does not work with SQL */
    conditions: ["AND", "OR", "XOR"],
  };

  $("#builder").queryBuilder(options);

  $(".parse-json").on("click", function () {
    var res = $("#builder").queryBuilder("getSQL", $(this).data("stmt"), false);
    console.log(
      res.sql +
        (res.params ? "\n\n" + JSON.stringify(res.params, undefined, 2) : "")
    );
  });
});

Here is an example image of the QueryBuilder on my website: click here

As said before, when I choose the 'OR' condition I get the desired SQL statement.

name = ? OR name = ?

[
  "Noah",
  "James"
]

But when I choose the "XOR" condition I get an error message saying:

Uncaught Error: Unable to build SQL query with condition "XOR"
  at Function.error (jquery-2.x-git.min.js:2)

Here you can find the file giving the error: jquery-2.x-git.min.js:2

I have searched the internet for over 2 hours but I could not find anything remotely pointing in that direction. Any help is greatly appreciated.

**One thing that is worth noting is that when extracting the rules as an object instead of an SQL statement, the "XOR" condition works. Here you can see the code used to get the statement as an object:

$(".parse-json").on("click", function () {
  console.log(
    JSON.stringify($("#builder").queryBuilder("getRules"), undefined, 2)
  );
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

No, it is not possible, the conditions property only allows 'AND' or 'OR' as values, as stated in the documentation:

Name type default description
[…]
conditions string[] ['AND', 'OR'] Array of available group conditions. Use the lang option to change the label.
[…]

Looks like there was an issue reported in 2018, but it was closed without any evident resolution: https://github.com/mistic100/jQuery-QueryBuilder/issues/645


I researched a bit more and it is not as clear-cut. Apparently, there are even tests in the repository which use 'XOR' and 'NAND' as conditions: https://github.com/mistic100/jQuery-QueryBuilder/blob/dev/tests/core.module.js. This is the opposite of what the documentation states.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda