Difference between revisions of "Understanding database timelines in Lianja"

From Lianjapedia
Jump to: navigation, search
(Rollback Timeline)
(SQL Select)
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
''Under Construction''
+
{{DISPLAYTITLE:Understanding Database Timelines}}
  
 
=See Also=
 
=See Also=
[[ALTER DATABASE]], [[ALTER TABLE]], [[:Category:Database Timelines|Database Timelines Commands and Functions]], [[Database Timelines (Video)]], [[SYSTIMELINE|Systimeline System Table]], [[Timeline Section Attributes]]  
+
[[ALTER DATABASE]], [[CLEAR TIMELINE]], [[:Category:Database Timelines|Database Timelines Commands and Functions]], [[Database Timelines (Video)]], [[LIST TIMELINE]], [[MetaData Editor]], [[ROLLBACK TIMELINE]], [[SET SYSTIMELINE]], [[SET TIMELINE]], [[SET TIMESTAMP]], [[SYSTIMELINE|Systimeline System Table]], [[TIMELINE()]], [[Timeline Section Attributes]]
  
 
=What are Database Timelines?=
 
=What are Database Timelines?=
Line 8: Line 8:
  
 
Database timelines record who did what from where, when they did it and what they changed.
 
Database timelines record who did what from where, when they did it and what they changed.
 +
 +
<div style="height:80px;margin-bottom:5px;padding:5px;border:0px solid orange;border-left:5px solid orange;background:#fff8dc;vertical-align:middle;position:relative;">
 +
[[File:bm-noteicon.png|top|40px|link=]]<div style="position:absolute;top:3px;margin-bottom;bottom:5px;margin-left:50px;"><b> Quick Start Guide</b>
 +
Database timelines can be enabled for all the tables in a database:<br/>
 +
''alter database southwind metadata "timeline=on"''
 +
</div>
 +
<span style="height:6px;"> </span>
 +
</div>
  
 
=Using Database Timelines=
 
=Using Database Timelines=
 
Database timelines can be enabled for all the tables in a database:  
 
Database timelines can be enabled for all the tables in a database:  
<pre>
+
<code lang="recital">
 
alter database southwind metadata "timeline=on"
 
alter database southwind metadata "timeline=on"
</pre>
+
</code>
 
or for individual tables:
 
or for individual tables:
<pre>
+
<code lang="recital">
 
open database southwind
 
open database southwind
 
alter table customers metadata "timeline=on"
 
alter table customers metadata "timeline=on"
 
alter table orders metadata "timeline=on"
 
alter table orders metadata "timeline=on"
</pre>
+
</code>
  
 
and to disable timelines:  
 
and to disable timelines:  
<pre>
+
<code lang="recital">
 
alter database southwind metadata "timeline=off"
 
alter database southwind metadata "timeline=off"
</pre>
+
</code>
<pre>
+
<code lang="recital">
 
open database southwind
 
open database southwind
 
alter table customers metadata "timeline=off"
 
alter table customers metadata "timeline=off"
 
alter table orders metadata "timeline=off"
 
alter table orders metadata "timeline=off"
</pre>
+
</code>
  
 
==Viewing a timeline==
 
==Viewing a timeline==
Line 57: Line 65:
  
  
With a data-bound Section (e.g. Form, Grid, Canvas) on the Page, add a '''Timeline Section''' from the Form Tools.
+
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.
 
Relate the parent Section to the child Timeline Section.
Line 68: Line 76:
  
 
===List Timeline===
 
===List Timeline===
<pre>
+
<code lang="recital">
 
list timeline
 
list timeline
 
  [range <begin as string-date> [, <end as string-date>]] | [since <begin as string-date>]
 
  [range <begin as string-date> [, <end as string-date>]] | [since <begin as string-date>]
 
  [for <condition as logical>]
 
  [for <condition as logical>]
 
  [to file <filename as character>]
 
  [to file <filename as character>]
</pre>
+
</code>
  
 
To view a timeline for a particular table e.g.
 
To view a timeline for a particular table e.g.
  
<pre>
+
<code lang="recital">
 
list timeline for table = "customers"
 
list timeline for table = "customers"
</pre>
+
</code>
  
To view a timeline since a certain date use the '''range''' or '''since''' keywords. Notice that the date range is encoded as a string in the format "YYYYMMDDHH:MM:SS:". This can be abbreviated  e.g.
+
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.
  
