Sqlite and FWH

Sqlite and FWH

Postby Natter » Thu Mar 17, 2022 5:55 pm

Hi,

Is it possible to work with the Sqlite database via FWH ?
Natter
 
Posts: 1224
Joined: Mon May 14, 2007 9:49 am

Re: Sqlite and FWH

Postby James Bott » Thu Mar 17, 2022 9:17 pm

Search the forum for "sqlite" and you will get about 20 pages of messages on this topic.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Sqlite and FWH

Postby Willi Quintana » Fri Mar 18, 2022 2:47 pm

Hello James---
See this code.

Code: Select all  Expand view  RUN

oConG := OpenSQLite( oConG )

cCad := "SELECT * FROM DOCUMENTO"
oObj := SSQLQry( oConG, oObj, cCad )

IF oObj:RecordCount() =0
  cCad := "INSERT INTO DOCUMENTO (NUM_RUC, TIP_DOCU, NUM_DOCU) VALUES ('00000000000','','')"
  lOK := oConG:Execute( cCad )
EndIf

cCad := "UPDATE PARAMETRO SET val_para = '1' WHERE cod_para = 'TIMEENVIA'"
lOK := oConG:Execute( cCad )



//---------------------------------------------------------------------------------------------------------------
Function OpenSQLite( oConL )
oConL                  := TOleAuto():new( "adodb.connection" )
oConL:ConnectionString := "Data Source=archivosfs;Version=3;New=True;Compress=True;"

TRY
   oConL:Open()
CATCH
   MsgStop( "No Hay Conexion ODBC - SQLIte", "Error", 2 )
   oConL := Nil
   QUIT
   QUIT
END

SysRefresh()

Return( oConL )

//-----------------------------------------------------------------------------------------------------------------------------
Function SSQLQry( oConT, oRs1, cCon )
oRs1 := FW_OpenRecordSet( oConT, cCon )
Return( oRs1 )


 
User avatar
Willi Quintana
 
Posts: 1022
Joined: Sun Oct 09, 2005 10:41 pm
Location: Cusco - Perú

Re: Sqlite and FWH

Postby Willi Quintana » Fri Mar 18, 2022 2:49 pm

More code
Code: Select all  Expand view  RUN

//----------abrir una SQLITE.DB
//---------------------------------------------------------------------------------------------------------------
Function OpenSQLite( oConL )
oConL                  := TOleAuto():new( "adodb.connection" )
oConL:ConnectionString := "Data Source=sqlitedat;Version=3;New=True;Compress=True;"         // sqitedat es el nombre indicado en el ODBC

TRY
   oConL:Open()
CATCH
   MsgStop( "No Hay Conexion ODBC - SQLIte", "Error", 2 )
   oConL := Nil
   QUIT
   QUIT
END

SysRefresh()

Return( oConL )


//-------hacer una consulta
...
cCad := "SELECT cod_para, val_para FROM TXXXX_PARAM"
oObj := SSQLQry( oConL, oObj, cCad )
WHILE !oObj:EOF()
  IF SQLvar( oObj, 0 ) = "FUNCIO"
    cMen := "SFS : " + IF(SQLVar( oObj, 1 ) = "01", "AUTOMÁTICO","MANUAL")
  EndIf
  oObj:Move(1)
ENDDO

//---------------------------------------------------------------------------------------------------------
Function SSQLQry( oConT, oRs1, cCon )
oRs1 := FW_OpenRecordSet( oConT, cCon )
Return( oRs1 )

//------------update datos
...
cCad := "UPDATE TXXXX_PARAM SET val_para = '0.2' WHERE cod_para = 'TIEMPO'"
lOK := oConL:Execute( cCad )

//-----------------------------------------------------------------------------------------------------------------------------
Function SQLVar( oObj, nCampo )
local cVar
TRY
cVar := oObj:Fields( nCampo ):Value
CATCH
cVar := ""
END
Return( cVar )


//-------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------------
Function SetBrow(oDataS, oBrw)
local lRet := .t.
local bGoTop, bGoBottom, bSkipper, bSkip
local cClsName

bGoTop    := { || If( oDataS:RecordCount() > 0, oDataS:MoveFirst(), nil ) }
bGoBottom := { || If( oDataS:RecordCount() > 0, oDataS:MoveLast(), nil )  }
bSkip     := { | n | AdoSkip( oDataS, IfNil( n, 1 ) ) }
bSkipper  := { | n | AdoSkip( oDataS, IfNil( n, 1 ) ) }


oBrw:cAlias    := ""
oBrw:bGoTop    := bGoTop
oBrw:bGoBottom := bGoBottom
oBrw:bSkip     := bSkipper
oBrw:bLogicLen := { || oDataS:RecordCount() }
if oBrw:oVScroll() != nil
  oBrw:oVscroll():SetRange( 1, oDataS:RecordCount() )
endif
oBrw:Refresh()

Return(NIl)

static function AdoSkip( oRs, n )

LOCAL nRec

if oRs:RecordCount() == 0
   return 0
endif

nRec := oRs:AbsolutePosition
If( oRs:Eof, oRs:MoveLast(), If( oRs:Bof, oRs:MoveFirst(),) )
oRs:Move( n )
If( oRs:Eof, oRs:MoveLast(), If( oRs:Bof, oRs:MoveFirst(),) )

return oRs:AbsolutePosition - nRec
 
User avatar
Willi Quintana
 
Posts: 1022
Joined: Sun Oct 09, 2005 10:41 pm
Location: Cusco - Perú

Re: Sqlite and FWH

Postby nageswaragunupudi » Fri Mar 18, 2022 3:44 pm

Mr. Willi
What ODBC driver are you using?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Sqlite and FWH

Postby Willi Quintana » Fri Mar 18, 2022 8:50 pm

Check your mail.
Regards
User avatar
Willi Quintana
 
Posts: 1022
Joined: Sun Oct 09, 2005 10:41 pm
Location: Cusco - Perú


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 36 guests