mirror of
https://github.com/mariadb-corporation/mariadb-connector-python.git
synced 2025-08-14 08:56:00 +00:00

Due to several incompatibilites (but also MDEV-23768, where errors can't be triggered in unbuffered) we decided to switch the default mode for cursor class for buffered from False to True.
410 lines
28 KiB
HTML
410 lines
28 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
<title>The cursor class — MariaDB Connector/Python 1.1.0-alpha documentation</title>
|
||
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
|
||
<link rel="stylesheet" type="text/css" href="_static/classic.css" />
|
||
|
||
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
|
||
<script src="_static/jquery.js"></script>
|
||
<script src="_static/underscore.js"></script>
|
||
<script src="_static/doctools.js"></script>
|
||
|
||
<link rel="index" title="Index" href="genindex.html" />
|
||
<link rel="search" title="Search" href="search.html" />
|
||
<link rel="next" title="The ConnectionPool class" href="pool.html" />
|
||
<link rel="prev" title="The connection class" href="connection.html" />
|
||
</head><body>
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="genindex.html" title="General Index"
|
||
accesskey="I">index</a></li>
|
||
<li class="right" >
|
||
<a href="py-modindex.html" title="Python Module Index"
|
||
>modules</a> |</li>
|
||
<li class="right" >
|
||
<a href="pool.html" title="The ConnectionPool class"
|
||
accesskey="N">next</a> |</li>
|
||
<li class="right" >
|
||
<a href="connection.html" title="The connection class"
|
||
accesskey="P">previous</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="index.html">MariaDB Connector/Python 1.1.0-alpha documentation</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">The cursor class</a></li>
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<div class="section" id="the-cursor-class">
|
||
<h1>The cursor class<a class="headerlink" href="#the-cursor-class" title="Permalink to this headline">¶</a></h1>
|
||
<dl class="py class">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor">
|
||
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">mariadb.cursors.</span></span><span class="sig-name descname"><span class="pre">Cursor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">connection</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#mariadb.cursors.Cursor" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>MariaDB Connector/Python Cursor Object</p>
|
||
</dd></dl>
|
||
|
||
<div class="section" id="cursor-methods">
|
||
<h2>Cursor methods<a class="headerlink" href="#cursor-methods" title="Permalink to this headline">¶</a></h2>
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.callproc">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">callproc</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sp</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">()</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#mariadb.cursors.Cursor.callproc" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Executes a stored procedure sp. The data sequence must contain an entry for
|
||
each parameter the procedure expects.</p>
|
||
<p>Input/Output or Output parameters have to be retrieved by .fetch methods,
|
||
the .sp_outparams attribute indicates if the result set contains output”
|
||
parameters</p>
|
||
<p>Example:</p>
|
||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="go">>>>cursor.execute("CREATE PROCEDURE p1(IN i1 VAR CHAR(20), OUT o2 VARCHAR(40))"</span>
|
||
<span class="go"> "BEGIN"</span>
|
||
<span class="go"> " SELECT 'hello'"</span>
|
||
<span class="go"> " o2:= 'test'"</span>
|
||
<span class="go"> "END")</span>
|
||
<span class="go">>>>cursor.callproc('p1', ('foo', 0))</span>
|
||
<span class="gp">>>> </span><span class="n">cursor</span><span class="o">.</span><span class="n">sp_outparams</span>
|
||
<span class="go">False</span>
|
||
<span class="gp">>>> </span><span class="n">cursor</span><span class="o">.</span><span class="n">fetchone</span><span class="p">()</span>
|
||
<span class="go">('hello',)</span>
|
||
<span class="gp">>>> </span><span class="n">cursor</span><span class="o">.</span><span class="n">nextset</span><span class="p">()</span>
|
||
<span class="go">True</span>
|
||
<span class="gp">>>> </span><span class="n">cursor</span><span class="o">.</span><span class="n">sp_outparams</span>
|
||
<span class="go">True</span>
|
||
<span class="gp">>>> </span><span class="n">cursor</span><span class="o">.</span><span class="n">fetchone</span><span class="p">()</span>
|
||
<span class="go">('test',)</span>
|
||
</pre></div>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.execute">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">execute</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">statement</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">()</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">buffered</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#mariadb.cursors.Cursor.execute" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Prepare and execute a SQL statement.</p>
|
||
<p>Parameters may be provided as sequence or mapping and will be bound
|
||
to variables in the operation. Variables are specified as question
|
||
marks (paramstyle=’qmark’), however for compatibility reasons MariaDB
|
||
Connector/Python also supports the ‘format’ and ‘pyformat’ paramstyles
|
||
with the restriction, that different paramstyles can’t be mixed within
|
||
a statement.</p>
|
||
<p>A reference to the operation will be retained by the cursor.
|
||
If the cursor was created with attribute prepared=True the statement
|
||
string for following execute operations will be ignored.
|
||
This is most effective for algorithms where the same operation is used,
|
||
but different parameters are bound to it (many times).</p>
|
||
<p>By default execute() method generates an unbuffered result set for
|
||
statements which return data, setting optional parameter buffered to
|
||
True will generate buffered result sets.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.executemany">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">executemany</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">statement</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">parameters</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#mariadb.cursors.Cursor.executemany" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Prepare a database operation (INSERT,UPDATE,REPLACE or DELETE statement) and
|
||
execute it against all parameter found in sequence.</p>
|
||
<p>Exactly behaves like .execute() but accepts a list of tuples, where each
|
||
tuple represents data of a row within a table.
|
||
.executemany() only supports DML (insert, update, delete) statements.</p>
|
||
<p>Example:</p>
|
||
<p>The following example will insert 3 rows:</p>
|
||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">data</span><span class="o">=</span> <span class="p">[</span>
|
||
<span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="s1">'Michael'</span><span class="p">,</span> <span class="s1">'Widenius'</span><span class="p">)</span>
|
||
<span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="s1">'Diego'</span><span class="p">,</span> <span class="s1">'Dupin'</span><span class="p">)</span>
|
||
<span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="s1">'Lawrin'</span><span class="p">,</span> <span class="s1">'Novitsky'</span><span class="p">)</span>
|
||
<span class="p">]</span>
|
||
<span class="n">cursor</span><span class="o">.</span><span class="n">executemany</span><span class="p">(</span><span class="s2">"INSERT INTO colleagues VALUES (?, ?, ?)"</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>To insert special values like NULL or a column default, you need to specify indicators:</p>
|
||
<ul class="simple">
|
||
<li><p>INDICATOR.NULL is used for NULL values</p></li>
|
||
<li><p>INDICATOR.IGNORE is used to skip update of a column.</p></li>
|
||
<li><p>INDICATOR.DEFAULT is used for a default value (insert/update)</p></li>
|
||
<li><p>INDICATOR.ROW is used to skip update/insert of the entire row.</p></li>
|
||
</ul>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<ul class="simple">
|
||
<li><p>All values for a column must have the same data type.</p></li>
|
||
<li><p>Indicators can only be used when connecting to a MariaDB Server 10.2 or newer. MySQL servers don’t support this feature.</p></li>
|
||
</ul>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.fetchall">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">fetchall</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mariadb.cursors.Cursor.fetchall" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Fetch all remaining rows of a query result, returning them as a
|
||
sequence of sequences (e.g. a list of tuples).</p>
|
||
<p>An exception will be raised if the previous call to execute() didn’t
|
||
produce a result set or execute() wasn’t called before.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.fetchmany">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">fetchmany</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">size</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#mariadb.cursors.Cursor.fetchmany" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Fetch the next set of rows of a query result, returning a sequence
|
||
of sequences (e.g. a list of tuples). An empty sequence is returned
|
||
when no more rows are available.</p>
|
||
<p>The number of rows to fetch per call is specified by the parameter.
|
||
If it is not given, the cursor’s arraysize determines the number
|
||
of rows to be fetched. The method should try to fetch as many rows
|
||
as indicated by the size parameter.
|
||
If this is not possible due to the specified number of rows not being
|
||
available, fewer rows may be returned.</p>
|
||
<p>An exception will be raised if the previous call to execute() didn’t
|
||
produce a result set or execute() wasn’t called before.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.fetchone">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">fetchone</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mariadb.cursors.Cursor.fetchone" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Fetch the next row of a query result set, returning a single sequence,
|
||
or None if no more data is available.</p>
|
||
<p>An exception will be raised if the previous call to execute() didn’t
|
||
produce a result set or execute() wasn’t called before.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.next">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">next</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mariadb.cursors.Cursor.next" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Return the next row from the currently executing SQL statement
|
||
using the same semantics as .fetchone().</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.nextset">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">nextset</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mariadb.cursors.Cursor.nextset" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Will make the cursor skip to the next available result set,
|
||
discarding any remaining rows from the current set.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.scroll">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">scroll</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'relative'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#mariadb.cursors.Cursor.scroll" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Scroll the cursor in the result set to a new position according to mode.</p>
|
||
<p>If mode is “relative” (default), value is taken as offset to the current
|
||
position in the result set, if set to absolute, value states an absolute
|
||
target position.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.setinputsizes">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">setinputsizes</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mariadb.cursors.Cursor.setinputsizes" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Required by PEP-249. Does nothing in MariaDB Connector/Python</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.setoutputsize">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">setoutputsize</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mariadb.cursors.Cursor.setoutputsize" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Required by PEP-249. Does nothing in MariaDB Connector/Python</p>
|
||
</dd></dl>
|
||
|
||
</div>
|
||
<div class="section" id="cursor-attributes">
|
||
<h2>Cursor attributes<a class="headerlink" href="#cursor-attributes" title="Permalink to this headline">¶</a></h2>
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.arraysize">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">arraysize</span></span><a class="headerlink" href="#mariadb.cursors.Cursor.arraysize" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>(read/write)</p>
|
||
<p>the number of rows to fetch</p>
|
||
<p>This read/write attribute specifies the number of rows to fetch at a time with .fetchmany(). It defaults to 1 meaning to fetch a single row at a time</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.buffered">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">buffered</span></span><a class="headerlink" href="#mariadb.cursors.Cursor.buffered" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>When True all result sets are immediately transferred and the connection
|
||
between client and server is no longer blocked. Since version 1.1.0 default
|
||
is True, for prior versions default was False.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.closed">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">closed</span></span><a class="headerlink" href="#mariadb.cursors.Cursor.closed" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Indicates if the cursor is closed and can’t be reused</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.connection">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">connection</span></span><a class="headerlink" href="#mariadb.cursors.Cursor.connection" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Read-Only attribute which returns the reference to the connection
|
||
object on which the cursor was created.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.description">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">description</span></span><a class="headerlink" href="#mariadb.cursors.Cursor.description" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>This read-only attribute is a sequence of 8-item sequences
|
||
Each of these sequences contains information describing one result column:</p>
|
||
<ul class="simple">
|
||
<li><p>name</p></li>
|
||
<li><p>type_code</p></li>
|
||
<li><p>display_size</p></li>
|
||
<li><p>internal_size</p></li>
|
||
<li><p>precision</p></li>
|
||
<li><p>scale</p></li>
|
||
<li><p>null_ok</p></li>
|
||
<li><p>field_flags</p></li>
|
||
</ul>
|
||
<p>This attribute will be None for operations that do not return rows or if the cursor has
|
||
not had an operation invoked via the .execute*() method yet.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>The 8th parameter ‘field_flags’ is an extension to the PEP-249 DB API standard.
|
||
In combination with the type element field, it can be determined for example,
|
||
whether a column is a BLOB or TEXT field:</p>
|
||
</div>
|
||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="n">cursor</span><span class="o">.</span><span class="n">description</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="n">FIELD_TYPE</span><span class="o">.</span><span class="n">BLOB</span><span class="p">:</span>
|
||
<span class="k">if</span> <span class="n">cursor</span><span class="o">.</span><span class="n">description</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">7</span><span class="p">]</span> <span class="o">==</span> <span class="n">FIELD_FLAG</span><span class="o">.</span><span class="n">BINARY</span><span class="p">:</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="s2">"column is BLOB"</span><span class="p">)</span>
|
||
<span class="k">else</span><span class="p">:</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="s2">"column is TEXT"</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.lastrowid">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">lastrowid</span></span><a class="headerlink" href="#mariadb.cursors.Cursor.lastrowid" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Returns the ID generated by a query on a table with a column having
|
||
the AUTO_INCREMENT attribute or the value for the last usage of
|
||
LAST_INSERT_ID().</p>
|
||
<p>If the last query wasn’t an INSERT or UPDATE
|
||
statement or if the modified table does not have a column with the
|
||
AUTO_INCREMENT attribute and LAST_INSERT_ID was not used, the returned
|
||
value will be zero</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.sp_outparams">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">sp_outparams</span></span><a class="headerlink" href="#mariadb.cursors.Cursor.sp_outparams" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Indicates if the current result set contains in out or out parameter
|
||
from a previous executed stored procedure</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.rowcount">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">rowcount</span></span><a class="headerlink" href="#mariadb.cursors.Cursor.rowcount" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>This read-only attribute specifies the number of rows that the last
|
||
execute*() produced (for DQL statements like SELECT) or affected
|
||
(for DML statements like UPDATE or INSERT).
|
||
The return value is -1 in case no .execute*() has been performed
|
||
on the cursor or the rowcount of the last operation cannot be
|
||
determined by the interface.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>For unbuffered cursors (default) the exact number of rows can only be
|
||
determined after all rows were fetched.</p>
|
||
</div>
|
||
<p>Example:</p>
|
||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">cursor</span><span class="o">=</span><span class="n">conn</span><span class="o">.</span><span class="n">cursor</span><span class="p">()</span>
|
||
<span class="gp">>>> </span><span class="n">cursor</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s2">"SELECT 1"</span><span class="p">)</span>
|
||
<span class="gp">>>> </span><span class="n">cursor</span><span class="o">.</span><span class="n">rowcount</span>
|
||
<span class="go">-1</span>
|
||
<span class="gp">>>> </span><span class="n">rows</span><span class="o">=</span> <span class="n">cursor</span><span class="o">.</span><span class="n">fetchall</span><span class="p">()</span>
|
||
<span class="gp">>>> </span><span class="n">cursor</span><span class="o">.</span><span class="n">rowcount</span>
|
||
<span class="go">1</span>
|
||
<span class="gp">>>> </span><span class="n">cursor</span><span class="o">=</span><span class="n">conn</span><span class="o">.</span><span class="n">cursor</span><span class="p">(</span><span class="n">buffered</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
||
<span class="gp">>>> </span><span class="n">cursor</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s2">"SELECT 1"</span><span class="p">)</span>
|
||
<span class="gp">>>> </span><span class="n">cursor</span><span class="o">.</span><span class="n">rowcount</span>
|
||
<span class="go">1</span>
|
||
</pre></div>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.statement">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">statement</span></span><a class="headerlink" href="#mariadb.cursors.Cursor.statement" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>(read only)</p>
|
||
<p>The last executed statement</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="mariadb.cursors.Cursor.warnings">
|
||
<span class="sig-prename descclassname"><span class="pre">Cursor.</span></span><span class="sig-name descname"><span class="pre">warnings</span></span><a class="headerlink" href="#mariadb.cursors.Cursor.warnings" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Returns the number of warnings from the last executed statement, or zero
|
||
if there are no warnings.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>Warnings can be retrieved by the show_warnings() method of connection class.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<div class="clearer"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||
<div class="sphinxsidebarwrapper">
|
||
<h3><a href="index.html">Table of Contents</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#">The cursor class</a><ul>
|
||
<li><a class="reference internal" href="#cursor-methods">Cursor methods</a></li>
|
||
<li><a class="reference internal" href="#cursor-attributes">Cursor attributes</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h4>Previous topic</h4>
|
||
<p class="topless"><a href="connection.html"
|
||
title="previous chapter">The connection class</a></p>
|
||
<h4>Next topic</h4>
|
||
<p class="topless"><a href="pool.html"
|
||
title="next chapter">The ConnectionPool class</a></p>
|
||
<div role="note" aria-label="source link">
|
||
<h3>This Page</h3>
|
||
<ul class="this-page-menu">
|
||
<li><a href="_sources/cursor.rst.txt"
|
||
rel="nofollow">Show Source</a></li>
|
||
</ul>
|
||
</div>
|
||
<div id="searchbox" style="display: none" role="search">
|
||
<h3 id="searchlabel">Quick search</h3>
|
||
<div class="searchformwrapper">
|
||
<form class="search" action="search.html" method="get">
|
||
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
|
||
<input type="submit" value="Go" />
|
||
</form>
|
||
</div>
|
||
</div>
|
||
<script>$('#searchbox').show(0);</script>
|
||
</div>
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="genindex.html" title="General Index"
|
||
>index</a></li>
|
||
<li class="right" >
|
||
<a href="py-modindex.html" title="Python Module Index"
|
||
>modules</a> |</li>
|
||
<li class="right" >
|
||
<a href="pool.html" title="The ConnectionPool class"
|
||
>next</a> |</li>
|
||
<li class="right" >
|
||
<a href="connection.html" title="The connection class"
|
||
>previous</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="index.html">MariaDB Connector/Python 1.1.0-alpha documentation</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">The cursor class</a></li>
|
||
</ul>
|
||
</div>
|
||
<div class="footer" role="contentinfo">
|
||
© Copyright 2019-2021 MariaDB Corporation and Georg Richter.
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
|
||
</div>
|
||
</body>
|
||
</html> |