Permalink
Browse files

queries are now executed against mysql - not shown yet

  • Loading branch information...
1 parent 3568a72 commit 2d9acfef21a1199eaad38277b05917201f330c4a Oliver Searle-Barnes committed Mar 18, 2010
Binary file not shown.
@@ -1,3 +1,6 @@
+require 'dbi'
+require 'mysql'
+
class ReportsController < ApplicationController
before_filter :load_database, :only => [:index, :new, :create]
@@ -11,6 +14,11 @@ def index
def show
@report = Report.find(params[:id])
+ @database = @report.database
+ require 'ruby-debug'
+ debugger
+ @conn = DBI.connect("DBI:Mysql:#{@database.schema}:#{@database.hostname}", @database.username, @database.password)
+ @result = @conn.select_all(@report.query);
end
def new
View
Binary file not shown.
View
@@ -1,4 +1,4 @@
class Database < ActiveRecord::Base
- attr_accessible :name, :username, :password, :hostname
+ attr_accessible :name, :username, :password, :hostname, :schema
has_many :reports
end
@@ -5,6 +5,10 @@
<%= f.text_field :name %>
</p>
<p>
+ <%= f.label :schema %><br />
+ <%= f.text_field :schema %>
+ </p>
+ <p>
<%= f.label :username %><br />
<%= f.text_field :username %>
</p>
@@ -6,13 +6,15 @@
<th>Username</th>
<th>Password</th>
<th>Hostname</th>
+ <th>Schema</th>
</tr>
<% for database in @databases %>
<tr>
<td><%=h database.name %></td>
<td><%=h database.username %></td>
<td><%=h database.password %></td>
<td><%=h database.hostname %></td>
+ <td><%=h database.schema %></td>
<td><%= link_to "Show", database %></td>
<td><%= link_to "Edit", edit_database_path(database) %></td>
<td><%= link_to "Destroy", database, :confirm => 'Are you sure?', :method => :delete %></td>
Binary file not shown.
@@ -4,13 +4,11 @@
<tr>
<th>Name</th>
<th>Query</th>
- <th>Database</th>
</tr>
<% for report in @reports %>
<tr>
<td><%=h report.name %></td>
<td><%=h report.query %></td>
- <td><%=h report.database_id %></td>
<td><%= link_to "Show", report %></td>
<td><%= link_to "Edit", edit_report_path(report) %></td>
<td><%= link_to "Destroy", report, :confirm => 'Are you sure?', :method => :delete %></td>
@@ -0,0 +1,9 @@
+class AddSchemaToDatabase < ActiveRecord::Migration
+ def self.up
+ add_column :databases, :schema, :string
+ end
+
+ def self.down
+ remove_column :databases, :schema
+ end
+end
View
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20100318134224) do
+ActiveRecord::Schema.define(:version => 20100318144715) do
create_table "databases", :force => true do |t|
t.string "name"
@@ -18,6 +18,7 @@
t.string "hostname"
t.datetime "created_at"
t.datetime "updated_at"
+ t.string "schema"
end
create_table "reports", :force => true do |t|

0 comments on commit 2d9acfe

Please sign in to comment.