sqlite-ruby 2.0.3 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/faq/faq.html +28 -28
- data/ext/sqlite-api.c +2 -0
- data/lib/sqlite/version.rb +2 -2
- metadata +3 -3
data/doc/faq/faq.html
CHANGED
@@ -62,25 +62,25 @@
|
|
62
62
|
<ul>
|
63
63
|
<li>How do I do a database query?
|
64
64
|
<ul>
|
65
|
-
<li><a href='#
|
66
|
-
<li><a href='#
|
67
|
-
<li><a href='#
|
68
|
-
<li><a href='#
|
69
|
-
<li><a href='#
|
70
|
-
<li><a href='#
|
65
|
+
<li><a href='#538732450'>I just want an array of the rows…</a></li>
|
66
|
+
<li><a href='#538732410'>I’d like to use a block to iterate through the rows…</a></li>
|
67
|
+
<li><a href='#538732370'>I need to get the column names as well as the rows…</a></li>
|
68
|
+
<li><a href='#538732330'>I need the result set object itself…</a></li>
|
69
|
+
<li><a href='#538732290'>I just want the first row of the result set…</a></li>
|
70
|
+
<li><a href='#538732250'>I just want the first value of the first row of the result set…</a></li>
|
71
71
|
</ul>
|
72
72
|
</li>
|
73
|
-
<li><a href='#
|
74
|
-
<li><a href='#
|
75
|
-
<li><a href='#
|
76
|
-
<li><a href='#
|
77
|
-
<li><a href='#
|
78
|
-
<li><a href='#
|
79
|
-
<li><a href='#
|
80
|
-
<li><a href='#
|
73
|
+
<li><a href='#538732180'>How do I prepare a statement for repeated execution?</a></li>
|
74
|
+
<li><a href='#538732140'>How do I use placeholders in an <span class="caps">SQL</span> statement?</a></li>
|
75
|
+
<li><a href='#538732100'>How do I discover metadata about a query?</a></li>
|
76
|
+
<li><a href='#538732060'>I’d like the rows to be indexible by column name.</a></li>
|
77
|
+
<li><a href='#538732020'>I’d like the values from a query to be the correct types, instead of String.</a></li>
|
78
|
+
<li><a href='#538731980'>How do I do a <span class="caps">DDL </span>(insert, update, delete) statement?</a></li>
|
79
|
+
<li><a href='#538731940'>How do I execute multiple statements in a single string?</a></li>
|
80
|
+
<li><a href='#538731900'>How do I begin/end a transaction?</a></li>
|
81
81
|
</ul>
|
82
82
|
</div>
|
83
|
-
<a name='
|
83
|
+
<a name='538732450'></a>
|
84
84
|
<div class='faq-title'>How do I do a database query? I just want an array of the rows…</div>
|
85
85
|
<div class='faq-answer'><p>Use the <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#execute</a> method. If you don’t give it a block, it will return an array of all the rows:</p>
|
86
86
|
|
@@ -90,7 +90,7 @@
|
|
90
90
|
db = SQLite::<a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database</a>.new( "test.db" )
|
91
91
|
rows = db.execute( "select * from test" )
|
92
92
|
</pre></div>
|
93
|
-
<a name='
|
93
|
+
<a name='538732410'></a>
|
94
94
|
<div class='faq-title'>How do I do a database query? I’d like to use a block to iterate through the rows…</div>
|
95
95
|
<div class='faq-answer'><p>Use the <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#execute</a> method. If you give it a block, each row of the result will be yielded to the block:</p>
|
96
96
|
|
@@ -102,7 +102,7 @@
|
|
102
102
|
...
|
103
103
|
end
|
104
104
|
</pre></div>
|
105
|
-
<a name='
|
105
|
+
<a name='538732370'></a>
|
106
106
|
<div class='faq-title'>How do I do a database query? I need to get the column names as well as the rows…</div>
|
107
107
|
<div class='faq-answer'><p>Use the <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#execute2</a> method. This works just like <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#execute</a>; if you don’t give it a block, it returns an array of rows; otherwise, it will yield each row to the block. <em>However</em>, the first row returned is always an array of the column names from the query:</p>
|
108
108
|
|
@@ -123,7 +123,7 @@
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
</pre></div>
|
126
|
-
<a name='
|
126
|
+
<a name='538732330'></a>
|
127
127
|
<div class='faq-title'>How do I do a database query? I need the result set object itself…</div>
|
128
128
|
<div class='faq-answer'><p>Sometimes you don’t want all the rows at once, and yet you’d like to be able to iterate through the results. For instance, you may want to pass the results to some other function (or series of functions) and have them pull rows from the results on demand. This is more effecient for very large queries.</p>
|
129
129
|
|
@@ -167,7 +167,7 @@
|
|
167
167
|
</pre>
|
168
168
|
|
169
169
|
<p>In general, <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#query</a> is not a very good choice for such operations…</p></div>
|
170
|
-
<a name='
|
170
|
+
<a name='538732290'></a>
|
171
171
|
<div class='faq-title'>How do I do a database query? I just want the first row of the result set…</div>
|
172
172
|
<div class='faq-answer'><p>Easy. Just call <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#get_first_row</a>:</p>
|
173
173
|
|
@@ -176,7 +176,7 @@
|
|
176
176
|
</pre>
|
177
177
|
|
178
178
|
<p>This also supports bind variables, just like <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#execute</a> and friends.</p></div>
|
179
|
-
<a name='
|
179
|
+
<a name='538732250'></a>
|
180
180
|
<div class='faq-title'>How do I do a database query? I just want the first value of the first row of the result set…</div>
|
181
181
|
<div class='faq-answer'><p>Also easy. Just call <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#get_first_value</a>:</p>
|
182
182
|
|
@@ -185,7 +185,7 @@
|
|
185
185
|
</pre>
|
186
186
|
|
187
187
|
<p>This also supports bind variables, just like <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#execute</a> and friends.</p></div>
|
188
|
-
<a name='
|
188
|
+
<a name='538732180'></a>
|
189
189
|
<div class='faq-title'>How do I prepare a statement for repeated execution?</div>
|
190
190
|
<div class='faq-answer'><p>If the same statement is going to be executed repeatedly, you can speed things up a bit by <em>preparing</em> the statement. You do this via the <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#prepare</a> method. It returns a <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Statement.html'>Statement</a> object, and you can then invoke #execute on that to get the <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/ResultSet.html'>ResultSet</a>:</p>
|
191
191
|
|
@@ -200,7 +200,7 @@
|
|
200
200
|
</pre>
|
201
201
|
|
202
202
|
<p>This is made more useful by the ability to bind variables to placeholders via the <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Statement.html'>Statement#bind_param</a> and <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Statement.html'>Statement#bind_params</a> methods. (See the next <span class="caps">FAQ</span> for details.)</p></div>
|
203
|
-
<a name='
|
203
|
+
<a name='538732140'></a>
|
204
204
|
<div class='faq-title'>How do I use placeholders in an <span class="caps">SQL</span> statement?</div>
|
205
205
|
<div class='faq-answer'><p>Placeholders in an <span class="caps">SQL</span> statement take any of the following formats:</p>
|
206
206
|
|
@@ -258,7 +258,7 @@
|
|
258
258
|
|
259
259
|
stmt.bind_params( "value", "name" => "bob" )
|
260
260
|
</pre></div>
|
261
|
-
<a name='
|
261
|
+
<a name='538732100'></a>
|
262
262
|
<div class='faq-title'>How do I discover metadata about a query?</div>
|
263
263
|
<div class='faq-answer'><p>If you ever want to know the names or types of the columns in a result set, you can do it in several ways.</p>
|
264
264
|
|
@@ -287,7 +287,7 @@
|
|
287
287
|
p stmt.columns
|
288
288
|
p stmt.types
|
289
289
|
</pre></div>
|
290
|
-
<a name='
|
290
|
+
<a name='538732060'></a>
|
291
291
|
<div class='faq-title'>I’d like the rows to be indexible by column name.</div>
|
292
292
|
<div class='faq-answer'><p>By default, each row from a query is returned as an Array of values. This means that you can only obtain values by their index. Sometimes, however, you would like to obtain values by their column name.</p>
|
293
293
|
|
@@ -312,7 +312,7 @@
|
|
312
312
|
p row[1] == row['column2']
|
313
313
|
end
|
314
314
|
</pre></div>
|
315
|
-
<a name='
|
315
|
+
<a name='538732020'></a>
|
316
316
|
<div class='faq-title'>I’d like the values from a query to be the correct types, instead of String.</div>
|
317
317
|
<div class='faq-answer'><p>You can turn on “type translation” by setting <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#type_translation</a> to true:</p>
|
318
318
|
|
@@ -347,14 +347,14 @@
|
|
347
347
|
obj = db.get_first_value( "select thing from objects where name='bob'" )
|
348
348
|
p obj == h
|
349
349
|
</pre></div>
|
350
|
-
<a name='
|
350
|
+
<a name='538731980'></a>
|
351
351
|
<div class='faq-title'>How do I do a <span class="caps">DDL </span>(insert, update, delete) statement?</div>
|
352
352
|
<div class='faq-answer'><p>You can actually do inserts, updates, and deletes in exactly the same way as selects, but in general the <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#execute</a> method will be most convenient:</p>
|
353
353
|
|
354
354
|
<pre>
|
355
355
|
db.execute( "insert into table values ( ?, ? )", *bind_vars )
|
356
356
|
</pre></div>
|
357
|
-
<a name='
|
357
|
+
<a name='538731940'></a>
|
358
358
|
<div class='faq-title'>How do I execute multiple statements in a single string?</div>
|
359
359
|
<div class='faq-answer'><p>The standard query methods (<a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#execute</a>, <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#execute2</a>, <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#query</a>, and <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Statement.html'>Statement#execute</a>) will only execute the first statement in the string that is given to them. Thus, if you have a string with multiple <span class="caps">SQL</span> statements, each separated by a string, you can’t use those methods to execute them all at once.</p>
|
360
360
|
|
@@ -376,7 +376,7 @@
|
|
376
376
|
</pre>
|
377
377
|
|
378
378
|
<p>Unlike the other query methods, <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#execute_batch</a> accepts no block. It will also only ever return <ins>nil</ins>. Thus, it is really only suitable for batch processing of <span class="caps">DDL</span> statements.</p></div>
|
379
|
-
<a name='
|
379
|
+
<a name='538731900'></a>
|
380
380
|
<div class='faq-title'>How do I begin/end a transaction?</div>
|
381
381
|
<div class='faq-answer'><p>Use <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#transaction</a> to start a transaction. If you give it a block, the block will be automatically committed at the end of the block, unless an exception was raised, in which case the transaction will be rolled back. (Never explicitly call <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#commit</a> or <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#rollback</a> inside of a transaction block—you’ll get errors when the block terminates!)</p>
|
382
382
|
|
data/ext/sqlite-api.c
CHANGED
data/lib/sqlite/version.rb
CHANGED
metadata
CHANGED
@@ -3,9 +3,9 @@ rubygems_version: 0.8.1
|
|
3
3
|
specification_version: 1
|
4
4
|
name: sqlite-ruby
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 2.0
|
7
|
-
date: 2004-09-
|
8
|
-
summary:
|
6
|
+
version: 2.1.0
|
7
|
+
date: 2004-09-27
|
8
|
+
summary: SQLite/Ruby is a module to allow Ruby scripts to interface with a SQLite database.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
author: Jamis Buck
|