Re: What class generates the sql?
Re: What class generates the sql?
- Subject: Re: What class generates the sql?
- From: Jonathan Rochkind <email@hidden>
- Date: Tue, 13 Apr 2004 13:06:31 -0500
This is a tricky thing to do, there aren't any methods to make it
easy for you, you've really got to dig about in the underbelly of EOF.
I'll give you some code that _might_ work to get an
EOFetchSpecification to generate SQL for you. It won't actually send
this SQL to the db; you'll need to execute the EOFetchSpec in a
normal way when you want to execute it. But I think it should work to
do what you want, although it might fail in some circumstances (if
the fetch spec has rawRowKeyPaths set, for instance, you won't get
the same SQL). I'm not at all confident in this code, it may not work
right at all, but maybe it's better than nothing.
EOFetchSpecification spec; //assume exists
String entityName; //assume exists: the entity name you are fetching on
EOEditingContext ec; //assume exists, an EC you could use to fetch
EOEntity entity = EOUtilities.entityNamed( ec, entityName );
EODatabaseContext dbContext =
EODatabaseContext.registeredDatabaseContextForModel(entity.model(),EOObjectStoreCoordinator.defaultCoordinator());
EOSQLExpressionFactory factory =
context.database().adaptor().expressionFactory();
EOSQLExpression expression = factory.expressionForEntity(entity);
expression.setUseAliases(true);
//We need to find all attributes that are class properties
NSSet allClassProperties = new NSSet(entity.classProperties());
//relationships and attributes
NSSet allAttributes = new NSSet( entity.attributes()); //all attributes
NSSet attributeClassProperties =
allClassProperties.setByIntersectingSet( allAttributes );
expression.prepareSelectExpressionWithAttributes(attributeClassProperties.allObjects(),
false,
spec);
String sql = expression.statement();
Good luck, maybe that'll work for you, maybe not.
--Jonathan
At 10:36 AM -0700 4/13/04, Ray Kiddy wrote:
Perhaps I am confused.
The original post said that the desire was to show the SQL to the user.
How will turning on EOAdaptorDebugEnabled, which writes to the
console, help the user?
Please share.
thanx - ray
On Apr 13, 2004, at 1:07 AM, Sam Hart wrote:
No one class generates the SQL in EOF, it tends to be a
collaborative effort :)
If you want to see the SQL generated without jumping through hoops
an old favorite is
to set
-EOAdaptorDebugEnabled YES
as a command line argument to your app ( err.... under the targets
tab I think )
S a m
------------------------------------------------------------------------------
Drawing on my fine command of language, I said nothing.
_______________________________________________
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.
Hi,
I cannot seem to find which class in EOF generates the sql. I have
a fetchSpec that I would like to display to the user the sql that
it will create.
Does anyone know how to achieve this?
Thanks,
Greg
_______________________________________________
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.
_______________________________________________
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.
_______________________________________________
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.