Page 1 of 1

Have a trigger to Auto Create a Database Table

Posted: 2018-11-21 21:30
by urichard
Hi Please help

I know it might not be suggested to have a separate table for each client that uses my database but i have my reasons why i want to create each of them their own database, i just don't want to create it after every time a new member signs up but instead hoped that after i generated my application after i have already designed all the tables and fields to have a trigger in the application that whenever a new client subscribes or registers with my application that there should automatically be a new database table created for that member to have all their records separate from other member's records, hopefully some code in the hooks folder i guess to auto create a additional new database table with fields pre-designed

Please help
Kind Regards
Richard

Re: Have a trigger to Auto Create a Database Table

Posted: 2018-11-22 06:33
by pbottcher
Hi,

just to understand. If you create a table for each new user (programatically), how would you access these tables through your application.
AppGini would not know about those tables.

As a suggestion: you could check if the table already exists in the database for the currently logged in user, and if not, create it.

Re: Have a trigger to Auto Create a Database Table

Posted: 2018-11-22 09:02
by urichard
Hi pbottcher

Thanks again for the quick response.

Wouldn't appgini know in a way of setting a if statement in some php code like for example as you said above.. to programatically create the new table once a user has registered and then when that user wants to access their own records table with zero records in or with records generated or "viewed" as with your previous post answer(which doesn't exist yet) to then auto create the table and tell appgine how to access this table for that user?

If this is possible? And what code would i need?

Re: Have a trigger to Auto Create a Database Table

Posted: 2018-11-22 10:43
by pbottcher
Hi,

I think this is not possible with the nature of AppGini. AppGini uses either an exisiting database and you specify through the GUI how the behaviour for the fields should be (e.g. lookup-field, or download, etc). Or you create your tables and fields through AppGini and once done you will create your application (app). This will generate the code that will handle those tables/fields.

If you add additional tables/fields now through the database directly (or even programaticaly through code in you app) AppGini would not know about those tables/fields and hence you would not have a web page to access your newly created tables/fields.

Re: Have a trigger to Auto Create a Database Table

Posted: 2018-11-28 11:11
by a.gneady
Hmm ... I guess it could be done if some naming rules are followed. I didn't analyze it in full detail but I can imagine it might work as follows: let's say a new member signs up. In the member_activity hook, you create a new table named for example "profile_{$username}" (so that the username is part of the table.

Before that, you should have defined a "profile" table in AppGini so that AppGini creates the interface files for it (profile_view.php, ... etc). And profile_username table that you create in the member_activity hook should follow the same schema ... Next, in the hooks/profile.php file, set the tablename in the profile_init hook to 'profile_{$userame}' .. you'd also need to set some other properties of the $options object in that init hook like $options->QueryFieldsTV, $options->QueryFieldsCSV, ... etc.

The above would cause AppGini to show data stored in the user-specific table rather than the generic profile table when the user visits profile_view.php ... Again, I didn't analyze this in detail or test it, but you could give it a try.

Re: Have a trigger to Auto Create a Database Table

Posted: 2018-11-28 12:00
by jsetzer
Next, in the hooks/profile.php file, set the tablename in the profile_init hook to 'profile_{$userame}' .. you'd also need to set some other properties of the $options object in that init hook like $options->QueryFieldsTV, $options->QueryFieldsCSV, ... etc.
Nice and interesting idea, @Ahmad !
Jan

Re: Have a trigger to Auto Create a Database Table

Posted: 2018-12-11 23:17
by urichard
Awesome!!!

I will give it a try and let you know how it works thanks a.gneady

Regards
Richard

Re: Have a trigger to Auto Create a Database Table

Posted: 2019-06-09 00:09
by bruceholt
Has anyone managed to work out how to do this as I, and probably many others would like to do it. The problem with only one big table I think, is that if there is an issue with the database, you could potentially loose everything.