Store a report definition in database field

From DBReport wiki
Jump to: navigation, search

In this tutorial a database is used for store report definition. The goal is save and retrieve a report definition from a column table of database.

Requirements

Walkthrough

  1. Open Tutorial01 project.
  2. Add sakila_rpts database.
  3. Add a button, change caption to "Desig. db".
  4. Add code for Desig. db to Action event.
  5. Add a button, change caption to "Print db".
  6. Add code for Print db to Action event.
  7. Save project as Tutorial04
  8. Run app.
  9. Click on Desig. db button.
  10. Click on Export button.
  11. Choose "Import" from popup menu.
  12. Select "Template.xml" from desktop.

A video show an example here.

Code for "Desig. db" button

Dim s As String
Dim i As Boolean
Dim r As RecordSet= sakila_rpts.SQLSelect("SELECT * FROM  reports WHERE name= 'Tutorial04';")
 
If r<> Nil Then
  If Not r.EOF Then
    s= r.Field("definition").StringValue
  Else
    i= True //INSERT
  End If
End If
 
r= sakila.SQLSelect("SELECT * FROM customer")
 
Dim rpt As New DBReport(s, r)
rpt.Designer "{""ShowExpImpBtn"": True}"
 
// Prepare statement
Dim p As PreparedSQLStatement
 
If i Then
  p= sakila_rpts.Prepare("INSERT INTO reports (group_name, name, definition) VALUES ('Tutorials', ?, ?)")
Else
  p= sakila_rpts.Prepare("UPDATE reports SET name= ? WHERE definition= ?")
End If
p.BindType(0, SQLitePreparedStatement.SQLITE_TEXT)
p.BindType(1, SQLitePreparedStatement.SQLITE_TEXT)
 
p.SQLExecute("Tutorial04", rpt.GetXML)

Code for "Printer db" button

Dim s As String
Dim r As RecordSet= sakila_rpts.SQLSelect("SELECT * FROM  reports WHERE name= 'Tutorial04';")
 
If r<> Nil Then
  s= r.Field("definition").StringValue
End If
 
r= sakila.SQLSelect("SELECT * FROM customer")
 
Dim rpt As New DBReport(s, r)
 
rpt.Print