[web2py] Re: Please explain how this query works

2013-05-21 Thread Anthony
db(some_query) creates a DAL Set object (on which you can then call methods 
such as .select(), .update(), etc.). A Set object is also callable, and if 
you call it by passing in another query, it will simply add the new query 
as an AND condition. So, that code is just equivalent to:

db(
(db.products.id == db.product_filter.product_id) 
(db.filters.id == db.product_filter.filter_id) 
(db.filters.name == hoodie)
)

or

db(db.products.id == db.product_filter.product_id)(db.filters.id == db.
product_filter.filter_id)\
(db.filters.name == hoodie)

The idea is that you can create a base Set object and then use it to create 
more specific sets by adding different conditions.

Anthony

On Tuesday, May 21, 2013 4:02:00 PM UTC-4, brac...@gmail.com wrote:

 Is there a section in the online web2py book that explains Niphlod's way 
 to building a query?

 Near the bottom of this 
 threadhttps://groups.google.com/forum/?fromgroups=#!topic/web2py/qL1DKqeEFkA
  there 
 is:

 all_in_one = db(
 (db.products.id == db.product_filter.product_id) 
 (db.filters.id == db.product_filter.filter_id) 
 )

 Then to get all corresponding rows in product_filter table,

 all_in_one_hoodies = all_in_one(db.filters.name == hoodie).select()

 I understand his cumbersome example, where you have to select a resultset 
 and then pass that to another select(). But I don't understand how I can 
 pass all_in_one() a parameter and how it knows to return all products which 
 have the hoodie filter name.




-- 

--- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Please explain how this query works

2013-05-21 Thread Anthony
Note, I'm not sure the fact that a Set is callable is documented in the 
book.

On Tuesday, May 21, 2013 4:14:48 PM UTC-4, Anthony wrote:

 db(some_query) creates a DAL Set object (on which you can then call 
 methods such as .select(), .update(), etc.). A Set object is also callable, 
 and if you call it by passing in another query, it will simply add the new 
 query as an AND condition. So, that code is just equivalent to:

 db(
 (db.products.id == db.product_filter.product_id) 
 (db.filters.id == db.product_filter.filter_id) 
 (db.filters.name == hoodie)
 )

 or

 db(db.products.id == db.product_filter.product_id)(db.filters.id == db.
 product_filter.filter_id)\
   (db.filters.name == hoodie)

 The idea is that you can create a base Set object and then use it to 
 create more specific sets by adding different conditions.

 Anthony

 On Tuesday, May 21, 2013 4:02:00 PM UTC-4, brac...@gmail.com wrote:

 Is there a section in the online web2py book that explains Niphlod's way 
 to building a query?

 Near the bottom of this 
 threadhttps://groups.google.com/forum/?fromgroups=#!topic/web2py/qL1DKqeEFkA
  there 
 is:

 all_in_one = db(
 (db.products.id == db.product_filter.product_id) 
 (db.filters.id == db.product_filter.filter_id) 
 )

 Then to get all corresponding rows in product_filter table,

 all_in_one_hoodies = all_in_one(db.filters.name == hoodie).select()

 I understand his cumbersome example, where you have to select a resultset 
 and then pass that to another select(). But I don't understand how I can 
 pass all_in_one() a parameter and how it knows to return all products which 
 have the hoodie filter name.




-- 

--- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Please explain how this query works

2013-05-21 Thread bracquet
Hm, but how does it know to return a set object from the product_filter 
table rather than the product or filter table?

And what does these two queries mean when it comes executing the queries?
(db.products.id == db.product_filter.product_id) 
(db.filters.id == db.product_filter.filter_id) 

Does it work something like this: 

Return the set object that contains the filter name hoodie
(db.filters.name == hoodie)

Then, knowing the id of the filter from the previous result set, find all 
the matching filter id in the product_filter table.
 (db.filters.id == db.product_filter.filter_id)

Now find all the products that has the same filter ids?
 (db.products.id == db.product_filter.product_id) 

But then why even do the last part? Wouldn't db.filters.id == 
db.product_filter.filter_id already give you the rows you'd want from 
product_filter table?

