Replacing CrUD statements with sprocs

Posts   
 
    
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 05-Dec-2006 00:31:07   

Heya,

Warning: I don't want discuss whether sprocs are good or not :-)

So, is it possible to use sprocs for CUD (not sure about R). I think to pass all required fields + some additional fields (like hashed password). The goal is to have logging and password checks at database level.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 05-Dec-2006 02:47:21   

I'm sure it's possible. In fact I believe the first version of LLBLGen (before Pro) did this.

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 05-Dec-2006 08:58:07   

Any hints on how to do it? Although I might use brute force simple_smile I prefer an elegant solution.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 05-Dec-2006 10:42:12   

Using procs for CUD operations is fragile. It comes down to the fact that you're not mapping entities onto tables/views but entities onto proc signatures.

The read operations are actually quite easy: use projections simple_smile

You've to save the entities manually through the procs, passing field values to parameters, there's no facility built in for this. You could try to do this transparently: in overrides of CreateInsert/Update/Delete query methods of adapter.

There, you'll use the target table / view as key in a list with procs you've made, so you can then create an ActionQuery object with the proc call and all parameters set. Then you return that one and everything goes as planned.

Be aware, it's fragile: there's no support for when your entity changes or your proc changes, so it then could break at runtime. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 05-Dec-2006 12:02:54   

Hi Frans,

Ok, I think I have enough info. About fragility: actually it is not that fragile if you create sprocs using template based code generator and include the sprocs generation in llblgen generator.

Of course, you are right, it would be extremly fragile if I do any code manually.

Thanks,