But what if you pass the default return value of dict.get? Does the
function raise exceptions?
i.e.
Result.get("my_field", None)
And you could catch invalid returned object exceptions with try-except
blocks, and replacing them with a default value (i.e. None)
This is what i understood so far:
parse() DAL.BaseAdapter (wich is called by dal's instance .select()
method) receives a rows argument (suposedly a dict returned
by ._select()?) and a colnames (a list of fields retrieved from the
adapter)
in parse():
-each dictionary creates a Row instance to be passed to the Rows
object returned by the function
-the Rows object is intantiated with a python list of Row instances as
argument
This is however a very simplified and incomplete description of the
parse function. It's complete working implementation can be read here:
http://web2py.com/examples/static/epydoc/web2py.gluon.dal-pysrc.html
(From line 1391)
>From then on, you should be able to process the query output basically
On Dec 4, 3:51 am, Mark Breedveld <[email protected]> wrote:
> That was indeed a bit help full, but I think the parse() functions takes
> care of that. Do I'm not sure what that function is expecting, but more
> tomorrow. I'm from Europe, so a bit of a hour gab there.
>
> Regards Mark,
>
> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:[email protected]] Namens Alan
> Etkin
> Verzonden: zondag 4 december 2011 2:21
> Aan: web2py-users
> Onderwerp: [web2py] Re: Convertingmongodbcollection torow
>
> I see your point now, you meant a Rows instance (kind of a subset of a
> table)
> Would you post the exception (if any), when trying to read the query result?
>
> The point is that the select method has to instantiate properly a Rows
> object
>
> Have you read this web2py API
> section?http://web2py.com/examples/static/epydoc/web2py.gluon.dal.Rows-class....
>
> I think it could help. That is the object wich is to be returned by a
> correct select
>
> Note that the Rows instance is normally returned by this web2py
> statement:
> dal_instance(query_object).select(*arguments)
>
> On Dec 3, 7:36 pm, Alan Etkin <[email protected]> wrote:
>
>
>
> > When you say that you try to convert a collection to arow, isn't there
> > a conflict with database systems?
>
> > I looking for the first time themongodbdatabase design, and i assume
> > there is got to be some sort of mapping of objects:
>
> > - A DAL Table is like a Collection
> > - A DALRowis (more or less) like a Document
> > - A DAL Field is like any object stored inside the Document at the
> > root Document level
>
> > As long as there is not more depth in themongodbobject than the
> > described, the parsing by using a json like simplejson or similar
> > interface should be straightforward. I think this goes beyond my
> > database skills but i would like to see the interface implemented if
> > it is available (and shared) somewhere.
>
> > Thanks for your feedback
>
> > On Dec 3, 12:35 pm, Mark Breedveld <[email protected]> wrote:
>
> > > I'm currently modifing the DAL.py file to get DAL working
> > > withmongoDB. I got the insert part working, but the of the select
> > > method. So __select is working, but select() ain't. Because I need
> > > to convert a pymongo collection to arow. The line I point to has
> > > been written by Massimo, but isn't working. I have no idea's at the
> > > moment to do this in a general way. The returned value is a dict or
> > > a list of dict's, but of course not formatted in a DAL way.
>
> > > -----Oorspronkelijk bericht-----
> > > Van: [email protected] [mailto:[email protected]] Namens
> > > Alan Etkin
> > > Verzonden: zaterdag 3 december 2011 17:14
> > > Aan: web2py-users
> > > Onderwerp: [web2py] Re: Convertingmongodbcollection torow
>
> > > Mark, i don't understand your post. Did you modify web2py code?
> > > Could you provide a little background on the interface you are working
> on?
> > > Thank you
>
> > > On Nov 30, 10:50 am, Mark Breedveld <[email protected]> wrote:
>
> > > > I have got the select function ofmongodbadapter working, but know
> > > > I need to convert a pymongo cursor torow.
> > > > The point is the pymongo supports nested documents and that can be
> > > > a bit hard to convert for a parameter of the parse method.
>
> > > > Here is the select function a have ajusted, but this one won't
> > > > work with yours because I also altered a lot of other functions.
> > > > But this is to get the idea. The line that has to be changed is
> > > > pointed to with
> > > > <--
> > > > def select(self,query,fields,attributes):
> > > > #if not isinstance(query,Query):
> > > > # raise SyntaxError, "Not Supported"
> > > > definition = self._select(query,fields,attributes)
>
> > > > ctable = self.connection[str(definition['tablename'])]
> > > > if ((definition['sort'] == None) & (definition['skip'] ==
> > > > None)):
> > > > result = ctable.find(definition['query'])
> > > > elif((definition['sort'] != None) & (definition['skip'] ==
> > > > None)):
> > > > result =
> > > > ctable.find(definition['query']).sort(definition['sort'])
> > > > elif((definition['sort'] == None) & (definition['skip'] !=
> > > > None)):
> > > > result =
> > > > ctable.find(definition['query']).skip(definition['skip'])
> > > > elif((definition['sort'] != None) & (definition['skip'] !=
> > > > None)):
> > > > result =
> > > > ctable.find(definition['query']).sort(definition['sort']).skip(def
> > > > init
> > > > ion['skip'])
> > > > else:
> > > > raise RuntimeError, "No valid query information found"
> > > > print str(result)
> > > > #rows = [cols['value'] for cols in result] <--- This line
> > > > converts the result to be parsed
> > > > return self.parse(rows, definition['colnames'], False)
>
> > > > Anyone with advise on the matter or ideas?
>
> > > -----
> > > Geen virus gevonden in dit bericht.
> > > Gecontroleerd door AVG -www.avg.com
> > > Versie: 2012.0.1873 / Virusdatabase: 2102/4653 - datum van uitgifte:
> > > 12/02/11
>
> -----
> Geen virus gevonden in dit bericht.
> Gecontroleerd door AVG -www.avg.com
> Versie: 2012.0.1873 / Virusdatabase: 2102/4654 - datum van uitgifte:
> 12/03/11