lib/ppcurses/actions/InsertSQLDataAction.rb in ppcurses-0.0.20 vs lib/ppcurses/actions/InsertSQLDataAction.rb in ppcurses-0.0.21
- old
+ new
@@ -1,61 +1,68 @@
require_relative 'BaseAction.rb'
+#noinspection RubyResolve
module PPCurses
class InsertSQLDataAction < GetDataAction
def initialize( actions, sql, db )
super(actions)
@sql = sql
@db = db
end
- def winHeight()
+ def win_height
8 + @actions.length
end
- def afterActions()
- preparedSql = @sql
- dataArray = []
+ def after_actions
+ prepared_sql = @sql
+ data_array = []
@actions.each do |action|
- preparedSql = preparedSql.sub('?', action.data)
- dataArray.push(action.data)
+ prepared_sql = prepared_sql.sub('?', action.data)
+ data_array.push(action.data)
end
- self.promptToChangeData(preparedSql, dataArray)
+ self.prompt_to_change_data(prepared_sql, data_array)
end
- def promptToChangeData(userDisplaySQL, dataArray)
- self.printLine(userDisplaySQL)
+ #
+ # returns true if data was inserted
+ #
+ def prompt_to_change_data(user_display_sql, data_array)
+ self.print_line(user_display_sql)
proceed = GetBooleanAction.new('Proceed? ')
- proceed.setParentAction(self)
- proceed.setWindow(@win)
+ proceed.set_parent_action(self)
+ proceed.set_window(@win)
proceed.execute()
- if proceed.data == '1' then
- self.printLine('')
+ did_insert = false
+
+ if proceed.data == '1'
+ self.print_line('')
begin
- prepStatement = @db.prepare(@sql)
- prepStatement.bind_params(dataArray)
- prepStatement.execute()
- prepStatement.close()
- self.printSuccessLine('Execution successful')
+ 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.printErrorLine('Exception occurred')
- self.printErrorLine(e.message)
+ self.print_error_line('Exception occurred')
+ self.print_error_line(e.message)
ensure
- self.printLine('')
- self.printLine('< Press any key to continue > ')
+ self.print_line('')
+ self.print_line('< Press any key to continue > ')
@win.getch()
end
end
-
+ did_insert
end
end
end