FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Incluyendo el SQLRDD
Posts: 105
Joined: Sat Jan 14, 2012 03:46 PM
Re: Incluyendo el SQLRDD
Posted: Thu Aug 24, 2023 09:39 AM
La linea 5962 llama a RuntimeErr
Code (fw): Select all Collapse
      If ::LineCount(.F.) == -1
         ::lOpened := .F.
         ::RuntimeErr( "27", SR_Msg(27) , 2, EG_OPEN, ESQLRDD_OPEN )
         Return Self
      EndIf
el codigo de LineCount
Code (fw): Select all Collapse
METHOD LineCount( lMsg ) CLASS SR_WORKAREA

   Local nRet := 0, aRet := {}

   DEFAULT lMsg := .T.

   If ::lISAM

      If nLineCountResult == 0
         Switch ::oSql:nSystemID
         Case SYSTEMID_POSTGR
            ::oSql:exec("SELECT " + SR_DBQUALIFY( ::cRecnoName, SYSTEMID_POSTGR) + " FROM " + ::cQualifiedTableName + " ORDER BY " + SR_DBQUALIFY( ::cRecnoName, ::oSql:nSystemID ) + " DESC LIMIT 1" + iif(::oSql:lComments, " /* Counting Records */", ""), lMsg, .t., @aRet)
            Exit
         Case SYSTEMID_FIREBR
            ::oSql:exec("SELECT gen_id("+::cFileName+",0) FROM RDB$DATABASE", .F., .T., @aRet)
            Exit
         Case SYSTEMID_CACHE
            ::oSql:exec("SELECT TOP 1 " + SR_DBQUALIFY(::cRecnoName, SYSTEMID_CACHE) + " FROM " + ::cOwner + ::cFileName + " ORDER BY " + SR_DBQUALIFY( ::cRecnoName, ::oSql:nSystemID ) + " DESC", lMsg, .t., @aRet)
            Exit
         Default
           ::oSql:exec("SELECT MAX( " + SR_DBQUALIFY( ::cRecnoName, ::oSql:nSystemID ) + " ) FROM " + ::cQualifiedTableName + iif(::oSql:lComments, " /* Counting Records */", ""), lMsg, .t., @aRet)
         End

         If Len(aRet) > 0 .and. valtype(aRet[1,1]) != "N"
           ::oSql:exec("SELECT COUNT( " + SR_DBQUALIFY( ::cRecnoName, ::oSql:nSystemID ) + " ) FROM " + ::cQualifiedTableName + iif(::oSql:lComments, " /* Counting Records */", ""), lMsg, .t., @aRet)
         EndIf

         If Len(aRet) > 0
            ::aInfo[ AINFO_RCOUNT ] := aRet[1,1]
            nRet := aRet[1,1]
         ElseIf ::oSql:nRetCode != SQL_SUCCESS .and. ::oSql:nRetCode != SQL_NO_DATA_FOUND
            nRet := -1     // Error
         EndIf
      Else
         nRet := nLineCountResult
         ::aInfo[ AINFO_RCOUNT ] := nRet
      EndIf
   Else
      nRet := len(::aCache)
   EndIf

   If Empty(nRet)
      ::lEmptyTable           := .T.
      ::aInfo[ AINFO_RECNO ]  := 1
      ::aInfo[ AINFO_RCOUNT ] := 0
      ::aInfo[ AINFO_BOF ]    := .T.
      ::aInfo[ AINFO_EOF ]    := .T.
   EndIf

Return nRet
Podria ser que no entrara a la consulta por el tema de ::lISAM, mi base de datos es innoDb, lo que no entiendo es que las tablas creadas con SQLRDD tambien son innoDB y funcionan
Fivewinner desde 1.9, programador PHP y Javascript, PWA & HTML5 evangelista
Posts: 105
Joined: Sat Jan 14, 2012 03:46 PM
Re: Incluyendo el SQLRDD
Posted: Thu Aug 24, 2023 10:58 AM
Si utilizo directamente la consulta, sin USE ... VIA SQLRDD...
Code (fw): Select all Collapse
   oSql:= SR_GetConnection()
   oSql:Exec("select * from customer",, .T., @aRows )
   ? oSql:GetAffectedRows()

   ? valtype(aRows), len(aRows)
   ? valtype(aRows[1])

   for each a in aRows 
      for each i in a
         ?? i
      next 
      ?
   next
