Skip to content

Commit

Permalink
executemany returns the result list now
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Bogensberger committed Aug 22, 2014
1 parent e6cd2cf commit f425763
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion CHANGES.txt
Expand Up @@ -2,7 +2,12 @@
Changes for crate
=================

- use bulk_args in executemany to increase performance
- use bulk_args in executemany to increase performance:
With crate server >= 0.42.0 executemany uses bulk_args
and returns a list of results.
With crate server < 0.42.0 executemany still issues
a request for every parameter and doesn't return
any results.

- improved docs formatting of field lists

Expand Down
8 changes: 7 additions & 1 deletion docs/client.txt
Expand Up @@ -57,12 +57,18 @@ To bulk insert data you can use the `executemany` function::
... [('Cloverleaf', '2007-03-11', 'Quasar', 7),
... ('Old Faithful', '2007-03-11', 'Quasar', 7)])

[{u'rowcount': 1}, {u'rowcount': 1}]

`executemany` returns a list of results for every parameter. Each result
contains a rowcount. If an error occures the rowcount is -2 and the result
may contain an `error_message` depending on the error.

.. note::

If you are using a crate server version older than 0.42.0 the client
will execute a single sql statement for every parameter in the parameter
sequence when you are using executemany. To avoid that overhead you can
sequence when you are using executemany. In this case, executemany doesn't
return any value. To avoid that overhead you can
use ``execute`` and make use of multiple rows in the INSERT
statement and provide a list of arguments with the length of
``number of inserted records * number of columns``::
Expand Down
4 changes: 3 additions & 1 deletion src/crate/client/cursor.py
Expand Up @@ -77,9 +77,11 @@ def executemany(self, sql, seq_of_parameters):
"rowcount": sum(row_counts) if row_counts else -1,
"duration": sum(durations) if durations else -1,
"rows": [],
"cols": self._result.get("cols", [])
"cols": self._result.get("cols", []),
"results": self._result.get("results")
}
self.rows = iter(self._result["rows"])
return self._result["results"]

def fetchone(self):
"""
Expand Down
2 changes: 2 additions & 0 deletions src/crate/client/cursor.txt
Expand Up @@ -190,6 +190,8 @@ executemany
>>> cursor = connection.cursor()

>>> cursor.executemany('', (1,2,3))
[{'rowcount': 3}, {'rowcount': 2}]

>>> cursor.rowcount
5
>>> cursor.duration
Expand Down

0 comments on commit f425763

Please sign in to comment.