RE: [PHP-DB] transaction locking

2003-12-08 Thread Angelo Zanetti
Hi ALek,

Yes you can make the column auto_increment. YOu can also make the
incrementations start at a particular value by using the ALTER command. EG:

ALTER TABLE mytable AUTO_INCREMENT = 99;

it will start your next inserted record with 99 for that specific column
value. I am not 100% sure about the values that you already have in your
field. I assume that they are all unique and that you want to start the
increment from the last value +1. anyway hope this helps.

Angelo



Disclaimer 
This e-mail transmission contains confidential information,
which is the property of the sender.
The information in this e-mail or attachments thereto is 
intended for the attention and use only of the addressee. 
Should you have received this e-mail in error, please delete 
and destroy it and any attachments thereto immediately. 
Under no circumstances will the Cape Technikon or the sender 
of this e-mail be liable to any party for any direct, indirect, 
special or other consequential damages for any use of this e-mail.
For the detailed e-mail disclaimer please refer to 
http://www.ctech.ac.za/polic or call +27 (0)21 460 3911

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] transaction locking

2003-12-05 Thread John W. Holmes
Aleks Kalynovych wrote:
I have a couple forms that generate a unique ID based on taking the highest
number in the ID column adding 1 to its value. The problem is that I dont
save that number until the form is submitted. If 2 or more persons fill out
the form at the same time they all get the same
ID number.  I hope that there are some suggestions on how to accomplish this
with a better method
What database are you using? Pretty much all of them have a method for 
generating these numbers internally. Consult your documentation.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] transaction locking

2003-12-05 Thread Miles Thompson
Aleks,

Many programmers learned the hard way that the scheme you are proposing did 
not work when they went from a single user to a networked environment.

You've not said what database you are using. If MySQL you can let it's 
autoincrement increase your key automatically, perhaps feed it back as 
confirmation of completion. Using this you will not get duplicates as the 
insert is unique per connection. Check the MySQL docs for the last insert id.

Try this - it works and takes a load off your code.

Alternately, if you want to use your own scheme, establish a lookup table 
with two fields: keyvalue and tablename. Write a function that with the 
table name as a parameter, locks the table, retrieves the keyvalue, adds 
one to it, updates and exits. You will have to test for locks, you may end 
up with gaps in your key numbers.

If possible, let the database do the work for you.

Regards - Miles Thompson

At 06:11 AM 12/5/2003 -0700, Aleks Kalynovych wrote:
Good morning all,

I have a couple forms that generate a unique ID based on taking the highest
number in the ID column adding 1 to its value. The problem is that I don’t
save that number until the form is submitted. If 2 or more persons fill out
the form at the same time they all get the same
ID number.  I hope that there are some suggestions on how to accomplish this
with a better method
TIA for your help

Aleks

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP-DB] transaction locking

2003-12-05 Thread Aleks K
 
Thanks Miles and John for you answers... Yes I am using MySQL.
I think I can work it to use the dB to generate these. I ran into 
The problem originally because this dB was taking up where a different
Tool was ending and I needed to start with a specific number scheme. Here
Is a though... If I have a field in MySQL that had numbers already populated
Along with an auto incremental column... Can I remove this auto column and
Change the properties of the already populated column to auto generate? Will
It accept the numbers already there or will I have to start from scratch?

In other words I know that in the dB if you setup a new table and set a
column\
To auto increment, it starts a the number 1. Can this be set to a higher
number
Say 5454 ??

TIA

Aleks
-Original Message-
From: Miles Thompson [mailto:[EMAIL PROTECTED] 
Sent: Friday, December 05, 2003 8:24 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] transaction locking

Aleks,

Many programmers learned the hard way that the scheme you are proposing did
not work when they went from a single user to a networked environment.

You've not said what database you are using. If MySQL you can let it's
autoincrement increase your key automatically, perhaps feed it back as
confirmation of completion. Using this you will not get duplicates as the
insert is unique per connection. Check the MySQL docs for the last insert
id.

Try this - it works and takes a load off your code.

