Understanding Database Timelines
Contents
See Also
ALTER DATABASE, CLEAR TIMELINE, Database Timelines Commands and Functions, Database Timelines (Video), LIST TIMELINE, MetaData Editor, ROLLBACK TIMELINE, SET SYSTIMELINE, SET TIMELINE, SET TIMESTAMP, Systimeline System Table, TIMELINE(), Timeline Section Attributes
What are Database Timelines?
Lianja database timelines provide row versioning for database tables for all CRUD operations performed on data. Whenever a change is made to a table that is timeline enabled then delta changes are automatically recorded for each transaction. Changes made to any tables that are timeline enabled can be undone much like you would undo changes to program code that you edit in a text editor.
Database timelines record who did what from where, when they did it and what they changed.

Database timelines can be enabled for all the tables in a database:
alter database southwind metadata "timeline=on"
Using Database Timelines
Database timelines can be enabled for all the tables in a database:
alter database southwind metadata "timeline=on"
or for individual tables:
open database southwind alter table customers metadata "timeline=on" alter table orders metadata "timeline=on"
and to disable timelines:
alter database southwind metadata "timeline=off"
open database southwind alter table customers metadata "timeline=off" alter table orders metadata "timeline=off"
Viewing a timeline
Timeline data can be viewed in the following ways:
- In the Data Workspace
- Using a Timeline Section
- Using the List Timeline command
- Using SQL Select command
Data Workspace
With a table open in the Data Editor, click the Timeline View toolbutton in the header to open the Timeline View.
In the Timeline View header the date range to be viewed can be selected: 'Today', 'Yesterday', 'This week', 'This month' or 'From' date and 'To' date.
The header also has a 'Refresh' option.
Timeline Section
With a data-bound Section (e.g. Form, Grid, Canvas) on the Page, add a Timeline Section from the Form Tools.
Relate the parent Section to the child Timeline Section.
In the Timeline header the date range to be viewed can be selected: 'Today', 'Yesterday', 'This week', 'This month' or 'From' date and 'To' date.
The Section can be refreshed using the icon in the Section header.
List Timeline
list timeline [range <begin as string-date> [, <end as string-date>]] | [since <begin as string-date>] [for <condition as logical>] [to file <filename as character>]
To view a timeline for a particular table e.g.
list timeline for table = "customers"
To view a timeline for a particular date or date range, use the range or since keywords. Notice that the dates are encoded as a string in the format "YYYYMMDDHH:MM:SS:". This can be abbreviated e.g.
// list the timeline since 1st October 2017 list timeline since "20171001" // list the timeline for 1st October 2017 only list timeline range "20171001" // list the timeline between the 1st and 31st of October 2017 list timeline range "20171001","20171031" // send the listing to a text file list timeline range "20171001","20171031" to file thismomth.txt
SQL Select
SQL SELECT can be used to query the system systimeline table directly:
select * from system!systimeline
SQL SELECT can also be used with the Lianja Data Object functions (rdo_xxx() functions) to traverse the timeline and generate html to populate a WebView Section if required e.g.
<%@ Language=VFP %> <html> <head> <style> table { font-family: arial, sans-serif; border-collapse: collapse; width: 100%;} td, th { border: 1px solid #dddddd; text-align: left; padding: 8px;} tr:nth-child(even) { background-color: #dddddd;} </style> </head> <body> <% results = rdo_query("SELECT * FROM system!systimeline ; WHERE between(left(timestamp,8), '20171001', '20171031')") ? "<h3>Timeline report</h3>" ? "<table>" ? "<tr><th>Table</th><th>User</th><th>Date</th><th>Command</th></tr>" foreach results as row ? "<tr><td>" + row["TABLE"] + "</td><td>" + row["USER"] + "</td><td>"; + left(row["TIMESTAMP"],8) + " " + right(row["TIMESTAMP"],8) ; + "</td><td>" + row["COMMAND"] + "</td></tr>" endfor ? "</table>" results = null %> </body> </html>
Undoing database changes
- In the Data Workspace
- Using a Timeline Section
- Using the Rollback Timeline command
Data Workspace
Click the undo icon at the far right of the row to undo that individual change.
You will be prompted to confirm the undo action.
Select the data range in the Timeline View header.
Click the undo icon in the date sub-header to undo all the changes for that date range.
You will be prompted to confirm the undo action.
Timeline Section
Click the undo icon at the far right of the row to undo that individual change.
You will be prompted to confirm the undo action.
Select the data range in the Timeline header.
Click the undo icon in the date sub-header to undo all the changes for that date range.
You will be prompted to confirm the undo action.
Rollback Timeline
You can undo database changes with the rollback timeline command. The range and for clauses can also be specified in the same way as the list timeline command e.g.
rollback timeline [range <begin as string-date> [, <end as string-date>]] [for <condition as logical>]
To see how many transactions would be rolled back prefix the rollback timeline command with explain.
explain rollback timeline [range <begin as string-date> [, <end as string-date>]] [for <condition as logical>]
Clearing a timeline
The clear timeline command will reset a timeline.
clear timeline