<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -3,12 +3,22 @@ class Report &lt; ActiveRecord::Base
   validates_presence_of :code, :name, :kind
   validates_uniqueness_of :name
   
-  
   def run
     if kind == 'sql'
-      ActiveRecord::Base.connection.select_all(code).map(&amp;:values)
+      rows = ActiveRecord::Base.connection.select_all(code)
+      header(rows) + rows.map(&amp;:values)
     else
       eval(code)
     end
   end
+  
+  private
+  
+  def header(rows)
+    if rows.first
+      [rows.first.map{|k,v| k}]
+    else
+      []
+    end
+  end
 end</diff>
      <filename>lib/report.rb</filename>
    </modified>
    <modified>
      <diff>@@ -18,7 +18,13 @@ describe Report do
   
   it &quot;should run the sql and return an array of arrays&quot; do
     @report.kind = 'sql'
-    @report.code = 'SELECT 1, 2 UNION SELECT 2, 3'
-    @report.run.should == [['1', '2'], ['2', '3']]
+    @report.code = 'SELECT 1 AS col_1, 2 AS col_2 UNION SELECT 2 AS col_1, 3 AS col_3'
+    @report.run.should == [['col_1', 'col_2'], ['1', '2'], ['2', '3']]
+  end
+  
+  it &quot;should return an empty array if no results&quot; do
+    @report.kind = 'sql'
+    @report.code = 'SELECT 1 WHERE 0'
+    @report.run.should == []
   end
 end</diff>
      <filename>spec/report_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>40201b24606610377f61e45c90830fa7b98e5e7e</id>
    </parent>
  </parents>
  <author>
    <name>Alexander Lang</name>
    <email>alex@skywalker.local</email>
  </author>
  <url>http://github.com/langalex/dead_simple_reports/commit/e8861b75c47b2f0bb7792bbece62ebbc1e5ed2ea</url>
  <id>e8861b75c47b2f0bb7792bbece62ebbc1e5ed2ea</id>
  <committed-date>2008-07-07T10:26:07-07:00</committed-date>
  <authored-date>2008-07-07T10:26:07-07:00</authored-date>
  <message>now showing column names in first row in sql reports</message>
  <tree>5e999ac9f9df971e0775724f21f22053e22a9eb3</tree>
  <committer>
    <name>Alexander Lang</name>
    <email>alex@skywalker.local</email>
  </committer>
</commit>
