Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - HDI keep database records sorted?

HDI keep database records sorted?

Discuss OrbForms Designer and PocketC Architect

Postby FrankG on Wed Feb 05, 2003 1:21 pm

What approaches does one use to add / delete records in databases that need to keep the records in some order? I get the impression records are stored purely by index number and therefore there's not a simple was, I think, to insert a records in the middle without bumping the rest of the records out. Is it similar to inserting an element in the middle of an array? Like if I had 5 records:

Alpha<br />Bravo<br />Delta<br />Echo

and I want to insert record Charlie in between B and D, do I have to create a blank record in the 5th spot, move the 4th to the 5th, the 3rd to the 4th, and then stick Charlie in the 3rd record?

It would seem to take a lot of the fun out of databases to manage the record order by hand but I get the impression that's what is necessary to do.

Thanks,
Frank
FrankG
 
Posts: 210
Joined: Thu Jan 23, 2003 7:58 pm

Postby jims on Wed Feb 05, 2003 1:45 pm

Frank,

You can use db.moverec to move records around. I have an insertion sort routine that I could give you if your interested. It's a little slow but it works. I modified the Survey example to use it and it can take about 7 seconds to sort 100 records on my Visor edge...

Also, Jermey mentioned that they may add a native db sort function sometime which would work like the current OrbSort for structures.

later,
jim
jims
 
Posts: 34
Joined: Wed May 22, 2002 4:01 pm
Location: USA

Postby FrankG on Wed Feb 05, 2003 4:17 pm

Jim,

I'd always be up to see some example code. Thank you for the offer. If you like maybe it could go in the examples forum. If not, e-mailing to me would be 'preciated.

I guess even with a moverec operation there'd still be a need to find the insertion point (a binary search might speed that up) and then moverec each of the following records down one. Whatever code overhead that'd require, it'd still be faster than add-a-record and then sort the entire DB, I bet, even with a built in dbsort.

I guess what would be handy to have would be a specifiy a key field capability (or assume field 1 is the sort key) and an insert operation that handles under the covers the insertion and bumping down of the following records.

If I have 4 databases in an application, is there a way to create a generic DBInsert function rather than one for each database?

I apologize if these are fundamental questions I ought to be able to deal with!

Thanks
Frank
FrankG
 
Posts: 210
Joined: Thu Jan 23, 2003 7:58 pm

Postby jims on Wed Feb 05, 2003 4:50 pm

Frank,

I have created a couple objects that make dealing with multiple databases much easer, at least for me. And yes, I do always make the "Record Index" the first element in the database record. Then you can write a function that just reads the Index of each record and maps that to the database index, which is really fast. Also, I try to pack all the sortable elements at the start of the record. That way I don't have to read the entire record when doing a sort.

You can see the example in the Survey source code which is available at:
http://members.cox.net/jims2/. The sort example at the bottom of RecordManager.oc, the routine uses a couple functions from my ofLib source code, but you can easily change them to the real db functions.

Please if you (or anyone else) has suggestions on a better way to sort db records let me know.

Thanks,
jim
jims
 
Posts: 34
Joined: Wed May 22, 2002 4:01 pm
Location: USA

Postby FrankG on Thu Feb 06, 2003 7:24 pm

Jim,

Thank you for the sample. That's a great example of using OO to make your life easier.

I played around with moverec and now keeping a database ordered is easier than I expected because of the little note in the moverec help that the move could cause indexes to change. Once I figured out what that meant, it became an easy three step process:<br />1) find the insertion point in the database for the new record<br />2) Create the record at the end of the data<br />3) Moverec the last record to the insertion point index.

No need to loop through the rest of the database to bump each record out; moverec handles it.

Back in business,
Frank
FrankG
 
Posts: 210
Joined: Thu Jan 23, 2003 7:58 pm


Return to OrbForms Designer and PocketC Architect

Who is online

Users browsing this forum: No registered users and 1 guest

cron