WebReflection / dblite

sqlite for node.js without gyp problems
MIT License
209 stars 34 forks source link

Query doesn't catch INSERT failures due to foreign keys #40

Closed gussmith23 closed 7 years ago

gussmith23 commented 9 years ago

If an INSERT fails due to foreign key constraints, a message is printed to say that the INSERT didn't happen; however, the "err" object in the callback is still null.

WebReflection commented 9 years ago

Please help me fix this for you:

Thanks

gussmith23 commented 9 years ago

OS: Raspbian, Raspberry Pi (ARM chip) SQLite: 3.7.13 dblite: 0.7.6

The code snippet that fails:

db.query(
          'PRAGMA foreign_keys = ON;' +         // Turn on foreign key constraints. Must be done here in the query!
          'INSERT INTO fact (uid) VALUES (?)',
          [uid],
          function(err,data) { // Note: have to put data argument in here to get err object. (with single arg, it's func(data))
             updateIndex();
             /**
              * TODO
              * Ideally, we'd check for INSERT failures due to foreign key constraints. 
              * These failures happen when we log a lap for a non-registered team.
              * An error will come up in the server's output: "Error: near line ?: foreign key constraint failed"
              * However, we'd like to detect this (so we don't waste time updating everything!)
              * The good news is that these records still aren't added in.
              */
          });
WebReflection commented 9 years ago

uhm ... I'm quite over-busy these days, but I've got more than a Pi to test this stuff.

If you could provide a failure test that includes table creation IF present and stuff it would help.

I do hope this is not one of those cases where no matter what I do, sqlite dumps the output in the log/stdout instead of stderr ... I hope I am wrong.

WebReflection commented 7 years ago

no reply for long time