Database bug reporting

 Database portal References: Tutorials/practical articles: Databases Advantage - MySQL - MSSQL - Postgres - Interbase - Firebird - Oracle - ODBC - Paradox - SQLite - dBASE - MS Access - Zeos

Sorts of bugs

Bugs regarding databases can lie in three areas:

• The GUI controls in Lazarus (DBGrid etc)
• The FPC database code (T*Connection, T*Query etc)
• The underlying infrastructure: database drivers/dlls, operating system, network, database server

Lazarus builds on the FPC code, which builds on the infrastructure, so problems that show up in Lazarus GUI programs can be caused by bugs from any category.

Reporting bugs

When reporting bugs, it is very useful (and often essential) to have a compilable test program that shows the problem. See Tips on writing bug reports for reasons why.

In case of database bugs, that means that you need to show how to create a database as well so others can repeat the test.

To make this easier, you can write your bug report for common test/demonstration databases such as

• Firebird's employee.fdb

If you don't, please add the DDL (the schema definition) and sample data SQL INSERT statements (or code that performs this).

Bug reporting template

It's annoying to have to write long test programs when you just want to report a bug. However, it's also annoying and time-consuming for developers to have to write a program just to test if behaviour is incorrect.

A possible solution: use a template program and adapt that to your bug.

Lazarus

For Lazarus, you can use one of the demo database applications in your examples directory (e.g. examples\database\sqldbtutorial3) and adapt that. Don't forget to specify how to create the required database (include the needed CREATE TABLE etc SQL) - or specify a well-known sample database as mentioned above.

FreePascal

A template program can be found below. Please adjust where marked. Once you've tested the program in your own environment, don't forget to remove confidential passwords etc.

program dberror;

{$mode objfpc}{$H+}

uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
{$ENDIF}{$ENDIF}
Classes, sysutils,
sqldb,
ibconnection {*REPLACE WITH RELEVANT CONNECTION LIBRARY*};

{
* ADD THE SQL NEEDED TO CREATE THE DATABASE HERE *
also known as the DDL/schema for the database.
For Firebird you can just say to use the Employee sample database.
For MSSQL you can just say to use the Adventureworks sample database.
}

var
Conn: TibConnection; {*REPLACE WITH RELEVANT CONNECTION *}
Tran: TSQLTransaction;
Q: TSQLQuery;
begin
Conn:=TIBConnection.create(nil); {*REPLACE WITH RELEVANT CONNECTION *}
Tran:=TSQLTransaction.create(nil);
Q:=TSQLQuery.Create(nil);
try
// *REMOVE IDENTIFYING INFO AND EDIT AS NEEDED*
Conn.HostName:='127.0.0.1';
Conn.DatabaseName:='employee';
// *END IDENTIFIYING INFO*
Conn.Transaction:=Tran;
Q.DataBase:=Conn;
Conn.Open;
// *EXAMPLE BUG TESTING CODE, REPLACE WITH YOUR OWN*
Q.SQL.Text:='select now() as RightNow ';
Q.Open;
Q.Last; //force recordcount update
writeln('recordcount: '+inttostr(q.RecordCount));
Q.Close;
// *END EXAMPLE BUG TESTING CODE*
Conn.Close;
finally
Q.Free;
Tran.Free;
Conn.Free;
end;
writeln('Program complete. Press a key to continue.');
end.

Of course, if you don't want to use this template but want to directly write a test case for the db test framework, that's very welcome.