lib/ppcurses/actions/InsertSQLDataAction.rb in ppcurses-0.0.18 vs lib/ppcurses/actions/InsertSQLDataAction.rb in ppcurses-0.0.19

- old
+ new

@@ -9,19 +9,53 @@ @sql = sql @db = db end def winHeight() - return 8 + @actions.length + 8 + @actions.length end def afterActions() preparedSql = @sql + dataArray = [] + @actions.each do |action| - preparedSql = preparedSql.sub("%s", action.data) + preparedSql = preparedSql.sub('?', action.data) + dataArray.push(action.data) end - self.promptToChangeData(preparedSql) + self.promptToChangeData(preparedSql, dataArray) + + end + + def promptToChangeData(userDisplaySQL, dataArray) + self.printLine(userDisplaySQL) + + proceed = GetBooleanAction.new('Proceed? ') + proceed.setParentAction(self) + proceed.setWindow(@win) + proceed.execute() + + if proceed.data == '1' then + self.printLine('') + begin + prepStatement = db.prepare(sql) + prepStatement.bind_params(dataArray) + prepStatement.execute() + prepStatement.close() + self.printSuccessLine('Execution successful') + rescue SQLite3::Exception => e + self.printErrorLine('Exception occurred') + self.printErrorLine(e.message) + ensure + self.printLine('') + self.printLine('< Press any key to continue > ') + @win.getch() + end + + end + + end end end