FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour ADS and DATA DICTIONARY
Posts: 1303
Joined: Tue Jul 21, 2009 08:12 AM
ADS and DATA DICTIONARY
Posted: Tue Mar 27, 2012 07:47 PM
Hello,

When working with tables in a Data Dictionary, how do you reindex and create indexes?.

Thank you very much.

Best regards,

Lucas
Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producci贸n]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: ADS and DATA DICTIONARY
Posted: Tue Mar 27, 2012 09:27 PM

Hello,

you can use a Store Procedure to do that

sp_CreateIndex
sp_CreateIndex90

regards

Marcelo

Posts: 1303
Joined: Tue Jul 21, 2009 08:12 AM
Re: ADS and DATA DICTIONARY
Posted: Wed Mar 28, 2012 10:21 AM

Hello Marcelo,

thanks for reply.

But you don麓t use INDEX ON TO..?.

Please, can I see a piece of code?.

Thank you very much.

Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producci贸n]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: ADS and DATA DICTIONARY
Posted: Wed Mar 28, 2012 12:16 PM

Hola,

from the ADS help file

sp_CreateIndex( TableName,CHARACTER,515,
FileName,CHARACTER,515,
TagName,CHARACTER,128,
Expression,CHARACTER,510,
Condition,CHARACTER,510,
Options,INTEGER,
PageSize,INTEGER );

Posts: 1303
Joined: Tue Jul 21, 2009 08:12 AM
Re: ADS and DATA DICTIONARY
Posted: Wed Mar 28, 2012 12:17 PM

Hello,

And how do you reindex?.

Thank you

Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producci贸n]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: ADS and DATA DICTIONARY
Posted: Wed Mar 28, 2012 12:27 PM
From the help file too, and with sample at the end of the page

Rebuilds all auto-open indexes associated with the given table.



Syntax

sp_Reindex( TableName,CHARACTER,515,

PageSize, INTEGER )



Parameters

TableName (I)
Name of table to rebuild indexes on. This can include path information for free tables if the table is in a different folder from the connection path.

PageSize (I)
The page size to use when rebuilding indexes on ADT tables. This is ignored for other table types. If the value 0 is given, the existing page size is used. Valid page sizes can be any value from 512 to 8192. Refer to Index Page Size and Index Key Size and Page Size Relationships for more information. Note that if the table is in an Advantage Data Dictionary, then only the administrator connection can be used to change the page size when reindexing a table.




Remarks

sp_Reindex rebuilds all auto-open indexes associated with the given table. Because the reindex operation requires exclusive access to the table, no other connections can have the table open when this is called.



Example



-- Rebuild all auto-open indexes on mytable with a page size of 1024

EXECUTE PROCEDURE sp_Reindex( 'mytable.adt', 1024 );

Posts: 1074
Joined: Fri Oct 07, 2005 01:56 PM
Re: ADS and DATA DICTIONARY
Posted: Wed Mar 28, 2012 01:43 PM
Lukas

Si las tablas ya tienen index puedes usar esto

Code (fw): Select all Collapse
聽 聽 aIndex := AdsDirectory()

聽 聽 for i := 1 to len( aIndex )
聽 聽 聽 聽 cDbf := Left( aIndex[i], len( aIndex[i] )-1 )
聽 聽 聽 聽 if Netuse( cDbf, .f. ) //abrimo la tabla exclusivo
聽 聽聽聽 聽 聽 聽PACK
聽 聽 聽 聽 聽 聽if ADSGETNUMINDEXES() > 0 // revisamos si la tabla tiene indice
聽 聽 聽 聽 聽 聽 聽 AdsReindex() 聽//reindexamo
聽 聽 聽 聽 聽 聽endif
聽 聽 聽 聽 endif
聽 聽 聽 聽 USE
聽 聽 next i
Saludos
Patricio

__________________________________________________________________
Version: Harbour 3.2.0dev (r1307082134),Compiler: Borland C++ 5.8.2 (32-bit)
PCode version: 0.3, FWH 13.2
http://www.sialm.cl
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: ADS and DATA DICTIONARY
Posted: Wed Mar 28, 2012 04:57 PM
esto lo hice a partir del ejemplo anterior.
Code (fw): Select all Collapse
PROCEDURE Reorganizar()
聽 聽LOCAL cTabla
聽 聽LOCAL aTablas
聽 聽LOCAL oError

聽 聽IF !MsgNoYes( "Para realizar este proceso, ningun usuario debe estar conectado al programa, desea continuar?" )
聽 聽 聽 RETURN
聽 聽ENDIF

