sqlite3-ruby 1.2.1-mswin32 → 1.2.2-mswin32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sqlite3-ruby might be problematic. Click here for more details.
- data/{README → README.rdoc} +2 -6
- data/doc/faq/faq.rb +1 -33
- data/ext/sqlite3_api/extconf.rb +3 -0
- data/ext/sqlite3_api/sqlite3_api.i +27 -28
- data/ext/sqlite3_api/sqlite3_api_wrap.c +36 -37
- data/ext/sqlite3_api/sqlite3_api_wrap.dll +0 -0
- data/ext/sqlite3_api/sqlite3_api_wrap.exp +0 -0
- data/ext/sqlite3_api/sqlite3_api_wrap.lib +0 -0
- data/ext/sqlite3_api/sqlite3_api_wrap.obj +0 -0
- data/ext/sqlite3_api/win32/build.bat +7 -7
- data/lib/sqlite3.rb +0 -32
- data/lib/sqlite3/constants.rb +0 -32
- data/lib/sqlite3/database.rb +7 -37
- data/lib/sqlite3/driver/dl/api.rb +0 -32
- data/lib/sqlite3/driver/dl/driver.rb +1 -32
- data/lib/sqlite3/driver/native/driver.rb +1 -33
- data/lib/sqlite3/errors.rb +1 -33
- data/lib/sqlite3/pragmas.rb +5 -35
- data/lib/sqlite3/resultset.rb +13 -39
- data/lib/sqlite3/statement.rb +5 -33
- data/lib/sqlite3/translator.rb +12 -39
- data/lib/sqlite3/value.rb +0 -32
- data/lib/sqlite3/version.rb +1 -33
- data/lib/sqlite3_api.dll +0 -0
- data/test/driver/dl/tc_driver.rb +0 -32
- data/test/mocks.rb +22 -79
- data/test/tc_database.rb +47 -65
- data/test/tc_errors.rb +2 -35
- data/test/tc_integration.rb +112 -64
- data/test/tests.rb +4 -34
- metadata +20 -18
- data/doc/faq/faq.html +0 -408
- data/ext/sqlite3_api/Makefile +0 -143
- data/lib/sqlite3_api.so +0 -0
data/doc/faq/faq.html
DELETED
@@ -1,408 +0,0 @@
|
|
1
|
-
<html>
|
2
|
-
<head>
|
3
|
-
<title>SQLite3/Ruby FAQ</title>
|
4
|
-
<style type="text/css">
|
5
|
-
a, a:visited, a:active {
|
6
|
-
color: #00F;
|
7
|
-
text-decoration: none;
|
8
|
-
}
|
9
|
-
|
10
|
-
a:hover {
|
11
|
-
text-decoration: underline;
|
12
|
-
}
|
13
|
-
|
14
|
-
.faq-list {
|
15
|
-
color: #000;
|
16
|
-
font-family: vera-sans, verdana, arial, sans-serif;
|
17
|
-
}
|
18
|
-
|
19
|
-
.faq-title {
|
20
|
-
background: #007;
|
21
|
-
color: #FFF;
|
22
|
-
font-family: vera-sans, verdana, arial, sans-serif;
|
23
|
-
padding-left: 1em;
|
24
|
-
padding-top: 0.5em;
|
25
|
-
padding-bottom: 0.5em;
|
26
|
-
font-weight: bold;
|
27
|
-
font-size: large;
|
28
|
-
border: 1px solid #000;
|
29
|
-
}
|
30
|
-
|
31
|
-
.faq-answer {
|
32
|
-
margin-left: 1em;
|
33
|
-
color: #000;
|
34
|
-
font-family: vera-sans, verdana, arial, sans-serif;
|
35
|
-
}
|
36
|
-
|
37
|
-
.faq-answer pre {
|
38
|
-
margin-left: 1em;
|
39
|
-
color: #000;
|
40
|
-
background: #FFE;
|
41
|
-
font-size: normal;
|
42
|
-
border: 1px dotted #CCC;
|
43
|
-
padding: 1em;
|
44
|
-
}
|
45
|
-
|
46
|
-
h1 {
|
47
|
-
background: #005;
|
48
|
-
color: #FFF;
|
49
|
-
font-family: vera-sans, verdana, arial, sans-serif;
|
50
|
-
padding-left: 1em;
|
51
|
-
padding-top: 1em;
|
52
|
-
padding-bottom: 1em;
|
53
|
-
font-weight: bold;
|
54
|
-
font-size: x-large;
|
55
|
-
border: 1px solid #00F;
|
56
|
-
}
|
57
|
-
</style>
|
58
|
-
</head>
|
59
|
-
<body>
|
60
|
-
<h1>SQLite/Ruby FAQ</h1>
|
61
|
-
<div class="faq-list">
|
62
|
-
<ul>
|
63
|
-
<li>How do I do a database query?
|
64
|
-
<ul>
|
65
|
-
<li><a href='#37380'>I just want an array of the rows…</a></li>
|
66
|
-
<li><a href='#36440'>I’d like to use a block to iterate through the rows…</a></li>
|
67
|
-
<li><a href='#32250'>I need to get the column names as well as the rows…</a></li>
|
68
|
-
<li><a href='#31680'>I just want the first row of the result set…</a></li>
|
69
|
-
<li><a href='#31240'>I just want the first value of the first row of the result set…</a></li>
|
70
|
-
</ul>
|
71
|
-
</li>
|
72
|
-
<li><a href='#30080'>How do I prepare a statement for repeated execution?</a></li>
|
73
|
-
<li><a href='#27350'>How do I use placeholders in an <span class="caps">SQL</span> statement?</a></li>
|
74
|
-
<li><a href='#26510'>How do I discover metadata about a query?</a></li>
|
75
|
-
<li><a href='#26320'>I’d like the rows to be indexible by column name.</a></li>
|
76
|
-
<li><a href='#26050'>I’d like the values from a query to be the correct types, instead of String.</a></li>
|
77
|
-
<li><a href='#25850'>How do insert binary data into the database?</a></li>
|
78
|
-
<li><a href='#25740'>How do I do a <span class="caps">DDL</span> (insert, update, delete) statement?</a></li>
|
79
|
-
<li><a href='#23610'>How do I execute multiple statements in a single string?</a></li>
|
80
|
-
<li><a href='#22110'>How do I begin/end a transaction?</a></li>
|
81
|
-
</ul>
|
82
|
-
</div>
|
83
|
-
<a name='37380'></a>
|
84
|
-
<div class='faq-title'>How do I do a database query? I just want an array of the rows…</div>
|
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
|
-
|
87
|
-
|
88
|
-
<pre>
|
89
|
-
require 'sqlite3'
|
90
|
-
|
91
|
-
db = SQLite3::<a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database</a>.new( "test.db" )
|
92
|
-
rows = db.execute( "select * from test" )
|
93
|
-
</pre></div>
|
94
|
-
<a name='36440'></a>
|
95
|
-
<div class='faq-title'>How do I do a database query? I’d like to use a block to iterate through the rows…</div>
|
96
|
-
<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>
|
97
|
-
|
98
|
-
|
99
|
-
<pre>
|
100
|
-
require 'sqlite3'
|
101
|
-
|
102
|
-
db = SQLite3::<a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database</a>.new( "test.db" )
|
103
|
-
db.execute( "select * from test" ) do |row|
|
104
|
-
...
|
105
|
-
end
|
106
|
-
</pre></div>
|
107
|
-
<a name='32250'></a>
|
108
|
-
<div class='faq-title'>How do I do a database query? I need to get the column names as well as the rows…</div>
|
109
|
-
<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>
|
110
|
-
|
111
|
-
|
112
|
-
<pre>
|
113
|
-
require 'sqlite3'
|
114
|
-
|
115
|
-
db = SQLite3::<a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database</a>.new( "test.db" )
|
116
|
-
columns, *rows = db.execute2( "select * from test" )
|
117
|
-
|
118
|
-
# or use a block:
|
119
|
-
|
120
|
-
columns = nil
|
121
|
-
db.execute2( "select * from test" ) do |row|
|
122
|
-
if columns.nil?
|
123
|
-
columns = row
|
124
|
-
else
|
125
|
-
# process row
|
126
|
-
end
|
127
|
-
end
|
128
|
-
</pre></div>
|
129
|
-
<a name='31680'></a>
|
130
|
-
<div class='faq-title'>How do I do a database query? I just want the first row of the result set…</div>
|
131
|
-
<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>
|
132
|
-
|
133
|
-
|
134
|
-
<pre>
|
135
|
-
row = db.get_first_row( "select * from table" )
|
136
|
-
</pre>
|
137
|
-
|
138
|
-
<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>
|
139
|
-
<a name='31240'></a>
|
140
|
-
<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>
|
141
|
-
<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>
|
142
|
-
|
143
|
-
|
144
|
-
<pre>
|
145
|
-
count = db.get_first_value( "select count(*) from table" )
|
146
|
-
</pre>
|
147
|
-
|
148
|
-
<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>
|
149
|
-
<a name='30080'></a>
|
150
|
-
<div class='faq-title'>How do I prepare a statement for repeated execution?</div>
|
151
|
-
<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>
|
152
|
-
|
153
|
-
|
154
|
-
<pre>
|
155
|
-
stmt = db.prepare( "select * from person" )
|
156
|
-
|
157
|
-
1000.times do
|
158
|
-
stmt.execute do |result|
|
159
|
-
...
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
stmt.close
|
164
|
-
|
165
|
-
# or, use a block
|
166
|
-
|
167
|
-
db.prepare( "select * from person" ) do |stmt|
|
168
|
-
1000.times do
|
169
|
-
stmt.execute do |result|
|
170
|
-
...
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
</pre>
|
175
|
-
|
176
|
-
<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>
|
177
|
-
<a name='27350'></a>
|
178
|
-
<div class='faq-title'>How do I use placeholders in an <span class="caps">SQL</span> statement?</div>
|
179
|
-
<div class='faq-answer'><p>Placeholders in an <span class="caps">SQL</span> statement take any of the following formats:</p>
|
180
|
-
|
181
|
-
|
182
|
-
<ul>
|
183
|
-
<li><code>?</code></li>
|
184
|
-
<li><code>?_nnn_</code></li>
|
185
|
-
<li><code>:_word_</code></li>
|
186
|
-
</ul>
|
187
|
-
|
188
|
-
|
189
|
-
<p>Where <em>n_ is an integer, and _word</em> is an alpha-numeric identifier (or number). When the placeholder is associated with a number, that number identifies the index of the bind variable to replace it with. When it is an identifier, it identifies the name of the correponding bind variable. (In the instance of the first format-<del>a single question mark</del>-the placeholder is assigned a number one greater than the last index used, or 1 if it is the first.)</p>
|
190
|
-
|
191
|
-
|
192
|
-
<p>For example, here is a query using these placeholder formats:</p>
|
193
|
-
|
194
|
-
|
195
|
-
<pre>
|
196
|
-
select *
|
197
|
-
from table
|
198
|
-
where ( c = ?2 or c = ? )
|
199
|
-
and d = :name
|
200
|
-
and e = :1
|
201
|
-
</pre>
|
202
|
-
|
203
|
-
<p>This defines 5 different placeholders: 1, 2, 3, and “name”.</p>
|
204
|
-
|
205
|
-
|
206
|
-
<p>You replace these placeholders by <em>binding</em> them to values. This can be accomplished in a variety of ways.</p>
|
207
|
-
|
208
|
-
|
209
|
-
<p>The <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#execute</a>, and <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#execute2</a> methods all accept additional arguments following the <span class="caps">SQL</span> statement. These arguments are assumed to be bind parameters, and they are bound (positionally) to their corresponding placeholders:</p>
|
210
|
-
|
211
|
-
|
212
|
-
<pre>
|
213
|
-
db.execute( "select * from table where a = ? and b = ?",
|
214
|
-
"hello",
|
215
|
-
"world" )
|
216
|
-
</pre>
|
217
|
-
|
218
|
-
<p>The above would replace the first question mark with ‘hello’ and the second with ‘world’. If the placeholders have an explicit index given, they will be replaced with the bind parameter at that index (1-based).</p>
|
219
|
-
|
220
|
-
|
221
|
-
<p>If a Hash is given as a bind parameter, then its key/value pairs are bound to the placeholders. This is how you bind by name:</p>
|
222
|
-
|
223
|
-
|
224
|
-
<pre>
|
225
|
-
db.execute( "select * from table where a = :name and b = :value",
|
226
|
-
"name" => "bob",
|
227
|
-
"value" => "priceless" )
|
228
|
-
</pre>
|
229
|
-
|
230
|
-
<p>You can also bind explicitly using the <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Statement.html'>Statement</a> object itself. Just pass additional parameters to the <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Statement.html'>Statement#execute</a> statement:</p>
|
231
|
-
|
232
|
-
|
233
|
-
<pre>
|
234
|
-
db.prepare( "select * from table where a = :name and b = ?" ) do |stmt|
|
235
|
-
stmt.execute "value", "name" => "bob"
|
236
|
-
end
|
237
|
-
</pre>
|
238
|
-
|
239
|
-
<p>Or do a <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#prepare</a> to get the <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Statement.html'>Statement</a>, and then use either <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Statement.html'>Statement#bind_param</a> or <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Statement.html'>Statement#bind_params</a>:</p>
|
240
|
-
|
241
|
-
|
242
|
-
<pre>
|
243
|
-
stmt = db.prepare( "select * from table where a = :name and b = ?" )
|
244
|
-
|
245
|
-
stmt.bind_param( "name", "bob" )
|
246
|
-
stmt.bind_param( 1, "value" )
|
247
|
-
|
248
|
-
# or
|
249
|
-
|
250
|
-
stmt.bind_params( "value", "name" => "bob" )
|
251
|
-
</pre></div>
|
252
|
-
<a name='26510'></a>
|
253
|
-
<div class='faq-title'>How do I discover metadata about a query?</div>
|
254
|
-
<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>
|
255
|
-
|
256
|
-
|
257
|
-
<p>The first way is to ask the row object itself. Each row will have a property “fields” that returns an array of the column names. The row will also have a property “types” that returns an array of the column types:</p>
|
258
|
-
|
259
|
-
|
260
|
-
<pre>
|
261
|
-
rows = db.execute( "select * from table" )
|
262
|
-
p rows[0].fields
|
263
|
-
p rows[0].types
|
264
|
-
</pre>
|
265
|
-
|
266
|
-
<p>Obviously, this approach requires you to execute a statement that actually returns data. If you don’t know if the statement will return any rows, but you still need the metadata, you can use <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#query</a> and ask the <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/ResultSet.html'>ResultSet</a> object itself:</p>
|
267
|
-
|
268
|
-
|
269
|
-
<pre>
|
270
|
-
db.query( "select * from table" ) do |result|
|
271
|
-
p result.columns
|
272
|
-
p result.types
|
273
|
-
...
|
274
|
-
end
|
275
|
-
</pre>
|
276
|
-
|
277
|
-
<p>Lastly, you can use <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#prepare</a> and ask the <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Statement.html'>Statement</a> object what the metadata are:</p>
|
278
|
-
|
279
|
-
|
280
|
-
<pre>
|
281
|
-
stmt = db.prepare( "select * from table" )
|
282
|
-
p stmt.columns
|
283
|
-
p stmt.types
|
284
|
-
</pre></div>
|
285
|
-
<a name='26320'></a>
|
286
|
-
<div class='faq-title'>I’d like the rows to be indexible by column name.</div>
|
287
|
-
<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>
|
288
|
-
|
289
|
-
|
290
|
-
<p>The first way to do this is to set the <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database</a> property “results_as_hash” to true. If you do this, then all rows will be returned as Hash objects, with the column names as the keys. (In this case, the “fields” property is unavailable on the row, although the “types” property remains.)</p>
|
291
|
-
|
292
|
-
|
293
|
-
<pre>
|
294
|
-
db.results_as_hash = true
|
295
|
-
db.execute( "select * from table" ) do |row|
|
296
|
-
p row['column1']
|
297
|
-
p row['column2']
|
298
|
-
end
|
299
|
-
</pre>
|
300
|
-
|
301
|
-
<p>The other way is to use Ara Howard’s <a href="http://rubyforge.org/projects/arrayfields">ArrayFields</a> module. Just require “arrayfields”, and all of your rows will be indexable by column name, even though they are still arrays!</p>
|
302
|
-
|
303
|
-
|
304
|
-
<pre>
|
305
|
-
require 'arrayfields'
|
306
|
-
|
307
|
-
...
|
308
|
-
db.execute( "select * from table" ) do |row|
|
309
|
-
p row[0] == row['column1']
|
310
|
-
p row[1] == row['column2']
|
311
|
-
end
|
312
|
-
</pre></div>
|
313
|
-
<a name='26050'></a>
|
314
|
-
<div class='faq-title'>I’d like the values from a query to be the correct types, instead of String.</div>
|
315
|
-
<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>
|
316
|
-
|
317
|
-
|
318
|
-
<pre>
|
319
|
-
db.type_translation = true
|
320
|
-
db.execute( "select * from table" ) do |row|
|
321
|
-
p row
|
322
|
-
end
|
323
|
-
</pre>
|
324
|
-
|
325
|
-
<p>By doing this, each return value for each row will be translated to its correct type, based on its declared column type.</p>
|
326
|
-
|
327
|
-
|
328
|
-
<p>You can even declare your own translation routines, if (for example) you are using an <span class="caps">SQL</span> type that is not handled by default:</p>
|
329
|
-
|
330
|
-
|
331
|
-
<pre>
|
332
|
-
# assume "objects" table has the following schema:
|
333
|
-
# create table objects (
|
334
|
-
# name varchar2(20),
|
335
|
-
# thing object
|
336
|
-
# )
|
337
|
-
|
338
|
-
db.type_translation = true
|
339
|
-
db.translator.add_translator( "object" ) do |type, value|
|
340
|
-
db.decode( value )
|
341
|
-
end
|
342
|
-
|
343
|
-
h = { :one=>:two, "three"=>"four", 5=>6 }
|
344
|
-
dump = db.encode( h )
|
345
|
-
|
346
|
-
db.execute( "insert into objects values ( ?, ? )", "bob", dump )
|
347
|
-
|
348
|
-
obj = db.get_first_value( "select thing from objects where name='bob'" )
|
349
|
-
p obj == h
|
350
|
-
</pre></div>
|
351
|
-
<a name='25850'></a>
|
352
|
-
<div class='faq-title'>How do insert binary data into the database?</div>
|
353
|
-
<div class='faq-answer'><p>Use blobs. Blobs are new features of SQLite3. You have to use bind variables to make it work:</p>
|
354
|
-
|
355
|
-
|
356
|
-
<pre>
|
357
|
-
db.execute( "insert into foo ( ?, ? )",
|
358
|
-
SQLite3::Blob.new( "\0\1\2\3\4\5" ),
|
359
|
-
SQLite3::Blob.new( "a\0b\0c\0d ) )
|
360
|
-
</pre>
|
361
|
-
|
362
|
-
<p>The blob values must be indicated explicitly by binding each parameter to a value of type SQLite3::Blob.</p></div>
|
363
|
-
<a name='25740'></a>
|
364
|
-
<div class='faq-title'>How do I do a <span class="caps">DDL</span> (insert, update, delete) statement?</div>
|
365
|
-
<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>
|
366
|
-
|
367
|
-
|
368
|
-
<pre>
|
369
|
-
db.execute( "insert into table values ( ?, ? )", *bind_vars )
|
370
|
-
</pre></div>
|
371
|
-
<a name='23610'></a>
|
372
|
-
<div class='faq-title'>How do I execute multiple statements in a single string?</div>
|
373
|
-
<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>
|
374
|
-
|
375
|
-
|
376
|
-
<p>Instead, use <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#execute_batch</a>:</p>
|
377
|
-
|
378
|
-
|
379
|
-
<pre>
|
380
|
-
sql = <<SQL
|
381
|
-
create table the_table (
|
382
|
-
a varchar2(30),
|
383
|
-
b varchar2(30)
|
384
|
-
);
|
385
|
-
|
386
|
-
insert into the_table values ( 'one', 'two' );
|
387
|
-
insert into the_table values ( 'three', 'four' );
|
388
|
-
insert into the_table values ( 'five', 'six' );
|
389
|
-
SQL
|
390
|
-
|
391
|
-
db.execute_batch( sql )
|
392
|
-
</pre>
|
393
|
-
|
394
|
-
<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>
|
395
|
-
<a name='22110'></a>
|
396
|
-
<div class='faq-title'>How do I begin/end a transaction?</div>
|
397
|
-
<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>
|
398
|
-
|
399
|
-
|
400
|
-
<pre> database.transaction do |db| db.execute( "insert into table values ( 'a', 'b', 'c' )" ) ... end </pre>
|
401
|
-
|
402
|
-
<p>Alternatively, if you don’t give a block to <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#transaction</a>, the transaction remains open until you 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>.</p>
|
403
|
-
|
404
|
-
|
405
|
-
<pre> db.transaction db.execute( "insert into table values ( 'a', 'b', 'c' )" ) db.commit </pre>
|
406
|
-
|
407
|
-
<p>Note that SQLite does not allow nested transactions, so you’ll get errors if you try to open a new transaction while one is already active. Use <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#transaction_active</a>? to determine whether a transaction is active or not.</p></div>
|
408
|
-
</body></html>
|
data/ext/sqlite3_api/Makefile
DELETED
@@ -1,143 +0,0 @@
|
|
1
|
-
|
2
|
-
SHELL = /bin/sh
|
3
|
-
|
4
|
-
#### Start of system configuration section. ####
|
5
|
-
|
6
|
-
srcdir = .
|
7
|
-
topdir = /opt/local/lib/ruby/1.8/i686-darwin8.5.2
|
8
|
-
hdrdir = $(topdir)
|
9
|
-
VPATH = $(srcdir):$(topdir):$(hdrdir)
|
10
|
-
prefix = $(DESTDIR)/opt/local
|
11
|
-
exec_prefix = $(DESTDIR)/opt/local
|
12
|
-
sitedir = $(prefix)/lib/ruby/site_ruby
|
13
|
-
rubylibdir = $(libdir)/ruby/$(ruby_version)
|
14
|
-
archdir = $(rubylibdir)/$(arch)
|
15
|
-
sbindir = $(exec_prefix)/sbin
|
16
|
-
vendordir = $(prefix)/lib/ruby/vendor_ruby
|
17
|
-
datadir = $(prefix)/share
|
18
|
-
includedir = $(prefix)/include
|
19
|
-
infodir = $(prefix)/info
|
20
|
-
sysconfdir = $(prefix)/etc
|
21
|
-
mandir = $(DESTDIR)/opt/local/share/man
|
22
|
-
libdir = $(DESTDIR)/opt/local/lib
|
23
|
-
sharedstatedir = $(prefix)/com
|
24
|
-
oldincludedir = $(DESTDIR)/usr/include
|
25
|
-
sitearchdir = $(sitelibdir)/$(sitearch)
|
26
|
-
vendorarchdir = $(vendorlibdir)/$(vendorarch)
|
27
|
-
bindir = $(exec_prefix)/bin
|
28
|
-
localstatedir = $(prefix)/var
|
29
|
-
vendorlibdir = $(vendordir)/$(ruby_version)
|
30
|
-
sitelibdir = $(sitedir)/$(ruby_version)
|
31
|
-
libexecdir = $(exec_prefix)/libexec
|
32
|
-
|
33
|
-
CC = gcc
|
34
|
-
LIBRUBY = $(LIBRUBY_SO)
|
35
|
-
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
36
|
-
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
|
37
|
-
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
|
38
|
-
|
39
|
-
CFLAGS = -fno-common -O -pipe -I/opt/local/include -fno-common -pipe -fno-common
|
40
|
-
CPPFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir) -DHAVE_SQLITE3_H -I/usr/local/include -O -pipe -I/opt/local/include
|
41
|
-
CXXFLAGS = $(CFLAGS)
|
42
|
-
DLDFLAGS = -L/opt/local/lib
|
43
|
-
LDSHARED = cc -dynamic -bundle -undefined suppress -flat_namespace
|
44
|
-
AR = ar
|
45
|
-
EXEEXT =
|
46
|
-
|
47
|
-
RUBY_INSTALL_NAME = ruby
|
48
|
-
RUBY_SO_NAME = ruby
|
49
|
-
arch = i686-darwin8.5.2
|
50
|
-
sitearch = i686-darwin8.5.2
|
51
|
-
vendorarch = i686-darwin8.5.2
|
52
|
-
ruby_version = 1.8
|
53
|
-
ruby = /opt/local/bin/ruby
|
54
|
-
RUBY = $(ruby)
|
55
|
-
RM = rm -f
|
56
|
-
MAKEDIRS = mkdir -p
|
57
|
-
INSTALL = /usr/bin/install -c
|
58
|
-
INSTALL_PROG = $(INSTALL) -m 0755
|
59
|
-
INSTALL_DATA = $(INSTALL) -m 644
|
60
|
-
COPY = cp
|
61
|
-
|
62
|
-
#### End of system configuration section. ####
|
63
|
-
|
64
|
-
preload =
|
65
|
-
|
66
|
-
libpath = /usr/local/lib $(libdir)
|
67
|
-
LIBPATH = -L"/usr/local/lib" -L"$(libdir)"
|
68
|
-
DEFFILE =
|
69
|
-
|
70
|
-
CLEANFILES =
|
71
|
-
DISTCLEANFILES =
|
72
|
-
|
73
|
-
extout =
|
74
|
-
extout_prefix =
|
75
|
-
target_prefix =
|
76
|
-
LOCAL_LIBS =
|
77
|
-
LIBS = $(LIBRUBYARG_SHARED) -lsqlite3 -lpthread -ldl -lobjc
|
78
|
-
SRCS = sqlite3_api_wrap.c
|
79
|
-
OBJS = sqlite3_api_wrap.o
|
80
|
-
TARGET = sqlite3_api
|
81
|
-
DLLIB = $(TARGET).bundle
|
82
|
-
STATIC_LIB =
|
83
|
-
|
84
|
-
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
85
|
-
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
86
|
-
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
87
|
-
|
88
|
-
TARGET_SO = $(DLLIB)
|
89
|
-
CLEANLIBS = $(TARGET).bundle $(TARGET).il? $(TARGET).tds $(TARGET).map
|
90
|
-
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
|
91
|
-
|
92
|
-
all: $(DLLIB)
|
93
|
-
static: $(STATIC_LIB)
|
94
|
-
|
95
|
-
clean:
|
96
|
-
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
97
|
-
|
98
|
-
distclean: clean
|
99
|
-
@-$(RM) Makefile extconf.h conftest.* mkmf.log
|
100
|
-
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
101
|
-
|
102
|
-
realclean: distclean
|
103
|
-
install: install-so install-rb
|
104
|
-
|
105
|
-
install-so: $(RUBYARCHDIR)
|
106
|
-
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
107
|
-
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
108
|
-
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
109
|
-
install-rb: pre-install-rb install-rb-default
|
110
|
-
install-rb-default: pre-install-rb-default
|
111
|
-
pre-install-rb: Makefile
|
112
|
-
pre-install-rb-default: Makefile
|
113
|
-
$(RUBYARCHDIR):
|
114
|
-
$(MAKEDIRS) $@
|
115
|
-
|
116
|
-
site-install: site-install-so site-install-rb
|
117
|
-
site-install-so: install-so
|
118
|
-
site-install-rb: install-rb
|
119
|
-
|
120
|
-
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
|
121
|
-
|
122
|
-
.cc.o:
|
123
|
-
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<
|
124
|
-
|
125
|
-
.cxx.o:
|
126
|
-
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<
|
127
|
-
|
128
|
-
.cpp.o:
|
129
|
-
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<
|
130
|
-
|
131
|
-
.C.o:
|
132
|
-
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<
|
133
|
-
|
134
|
-
.c.o:
|
135
|
-
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
|
136
|
-
|
137
|
-
$(DLLIB): $(OBJS)
|
138
|
-
@-$(RM) $@
|
139
|
-
$(LDSHARED) $(DLDFLAGS) $(LIBPATH) -o $@ $(OBJS) $(LOCAL_LIBS) $(LIBS)
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
$(OBJS): ruby.h defines.h
|