ruby - SQlite error: "no such table " -
i building simple bank program in ruby. have set mvc style. getting following error message.
/home/devil/.rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `initialize': no such table: managers (sqlite3::sqlexception) /home/devil/.rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `new' /home/devil/.rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `prepare' /home/devil/.rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:134:in `execute' /home/devil/desktop/rubybank-manager_model/model.rb:19:in `initialize_database' /home/devil/desktop/rubybank-manager_model/model.rb:7:in `initialize' controller.rb:8:in `new' controller.rb:8:in `initialize' controller.rb:124:in `new' controller.rb:124:in `<main>'
earlier in day program working fine. changed local variable's name in controller method , started throw me above error.
things have tried have failed:
update sqlite gem files latest version.
revert previous commits github worked , tried run program.
revert local variable method in question it's former functioning name.
googling heart's content.
see github program code: https://github.com/erikasland/rubybank/tree/add_manager
it looks problem created in this commit, on line 19 of model.rb
. you're attempting check if table exists selecting it:
managers_exist = db.execute("select * managers").length > 0
this can solved querying against schema, rather table - you've done accounts
table:
accounts_table_exists = db.execute("select 1 sqlite_master type='table' , name= ?", "accounts").length > 0
notice you're selecting sqlite_master
, not accounts
. want this:
managers_exist= db.execute("select 1 sqlite_master type='table' , name= ?", "managers").length > 0
however, seems me create table if not exists
approach might solution you're looking for.
Comments
Post a Comment