[fpc-pascal] Firebird stored procedure exceptions generate access violation
Hi all, Still working on my locate clone at http://bitbucket.org/jb/flocate/ - download at http://bitbucket.org/jb/flocate/downloads Running Free Pascal Compiler version 2.4.1 [2010/06/01] for x86_64 on Windows. I've cobbled together some Firebird database code. If you want to have a more complete overview, I've posted the entire database unit to http://pastebin.com/rgpAK91Q I have connection/transaction/query objects open. The query calls a stored procedure on the database and has parameters defined... like this EXECUTE PROCEDURE SPADDFILEDEFAULT ( ' + ':COMPUTERNAME, ' + and a lot of others In a loop going through the files I've found on the computer (in TDirectoryEntryList = class(TFPObjectList) ), I call a procedure procedure TflocateDB.SaveDirectoryEntry(COMPUTERNAME: string; and a lot of others that use the open query, first clear (for luck, I guess ;) then assign parameters (e.g. FInsertQuery.Params.ParamByName('COMPUTERNAME').AsString := COMPUTERNAME; FInsertQuery.Params.ParamByName('DATEACCESSED').AsDateTime := DATEACCESSED; Finally I execute the SQL within an try...except block try FInsertQuery.ExecSQL; FTransaction.CommitRetaining; //todo: this is for testing so we can see what didn't get inserted //in production, we'd just have one big happy transaction I suppose except on E: EIBDatabaseError do begin // We would havee committed, so we should be rolling back. {$IFDEF DEBUG} Writeln(stderr, 'Debug: ', DateTimeToStr(Now), ': Database error running insert query (filename: ', FILENAME, '). Database error message: ', E.Message, '; Database error code: ', E.GDSErrorCode ); Writeln(stderr, 'Debug: ', DateTimeToStr(Now), ': Parameters were: '); for DebugCounter := 0 to FInsertQuery.Params.Count - 1 do begin Writeln(stderr, FInsertQuery.Params[DebugCounter].Name, ': *', FInsertQuery.Params[DebugCounter].Value , '*'); end; Writeln(stderr, 'Debug: ', DateTimeToStr(Now), ': Rolling back transaction.'); {$ENDIF DEBUG} FTransaction.RollBack; end; on E: Exception do begin {$IFDEF DEBUG} Writeln(stderr, 'Debug: ', DateTimeToStr(Now), ': Error running insert query (filename: ', FILENAME, '). Technical details: ', E.Message ); Writeln(stderr, 'Debug: ', DateTimeToStr(Now), ': Parameters were: '); for DebugCounter := 0 to FInsertQuery.Params.Count - 1 do begin Writeln(stderr, FInsertQuery.Params[DebugCounter].Name, ': *', FInsertQuery.Params[DebugCounter].Value, '*'); end; {$ENDIF DEBUG} end; //E: Exception end; //end of actual execsql block The stored procedure in Firebird takes all the parameters, looks them up in the respective tables (e.g. TBLCOMPUTERS), inserts new records if required, gets the resulting primary keys for dependent tables and finally inserts all these keys and some more data in a TBLFILES table. This stored procedure is not faultless yet; sometimes it errors out. I've implemented multiple custom Firebird exceptions in the stored procedures like this: CREATE EXCEPTION SPCOULDNOTFINDVERSIONINFO 'Could not add records: unable to add version information to database'; The SP calls these exceptions when something seriously goes wrong e.g. SELECT EXEID FROM TBLEXES WHERE EXEFILEVERSION=:exefileversion AND EXEPRODUCTVERSION=:exeproductversion INTO :localEXEID; IF (:localEXEID IS NULL) THEN BEGIN /* when we can't add the info */ /* in the related table, we should just abort */ localDUMMY = FBDEBUG('Exception for TBLEXES problems will be called: SPCOULDNOTFINDVERSIONINFO', '/tmp/test.txt'); ... some more debugging stuff... EXCEPTION SPCOULDNOTFINDVERSIONINFO; END When I hit the stored procedure exception mentioned above, my code doesn't complain, but on the next file and all subsequent files, the error code in my code indicates I got an access violation. E.g. my Firebird logging gives: 5-6-10 10:02:07:Exception for TBLEXES problems will be called: SPCOULDNOTFINDVERSIONINFO 5-6-10 10:02:07:FILENAME :*nmwcdclsx64.dll* 5-6-10 10:02:07:FILEPATH :*C:\windows\system32\* 5-6-10 10:02:07:localEXEID :** 5-6-10 10:02:07:EXECOMPANY :*Nokia* 5-6-10 10:02:07:EXECOPYRIGHT :*Copyright (c) 2002,2003,2004,2005. Nokia. All rights reserved.* 5-6-10 10:02:07:EXEDESCRIPTION :*Wireless Communication Device Class Installer* 5-6-10 10:02:07:EXEFILEVERSION may not be NULL :*7.1.18.34* 5-6-10 10:02:07:EXEINTERNALNAME:*NMWCDCLSX64* 5-6-10 10:02:07:EXEORIGINALFILENAME:*nmwcdclsx64.dll* 5-6-10 10:
Re: [fpc-pascal] Firebird stored procedure exceptions generate access violation
On Sat, 5 Jun 2010, Jim wrote: Hi all, Still working on my locate clone at http://bitbucket.org/jb/flocate/ - download at http://bitbucket.org/jb/flocate/downloads Running Free Pascal Compiler version 2.4.1 [2010/06/01] for x86_64 on Windows. I've cobbled together some Firebird database code. If you want to have a more complete overview, I've posted the entire database unit to http://pastebin.com/rgpAK91Q I have connection/transaction/query objects open. The query calls a stored procedure on the database and has parameters defined... like this EXECUTE PROCEDURE SPADDFILEDEFAULT ( ' + ':COMPUTERNAME, ' + and a lot of others In a loop going through the files I've found on the computer (in TDirectoryEntryList = class(TFPObjectList) ), I call a procedure procedure TflocateDB.SaveDirectoryEntry(COMPUTERNAME: string; and a lot of others that use the open query, first clear (for luck, I guess ;) then assign parameters (e.g. FInsertQuery.Params.ParamByName('COMPUTERNAME').AsString := COMPUTERNAME; FInsertQuery.Params.ParamByName('DATEACCESSED').AsDateTime := DATEACCESSED; Finally I execute the SQL within an try...except block try FInsertQuery.ExecSQL; FTransaction.CommitRetaining; //todo: this is for testing so we can see what didn't get inserted //in production, we'd just have one big happy transaction I suppose except on E: EIBDatabaseError do begin // We would havee committed, so we should be rolling back. {$IFDEF DEBUG} Writeln(stderr, 'Debug: ', DateTimeToStr(Now), ': Database error running insert query (filename: ', FILENAME, '). Database error message: ', E.Message, '; Database error code: ', E.GDSErrorCode ); Writeln(stderr, 'Debug: ', DateTimeToStr(Now), ': Parameters were: '); for DebugCounter := 0 to FInsertQuery.Params.Count - 1 do begin Writeln(stderr, FInsertQuery.Params[DebugCounter].Name, ': *', FInsertQuery.Params[DebugCounter].Value , '*'); end; Writeln(stderr, 'Debug: ', DateTimeToStr(Now), ': Rolling back transaction.'); {$ENDIF DEBUG} FTransaction.RollBack; end; on E: Exception do begin {$IFDEF DEBUG} Writeln(stderr, 'Debug: ', DateTimeToStr(Now), ': Error running insert query (filename: ', FILENAME, '). Technical details: ', E.Message ); Writeln(stderr, 'Debug: ', DateTimeToStr(Now), ': Parameters were: '); for DebugCounter := 0 to FInsertQuery.Params.Count - 1 do begin Writeln(stderr, FInsertQuery.Params[DebugCounter].Name, ': *', FInsertQuery.Params[DebugCounter].Value, '*'); end; {$ENDIF DEBUG} end; //E: Exception end; //end of actual execsql block The stored procedure in Firebird takes all the parameters, looks them up in the respective tables (e.g. TBLCOMPUTERS), inserts new records if required, gets the resulting primary keys for dependent tables and finally inserts all these keys and some more data in a TBLFILES table. This stored procedure is not faultless yet; sometimes it errors out. I've implemented multiple custom Firebird exceptions in the stored procedures like this: CREATE EXCEPTION SPCOULDNOTFINDVERSIONINFO 'Could not add records: unable to add version information to database'; The SP calls these exceptions when something seriously goes wrong e.g. SELECT EXEID FROM TBLEXES WHERE EXEFILEVERSION=:exefileversion AND EXEPRODUCTVERSION=:exeproductversion INTO :localEXEID; IF (:localEXEID IS NULL) THEN BEGIN /* when we can't add the info */ /* in the related table, we should just abort */ localDUMMY = FBDEBUG('Exception for TBLEXES problems will be called: SPCOULDNOTFINDVERSIONINFO', '/tmp/test.txt'); ... some more debugging stuff... EXCEPTION SPCOULDNOTFINDVERSIONINFO; END When I hit the stored procedure exception mentioned above, my code doesn't complain, but on the next file and all subsequent files, the error code in my code indicates I got an access violation. E.g. my Firebird logging gives: 5-6-10 10:02:07:Exception for TBLEXES problems will be called: SPCOULDNOTFINDVERSIONINFO 5-6-10 10:02:07:FILENAME :*nmwcdclsx64.dll* 5-6-10 10:02:07:FILEPATH :*C:\windows\system32\* 5-6-10 10:02:07:localEXEID :** 5-6-10 10:02:07:EXECOMPANY :*Nokia* 5-6-10 10:02:07:EXECOPYRIGHT :*Copyright (c) 2002,2003,2004,2005. Nokia. All rights reserved.* 5-6-10 10:02:07:EXEDESCRIPTION :*Wireless Communication Device Class Installer* 5-6-10 10:02:07:EXEFILEVERSION may not be NULL :*7.1.18.34* 5-6-10 10:02:07:EXEINTERNALNAME:*NMWCDCLSX64* 5-6-10 10:02:07:EXEORIGINALFILENAME:*nmwcdclsx64.dll* 5-6-10 10:02:07:EXEPRODUCTNA
Re: [fpc-pascal] Firebird stored procedure exceptions generate access violation
On 5-6-2010 10:47, Michael Van Canneyt wrote: > On Sat, 5 Jun 2010, Jim wrote: >> Finally, the question: >> What I really want is to get a Firebird SQLCODE error code or some other >> details that allow me to figure out whether one of my custom exceptions >> get called. Also, it seems something is wrong after the error; although >> the objects still seem to exist, the database obviously won't insert >> anymore. >> >> How do I get proper error codes and/or fix this code? (Of course, >> suggestions on code improvement etc are also welcome) > > It might be worth putting all parameters in a record definition and pass > the > record to your function. That makes the procedure declaration somewhat more > manageable and understandable. (and definitely more efficent as well). > > Then, there is an access violation in your code: > Try to get a stack trace, we can then tell where the access violation > occured, maybe it will tell us a little more. > > Michael. Ok, I'll have a go at doing that... I'll get back to the list. -- Regards, jb ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Firebird stored procedure exceptions generate access violation
On 5-6-2010 10:47, Michael Van Canneyt wrote: > On Sat, 5 Jun 2010, Jim wrote: >> Finally, the question: >> What I really want is to get a Firebird SQLCODE error code or some other >> details that allow me to figure out whether one of my custom exceptions >> get called. Also, it seems something is wrong after the error; although >> the objects still seem to exist, the database obviously won't insert >> anymore. >> >> How do I get proper error codes and/or fix this code? (Of course, >> suggestions on code improvement etc are also welcome) > > It might be worth putting all parameters in a record definition and pass > the > record to your function. That makes the procedure declaration somewhat more > manageable and understandable. (and definitely more efficent as well). > > Then, there is an access violation in your code: > Try to get a stack trace, we can then tell where the access violation > occured, maybe it will tell us a little more. I've not yet looked into converting the procedure call parameters into a record. However, using gdb I got the following backtrace: gdb flocate break fpc_raiseexception =>gives Cannot access memory at address 0xc800 run c:\windows\system32 => passing the directory for flocate to search in. ... snip a lot of my program's debug output... Debug: 5-6-2010 11:54:30: SaveDirectoryEntry: going to add parameters for insert query (nmwcdclsx64.dll) Debug: 5-6-2010 11:54:30: SaveDirectoryEntry: insert query code done. (nmwcdclsx64.dll) Debug: 5-6-2010 11:54:30: SaveDirectoryEntry: going to add parameters for insert query (NOISE.CHS) Program received signal SIGSEGV, Segmentation fault. 0x0001ad7d in FINALIZE$_DATEUTILS () (gdb) backtrace #0 0x0001ad7d in FINALIZE$_DATEUTILS () #1 0x05d73f80 in ?? () #2 0x012baf10 in ?? () #3 0x012baf10 in ?? () #4 0x0001715c in FINALIZE$_DATEUTILS () #5 0x00010a70 in ?? () #6 0x77c38f15 in ?? () #7 0x0001 in ?? () #8 0x05d73f80 in ?? () #9 0x0102ef00 in ?? () #10 0x0001000531b0 in FINALIZE$_DATEUTILS () #11 0x in ?? () Hope this is what you're looking for... regards, jb ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Firebird stored procedure exceptions generate access violation
On Sat, 5 Jun 2010, Jim wrote: On 5-6-2010 10:47, Michael Van Canneyt wrote: On Sat, 5 Jun 2010, Jim wrote: Finally, the question: What I really want is to get a Firebird SQLCODE error code or some other details that allow me to figure out whether one of my custom exceptions get called. Also, it seems something is wrong after the error; although the objects still seem to exist, the database obviously won't insert anymore. How do I get proper error codes and/or fix this code? (Of course, suggestions on code improvement etc are also welcome) It might be worth putting all parameters in a record definition and pass the record to your function. That makes the procedure declaration somewhat more manageable and understandable. (and definitely more efficent as well). Then, there is an access violation in your code: Try to get a stack trace, we can then tell where the access violation occured, maybe it will tell us a little more. I've not yet looked into converting the procedure call parameters into a record. However, using gdb I got the following backtrace: gdb flocate break fpc_raiseexception =>gives Cannot access memory at address 0xc800 run c:\windows\system32 => passing the directory for flocate to search in. ... snip a lot of my program's debug output... Debug: 5-6-2010 11:54:30: SaveDirectoryEntry: going to add parameters for insert query (nmwcdclsx64.dll) Debug: 5-6-2010 11:54:30: SaveDirectoryEntry: insert query code done. (nmwcdclsx64.dll) Debug: 5-6-2010 11:54:30: SaveDirectoryEntry: going to add parameters for insert query (NOISE.CHS) Program received signal SIGSEGV, Segmentation fault. 0x0001ad7d in FINALIZE$_DATEUTILS () (gdb) backtrace #0 0x0001ad7d in FINALIZE$_DATEUTILS () #1 0x05d73f80 in ?? () #2 0x012baf10 in ?? () #3 0x012baf10 in ?? () #4 0x0001715c in FINALIZE$_DATEUTILS () #5 0x00010a70 in ?? () #6 0x77c38f15 in ?? () #7 0x0001 in ?? () #8 0x05d73f80 in ?? () #9 0x0102ef00 in ?? () #10 0x0001000531b0 in FINALIZE$_DATEUTILS () #11 0x in ?? () Hope this is what you're looking for... It is, but it doesn't give the expected output. Are you using a UDF ? Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Crosscompile FPC from Win32 to Linux
On 5 June 2010 00:47, Henry Vermaak wrote: > > It may be better building the whole compiler for the latest version of > cygwin, but I'll see if I can scrape together the necessary files you > can drop into your fpc bin directory for this to work (not that many). > I managed to get a simple writeln app to cross compile and run on > linux. Luckily, someone else has built mingw cross tools here: ftp://ftp.freepascal.org/pub/fpc/contrib/cross/mingw/ You can download binutils-2.15-win32-i386-linux.zip and extract it into your fpc bin directory. After that it's just a matter of recompiling your rtl and packages (if needed). Let me know if you need help with doing this. Henry ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] regex vs synregexpr unit
I've search fpc mailing list about this matter, I found they were discussed a long time ago (2006), and I still didn't have a conclusion about which one should be used. I need an advice about which unit should be used in terms of features, speed, etc. Also, if someone here know a better approach to implement full-featured regular expression in our FPC programs, please let me know it. Thanks in advance. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] linking name issue
Hello, I have renamed a unit previously called "UnitType" to "UnitSystem". The unit name itself, its file name, and the name used to import it in a uses clause inside a testing program where all changed. But the linker still expects the previous name: testUnit.pas(78,1) Warning: Object UnitType.o not found, Linking may fail ! testUnit.pas(79,1) Error: Error while linking Note: UnitSystem compile finely, UnitSystem.o exists. I'm blocked! Denis vit esse estrany ☣ spir.wikidot.com ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] regex vs synregexpr unit
On Sat, 5 Jun 2010 09:54:51 -0700 (PDT) Bihar Anwar wrote: > I've search fpc mailing list about this matter, I found they were discussed a > long time ago (2006), and I still didn't have a conclusion about which one > should be used. I need an advice about which unit should be used in terms of > features, speed, etc. > > Also, if someone here know a better approach to implement full-featured > regular expression in our FPC programs, please let me know it. Interested, too. And with a PEG library, if any (have searched, already); If there is none, I'll have to build one in a few weeks. Denis vit esse estrany ☣ spir.wikidot.com ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] linking name issue
On 05 Jun 2010, at 19:38, spir wrote: > I have renamed a unit previously called "UnitType" to "UnitSystem". The unit > name itself, its file name, and the name used to import it in a uses clause > inside a testing program where all changed. > But the linker still expects the previous name: > testUnit.pas(78,1) Warning: Object UnitType.o not found, Linking may fail ! > testUnit.pas(79,1) Error: Error while linking > Note: UnitSystem compile finely, UnitSystem.o exists. Maybe you did not recompile all units that used the old unit name? Try rebuilding the program (compile with the -B option, or delete all .ppu files). Jonas___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] regex vs synregexpr unit
Hi The pcre library (written in C) has a good reputation. You can get pascal headers from the Project JEDI Code Library (JCL). Mischi___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] linking name issue
Try deleting testunit.o and/or testunit.a, testunit.ppu ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] [SOLVED] linking name issue
On Sat, 5 Jun 2010 11:13:31 -0700 David Emerson wrote: > Try deleting testunit.o and/or testunit.a, testunit.ppu Yes, there was another unit still referencing "UnitType" -- but not used by the TestUnit test prog. Strange that it may prevent testUnit to compile and link. Anything, deleted all but .pas files and it works fine. Thank you for your help. Denis vit esse estrany ☣ spir.wikidot.com ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] regex vs synregexpr unit
Schindler Karl-Michael wrote on June 6, 2010 1:09:02 AM: >The pcre library (written in C) has a good reputation. You can get pascal headers from the Project JEDI Code Library (JCL). Wow, that seems a more promising approach in the current time, I'll look on it. Thanks so much. BTW, which approach should be used to call C functions from FPC: call them through DLL, or compile the C source into an .o file then link it with FPC code? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal