IF !HB_FileExists("DataSystem\Sucursales.db")
pDB:= sqlite3_open("DataSystem\Sucursales.db", .T. )
IF Empty( pDB )
MessageBox( wvw_GetWindowHandle(), ;
"No es posible crear la base de datos de listado de Empresas", ;
"Sistema para Restaurantes..", MB_OK + MB_ICONALERT + MB_SYSTEMMODAL )
RETURN .F.
ENDIF
cSQLQuery:= "CREATE TABLE empresas(id_empresa VARCHAR(10),nombre_empresa VARCHAR(35),ads_fileini VARCHAR(10),bodega VARCHAR(2) )"
IF sqlite3_exec( pDB, cSQLQuery ) != SQLITE_OK
MessageBox( wvw_GetWindowHandle(), ;
"No es posible cargar la tabla de listado de Empresas", ;
"Sistema para Restaurantes..", MB_OK + MB_ICONALERT + MB_SYSTEMMODAL )
pDB := NIL // close database
RETURN .F.
ENDIF
cSQLQuery:= "INSERT INTO empresas(id_empresa,nombre_empresa,ads_fileini,bodega) VALUES(:id_empresa,:nombre_empresa,:ads_fileini,:bodega)"
stmt := sqlite3_prepare( pDB, cSQLQuery)
IF Empty( stmt )
MessageBox( wvw_GetWindowHandle(), ;
"Can't prepare statement :", ;
"Sistema para Restaurantes..", MB_OK + MB_ICONALERT + MB_SYSTEMMODAL )
pDB := NIL
RETURN NIL
ENDIF
aEmpresas:= { {"CDIS0", "CENTRO PRODUCCION PONIENTE", "SETTINGS", "99" }, ;
{"SUC00", "GRINGOS CHICKEN PONIENTE", "SERVER3", "00" }, ;
{"SUC01", "GRINGOS CHICKEN CATEDRAL", "SERVER5","01" }, ;
{"SUC02", "GRINGOS CHICKEN ORIENTE", "SERVER4","02" }, ;
{"SUC03", "GRINGOS CHICKEN TERAN", "SERVER6", "03" }, ;
{"SUC04", "EL POLLO ASADITO", "SERVER1","04" } }
FOR EACH aSucs IN aEmpresas
sqlite3_reset( stmt )
sqlite3_bind_text( stmt, 1, aSucs[1] )
sqlite3_bind_text( stmt, 2, aSucs[2] )
sqlite3_bind_text( stmt, 3, aSucs[3] )
sqlite3_bind_text( stmt, 4, aSucs[4] )
sqlite3_step( stmt )
NEXT
sqlite3_clear_bindings( stmt )
sqlite3_finalize( stmt )
ELSE
pDB:= sqlite3_open("DataSystem\Sucursales.db", .F. )
IF Empty( pDB )
MessageBox( wvw_GetWindowHandle(), ;
"No es posible crear la base de datos de listado de Empresas", ;
"Sistema para Restaurantes..", MB_OK + MB_ICONALERT + MB_SYSTEMMODAL )
RETURN .F.
ENDIF
ENDIF
nJ:= 0
stmt:= sqlite3_prepare( pDB, "SELECT id_empresa,nombre_empresa,ads_fileini,bodega FROM empresas" )
DO WHILE sqlite3_step( stmt ) == SQLITE_ROW
++nJ
ENDDO
aEmpresas:= Array(nJ,4)
nJ:= 0
DO WHILE sqlite3_step( stmt ) == SQLITE_ROW
nCCount := sqlite3_column_count( stmt )
++nJ
IF nCCount > 0
FOR nI := 1 TO nCCount
ncType := sqlite3_column_type( stmt, nI )
SWITCH ncType
CASE SQLITE_INTEGER
EXIT
CASE SQLITE_NULL
EXIT
CASE SQLITE_TEXT
IF sqlite3_column_name(stmt,nI)="id_empresa"
aEmpresas[nJ,1]:= sqlite3_column_text( stmt, nI )
ENDIF
IF sqlite3_column_name(stmt,nI)="nombre_empresa"
aEmpresas[nJ,2]:= sqlite3_column_text( stmt, nI )
ENDIF
IF sqlite3_column_name(stmt,nI)="ads_fileini"
aEmpresas[nJ,3]:= sqlite3_column_text( stmt, nI )
ENDIF
IF sqlite3_column_name(stmt,nI)="bodega"
aEmpresas[nJ,4]:= sqlite3_column_text( stmt, nI )
ENDIF
EXIT
ENDSWITCH
NEXT
ENDIF
ENDDO
sqlite3_clear_bindings( stmt )
sqlite3_finalize( stmt )
sqlite3_sleep(100)
pDB:= NIL
#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
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 RUN
#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.
Con estos pasos habremos instalado el driver ODBC para acceso a SQLite. A continuación deberemos añadir un origen de datos ODBC, desde "Inicio" - "Configuración" - "Panel de control" - "Herramientas administrativas" - "Orígenes de datos ODBC", en la ventana de Administrador de orígenes de datos ODBC, en la pestaña "DSN de sistema" pulsaremos "Agregar":
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 75 guests