On Tuesday, May 21, 2013 4:19:29 PM UTC-4, Anthony wrote:

 Note, I'm not sure the fact that a Set is callable is documented in the 
 book.

 On Tuesday, May 21, 2013 4:14:48 PM UTC-4, Anthony wrote:

 db(some_query) creates a DAL Set object (on which you can then call 
 methods such as .select(), .update(), etc.). A Set object is also callable, 
 and if you call it by passing in another query, it will simply add the new 
 query as an AND condition. So, that code is just equivalent to:

 db(
 (db.products.id == db.product_filter.product_id) 
 (db.filters.id == db.product_filter.filter_id) 
 (db.filters.name == hoodie)
 )

 or

 db(db.products.id == db.product_filter.product_id)(db.filters.id == db.
 product_filter.filter_id)\
   (db.filters.name == hoodie)

 The idea is that you can create a base Set object and then use it to 
 create more specific sets by adding different conditions.

 Anthony

 On Tuesday, May 21, 2013 4:02:00 PM UTC-4, brac...@gmail.com wrote:

 Is there a section in the online web2py book that explains Niphlod's 
 way to building a query?

 Near the bottom of this 
 threadhttps://groups.google.com/forum/?fromgroups=#!topic/web2py/qL1DKqeEFkA
  there 
 is:

 all_in_one = db(
 (db.products.id == db.product_filter.product_id) 
 (db.filters.id == db.product_filter.filter_id) 
 )

 Then to get all corresponding rows in product_filter table,

 all_in_one_hoodies = all_in_one(db.filters.name == hoodie).select()

 I understand his cumbersome example, where you have to select a 
 resultset and then pass that to another select(). But I don't understand 
 how I can pass all_in_one() a parameter and how it knows to return all 
 products which have the hoodie filter name.




-- 

--- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Please explain how this query works

2013-05-21 Thread Niphlod
all those (query) just add a bit of where clause in the select that you 
pass to the db.
you can use them with db((query)  (query)  (query)) or with 
db(query)(query)(query) ... the resulting select passed to the db would be 
the same!

On Tuesday, May 21, 2013 10:43:48 PM UTC+2, brac...@gmail.com wrote:

 Hm, but how does it know to return a set object from the product_filter 
 table rather than the product or filter table?

 And what does these two queries mean when it comes executing the queries?
 (db.products.id == db.product_filter.product_id) 
 (db.filters.id == db.product_filter.filter_id) 

 Does it work something like this: 

 Return the set object that contains the filter name hoodie
 (db.filters.name == hoodie)

 Then, knowing the id of the filter from the previous result set, find all 
 the matching filter id in the product_filter table.
  (db.filters.id == db.product_filter.filter_id)

 Now find all the products that has the same filter ids?
  (db.products.id == db.product_filter.product_id) 

 But then why even do the last part? Wouldn't db.filters.id == 
 db.product_filter.filter_id already give you the rows you'd want from 
 product_filter table?

 On Tuesday, May 21, 2013 4:19:29 PM UTC-4, Anthony wrote:

 Note, I'm not sure the fact that a Set is callable is documented in the 
 book.

 On Tuesday, May 21, 2013 4:14:48 PM UTC-4, Anthony wrote:

 db(some_query) creates a DAL Set object (on which you can then call 
 methods such as .select(), .update(), etc.). A Set object is also callable, 
 and if you call it by passing in another query, it will simply add the new 
 query as an AND condition. So, that code is just equivalent to:

 db(
 (db.products.id == db.product_filter.product_id) 
 (db.filters.id == db.product_filter.filter_id) 
 (db.filters.name == hoodie)
 )

 or

 db(db.products.id == db.product_filter.product_id)(db.filters.id == db.
 product_filter.filter_id)\
   (db.filters.name == hoodie)

 The idea is that you can create a base Set object and then use it to 
 create more specific sets by adding different conditions.

 Anthony

 On Tuesday, May 21, 2013 4:02:00 PM UTC-4, brac...@gmail.com wrote:

 Is there a section in the online web2py book that explains Niphlod's 
 way to building a query?

 Near the bottom of this 
 threadhttps://groups.google.com/forum/?fromgroups=#!topic/web2py/qL1DKqeEFkA
  there 
 is:

 all_in_one = db(
 (db.products.id == db.product_filter.product_id) 
 (db.filters.id == db.product_filter.filter_id) 
 )

 Then to get all corresponding rows in product_filter table,

 all_in_one_hoodies = all_in_one(db.filters.name == hoodie).select()

 I understand his cumbersome example, where you have to select a 
 resultset and then pass that to another select(). But I don't understand 
 how I can pass all_in_one() a parameter and how it knows to return all 
 products which have the hoodie filter name.




-- 

--- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Please explain how this query works

2013-05-21 Thread Robin Manoli
it's explained here:
http://web2py.com/books/default/chapter/29/06#Many-to-many

