sqlite3-ruby 1.2.2 → 1.2.3

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/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='#3128110'>I just want an array of the rows&#8230;</a></li>
66
- <li><a href='#3127990'>I&#8217;d like to use a block to iterate through the rows&#8230;</a></li>
67
- <li><a href='#3127870'>I need to get the column names as well as the rows&#8230;</a></li>
68
- <li><a href='#3127750'>I just want the first row of the result set&#8230;</a></li>
69
- <li><a href='#3127650'>I just want the first value of the first row of the result set&#8230;</a></li>
65
+ <li><a href='#9144150'>I just want an array of the rows&#8230;</a></li>
66
+ <li><a href='#9144080'>I&#8217;d like to use a block to iterate through the rows&#8230;</a></li>
67
+ <li><a href='#9144010'>I need to get the column names as well as the rows&#8230;</a></li>
68
+ <li><a href='#9143940'>I just want the first row of the result set&#8230;</a></li>
69
+ <li><a href='#9143870'>I just want the first value of the first row of the result set&#8230;</a></li>
70
70
  </ul>
71
71
  </li>
72
- <li><a href='#3127470'>How do I prepare a statement for repeated execution?</a></li>
73
- <li><a href='#3127360'>How do I use placeholders in an <span class="caps">SQL</span> statement?</a></li>
74
- <li><a href='#3127240'>How do I discover metadata about a query?</a></li>
75
- <li><a href='#3127090'>I&#8217;d like the rows to be indexible by column name.</a></li>
76
- <li><a href='#3126930'>I&#8217;d like the values from a query to be the correct types, instead of String.</a></li>
77
- <li><a href='#3126780'>How do insert binary data into the database?</a></li>
78
- <li><a href='#3126610'>How do I do a <span class="caps">DDL</span> (insert, update, delete) statement?</a></li>
79
- <li><a href='#3126460'>How do I execute multiple statements in a single string?</a></li>
80
- <li><a href='#3126340'>How do I begin/end a transaction?</a></li>
72
+ <li><a href='#9143750'>How do I prepare a statement for repeated execution?</a></li>
73
+ <li><a href='#9143680'>How do I use placeholders in an <span class="caps">SQL</span> statement?</a></li>
74
+ <li><a href='#9143610'>How do I discover metadata about a query?</a></li>
75
+ <li><a href='#9143540'>I&#8217;d like the rows to be indexible by column name.</a></li>
76
+ <li><a href='#9143470'>I&#8217;d like the values from a query to be the correct types, instead of String.</a></li>
77
+ <li><a href='#9143400'>How do insert binary data into the database?</a></li>
78
+ <li><a href='#9143330'>How do I do a <span class="caps">DDL</span> (insert, update, delete) statement?</a></li>
79
+ <li><a href='#9143260'>How do I execute multiple statements in a single string?</a></li>
80
+ <li><a href='#9143190'>How do I begin/end a transaction?</a></li>
81
81
  </ul>
82
82
  </div>
83
- <a name='3128110'></a>
83
+ <a name='9144150'></a>
84
84
  <div class='faq-title'>How do I do a database query? I just want an array of the rows&#8230;</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&#8217;t give it a block, it will return an array of all the rows:</p>
86
86
 
@@ -91,7 +91,7 @@
91
91
  db = SQLite3::<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='3127990'></a>
94
+ <a name='9144080'></a>
95
95
  <div class='faq-title'>How do I do a database query? I&#8217;d like to use a block to iterate through the rows&#8230;</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='3127870'></a>
107
+ <a name='9144010'></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&#8230;</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&#8217;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
 
@@ -126,7 +126,7 @@
126
126
  end
127
127
  end
128
128
  </pre></div>
129
- <a name='3127750'></a>
129
+ <a name='9143940'></a>
130
130
  <div class='faq-title'>How do I do a database query? I just want the first row of the result set&#8230;</div>
131
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
132
 
@@ -136,7 +136,7 @@
136
136
  </pre>
137
137
 
138
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='3127650'></a>
139
+ <a name='9143870'></a>
140
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&#8230;</div>
141
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
142
 
