SQLite error: 'could not convert text value to numeric value.'

别说谁变了你拦得住时间么 提交于 2019-12-24 04:15:08

问题


I've found a work-around, but I am completely perplexed by an issue I ran into with Adobe Air and SQLite. An UPDATE query that I believe worked correctly earlier in the development process suddenly started failing with the error details:'could not convert text value to numeric value.', operation:'execute', detailID:'2300'. Several hours later I found that if I included a pretty irrelevant column in the query, setting it to an arbitrary value, the problem went away. As luck would have it, this did not affect the business logic in any meaningful way, so I'm going to leave it as is. However, I detest mysteries like this. Can anyone think of what might have happened?

(Edit: Sorry, I made a mistake in my code. The last two queries were identical in my original post. In fact, the UPDATE query only worked when I also added locked = null or locked = 0 to the query. If I didn't set this value, the query would fail. I did just about everything I could to get around this, including rebuilding the database file.)

Here's the table definition:

CREATE TABLE cars (
    car_id INTEGER  PRIMARY KEY AUTOINCREMENT DEFAULT NULL,
    cargroup_id NUMERIC,
    starting_ordinal NUMERIC,
    ending_ordinal NUMERIC,
    locked NUMERIC
);

This query has always worked:

var query = new Query(
    "UPDATE cars SET locked = (car_id = ?) WHERE cargroup_id = ?",
    [intCarId,intCargroupId],
    success,failure
);

This query failed with the above error ([edit]):

var query = new Query( 
    "UPDATE cars SET starting_ordinal = ?, ending_ordinal = ?, cargroup_id = ? WHERE car_id = ?",
    [
        parseInt(objPayout.starting_ordinal,10),
        parseInt(objPayout.ending_ordinal,10),
        parseInt(objPayout.cargroup_id,10),
        parseInt(objPayout.car_id,10)
    ],
    success,failure
);

I solved the problem by changing the query to this:

var query = new Query(
    "UPDATE cars SET starting_ordinal = ?, ending_ordinal = ?, cargroup_id = ?, locked = null WHERE car_id = ?",
    [
        parseInt(objPayout.starting_ordinal,10),
        parseInt(objPayout.ending_ordinal,10),
        parseInt(objPayout.cargroup_id,10),
        parseInt(objPayout.car_id,10)
    ],
    success,failure
);

来源:https://stackoverflow.com/questions/4092630/sqlite-error-could-not-convert-text-value-to-numeric-value

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