Alaska Software Inc. - ADS and external DLL
Username: Password:
AuthorTopic: ADS and external DLL
Pascal BoivinADS and external DLL
on Fri, 03 Jul 2020 22:26:46 +0200
I'm looking at CXP samples for the first time. There is 2 things I can
not find :
- How to use a different DBE? My apps are using ADS with OEM caracter
set.

- How to include an xbase DLL full of code? I would like to put all
business logic in a DLL (create customer, create invoice, ...) and just
call functions from CXP.
Pascal BoivinRe: ADS and external DLL
on Thu, 09 Jul 2020 15:57:53 +0200
I succefully modify websamples\suppliers.cxp to use ADS with OEM
caracter set. I also add forward/backward index support. Here it is if
someone need it.

----

<%#code locality="page-global"%>
<%
#include "adsdbe.ch"

FUNCTION CreateDacSession(cDriver, cPath, cUID, cPW, cExtra, cErr)
LOCAL oSession := NIL, DBE, T
LOCAL cConnect

    cErr := ""
    IF ValType(cUID) <> "C"
      T := Appname()
      cUID := Left(T, RAt(".", T) - 1)
    ENDIF
    IF ValType(cPW) <> "C"
      cPW := ""
    ENDIF
    IF !Empty(cExtra)
      IF cExtra[-1] <> ";"
        cExtra := cExtra + ";"
      ENDIF
    ELSE
      cExtra := ""
    ENDIF

    cConnect := "DBE=" + cDriver + ";SERVER=" + cPath + ";" + cExtra +
"UID=" + cUID
    IF !Empty(cPW)
      cConnect += ";PWD=" + cPW
    ENDIF
    cErr := "Connecting to " + cConnect + ": "
    oSession := DacSession():new(cConnect, .F.)
    IF !oSession:isConnected()
      cErr += oSession:getLastMessage()
      RETURN NIL
    ELSE
      DbeSetDefault(cDriver)
      oSession:SetDefault()
      DbeInfo( COMPONENT_DATA, ADSDBE_TBL_MODE, ADSDBE_CDX)
      DbeInfo( COMPONENT_ORDER, ADSDBE_TBL_MODE, ADSDBE_CDX)
      DbeInfo( COMPONENT_ORDER, ADSDBE_INDEX_EXT, "CDX")
      DbeInfo( COMPONENT_DATA, ADSDBE_LOCK_MODE,
ADSDBE_PROPRIETARY_LOCKING  )

      cErr += "OK"
    ENDIF
RETURN oSession
%>
<%#code locality="page-render"%>
<%
   IF ! DbeLoad( "ADSDBE", .F.)
      ? "Database engine ADSDBE not loaded"
      RETURN
   ENDIF
   DbeSetDefault( "ADSDBE" )
   SET COLLATION TO AMERICAN

   cErr := ""
   oSession := CreateDacSession("ADSDBE", "N:\DIRECTORY\DATABASE.ADD",
"", "", "", @cErr)
   IF oSession == NIL
      ? cErr
      RETURN
   ENDIF

 USE SUPPLIER READONLY

 nPage := Max(1,Val(::HttpRequest:Form:Page))   which page
 nRows := Max(5,Val(::HttpRequest:Form:Rows))   many rows
 cIdx  := ::HttpRequest:Form:Sidx   index key name
 lDesc := ::HttpRequest:Form:Sord=="desc"   asc or desc order

 cData := "<?xml version='1.0' encoding='iso-8859-1'?>"+Chr(13)+Chr(10)
 cData += "<rows>"
 cData += "<page>"+Str(nPage)+"</page>"
 cData += "<total>"+Str(Int(RecCount()/nRows)+1)+"</total>"
 cData += "<records>"+Str(RecCount())+"</records>"

  id is physical nav
 IF(cIdx=="id")
   OrdSetFocus(0)
   IF lDesc
      GO BOTTOM
      DbGoTo( OrdKeyNo() - ((nPage-1)*nRows)+1 )
   ELSE
      DbGoTo( ((nPage-1)*nRows)+1 )
   ENDIF
 ELSE
   OrdSetFocus(cIdx)
   IF lDesc
      GO BOTTOM
      nPos := -((nPage-1)*nRows)
   ELSE
      nPos := (nPage-1)*nRows
   ENDIF
   SKIP nPos
   IF EOF()
      SKIP -1
   ENDIF
 ENDIF

 nLoaded := 0
 DO WHILE nLoaded!=nRows .AND. !EOF()
   nLoaded++
   cData += "<row id='"+Str(RecNo())+"'>"
   cData += "<cell>"+Var2Xml(FIELD->SUPPLIER_I)+"</cell>"
   cData += "<cell>"+Var2Xml(FIELD->COMPANY_NA)+"</cell>"
   cData += "<cell>"+Var2Xml(FIELD->CONTACT_NA)+"</cell>"
   cData += "<cell>"+Var2Xml(FIELD->POSTAL_COD)+"</cell>"
   cData += "<cell>"+Var2Xml(FIELD->CITY)+"</cell>"
   cData += "<cell>"+Var2Xml(FIELD->COUNTRY)+"</cell>"
   cData += "</row>"
   IF lDesc
      SKIP -1
      IF BOF()
         nLoaded := nRows
      ENDIF
   ELSE
      SKIP 1
      IF EOF()
         nLoaded := nRows
      ENDIF
   ENDIF
 ENDDO
 cData += "</rows>"
 USE
 oSession:disconnect()

 ::HttpResponse:ContentType := "text/xml;charset=iso-8859-1"
 OutputDebugStringA( Var2Char(cData ) )

 ::HttpResponse:Reset()
 ::HttpResponse:Write( cData )

%>