Sha256: b194343d8d64c3ed06c1568c978dde3aff2f2c64c07448089e73debc72d7fe07

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

require_relative 'BaseAction.rb'

module PPCurses

  class InsertSQLDataAction < GetDataAction

    def initialize( actions, sql, db )
      super(actions)
      @sql = sql
      @db = db
    end

    def winHeight()
      8 + @actions.length
    end

    def afterActions()
      preparedSql = @sql
      dataArray = []

      @actions.each do |action|
        preparedSql = preparedSql.sub('?', action.data)
        dataArray.push(action.data)
      end

      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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ppcurses-0.0.20 lib/ppcurses/actions/InsertSQLDataAction.rb