Error en query - get list Bean

Buenas
Estoy obteniendo una excepción utilizando el método get_list trabajando con Beans. Espero puedan ayudarme a encontrarlo:

<?php


function existeBeanPorDNI($dni=0){

$beanUP= BeanFactory::getBean('RUP_Unidad_Productiva_Relevada');

try{

$beanlist = $beanUP->get_list(

  $order_by = "dni_up_c",
  $where = "dni_up_c = $dni",
  $row_offset = 0,
  $limit=-1,
  $max=-1,
  $show_deleted = 0);

  if($beanlist['row_count'] > 0) {
    return true;

  } elseif ($dni==0 || !isset($dni) || $dni==null){
    return false;
  }
  else {
    return false;
  }
} catch (Exception $e) {
  //echo $e->getMessage();
  var_dump($e);
}


}


function existeBeanPorCUIT($cuit=0){

$beanUP= BeanFactory::getBean('RUP_Unidad_Productiva_Relevada');

try{

$beanlist = $beanUP->get_list(
  $order_by = "cuit_cuil_up_c",
  $where = "cuit_cuil_up_c = $cuit",
  $row_offset = 0,
  $limit=-1,
  $max=-1,
  $show_deleted = 0);

  if($beanlist['row_count'] > 0) {
    return true;

  } elseif ($cuit==0 || !isset($cuit) || $cuit==null){
    return false;
  }
  else {
    return false;
  }
} catch (Exception $e) {
  //echo $e->getMessage();
  var_dump($e);
}


}

El error que me sale es el siguiente:

Error en base de datos. Consulte suitecrm .log para mas detalles.

En el log encuentro lo siguiente:

Query Failed: SELECT count(*) c FROM rup_unidad_productiva_relevada LEFT JOIN rup_unidad_productiva_relevada_cstm ON rup_unidad_productiva_relevada.id = rup_unidad_productiva_relevada_cstm.id_c LEFT JOIN users jt0 ON rup_unidad_productiva_relevada.modified_user_id=jt0.id AND jt0.deleted=0 AND jt0.deleted=0 LEFT JOIN users jt1 ON rup_unidad_productiva_relevada.created_by=jt1.id AND jt1.deleted=0 AND jt1.deleted=0 LEFT JOIN users jt2 ON rup_unidad_productiva_relevada.assigned_user_id=jt2.id AND jt2.deleted=0 AND jt2.deleted=0 where (dni_up_c = ) AND rup_unidad_productiva_relevada.deleted=0: MySQL error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')

Que podría estar causando esto? Intento controlar la mayor parte de lo que pueda llegar con condiciones de si está seteado, es nulo o llega 0 como parámetro.

Gracias

Algo está equivocado aqui:

where (dni_up_c = )

Intenta con otros valores de $dni (en lugar del 0), como "" ó algun otro valor

Hola Pgr. Gracias como siempre, es correcto, dejo la solución por si acaso le sirve a alguien:

La funcion estaba recibiendo argumentos: NULL y Strings vacios ( “” ). Para evitar que entre en el get_list si esto era así, solamente evaluaba esa condición antes de entrar al método:

<?php

function existeBeanPorDNI($dni=0){

$beanUP= BeanFactory::getBean('RUP_Unidad_Productiva_Relevada');

if($dni==null || $dni=="" || $dni=0) {

  return false;

}

try{

$beanlist = $beanUP->get_list(  

  $order_by = "dni_up_c",

  $where = "dni_up_c = $dni",

  $row_offset = 0,

  $limit=-1,

  $max=-1,

  $show_deleted = 0);

  if($beanlist['row_count'] > 0) {

    return true;

  }  else {

    return false;

  }

} catch (Exception $e) {

  echo $e->getMessage();

}

}

function existeBeanPorCUIT($cuit=0){

$beanUP= BeanFactory::getBean('RUP_Unidad_Productiva_Relevada');

if($cuit==null || $cuit=="" || $cuit=0) {

  return false;

}

try{

$beanlist = $beanUP->get_list(

  $order_by = "cuit_cuil_up_c",

  $where = "cuit_cuil_up_c = $cuit",

  $row_offset = 0,

  $limit=-1,

  $max=-1,

  $show_deleted = 0);

  if($beanlist['row_count'] > 0) {

    return true;

  }  else {

    return false;

  }

} catch (Exception $e) {

  echo $e->getMessage();

}

}

?>
1 Like