How use EPQDatabaseError ? lazarus / 16-Databases ---------------------------------------------------------------------- Pabdym · 2012-10-08 09:05 Hi, I look for examples of use of EPQDatabaseError.SQLState (TPQConnection) with SQLquery.ExecSQL (INSERT, UPDATE, DELETE)  and SQLquery.Open (SELECT... FOR UPDATE NOWAIT). Thanks. PS : TSQLTransaction.Action := caCommit;  All other properties of TPQConnection, TSQLTransaction, TSQLQuery : by default. ---------------------------------------------------------------------- Pabdym · 2012-10-10 14:33 After many tests, I was easily able to obtain with the EQPDatabaseError, the codes of errors corresponding to errors of formulation in the requests. But, never, for example, I have to make send back : Code of error 23505 ( unique_violation ) in an Insert or UpdateSQL while E.message ( EDataBaseError) indicates correctly the violation. It seem's that it is not possible. It is really a lack if we compare with the use of FIBConnection. Regards. ---------------------------------------------------------------------- ludob · 2012-10-10 17:21 There are some parts of pqconnection that still use EDatabaseError instead of the extended EQPDatabaseError. As a result you get extended info for the preparation of the query (syntax errors, etc) but not for the execute part (unique violation,...). I'll create a fix for that. ---------------------------------------------------------------------- ludob · 2012-10-10 18:43 A fix is committed to FPC 2.7.1 rev 22610. A EPQDatabaseError is now raised for execute. There is still a mix of EPQDatabaseError and EDatabaseError because the first one is only relevant for result sets. So your code should look like the following test snippet: Code: [Select]    SQLQuery1.SQL.Text:='create table testunique (id integer NOT NULL, CONSTRAINT "PK_testunique_id" PRIMARY KEY (id ))';     SQLQuery1.ExecSQL;     SQLQuery1.SQL.Text:='insert into testunique values (1)';     SQLQuery1.ExecSQL;     try       SQLQuery1.SQL.Text:='insert into testunique values (1)';       SQLQuery1.ExecSQL;     except       on E: Exception do         if E is EPQDatabaseError then           Showmessage((E as EPQDatabaseError).SQLSTATE);     end; The test will pop up a box with '23505'. ---------------------------------------------------------------------- Pabdym · 2012-10-10 18:49 OK. Thank you. If I can help : I have the possibility to test the code: Lazarus/FPC trunk  Win, Linux (32 and 64 bits), MACPostgreSQL9.1 Servers Win 32and Squeeze 64.Regards. ---------------------------------------------------------------------- Pabdym · 2012-10-10 22:49 Client -->  Win32:  fpc/trunk -Rev. 22610 - laz/trunk-Rev. 39038 Server -> Squeeze 64 bits - PostgreSQL 9.1.5 Tested with an Insert Request : It works fine. Look at the attachment please.  Question : To install Lazarus/FPC, I respected the procedure described in the link (by replacing 2.6.1 by trunk) http://wiki.freepascal.org/I nstalling_Lazarus#Compiling.2Finstalling_FPC_and_Lazarus_from_Sources_ of_SVN_.28Win32.29 It works correctly but at the end, it is necessary to add missing files in \lazarus\fpc\trunk\bin\i386-win32 : make.exe and gdb.exe. Is it normal ? Thank you again for your help. Regards. ---------------------------------------------------------------------- ludob · 2012-10-11 06:27 QuoteIt works correctly but at the end, it is necessary to add missing files in \lazarus\fpc\trunk\bin\i386-win32 : make.exe and gdb.exe. Is it normal ?To build trunk you need a 2.6.0 compiler which typically comes with make.exe. It is not necessary to re-install as long as it can be found in the PATH. For lazarus in Tools/Setup/Environment you can set the path tp make.exe. In Tools/Setup/Debugger you can set the path to gdb.exe.