FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Filtrar consulta de tdolphin
Posts: 851
Joined: Sun Nov 09, 2014 05:01 PM
Filtrar consulta de tdolphin
Posted: Sun Sep 24, 2023 06:01 PM

Saludos estimados amigos.

Necesito filtrar una consulta de tDolphin despues de realizada para mostrarla en un xBrowse.

He leido y visto ejemplos aqui en el foro sobre SetWhere pero no logro hacer que me funcione.

oQry:SetWhere("nSaldo>0")

Pero me da error de sintaxis.

nSaldo es una columna que se genera desde una subconsulta, es decir, no existe en la tabla, sino que se crea "al vuelo" por eso no puedo filtrar al momento de crear el objeto de la consulta.

Alguna luz de como solucionar?

Gracias!

"Los errores en programaci贸n, siempre est谩n entre la silla y el teclado..."



Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin



Carora, Estado Lara, Venezuela.
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: Filtrar consulta de tdolphin
Posted: Sun Sep 24, 2023 06:24 PM

Pasa la consulta a.una tbala dbf y haces el filtro. Es lo que se me ocurre.

Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: Filtrar consulta de tdolphin
Posted: Mon Sep 25, 2023 12:13 PM
El setwhere tiene que ser sobre un campo de algunas de las tablas de tu consulta, no puede ser de un campo creado con AS
Otra opci贸n es crear una tabla temporal mysql, con el resultado de tu consulta, y sobre ella hacer el setwhere
Code (fw): Select all Collapse
#include "tdolphin.ch"
#include "fivewin.ch"
FUNCTION Main()
LOCAL oServer, oBrw, oQry
CONNECT oServer HOST 'localhost' ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 USER 'user' ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 PASSWORD 'mypass' ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 PORT 3306 ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 FLAGS 0;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 DATABASE 'test'

oServer:Execute("CREATE TEMPORARY TABLE IF NOT EXISTS temp "+;
聽 聽 聽 聽 聽 聽 聽 聽 " (SELECT c.codpro as codigo, p.nombre as proveedor, sum(importe) as importe "+;
聽 聽 聽 聽 聽 聽 聽 聽 " FROM compras c INNER JOIN proveedores p ON c.codpro = p.codigo GROUP BY c.codpro) ")
oQry := oServer:Query("SELECT * FROM temp")
oQry:SetWhere("importe > 10000")
xbrowse(oQry)
RETURN nil
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: Filtrar consulta de tdolphin
Posted: Mon Sep 25, 2023 10:50 PM

Interesante, en que momento deja de existir esa tabla temporal?

Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: Filtrar consulta de tdolphin
Posted: Tue Sep 26, 2023 04:09 AM

Carlos:

Las tablas TEMPORAY se auto-eliminan al momento de salir del PRG que las crea.

Saludos

SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
Posts: 492
Joined: Wed Nov 16, 2005 12:03 PM
Re: Filtrar consulta de tdolphin
Posted: Tue Sep 26, 2023 09:06 AM
Jos茅 Saludos
Puedes utilizar la Clausula Having para filtrar el resultado de la consulta .

En el siguiente ejemplo, detectamos cuantos documentos estan repetidos CUANTOS>1
Code (fw): Select all Collapse
cSql:=[ SELECT DOC_CODSUC,DOC_TIPDOC,DOC_TIPTRA,DOC_NUMERO,DOC_FECHA,COUNT(*) AS CUANTOS]+;
聽 聽 聽 聽 [ FROM DPDOCCLI ]+;
聽 聽 聽 聽 [ WHERE DOC_TIPTRA="D" ]+;
聽 聽 聽 聽 [ GROUP BY DOC_CODSUC,DOC_TIPDOC,DOC_TIPTRA,DOC_NUMERO,DOC_FECHA ]+;
聽 聽 聽 聽 [ HAVING CUANTOS>1 ]+;
聽 聽 聽 聽 [ ORDER BY DOC_CODSUC,DOC_TIPDOC,DOC_TIPTRA,DOC_NUMERO,DOC_FECHA ]
Posts: 492
Joined: Wed Nov 16, 2005 12:03 PM
Re: Filtrar consulta de tdolphin
Posted: Tue Sep 26, 2023 09:09 AM

Jose,

Puedes agregar en tu consulta.

SELECT ... FROM ...

