Flex 3 SQLite and the mystery of “text value to numeric value”

Learning new development environments and languages can be quite fun, but sometimes it turns out just plain frustrating. Especially so if you are trying to learn something that is still in its beta stage. This time it was Adobe AIR and Flex 3.

The program in question required storing date and time values in an sqlite3 database. Now, as the title of this entry says, I should’ve just read the AIR sqlite handling manual 1 more time (or 2-10 more times) and I could’ve learnt that AIR SQL handling accepts “Date” as column type and handles inserting and getting Date objects from the database transparently. I did not notice this while studying and used “TIMESTAMP” as column type instead. This is where things went wrong… so wrong…

Using “TIMESTAMP” column type and inserting datetime strings worked flawlessly in the betas along with using sqlite date functions. But AIR 1.0 release came and suddenly my application started producing the following SQL errors everywhere:

SQLError: 'Error #3115: SQL Error.', details:'could not convert text value to numeric value.', operation:'execute'

Naturally for a few days I went through my SQL code and tables trying different things on columns that had types like “INTEGER”, “REAL”, “NUMERIC” and so on. After trying and trying I finally decided to read the AIR documentation again. The essential part turned out to be how AIR handles the column affinities in the release version: everything not recognized by AIR is given “NUMERIC” column affinity. This and the fact that AIR is now stricter about types is what changed between the betas and release version and broke the columns with “TIMESTAMP” as type since I was trying to insert text.

So, again, I should’ve just rtfm…

10 thoughts on “Flex 3 SQLite and the mystery of “text value to numeric value”

  1. Hi,

    I could not understand what you got as solution. Can you please elaborate it more?

    Thanks,

    Naresh

  2. Hi!

    I have the same problem. I want to insert time (like 18:45) and gives me the same error. Can u help me. I don’t understand your description.

    Thanks,
    Toni

  3. I had the same problem. I added like one line of code and that error started appearing. I took that line of code out and I was still getting the error. I took a bunch of code out and it was still happening. I checked the values and types in the database. The only thing that might have been an issue was that I had 00 in one cell instead of 0. Although it was not taken care of after that I might have blanked out that cell and then set it to zero.

    I would even suggest making a new database and trying your program with the new database. In conclusion, it just started working. I put more of the code back hoping it would keep working and it did. I just think there is a problem with this error still.

  4. Hey Sarni, thanks for the post. Would you mind posting an SQL example of how you insert/select dates into sqlite so they are read correctly by Flex? I am pulling out my hair trying to figure out why SQLite contains date fields, but Flex refuses to read them. Thanks!

  5. I digged up some old code (this page is oooold…). Hope this helps ppl:

    “CREATE TABLE IF NOT EXISTS Vaccinations(” +

    “id INTEGER PRIMARY KEY,” +

    “datetime DATE,” + // This will transparently accept and return Date objects

    “vaccine INTEGER,” +

    “vaccinationspot INTEGER,” +

    “patient INTEGER,” +

    “giver TEXT,” +

    “target TEXT,” +

    “notes TEXT,” +

    “vaccine_lot TEXT)”,

    private static const UPDATE_VACCINATION:String =

    “UPDATE Vaccinations SET ” +

    “datetime = :datetime, ” +

    “giver = :giver, ” +

    “target = :target, ” +

    “notes = :notes, ” +

    “vaccine_lot = :vaccine_lot ” +

    “WHERE id = :id”;

    public function updateVaccination(v:Vaccination):void

    {

    var values:Object = {

    “:id”:v.id,

    “:datetime”:v.datetime,

    “:giver”:v.giver,

    “:target”:v.target,

    “:notes”:v.notes,

    “:vaccine_lot”:v.vaccine_lot

    };

    runSqlCmd(sqlStatements[UPDATE_VACCINATION], values);

    }

  6. change the datatype of “timestamp” field to “text” type. Then it will work.

Leave a Reply

Your email address will not be published. Required fields are marked *