Merge branch '1.x'

Conflicts:
	CHANGELOG.rst
	cassandra/cluster.py
	cassandra/query.py
	tests/integration/standard/test_query.py
This commit is contained in:
Tyler Hobbs
2014-05-09 17:17:41 -05:00
4 changed files with 25 additions and 11 deletions

View File

@@ -5,6 +5,10 @@ In Progress
Merged From 1.x
---------------
Features
--------
* Add Session.default_consistency_level (PYTHON-14)
Bug Fixes
^^^^^^^^^
* Don't strip trailing underscores from column names when using the

View File

@@ -968,6 +968,15 @@ class Session(object):
.. versionadded:: 2.0.0b1
"""
default_consistency_level = ConsistencyLevel.ONE
"""
The default :class:`~ConsistencyLevel` for operations executed through
this session. This default may be overridden by setting the
:attr:`~.Statement.consistency_level` on individual statements.
.. versionadded:: 1.2.0
"""
max_trace_wait = 2.0
"""
The maximum amount of time (in seconds) the driver will wait for trace
@@ -1114,6 +1123,7 @@ class Session(object):
elif isinstance(query, PreparedStatement):
query = query.bind(parameters)
cl = query.consistency_level if query.consistency_level is not None else self.default_consistency_level
fetch_size = query.fetch_size
if not fetch_size and self._protocol_version >= 2:
fetch_size = self.default_fetch_size
@@ -1123,11 +1133,11 @@ class Session(object):
if parameters:
query_string = bind_params(query.query_string, parameters)
message = QueryMessage(
query_string, query.consistency_level, query.serial_consistency_level,
query_string, cl, query.serial_consistency_level,
fetch_size=fetch_size)
elif isinstance(query, BoundStatement):
message = ExecuteMessage(
query.prepared_statement.query_id, query.values, query.consistency_level,
query.prepared_statement.query_id, query.values, cl,
query.serial_consistency_level, fetch_size=fetch_size)
prepared_statement = query.prepared_statement
elif isinstance(query, BatchStatement):
@@ -1137,8 +1147,7 @@ class Session(object):
"2 or higher (supported in Cassandra 2.0 and higher). Consider "
"setting Cluster.protocol_version to 2 to support this operation.")
message = BatchMessage(
query.batch_type, query._statements_and_parameters,
query.consistency_level)
query.batch_type, query._statements_and_parameters, cl)
if trace:
message.tracing = True

View File

@@ -142,10 +142,11 @@ class Statement(object):
this will be set to a :class:`.QueryTrace` instance.
"""
consistency_level = ConsistencyLevel.ONE
consistency_level = None
"""
The :class:`.ConsistencyLevel` to be used for this operation. Defaults
to :attr:`.ConsistencyLevel.ONE`.
to :const:`None`, which means that the default consistency level for
the Session this is executed in will be used.
"""
fetch_size = None
@@ -271,7 +272,7 @@ class SimpleStatement(Statement):
return self._query_string
def __str__(self):
consistency = ConsistencyLevel.value_to_name[self.consistency_level]
consistency = ConsistencyLevel.value_to_name.get(self.consistency_level, 'Not Set')
return (u'<SimpleStatement query="%s", consistency=%s>' %
(self.query_string, consistency))
__repr__ = __str__
@@ -294,12 +295,11 @@ class PreparedStatement(object):
routing_key_indexes = None
consistency_level = ConsistencyLevel.ONE
consistency_level = None
serial_consistency_level = None
def __init__(self, column_metadata, query_id, routing_key_indexes, query, keyspace,
consistency_level=ConsistencyLevel.ONE, serial_consistency_level=None,
fetch_size=None):
consistency_level=None, serial_consistency_level=None, fetch_size=None):
self.column_metadata = column_metadata
self.query_id = query_id
self.routing_key_indexes = routing_key_indexes

View File

@@ -191,7 +191,7 @@ class PrintStatementTests(unittest.TestCase):
Highlight the format of printing SimpleStatements
"""
ss = SimpleStatement('SELECT * FROM test3rf.test')
ss = SimpleStatement('SELECT * FROM test3rf.test', consistency_level=ConsistencyLevel.ONE)
self.assertEqual(str(ss),
'<SimpleStatement query="SELECT * FROM test3rf.test", consistency=ONE>')
@@ -204,6 +204,7 @@ class PrintStatementTests(unittest.TestCase):
session = cluster.connect()
prepared = session.prepare('INSERT INTO test3rf.test (k, v) VALUES (?, ?)')
prepared.consistency_level = ConsistencyLevel.ONE
self.assertEqual(str(prepared),
'<PreparedStatement query="INSERT INTO test3rf.test (k, v) VALUES (?, ?)", consistency=ONE>')