Files
harbour-core/harbour/contrib/rddads/tests/datad.prg
Viktor Szakats 62a09afd19 2009-10-19 23:13 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
* contrib/gtalleg/tests/hbmk.hbm
  * contrib/hbmysql/utils/hbmk.hbm
  * contrib/hbmysql/utils/dbf2mysq.prg
  * contrib/hbmysql/tests/test.prg
  * contrib/hbmysql/tests/hbmk.hbm
  * contrib/hbct/tests/tab.prg
  * contrib/hbct/tests/tokensep.prg
  * contrib/hbct/tests/datetime.prg
  * contrib/hbct/tests/hbmk.hbm
  * contrib/hbct/tests/token2.prg
  * contrib/hbct/tests/charhist.prg
  * contrib/xhb/tests/hbmk.hbm
  * contrib/hbodbc/tests/hbmk.hbm
  * contrib/hbtpathy/tests/hbmk.hbm
  * contrib/hbmzip/tests/hbmk.hbm
  * contrib/hbsqlit3/tests/hbmk.hbm
  * contrib/hbsqlit3/tests/authoriz.prg
  * contrib/hbblat/tests/hbmk.hbm
  * contrib/hbqt/tests/hbmk.hbm
  * contrib/hbfbird/tests/simple.prg
  * contrib/hbfbird/tests/test.prg
  * contrib/hbfbird/tests/hbmk.hbm
  * contrib/hbziparc/tests/hbmk.hbm
  * contrib/hbxbp/tests/hbmk.hbm
  * contrib/hbnf/tests/ftgete.prg
  * contrib/hbnf/tests/hbmk.hbm
  * contrib/hbcurl/tests/ftp_uldl.prg
  * contrib/hbcurl/tests/hbmk.hbm
  * contrib/hbmemio/tests/hbmk.hbm
  * contrib/gtqtc/tests/demoqtc.prg
  * contrib/gtqtc/tests/hbmk.hbm
  * contrib/hbnetio/utils/hbmk.hbm
  * contrib/hbnetio/tests/hbmk.hbm
  * contrib/rddsql/tests/hbmk.hbm
  * contrib/hbhpdf/tests/harupdf.prg
  * contrib/hbhpdf/tests/hbmk.hbm
  * contrib/rddado/tests/hbmk.hbm
  * contrib/gtwvg/tests/hbmk.hbm
  * contrib/hbpgsql/tests/async.prg
  * contrib/hbpgsql/tests/test.prg
  * contrib/hbpgsql/tests/hbmk.hbm
  * contrib/hbpgsql/tests/cache.prg
  * contrib/hbpgsql/tests/stress.prg
  * contrib/hbpgsql/tests/dbf2pg.prg
  * contrib/hbclipsm/tests/hbmk.hbm
  * contrib/rddads/tests/datad.prg
  * contrib/rddads/tests/hbmk.hbm
  * contrib/rddads/tests/testmg.prg
  * contrib/hbfimage/tests/fitest.prg
  * contrib/hbfimage/tests/hbmk.hbm
  * contrib/hbgd/tests/tostring.prg
  * contrib/hbgd/tests/gdtestcl.prg
  * contrib/hbgd/tests/gdtest.prg
  * contrib/hbgd/tests/animgif.prg
  * contrib/hbgd/tests/testdpi.prg
  * contrib/hbgd/tests/hbmk.hbm
  * contrib/hbgd/tests/counter.prg
  * contrib/hbgd/tests/antialia.prg
  * contrib/hbgd/tests/bartest.prg
  * contrib/hbgd/tests/barms.prg
  * contrib/hbgd/tests/test_out.prg
  * contrib/hbmisc/tests/testhbf.prg
  * contrib/hbmisc/tests/hbmk.hbm
  * contrib/hbmisc/tests/twirl.prg
  * contrib/hbtip/tests/dnldftp.prg
  * contrib/hbtip/tests/upld_ftp.prg
  * contrib/hbtip/tests/dbtohtml.prg
  * contrib/hbtip/tests/hbmk.hbm
  * contrib/hbwin/hbwin.h
  * contrib/hbwin/hbwin.ch
  * contrib/hbwin/tests/testsim.prg
  * contrib/hbwin/tests/testole.prg
  * contrib/hbwin/tests/testcom2.prg
  * contrib/hbwin/win_com.c
  * contrib/hbssl/tests/hbmk.hbm
  * contrib/hbbtree/tests/hbmk.hbm
    ! Fixed warnings and errors in test apps.
    + Added -es2 option to test/util default options.
    * Renamed few macros in hbwin / win_com implementation:
        FCN* -> WIN_COM_FUN_*
        WPDBG* -> WIN_COM_DBG_*
    ; TOFIX: Some errors are left in hbgd/test_out.prg and 
             gtwvg to be fixed, now the can't be built.
             Please do it.
2009-10-19 21:17:04 +00:00

152 lines
4.7 KiB
Plaintext

