Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > auto increement in realbasic

auto increement in realbasic
Thread Tools
Mac Enthusiast
Join Date: Jun 2000
Location: New York, NY
Status: Offline
Reply With Quote
Apr 21, 2002, 10:10 AM
 
I'm making an application that uses a realbasic database. i want to have an ID field that auto increments. can i do this with a realDB? if not, does anyone know of a work around?

Thanks in advance
12" Aluminum Powerbook
1.5Ghz G4 | 512Mb Ram | GeForce FX Go5200
     
Fresh-Faced Recruit
Join Date: Apr 2002
Status: Offline
Reply With Quote
Apr 24, 2002, 03:07 PM
 
*Disclaimer: I don't know jack about realdb, or realbasic, I don't know if it uses normal sql or not... use at your own risk*

A quick work around for your application could be to control it at the app level... in your database create an int field that is just going to be for your sudo auto-increment number.

At the beginning of your application (on startup) do a select from the database grabbing the max number from that column (something like SELECT MAX(COUNTER) FROM MYTABLE, where COUNTER is your int field described above), put that value into a variable, say COUNTER_HOLDER...

So you should have something that slightly resembles this in action:

int COUNTER_HOLDER
COUNTER_HOLDER = SELECT MAX(COUNTER) FROM MYTABLE

this will take the highest number in the database, and store it in COUNTER_HOLDER. Then when you insert rows into the database, you would increment COUNTER_HOLDER (using COUNTER_HOLDER = COUNTER_HOLDER + 1, or COUNTER_HOLDER++, however you do it..) then use that new number on the insert... Make sure to account for failed inserts by decrementing COUNTER_HOLDER on a failure.

easy enough, huh?

Mike
------------------------------
Always remember: A friend will help you move, a good friend will help you move a body.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:51 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2