Page 1 of 1

Calculated table with view mode only

PostPosted: Sat Oct 20, 2012 1:52 am
by Gwynnbleid1
Hi. I have a situation like this:
Code: Select all
conf.ini:
[_tables]
tableA = "Table A"
tableB = "Data calculated only from tableA, which shoud only present data"


tableB doesn't exist, but for it I provided sql directive in fields file which gets data calculated from tableA. I'm getting an error that tableB doesn't exist. Is it possible to achieve this ? I can't use tableA twice because I can't use two different sql directives for it (one which gets all data and one which gets calculated data).

Re: Calculated table with view mode only

PostPosted: Sat Oct 20, 2012 6:45 am
by silma
If you calculations are not too complicated, you could create a view from your tableA on the database, and use it as a tableB. You 'll have to set the primary key for it in the fields.ini, and make it readable only.
It may be the easier way.


Also, if you don't need to store your calculated field, you could make an action on your tableA, that show your calculated values

Re: Calculated table with view mode only

PostPosted: Sat Oct 20, 2012 2:29 pm
by Gwynnbleid1
silma wrote:If you calculations are not too complicated, you could create a view from your tableA on the database, and use it as a tableB. You 'll have to set the primary key for it in the fields.ini, and make it readable only.
It may be the easier way.


Also, if you don't need to store your calculated field, you could make an action on your tableA, that show your calculated values

Can you point me to an example, or write one about how to make a view from table ?

Re: Calculated table with view mode only

PostPosted: Sun Oct 21, 2012 4:48 am
by silma
Here the doc : http://dev.mysql.com/doc/refman/5.0/en/create-view.html

In your case i guess it would be something like :

Code: Select all
CREATE VIEW tableB AS SELECT fieldA4*fieldA2 AS fieldB1, fieldA3*100 AS FielsB2 FROM tableA;


Your view will then stand as a table, and you can use it in xataface like another table, except thant you have to declare the primary key in the tables/tablesB/fields .ini
Code: Select all
[NameOfTheFieldInTableB]
    Key=PRI

Choose a field that wil be unique.

Hope it helps =)

Re: Calculated table with view mode only

PostPosted: Sun Oct 21, 2012 12:52 pm
by Gwynnbleid1
silma wrote:Here the doc : http://dev.mysql.com/doc/refman/5.0/en/create-view.html

In your case i guess it would be something like :

Code: Select all
CREATE VIEW tableB AS SELECT fieldA4*fieldA2 AS fieldB1, fieldA3*100 AS FielsB2 FROM tableA;


Your view will then stand as a table, and you can use it in xataface like another table, except thant you have to declare the primary key in the tables/tablesB/fields .ini
Code: Select all
[NameOfTheFieldInTableB]
    Key=PRI

Choose a field that wil be unique.

Hope it helps =)

It helped a lot. I didn't know that something like View existed in MySql. With some struggle with permissions now I have beautiful view table ready :) Thanks a lot :)