HAVING nSaldo >0

Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: Filtrar consulta de tdolphin
Posted: Tue Sep 26, 2023 11:52 AM
carlos vargas wrote:Interesante, en que momento deja de existir esa tabla temporal?
Carlos, las tablas temporales solo tienen visibilidad en la sesion que son creadas, y mientras no se cierre la misma, tienen vida (o sea, mientras no hagamos oServer:End()).
Por lo dem谩s, podemos hacer sobre ellas todo lo que podriamos hacer sobre una tabla normal. Creo que eso es una ventaja sobre una dbf.
Si tienes dos puestos de trabajo, y en ambos creas una tabla temporal, dichas tablas no ser谩n visibles para el puesto que no las cre贸, por lo tanto puedes definir un m贸dulo que las utilice, sin que se pisen los datos entre ambos puestos de trabajo.
Posts: 851
Joined: Sun Nov 09, 2014 05:01 PM
Re: Filtrar consulta de tdolphin
Posted: Tue Sep 26, 2023 12:26 PM
Hola a todos,


disculpen la tardanza en contestar a sus amables repuestas y ayuda.


Carlos Vargas: tu idea de la dbf es muy acertada, la tendr茅 en cuenta para alg煤n otro caso que se presente.

Cesar G贸mez: a pesar de haber usado las tablas temporales de memoria en muchas oportunidades, no se me pas贸 por la mente hacerlo as铆 隆muy bien!

Juan Navas: tu idea usando HAVING funciona perfectamente, 隆excelente! tal como dices, solo tuve que agregar HAVING nSaldoFac>0
a la consulta y 隆LISTO!, a pesar de ser una columna din谩mica.


Muchas gracias a todos por su generosa ayuda, todas las ideas que aportaron son 煤tiles y las voy guardando, en alg煤n momento cada una tendr谩 su aplicaci贸n en casos espec铆ficos.

Ahora bien, aprovecho de hacer otra consulta para terminar de colocarle "la cereza al helado"

Siempre que hago xBrowse usando como datasource un oQry, los totales en el footer hacen caso omiso de los PICTURE.
Si lo hago con un array, funciona perfecto el picture, pero con las consultas de mysql no. Dejo una imagen de referencia y el c贸digo.
Code (fw): Select all Collapse
聽 聽 聽 聽 WITH OBJECT oBrwFac

聽 聽 聽 聽 聽 聽 聽 :aCols[5]:cEditPicture:= "@E 9,999,999,999.99"
聽 聽 聽 聽 聽 聽 聽 :aCols[5]:nFooterType := AGGR_TOTAL

聽 聽 聽 聽 聽聽 聽 聽:aCols[6]:cEditPicture:= "@E 9,999,999,999.99"
聽 聽 聽 聽 聽聽 聽 聽:aCols[6]:nFooterType := AGGR_TOTAL

聽 聽 聽 聽 聽 聽 聽 :aCols[7]:cEditPicture:= "@E 9,999,999,999.99"
聽 聽 聽 聽 聽 聽 聽 :aCols[7]:nFooterType := AGGR_TOTAL

聽 聽 聽 聽 聽 聽 聽 :MakeTotals()

聽 聽 聽 聽 END
pero el resultado no respeta el picture:



驴alguna idea de como solucionar?
"Los errores en programaci贸n, siempre est谩n entre la silla y el teclado..."



Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin



Carora, Estado Lara, Venezuela.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Filtrar consulta de tdolphin
Posted: Tue Sep 26, 2023 04:56 PM
Footer Pictures
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

聽 聽local oServer, oQry

聽 聽FWNumFormat( "E", .t. )

聽 聽oServer := TDolphinSrv():New( "208.91.198.197", "gnraofwh", "Bharat@1950", ;
聽 聽 聽 聽 聽 聽 聽 聽0, 0, "fwhdemo" )

聽 聽oQry 聽:= oServer:Query( "select id,first as Name, salary as Amount from customer" )

聽 聽XBROWSER oQry SETUP ( ;
聽 聽 聽 oBrw:Amount:nFooterType := AGGR_SUM, ;
聽 聽 聽 oBrw:MakeTotals(), ;
聽 聽 聽 oBrw:lFooter := .t. )

聽 聽oQry:End()
聽 聽oServer:End()

return nil
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Filtrar consulta de tdolphin
Posted: Tue Sep 26, 2023 05:42 PM
Necesito filtrar una consulta de tDolphin despues de realizada para mostrarla en un xBrowse.
This is extremely easy using FWH Maria library.
But here we are using Dolphin.

Do not think of reading the filtered data again from the Server.
Let us just filter the data inside XBrowse. i.e., let us display in xbrowse only those records that match the filter condition.

We will take the above example.
We want to show only those records where the "AMOUNT" is exactly divisible by 19.
We will apply this filter on right mouse click.
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

聽 聽local oServer, oQry

聽 聽FWNumFormat( "E", .t. )

