sqlite “row value misused” error

亡梦爱人 提交于 2020-05-26 10:23:12

问题


I'm getting an error from an sqlite3 query for which I can't find any reference material. Googling the string takes me deep in the sqlite code itself, and that's so opaque I can't make heads or tails of it.

The table schema:

CREATE TABLE quote (
    seqnum INTEGER,
    session STRING,
    timestamp_sip INTEGER,
    timestamp_1 INTEGER,
    market_center STRING,
    symbol STRING,
    bid_price INTEGER,
    bid_lots INTEGER,
    offer_price INTEGER,
    offer_lots INTEGER,
    flags INTEGER,
    PRIMARY KEY (symbol, seqnum) );

The query:

select (seqnum, session, timestamp_sip, timestamp_1, market_center, symbol)
    from quote
    where symbol = 'QQQ';

The error:

Error: row value misused

I have no idea how to proceed here. There is plenty of data in the table that would match the query:

sqlite> select count(*) from quote where symbol = 'QQQ';
2675931

Can anyone offer any guidance here? Sqlite version is 3.16.2.


回答1:


Nevermind. Those parentheses around the select columns (left over from a copy/paste) are the problem. Poor error message, maybe. But my fault.




回答2:


I had a similar when working with a Rails 5.2 Application.

For my case I was trying to write a search query for a model in application:

def self.search(params)
  applications = all.order('created_at DESC') # for not existing params args
  applications = applications.where("cast(id as text) like ?, email like ?, first_name like ?, last_name like ?, appref like ?", "#{params[:search]}", "%#{params[:search]}%", "#{params[:search]}", "#{params[:search]}", "#{params[:search]}",) if params[:search]
  applications
end

The issue was that I was using a comma (,) to separate the search parameters, I simply corrected by using an OR instead:

def self.search(params)
  applications = all.order('created_at DESC') # for not existing params args
  applications = applications.where("cast(id as text) like ? OR email like ? OR first_name like ? OR last_name like ? OR appref like ?", "#{params[:search]}", "%#{params[:search]}%", "#{params[:search]}", "#{params[:search]}", "#{params[:search]}",) if params[:search]
  applications
end

That's all.

I hope this helps



来源:https://stackoverflow.com/questions/42123011/sqlite-row-value-misused-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!