Re: Using ADT files - a few questions
Posted: Wed May 23, 2012 3:39 am
I just saw this thread. I thought there would be a lot more people using .adt files.
Is adt tables still an issue?
You still use the very same rdd_ads.lib with ntx/cdx/vfp or adt tables. All you do is change the RDD. For dbf tables with harbour you have the choice of using DBFNTX, DBFCDX, or ADSNTX, ADSCDX, ADSVFP and for adt tables ADSADT. As in use tablename VIA ADSCDX. That's it.
Now, ADT tables as well as dbf tables can be used with ADS RDD as free tables or DD bound tables. Using DD bound tables is simply a lot better. Creating indexes with ads rdd can be done the same way it is done for dbf tables. Having said that, with ads you can also create indexes using the sp_createIndex stored procedure or with sql syntax.
Since I see there is some doubts on this subject, I wrote a short self contained sample of how to create .adt tables and indexes using regular clipper syntax. I haven't tested the code much, and it is been a long time since I use clipper syntax so there might be some errors, but you'll get the idea:
Hope that helps.
Reinaldo.
Is adt tables still an issue?
You still use the very same rdd_ads.lib with ntx/cdx/vfp or adt tables. All you do is change the RDD. For dbf tables with harbour you have the choice of using DBFNTX, DBFCDX, or ADSNTX, ADSCDX, ADSVFP and for adt tables ADSADT. As in use tablename VIA ADSCDX. That's it.
Now, ADT tables as well as dbf tables can be used with ADS RDD as free tables or DD bound tables. Using DD bound tables is simply a lot better. Creating indexes with ads rdd can be done the same way it is done for dbf tables. Having said that, with ads you can also create indexes using the sp_createIndex stored procedure or with sql syntax.
Since I see there is some doubts on this subject, I wrote a short self contained sample of how to create .adt tables and indexes using regular clipper syntax. I haven't tested the code much, and it is been a long time since I use clipper syntax so there might be some errors, but you'll get the idea:
Code: Select all | Expand
#include "ads.ch"
#xcommand DEFAULT <uVar1> := <uVal1> ;
[, <uVarN> := <uValN> ] => ;
<uVar1> := iif( <uVar1> == nil, <uVal1>, <uVar1> ) ;;
[ <uVarN> := iif( <uVarN> == nil, <uValN>, <uVarN> ); ]
REQUEST ADS
request hb_gt_win //needed for console mode app.
Static cPath
*-----------------------------------------------------------------------------------------------------
Function Main()
local nerr
local afiles
SetMode(25,80) //25 lines by 80 columns console
rddRegister( "ADS", 1 )
rddSetDefault( "ADS" )
adsSetServerType( ADS_LOCAL_SERVER )
AdsLocking( .t. ) //NON-compatible locking mode
cPath := hb_ArgV( 1 )
DEFAULT cpath := ""
if !empty( cPath ) .and. right( cPath, 1 ) != "\" ;cPath += "\" ;endif
afiles := CreateTables()
if !empty( afiles ) ;CreateDictionary( afiles ) ;endif
return nil
*--------------------------------------------------------------------------------------------------------
static function CreateTables()
local cAlias := "MyAlias"
local afiles := {}
local cFileName, e
//---------------------- customers.adt --------------------------------------------
local aStruc := { { "cust_id" , "C", 10, 0 },;
{ "Sequence" , "AutoInc", 07, 0 },; //ADT extended field type autoincrement
{ "customer_name" , "C", 25, 0 },;
{ "Start_date" , "TimeStamp", 01, 0 },; //ADT extended field type
{ "Notes" , "M", 10, 0 } }
AdsSetFileType( ADS_ADT )
TRY
dbCreate( ( cFileName := cPath + "customers.adt" ), aStruc,, .t., cAlias )
( cAlias )->( OrdCreate( cPath + "customers", "cust_id", "cust_id" ) )
( cAlias )->( OrdCreate( cPath + "customers", "Start_date", "Start_date" ) )
( cAlias )->( dbclosearea() )
aadd( afiles, { cFileName, "customers.adi" } )
//------------------------ sales.dbf -------------------------------------------------
aStruc := { { "cust_id" , "C", 10, 0 },;
{ "invoice" , "C", 15, 0 },;
{ "s_date" , "TimeStamp", 01, 0 },; //VFP extended field type
{ "item_id" , "C", 15, 0 },;
{ "Units" , "N", 03, 0 },;
{ "Price" , "Money", 09, 2 },; //VFP extended field type
{ "Notes" , "M", 10, 0 } }
AdsSetFileType( ADS_VFP )
dbCreate( ( cFileName := cPath + "sales.dbf" ), aStruc,, .t., cAlias )
( cAlias )->( OrdCreate( cPath + "sales", "invoice", "invoice" ) )
( cAlias )->( OrdCreate( cPath + "sales", "cust_id", "cust_id" ) )
( cAlias )->( dbclosearea() )
aadd( afiles, { cFileName, "sales.cdx" } )
//------------------------ items.dbf -------------------------------------------------
aStruc := { { "item_id" , "C", 15, 0 },;
{ "Desc" , "C", 25, 0 },;
{ "Price" , "N", 07, 2 } }
AdsSetFileType( ADS_NTX )
dbCreate( ( cFileName := cPath + "items.dbf" ), aStruc,, .t., cAlias )
( cAlias )->( OrdCreate( cPath + "itm_id",, "item_id" ) )
( cAlias )->( OrdCreate( cPath + "itm_desc",, "Desc" ) )
( cAlias )->( dbclosearea() )
aadd( afiles, { cFileName, "itm_id.ntx;itm_desc.ntx" } )
CATCH e
ShowError( cFileName, e )
afiles := {}
END
return afiles
/*--------------------------------------------------------------------------------------------------------
CreateDictionary creates an Advantage Data Dictionary based on already existing tables
--------------------------------------------------------------------------------------------------------*/
static function CreateDictionary( afiles )
local cExt AS CHARACTER := ""
local cDD := cPath + "test_dd.add"
if !ADSDDCREATE( cDD,, "Sample data dictinoary" )
Alert( "AdsCreate() of " + cDD + " failed. Error:" + Str( AdsGetLastError() ) )
return nil
Endif
AdsDDSetDatabaseProperty( ADS_DD_ENABLE_INTERNET, .t. )
AdsDDSetDatabaseProperty( ADS_DD_INTERNET_SECURITY_LEVEL, ADS_DD_LEVEL_2 )
AdsDDSetDatabaseProperty( ADS_DD_DEFAULT_TABLE_PATH, cPath )
AdsDDSetDatabaseProperty( ADS_DD_LOG_IN_REQUIRED, .t. )
AdsDDCreateUser( , "user1", "password1", "User named userd1 with password password1" )
AdsDDCreateUser( , "user2", "password2", "Description of user2" )
AdsDDCreateUser( , "user3", "password3", "Optional description of user3" )
aEval( aFiles, ;
{ |e| hb_FNameSplit( iif( len( e ) > 1, e[ 2 ], e[ 1 ] ), , , @cExt ), ;
AdsSetFiletype( iif( lower( cExt ) $ ".adt,.adi", ADS_ADT, ;
iif( lower( cExt ) == ".ntx", ADS_NTX, ADS_VFP ) ) ),;
addfiletoDD( e, cPath ), ;
SetTableProp( e ), ;
QOut( "Adding table to DD", ;
e[ 1 ], ;
AdsSetFileType(), ;
cExt, ;
ADSGetLastError() ) } )
AdsDDSetDatabaseProperty( ADS_DD_ADMIN_PASSWORD, "password" )
Wait
return Nil
*-------------------------------------------------------------------------------------------------------------------------------
Static Function AddFiletoDD( aFile, cPath )
local cIndexs := ""
if len( afile ) > 1 .and. left( afile[ 2 ], 1 ) <> "."
aEval( afile, { |e| cIndexs += e +";" }, 2 )
cIndexs := left( cIndexs, len( cIndexs ) -1 )
Endif
Return( AdsDDAddTable( left( afile[ 1 ], at(".", afile[1] )-1 ), ;
cPath + aFile[ 1 ], ;
cIndexs ) )
*-------------------------------------------------------------------------------------------------------------------------------
static function SetTableProp( aFile )
local cFileName
hb_FNameSplit( afile[ 1 ],, @cFileName )
// AdsDDSetTableProperty( cFileName, ADS_DD_TABLE_AUTO_CREATE, .t. )
// AdsDDSetTableProperty( cFileName, ADS_DD_TABLE_ENCRYPTION, .t. )
return Nil
*-------------------------------------------------------------------------------------------------------------------------------
static function ShowError( cMsg, oErr )
local cErr
cErr := Str( AdsGetLastError() )
Alert( "Error : " + alltrim( cErr ) + " " + ;
cMsg + " " + oErr:Subsystem + " " + ;
str( oErr:subCode ) + " " + oErr:operation + " " + oErr:description )
dbcloseall()
return nil
Hope that helps.
Reinaldo.