lib/dreaming_god/session.rb in dreaming_god-0.1.2 vs lib/dreaming_god/session.rb in dreaming_god-0.1.3
- old
+ new
@@ -102,20 +102,20 @@
when 'person type'
column_a = 'person_type'
when 'place type'
column_a = 'place_type'
else
- column_a = (column_a == 'all' ? '*' : "'#{column_a}'")
+ column_a = (column_a == 'all' ? '*' : "#{column_a}")
end
table_name = @intent.slots['table']['value'] #people
column_b = @intent.slots['columnb']['value'] #name
compare_value = @intent.slots['comparevalue']['value'] #bob
- sql_string = "SELECT #{column_a.capitalize} FROM db_#{table_name} WHERE #{column_b} = '#{compare_value}'"
+ sql_string = "SELECT #{column_a} FROM db_#{table_name} WHERE #{column_b} = '#{compare_value}'"
result = "Db#{(table_name.capitalize.singularize)}".constantize.find_by_sql(sql_string)
names = ""
result.each do |r|
- names << "#{r.send(column_b)}, "
+ names << "#{r.send(column_a)}, "
end
names = "#{table_name} table is empty" if names.length == 0
card = response_card 'Dreaming God'
ssml_response(speak("I have found the following, #{names}"), card, true)
when 'update_row'
@@ -131,16 +131,16 @@
when 'person type'
column_a = 'person_type'
when 'place type'
column_a = 'place_type'
else
- column_a = (column_a == 'all' ? '*' : "'#{column_a}'")
+ column_a = (column_a == 'all' ? '*' : "#{column_a}")
end
sql_string = "UPDATE db_#{table_name} SET #{column_a} = '#{value_a}' WHERE #{column_b} = '#{compare_value}'"
result = "Db#{(table_name.capitalize.singularize)}".constantize.find_by_sql(sql_string)
- res = "I have updated the database where #{column_b} is equal to #{compare_value}"
+ res = "I have updated the database where #{column_b} is equal to #{compare_value} with #{column_a} set to #{value_a}"
card = response_card res
ssml_response(speak(res), card, true)
when 'destroy_row'
table_name = @intent.slots['table']['value'] #people
column = @intent.slots['column']['value'] #label
@@ -152,10 +152,10 @@
when 'person type'
column = 'person_type'
when 'place type'
column = 'place_type'
else
- column = (column == 'all' ? '*' : "'#{column}'")
+ column = (column == 'all' ? '*' : "#{column}")
end
sql_string = "DELETE FROM db_#{table_name} where #{column} = '#{compare_value}'"
"Db#{(table_name.capitalize.singularize)}".constantize.find_by_sql(sql_string)
res = "I have destroyed rows from the database where #{column} is equal to #{compare_value}"