@@ -146,7 +146,7 @@
146
146
  </pre>
147
147
 
148
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='3127470'></a>
149
+ <a name='9143750'></a>
150
150
  <div class='faq-title'>How do I prepare a statement for repeated execution?</div>
151
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
152
 
@@ -174,7 +174,7 @@
174
174
  </pre>
175
175
 
176
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='3127360'></a>
177
+ <a name='9143680'></a>
178
178
  <div class='faq-title'>How do I use placeholders in an <span class="caps">SQL</span> statement?</div>
179
179
  <div class='faq-answer'><p>Placeholders in an <span class="caps">SQL</span> statement take any of the following formats:</p>
180
180
 
@@ -249,7 +249,7 @@
249
249
 
250
250
  stmt.bind_params( "value", "name" =&gt; "bob" )
251
251
  </pre></div>
252
- <a name='3127240'></a>
252
+ <a name='9143610'></a>
253
253
  <div class='faq-title'>How do I discover metadata about a query?</div>
254
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
255
 
@@ -282,7 +282,7 @@
282
282
  p stmt.columns
283
283
  p stmt.types
284
284
  </pre></div>
285
- <a name='3127090'></a>
285
+ <a name='9143540'></a>
286
286
  <div class='faq-title'>I&#8217;d like the rows to be indexible by column name.</div>
287
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
288
 
@@ -310,7 +310,7 @@
310
310
  p row[1] == row['column2']
311
311
  end
312
312
  </pre></div>
313
- <a name='3126930'></a>
313
+ <a name='9143470'></a>
314
314
  <div class='faq-title'>I&#8217;d like the values from a query to be the correct types, instead of String.</div>
315
315
  <div class='faq-answer'><p>You can turn on &#8220;type translation&#8221; by setting <a href='http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html'>Database#type_translation</a> to true:</p>
316
316
 
@@ -348,7 +348,7 @@
348
348
  obj = db.get_first_value( "select thing from objects where name='bob'" )
349
349
  p obj == h
350
350
  </pre></div>
351
- <a name='3126780'></a>
351
+ <a name='9143400'></a>
352
352
  <div class='faq-title'>How do insert binary data into the database?</div>
353
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
354
 
@@ -360,7 +360,7 @@
360
360
  </pre>
361
361
 
362
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='3126610'></a>
363
+ <a name='9143330'></a>
364
364
  <div class='faq-title'>How do I do a <span class="caps">DDL</span> (insert, update, delete) statement?</div>
365
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
366
 
@@ -368,7 +368,7 @@
368
368
  <pre>
369
369
  db.execute( "insert into table values ( ?, ? )", *bind_vars )
370
370
  </pre></div>
371
- <a name='3126460'></a>
371
+ <a name='9143260'></a>
372
372
  <div class='faq-title'>How do I execute multiple statements in a single string?</div>
373
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&#8217;t use those methods to execute them all at once.</p>
374
374
 
@@ -392,7 +392,7 @@
392
392
  </pre>
393
393
 
394
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='3126340'></a>
395
+ <a name='9143190'></a>
396
396
  <div class='faq-title'>How do I begin/end a transaction?</div>
397
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&#8212;you&#8217;ll get errors when the block terminates!)</p>
398
398
 
@@ -4,6 +4,14 @@
4
4
  #include <sqlite3.h>
5
5
  #include "ruby.h"
6
6
 
7
+ #ifndef RSTRING_PTR
8
+ #define RSTRING_PTR(s) (RSTRING(s)->ptr)
9
+ #endif
10
+
11
+ #ifndef RSTRING_LEN
12
+ #define RSTRING_LEN(s) (RSTRING(s)->len)
13
+ #endif
14
+
7
15
  #define Init_API Init_sqlite3_api
8
16
 