聽 聽oServer := TDolphinSrv():New( "208.91.198.197", "gnraofwh", "Bharat@1950", ;
聽 聽 聽 聽 聽 聽 聽 聽0, 0, "fwhdemo" )

聽 聽oQry 聽:= oServer:Query( "select id,first as Name, salary as Amount from customer" )

聽 聽XBROWSER oQry SHOW RECID SETUP ( ;
聽 聽 聽 oBrw:Amount:nFooterType := AGGR_SUM, ;
聽 聽 聽 oBrw:MakeTotals(), ;
聽 聽 聽 oBrw:lFooter := .t., ;
聽 聽 聽 oBrw:bRClicked := { |r,c,f,o| BrwRecs( o, { |Self| ( ::Amount:Value % 19 ) == 0 } ) } )

聽 聽oQry:End()
聽 聽oServer:End()

return nil

static function BrwRecs( oBrw, bFilter )

聽 聽local aRecs := {}

聽 聽Eval( oBrw:bGoTop )
聽 聽repeat
聽 聽 聽 if Eval( bFilter, oBrw )
聽 聽 聽 聽 聽AAdd( aRecs, oBrw:BookMark )
聽 聽 聽 endif
聽 聽until Eval( oBrw:bSkip, 1 ) == 0
聽 聽oBrw:aFilter 聽 := aRecs
聽 聽oBrw:GoTop()
聽 聽oBrw:MakeTotals()
聽 聽oBrw:Refresh()

return nil
Regards



G. N. Rao.

Hyderabad, India
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: Filtrar consulta de tdolphin
Posted: Tue Sep 26, 2023 05:50 PM
Code (fw): Select all Collapse
 聽 聽 聽:aCols[ 07 ]:nFooterType 聽 := AGGR_SUM
聽 聽 聽 :aCols[ 08 ]:nFooterType 聽 := AGGR_SUM
聽 聽 聽 :aCols[ 09 ]:nFooterType 聽 := AGGR_SUM
聽 聽 聽 :aCols[ 01 ]:cFooterPicture:= "9999"
聽 聽 聽 :aCols[ 07 ]:cFooterPicture:= "999,999,999.99"
聽 聽 聽 :aCols[ 08 ]:cFooterPicture:= "999,999,999.99"
聽 聽 聽 :aCols[ 09 ]:cFooterPicture:= "999,999,999.99"
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Filtrar consulta de tdolphin
Posted: Tue Sep 26, 2023 06:11 PM
carlos vargas wrote:
Code (fw): Select all Collapse
 聽 聽 聽:aCols[ 07 ]:nFooterType 聽 := AGGR_SUM
聽 聽 聽 :aCols[ 08 ]:nFooterType 聽 := AGGR_SUM
聽 聽 聽 :aCols[ 09 ]:nFooterType 聽 := AGGR_SUM
聽 聽 聽 :aCols[ 01 ]:cFooterPicture:= "9999"
聽 聽 聽 :aCols[ 07 ]:cFooterPicture:= "999,999,999.99"
聽 聽 聽 :aCols[ 08 ]:cFooterPicture:= "999,999,999.99"
聽 聽 聽 :aCols[ 09 ]:cFooterPicture:= "999,999,999.99"
Our recommendation is NOT to write any code, which is not essential.
In other words, do not specify picture clauses at all in xbrowse.

Keep this one line of code at the beginning of the Application
Code (fw): Select all Collapse
FWNumFormat( "E", .t. ) // European format with thousand separators
and allow XBrowse to provide suitable cEditPictures and cFooterPictures.
You do not provide cEditPicture or cFooterPicture, except where it is a totally different kind.

With XBrowse, lesser the code better are the results.

Please see my above sample. We did not provide any picture clause.
But XBrowse, on its own, used the correct picture .
Regards



G. N. Rao.

Hyderabad, India
Posts: 492
Joined: Wed Nov 16, 2005 12:03 PM
Re: Filtrar consulta de tdolphin
Posted: Tue Sep 26, 2023 07:05 PM
Jos茅,
Colegas
Si deseas puedo apoyarles y/o capacitarles en el uso de MYSQL. Mi tel +5841430000518 jnadaptapro@gmail.com
Podemos ver:
1. Integridad referencial
2. Disparadores.
3. Vistas.
4. Sub consultas.
5. Optimizaci贸n WHERE, JOIN
Posts: 492
Joined: Wed Nov 16, 2005 12:03 PM
Re: Filtrar consulta de tdolphin
Posted: Tue Sep 26, 2023 07:07 PM

Corrijo mi tel +584143000518