Monday, 9 January 2012
Linux support restored
Saturday, 24 September 2011
Data Visualisation
There are lots of charting and data visualisation libraries, but adding a package such as Visiblox to Pyrrho would more than double its size (the Visiblox DLL is 797KB, while Pyrrho is 700KB). So for now I plan to code the extensions myself.
I have added a set of metadata flags for Tables and Columns that activate the charting code. As usual these are role specific so it is easy to imagine a data visualisation role, with multiple charts for tables. By design column metadata can also be added to views. The flags can be added using ALTER syntax, e.g.
alter table monthlysales series ‘Sales analysis by month’
alter table monthlysales alter mth X ‘Month’
alter table monthlysales alter total line ‘Total Sales $M’
alter table monthlysales alter recurring line ‘Repeat Orders $M’
The following flags have been added so far:
| Output flag | Context | Effect |
|---|---|---|
| Pie | Table/View | Pie chart |
| Series | Table/View | Data Series |
| Points | Table/View | Scatter chart |
| Caption | Column | Column contains strings to annotate chart points |
| X | Column | Common column for series or X for X-Y plot. The plan here is that X could be a string, an int, or a real |
| Y | Column | Y column for points chart. Data should be int or real |
| Histogram | Column | For bar series chart: description string is for legend |
| Line | Column | For line series chart: description string is for legend |
Monday, 12 September 2011
Using the WPF DataGrid
Sunday, 11 September 2011
Application Programming with POCO
You can paste these class definitions into your application program. If this has been done for a MOVIE class in a database called Movies, the following simple code works:
using Pyrrho;
class Test
{
public static void Main(string[] args)
{
var db = new PyrrhoConnect("Files=Movies");
db.Open();
var obs = db.Get("/MOVIE");
foreach(MOVIE m in obs)
Console.WriteLine(m.TITLE);
db.Close();
}
}
POCO stands for Plain Old CLR Object. The above example is using the following API in the PyrrhoConnect class:
| Property or Method signature | Explanation |
|---|---|
| object[] Get(string rurl) | Return the set of objects selected by the given relative URL |
| void Get(object ob,string rurl) | The actual type of the object should match the first object returned by the URL. Fills the object with the data returned. |
| void Post(object ob) | Installs the given object as a new row in the appropriate base table. |
| void Put(object old,object ob) | The old object should have been obtained from the database using one of the Get methods above. ob should be an updated version of this: the database will be updated. |
| void Delete(object ob) | The object should have been obtained from the database using one of the Get methods above. The object will be deleted from the database. |
Thursday, 8 September 2011
REST and transactions
But Http is supposed to be a stateless protocol, and connections are closed on each request.
In recent years there has been a trend away from using session state as it creates server affinity and so is not scalable. One option is to use stored procedures to wrap several steps into an action that can be called using REST. Another is to offer transaction scripts, and these are available in Pyrrho v4.5 as described in this posting.
Recall that a REST URL in Pyrrho has the form
proto://host:port/database/role{/Selector|/Processing}
If no Selector or Processing components are provided, the target is the Role itself, to which a REST transaction script can be POSTed. This is envisaged for application use (not for an interactive user). Here is an example (POST to https://mybank:8133/MyBank/Teller):
(
(POST /CurrentAccount (AC:567123,AMT:655.43,REASON:’From Malcolm’))
(POST /CurrentAccount (AC:423991,AMT:-655.43,REASON:’To Fred’))
(COMMIT)
)
In this syntax embedded spaces in the url must be encoded as %20. In XML this could look like:
<?xml version=”1.0”?>
<root>
<POST Path=”/CurrentAccount” AC=”567123” AMT=”655.43”>
<REASON>From Malcolm</REASON>
</POST>
<POST Path=”/CurrentAccount” AC=”423991” AMT=”-655.43”>
<REASON>To Fred</REASON>
</POST>
<COMMIT/>
</root>
As usual with transactions, from within the transaction each step is seen to complete, but no external or persistent changes are made unless the COMMIT executes without conflict. The SQL syntax for a transaction script is thus:
Script = ‘(‘ ‘(‘ Step ‘)’ { [‘,’] ‘(‘ Step ‘)’ } ‘)’ .
Step = POST url Row_Value
| PUT url ‘(‘ Row_Value {[‘,’] Row_Value } ‘)’
| GET url
| DELETE url
| COMMIT .
Tuesday, 6 September 2011
REST and role-based CRUD operations
We will use the following simple REST client (which is not Pyrrho-specific):
This screenshot shows the database as Library, the role as Library, and the table as BOOK (the REST interface is case-sensitive, and the default case in SQL is upper case).
Let us use PUT to provide better author names. With the permissions set up in previous postings, any user granted the Library or LIBRARIAN roles can do this. The roles are different as we will see below. We can use XML or SQL format for the data we supply. First let’s use SQL. The SQL output format for http://localhost:8180/Library/Library/AUTHOR/NAME gives (('Dickens')(‘Conrad’)), so we use the same format, naturally, to update the names:
If we use XML, things look a little different. Let’s look at BOOK with XML
Here the librarian has changed the names of some columns for the LIBRARIAN role, and marked book as an entity and id and aid as attributes. We can post a new book:
Notice that we don’t need to supply all of the fields (in this case it would be incorrect to supply values for the generated Author column). Pyrrho is forgiving about whether columns are supplied as attributes or children. But only one record can be POSTed at a time.
POST does not return data.
Checking, we see the new book has gone in with a generated key value of 1 (we could have given our own value).
Recall that this table looks very different in other roles:
Finally DELETE works. Provided the current role has the right permissions, the records that would be returned by GET are instead deleted.
Role names do not need to be meaningful, and using a hard-t-guess name for a role with extra privileges can be a useful extra layer of security.
Wednesday, 31 August 2011
REST and role models
For now let’s just consider GET actions. (As we will see in the next posting, one simple way of handling moderate security for PUT, DELETE and POST is to grant Insert, Update and Delete to a role with a hard-to-guess name.)
We can use REST to explore the Web role of the database:
For the Author table, AUTHOR has been declared as an entity, and ID has been declared as an attribute, so the output has a different form:
We can select by a primary key value
We can limit the output to particular columns:
We can select rows satisfying a particular set of conditions:
We can navigate foreign keys:
We can reverse-navigate foreign keys using the OF keyword (see below)
The syntax here is
http://host:port/database/role{/Selector|/Processing}
Selector matches
[table ]Table_id
[procedure ]Procedure_id
[where ]Column_id=string
[select ]Column_id{,Column_id}
[key ]string
[of ]Table_id[(Column_id{, Column_id})]
Appending another selector is used to restrict a list of data to match a given primary key value or named column values, or to navigate to another list by following a foreign key, or supply the current result as the parameters of a named procedure. The of option is used for reverse navigation of foreign keys, or to traverse many-many relationships.
Processing matches:
distinct [Column_id{, Column_id}]
ascending Column_id{, Column_id}
descending Column_id{, Column_id}
skip Int_string
count Int_string
The relationship of this Library database to the one in the last posting is (approximately) as follows:
In role Library:
Create role “Web”
Grant select on author to “Web”
Grant select on book to “Web”
Insert into book(title,aid) values(‘Great Expectations’,1)
In role “Web”:
Alter table author entity
Alter table author alter id attribute




















