[Kde-java] QSqlCursor lastError( )

David Goodenough david.goodenough at btconnect.com
Fri Oct 22 14:04:25 CEST 2004


I was trying to add some records to a DB, and getting a zero value back from
cursor.insert( ).  So I added a few lines to try to get the QSqlError object
back and the program segfaulted.

The code read:-

  QSqlCursor cursor = new QSqlCursor( "charges");
  cursor.setMode( QSqlCursor.Writable);
  record = cursor.primeInsert( );
  addItem( record, "Installation", 1, invoiced, due);
  records += cursor.insert( );
  if( records == 0)
   {
    QSqlError error = cursor.lastError( );
    System.out.println( ( error == null) ? "No Error" : error.text( ));
    }

where addItem just fills in a few fields in the record.

Without the if clause the code does not trap (it did not insert the
record because there was an SQL constraint which meant it rejected
the new record as a unique field was not unique).

With the if clause the code traps, with no indication of where the 
problem was.  I can only presume that either the cursor.lastError( )
or the error.text( ) has a problem.

David


More information about the Kde-java mailing list