Se muestran correctamente los registros
Code (fw): Select all Collapse
Taouk               Dockett             24636 Golden Springs Rd       Princeton                     NH51508-620307/05/90 00:00:00.000.F.         27     23300.0000000000000000000000000000000This is a test for record 492

Mario               French              18139 Hewes Street            Williston                     HI28288-220308/08/83 00:00:00.000.T.         46     55300.0000000000000000000000000000000This is a test for record 493

Gary                Beilharz            16861 Abbots Place            Amerspoort                    WI79471-858301/30/91 00:00:00.000.F.         67    144000.0000000000000000000000000000000This is a test for record 494

Guy                 Acker               27636 Broadway                Framingham                    AK84142-806905/20/89 00:00:00.000.T.         48     39300.0000000000000000000000000000000This is a test for record 495

Dickson             Valle               32693 Stonecutter Lane        Kowloon Bay                   AL18415-926307/14/91 00:00:00.000.F.         87     42200.0000000000000000000000000000000This is a test for record 496
Otra forma que también funciona :
Code (fw): Select all Collapse
   dbUseArea( .F., "SQLRDD", "select * from customer", "customer" )
   ? customer->FIRST
   WAIT
   browse()
Pero sigue sin funcionar si la tabla no se ha creado desde SQLRDD, la unica forma es la anterior
Code (fw): Select all Collapse
USE "customer" NEW VIA "SQLRDD"
Fivewinner desde 1.9, programador PHP y Javascript, PWA & HTML5 evangelista
Posts: 105
Joined: Sat Jan 14, 2012 03:46 PM
Re: Incluyendo el SQLRDD
Posted: Thu Aug 24, 2023 11:42 AM
Descubierto el misterio ...

Si queremos abrir una tabla con USE cTable VIA SQLRDD, que no haya sido creada con el RDD, tendremos que modificar la estructura y añadir un campo en dicha tabla
Code (fw): Select all Collapse
    `sr_recno` BIGINT(20) NOT NULL AUTO_INCREMENT, UNIQUE INDEX `sr_recno` (`sr_recno`) USING BTREE
Las tablas creadas por SQLRDD via dbCreate(...) ya añaden de forma automática sr_recno, como he mencionado anteriormente, por lo que no fallará USE cTable VIA SQLRDD

Si no se desea modificar la estructura, siempre se puede utilizar dbUseArea( .F., "SQLRDD", "select * from customer", "customer" )

En conclusión, si se pretende migrar todo un sistema de tablas DBF a una BD SQL es mejor crear las tablas con DbCreate utilizando SQLRDD y posteriormente añadir los registros

Entendiendo un poco como funciona SQLRDD, creo que puede ser realidad el paso de paradigma DBF a SQL
sin tocar una línea de código
... veremos :)
Fivewinner desde 1.9, programador PHP y Javascript, PWA & HTML5 evangelista
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Incluyendo el SQLRDD
Posted: Thu Aug 24, 2023 12:44 PM
Excellente !!! :-D
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1283
Joined: Fri Feb 10, 2006 02:34 PM
Re: Incluyendo el SQLRDD
Posted: Thu Aug 24, 2023 02:39 PM
Quim
Joaquim Ferrer wrote:Descubierto el misterio ...
Las frescas noches de verano te ayudan a resolver.... :lol:

Congratulations.
C.
Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
HIX -> https://github.com/carles9000/hix
Posts: 105
Joined: Sat Jan 14, 2012 03:46 PM
Re: Incluyendo el SQLRDD
Posted: Thu Aug 24, 2023 03:35 PM
Gràcies Carles !!!

