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: Sun, 09 May 2004 14:30:44 +0200
User-agent: Mozilla Thunderbird 0.6 (Windows/20040502)


Thanks - it works fine: for mysql you can name the sequence whatever you want (a table is created) - but for pgsql - you have to name a valid existing sequence (<table_name>_<column_name>_seq)

Sigurd

Joseph Engo wrote:
When you request a sequence that doesn't exist, it will create it.  I
believe the format we are going to use for sequence names is as follows.

phpgw_<app>_<table [optional]>_seq

For a simple app like notes, you don't need the table name.  You can
use phpgw_notes_seq
A  multi-table app could look like: phpgw_addressbook_contacts_seq

Keep in mind, there *IS* a size limit on the field name.  So, if you
need to shorten it to phpgw_ab_contacts_seq, thats acceptable.

Once you pick a name for your sequence, DON'T change it.  We will
create some sort of upgrade path later for this.

Also, in regards to tables.  Even though upgrades aren't presently
supported, any time you make changes to your tables, change your
version number.

IE, 1.9.0.001 -> 1.9.0.002

This way, we know if we need to recreate our database.

Sigurd Nes wrote:

| 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
|
|
|
|
|
|
| _______________________________________________
| 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]