Alternately, if you want to use your own scheme, establish a lookup table
with two fields: keyvalue and tablename. Write a function that with the
table name as a parameter, locks the table, retrieves the keyvalue, adds one
to it, updates and exits. You will have to test for locks, you may end up
with gaps in your key numbers.

If possible, let the database do the work for you.

Regards - Miles Thompson

At 06:11 AM 12/5/2003 -0700, Aleks Kalynovych wrote:
Good morning all,

I have a couple forms that generate a unique ID based on taking the 
highest number in the ID column adding 1 to its value. The problem is 
that I don’t save that number until the form is submitted. If 2 or 
more persons fill out the form at the same time they all get the same 
ID number.  I hope that there are some suggestions on how to accomplish 
this with a better method

TIA for your help

Aleks

--
PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: 
http://www.php.net/unsub.php

--
PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] transaction locking

2003-12-05 Thread Opec Kemp [ q u a s a r z ]
Hi, 

Aleks Kalynovych wrote:
 I have a couple forms that generate a unique ID based on taking
 the highest
 number in the ID column adding 1 to its value. The problem is that I
 dont save that number until the form is submitted. If 2 or more
 persons fill out
 the form at the same time they all get the same
 ID number.  I hope that there are some suggestions on how to
 accomplish this
 with a better method

You really should avoid using this method precisely because of the concurrency issue 
that will invariably happen. If you're using MySQL and your ID field is of type 
AUTO_INCREMENT then you can use MySQL built-in method named: LAST_INSERT_ID() or in 
PHP you can use a function named: mysql_insert_id()

http://www.php.net/mysql_insert_id

For more information visit:
http://www.mysql.com/doc/en/example-AUTO_INCREMENT.html

This is concurrency safe so you shouldn't have this problem in the future.

HTH

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] transaction locking

2003-12-05 Thread Miles Thompson
Aleks,

Every time I've dumped and moved a database with autoincrement fields the 
numbering has picked up where it left off.

Dump the database, including the data, adjust the field type in the 
database schema, and reload.

Regards - Miles

At 09:36 AM 12/5/2003 -0500, Aleks K wrote:
Thanks Miles and John for you answers... Yes I am using MySQL.
I think I can work it to use the dB to generate these. I ran into
The problem originally because this dB was taking up where a different
Tool was ending and I needed to start with a specific number scheme. Here
Is a though... If I have a field in MySQL that had numbers already populated
Along with an auto incremental column... Can I remove this auto column and
Change the properties of the already populated column to auto generate? Will
It accept the numbers already there or will I have to start from scratch?
In other words I know that in the dB if you setup a new table and set a
column\
To auto increment, it starts a the number 1. Can this be set to a higher
number
Say 5454 ??
TIA

Aleks
-Original Message-
From: Miles Thompson [mailto:[EMAIL PROTECTED]
Sent: Friday, December 05, 2003 8:24 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] transaction locking
Aleks,

Many programmers learned the hard way that the scheme you are proposing did
not work when they went from a single user to a networked environment.
You've not said what database you are using. If MySQL you can let it's
autoincrement increase your key automatically, perhaps feed it back as
confirmation of completion. Using this you will not get duplicates as the
insert is unique per connection. Check the MySQL docs for the last insert
id.
Try this - it works and takes a load off your code.

Alternately, if you want to use your own scheme, establish a lookup table
with two fields: keyvalue and tablename. Write a function that with the
table name as a parameter, locks the table, retrieves the keyvalue, adds one
to it, updates and exits. You will have to test for locks, you may end up
with gaps in your key numbers.
If possible, let the database do the work for you.

Regards - Miles Thompson

At 06:11 AM 12/5/2003 -0700, Aleks Kalynovych wrote:
Good morning all,

I have a couple forms that generate a unique ID based on taking the
highest number in the ID column adding 1 to its value. The problem is
that I don’t save that number until the form is submitted. If 2 or
more persons fill out the form at the same time they all get the same
ID number.  I hope that there are some suggestions on how to accomplish
this with a better method

TIA for your help

Aleks

--
PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php