scraperwiki 2.0.5 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/scraperwiki.rb +27 -0
- metadata +1 -1
data/lib/scraperwiki.rb
CHANGED
@@ -204,4 +204,31 @@ module ScraperWiki
|
|
204
204
|
end
|
205
205
|
raise SqliteException.new(rerror)
|
206
206
|
end
|
207
|
+
|
208
|
+
# Allows for a simplified select statement
|
209
|
+
#
|
210
|
+
# === Parameters
|
211
|
+
#
|
212
|
+
# * _sqlquery_ = A valid select statement, without the select keyword
|
213
|
+
# * _data_ = Any data provided for ? replacements in the query
|
214
|
+
# * _verbose_ = A verbosity level
|
215
|
+
#
|
216
|
+
# === Returns
|
217
|
+
# A list of hashes containing the returned data
|
218
|
+
#
|
219
|
+
# === Example
|
220
|
+
# ScraperWiki::select('* from swdata')
|
221
|
+
#
|
222
|
+
def ScraperWiki.select(sqlquery, data=nil, verbose=1)
|
223
|
+
if data != nil && sqlquery.scan(/\?/).length != 0 && data.class != Array
|
224
|
+
data = [data]
|
225
|
+
end
|
226
|
+
result = ScraperWiki.sqliteexecute("select "+sqlquery, data, verbose)
|
227
|
+
res = [ ]
|
228
|
+
for d in result["data"]
|
229
|
+
#res.push(Hash[result["keys"].zip(d)]) # post-1.8.7
|
230
|
+
res.push(Hash[*result["keys"].zip(d).flatten]) # pre-1.8.7
|
231
|
+
end
|
232
|
+
return res
|
233
|
+
end
|
207
234
|
end
|