Fix: Error en el servidor: sql: no rows in result set when using thermal printer plugin

In this post I will show you how to fix an error that appears in my thermal printer plugin that says: Error en el servidor: sql: no rows in result set.

This error says that there are no rows in the database, and you may be wondering what printing has to do with a database, so that is exactly what I will discuss in this post.

sql: no rows in result set

In the first versions of the plugin, there was the option called setImpresora that was to set the printer in which the tickets would be printed by default. Once established, that printer name was stored in a SQLite3 database.

This error is caused because there is no data in the database because you have not invoked setImpresora, so when you try to print it gives you that error because there is no data in the database (there are no rows, that simple).

Later I implemented the imprimirEnImpresora function that allows you to specify which printer to use when printing, by sending it the printer name as a string.

Correct fix

I have always recommended using the imprimirEnImpresora method instead of the end method to finish the print job, in this way you take care of saving the name of the printer and passing it to the plugin when printing.

So to fix this problem, don’t do this, this is wrong:

let impresora = new Impresora(RUTA_API);
impresora.setFontSize(1, 1);
impresora.write("Fuente 1,1\n");
impresora.setFontSize(1, 2);
impresora.write("Fuente 1,2\n");
impresora.setFontSize(2, 2);
impresora.write("Fuente 2,2\n");
impresora.setFontSize(2, 1);
impresora.write("Fuente 2,1\n");
impresora.setFontSize(1, 1);
impresora.setEmphasize(1);
impresora.write("Emphasize 1\n");
impresora.setEmphasize(0);
impresora.write("Emphasize 0\n");
impresora.setAlign("center");
impresora.write("Centrado\n");
impresora.setAlign("left");
impresora.write("Izquierda\n");
impresora.setAlign("right");
impresora.write("Derecha\n");
impresora.setFont("A");
impresora.write("Fuente A\n");
impresora.setFont("B");
impresora.write("Fuente B\n");
impresora.feed(2);
impresora.write("Separado por 2\n");
impresora.cut();
impresora.cutPartial(); // Pongo este y también cut porque en ocasiones no funciona con cut, solo con cutPartial
impresora.end()
    .then(valor => {
        loguear("Al imprimir: " + valor);
    });

Do this, this is right:

let impresora = new Impresora(RUTA_API);
impresora.setFontSize(1, 1);
impresora.write(`Tratando de imprimir en ${nombreImpresora}
`);
impresora.write(mensaje);
impresora.cut();
impresora.cutPartial(); // Pongo este y también cut porque en ocasiones no funciona con cut, solo con cutPartial
impresora.imprimirEnImpresora(nombreImpresora)
    .then(valor => {
        loguear("Al imprimir: " + valor);
    });

The difference is that I am invoking imprimirEnImpresora by passing the printer name, and not just the end method.

Simple fix

Another solution is to simply invoke setImpresora. Most of the time this problem occurs because the client uses the free plugin and calls setImpresora correctly; It works for him and he buys the premium version, but when using the premium version he forgets to invoke setImpresora, so he gets the error sql: no rows in result set.

In short

You can do two things: invoke the setImpresora method again with the name of your printer, or start using the imprimirEnImpresora method instead of the end method.


I am available for hiring if you need help! I can help you with your project or homework feel free to contact me.
If you liked the post, show your appreciation by sharing it, or making a donation

Leave a Comment

Your email address will not be published. Required fields are marked *