Como dijo aquel... las neuronas estan fritas, pero la barbacoa está rica :)
Fivewinner desde 1.9, programador PHP y Javascript, PWA & HTML5 evangelista
Posts: 670
Joined: Wed Oct 19, 2005 06:41 PM
Re: Incluyendo el SQLRDD
Posted: Thu Aug 24, 2023 04:15 PM
Joaquim buenos dias
podrias actualizar https://github.com/QuimFerrer/sqlrdd.git por favor con tus avances
gracias por tu ayuda
Wilson 'W' Gamboa A
Wilson.josenet@gmail.com
Posts: 105
Joined: Sat Jan 14, 2012 03:46 PM
Re: Incluyendo el SQLRDD
Posted: Thu Aug 24, 2023 05:02 PM
Repositorio actualizado !

Estaria bien compartir experiencias :)
wilsongamboa wrote:Joaquim buenos dias
podrias actualizar https://github.com/QuimFerrer/sqlrdd.git por favor con tus avances
gracias por tu ayuda
Fivewinner desde 1.9, programador PHP y Javascript, PWA & HTML5 evangelista
Posts: 670
Joined: Wed Oct 19, 2005 06:41 PM
Re: Incluyendo el SQLRDD
Posted: Thu Aug 24, 2023 05:56 PM

Joaquim gracias mira esto tengo

c:\demo\sqlrddq>hbmk2 project.hbp

prg\demo01.prg(8) Error F0029 Can't open #include file 'myconn.ch'

hbmk2: Error: Running Harbour compiler (embedded). 1

(c:\hbb\bin\harbour.exe) -n2 prg\demo01.prg -n -q0 -DHBMK_HAS_HBCT=1 -DHBMK_HAS_

HBTIP=1 -DHBMK_HAS_HBFSHIP=1 -DHBMK_HAS_HBXPP=1 -DHBMK_HAS_HBWIN=1 -DHBMK_HAS_XH

B=1 -oC:\Users\gussw\AppData\Local\Temp\hbmk_yolxxb.dir\ -ic:\bcc7\Include -ic:\

bcc7\Include\dinkumware -ic:\bcc7\Include\windows\crtl -ic:\bcc7\Include\windows

\rtl -ic:\bcc7\Include\windows\sdk -ic:\hbb\include -iinclude -ic:\hbb\contrib\x

hb -ic:\hbb\contrib\hbct -ic:\hbb\contrib\hbtip -ic:\hbb\contrib\hbfship -ic:\hb

b\contrib\hbxpp -ic:\hbb\contrib\hbwin -u+c:\hbb\contrib\hbwin\hbwin.ch

saludos

Wilson

creo falta ese archivo myconn.ch

Wilson 'W' Gamboa A
Wilson.josenet@gmail.com
Posts: 670
Joined: Wed Oct 19, 2005 06:41 PM
Re: Incluyendo el SQLRDD
Posted: Thu Aug 24, 2023 06:00 PM

mi experiencia

intente cuando apenas salio este producto pero me fallaba cuando hacia use \sistemas\siste001\empre001\ventas\ventas.dbf index \sistemas\siste001\empre001\ventas\ventas.ntx alias ventas

intente con una funcion que ellos tenian para estos casos pero no me funciono

hasta alli llegue eso unido a mis escasos conocimientos de sql en esa epoca ( y ahora ) me detuvieron no me atrevi a comprar la lib por mi falta de conocimiento del campo sql

saludos

wilson

pd: me cai del asiento cuando vi que estaban disponibles los fuentes ja ja ja

gracias a don Marcelo Lombardo y al equipo de xharbour.com !!

Wilson 'W' Gamboa A
Wilson.josenet@gmail.com
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: Incluyendo el SQLRDD
Posted: Fri Aug 25, 2023 01:19 AM

hi,

