12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/sapphire/DataAbstractions/Database.rb', line 12
def query(sql)
recordset = WIN32OLE.new('ADODB.Recordset')
recordset.Open(sql, @connection, 0 , 1)
fields = []
recordset.Fields.each do |field|
fields << field.Name
end
begin
recordset.MoveFirst
data = recordset.GetRows
rescue
data = []
end
if(recordset.State != 0)
recordset.Close
end
data = data.transpose
records = []
data.each do |row|
y = 0
record = Hash.new
row.each do |column|
if(column != nil)
record.store fields[y].underscore.intern, column.to_s
else
record.store fields[y].underscore.intern, column
end
y += 1
end
records << record
end
records
end
|