Den tisdagen den 21:e maj 2013 kl. 22:02:00 UTC+2 skrev brac...@gmail.com:

 Is there a section in the online web2py book that explains Niphlod's way 
 to building a query?

 Near the bottom of this 
 threadhttps://groups.google.com/forum/?fromgroups=#!topic/web2py/qL1DKqeEFkA
  there 
 is:

 all_in_one = db(
 (db.products.id == db.product_filter.product_id) 
 (db.filters.id == db.product_filter.filter_id) 
 )

 Then to get all corresponding rows in product_filter table,

 all_in_one_hoodies = all_in_one(db.filters.name == hoodie).select()

 I understand his cumbersome example, where you have to select a resultset 
 and then pass that to another select(). But I don't understand how I can 
 pass all_in_one() a parameter and how it knows to return all products which 
 have the hoodie filter name.




-- 

--- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Please explain how this query works

2013-05-21 Thread Anthony


 Hm, but how does it know to return a set object from the product_filter 
 table rather than the product or filter table?


Set objects are not associated with a particular table -- they represent a 
set of records to be returned by the db, which may involve a join of 
multiple tables. Basically, the Set object specifies the WHERE clauses in a 
SQL query.
 

 And what does these two queries mean when it comes executing the queries?
 (db.products.id == db.product_filter.product_id) 
 (db.filters.id == db.product_filter.filter_id) 


In SQL, there are two ways to specify an inner join -- one is by using the 
INNER JOIN (or just JOIN) command, and the other is by adding a WHERE 
clause that equates the primary key of one table with the associated 
foreign key from the other table. The above queries are using the latter 
method (in web2py, to use the former method, you pass the join argument 
to the .select() method).
 

 Does it work something like this: 

 Return the set object that contains the filter name hoodie
 (db.filters.name == hoodie)

 Then, knowing the id of the filter from the previous result set, find all 
 the matching filter id in the product_filter table.
  (db.filters.id == db.product_filter.filter_id)

 Now find all the products that has the same filter ids?
  (db.products.id == db.product_filter.product_id) 


No, the above find products with id's that match the product_id of the 
records from db.product_filter, not that match the filter id's (there are 
no filter id's in the db.products table). As noted above, the immediately 
preceding two queries are used to join the db.product_filter table to the 
db.filters and db.products tables, respectively. This is necessary because 
this is a many-to-many relationship.

Anthony

-- 

--- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Re: please explain this

2010-12-25 Thread Branko Vukelić
Take a look at this for the explanation of _why_ you use escaping:

http://en.wikipedia.org/wiki/Cross-site_scripting

On Sat, Dec 25, 2010 at 8:02 AM, Sahil Arora sahilarora...@gmail.com wrote:
 thanks

 On Sat, Dec 25, 2010 at 12:09 PM, Thadeus Burgess thade...@thadeusb.com
 wrote:

 Escape will convert the text to html entities. For example,

  x = A 'quote' is bbold/b
  print response.write(x, escape=True)
 A 'quote' is lt;bgt;boldlt;/bgt;

 This protects your page from html injection hacks. If you need to display
 html from a variable and you know absolutely sure that it is safe, use

 {{=XML(x)}}

 Which also provides some helper methods to allow you to select safe tags
 without allowing everything.

 --
 Thadeus




 On Fri, Dec 24, 2010 at 11:39 PM, Sahil Arora sahilarora...@gmail.com
 wrote:

 I am asking what does escape=true does

 On Sat, Dec 25, 2010 at 11:02 AM, mdipierro mdipie...@cs.depaul.edu
 wrote:

 {{=x}}

 is equivalent to

 {{response.write(x,escape=True)}}

 Did I answer the question?


 On Dec 24, 10:04 pm, Sahil Arora sahilarora...@gmail.com wrote:
  what do you mean by word 'escape' when we say escape = False
 
  or
  in
  {{=x}}
  Variables injected into the HTML in this way are escaped by default.
  The
  escaping is ignored if x is an XML object, even if escape is set to
  True.
 
  --
  Sahil Arora
  B.Tech 2nd year
  Computer Science and Engineering
  IIT Delhi
  Contact No: +91 9871491046


 --
 Sahil Arora
 B.Tech 2nd year
 Computer Science and Engineering
 IIT Delhi
 Contact No: +91 9871491046




 --
 Sahil Arora
 B.Tech 2nd year
 Computer Science and Engineering
 IIT Delhi
 Contact No: +91 9871491046




-- 
Branko Vukelic

stu...@brankovukelic.com
http://www.brankovukelic.com/


[web2py] Re: please explain this

2010-12-24 Thread mdipierro
{{=x}}

is equivalent to

{{response.write(x,escape=True)}}

Did I answer the question?


On Dec 24, 10:04 pm, Sahil Arora sahilarora...@gmail.com wrote:
 what do you mean by word 'escape' when we say escape = False

 or
 in
 {{=x}}
 Variables injected into the HTML in this way are escaped by default. The
 escaping is ignored if x is an XML object, even if escape is set to True.

 --
 Sahil Arora
 B.Tech 2nd year
 Computer Science and Engineering
 IIT Delhi
 Contact No: +91 9871491046


