Calculated table with view mode only

A place for users and developers of the Xataface to discuss and receive support.

Calculated table with view mode only

Postby Gwynnbleid1 » Sat Oct 20, 2012 1:52 am

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).
Gwynnbleid1
 
Posts: 31
Joined: Thu Sep 20, 2012 3:02 pm

Re: Calculated table with view mode only

Postby silma » Sat Oct 20, 2012 6:45 am

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
silma
 
Posts: 87
Joined: Tue Apr 28, 2009 11:47 pm

Re: Calculated table with view mode only

Postby Gwynnbleid1 » Sat Oct 20, 2012 2:29 pm

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 ?
Gwynnbleid1
 
Posts: 31
Joined: Thu Sep 20, 2012 3:02 pm

Re: Calculated table with view mode only

Postby silma » Sun Oct 21, 2012 4:48 am

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 =)
silma
 
Posts: 87
Joined: Tue Apr 28, 2009 11:47 pm

Re: Calculated table with view mode only

Postby Gwynnbleid1 » Sun Oct 21, 2012 12:52 pm

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 :)
Gwynnbleid1
 
Posts: 31
Joined: Thu Sep 20, 2012 3:02 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 20 guests

Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved