mirror of
https://gitea.invidious.io/iv-org/shard-crystal-sqlite3.git
synced 2024-08-15 00:53:26 +00:00
520 lines
19 KiB
HTML
520 lines
19 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<link href="../css/style.css" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<body>
|
|
|
|
|
|
<h1>class SQLite3::Database</h1>
|
|
|
|
|
|
|
|
<h2>Overview</h2>
|
|
|
|
<p>The Database class encapsulates single connection to an SQLite3 database. Its usage is very straightforward:</p>
|
|
|
|
<pre><code><span class="k">require</span> <span class="s">"sqlite3"</span>
|
|
|
|
db <span class="o">=</span> <span class="t">SQLite3</span><span class="t">::</span><span class="t">Database</span>.<span class="k">new</span>( <span class="s">"data.db"</span> )
|
|
db.execute(<span class="s">"select * from table"</span>) <span class="k">do</span> <span class="o">|</span>row<span class="o">|</span>
|
|
p row
|
|
<span class="k">end</span>
|
|
db.close</code></pre>
|
|
|
|
<p>Lower level methods are also provided.</p>
|
|
|
|
|
|
|
|
|
|
|
|
<h2>Superclass hierarchy</h2>
|
|
<div style="padding-left: 0px">Object</div><div style="padding-left: 20px">Reference</div><div style="padding-left: 40px"><a href="../SQLite3/Database.html">SQLite3::Database</a></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2>Class Method Summary</h2>
|
|
<ul>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#new%28filename%2C%20%26block%29-class-method" class="signature"><strong>.new</strong>(filename, &block)</a>
|
|
|
|
<div class="summary"><p>Creates a new Database object that opens the given file, yields it, and closes it at the end.</p></div>
|
|
|
|
</li>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#new%28filename%29-class-method" class="signature"><strong>.new</strong>(filename)</a>
|
|
|
|
<div class="summary"><p>Creates a new Database object that opens the given file.</p></div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<h2>Instance Method Summary</h2>
|
|
<ul>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#close-instance-method" class="signature"><strong>#close</strong></a>
|
|
|
|
<div class="summary"><p>Closes this database.</p></div>
|
|
|
|
</li>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#closed%3F-instance-method" class="signature"><strong>#closed?</strong></a>
|
|
|
|
<div class="summary"><p>Returns <code>true</code> if this database instance has been closed (see <code><a href="../SQLite3/Database.html#close-instance-method">#close</a></code>).</p></div>
|
|
|
|
</li>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#execute%28sql%2C%20%2Abinds%2C%20%26block%29-instance-method" class="signature"><strong>#execute</strong>(sql, *binds, &block)</a>
|
|
|
|
<div class="summary"><p>Executes the given SQL statement.</p></div>
|
|
|
|
</li>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#execute%28sql%2C%20binds%20%3A%20Enumerable%29-instance-method" class="signature"><strong>#execute</strong>(sql, binds : Enumerable)</a>
|
|
|
|
<div class="summary"><p>Executes the given SQL statement.</p></div>
|
|
|
|
</li>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#execute%28sql%2C%20%2Abinds%29-instance-method" class="signature"><strong>#execute</strong>(sql, *binds)</a>
|
|
|
|
<div class="summary"><p>Executes the given SQL statement.</p></div>
|
|
|
|
</li>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#execute%28sql%2C%20binds%20%3A%20Enumerable%2C%20%26block%29-instance-method" class="signature"><strong>#execute</strong>(sql, binds : Enumerable, &block)</a>
|
|
|
|
<div class="summary"><p>Executes the given SQL statement.</p></div>
|
|
|
|
</li>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#get_first_row%28sql%2C%20binds%20%3A%20Enumerable%29-instance-method" class="signature"><strong>#get_first_row</strong>(sql, binds : Enumerable)</a>
|
|
|
|
<div class="summary"><p>A convenience method that returns the first row of a query result.</p></div>
|
|
|
|
</li>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#get_first_row%28sql%2C%20%2Abinds%29-instance-method" class="signature"><strong>#get_first_row</strong>(sql, *binds)</a>
|
|
|
|
<div class="summary"><p>A convenience method that returns the first row of a query result.</p></div>
|
|
|
|
</li>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#get_first_value%28sql%2C%20binds%20%3A%20Enumerable%29-instance-method" class="signature"><strong>#get_first_value</strong>(sql, binds : Enumerable)</a>
|
|
|
|
<div class="summary"><p>A convenience method that returns the first value of the first row of a query result.</p></div>
|
|
|
|
</li>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#get_first_value%28sql%2C%20%2Abinds%29-instance-method" class="signature"><strong>#get_first_value</strong>(sql, *binds)</a>
|
|
|
|
<div class="summary"><p>A convenience method that returns the first value of the first row of a query result.</p></div>
|
|
|
|
</li>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#last_insert_row_id-instance-method" class="signature"><strong>#last_insert_row_id</strong></a>
|
|
|
|
<div class="summary"><p>Obtains the unique row ID of the last row to be inserted by this Database instance.</p></div>
|
|
|
|
</li>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#prepare%28sql%29-instance-method" class="signature"><strong>#prepare</strong>(sql)</a>
|
|
|
|
<div class="summary"><p>Prepares an sql statement.</p></div>
|
|
|
|
</li>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#query%28sql%2C%20binds%20%3A%20Enumerable%29-instance-method" class="signature"><strong>#query</strong>(sql, binds : Enumerable)</a>
|
|
|
|
<div class="summary"><p>Executes a query and gives back a <code><a href="../SQLite3/ResultSet.html">ResultSet</a></code>.</p></div>
|
|
|
|
</li>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#query%28sql%2C%20%2Abinds%29-instance-method" class="signature"><strong>#query</strong>(sql, *binds)</a>
|
|
|
|
<div class="summary"><p>Executes a query and gives back a <code><a href="../SQLite3/ResultSet.html">ResultSet</a></code>.</p></div>
|
|
|
|
</li>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#query%28sql%2C%20%2Abinds%2C%20%26block%29-instance-method" class="signature"><strong>#query</strong>(sql, *binds, &block)</a>
|
|
|
|
<div class="summary"><p>Executes a query and yields a <code><a href="../SQLite3/ResultSet.html">ResultSet</a></code> that will be closed at the end of the given block.</p></div>
|
|
|
|
</li>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#query%28sql%2C%20binds%20%3A%20Enumerable%2C%20%26block%29-instance-method" class="signature"><strong>#query</strong>(sql, binds : Enumerable, &block)</a>
|
|
|
|
<div class="summary"><p>Executes a query and yields a <code><a href="../SQLite3/ResultSet.html">ResultSet</a></code> that will be closed at the end of the given block.</p></div>
|
|
|
|
</li>
|
|
|
|
<li class="entry-summary">
|
|
<a href="#quote%28string%29-instance-method" class="signature"><strong>#quote</strong>(string)</a>
|
|
|
|
<div class="summary"><p>Quotes the given string, making it safe to use in an SQL statement.</p></div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2>Class Method Detail</h2>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="new%28filename%2C%20%26block%29-class-method">
|
|
|
|
def self.<strong>new</strong>(filename, &block)
|
|
</div>
|
|
|
|
<div class="doc"><p>Creates a new Database object that opens the given file, yields it, and closes it at the end.</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L25" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="new%28filename%29-class-method">
|
|
|
|
def self.<strong>new</strong>(filename)
|
|
</div>
|
|
|
|
<div class="doc"><p>Creates a new Database object that opens the given file.</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L16" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
|
|
|
|
|
|
<h2>Instance Method Detail</h2>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="close-instance-method">
|
|
|
|
def <strong>close</strong>
|
|
</div>
|
|
|
|
<div class="doc"><p>Closes this database.</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L167" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="closed%3F-instance-method">
|
|
|
|
def <strong>closed?</strong>
|
|
</div>
|
|
|
|
<div class="doc"><p>Returns <code>true</code> if this database instance has been closed (see <code><a href="../SQLite3/Database.html#close-instance-method">#close</a></code>).</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L162" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="execute%28sql%2C%20%2Abinds%2C%20%26block%29-instance-method">
|
|
|
|
def <strong>execute</strong>(sql, *binds, &block)
|
|
</div>
|
|
|
|
<div class="doc"><p>Executes the given SQL statement. If additional parameters are given, they are treated as bind variables,
|
|
and are bound to the placeholders in the query.</p>
|
|
|
|
<p>Note that if any of the values passed to this are hashes, then the key/value pairs are each bound separately,
|
|
with the key being used as the name of the placeholder to bind the value to.</p>
|
|
|
|
<p>Yields one <code>Array(<a href="../SQLite3/Value.html">Value</a>)</code> for each result.</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L52" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="execute%28sql%2C%20binds%20%3A%20Enumerable%29-instance-method">
|
|
|
|
def <strong>execute</strong>(sql, binds : Enumerable)
|
|
</div>
|
|
|
|
<div class="doc"><p>Executes the given SQL statement. If additional parameters are given, they are treated as bind variables,
|
|
and are bound to the placeholders in the query.</p>
|
|
|
|
<p>Note that if any of the values passed to this are hashes, then the key/value pairs are each bound separately,
|
|
with the key being used as the name of the placeholder to bind the value to.</p>
|
|
|
|
<p>Returns an <code>Array(Array(<a href="../SQLite3/Value.html">Value</a>))</code>.</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L65" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="execute%28sql%2C%20%2Abinds%29-instance-method">
|
|
|
|
def <strong>execute</strong>(sql, *binds)
|
|
</div>
|
|
|
|
<div class="doc"><p>Executes the given SQL statement. If additional parameters are given, they are treated as bind variables,
|
|
and are bound to the placeholders in the query.</p>
|
|
|
|
<p>Note that if any of the values passed to this are hashes, then the key/value pairs are each bound separately,
|
|
with the key being used as the name of the placeholder to bind the value to.</p>
|
|
|
|
<p>Returns an <code>Array(Array(<a href="../SQLite3/Value.html">Value</a>))</code>.</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L41" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="execute%28sql%2C%20binds%20%3A%20Enumerable%2C%20%26block%29-instance-method">
|
|
|
|
def <strong>execute</strong>(sql, binds : Enumerable, &block)
|
|
</div>
|
|
|
|
<div class="doc"><p>Executes the given SQL statement. If additional parameters are given, they are treated as bind variables,
|
|
and are bound to the placeholders in the query.</p>
|
|
|
|
<p>Note that if any of the values passed to this are hashes, then the key/value pairs are each bound separately,
|
|
with the key being used as the name of the placeholder to bind the value to.</p>
|
|
|
|
<p>Yields one <code>Array(<a href="../SQLite3/Value.html">Value</a>)</code> for each result.</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L80" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="get_first_row%28sql%2C%20binds%20%3A%20Enumerable%29-instance-method">
|
|
|
|
def <strong>get_first_row</strong>(sql, binds : Enumerable)
|
|
</div>
|
|
|
|
<div class="doc"><p>A convenience method that returns the first row of a query result.</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L94" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="get_first_row%28sql%2C%20%2Abinds%29-instance-method">
|
|
|
|
def <strong>get_first_row</strong>(sql, *binds)
|
|
</div>
|
|
|
|
<div class="doc"><p>A convenience method that returns the first row of a query result.</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L89" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="get_first_value%28sql%2C%20binds%20%3A%20Enumerable%29-instance-method">
|
|
|
|
def <strong>get_first_value</strong>(sql, binds : Enumerable)
|
|
</div>
|
|
|
|
<div class="doc"><p>A convenience method that returns the first value of the first row of a query result.</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L110" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="get_first_value%28sql%2C%20%2Abinds%29-instance-method">
|
|
|
|
def <strong>get_first_value</strong>(sql, *binds)
|
|
</div>
|
|
|
|
<div class="doc"><p>A convenience method that returns the first value of the first row of a query result.</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L105" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="last_insert_row_id-instance-method">
|
|
|
|
def <strong>last_insert_row_id</strong>
|
|
</div>
|
|
|
|
<div class="doc"><p>Obtains the unique row ID of the last row to be inserted by this Database instance.
|
|
This is an <code>Int64</code>.</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L151" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="prepare%28sql%29-instance-method">
|
|
|
|
def <strong>prepare</strong>(sql)
|
|
</div>
|
|
|
|
<div class="doc"><p>Prepares an sql statement. Returns a <code><a href="../SQLite3/Statement.html">Statement</a></code>.</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L145" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="query%28sql%2C%20binds%20%3A%20Enumerable%29-instance-method">
|
|
|
|
def <strong>query</strong>(sql, binds : Enumerable)
|
|
</div>
|
|
|
|
<div class="doc"><p>Executes a query and gives back a <code><a href="../SQLite3/ResultSet.html">ResultSet</a></code>.</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L133" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="query%28sql%2C%20%2Abinds%29-instance-method">
|
|
|
|
def <strong>query</strong>(sql, *binds)
|
|
</div>
|
|
|
|
<div class="doc"><p>Executes a query and gives back a <code><a href="../SQLite3/ResultSet.html">ResultSet</a></code>.</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L121" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="query%28sql%2C%20%2Abinds%2C%20%26block%29-instance-method">
|
|
|
|
def <strong>query</strong>(sql, *binds, &block)
|
|
</div>
|
|
|
|
<div class="doc"><p>Executes a query and yields a <code><a href="../SQLite3/ResultSet.html">ResultSet</a></code> that will be closed at the end of the given block.</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L126" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="query%28sql%2C%20binds%20%3A%20Enumerable%2C%20%26block%29-instance-method">
|
|
|
|
def <strong>query</strong>(sql, binds : Enumerable, &block)
|
|
</div>
|
|
|
|
<div class="doc"><p>Executes a query and yields a <code><a href="../SQLite3/ResultSet.html">ResultSet</a></code> that will be closed at the end of the given block.</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L138" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
<div class="entry-detail">
|
|
<div class="signature" id="quote%28string%29-instance-method">
|
|
|
|
def <strong>quote</strong>(string)
|
|
</div>
|
|
|
|
<div class="doc"><p>Quotes the given string, making it safe to use in an SQL statement.
|
|
It replaces all instances of the single-quote character with two single-quote characters.</p></div>
|
|
|
|
|
|
<br/>
|
|
<div>[<a href="https://github.com/manastech/crystal-sqlite3/blob/d62185867bf35fa946436da24de5e8aa6f1a6227/src/sqlite3/database.cr#L157" target="_blank">View source</a>]</div>
|
|
|
|
</div>
|
|
<hr/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|