En una tabla de wordpress se guarda un registro donde se concatenan los id’s de las imagenes adjuntas a un tipo de post, por ejemplo

meta_value
27954,27955,27956,27958,27960,27962,27964,

para encontrar los posts (de tipo attachment) que corresponden a estos id’s podemos utilizar la función find_in_set de la siguiente manera

select p.post_title, concat('http://localhost/wp-content/uploads/', m.meta_value) image_url
from wptv_posts p 
join wptv_postmeta m on p.id = m.post_id
where 1 = 1 
and m.meta_key = '_wp_attached_file'
and find_in_set(p.id, 
(select m.meta_value
from wptv_posts p
join wptv_postmeta m on p.id = m.post_id
where 1 = 1
 and p.id = 27116
 and m.meta_key = 'image_to_attach'
 )) > 0

en esta consulta utilizamos primero una subconsulta para encontrar la información ‘meta’, del post que nos interesa, donde estan las referencias a los archivos adjuntos y luego buscamos el atributo ‘_wp_attached_file’ para los registros encontrados para formar la ruta a las imagenes mediante la función concat.

Un ejemplo sin la subconsulta sería el siguiente

select p.post_title, concat('http://localhost/wp-content/uploads/', m.meta_value) image_url
from wptv_posts p 
join wptv_postmeta m on p.id = m.post_id
where 1 = 1 
and m.meta_key = '_wp_attached_file'
and find_in_set(p.id, 
'27954,27955,27956,27958,27960,27962,27964,') > 0

La función find_in_set regresa el índice del elemento si lo encuentra en el arreglo de cadena, por ello filtramos los registros en que es mayor a cero (si se encontró).

fuentes:
https://stackoverflow.com/questions/2153149/mysql-select-in-from-string

Anuncios

Para concatenar campos en Oracle utilizas el caracter ‘|’ (pipe), por ejemplo

select ‘titulo ‘ || ‘largo’ from dual;

En mySQL se utiliza una función llamada concat, por ejemplo

select concat(‘titulo ‘, ‘largo’);

nótese además que en mySQL no se utiliza una tabla auxiliar para ejecutar el query.

fuentes:
https://stackoverflow.com/questions/19261760/concatenate-string-with-field-value-in-mysql

We have a glassfish instance for development purposes in which monitoring was activated on all modules. This caused it to start very slow. We couldn’t access the admin console either because the startup process was failing or taking too long. So, changing the configuration from the admin console wasn’t an option neither from the command line (CLI) with the asadmin command -because it needs the server to be up and running first-

So, you have to disable monitoring from the configuration file prior to attempting to start the server. The file is {jboss-home}/glassfish/domains/domain1/config/domain.xml

look for the lines

<monitoring-service>
        <module-monitoring-levels connector-connection-pool="HIGH" jdbc-connection-pool="HIGH" ejb-container="HIGH" thread-pool="HIGH" jpa="HIGH"></module-monitoring-levels>
</monitoring-service>

and change it to

<monitoring-service>
        <module-monitoring-levels connector-connection-pool="OFF" jdbc-connection-pool="OFF" ejb-container="OFF" thread-pool="OFF" jpa="OFF"></module-monitoring-levels>
</monitoring-service>

or remove them altogether like so

<monitoring-service>
        <module-monitoring-levels></module-monitoring-levels>
</monitoring-service>

then start the server

asadmin start-domain –verbose

sources:
https://stackoverflow.com/questions/13747147/glassfish-3-1-2-monitoring-ejb-container-bean-methods
https://stackoverflow.com/questions/32118705/start-glassfish-domain-without-enabling-or-starting-deployed-applications
https://www.c2b2.co.uk/middleware-blog/glassfish-4-performance-tuning-monitoring-and-troubleshooting.php

runlevel3

What to do when there’s no space left on device (boot partition)

First identify your current kernel with

uname -r

then list all other kernel images you have installed (except your current)

dpkg -l linux-{image,headers}-“[0-9]*” | awk ‘/^ii/{ print $2}’ | grep -v -e uname -r | cut -f1,2 -d"-" | grep -e ‘[0-9]’

you can try to remove them with the following command

dpkg -l linux-{image,headers}-“[0-9]*” | awk ‘/^ii/{ print $2}’ | grep -v -e uname -r | cut -f1,2 -d"-" | grep -e ‘[0-9]’ | xargs sudo apt-get -y purge

if that doesn’t work, you could try to remove them manually.

Identify kernel images you may remove with

sudo dpkg –list ‘linux-image*’|awk ‘{ if ($1==”ii”) print $2}’|grep -v uname -r

remove the files with using the older versions and, perhaps, leaving out the last 2 versions for having an option in case you need to boot with a previous kernel

rm -rf /boot/-4.4.0-{47,51,53,57}

fix missing dependencies with

sudo apt-get -f install

and finally clean up with

sudo apt-get autoremove

