[TriLUG] Yet another c++ question

Owen Berry oberry at trilug.org
Wed Nov 16 09:56:12 EST 2005


If you want unique id's for records that aren't being inserted into the
database, you can also create a sequence in the database, which you can
then query to get the next id.

Postgres:
   create sequence myseq increment by 1 start with 1500000 no cycle;
   select nextval('myseq');

Oracle:
   create sequence myseq increment by 1 start with 1500000 nocycle;
   select myseq.nextval from dual;

MySql:
   create table seqtable (id unsigned bigint not null auto_increment,
   primary_key(id));
   insert into seqtable(null);
   select last_insert_id();

Haven't double checked the syntax against a database, but you get the
idea. MySql is a little kludgy for this particular idea, and you might
need to do some more fiddling to get a starting value.

BTW, you'll still need good backups, no matter where your "index" is
stored - files can be deleted, drives can crash, just like the Windows
registry can be corrupted.

Owen

On Tue, Nov 15, 2005 at 11:29:00AM -0500, Steve Kuekes wrote:
> I think your key needs to be stored in the database and let the database 
> automatically handle it for you. For SQLServer you need to create the 
> table with a column with the IDENTITY attribute.  This tells SQLServer 
> to automatically populate the field with a unique value and increment it 
> according to your definition (you don't have to increment by 1 if you 
> don't want to).  MYSQL had the same type of thing its just called 
> AUTOINCREMENT.  You can even have the IDENTITY column start its counter 
> at other than zero so you can move your data in and start where your 
> registry key leaves off.
> 
> Having the database handle this even handles multiple programs inserting 
> rows into the database at the same time.  After you insert each row you 
> can read the value the database assigned to the field by using "SELECT 
> @@IDENTITY".
> 
> 
> Mark Freeze wrote:
> >I do store my records in a SQLServer database that I am going to be
> >moving to MySql.  Thanks for the info on the Oracle system.  That may
> >influence my databasing decisions when I get to that step.
> >
> >I think Phillip has hit a little closer to what I am looking for, but
> >I still was looking for a different solution.
> >
> >My Windows system has a key stored in the registry with one value.
> >Which lets say for examples sake is 16E360. (Or 1.5 million.)  My VB
> >program would get this value and then assign my first record the
> >unique key of 16E361, then the next 16E262, etc... until the program
> >gets to the eof of the text file currently being processed.  At eof,
> >the VB program writes the last assigned keys value back to the
> >registry to wait until the program needs more unique values. This week
> >I processed 149,893 records, so the registry value would now be
> >192CE5.
> >
> >I know Linux doesn't have a registry so I am looking for a more secure
> >way of keeping track of this value other than just writing it to a
> >file somewhere on the disk.  If writing this value to a file is the
> >only way to keep track of it, what are some methods that I could
> >employ to secure the file so that it is not deleted, lost,
> >overwritten, or tampered with but still remains open enough where any
> >user could run the program?
> >
> >Thanks,
> >Mark.
> >
> >
> >On 11/15/05, Dave Sorenson <dave at logicalgeek.com> wrote:
> >
> >>I second the database idea. Having the registry hold mission critical
> >>data would scare the bejebus outta me seeing how often my windows gaming
> >>box decides to scramble its registry. Databases are made for this and
> >>even MySQL could handle a million or 2 statements without too much
> >>trouble. Oracle has released 10g in a no cost form, some restriction
> >>apply, but it might work well as well. See:
> >>http://www.oracle.com/corporate/press/2005_oct/103105_databasexe_finalsite.html.
> >>I'm going to be installing on my test server and play with it and see if
> >>it can be useful.
> >>
> >>Dave S.
> >>
> >>Phillip Rhodes wrote:
> >>
> >>>On 11/15/05, Mark Freeze <mfreeze at gmail.com> wrote:
> >>>
> >>>
> >>>>My question is this: What would be the best way on a Linux system to
> >>>>keep track of this unique key identifier? Or is there a better way to
> >>>>accomplish this task? I chose to write it to the Windows registry with
> >>>>VB so it wouldn't get deleted from the disk, it was not easily
> >>>>tampered with by users of the program, and really, it was just one
> >>>>less file that I had to keep up with. Having the key off by even one
> >>>>record could potentially catastrophic. I keep these files forever and
> >>>>I process and print around 1 million statements per month.
> >>>>
> >>>
> >>>
> >>>I probably just don't understand your process well enough to comment,
> >>>but it seems to me like it might be easier to just pump the data into
> >>>an RDBMS as step 1 and then rely on the facilities the RDBMS
> >>>provides for doing a lot of this other stuff... Is there a specific 
> >>>reason
> >>>why that isn't an option?
> >>>
> >>>Failing that, Linux has no registry per se, so you'd probably just have
> >>>to write your key values out to a file somewhere, or store the keys in an
> >>>RDBMS.
> >>>
> >>>
> >>>TTYL,
> >>>
> >>>Phil
> >>>



More information about the TriLUG mailing list