Sign in Join
Wiki copytemporary

Database bug reporting: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Database bug reporting

OldNewLine
1+## Sorts of bugs
2+
3+Bugs regarding databases can lie in three areas:
4+
5+- The GUI controls in Lazarus (DBGrid etc)
6+- The FPC database code (T*Connection, T*Query etc)
7+- The underlying infrastructure: database drivers/dlls, operating system, network, database server
8+
9+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.
10+
11+## Reporting bugs
12+
13+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.
14+
15+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.
16+
17+To make this easier, you can write your bug report for common test/demonstration databases such as:
18+
19+- Firebird's employee.fdb
20+- Microsoft SQL Server's AdventureWorks
21+
22+If you don't, please add the DDL (the schema definition) and sample data SQL INSERT statements (or code that performs this).
23+
24+## Bug reporting template
25+
26+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.
27+
28+A possible solution: use a template program and adapt that to your bug.
29+
30+### Lazarus
31+
32+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.
33+
34+### Free Pascal
35+
36+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.
37+
38+``` pascal
39+program dberror;
40+
41+{$mode objfpc}{$H+}
42+
43+uses
44+ {$IFDEF UNIX}{$IFDEF UseCThreads}
45+ cthreads,
46+ {$ENDIF}{$ENDIF}
47+ Classes, sysutils,
48+ sqldb,
49+ ibconnection {*REPLACE WITH RELEVANT CONNECTION LIBRARY*};
50+
51+{
52+* ADD THE SQL NEEDED TO CREATE THE DATABASE HERE *
53+also known as the DDL/schema for the database.
54+For Firebird you can just say to use the Employee sample database.
55+For MSSQL you can just say to use the Adventureworks sample database.
56+}
57+
58+var
59+ Conn: TibConnection; {*REPLACE WITH RELEVANT CONNECTION *}
60+ Tran: TSQLTransaction;
61+ Q: TSQLQuery;
62+begin
63+ Conn:=TIBConnection.create(nil); {*REPLACE WITH RELEVANT CONNECTION *}
64+ Tran:=TSQLTransaction.create(nil);
65+ Q:=TSQLQuery.Create(nil);
66+ try
67+ // *REMOVE IDENTIFYING INFO AND EDIT AS NEEDED*
68+ Conn.HostName:='127.0.0.1';
69+ Conn.UserName:='SYSDBA';
70+ Conn.Password:='masterkey';
71+ Conn.DatabaseName:='employee';
72+ // *END IDENTIFIYING INFO*
73+ Conn.Transaction:=Tran;
74+ Q.DataBase:=Conn;
75+ Conn.Open;
76+ // *EXAMPLE BUG TESTING CODE, REPLACE WITH YOUR OWN*
77+ Q.SQL.Text:='select now() as RightNow ';
78+ Q.Open;
79+ Q.Last; //force recordcount update
80+ writeln('recordcount: '+inttostr(q.RecordCount));
81+ Q.Close;
82+ // *END EXAMPLE BUG TESTING CODE*
83+ Conn.Close;
84+ finally
85+ Q.Free;
86+ Tran.Free;
87+ Conn.Free;
88+ end;
89+ writeln('Program complete. Press a key to continue.');
90+ readln;
91+end.
92+```
93+
94+Of course, if you don't want to use this template but want to directly write a test case for the [[Databases|db test framework]], that's very welcome.
95+
96+## See also
97+
98+- [[How do I create a bug report]] General information on how to report a bug for Lazarus/FPC
99+- [[Tips on writing bug reports]] Explains e.g. why test programs in bug reports are so important
100+
101+---
102+*From the Free Pascal wiki, page "Database bug reporting", as it stood on 2020-09-16 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
103+Category: Databases
104+Category: Lazarus
105+Category: Troubleshooting

Back to history