• 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: EOAdaptorChannel's evaluateExpression()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EOAdaptorChannel's evaluateExpression()


  • Subject: Re: EOAdaptorChannel's evaluateExpression()
  • From: Ricardo Parada <email@hidden>
  • Date: Wed, 13 Jul 2005 20:40:30 -0500




Actually what I'm doing is database independent believe it or not.  I build the SQL string using EOSQLExpressionFactory and EOSQLExpression. For example, the SELECT FROM ... WHERE ... part of the string is built by building first a fetch specification and then calling the EOSQLExpressionFactory's selectStatementForAttributes() method to get an EOSQLExpression object given the fetch specification.  I then invoke the following methods on the EOSQLExpression object:

tableListWithRootEntity()
joinClauseString()
whereClauseString()
 
which gives the the SQL that goes in after the FROM and the WHERE clause in the statement I'm building.

I then create a second EOSQLExpression.  Using the full SQL string I built invoke call the setStatement() method in this _expression_ and pass in the SQL string.  Finally I just copy the bindings from the first _expression_ to this second _expression_ using code similar to this:

        Enumeration enumeration = tempExpression.bindVariableDictionaries().objectEnumerator();
        while (enumeration.hasMoreElements()) {
            NSDictionary binding = (NSDictionary)enumeration.nextElement();
            main_expression_.addBindVariableDictionary(binding);
        }


I can then execute the resulting _expression_ which has the full INSERT-SELECT statement.

By the way I'm assuming that the INSERT-SELECT is standard.  But maybe it is ORACLE-specific.  :-)


Thanks for the suggestion.

Ricardo


On Jul 13, 2005, at 11:23 AM, email@hidden wrote:

On 13 Jul 2005, at 02:03, Ricardo Parada wrote:



Hi,

I created an instance of EOSQLExpression that contains a SQL statement 
similar to this:

INSERT INTO ...
SELECT ...
FROM ...
WHERE ...

I then use the EOAdaptorChannel's evaluateExpression() to execute the 
_expression_.  The SQL statement executes great and I'm able to insert a 
ton of records with a single SQL statement.  (I love EOF  :-) )

However, I'm wondering if I can get the number of records inserted.  I 
tried using EOAdaptorChannel's fetchRow() but I get nothing back.  
Right now the work around is to build and execute a separate 
EOSQLExpression that counts the records inserted, e.g. something like 
this:

SELECT COUNT(*)
FROM ...
WHERE ...

It works great but it would be nicer if I could get the number of 
records inserted when I execute the insert-select statement.  Then I 
wouldn't need to create and execute the counting _expression_.

Thanks,
Ricardo Parada
Medical Present Value, Inc.


Using Sybase, you can obtain the count of rows affected:
    select @@rowcount
and I would expect other RDBMSs to offer comparable facilities.
This approach would mean that your app uses RDBMS-specific SQL, but you 
appear to be doing that already.  You would also need to working at the 
adaptor level to fetch the results from 'select @@rowcount' or 
whatever, but you're doing that already too.

Failing that... you could go hacking.  A while back I had a problem 
with JDBCChannel.cancelFetch() not invoking 
java.sql.Statement.cancel(), which I fixed by making my own JDBC 
Adaptor -- I subclassed JDBCAdaptor, JDBCContext and JDBCChannel in 
order to be able to get at a protected ivar _statement in JDBCChannel, 
so that I could call JDBC API.

See also "EOFetchSpecification.setFetchLimit(), 
EOAdaptorChannel.cancelFetch(), etc" which I posted to 
email@hidden on 17 Jul 2003, which included source 
code.




 _______________________________________________
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

  • Prev by Date: Re: Programatically calling Direct Actions
  • Next by Date: Re: EOModeler Issue
  • Previous by thread: Re: EOAdaptorChannel's evaluateExpression()
  • Next by thread: WO free on Windows?
  • Index(es):
    • Date
    • Thread