• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: EOF inserts PK automatically
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EOF inserts PK automatically


  • Subject: Re: EOF inserts PK automatically
  • From: Chuck Hill <email@hidden>
  • Date: Mon, 22 Nov 2004 11:21:53 -0800

Hi Frank,

Yes, if you absolutely _need_ to work with a database schema that used identity columns and you are willing to go to the lengths that you describe, then you can. But this is not using EOF. That was, as you guessed, my point.

Off-list Michael Müller pointed out that I may no longer be correct:
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/ Statement.html#getGeneratedKeys()


Apparently it is possible with modern JDBC drivers and modern (compared to the last time I peered into the depths of JDBC) to determine the value used in an identity column after an insert. If this functionality is available to you, then it may be possible to bend EOF into using this. The problem will be that EOF expects the PK to be cast in stone at a certain point and I am not sure if you could get the PK back and update the EO before EOF records the permanent PK. If not, then you are back to forgetting and refetching the object.


Chuck



On Nov 22, 2004, at 1:00 AM, Ruenagel, Frank wrote:

Hi Chuck,

I really love your contributions. They have often helped me.
But in this case IMHO it *is* possible to get WO running with
identity columns.  True is that you cannot use the standard
mechanisms for insert (and I guess you mean that).

In case of insert into a table with a identity-column EOF has to be
informed about the pk which is not created by itself. EOF has to
be forced to stay away from any insert.
EOUtilties.ObjectForPrimaryKey works fine with PKs EOF has not
seen before, because he makes a database roundtrip in this case and
creates the object for you:

1. You want to insert an new record
2. Execute a stored procecure which inserts a new record and
   gives back its primary key. I use a marker in a special column
   to find the newly created record after insert.
3. Create the EO with EOUtilities.objectWithPrimaryKeyValue

Dear Chuck, are there any reasons why this should not work?

Best regards
Frank


Perhaps it is worth wading into this one more time. Using database generated unique numbers (a.k.a. sequences) is not a problem. As Benjamin points out below, it is just a matter of some code in the plugin or even in your app as a delegate method to one of the EOAccess classed (I forget which off the top of my head and am too lazy to look it up).

Another way that databases generate the primary key is what is often
referred to as an identity column.  The values in this column are
filled in by the database when the row is inserted.  The method of
primary key generation can NOT be used with WO, or any other
environment that does not use some proprietary database
access method.
If you think about it you will quickly see why it won't work.
 You have
some data, but no primary key.  You insert it, and the PK is
created by
the database and added to the data.  But _you_ are never told
what the
PK is.  SQL INSERT only returns a success or failure code, not a copy
of the inserted data.  So now you have the data, but not the primary
key (which you have no way of knowing) and the database has the same
data _and_ the primary key.  Now, how are you going to update that
exact row if you don't know the PK?  You could the row where all the
other values are the same, but there is no guarantee that
this defines
a unique row.  In many, many cases it does not define a
unique row, it
defines a set of rows.  How are you going to know which one
the the one
you just inserted?  In a nutshell, you can't.

Your only hope for using this with WO is to:
1. Somehow force it to not generate the PK and use null as the insert
value.  If the database takes 0 as null, then this is easy
2. After insertion _immediately_ tell the ec to forget the
object (not
invalidate, forget).
3. The user will then have to somehow fetch some data that includes
this new object.

Me, I'd stay far away from that.

Chuck


On Nov 19, 2004, at 10:58 AM, Benjamin J Doherty wrote:

On Nov 19, 2004, at 3:33 AM, Sako! wrote:

if you read my first or second post, you will mention i use MS-SQL.
and tipically Apple talks about all the world ECCEPT MS-SQL.
"Apple hates Microsoft" why do i wonder?

Mention this sentence in the site:
" It doesn't work if the database includes rows that are
inserted by
non-Enterprise Objects applications."
so what the hell do i have as a solution then? non.
this sentence tells me i have to forget the PK feature in EOF.
Ok fine. my first question was and still:  how can i force
EOF to stop
trying to use this week pk feature(s)?


I don't know ANYTHING about MS-SQL, but I assume that like most databases it has some support for sequences. If you want
to use these
instead of that (agreed) weak EO_PK_TABLE, just subclass the MS-SQL
adapter, rework the code from the PostgresqlPlugIn from
Project Wonder
(which uses sequences to generate primary keys), and voilà sommes
nous.

But I wasn't following the whole discussion, so I admit I
may not be
on the nose here.

Benjamin J Doherty
sole proprietor
!&# Group
www.bangpound.org
+1-773-934-4236
--
Practical WebObjects - a book for intermediate WebObjects developers
who want to increase their overall knowledge of WebObjects, or those
who are trying to solve specific application development problems.
http://www.global-village.net/products/practical_webobjects



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden

This email sent to email@hidden

--
Practical WebObjects - a book for intermediate WebObjects developers who want to increase their overall knowledge of WebObjects, or those who are trying to solve specific application development problems.
http://www.global-village.net/products/practical_webobjects




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: EOF inserts PK automatically (From: "Ruenagel, Frank" <email@hidden>)

  • Prev by Date: Booking app someone?
  • Next by Date: Re: EOF inserts PK automatically
  • Previous by thread: Re: EOF inserts PK automatically
  • Next by thread: Re: EOF inserts PK automatically
  • Index(es):
    • Date
    • Thread