<pre>
+
<code lang="recital">
 
// list the timeline since 1st October 2017
 
// list the timeline since 1st October 2017
list timeline range "20171001"
 
// or
 
 
list timeline since "20171001"
 
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 the timeline between the 1st and 31st of October 2017  
Line 94: Line 103:
 
// send the listing to a text file
 
// send the listing to a text file
 
list timeline range "20171001","20171031" to file thismomth.txt
 
list timeline range "20171001","20171031" to file thismomth.txt
</pre>
+
</code>
  
 
===SQL Select===
 
===SQL Select===
 
[[SQL SELECT]] can be used to query the [[SYSTIMELINE|system systimeline]] table directly:
 
[[SQL SELECT]] can be used to query the [[SYSTIMELINE|system systimeline]] table directly:
<pre>
+
<code lang="recital">
 
select * from system!systimeline
 
select * from system!systimeline
</pre>
+
</code>
  
 
[[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.
 
[[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.
Line 123: Line 132:
 
<body>
 
<body>
 
<%
 
<%
results = rdo_query("SELECT * FROM system!systimeline WHERE between(timestamp, '20171001', '20171031')")
+
results = rdo_query("SELECT * FROM system!systimeline ;
 +
                                        WHERE between(left(timestamp,8), '20171001', '20171031')")
 
? "<h3>Timeline report</h3>"
 
? "<h3>Timeline report</h3>"
 
         ? "<table>"
 
         ? "<table>"
Line 129: Line 139:
 
foreach results as row
 
foreach results as row
 
       ? "<tr><td>" + row["TABLE"] + "</td><td>" + row["USER"] + "</td><td>";
 
       ? "<tr><td>" + row["TABLE"] + "</td><td>" + row["USER"] + "</td><td>";
           + left(row["TIMESTAMP"],8) + "  " + right(row["TIMESTAMP"],8)+ "</td><td>" + row["COMMAND"] + "</td></tr>"
+
           + left(row["TIMESTAMP"],8) + "  " + right(row["TIMESTAMP"],8) ;
 +
          + "</td><td>" + row["COMMAND"] + "</td></tr>"
 
endfor
 
endfor
 
? "</table>"
 
? "</table>"
Line 196: Line 207:
 
You can undo database changes with the [[ROLLBACK TIMELINE|rollback timeline]] command. The '''range''' and '''for''' clauses can also be specified in the same way as the [[LIST TIMELINE|list timeline]] command e.g.
 
You can undo database changes with the [[ROLLBACK TIMELINE|rollback timeline]] command. The '''range''' and '''for''' clauses can also be specified in the same way as the [[LIST TIMELINE|list timeline]] command e.g.
  
<pre>
+
<code lang="recital">
 
rollback timeline [range <begin as string-date> [, <end as string-date>]]
 
rollback timeline [range <begin as string-date> [, <end as string-date>]]
 
  [for <condition as logical>]
 
  [for <condition as logical>]
</pre>
+
</code>
  
 
To see how many transactions would be rolled back prefix the '''rollback timeline''' command with '''explain'''.
 
To see how many transactions would be rolled back prefix the '''rollback timeline''' command with '''explain'''.
  
<pre>
+
<code lang="recital">
 
explain rollback timeline [range <begin as string-date> [, <end as string-date>]]
 
explain rollback timeline [range <begin as string-date> [, <end as string-date>]]
 
  [for <condition as logical>]
 
  [for <condition as logical>]
</pre>
+
</code>
  
 
==Clearing a  timeline==
 
==Clearing a  timeline==
 
The [[CLEAR TIMELINE|clear timeline]] command will reset a timeline.
 
The [[CLEAR TIMELINE|clear timeline]] command will reset a timeline.
  
<pre>
+
<code lang="recital">
 
clear timeline
 
clear timeline
</pre>
+
</code>
  
 
[[Category:Database Timelines]]
 
[[Category:Database Timelines]]

Latest revision as of 17:52, 27 March 2020


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.

Bm-noteicon.png
Quick Start Guide

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:

Data Workspace

Data Workspace: Timeline View


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

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

Data Workspace

Data Workspace: Undo individual change



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.


Data Workspace: Undo changes for date range



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

Timeline Section: Undo individual change


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.


Timeline Section: Undo changes for date range


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