OraLogo Ora Tool

English  Italiano

DAO Gen Button  DAO (Data access object)

OraTool fornisce un automatismo per la creazione di DAO PL/SQL per effettuare le operazioni base sulle tabelle e i Tipi:

Come si usano i DAO

Supponiamo di avere una tabella Users in cui registriamo gli utenti di sistema ed una tabella Log_Access con cui monitoriamo gli accessi:

-- Create Table
Create Table Users
      (Iduser NUMBER(38,0),
       Username VARCHAR2(10),
       Password VARCHAR2(10),
       Pagesvisited NUMBER(38,0))
tablespace USERS
Storage (initial 64K) ;

-- Primary Key on table Users
Alter Table Users Add Constraint USERS_PK Primary Key (IDUSER);

-- Create Table
Create Table Log_Access
      (Idlog NUMBER(38,0),
       Iduser NUMBER(38,0),
       Datetime DATE,
       Page VARCHAR2(100))
tablespace USERS
Storage (initial 64K) ;

-- Primary Key on table Log_Access
Alter Table Log_Access Add Constraint LOG_ACCESS_PK Primary Key (IDLOG);

-- Foreign Key on table Log_Access
Alter Table Log_Access Add Constraint LOG_ACCESS_FK1 Foreign Key (IDUSER)
references USERS;
 

A questo punto supponiamo di dovere creare un script con cui aggiornare il numero di pagine visitate sulla tabella Users.

Dopo aver generato i DAO con l'apposito pulsante DAO Gen รจ sufficiente lanciare:

Declare
  Cursor cUsers is
    Select *
    From Users;

Begin
  For rUsers in cUsers Loop
    -- Calculate the number of pages visited
    Select count(*)
    Into rUsers.PagesVisited
    from Log_Access
    where Iduser = rUsers.Iduser;
    
    -- Update Users using Dao
    Dao_update.Users (rUsers, rUsers);
    
    -- Trace rUsers record
    Dao_Log.Users (rUsers);
  End Loop;
End; 
 
Get oraTool at SourceForge.net. Fast, secure and Free Open Source software downloads Project hosted by