Page 2 of 3

Re: Quiero comenzar con sqlite

PostPosted: Thu Aug 06, 2020 1:28 pm
by MarioG
Buen dia Crsitobal

oCn := FW_OpenAdoConnection( cdb )

if oCn == nil
? "failed"
return nil
endif

Re: Quiero comenzar con sqlite

PostPosted: Thu Aug 06, 2020 1:29 pm
by MarioG
Cristobal;
También leí un post tuyo sobre pasar la .dll a .lib
Eso no lo hice (o ya no es necesario)

Re: Quiero comenzar con sqlite

PostPosted: Thu Aug 06, 2020 2:29 pm
by MarioG
MarioG wrote:Buen dia Crsitobal

oCn := FW_OpenAdoConnection( cdb )

if oCn == nil
? "failed"
return nil
endif


Cristobal... resuelto!!
Al parecer tenía una dll errónea.
Instalé las de las Contribuciones de Harbour y salió andando

muchas gracias por interesarte!

Re: Quiero comenzar con sqlite

PostPosted: Thu Aug 06, 2020 4:49 pm
by MarioG
nageswaragunupudi wrote:If you have installed sqlite odbc driver and want to use ODBC/ADO, FWH makes it EXTREMELY simple to use Sqlite3.
You do not have to know anything other than simple FWH ado functions, which we must be already using for other ADO databaes.

Here is a simple program:
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local cdb := "testsqlite3.db"
   local ocn, ors, cSql

   oCn := FW_OpenAdoConnection( cdb )
   if oCn == nil
      ? "failed"
      return nil
   endif

   FW_AdoImportFromDBF( ocn, "c:\fwh\samples\customer.dbf" )

   oRs   := FW_OpenRecordSet( oCn, "customer" )

   XBROWSER oRs FASTEDIT TITLE "SQLITE3 DATABASE TABLE"

   oRs:Close()
   ocn:close()

return nil
 

This program connects to the database if it exists and otherwise creates a new database and connects.
To use sqlite, you do not need to learn anything more than this and you can start working straight from the next minute.


Siguiente paso...
Si no tengo creada una DB como me conecto?
Lo que deseo es hacer DBCREATE DATABASE desde código.
O sea conectarme sin pasar la var. cdb, como arriba en FW_OpenAdoConnection( cdb )

Re: Quiero comenzar con sqlite

PostPosted: Thu Aug 06, 2020 5:07 pm
by MarioG
Disculpas!
No pregunte nada...
estoy un poco mareado.
Gracias por leer!

Re: Quiero comenzar con sqlite

PostPosted: Fri Aug 07, 2020 11:53 pm
by gabo
Este es mi proyecto harbour + gtwvw (Obviamente tienes que crear SQLite)
con el codigo anterios si la DB no existe se crea..
Saludos!

El proyecto
og.hbp
Code: Select all  Expand view

-iinclude
-inc
-oOreganoGourmet
-run

source\OREGANOGOURMET.PRG
...
...
...
...
source\FunTools\WINTOOLS.C
source\FunTools\CRYPT.C
source\FunTools\BLOWFISH.C

Resource\OG_Harbour.rc                                                                              
 

el make hbmk.hbm

Code: Select all  Expand view

#
# $Id: hbmk.hbm 13358 2009-12-22 02:50:24Z vszakats $
#

E:/ToolsDeveloper/harbour-3.0.0/examples/gtwvw/gtwvw.hbc

# NOTE: Disabled until test code is cleaned/fixed.
#-w3 -es2

-w1 -es2

-lhbxpp
-lhbwin
-lhbct
-lace32
-lrddads
-lhbsqlit3
-lsqlite3
-lE:\ToolsDeveloper\tdolphin\lib\HARBOUR\MINGW32\libdolphin.a
-lE:\ToolsDeveloper\tdolphin\lib\mysql\libmysql.a
-lxhb
 

Re: Quiero comenzar con sqlite

PostPosted: Sat Aug 08, 2020 12:29 pm
by MarioG
Buen dia Gabo
Gracias por tu aporte!

Re: Quiero comenzar con sqlite

PostPosted: Sun Aug 09, 2020 2:51 pm
by MarioG
Buenos dia!
En un tabla, definida asi:
Code: Select all  Expand view
local cSQL := "CREATE TABLE IF NOT EXISTS " + cTabla  + ;
              "( 'ID'          INTEGER UNIQUE,"          + ;
                "'MGAPP'       CHAR(15) NULL, "       + ;
                "'VERSION'     CHAR(30) NULL, "       + ;
                "PRIMARY KEY('ID' AUTOINCREMENT) )"
 

