DBTimestamp2.gms : Retrieves Data from Database once each Day

Description

Retrieve data from database once each day. Day of month in 'dbtimestamp.inc'
is compared with current day and if they are different, data are selected
and 'dbtimestamp.inc' is updated with current date. Note that if 'dbtimestamp.inc'
does not exist, it is created with day of month equaling to '0' to ensure data
selection.

This model is referenced in section "Strategies" from the SQL2GMS Documentation.

Keywords: SQL2GMS, data exchange, GAMS language features


Category : GAMS Data Utilities library


Main file : DBTimestamp2.gms   includes :  Transportation.accdb  DBTimestamp2.gms  SQLSr0.gms

$title Retrieves Data from Database once each Day (DBTimestamp2,SEQ=057)

$onText
Retrieve data from database once each day. Day of month in 'dbtimestamp.inc'
is compared with current day and if they are different, data are selected
and 'dbtimestamp.inc' is updated with current date. Note that if 'dbtimestamp.inc'
does not exist, it is created with day of month equaling to '0' to ensure data
selection.

This model is referenced in section "Strategies" from the SQL2GMS Documentation.

Keywords: SQL2GMS, data exchange, GAMS language features
$offText

$callTool win32.msappavail Access
$if errorlevel 1 $abort.noError "No Access available"

* C=Provider=Microsoft.ACE.OLEDB.12.0;Data Source=.\Transportation.accdb
$onEcho > getDate.txt
C=DRIVER=Microsoft Access Driver (*.mdb, *.accdb);dbq=.\Transportation.accdb
Q=SELECT day(now())
O=dbtimestamp.inc
$offEcho

$if not exist dbtimestamp.inc $call "echo 0 > dbtimestamp.inc"

Scalar dbtimestamp 'day of month when data was retrieved' /
$include dbtimestamp.inc
/;

Scalar currentday 'day of this run';
currentday = gday(jnow);

display "compare", dbtimestamp, currentday;

if(dbtimestamp <> currentday,
   execute '=gams.exe SQLsr0 lo=%GAMS.lo% gdx=transportation.gdx';
   abort$errorLevel "step 0 (database access) failed";
   execute 'sql2gms.exe @getDate.txt > %system.nullfile%'
);