fuentes:
https://askubuntu.com/questions/89710/how-do-i-free-up-more-space-in-boot
https://askubuntu.com/questions/345588/what-is-the-safest-way-to-clean-up-boot-partition

Supongamos que tienes un reporte en el que quieres ocultar un listado de una consulta de acuerdo al valor de un parámetro.

Podríamos ocultarlo fácilmente mediante la opción de visibilidad ‘Properties | Visibility | Hide element’ y utilizar una expresión como la siguiente

params[‘ocultarDetalles’].value === true

Screenshot from 2017-06-23 15-02-13

pero la consulta se ejecutaría de cualquier manera, lo que ocasionaría tiempo y procesamiento innecesario.

Para que no se ejecuté la consulta, es necesario remover el elemento que queremos ocultar en el método ‘beforeFactory’ del reporte. Para ello, primero necesitamos especificar el nombre al elemento que queremos ocultar, yo utilicé un grid el cual contiene la tabla de la consulta y lo nombré grdDetalles.
Screenshot from 2017-06-23 15-28-46

Luego selecciona la pestaña ‘Script’ y en la ventana ‘Outline’ selecciona el reporte. Asegurate seleccionar el evento ‘beforeFactory’ y agrega el siguiente script

if (params['ocultarDetalles'].value === true) {
    reportContext.getDesignHandle().findElement("grdDetalles").drop();
}

Screenshot from 2017-06-23 15-01-23

con esto se evita que se realice innecesariamente la consulta.

fuentes:
http://developer.actuate.com/community/forum/index.php?/topic/34143-does-birt-still-execute-a-query-if-an-element-is-hidden/

While I was working with a lot of reports, it made sense to use a standard file name for all the files. This was an afterthought, so it required me to rename the files. I was hoping Ubuntu Nautilus had this option, but for my current version -16.04- it doesn’t. That feature is expected to land in 17.04. in the meantime you can install nautilus-renamer which offers the same feature.

Just download the .deb package from the nautilus-renamer launchpad page and install it with

sudo dpkg -i nautilus-renamer_4.0-quantal_all.deb
sudo apt install -f
killall nautilus

It des not work if parent folders contain spaces in their name and it does not support unicode characters. I guess the nautilus version for 17.04 should work with these.

Then, just open a nautilus window and select a bunch of files, right click and select ‘rename…’ or just press F2.

done!

sources:
http://www.omgubuntu.co.uk/2016/06/nautilus-batch-rename-feature-coming-gnome-3-22
https://launchpad.net/nautilus-renamer
http://www.omgubuntu.co.uk/2016/08/quick-look-new-features-nautilus-3-22
https://launchpad.net/~gnome3-team/+archive/ubuntu/gnome3

We have a bunch of tables per office, each on its own schema in an Oracle Database.

For simplicity, we have created views on this tables and synonyms to access this views from one single schema. Hibernate supports mapping entities to synonyms, so there’s nothing more we need to do on our entities. But we still want to be able to add and modify underlying data.

To achieve this we had to create views and triggers like so

SET DEFINE OFF;
CREATE OR REPLACE FORCE VIEW CENTRAL.VPARTES
(
   SID_PARTE,
   ...
)
AS
   SELECT 'OF001' SID_OFICINA,
          T.SID_PARTE,
          ...
     FROM OFICINA001.TPARTES T
    WHERE 1 = 1 AND T.NESTATUS IN (1, 2)
   UNION ALL
   SELECT 'OF002' SID_OFICINA,
          T.SID_PARTE,
          ...
     FROM OFICINA002.TPARTES T
    WHERE 1 = 1 AND T.NESTATUS IN (1, 2);


CREATE OR REPLACE TRIGGER CENTRAL.TG_VPARTES_UPD
INSTEAD OF UPDATE
ON CENTRAL.VPARTES
FOR EACH ROW
BEGIN
IF :OLD.SID_OFICINA = 'OF001' THEN
UPDATE OFICINA001.TPARTES
SET    
       SESTATUS       = :NEW.SESTATUS,
       ...
WHERE  1 = 1
AND SID_PARTE        = :NEW.SID_PARTE ;
ELSIF :OLD.SID_OFICINA = 'OF002' THEN 
UPDATE OFICINA002.TPARTES
SET    
       SESTATUS       = :NEW.SESTATUS,
       ...
WHERE  1 = 1
AND SID_PARTE        = :NEW.SID_PARTE ;
END IF;
END;
/

for the INSERT it would be kind of the same.

If you happen to use JHipster, to allow the usage of synonyms while passing the liquibase validation we need to add a hibernate property on our corresponding application-{profile}.yml or disable liquibase altogether.

spring:
    profiles:
        include: no-liquibase
...
    jpa:
        database-platform: org.hibernate.dialect.Oracle12cDialect
        database: ORACLE
        show-sql: false
        properties:
            ...
            hibernate.synonyms: true

sources:
http://stackoverflow.com/questions/6531729/updatable-view-oracle
http://stackoverflow.com/questions/8817253/jpa-entiy-on-synonym-instead-of-table