MCPcopy Index your code
hub / github.com/apache/cassandra-python-driver / UpdateStatement

Class UpdateStatement

cassandra/cqlengine/statements.py:765–837  ·  view source on GitHub ↗

an cql update select statement

Source from the content-addressed store, hash-verified

763
764
765class UpdateStatement(AssignmentStatement):
766 """ an cql update select statement """
767
768 def __init__(self,
769 table,
770 assignments=None,
771 where=None,
772 ttl=None,
773 timestamp=None,
774 conditionals=None,
775 if_exists=False):
776 super(UpdateStatement, self). __init__(table,
777 assignments=assignments,
778 where=where,
779 ttl=ttl,
780 timestamp=timestamp,
781 conditionals=conditionals)
782
783 self.if_exists = if_exists
784
785 def __unicode__(self):
786 qs = ['UPDATE', self.table]
787
788 using_options = []
789
790 if self.ttl:
791 using_options += ["TTL {0}".format(self.ttl)]
792
793 if self.timestamp:
794 using_options += ["TIMESTAMP {0}".format(self.timestamp_normalized)]
795
796 if using_options:
797 qs += ["USING {0}".format(" AND ".join(using_options))]
798
799 qs += ['SET']
800 qs += [', '.join([str(c) for c in self.assignments])]
801
802 if self.where_clauses:
803 qs += [self._where]
804
805 if len(self.conditionals) > 0:
806 qs += [self._get_conditionals()]
807
808 if self.if_exists:
809 qs += ["IF EXISTS"]
810
811 return ' '.join(qs)
812
813 def get_context(self):
814 ctx = super(UpdateStatement, self).get_context()
815 for clause in self.conditionals:
816 clause.update_context(ctx)
817 return ctx
818
819 def update_context_id(self, i):
820 super(UpdateStatement, self).update_context_id(i)
821 for conditional in self.conditionals:
822 conditional.set_context_id(self.context_counter)

Calls

no outgoing calls