9
17
  struct CallbackData {
@@ -1,7 +1,7 @@
1
- REM This is not guaranteed to work, ever. It's just a little helper
2
- REM script that I threw together to help me build the win32 version of
3
- REM the library. If someone with more win32-fu than I wants to make
4
- REM something more robust, please feel free! I'd love to include it.
5
- REM -- Jamis Buck
6
-
7
- cl /LD /Ie:\WinSDK\Include /Ic:\ruby\lib\ruby\1.8\i386-mswin32 /Ic:\ruby\sqlite3\src /Ic:\ruby\src\ruby-1.8.4_2006-04-14 sqlite3_api_wrap.c /link /LIBPATH:c:\ruby\sqlite3 /LIBPATH:e:\WinSDK\Lib /LIBPATH:c:\ruby\lib sqlite3.lib msvcrt-ruby18.lib
1
+ REM This is not guaranteed to work, ever. It's just a little helper
2
+ REM script that I threw together to help me build the win32 version of
3
+ REM the library. If someone with more win32-fu than I wants to make
4
+ REM something more robust, please feel free! I'd love to include it.
5
+ REM -- Jamis Buck
6
+
7
+ cl /LD /Ie:\WinSDK\Include /Ic:\ruby\lib\ruby\1.8\i386-mswin32 /Ic:\ruby\sqlite3 /Ic:\ruby\src\ruby-1.8.4_2006-04-14 sqlite3_api_wrap.c /link /LIBPATH:c:\ruby\sqlite3 /LIBPATH:e:\WinSDK\Lib /LIBPATH:c:\ruby\lib sqlite3.lib msvcrt-ruby18.lib
@@ -10,16 +10,25 @@ module SQLite3
10
10
  class ResultSet
11
11
  include Enumerable
12
12
 
13
- # A trivial module for adding a +types+ accessor to an object.
14
- module TypesContainer
13
+ # The class of which we return an object in case we want an Array as
14
+ # result. (ArrayFields is installed.)
15
+ class ArrayWithTypes < Array
15
16
  attr_accessor :types
16
17
  end
17
18
 
18
- # A trivial module for adding a +fields+ accessor to an object.
19
- module FieldsContainer
19
+ # The class of which we return an object in case we want an Array as
20
+ # result. (ArrayFields is not installed.)
21
+ class ArrayWithTypesAndFields < Array
22
+ attr_accessor :types
20
23
  attr_accessor :fields
21
24
  end
22
25
 
26
+ # The class of which we return an object in case we want a Hash as
27
+ # result.
28
+ class HashWithTypes < Hash
29
+ attr_accessor :types
30
+ end
31
+
23
32
  # Create a new ResultSet attached to the given database, using the
24
33
  # given sql text.
25
34
  def initialize( db, stmt )
@@ -112,15 +121,18 @@ module SQLite3
112
121
  end
113
122
 
114
123
  if @db.results_as_hash
115
- new_row = Hash[ *( @stmt.columns.zip( row ).flatten ) ]
124
+ new_row = HashWithTypes[ *( @stmt.columns.zip( row ).to_a.flatten ) ]
116
125
  row.each_with_index { |value,idx| new_row[idx] = value }
117
126
  row = new_row
118
127
  else
119
- row.extend FieldsContainer unless row.respond_to?(:fields)
128
+ if row.respond_to?(:fields)
129
+ row = ArrayWithTypes.new(row)
130
+ else
131
+ row = ArrayWithTypesAndFields.new(row)
132
+ end
120
133
  row.fields = @stmt.columns
121
134
  end
122
135
 
123
- row.extend TypesContainer
124
136
  row.types = @stmt.types
125
137
 
126
138
  return row
@@ -4,7 +4,7 @@ module SQLite3
4
4
 
5
5
  MAJOR = 1
6
6
  MINOR = 2
7
- TINY = 2
7
+ TINY = 3
8
8
 
9
9
  STRING = [ MAJOR, MINOR, TINY ].join( "." )
10
10
  #:beta-tag:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqlite3-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamis Buck
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-31 00:00:00 -06:00
12
+ date: 2008-08-26 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  requirements: []
85
85
 
86
86
  rubyforge_project:
87
- rubygems_version: 1.1.1
87
+ rubygems_version: 1.2.0
88
88
  signing_key:
89
89
  specification_version: 2
90
90
  summary: SQLite3/Ruby is a module to allow Ruby scripts to interface with a SQLite3 database.