SQLite Forum

Bug ? Same query that works in shell produces constraint violation when run by a C program with sqlite3_{prepare,bind,step}
Login
Thanks for the tip. Here is a snippet of my code doing the bind:

      // I have snprintf-ed the string parameters to a buffer,
      // and converted the fractional seconds into a double 'fract_sec' value:

      fprintf(stderr, "TIMESTAMP: %*.*s + %s %g\n", len, len, &_buf_.b[0],  
              (char*)(&_buf_.b[0] + len + 1), fract_sec);
      if ( (sql_err = sqlite3_bind_text( _insert_location_stmt_,  1, 
                                         &_buf_.b[0], len, SQLITE_STATIC )
                                       )
         != SQLITE_OK
         )
        _ERR_(ERROR_LOG | ERROR_SYSTEM, ERR_ACT_RETURN, 0, false, 
              "Failed to bind timestamp to location insert statement: '%s'",
              sqlite3_errmsg(_db_)
             );
      if ( (sql_err = sqlite3_bind_double(_insert_location_stmt_, 2,
                                             fract_sec))
            != SQLITE_OK
         )
        _ERR_(ERROR_LOG | ERROR_SYSTEM, ERR_ACT_RETURN, 0, false, 
         "Failed to bind fractional seconds to location insert statement: '%s'",
         sqlite3_errmsg(_db_)
             );
      // bind more parameters ...
      switch (sql_err = sqlite3_step(_insert_location_stmt_) )
      {case SQLITE_DONE:
        break;
       default:
        _ERR_(ERROR_LOG | ERROR_SYSTEM, ERR_ACT_RETURN, 0, false, 
             "sqlite_step failed: "
             "%u:'%s'", sql_err, sqlite3_errmsg(_db_)
             );
      }


This code fragment prints:

      TIMESTAMP: 2021-03-19T11:00:00.123456+00:00 + .123456 0.123456
      src\${my_prog}.exe[8616] : sql\${my_src}.c:375($the_function_name) :
      Error: - sqlite_step failed: 19:'NOT NULL constraint failed: 
                                       $TABLENAME.timestamp'.

Those are exactly the same values I use in the shell version of the query,
which works .

Is there no way to get the VSIX winsqlite3.dll code to print out more
information about the query it has prepared ? 

Why don't '.echo on' or '.explain on' seem to work when run with 
sqlite3_exec ? 

Is there any other way of getting the libraries to print more info ?

It would be nice if the VSIX package supplied debugging versions of the libraries & their *.pdb files . I am now trying to build them from source 
with debugging enabled.