• 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: obtain SQL query
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: obtain SQL query


  • Subject: RE: obtain SQL query
  • From: "Pierre Bernard" <email@hidden>
  • Date: Mon, 18 Aug 2003 11:17:48 +0200
  • Thread-topic: obtain SQL query

Hi!

Start off with this:

String entityName	= fetchSpecification.entityName();
EOEntity entity = EOModelGroup.defaultGroup().entityNamed(entityName);
Class expressionClass = ((EOAdaptor) EOAdaptor.adaptorWithModel(entity.model())).expressionClass();
Constructor	constructor	= expressionClass.getConstructor(new Class[] { EOEntity.class });
EOSQLExpression expression = (EOSQLExpression) constructor.newInstance(new Object[] { entity });
EOQualifier qualifier = fetchSpecification.qualifier();

if (qualifier != null)
{
   fetchSpecification = (EOFetchSpecification) fetchSpecification.clone();
   fetchSpecification.setQualifier(entity.schemaBasedQualifier(qualifier));
}

expression.prepareSelectExpressionWithAttributes(entity.attributesToFetch(), false, fetchSpecification);

if (expression.bindVariableDictionaries() != null)
{
   returnSqlString = (String) fillBindings(expression, expression.statement())
}
else
{
   returnSqlString = expression.statement();
}

public static String fillBindings(EOSQLExpression  expression, String sqlString)
{
   String query = sqlString;
   NSArray bindVariables = expression.bindVariableDictionaries();
   int count = bindVariables.count();

   for (int i = 0; i < count; i++)
   {
      NSDictionary variable = (NSDictionary) bindVariables.objectAtIndex(i);
      Object value = variable.objectForKey(EOSQLExpression.BindVariableValueKey);
      EOAttribute attribute = (EOAttribute) variable.objectForKey(EOSQLExpression.BindVariableAttributeKey);
      String placeholder = (String) variable.objectForKey(EOSQLExpression.BindVariablePlaceHolderKey);
      String replacement = formatValueForAttribute(value, attribute);
      query = query.substring(0, query.indexOf(placeholder)) + replacement + query.substring(query.indexOf(placeholder) + placeholder.length());
   }

   return query;
}

Pierre

--
Got a hang for movies?
http://homepage.mac.com/I_love_my/movies.html

-----Original Message-----
From: Alex Blaj [mailto:email@hidden]
Sent: Monday, August 18, 2003 10:06 AM
To: email@hidden
Subject: obtain SQL query


Hi there,

Does anyone know of a way to obtain the SQL query formed by the EOF before
sending it to a database?

Thanks,
Alex.


===================================================================Lettrix bv,
P.O. Box 5, 6980 AA Doesburg,
The Netherlands -- Tel: +31 313 478 000,
Fax: +31 313 478 080 -- Check our website at:
http://www.lettrix.com
===================================================================Disclaimer
:
The information contained in this communication is confidential and
may be legally privileged. It is intended solely for the use of the
individual or entity to whom it is addressed and others authorised to
receive it. If you are not the intended recipient you are hereby
notified that any disclosure, copying, distribution or taking any
action in reliance on the contents of this information is strictly
prohibited and may be unlawful. Lettrix B.V. is neither liable for
the proper and complete transmission of the information contained in
this communication nor for any delay in its receipt.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.


**********************************************************************
This email and any files transmitted with it are intended solely for
the use of the individual or entity to whom they are addressed.
If you have received this email in error please notify the sender
of this message. (email@hidden)
This email message has been checked for the presence of computer
viruses; however this protection does not ensure this message is
virus free.
Banque centrale du Luxembourg; Tel ++352-4774-1; http://www.bcl.lu
**********************************************************************
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: obtain SQL query
  • Next by Date: WO build queries
  • Previous by thread: obtain SQL query
  • Next by thread: WO build queries
  • Index(es):
    • Date
    • Thread