示例#1
0
  def update(self):
    """
      Verify the record and if OK, update it in the database
    """

    if self.__verify():
      self.sql.update(table=self.table, queryRec=self)
    else:
      raise dbError("Can't update record in table %s: errors: %s." 
                      % (self.app.getTableLable(self.table), unicode(self.errFields))
                   )
示例#2
0
 def insert(self, checkIntegrity=TRUE):
   """
     Add the record to the database
   """
   if checkIntegrity:
     if  self.__verify() :
       return self.sql.insert(self.table, self)
     else:
       raise dbError("Error inserting into " + self.app.getTableLable(self.table)
                     + "\n" + string.join(self.errFields,"\n"))
   else:
     return self.sql.insert(self.table, self)
示例#3
0
 def delete(self, delChildren=FALSE):
   """
     Delete the current record from the database.
     
     If delChildren , records in all child tables
     will be deleted too, else, if there are child records,
     the record won't be deleted.
   """
   if delChildren:
     for childtable in self.tableDef.childtables.keys():
       self.deleteChildren(childtable)
   if self.__deleteOK():
     self.sql.delete(self.table, self)
   else:
     raise dbError("Can't delete %s from %s: child records found." %
                   (self.getPrimaryKey(), self.app.getTableLable(self.table)))
示例#4
0
  def __checkLength(self):
    """
      Check if there are fields with values that are
      too long.
    """
    for (fieldname, fieldDef) in self.tableDef.fields.items():
      if fieldDef.owner:

        val = getattr(self, fieldname)
        if val != None:
          if fieldDef.datatype==VARCHAR:
            try:
              val = unicode(val)
            except:
              continue
            if len(val) > fieldDef.length:
              self.errFields.append(dbError( "Value [%s]for field %s too long, max %s." 
                                              % (val, fieldname, fieldDef.length)
                                            )
                                   )
示例#5
0
 def createChild(self, childtable, relation):
   """
   Complicated...
   
   master table a (pkA=1, fld='yyy' ....)
   detail table b (pkB= , fk=, fldA=, ...)
   
   relation: b_a (keys=[dbPair(local=pkB, foreign=pkA)]
                 ,descriptors=[dbPair(local='fldA', foreign=fld)]
                 ,rtable=a 
                 ,ralias... 
                 ) 
                 
                 We try to construct a record of table b, knowing only the tablename
                 and the right relation """
   
   masterkey=self.getPrimaryKey()
   if masterkey==None:
     raise dbError("Error: No primary key yet. Can't create child record.")
   rec=self.app.createObject(childtable, fields={relation.keys.local: masterkey})
   return rec