聽 聽IF !ADSRunSQL( "TABLAS", "SELECT * FROM SYSTEM.TABLES" )
聽 聽 聽 RETURN
聽 聽ELSE
聽 聽 聽 aTablas := {}
聽 聽 聽 TABLAS->( DBEval( {|| AAdd( aTablas, RTrim( FIELD->NAME ) ) } ), DBCloseArea() )
聽 聽 聽 IF Len( aTablas ) = 0
         TABLA->(dbclosearea())
聽 聽 聽 聽 聽RETURN
聽 聽 聽 ENDIF
聽 聽ENDIF

聽 聽WaitOn( "Cerrando tablas..." )
聽 聽DbCloseAll()
聽 聽WaitOff()

聽 聽WaitOn( "Reorganizando datos..." )
聽 聽CursorWait()

聽 聽FOR EACH cTabla IN aTablas
聽 聽 聽 TRY
聽 聽 聽 聽 聽USE (cTabla) NEW EXCLUSIVE
聽 聽 聽 聽 聽IF !NetErr()
聽 聽 聽 聽 聽 聽 IF AdsGetNumIndexes() > 0
聽 聽 聽 聽 聽 聽 聽 聽IF !AdsReindex()
聽 聽 聽 聽 聽 聽 聽 聽 聽 MsgInfo( AdsGetLastError(), "Usuario" )
聽 聽 聽 聽 聽 聽 聽 聽ENDIF
聽 聽 聽 聽 聽 聽 ENDIF
聽 聽 聽 聽 聽ENDIF
聽 聽 聽 聽 聽DBCloseArea()
聽 聽 聽 CATCH oError
聽 聽 聽 聽 聽MsgAlert( "Error reorganizando informaci贸n en tabla en: " + Upper( cTabla ) + FINL + oError:Description )
聽 聽 聽 END
聽 聽NEXT

聽 聽CursorArrow()
聽 聽WaitOff()

聽 聽MsgRun( "Espere un momento, abriendo nuevamente tablas de datos.", "CREDICOM", {|| Conectar_AbrirTablas( TRUE, TRUE ) } )

RETURN
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 1303
Joined: Tue Jul 21, 2009 08:12 AM
Re: ADS and DATA DICTIONARY
Posted: Wed Mar 28, 2012 07:00 PM

Hello,

Thank you both very much, Patricio and Carlos.

The point is that with a Data Dictionary INDEX ON TO.. does not work. AdsReindex() should be used instead. But I could not find this nor in the documentation nor in Rene Flore麓s manual.

Using Remote or Local server works the same as RDDCDX, but not when using a data dictionary.

Thanks a lot!!!

Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producci贸n]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: ADS and DATA DICTIONARY
Posted: Thu Mar 29, 2012 12:08 AM

en un diccionario es necesario usar la funciones

EXECUTE PROCEDURE sp_CreateIndex90(
'caja',
'caja.adi',
'NUM_CIUD',
'num_ciud',
'',
2,
512,
'' );

Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: ADS and DATA DICTIONARY
Posted: Thu Mar 29, 2012 12:10 AM
creacion por codigo de un dd, talas e indices.

salu2

Code (fw): Select all Collapse
/*
    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, hConnection2
   local lIsDict := .f.

   CLS

   RddSetDefault("ADT")
   AdsSetServerType ( 7 )
   SET Filetype to ADT

   ? "Default connection is 0:", adsConnection()

   fErase("xharbour.add")
   fErase("xharbour.ai")
   fErase("xharbour.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("xharbour.add")
      ADSDDCREATE("xharbour.add",, "Xharbour 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 id TAG codigo
      USE

      USE table2 new
      INDEX ON id TAG codigo
      USE
   ENDIF

   // now the magic
   IF adsConnect60("xharbour.add", 7/* All types of connection*/, "ADSSYS", "", , @hConnection1 )
      // The connection handle to xharbour.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 xharbour.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("xharbour.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)
            AdsExecuteSqlDirect(" insert into Table1( name,address,city,age) VALUES( '" + strzero(n)+"','"+strzero(n)+"','"+strzero(n)+"'," +str(n)+ ")" )
            USE
         ENDIF
      NEXT

      FOR n := 1 TO 100
         IF AdsCreateSqlStatement("Data1", 3)
            AdsExecuteSqlDirect(" insert into " +'"Customer Data"'+"( name,address,city,age) VALUES( '"+ strzero(n)+"','"+strzero(n)+"','"+strzero(n)+"'," +str(n)+")" )
            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
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)

Continue the discussion