under SQL you need a UNIQUE "Identifier" like RECNO() under DBF

Fivewin seems to use "ID" and Xbase++ "__Record" as PRIMARY KEY

SQLRDD use "sr_recno" so everybody can use a other "Identifier"

it is recommend to use "Import" Function which include PRIMARY Key for those SQL Table

greeting,

Jimmy
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: Incluyendo el SQLRDD
Posted: Fri Aug 25, 2023 01:33 AM
SR_RecnoName()
Returns the name of the column that stores the Recno()

› Syntax


SR_RecnoName( [<cName>] ) ==> cOldSet


› Arguments



<cName> Column name to manage the Recno().




› Return


Returns the status that was current before SR_RecnoName() was called.


› Description


Returns the name of the column that manages the Recno(). By default, the SQLRDD adopts the name SR_RECNO. If you want to use another name, call SR_RecnoName("NAME") before dbUseArea() or dbCreate().
This function is also very useful when we want to open tables not created by SQLRDD, but we can use another auto sequenced numeric column for this purpose.


› Examples


SR_RecnoName( "CAMPO1" )
USE TABELA1 // will use the field COMPO01 as recno(). If this field does not exist, it will generate a runtime error.
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: Incluyendo el SQLRDD
Posted: Fri Aug 25, 2023 01:34 AM
SR_DeletedName()
Returns the name of the column that manages the Deleted() status

› Syntax


SR_DeletedName( [<cName>] ) ==> cOldSet


› Arguments



<cName> Name column to manage the Deleted() status.




› Return


Returns the status that was current before SR_DeletedName() was called.


› Description


Returns the name of the column that manages the Deleted() status. By default, the SQLRDD adopts the name SR_DELETED. If you want to use another name, call SR_DeletedName("NAME") before dbUseArea() or dbCreate().
This function is also very useful when we want to open tables not created by SQLRDD, but we can use another not null character column for that purpose.
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: Incluyendo el SQLRDD
Posted: Fri Aug 25, 2023 01:35 AM

se necesita además un campo para controlar el borrado de fila, por defecto es sr_deleted

Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 105
Joined: Sat Jan 14, 2012 03:46 PM
Re: Incluyendo el SQLRDD
Posted: Fri Aug 25, 2023 06:56 AM
wilsongamboa wrote:Joaquim gracias mira esto tengo
c:\demo\sqlrddq>hbmk2 project.hbp
prg\demo01.prg(8) Error F0029 Can't open #include file 'myconn.ch'
hbmk2: Error: Running Harbour compiler (embedded). 1
(c:\hbb\bin\harbour.exe) -n2 prg\demo01.prg -n -q0 -DHBMK_HAS_HBCT=1 -DHBMK_HAS_
HBTIP=1 -DHBMK_HAS_HBFSHIP=1 -DHBMK_HAS_HBXPP=1 -DHBMK_HAS_HBWIN=1 -DHBMK_HAS_XH
B=1 -oC:\Users\gussw\AppData\Local\Temp\hbmk_yolxxb.dir\ -ic:\bcc7\Include -ic:\
bcc7\Include\dinkumware -ic:\bcc7\Include\windows\crtl -ic:\bcc7\Include\windows
\rtl -ic:\bcc7\Include\windows\sdk -ic:\hbb\include -iinclude -ic:\hbb\contrib\x
hb -ic:\hbb\contrib\hbct -ic:\hbb\contrib\hbtip -ic:\hbb\contrib\hbfship -ic:\hb
b\contrib\hbxpp -ic:\hbb\contrib\hbwin -u+c:\hbb\contrib\hbwin\hbwin.ch

saludos
Wilson
creo falta ese archivo myconn.ch
Wilson, crea el archivo /include/myconn.ch y le añades
Code (fw): Select all Collapse
#define __DB__    "mi base de datos"
#define __PWD__   "mi password"
Fivewinner desde 1.9, programador PHP y Javascript, PWA & HTML5 evangelista