phpgroupware-developers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Phpgroupware-developers] proposal-branch; porting


From: Sigurd Nes
Subject: Re: [Phpgroupware-developers] proposal-branch; porting
Date: Sat, 08 May 2004 10:30:18 +0200
User-agent: Mozilla Thunderbird 0.6 (Windows/20040502)

How do I define the table I want the next ID for when using genid('<sequence_name>')?

Do I need the 'sequence_name' ? if so – how do I get it?

Sigurd

Joseph Engo wrote:
$GLOBALS['phpgw']->db->begintrans();
$id = $GLOBALS['phpgw']->db->genid('<sequence_name>');
$GLOBALS['phpgw']->db->execute("insert into table x (id,value) values
($id,'x')");
[ ... ]
[ ... ]
[ ... ]
[ ... ]
$GLOBALS['phpgw']->db->committrans();

Your example is not reliable there is a chance of a race condition,
which is why we are using genid()

Sigurd Nes wrote:

| How would it be to compute the next id for instertion inside a
| transaction ?
|
| $GLOBALS['phpgw']->db->begintrans(); $dbresult =
| $GLOBALS['phpgw']->db->Execute("SELECT max(id) as max_id FROM
| $table"); $next_id = $dbresult->fields['max_id']+1;
| $GLOBALS['phpgw']->db->Execute("INSERT INTO $table ...
| $GLOBALS['phpgw']->db->committrans();
|
| Sigurd
|
| Joseph Engo wrote:
|
|> Just a follow up on this, I did some research on how ADODB
|> handles sequences / last insert ID number for cross database
|> support. - For MySQL, it will create a table named
|> <sequence_id_name> and update that when you request the next id
|> number. ~  This also holds true for any databases which don't
|> support native sequences. - PostgreSQL will keep using its build
|> in sequence support.  It will just do a
|> nextval('<sequence_id_name>')
|>
|> Keep in mind, you *must* request an ID number *before* you do
|> your insert.  At that time, you must specify the new ID number in
|> your insert.
|>
|> I don't like how it creates a seperate table for each sequence,
|> it really clutters things up.  I would prefear to create a
|> generic single table to handle all of these.  However, I want to
|> wait until more databases are tested to make sure its all going
|> to fit together.  Presently, you must specify the PostgreSQL
|> generated sequence name.  I want to develop our own naming
|> conventions for this, kind of like what schemaproc does.  This
|> will need to be changed in ADODB, I am going to contact that
|> developers of the AXMLS and ADODB to have this added in a future
|> release.  I want to make as little, if any changes to there code.
|> Make sure its up to date.
|>
|> If anyone is porting or working on apps for the new framework,
|> please follow the above method.  Once you come up with some
|> standard names, it won't be hard to make changes.
|>
|> Joseph Engo wrote:
|>
|> | Dan Kuykendall wrote: | | | Joseph Engo wrote: | |> -----BEGIN
|> PGP SIGNED MESSAGE----- Hash: | SHA1 |> |> |
|> $GLOBALS['phpgw']->db->get_last_insert_id() | This is | something
|> |> I need to add.  Its very easy to do for PostgreSQL, | but
|> MySQL is |> more of a pain.  For now, I am just doing a select |
|> after I add |> the record.  Which will be fixed later once |
|> get_last_insert_id() |> is ported.  AdoDB doesn't, from what I |
|> understand have something |> like this, or its something they |
|> removed over time for whatever |> reason. | | | Why do you think
|> it | was removed? | | |
|> http://phplens.com/lens/adodb/docs-adodb.htm#inserted_id | | |
|> "PostgreSQL returns the OID, which can change on a database |
|> reload." - The OID number is useless to an app developer, it |
|> doesn't return the last insert ID like you think it would.  The
|> OID | number is a unique number for every insert and update,
|> which can be | later referenced to an action. | |
|>
|> _______________________________________________
|> Phpgroupware-developers mailing list
|> address@hidden
|> http://mail.gnu.org/mailman/listinfo/phpgroupware-developers
|>
|>
|
| _______________________________________________
| Phpgroupware-developers mailing list
| address@hidden
| http://mail.gnu.org/mailman/listinfo/phpgroupware-developers
|
|
|
|
|
|
| _______________________________________________
| Phpgroupware-developers mailing list
| address@hidden
| http://mail.gnu.org/mailman/listinfo/phpgroupware-developers



_______________________________________________
Phpgroupware-developers mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/phpgroupware-developers








reply via email to

[Prev in Thread] Current Thread [Next in Thread]