Blender and requests PostgreSql I am new to programming.
Since Blender, I communicate with the PostgeSQL database. The purpose of the code is:

1 / Browse the table "works" and find new date_works for each object.
2 / affect the material to each object based on the date.
3 / if an object is in the group 'work', we find the parent.
If date_works of the child is higher than that of the mother, we hide the child object.

This is the point 3, which does not. What do you think of my code? What is wrong?
Thank you.

#Find the most recent work in the table "works"       
    for  works ,recentW in db.prepare("SELECT mesh_ works,max(date_ works) FROM  works GROUP BY mesh_ works"):    
       year=str(recentW.year)
       mat_M= bpy.data.materials.get(year)
       mesh=bpy.data.meshes["%s"% works]
       for obj in bpy.data.objects:
        if (obj.data==mesh):
                 c=obj                      
       # materials allocation in accordance with the date found. (example: finding dates 2015 =&gt; material it affects the "2015")
       c.active_material=mat_M
       # ensure that these objects are visible
       c.hide=False          
    # hide child objects whose work dates predate those of parents
       #if it is a child, 
       if c.name in bpy.data.groups["Child"].objects:
           #find parent
           parent=c.parent
           #search in the database of the most recent date of the parent
           recentParent=db.prepare("SELECT MAX(date_ works) FROM  works WHERE id_ works='%s'"%parent)
           #if the date of the parent is more recent than that of the child while the child is masked.
           for recent in recentParent:                      
                     if(recent[0]!=None):
                       yearParent=str(recent[0].year)                              
                       if(yearParent&gt;=year):
                         c.hide=True
    return {'FINISHED'}
Syntactically something like this should work (I striped the DB code):

import bpy

mat_M= bpy.data.materials.get('2015')
year='2014'
for obj in bpy.data.objects:
    c = None
    print(obj)
    if obj.type=='MESH':
        c=obj
    if c == None:
        continue                      
    c.active_material=mat_M
    c.hide=False          
    if c.name in bpy.data.groups["Child"].objects:
        parent=c.parent
        recentParent = [[2014],[2015]]
        for recent in recentParent:                      
            if recent[0]!=None:
                yearParent=str(recent)
                if yearParent&gt;=year:
                    c.hide=True


for recent in recentParent iterates over the result of the db query, try your exact statement in a UI for your SQL server. If it doesn't return any data you need to fix that first. DB connections are better ask on stackoverflow. Note that there is a space in id_ works