Re: [web2py] Re: please explain this

2010-12-24 Thread Sahil Arora
I am asking what does escape=true does

On Sat, Dec 25, 2010 at 11:02 AM, mdipierro mdipie...@cs.depaul.edu wrote:

 {{=x}}

 is equivalent to

 {{response.write(x,escape=True)}}

 Did I answer the question?


 On Dec 24, 10:04 pm, Sahil Arora sahilarora...@gmail.com wrote:
  what do you mean by word 'escape' when we say escape = False
 
  or
  in
  {{=x}}
  Variables injected into the HTML in this way are escaped by default. The
  escaping is ignored if x is an XML object, even if escape is set to True.
 
  --
  Sahil Arora
  B.Tech 2nd year
  Computer Science and Engineering
  IIT Delhi
  Contact No: +91 9871491046




-- 
Sahil Arora
B.Tech 2nd year
Computer Science and Engineering
IIT Delhi
Contact No: +91 9871491046


Re: [web2py] Re: please explain this

2010-12-24 Thread Thadeus Burgess
Escape will convert the text to html entities. For example,

 x = A 'quote' is bbold/b
 print response.write(x, escape=True)
A 'quote' is lt;bgt;boldlt;/bgt;

This protects your page from html injection hacks. If you need to display
html from a variable and you know absolutely sure that it is safe, use

{{=XML(x)}}

Which also provides some helper methods to allow you to select safe tags
without allowing everything.

--
Thadeus




On Fri, Dec 24, 2010 at 11:39 PM, Sahil Arora sahilarora...@gmail.comwrote:

 I am asking what does escape=true does


 On Sat, Dec 25, 2010 at 11:02 AM, mdipierro mdipie...@cs.depaul.eduwrote:

 {{=x}}

 is equivalent to

 {{response.write(x,escape=True)}}

 Did I answer the question?


 On Dec 24, 10:04 pm, Sahil Arora sahilarora...@gmail.com wrote:
  what do you mean by word 'escape' when we say escape = False
 
  or
  in
  {{=x}}
  Variables injected into the HTML in this way are escaped by default. The
  escaping is ignored if x is an XML object, even if escape is set to
 True.
 
  --
  Sahil Arora
  B.Tech 2nd year
  Computer Science and Engineering
  IIT Delhi
  Contact No: +91 9871491046




 --
 Sahil Arora
 B.Tech 2nd year
 Computer Science and Engineering
 IIT Delhi
 Contact No: +91 9871491046



Re: [web2py] Re: please explain this

2010-12-24 Thread Sahil Arora
thanks

On Sat, Dec 25, 2010 at 12:09 PM, Thadeus Burgess thade...@thadeusb.comwrote:

 Escape will convert the text to html entities. For example,

  x = A 'quote' is bbold/b
  print response.write(x, escape=True)
 A 'quote' is lt;bgt;boldlt;/bgt;

 This protects your page from html injection hacks. If you need to display
 html from a variable and you know absolutely sure that it is safe, use

 {{=XML(x)}}

 Which also provides some helper methods to allow you to select safe tags
 without allowing everything.

 --
 Thadeus





 On Fri, Dec 24, 2010 at 11:39 PM, Sahil Arora sahilarora...@gmail.comwrote:

 I am asking what does escape=true does


 On Sat, Dec 25, 2010 at 11:02 AM, mdipierro mdipie...@cs.depaul.eduwrote:

 {{=x}}

 is equivalent to

 {{response.write(x,escape=True)}}

 Did I answer the question?


 On Dec 24, 10:04 pm, Sahil Arora sahilarora...@gmail.com wrote:
  what do you mean by word 'escape' when we say escape = False
 
  or
  in
  {{=x}}
  Variables injected into the HTML in this way are escaped by default.
 The
  escaping is ignored if x is an XML object, even if escape is set to
 True.
 
  --
  Sahil Arora
  B.Tech 2nd year
  Computer Science and Engineering
  IIT Delhi
  Contact No: +91 9871491046




 --
 Sahil Arora
 B.Tech 2nd year
 Computer Science and Engineering
 IIT Delhi
 Contact No: +91 9871491046





-- 
Sahil Arora
B.Tech 2nd year
Computer Science and Engineering
IIT Delhi
Contact No: +91 9871491046


[web2py] Re: please explain this twitter post

2010-07-21 Thread mdipierro
Oops. It seems the link got truncated
http://www.computer.org/portal/web/csdl/doi/10.1109/MCSE.2010.97