Skip to content

Commit

Permalink
Added MySQL and SQLite3 support to Gemfile. MySQL tests pass. SQLite3…
Browse files Browse the repository at this point in the history
… test passage pending.
  • Loading branch information
Pistos committed Jul 14, 2011
1 parent a12cf59 commit 3a57322
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
m4dbi-sqlite
m4dbi-sqlite-journal
m4dbi.sqlite3
m4dbi2
m4dbi.db
m4dbi2.db
m4dbi2.sqlite3
*.gem
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ gem 'rake'
gem 'metaid'
gem 'rdbi', :git => 'git://github.com/RDBI/rdbi.git'
gem 'rdbi-driver-postgresql', :git => 'git://github.com/RDBI/rdbi-driver-postgresql.git', :require => 'rdbi/driver/postgresql'
gem 'rdbi-driver-mysql', :git => 'git://github.com/RDBI/rdbi-driver-mysql.git', :require => 'rdbi/driver/mysql'
gem 'rdbi-driver-sqlite3'

gem 'bacon'
19 changes: 19 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
GIT
remote: git://github.com/RDBI/rdbi-driver-mysql.git
revision: fe717ab0f8fab7f6dba1f78145a6cc7146c3b27d
specs:
rdbi-driver-mysql (0.9.2)
mysql (>= 2.8.1)
rdbi

GIT
remote: git://github.com/RDBI/rdbi-driver-postgresql.git
revision: 216a0040f2dcac077b2905b7b32e7b5e283e279d
Expand All @@ -24,8 +32,17 @@ GEM
epoxy (0.3.1)
metaid (1.0)
methlab (0.1.0)
mysql (2.8.1)
pg (0.9.0)
rake (0.8.7)
rdbi-driver-sqlite3 (0.9.1)
epoxy (>= 0.3.1)
methlab
rdbi
sqlite3-ruby (~> 1.3)
sqlite3 (1.3.3)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
typelib (0.1.0)

PLATFORMS
Expand All @@ -36,4 +53,6 @@ DEPENDENCIES
metaid
rake
rdbi!
rdbi-driver-mysql!
rdbi-driver-postgresql!
rdbi-driver-sqlite3
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ namespace :db do
namespace :mysql do
desc 'Create MySQL test database, with schema'
task :init do
exec "echo 'CREATE DATABASE m4dbi;' | mysql -u root -p; cat #{$m4dbi_project_root}/spec/test-schema-mysql.sql | mysql -u m4dbi -p m4dbi"
exec "echo 'CREATE DATABASE m4dbi; CREATE DATABASE m4dbi2' | mysql -u root -p; cat #{$m4dbi_project_root}/spec/test-schema-mysql.sql | mysql -u m4dbi -p m4dbi; cat #{$m4dbi_project_root}/spec/test-schema-mysql.sql | mysql -u m4dbi -p m4dbi2"
end

desc 'Drop and recreate MySQL test database, with schema'
task :reset do
exec "echo 'DROP DATABASE m4dbi; CREATE DATABASE m4dbi;' | mysql -u root -p; cat #{$m4dbi_project_root}/spec/test-schema-mysql.sql | mysql -u m4dbi -p m4dbi"
exec "echo 'DROP DATABASE m4dbi; CREATE DATABASE m4dbi; DROP DATABASE m4dbi2; CREATE DATABASE m4dbi2;' | mysql -u root -p; cat #{$m4dbi_project_root}/spec/test-schema-mysql.sql | mysql -u m4dbi -p m4dbi; cat #{$m4dbi_project_root}/spec/test-schema-mysql.sql | mysql -u m4dbi -p m4dbi2"
end
end
end
Expand Down
11 changes: 5 additions & 6 deletions lib/m4dbi/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,10 @@ def self.Model( table, options = Hash.new )
meta_def( "last_record".to_sym ) do |dbh_|
self.s1 "SELECT * FROM #{table} WHERE #{pk_str} = currval( '#{table}_#{pk_str}_seq' );"
end
# TODO: MySQL
# elsif defined?( DBI::DBD::Mysql::Database ) and DBI::DBD::Mysql::Database === h
# meta_def( "last_record".to_sym ) do |dbh_|
# self.s1 "SELECT * FROM #{table} WHERE #{pk_str} = LAST_INSERT_ID();"
# end
elsif defined?( RDBI::Driver::MySQL ) && RDBI::Driver::MySQL === h.driver
meta_def( "last_record".to_sym ) do |dbh_|
self.s1 "SELECT * FROM #{table} WHERE #{pk_str} = LAST_INSERT_ID();"
end
elsif defined?( RDBI::Driver::SQLite3 ) && RDBI::Driver::SQLite3 === h.driver
meta_def( "last_record".to_sym ) do |dbh_|
self.s1 "SELECT * FROM #{table} WHERE #{pk_str} = last_insert_rowid();"
Expand Down Expand Up @@ -474,4 +473,4 @@ def self.Model( table, options = Hash.new )
end
end

end
end
9 changes: 8 additions & 1 deletion spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ def connect_to_spec_database( database = ( ENV[ 'M4DBI_DATABASE' ] || 'm4dbi' )
else
raise "Unrecognized RDBI driver: #{driver}"
end
M4DBI.connect( driver, :database => database, :username => 'm4dbi' )

M4DBI.connect(
driver,
:database => database,
:username => 'm4dbi',
:hostname => 'localhost',
:password => 'm4dbi'
)
end

def reset_data( dbh = $dbh, datafile = "test-data.sql" )
Expand Down

0 comments on commit 3a57322

Please sign in to comment.