Example #1
0
    def insert(self, dbobj, dont_select=False):
        """
        @param dbobj: The dbobj to be inserted (must not be created by a
            select statement.
        @param dont_select: Do not perform a SELECT query for those columns
            whoes values are provided by the backend, either through
            AUTO_INCREMENT mechanisms or default column values.
        """
        if dbobj.__is_stored__():
            raise ObjectAlreadyInserted(repr(dbobj))
        
        sql_columns = []
        sql_values = []
        for property in dbobj.__dbproperties__():
            if property.isset(dbobj) and \
                   property.column not in sql_columns and \
                   property.sql_literal(dbobj) is not None:                
                sql_columns.append(property.column)
                sql_values.append(property.sql_literal(dbobj))

        if len(sql_columns) == 0:
            raise DBObjContainsNoData("Please set at least one of the attributes of this dbobj")

        statement = sql.insert(dbobj.__relation__, sql_columns, sql_values)
        self.execute(statement, modify=True)

        dbobj.__insert__(self)

        if not dont_select:
            self.select_after_insert(dbobj)
Example #2
0
    def insert(self, dbobj, dont_select=False):
        """
        @param dbobj: The dbobj to be inserted (must not be created by a
            select statement.
        @param dont_select: Do not perform a SELECT query for those columns
            whoes values are provided by the backend, either through
            AUTO_INCREMENT mechanisms or default column values.
        """
        if dbobj.__is_stored__():
            raise ObjectAlreadyInserted(repr(dbobj))

        sql_columns = []
        sql_values = []
        for property in dbobj.__dbproperties__():
            if property.isset(dbobj) and \
                   property.column not in sql_columns and \
                   property.sql_literal(dbobj) is not None:
                sql_columns.append(property.column)
                sql_values.append(property.sql_literal(dbobj))

        if len(sql_columns) == 0:
            raise DBObjContainsNoData(
                "Please set at least one of the attributes of this dbobj")

        statement = sql.insert(dbobj.__relation__, sql_columns, sql_values)
        self.execute(statement, modify=True)

        dbobj.__insert__(self)

        if not dont_select:
            self.select_after_insert(dbobj)
Example #3
0
        def append(self, *new_child_objects):
            """
            Appends new child objects to the parent's many2many dbproperty. 
            """
            for dbobj in new_child_objects:
                if not isinstance(dbobj, self.child_class()):
                    msg = "This relationship can only handle %s" % \
                                           repr(self.child_class())
                    raise TypeError(msg)

                if not dbobj.__is_stored__():
                    # The many2many relationship will insert fresh objects
                    # into the database.
                    self.ds().insert(dbobj)

                # insert a row into the link_relation
                command = sql.insert(self.relationship.link_relation, (
                    self.relationship.parent_link_column(self.dbobj),
                    self.relationship.child_link_column(),
                ), (
                    self.relationship.parent_own_key(self.dbobj).sql_literal(
                        self.dbobj),
                    self.relationship.child_own_key().sql_literal(dbobj),
                ))

                self.ds().execute(command)
Example #4
0
        def append(self, *new_child_objects):
            """
            Appends new child objects to the parent's many2many dbproperty. 
            """
            for dbobj in new_child_objects:
                if not isinstance(dbobj, self.child_class()):
                    msg = "This relationship can only handle %s" % repr(self.child_class())
                    raise TypeError(msg)

                if not dbobj.__is_stored__():
                    # The many2many relationship will insert fresh objects
                    # into the database.
                    self.ds().insert(dbobj)

                # insert a row into the link_relation
                command = sql.insert(
                    self.relationship.link_relation,
                    (self.relationship.parent_link_column(self.dbobj), self.relationship.child_link_column()),
                    (
                        self.relationship.parent_own_key(self.dbobj).sql_literal(self.dbobj),
                        self.relationship.child_own_key().sql_literal(dbobj),
                    ),
                )

                self.ds().execute(command)