简体   繁体   中英

no such column: COLIN (SQLite3::SQLException)

My code is giving me the no such column error on my update function. It's returning the right output but still giving an error. I'm just want the update function to modify the first name when ran. Any ideas why?

    
    class User 
        def self.create(user_info)
            DBConnection.execute(<<-SQL)
              INSERT INTO
                users (firstname, lastname, age, password, email)
              VALUES
                ('#{user_info[:firstname]}', '#{user_info[:lastname]}',
                '#{user_info[:age]}', '#{user_info[:password]}', '#{user_info[:email]}')
            SQL
            DBConnection.last_insert_row_id
          end
    
          def self.find(user_id)
            DBConnection.execute(<<-SQL, user_id)
                SELECT* FROM
                    USERS
                WHERE
                    id = ?
            SQL
            .first
          end  
    
          def self.update(user_id, attribute, value)
            DBConnection.execute(<<-SQL, user_id, attribute, value)
                UPDATE
                    users
                SET
                    #{attribute} = #{value}
                WHERE
                    id = #{user_id}
            SQL
          end 
           
    end    
    
    user1 = User.create(firstname: "Colin", lastname: "Doe", age: "25", password: "password", email: "bla")
    user2 = User.create(firstname: "Jane", lastname: "Doe", age: "25", password: "password", email: "bla")
    user3 = User.create(firstname: "Ted", lastname: "Doe", age: "25", password: "password", email: "bla")
    User.update(1, :firstname, 'COLIN')
    print User.find(1)``
    ```

Is it just this typo?

def self.create(user_info)
  DBConnection.execute(<<-SQL)

Should be:

def self.create(user_info)
  DBConnection.execute(<<-SQL,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM