![]() |
![]() |
![]()
Posts: 3
Registered: 2007-07-29 |
Hi all, this is my first post here, so nice to meet you all :-)
I've been trying TextDB at home and works great, but I'm stuck in a question... that is suposse must be very simple to solve, but I dont find how... After I delete a tables's record, the record's Id its erased too, how can I rebuild the table's Ids index to avoid empty spaces? I mean: I have a table: id=1 potato id=2 orange id=3 apple I delete record id=2, and my table is now is this way: id=1 potato id=3 apple I want to rebuild the id's in order to obtain a table like this: id=1 potato id=2 orange I've been taking a look to the info and in previous versions there was a "rebuild" function that solved this issue, but in v5 I dont find how to do it. Best regards and thanks in advance. b:. ------------------------------------------------------ EDIT: I've just discovered thst I'm not using V.5, I'm using V.4.4.2... where can I daownload V.5.1? Thanks again. |
|
Last edited by: bodito on Jul 29, 2007 8:06:16 pm
| |
![]() UPB Team Member
Posts: 835
Registered: 2006-11-14 |
Well there isn't any existing method to do this (nor was there any method in the past, the reBuild function just moved records arround, it never modified them). The reason this method doesn't exist is simple. Look at it from our point of view. If record IDs updated themselves in the fashion you described, it wouldn't be very practical for a forum. For instance if you wanted to e-mail this topic thread to a friend you would send this: www.myupb.com/viewtopic.php?id=8&t_id=36&page=). The moment an admin deleted a topic from 1 to 35, the URL would change to www.myupb.com/viewtopic.php?id=8&t_id=35&page=, so when your friend clicked on the old link, he would get a completely different topic. The point I'm trying to make is that record IDs are specific to each record. If you were to update it everytime a record would delete it, not only would you get inconsistancies such as the one explained above, but you would also create more overhead, because you have to edit each record after the deleted one, to shift the ID number.
HOWEVER, if you are still persistant in updating the IDs, there may be a way. The recordID is used by users calling functions, such as get, edit, delete, etc. Internally, TextDB also utilizes a fileID, to track where in the textdb the record is located at, which can change when records are deleted. So we have the static, non-changable recordID, and we have the changable fileID, which updates automatically when records are deleted. One way you can utilize the fileID, is the function fileIdById. It takes in a $fp, and the recordID, and returns the fileID of the record. In order to retrieve that record, instead of using get(), use listRec($fp, $fileID, 1), which will list one record starting at the fileID. However you will still need to use the recordID for functions such as delete and edit. It might be more trouble than it's worth, but it's an alternative you might want to look into. Be careful, this will not work in tDB v 5.0 or later, as the textDB was restructured. You'll have to use tDB v4.3.5 if you wish to utilize the fileID in the mannor you specified. OR... if you know PHP, have a desire to learn and use textdb, you could create a custom class that extends tdb, and force it to utilize the fileID in most/all functions. ![]() |
![]()
Posts: 3
Registered: 2007-07-29 |
Thanks a lot for your lightning-fast answer ;-)
Its clear to me. You have the reason about the posible inconsistencies to external refers if ids change. Well... I'm thinking about to use it in a small news section to my site, its not a critical thing, and as you say there is allways the option to code myself a "ids rebuilding" method, and expand the class :-) Another question... where can I download V.5? The one I'm trying is 4.4.3 (i think) Thanks again for your time. Best regards. b:. |
![]() UPB Team Member
Posts: 835
Registered: 2006-11-14 |
tdb v5 development is parallel to upb development, so both are still in betas. you can find tdb v5 by downloading upb, and extracting the ./includes/class/tdb.class.php.
![]() |
![]()
Posts: 3
Registered: 2007-07-29 |
Annoying again :)
Well, taking a look this afternoon around my "problem" (its clear its not a problem with textDB). I tought about several approaches to the subject of "sorting" the ids I concluded four possible solutions: 1. I tried to change id value using db->edit, obviously didn't worked (I suppossed not to work, but whatever, was easy to try :-) 2. Use editField to change id type to number, edit the number field, and back to id type... I didnt realized that I can't use db->edit without an target id :-) haha 3. Touching up a little the class, I founded the place were ids are maintained, and tried to touch a little the code, even I was able to change one id from 17 to 9999, but I got troubles with my table later, I suppose that due the filesystem, that I see that handles offsets within the file and things so... at this moment is too advanced to me... I'll need more time to try around. 4. So my last option to sort my news table (move one new up or down) at my wish in a easy way is to add an additional field named "sorting_order" of number, maintain my table ordered using this field, re-index, and resort this "sorting_order" when I want... I think is not the most elegant way, but It will work for sure ;-) Thanks a lot for your support and your time, TextDB is a great class, clear and very easy to use. Best regards from spain. b:. |
![]() UPB Team Member
Posts: 802
Registered: 2006-11-14 |
If you outline your problem with more detail i'd be happy to suggest a solution. Me and Rebles have found numerous ingenious solutions to make things work nicely.
One must fall in order to get up - Pilot
UPB Programmer |
![]()
Posts: 1
Registered: 2009-09-26 |
пробую кирилицу
|