Yarin Hello, good afternoon, I take your question to answer in general
terms as used in web2py Procedures.
1- sure that the database engine you use supports stored procedures (ex:
mysql, postgresql, Sybase, Oracle, etc).
2- must create the procedure in the database using the SQL client that
corresponds to your database engine, always remember enforce a standard
structure in its design (declare variables in / out, creating logic DML or
DDL required your business, handle errors, etc).
3 - hard test your SQL SP with the cliente dba, etc.
4 to 1 Once you have the well-oiled sp layer web2py comes.
5 - deberasa create a function in web2py. perfeccionalos then follow these
steps (the explanation is conceptual trial and error will have to make in
the implementation):
6 - in the "model" of web2py should create a new layer .py module (it must
be created after instantiate and register the DAL connection).
Deberas with the module in question make a standard function that allows
you to receive parameters, "the name of the procedure", "sql chain
execution."
ex: def exec_proc_web2py (nombre_sp, parameters)
string_sql = "CALL base." Nombre_sp + + "(" + parameters + ");"
admindb.executesql return = (string_sql)
ex: if I run the procedure from the SQL client: you would use the command
,Ex: mysql
CALL stm_desa.sp_stm_apl_dep ('A' , '16');
7- in the layer model you need to call the function used to call the
procedure and will spend the parameters that your function needs.
8- In case your sp need to do more than one instruction to insert, update or
delete, you must do the transaction group within the SP, in blocks start
and end of DML transactions. in short inside "begin transaction" and "
commit"
We spent a couple of references such as the execution of SQL as well as the
execution of the command "db.ExecuteSQL ()"
If you use mysql:
https://dev.mysql.com/doc/refman/5.7/en/commit.html
http://www.latinuxpress.com/books/drafts/web2py/caps/cap6.html
http://web2py.com/book/default/chapter/06
El sábado, 25 de agosto de 2012, 18:56:10 (UTC-3), Yarin escribió:
>
> I'm assuming there's probably no support for defining stored procedures
> using DAL functions. Instead I was going to try to create them in raw sql
> using executesql whenever migrate was turned on. Just wondering if this
> is the best technique, or someone has another idea
>
>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.