sqlite-ruby 2.2.2-mswin32 → 2.2.3-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/doc/faq/faq.html +30 -30
- data/doc/faq/faq.rb +2 -2
- data/doc/faq/faq.yml +2 -2
- data/ext/extconf.rb +1 -1
- data/lib/sqlite/version.rb +1 -1
- data/lib/sqlite_api.so +0 -0
- data/test/sql/fixtures.sql +58 -0
- metadata +7 -4
data/README
CHANGED
@@ -16,7 +16,7 @@ Simply do the following, after installing SQLite:
|
|
16
16
|
Alternatively, you can download and install the RubyGem package for
|
17
17
|
SQLite/Ruby (you must have RubyGems and SQLite installed, first):
|
18
18
|
|
19
|
-
gem --remote
|
19
|
+
gem install --remote sqlite-ruby
|
20
20
|
|
21
21
|
|
22
22
|
== Usage
|
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='#538671166'>I just want an array of the rows…</a></li>
|
66
|
+
<li><a href='#538671126'>I’d like to use a block to iterate through the rows…</a></li>
|
67
|
+
<li><a href='#538671086'>I need to get the column names as well as the rows…</a></li>
|
68
|
+
<li><a href='#538671046'>I need the result set object itself…</a></li>
|
69
|
+
<li><a href='#538671006'>I just want the first row of the result set…</a></li>
|
70
|
+
<li><a href='#538670966'>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='#538670896'>How do I prepare a statement for repeated execution?</a></li>
|
74
|
+
<li><a href='#538670856'>How do I use placeholders in an <span class="caps">SQL</span> statement?</a></li>
|
75
|
+
<li><a href='#538670816'>How do I discover metadata about a query?</a></li>
|
76
|
+
<li><a href='#538670776'>I’d like the rows to be indexible by column name.</a></li>
|
77
|
+
<li><a href='#538670736'>I’d like the values from a query to be the correct types, instead of String.</a></li>
|
78
|
+
<li><a href='#538670696'>How do I do a <span class="caps">DDL </span>(insert, update, delete) statement?</a></li>
|
79
|
+
<li><a href='#538670656'>How do I execute multiple statements in a single string?</a></li>
|
80
|
+
<li><a href='#538670616'>How do I begin/end a transaction?</a></li>
|
81
81
|
</ul>
|
82
82
|
</div>
|
83
|
-
<a name='
|
83
|
+
<a name='538671166'></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
|
|
@@ -91,7 +91,7 @@
|
|
91
91
|
db = SQLite::<a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database</a>.new( "test.db" )
|
92
92
|
rows = db.execute( "select * from test" )
|
93
93
|
</pre></div>
|
94
|
-
<a name='
|
94
|
+
<a name='538671126'></a>
|
95
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
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
97
|
|
@@ -104,7 +104,7 @@
|
|
104
104
|
...
|
105
105
|
end
|
106
106
|
</pre></div>
|
107
|
-
<a name='
|
107
|
+
<a name='538671086'></a>
|
108
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
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
110
|
|
@@ -113,12 +113,12 @@
|
|
113
113
|
require 'sqlite'
|
114
114
|
|
115
115
|
db = SQLite::<a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database</a>.new( "test.db" )
|
116
|
-
columns, *rows = db.
|
116
|
+
columns, *rows = db.execute2( "select * from test" )
|
117
117
|
|
118
118
|
# or use a block:
|
119
119
|
|
120
120
|
columns = nil
|
121
|
-
db.
|
121
|
+
db.execute2( "select * from test" ) do |row|
|
122
122
|
if columns.nil?
|
123
123
|
columns = row
|
124
124
|
else
|
@@ -126,7 +126,7 @@
|
|
126
126
|
end
|
127
127
|
end
|
128
128
|
</pre></div>
|
129
|
-
<a name='
|
129
|
+
<a name='538671046'></a>
|
130
130
|
<div class='faq-title'>How do I do a database query? I need the result set object itself…</div>
|
131
131
|
<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>
|
132
132
|
|
@@ -170,7 +170,7 @@
|
|
170
170
|
end
|
171
171
|
</pre>
|
172
172
|
<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>
|
173
|
-
<a name='
|
173
|
+
<a name='538671006'></a>
|
174
174
|
<div class='faq-title'>How do I do a database query? I just want the first row of the result set…</div>
|
175
175
|
<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>
|
176
176
|
|
@@ -179,7 +179,7 @@
|
|
179
179
|
row = db.get_first_row( "select * from table" )
|
180
180
|
</pre>
|
181
181
|
<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>
|
182
|
-
<a name='
|
182
|
+
<a name='538670966'></a>
|
183
183
|
<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>
|
184
184
|
<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>
|
185
185
|
|
@@ -188,7 +188,7 @@
|
|
188
188
|
count = db.get_first_value( "select count(*) from table" )
|
189
189
|
</pre>
|
190
190
|
<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>
|
191
|
-
<a name='
|
191
|
+
<a name='538670896'></a>
|
192
192
|
<div class='faq-title'>How do I prepare a statement for repeated execution?</div>
|
193
193
|
<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>
|
194
194
|
|
@@ -203,7 +203,7 @@
|
|
203
203
|
end
|
204
204
|
</pre>
|
205
205
|
<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>
|
206
|
-
<a name='
|
206
|
+
<a name='538670856'></a>
|
207
207
|
<div class='faq-title'>How do I use placeholders in an <span class="caps">SQL</span> statement?</div>
|
208
208
|
<div class='faq-answer'><p>Placeholders in an <span class="caps">SQL</span> statement take any of the following formats:</p>
|
209
209
|
<ul>
|
@@ -261,7 +261,7 @@
|
|
261
261
|
|
262
262
|
stmt.bind_params( "value", "name" => "bob" )
|
263
263
|
</pre></div>
|
264
|
-
<a name='
|
264
|
+
<a name='538670816'></a>
|
265
265
|
<div class='faq-title'>How do I discover metadata about a query?</div>
|
266
266
|
<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>
|
267
267
|
|
@@ -291,7 +291,7 @@
|
|
291
291
|
p stmt.columns
|
292
292
|
p stmt.types
|
293
293
|
</pre></div>
|
294
|
-
<a name='
|
294
|
+
<a name='538670776'></a>
|
295
295
|
<div class='faq-title'>I’d like the rows to be indexible by column name.</div>
|
296
296
|
<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>
|
297
297
|
|
@@ -317,7 +317,7 @@
|
|
317
317
|
p row[1] == row['column2']
|
318
318
|
end
|
319
319
|
</pre></div>
|
320
|
-
<a name='
|
320
|
+
<a name='538670736'></a>
|
321
321
|
<div class='faq-title'>I’d like the values from a query to be the correct types, instead of String.</div>
|
322
322
|
<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>
|
323
323
|
|
@@ -353,7 +353,7 @@
|
|
353
353
|
obj = db.get_first_value( "select thing from objects where name='bob'" )
|
354
354
|
p obj == h
|
355
355
|
</pre></div>
|
356
|
-
<a name='
|
356
|
+
<a name='538670696'></a>
|
357
357
|
<div class='faq-title'>How do I do a <span class="caps">DDL </span>(insert, update, delete) statement?</div>
|
358
358
|
<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>
|
359
359
|
|
@@ -361,7 +361,7 @@
|
|
361
361
|
<pre>
|
362
362
|
db.execute( "insert into table values ( ?, ? )", *bind_vars )
|
363
363
|
</pre></div>
|
364
|
-
<a name='
|
364
|
+
<a name='538670656'></a>
|
365
365
|
<div class='faq-title'>How do I execute multiple statements in a single string?</div>
|
366
366
|
<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>
|
367
367
|
|
@@ -383,7 +383,7 @@
|
|
383
383
|
db.execute_batch( sql )
|
384
384
|
</pre>
|
385
385
|
<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>
|
386
|
-
<a name='
|
386
|
+
<a name='538670616'></a>
|
387
387
|
<div class='faq-title'>How do I begin/end a transaction?</div>
|
388
388
|
<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>
|
389
389
|
|
data/doc/faq/faq.rb
CHANGED
@@ -20,7 +20,7 @@ def process_faq_list_item( faq )
|
|
20
20
|
puts question_text
|
21
21
|
process_faq_list answer
|
22
22
|
else
|
23
|
-
print "<a href='##{question.
|
23
|
+
print "<a href='##{question.object_id}'>#{question_text}</a>"
|
24
24
|
end
|
25
25
|
|
26
26
|
puts "</li>"
|
@@ -43,7 +43,7 @@ def process_faq_description( faq, path )
|
|
43
43
|
title = RedCloth.new( path ).to_html.gsub( %r{</?p>}, "" )
|
44
44
|
answer = RedCloth.new( answer || "" )
|
45
45
|
|
46
|
-
puts "<a name='#{question.
|
46
|
+
puts "<a name='#{question.object_id}'></a>"
|
47
47
|
puts "<div class='faq-title'>#{title}</div>"
|
48
48
|
puts "<div class='faq-answer'>#{add_api_links(answer.to_html)}</div>"
|
49
49
|
end
|
data/doc/faq/faq.yml
CHANGED
@@ -40,12 +40,12 @@
|
|
40
40
|
require 'sqlite'
|
41
41
|
|
42
42
|
db = SQLite::Database.new( "test.db" )
|
43
|
-
columns, *rows = db.
|
43
|
+
columns, *rows = db.execute2( "select * from test" )
|
44
44
|
|
45
45
|
# or use a block:
|
46
46
|
|
47
47
|
columns = nil
|
48
|
-
db.
|
48
|
+
db.execute2( "select * from test" ) do |row|
|
49
49
|
if columns.nil?
|
50
50
|
columns = row
|
51
51
|
else
|
data/ext/extconf.rb
CHANGED
data/lib/sqlite/version.rb
CHANGED
data/lib/sqlite_api.so
CHANGED
Binary file
|
@@ -0,0 +1,58 @@
|
|
1
|
+
create table A
|
2
|
+
(
|
3
|
+
name VARCHAR(60),
|
4
|
+
age INTEGER,
|
5
|
+
birth DATE
|
6
|
+
);
|
7
|
+
|
8
|
+
create table B
|
9
|
+
(
|
10
|
+
id INTEGER PRIMARY KEY,
|
11
|
+
name VARCHAR(60)
|
12
|
+
);
|
13
|
+
|
14
|
+
create index B_idx on B ( name );
|
15
|
+
|
16
|
+
create table C
|
17
|
+
(
|
18
|
+
d1 DATE,
|
19
|
+
d2 DATETIME,
|
20
|
+
d3 TIME,
|
21
|
+
r1 DECIMAL,
|
22
|
+
r2 FLOAT,
|
23
|
+
r3 NUMERIC,
|
24
|
+
r4 DOUBLE,
|
25
|
+
r5 REAL,
|
26
|
+
r6 DEC,
|
27
|
+
r7 FIXED,
|
28
|
+
i1 INTEGER,
|
29
|
+
i2 SMALLINT,
|
30
|
+
i3 MEDIUMINT,
|
31
|
+
i4 INT,
|
32
|
+
i5 BIGINT,
|
33
|
+
b1 BIT,
|
34
|
+
b2 BOOL,
|
35
|
+
b3 BOOLEAN,
|
36
|
+
t1 TIMESTAMP,
|
37
|
+
t2 TINYINT(1),
|
38
|
+
t3 TINYINT(4),
|
39
|
+
s1 STRING,
|
40
|
+
s2 VARCHAR(15),
|
41
|
+
s3 CHAR(15),
|
42
|
+
s4 VARCHAR2(15),
|
43
|
+
m1 OBJECT,
|
44
|
+
n1 STRING,
|
45
|
+
n2 DATE,
|
46
|
+
n3 BOOLEAN
|
47
|
+
);
|
48
|
+
|
49
|
+
create table D
|
50
|
+
(
|
51
|
+
b_id INTEGER REFERENCES B ( id )
|
52
|
+
);
|
53
|
+
|
54
|
+
create table E
|
55
|
+
(
|
56
|
+
name VARCHAR(20) NOT NULL,
|
57
|
+
thing OBJECT
|
58
|
+
);
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.8.
|
2
|
+
rubygems_version: 0.8.4
|
3
3
|
specification_version: 1
|
4
4
|
name: sqlite-ruby
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 2.2.
|
7
|
-
date:
|
6
|
+
version: 2.2.3
|
7
|
+
date: 2005-01-30
|
8
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
|
-
author: Jamis Buck
|
12
11
|
email: jgb3@email.byu.edu
|
13
12
|
homepage: http://sqlite-ruby.rubyforge.org
|
14
13
|
rubyforge_project:
|
@@ -25,6 +24,8 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
25
24
|
version: 1.8.0
|
26
25
|
version:
|
27
26
|
platform: mswin32
|
27
|
+
authors:
|
28
|
+
- Jamis Buck
|
28
29
|
files:
|
29
30
|
- doc/faq
|
30
31
|
- doc/faq/faq.html
|
@@ -43,6 +44,7 @@ files:
|
|
43
44
|
- lib/sqlite/version.rb
|
44
45
|
- lib/sqlite/pragmas.rb
|
45
46
|
- test/db
|
47
|
+
- test/sql
|
46
48
|
- test/tc_parsed_statement.rb
|
47
49
|
- test/tc_api_core.rb
|
48
50
|
- test/tests.rb
|
@@ -52,6 +54,7 @@ files:
|
|
52
54
|
- test/tc_type_translation.rb
|
53
55
|
- test/tc_database.rb
|
54
56
|
- test/db/fixtures.sql
|
57
|
+
- test/sql/fixtures.sql
|
55
58
|
- README
|
56
59
|
test_files:
|
57
60
|
- test/tests.rb
|