400 users using DBSP now!
home -> documentation -> environment guide -> DBSP Foundations

One of the DBSP project goals, is to make it easy to learn. For this reason, DBSP language has a markup language syntax like HTML or XML. This contributes to a shorter learning curve and enables a perfect coupling between HTML or XML and DBSP.

A simple DBSP example

Consider the following example. Suppose you want to create an HTML table based on the results of a SQL Query. The columns of the table and its HTML code are shown below:

Employee No. Name Department Salary
       

<table border="1" cellspacing="0" cellpadding="1">
<tr>
<td width="80">Employee No.</td>
<td width="250">Name</td>
<td width="150">Department</td>
<td width="120">Salary</td>
</tr>
<tr>
<td>1</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>

Now, consider the SQL sentence that you will use to fill the table is this :

SELECT EMPNO, NAME, DEPARTMENT, SALARY FROM EMPLOYEE

 

With DBSP you could accomplish this task with the following steps:

1. Connect to the database using the DBSP Builder (Main DBSP graphical development tool).




2. Create a new SQL Sentence object an insert the SQL sentence.




3. DBSP will assign an OBJECT ID for the sentence. We will use this ID to access the QUERY from the DBSP document. In order to do this, we will need to modify the code in the following way:

<table border="1" cellspacing="0" cellpadding="1">
<tr>
<td width="80">Employee No.</td>
<td width="250">Name</td>
<td width="150">Department</td>
<td width="120">Salary</td>
</tr>

<#DATASET ALIAS="DEMO" QUERYID="1">

<!-- Inside this block, you have access to the columns of the SQL sentence by just typing the column name !-->
<tr>
<td><#EMPNO></td>
<td><#NAME></td>
<td><#DEPARTMENT></td>
<!-- You can apply several displaying formats to the data, like in the following column: !-->
<td><#SALARY FORMAT="MONEY:8:2"></td>
</tr>

<#/DATASET>
</table>

 

4. In this case the DATASET element will clearly define the scope for the SQL query. This means that you know exactly where the block starts and where the block ends. Inside this block you will have immediate access to the contents of the query, so the final result will be:

Employee No. Name Department Salary
1 Leonardo da Vinci Creative Design $ 15,000
2 Nicolás Maquiavelo Political Affairs $ 11,000
3 Carl Sagan Astronomy $ 12,500

As you can notice, the block delimited by the DATASET element will be inserted for each row that the query contains.

This is a brief introduction to the DBSP philosophy. For more detailed information, keep on reading.

Previous | Next