/*
* $Id$
*/
/*
Demo of ADS Connection handling and Data Dictionaries
*/
#include "ads.ch"
REQUEST ADS
FUNCTION MAIN
local n
local cErr, cStr
local aStru := {{ "ID", "A", 1, 0}, {"Name", "C", 50, 0}, {"address", "C", 50, 0}, {"city", "C", 30, 0}, {"Age", "n", 3, 0}}
local hConnection1
CLS
RddSetDefault("ADT")
AdsSetServerType ( 7 )
SET Filetype to ADT
? "Default connection is 0:", adsConnection()
fErase("harbour.add")
fErase("harbour.ai")
fErase("harbour.am")
fErase("Table1.adt")
fErase("Table1.adi")
fErase("Table2.adt")
fErase("Table2.adi")
// now Create a Data dictionary and the files if not exist
IF !File("harbour.add")
ADSDDCREATE("harbour.add",, "(x)Harbour ADS demo for data dictionary")
// This also creates an Administrative Handle that is set as the default
? "Default connection is now this admin handle:", adsConnection()
AdsDisconnect() // disconnect current default.
// if you wanted to retain this connection for later, you could use
// hAdminCon := adsConnection(0)
// This get/set call would return the current connection, then set it to 0
? "Default connection is now this handle (zero):", adsConnection()
// now create two free tables with same structure
DbCreate("Table1", aStru)
DbCreate("Table2", aStru)
//now create an index
USE table1 new
INDEX ON FIELD->id TAG codigo
USE
USE table2 new
INDEX ON FIELD->id TAG codigo
USE
ENDIF
// now the magic
IF adsConnect60("harbour.add", 7/* All types of connection*/, "ADSSYS", "", , @hConnection1 )
// The connection handle to harbour.add is now stored in hConnection1,
// and this is now the default connection
? "Default connection is now this handle:", adsConnection()
? " Is it a Data Dict connection? (ADS_DATABASE_CONNECTION=6, "
? " ADS_SYS_ADMIN_CONNECTION=7):", AdsGetHandleType()
// Add one user
AdsDDCreateUser(, "Luiz", "papael", "This is user Luiz")
IF adsddGetUserProperty("Luiz", ADS_DD_COMMENT, @cStr, hConnection1)
? "User comment:", cStr
ELSE
? "Error retrieving User comment"
ENDIF
? "Add the tables"
AdsDDaddTable("Table1", "table1.adt", "table1.adi")
?
IF ! AdsDDaddTable("Customer Data", "table2.adt", "table2.adi")
// notice the "long table name" for file Table2.adt. Later open it with "Customer Data" as the table name
? "Error adding table:", adsGetLastError(@cErr), cErr
ENDIF
? "Set new admin pword on default connection:", AdsDDSetDatabaseProperty( ADS_DD_ADMIN_PASSWORD, "newPWord" )
? "Set new admin pword on explicit connection:", AdsDDSetDatabaseProperty( ADS_DD_ADMIN_PASSWORD, "newPWord", hConnection1 )
? "Clear admin pword:", AdsDDSetDatabaseProperty( ADS_DD_ADMIN_PASSWORD, "" )
ELSE
? "Error connecting to harbour.add!"
ENDIF
AdsDisconnect(hConnection1)
hConnection1 := nil // you should always reset a variable holding a handle that is no longer valid
? "Default connection is back to 0:", adsConnection()
? "Is a Data Dict connection? (AE_INVALID_HANDLE = 5018):", AdsGetHandleType()
// now open the tables and put some data
IF AdsConnect60("harbour.add", 7/* All types of connection*/, "Luiz", "papael", , @hConnection1)
? "Default connection is now this handle:", adsConnection()
? "Connection type?", AdsGetHandleType()
FOR n := 1 TO 100
IF AdsCreateSqlStatement("Data2", 3)
IF !AdsExecuteSqlDirect(" insert into Table1( name,address,city,age) VALUES( '" + strzero(n)+"','"+strzero(n)+"','"+strzero(n)+"'," +str(n)+ ")" )
ShowAdsError()
ENDIF
USE
ENDIF
NEXT
FOR n := 1 TO 100
IF AdsCreateSqlStatement("Data1", 3)
IF !AdsExecuteSqlDirect(" insert into " +'"Customer Data"'+"( name,address,city,age) VALUES( '"+ strzero(n)+"','"+strzero(n)+"','"+strzero(n)+"'," +str(n)+")" )
ShowAdsError()
ENDIF
USE
ENDIF
NEXT
// AdsUseDictionary(.t.) this function no longer is needed; the system knows if it's using a Data Dictionary connection
// Open the "long table name" for Table2
DbUseArea(.t.,, "Customer Data", "custom", .t., .f.)
? "Press a key to browse", alias()
inkey(0)
Browse()
USE
USE table1 new
Browse()
USE
ENDIF
AdsDisconnect(hConnection1)
@ 24, 0 say ""
RETURN NIL
PROC ShowAdsError()
LOCAL cMsg
AdsGetLastError( @cMsg )
Alert( cMsg )
RETURN