[web2py] Re: Select rows
On Tuesday, 23 December 2014 17:24:12 UTC+11, Dave S wrote: On Wednesday, December 17, 2014 12:17:53 PM UTC-8, Oliver wrote: I'm getting None printed in the webpage. I'm trying to print all first_name in the users table database. I'm trying to follow the select section in http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Query--Set--Rows I'm using MySQL for database and have few test records inserted in the users table. Please let me know what am I missing in the controller. I appreciate your help. Thanks Just to pick up on what Dave said ... where are you looking to see the output from 'print'? in web2py controllers usually return variables which are packed into an HTML page via a view (in development mode, running on a local server such as the one built in to web2py, default views work fine). Because you are not returning any value, the view shows None. Carefully re-read the introductory parts of the book if this doesn't make sense. You may notice that you can do return locals() at the end of your controller, which with a default developer view will show all your local variables. you could then do rows = db.select() return locals() The rows will then show up in your view. You can use print. It will write output to the python console. Where you see this depends on what your development environment is. *My Model: * db.define_table('users', Field('first_name', 'text'), Field('last_name', 'text')) *My Controller:* def printall(): for row in db(db.users.id 0).select(db.users.ALL): print row.first_name or def printall(): for row in db().select(db.users.ALL): print row.first_name You are trying to print to the console for development purposes? If you are showing a None as your result, then it appears your query isn't selecting any rows. If you use the command line interface to your DB (sqlite3?) can you form a SQL SELECT command that retrieves the records you want? If so, can you paste that command here? /dps -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Select rows
I used this to get print def printme(): response.view='list.html' users = db(db.users).select(db.users.first_name,db.users.last_name) return dict(users=users) It's working for me now. thanks On Tuesday, December 23, 2014 1:24:12 AM UTC-5, Dave S wrote: On Wednesday, December 17, 2014 12:17:53 PM UTC-8, Oliver wrote: I'm getting None printed in the webpage. I'm trying to print all first_name in the users table database. I'm trying to follow the select section in http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Query--Set--Rows I'm using MySQL for database and have few test records inserted in the users table. Please let me know what am I missing in the controller. I appreciate your help. Thanks *My Model: * db.define_table('users', Field('first_name', 'text'), Field('last_name', 'text')) *My Controller:* def printall(): for row in db(db.users.id 0).select(db.users.ALL): print row.first_name or def printall(): for row in db().select(db.users.ALL): print row.first_name You are trying to print to the console for development purposes? If you are showing a None as your result, then it appears your query isn't selecting any rows. If you use the command line interface to your DB (sqlite3?) can you form a SQL SELECT command that retrieves the records you want? If so, can you paste that command here? /dps -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Select rows
On Wednesday, December 17, 2014 12:17:53 PM UTC-8, Oliver wrote: I'm getting None printed in the webpage. I'm trying to print all first_name in the users table database. I'm trying to follow the select section in http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Query--Set--Rows I'm using MySQL for database and have few test records inserted in the users table. Please let me know what am I missing in the controller. I appreciate your help. Thanks *My Model: * db.define_table('users', Field('first_name', 'text'), Field('last_name', 'text')) *My Controller:* def printall(): for row in db(db.users.id 0).select(db.users.ALL): print row.first_name or def printall(): for row in db().select(db.users.ALL): print row.first_name You are trying to print to the console for development purposes? If you are showing a None as your result, then it appears your query isn't selecting any rows. If you use the command line interface to your DB (sqlite3?) can you form a SQL SELECT command that retrieves the records you want? If so, can you paste that command here? /dps -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: select rows having more than one item in list:string field
list:string field values are stored as simple strings with the items delimited by | characters (the values are converted to/from lists during the select/insert process on the web2py side). So, a value with one tag would like like |tag|, and a value with more than one tag would therefore have at least one additional | character in between the opening and closing |, which leads to the following query: db(db.sample_table.tags.like('|%|%|')).select() Note, that will also include records with a single tag if that single tag happens to include a | character within it (which presumably would be quite rare, if not prohibited). Anthony On Monday, February 24, 2014 1:44:39 PM UTC-5, Kök Eksi Bir wrote: How do I write a query that selects rows having more than one item in list:string field? Assume I have a table definition db.define_table('sample_table', Field('tags', 'list:string'), ) How can I select rows that have more than one tag? Regards, -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.