Re: [harbour-users] SQL QUERY IN DBF FILE WITH HARBOUR?

397 views
Skip to first unread message

Gabriel Ornelas

unread,
Oct 6, 2017, 10:54:24 AM10/6/17
to harbou...@googlegroups.com

Xavi

         cSQLQuery := "SELECT * FROM DETXMESH WHERE " + ;
                      "FECHA='" + cFechaVenta + "' AND " + ;
                      "CAJAS='" + cID_Caja + "' AND " + ;
                      "CUENTA=" + AllTrim( Str(nCuenta) )
         IF ! ADSRunSQL( "DETALLE", cSQLQuery,, AppData:oAdsDSMain:hConnect )             
              MsgStop( "No open Query", "Query ADS" )
              RETURN .F.
         ENDIF
         DBSelectArea("detalle");ordSetFocus( "fecha" )

/*-----------------------------------------------------------------------------------------------*/
FUNCTION ADSRunSQL( cAlias, cSqlQuery, aParameters, hConnection )
/*-----------------------------------------------------------------------------------------------*/
  LOCAL nItem, xParameter, lSqlCreate, lSqlQuery, nError, cError, lSqlOK

  lSqlQuery := .F.
  lSqlCreate:= .F.
  lSqlOK    := .F.
  cError    := ""
  nItem     := 0

  IF HB_IsNil(hConnection)
    hConnection:= AdsConnection()
  ENDIF
  IF !Empty( cSqlQuery )
     IF Select( cAlias ) > 0
        ( cAlias )->( DBCloseArea() )
     ENDIF
     DBSelectArea( 0 )
     cSqlQuery := StrTran( cSqlQuery, ";", "" )
     lSqlCreate:= AdsCreateSqlStatement( cAlias, 3, hConnection )
     IF ! lSqlCreate
        nError:= AdsGetLastError(@cError)
        MsgStop( "Error AdsExecuteSqlDirect( cSql )" + HB_OsNewLine() + ;
                 "Error:" + AllTrim(Str(nError))  + HB_OsNewLine() + ;
                  cError + HB_OsNewLine() + HB_OsNewLine() + cSqlQuery + HB_OsNewLine() + cAlias, ;
                  "ERROR SCRIPT DE ADVANTAGE..." )
     ELSE
        IF !HB_IsNil( aParameters ) .and. HB_IsArray( aParameters )
           FOR EACH xParameter IN aParameters
              nItem := xParameter:__EnumIndex()
              cSqlQuery:= StrTran( cSqlQuery, "%" + AllTrim( Str( nItem ) ), Var2Str( xParameter ) )
           NEXT
        ENDIF
        lSqlQuery:= ADSExecuteSQLDirect( cSqlQuery )
        IF !lSqlQuery
           nError:= AdsGetLastError(@cError)
           MsgStop( cError + HB_OsNewLine() + cSqlQuery + HB_OsNewLine() + cAlias, ;
                    'ERROR SCRIPT DE ADVANTAGE...' )
        ELSE
           lSqlOK:= .T.
           DBGoTop()
        ENDIF
     ENDIF
  ENDIF
  RETURN lSqlOK


El 06/10/2017 a las 09:01, xavi escribió:
Hi,

I've just started with harbour because I need to make a program for my company. They gave me a .dbf file and they want to make queries to this database without using odbc drivers, only the ADS(Advantage Database). How can I edit this database File, doing SQL queries?

I'm using Fivewin with Harbour and Borland 5.5 Compiler.

If I can do it with harbour without Fivewin better.

I'tried this code but it doesn't work:

#include "FiveWin.ch"

#include "ads.ch"

 

REQUEST _ADS

 

function Main()

 

   rddRegister
( "ADS", 1 )

   rddsetdefault
( "ADS" )

   SET SERVER LOCAL

   SET FILETYPE TO CDX

   

   USE
Clientes // Open any DBF

   
OrdSetFocus("DIRECCION") // Second Tag on Clientes.cdx

   
Gotop()

   
Browse() // Quick browse!!!

   USE

 

return nil



Thanks!!

--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Miroslav Georgiev

unread,
Oct 6, 2017, 1:43:11 PM10/6/17
to Harbour Users
Hi Gabo. Do you use ADS. If yes - what version?
Reply all
Reply to author
Forward
0 new messages