Class: PPCurses::InsertSQLDataAction
- Inherits:
-
GetDataAction
- Object
- BaseAction
- GetDataAction
- PPCurses::InsertSQLDataAction
- Defined in:
- lib/ppcurses/actions/InsertSQLDataAction.rb
Instance Method Summary collapse
- #after_actions ⇒ Object
-
#initialize(actions, sql, db) ⇒ InsertSQLDataAction
constructor
A new instance of InsertSQLDataAction.
-
#prompt_to_change_data(user_display_sql, data_array) ⇒ Object
returns true if data was inserted.
- #win_height ⇒ Object
Methods inherited from GetDataAction
#before_actions, #create_window, #data, #execute, #print_error_line, #print_line, #print_success_line
Methods inherited from BaseAction
#create_window, #set_window, #show, #win_padding, #win_width, #x_padding
Constructor Details
#initialize(actions, sql, db) ⇒ InsertSQLDataAction
Returns a new instance of InsertSQLDataAction.
8 9 10 11 12 |
# File 'lib/ppcurses/actions/InsertSQLDataAction.rb', line 8 def initialize( actions, sql, db ) super(actions) @sql = sql @db = db end |
Instance Method Details
#after_actions ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ppcurses/actions/InsertSQLDataAction.rb', line 18 def after_actions prepared_sql = @sql data_array = [] @actions.each do |action| prepared_sql = prepared_sql.sub('?', action.data) data_array.push(action.data) end self.prompt_to_change_data(prepared_sql, data_array) end |
#prompt_to_change_data(user_display_sql, data_array) ⇒ Object
returns true if data was inserted
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ppcurses/actions/InsertSQLDataAction.rb', line 34 def prompt_to_change_data(user_display_sql, data_array) self.print_line(user_display_sql) proceed = GetBooleanAction.new('Proceed? ') proceed.set_parent_action(self) proceed.set_window(@win) proceed.execute did_insert = false if proceed.data == '1' self.print_line('') begin prep_statement = @db.prepare(@sql) prep_statement.bind_params(data_array) prep_statement.execute prep_statement.close did_insert = true self.print_success_line('Execution successful') rescue SQLite3::Exception => e self.print_error_line('Exception occurred') self.print_error_line(e.) ensure self.print_line('') self.print_line('< Press any key to continue > ') @win.getch end end did_insert end |
#win_height ⇒ Object
14 15 16 |
# File 'lib/ppcurses/actions/InsertSQLDataAction.rb', line 14 def win_height 8 + @actions.length end |