Please be sure to read the DAL section of the online web2py book it will
explain a lot of this.
When you use executesql you can choose how to see the results the as_dict
means you can address fields/columns as dict keys or you can also use the
fields & colnames options to get objects just like "normal" DAL results.
Example of as_dict
#IN CONTROLLER
def show_cart():
user_id = request.args[0]
results = db.executesql('Select item, quantity, cost FROM shoping_cart
WHERE user_id = ?', [user_id], as_dict=True)
#now loop through the results, it's just a list of dicts.
for row in results:
On Tuesday, March 25, 2014 3:55:23 PM UTC-5, learning wrote:
>
> Thanks. But if I do that doesn't that mean I can't use the results as
> "objects"? Isn't that the reason for the DAL and ORM (does it have an
> ORM)? How do I handle the values? I'd also have to insert data.
>
> For a select, you have, from the docs, as_dict=True. I'm new to Python.
> Can you show me how to iterate through that? I have:
>
> for key, value in db.iteritems():
> print key, value
>
> What do I do about Insert and Updates? How do I send a value to the DAL
> for raw SQL queries?
>
> I found this from the documentation you sent me to,
>
> db.person.insert(name="Alex")
>
> But that's not "raw" SQL.
>
> I don't mind using SQL via a DAL, I'm just not sure how to go through the
> results in a "python" way.
>
> Then I found this, web2py can connect to legacy databases under some
> conditions.
>
> Don't know if this matters, if I can do transactions, many things that you
> would do with the DAL. For example, how could I do a transaction with raw
> SQL? Everything is based on the DAL creation of the database objects.
>
> On Thursday, March 20, 2014 12:37:24 PM UTC-4, learning wrote:
>>
>> I know what Python and web framework are, but need help understanding
>> something about web2py. I have an old application that uses vbscript/asp.
>> It hits multiple databases and brings it back to the user for a seamless
>> experience. In other words, they don't have to go to ten pages to get
>> information.
>>
>> All these databases are different engines. One might be Oracle, another
>> MySQL, SQL Server, etc.
>>
>> How do I do that with Web2py? Do I have to get Web2py to generate models
>> and am I forced to use an ORM? Is web2py suitable for a project like this?
>> Can I use straight up SQL?
>>
>> These aggregate web pages are separate from the actual main page with the
>> menu, etc. The "portal" page. Same website.
>>
>> Thanks.
>>
>
--
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.