Insert, update, and delete

Finally, the most common scenario is the one where we fully manage the source by checking for new, modified, or deleted records. 

The script will be the same as the one used in the insert and update scenario; however, we must add a join to the source to eliminate from our QVD those records that have been deleted after we saved the QVD file.

The following block of code inserts, updates, and deletes records from the source:

/* I treat my table keys as system fields by hiding them. We do not want to use the keys in the front end and therefore we shouldn't show them. */

set HidePrefix='%' ;

/* I check if the file exists. If it doesn't I do a full load, if it does I perform the incremental load. */

IF IsNull(QvdCreateTime('C:myQVDCountries.qvd')) THEN

TRACE Performing full load of data source;

Countries:
SELECT * FROM COUNTRY;

STORE Countries INTO C:myQVDCountries.qvd (qvd);

ELSE
TRACE File exists. Performing incremental load;

maxDate:
LOAD max(LastModifiedDate) AS MaxModifiedDate
FROM c:myQVDCountries.qvd (qvd);

TRACE Storing the most current modified date into a variable.;

LET vMaxModifiedDate = peek(MaxModifiedDate);

TRACE Loading new records from the source.;

Countries:
SELECT * FROM COUNTRY
WHERE LastModifiedDate > $(vMaxModifiedDate)
;

TRACE Appending stored records to new ones.;

Concatenate
LOAD * FROM c:myQVDCountries.qvd (Qvd)
WHERE Not EXISTS(%Id);

TRACE We join the final table with all the current keys in the source to remove the delete records.;

INNER JOIN
SQL SELECT %Id FROM COUNTRY;

TRACE Storing modified qvd file.;


STORE Countries INTO c:myQVDCountries.qvd (Qvd);

ENDIF
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.70.38