Pages

Pages

How to use views

MySQL 5 supports Views. This how-to describes how to use one of these Views in Dataface

You may have tried to use a view in Xataface by simply treating the view as if it was a table. You probably would have found that it doesn't quite work. Perhaps you only see the first row of the view in the list tab - or perhaps it didn't work at all. This is because Xataface depends heavily on primary keys to be able to identify records of a table uniquely, and MySQL doesn't provide information about which columns of a view are part of the primary key.

Luckily, you can add this information inside your fields.ini file. Suppose we have tables defined as follows:

Profiles (ProfileID, FirstName, LastName, Income, Expenses)

And we define a view as follows:

MyProfiles ( select *, Income-Expenses as Profit from Profiles )

Hence the view contains all of the same information as the table, except that it adds a calculated field 'Profit'.

In order to use the MyProfiles view in your Xataface application you will need to tell Xataface which columns are part of the Primary key. Do this by creating a fields.ini file for the MyProfiles view as follows:

tables/MyProfiles/fields.ini:

[ProfileID]
Key=PRI

Note that this is case sensitive!!

Now you can treat the MyProfiles view as if it was a table.

Powered by Xataface
(c) 2005-2025 All rights reserved