Forum > Databases
TDbf Pack problem/issue ...
1HuntnMan:
I have an issue with an almost completed app with 2 tables in a TDbf database. I moving soon to SQLite but got to fix this first. This app has 8 main tables with several other lookup tables such as States/Provinces, Countries, etc. On 2 of the forms, Appointments (Appmts.dbf) and Photography (Photos.dbf) I have a major issue with packing these 2 tables. I have a system create procedure that creates all the tables and indices for the app and another procedure for table maintenance. The issue is when on these 2 tables for some reason crater on the Pack code line, see the example code snipet below:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- try //->Appointments table maintenance start... 1 DbfAppmts.Exclusive:= True; DbfAppmts.Open; DbfAppmts.Active:= True; //->DbfAppmts.PackTable; //->Pack Appointments.Dbf table !!! Error here! DbfAppmts.RegenerateIndexes; //->Rebuild Appointments table indexes DbfAppmts.Exclusive:= False; DbfAppmts.Close; finally DbfAppmts.Free; PrgrsBarRebld.Position:= 10; end;
This is the error that bombs out below, I can comment out these 2 Pack and Regen Indexes for these 2 tables and no issue. I can comment out the 2 Pack lines and no problemo! Error attached which is this:
"Project pms raised exception class 'External: FLT INVALID OPERATION'. At address 100626CF"
Anyone have a clue why just these 2 while the rest (6), no problems.
Tks...
paweld:
The reason for the floating-point exception could be invalid values in the numeric columns, or an invalid data type for the indicated TableLevel - some numeric data types are only supported in specific TableLevel: https://wiki.lazarus.freepascal.org/Lazarus_Tdbf_Tutorial#Adding_fields
wp:
Not solving your problem, but I noticed the following points:
* Dataset.Open and Dataset.Active := true do the same - use only one of them
* Shouldn't Dataset.Exclusive := false be done after closing the dataset?
* Immediately afterwards you destroy the dataset. Is this really intended? Where is it created? Are you sure that it exists when the procedure is entered next time?
* Is Dbf.Active true already in the object inspector? This may cause problem with exclusive access (https://forum.lazarus.freepascal.org/index.php/topic,38350.msg260201.html#msg260201).
* There is also a "FastPackTable" which only fills the holes in the file for an "in-place" pack (Dbf1.DbfFile.FastPackTable). This method already contains the call to RegenerateIndexes
1HuntnMan:
So, it appears that I don't need to both Open the Dbf.Table and also set the Dbf.Table to Active. Also, it appears that I can just set Exclusive to True first, then just OPEN table and then FastPackTable with no need to RegenerateIndexes and then just close DbfAppmts table. Lastly, set Exclusive to False. I think my understanding is that table can't be open or active when adjusting the Exclusive property, correct and I don't need to Open and also set the table Active to True, just Open it. The only properties I have set for all the tables in this maintenance Procedure is Active is OFF, FilePath/FilePathFull are set to the Data directory, TableLevel=7 and the TableName is set to the table file name, i.e. Appointments.dbf in the PMS Data folder below the executable per the FilePathFull.
This is what I'm going to test, I'll be back to let ya'll know...
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- try //->Appointments table maintenance start... 1 DbfAppmts.Exclusive:= True; DbfAppmts.Open; //->DbfAppmts.Active:= True; // No need since it's OPEN DbfAppmts.FastPackTable; //->Pack Appointments.Dbf table PLUS Regenerate the indexes! //DbfAppmts.RegenerateIndexes; //->No need to Rebuild Appointments table indexes, done already DbfAppmts.Close; DbfAppmts.Exclusive:= False; finally DbfAppmts.Free; PrgrsBarRebld.Position:= 10; end;
wp:
--- Quote from: 1HuntnMan on August 02, 2024, 11:16:56 pm ---
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- try //->Appointments table maintenance start... 1 DbfAppmts.Exclusive:= True; DbfAppmts.Open; //->DbfAppmts.Active:= True; // No need since it's OPEN DbfAppmts.FastPackTable; //->Pack Appointments.Dbf table PLUS Regenerate the indexes! //DbfAppmts.RegenerateIndexes; //->No need to Rebuild Appointments table indexes, done already DbfAppmts.Close; DbfAppmts.Exclusive:= False; finally DbfAppmts.Free; PrgrsBarRebld.Position:= 10; end;
--- End quote ---
Let me add: Assuming that you really intend to Free the dbf at the end you can even skip the Exclusive := false. Maybe one important point: if DbfAppmts is a global variable rather than local to the current procedure you should nil DbfAppmts immediately after freeing (or call FreeAndNil(DbfAppmts)) in order to signal to possible calling methods that it does not exist any more (you must check DbfAppts there for nil before accessing it).
To understand the equivalence of Dataset.Open and Dataset.Active := true, just take a look at the source code of TDataset:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TDataSet.Open;begin Active:=True;end; Likewise for Close:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TDataSet.Close;begin Active:=False;end;
Navigation
[0] Message Index
[#] Next page