[Kde-java] QSqlCursor lastError( )

Richard Dale Richard_Dale at tipitina.demon.co.uk
Tue Oct 26 10:56:11 CEST 2004


On Friday 22 October 2004 13:04, David Goodenough wrote:
> 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.
I can't anything obvious wrong from looking at the code. Can you print some 
debugging to see which line it crashes on?

-- Richard


More information about the Kde-java mailing list