vendredi 13 avril 2018

SQLITE -hashes accessing values

Background: I am using SQLite to access data for making databases(testing only). I want to filter tweets (requests for cancellations via twitter), and I am calling values from the all_tweets table.

Main Problem: I am confused why I am getting the following when I am running the main program:

  1. I am getting two sets of values for the same columns, one with the column name and the other with numbers. See the image below1

  2. Also, I am getting {"COUNT() =>0", 0=>0} which is puzzling because it should return true when the count= 0. I have no idea why I am not getting an integer like 0 or 1 instead of "COUNT()=>0". When the count is 0, the boolean value should be true , I am getting false.

I have a feeling that this is a rookie mistake. Any help will be appreciated.

      @filter_potential_cancellations = %{SELECT * FROM all_tweets WHERE tweet LIKE '%#cancellation%'}

          # checking that the user is registered(not banned too) and the order is not completed/cancelled before
          #@filter_potential_cancellations_2 = %{SELECT * FROM all_orders_info WHERE Is_customer=1 AND order_status<2 AND order_status>=0}

          @filter_potential_cancellations_results = @all_tweetsDB.execute @filter_potential_cancellations ;



          @filter_potential_cancellations_results.each do |potential_cancellations|

              puts potential_cancellations
              # avoids repitition of the same tweet in the cancellation table
          count_cancellations = @all_tweetsDB.execute('SELECT COUNT(*) FROM all_potential_cancellations WHERE id = ? ', [potential_cancellations['id']])
          @unique_cancellation_tweet = (count_cancellations == 0);



    #testing

        puts count_cancellations ;
        puts @unique_cancellation_tweet ;
            #end of test
            #some extra code 
  end

Aucun commentaire:

Enregistrer un commentaire