Hago lo siguiente para Insertar:
Code: Select all  Expand view
local cInsert:= "INSERT INTO " +cTabla +" " + ;
                             "(ID,MGAPP,VERSION) " + ;
                      "VALUES (" + ;
                              "NULL," + ;      // FW_ValToSQL( 0 )  // "," lo comentado son otras formas probadas
                              "'mgSQL3'," + ;
                              "'08.20 Build(0000)' )"

   oConn:Execute( cInsert )
 

Ocurre que en el campo ID; ingresando: NULL en el campo ID; el registro se agrega
Aunque, me devuelve el mensaje: ADO ERROR UNKNOW.
Al capturar el error me informa:
Operation: +
Description: Error de argumento
Obviamente que chequeada la var cInsert, esta correcta...pero no encuentro lo que hago mal
Cual es mi error?

Gracias!

Re: Quiero comenzar con sqlite

PostPosted: Tue Aug 11, 2020 5:55 am
by nageswaragunupudi
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local cdb := "testsqlite3.db"
   local ocn, ors, cSql

   FW_SetUnicode( .t. )

   oCn := FW_OpenAdoConnection( cdb )
   if oCn == nil
      ? "failed"
      return nil
   endif

   if FW_AdoTableExists( "TEST1", oCn )
      oCn:Execute( "DROP TABLE TEST1" )
   endif

TEXT INTO cSql
CREATE TABLE TEST1 (
   ID INTEGER PRIMARY KEY  AUTOINCREMENT,
   MGAPP    VARCHAR(15),
   VERSION  VARCHAR(30)
   )
ENDTEXT

   oCn:Execute( cSql )

   cSql  := "INSERT INTO TEST1 ( ID, MGAPP, VERSION ) VALUES ( NULL, 'mgSQL3', '08.20 Build(0000)' )"

   oCn:Execute( cSql )

   oRs   := FW_OpenRecordSet( oCn, "select * from test1" )
   xbrowser fwadostruct( ors )
   XBROWSER oRs

   oRs:Close()
   ocn:close()

return nil
 


Image

Re: Quiero comenzar con sqlite

PostPosted: Tue Aug 11, 2020 3:59 pm
by MarioG
Many Thank Mr. Rao
My chain of datas is many long that my sample; so I've an error in ohter side (field)

Re: Quiero comenzar con sqlite

PostPosted: Tue Aug 11, 2020 8:44 pm
by nageswaragunupudi
To build a reliable sql statement, try to use
Code: Select all  Expand view

cSql := SQL INSERT INTO <table> ( fld1,fld2,... ) VALUES ( list of harbour variables )
 

This gives a properly formatted SQL statement.
You may give it a try.

Re: Quiero comenzar con sqlite

PostPosted: Tue Aug 11, 2020 10:19 pm
by MarioG
Many thanks Mr.Rao
Thats all OK now

Re: Quiero comenzar con sqlite

PostPosted: Wed Aug 26, 2020 10:04 pm
by MarioG
Hola
Necesito ayuda en lo siguiente
Cuando creo la DB luego, creo la Tabla e Inserto un registro
Todo esto ocurre sin problemas
Luego recupero un registro así:
Code: Select all  Expand view
local cSelect:= "SELECT Count(ID) FROM " +::cTablaSys + " WHERE APPNAME='"+cAppName+"'"   // cAppName es el nombre del ejecutable que obviamente existe en la Tabla

   ::oRSDB:= FW_OpenRecordSet( ::oConDB, cSelect )

// Verifico asi:
   if !FW_AdoQueryResult( cSelect, ::oRSDB:ActiveConnection ) == 0
      ?  "ID", ::oRSDB:Fields( 'ID' ):Value
   end
 

y recibo este error:
Error description: (DOS Error -2147352567) WINOLE/1007 No se encontró el elemento en la colección que corresponde al nombre o el ordinal solicitado. (0x800A0CC1): ADODB.Recordset
Args:
[ 1] = C ID

Que puedo estar haciendo mal?

Re: Quiero comenzar con sqlite

PostPosted: Wed Aug 26, 2020 11:22 pm
by nageswaragunupudi
Obviously. There is no field by name "ID" in the result of the query "SELECT COUNT(ID) FROM .......... "

Re: Quiero comenzar con sqlite

PostPosted: Thu Aug 27, 2020 1:06 am
by MarioG
Mr Rao.
I'm very confused because this is the structure
And I tried with several fields; and they all return the same error
Image