Xcode 4 and Core Data: How to enable SQL Debugging

38,243

Solution 1

You should be looking at the same place you get NSLOGS

And you should Go to Product -> Edit Scheme -> Then from the left panel select Run YOURAPP.app and go to the main panel's Arguments Tab.

There you can add an Argument Passed On Launch.

You should add -com.apple.CoreData.SQLDebug 4 (number between 1 and 4, higher number makes it more verbose)

Press OK and your are all set.

The key here is to edit the scheme you will be using for testing.

Solution 2

XCode 4

It's in the same place I manage my NSZombieEnabled

Product -> Edit Scheme -> Run YouApp.app Debug

Under "Arguments Passed on Launch", paste in exactly:

-com.apple.CoreData.SQLDebug 1

Warning - this stuff is very verbose, if you're having Core Data issues, this might be well worth looking at, but it may also be more info than you need about the wrong thing.

Solution 3

I was having a problem with this and then realized it was a silly omission, which I assume is a comer mistake for some of you. When I entered the argument in Xcode (4.3.1), I left out the leading hyphen. I wouldn't have done so were I entering it on a command line, but in the GUI I had omitted it. I didn't find any difference between entering at 2 separate args or one (as some posts had suggested). So use:

-com.apple.CoreData.SQLDebug 1

and not simply:

com.apple.CoreData.SQLDebug 1

that worked for me in both simulator and real device

Solution 4

Note that you can put in different levels of the value passed. Which provide more and more verbosity.

-com.apple.CoreData.SQLDebug 1
-com.apple.CoreData.SQLDebug 2
-com.apple.CoreData.SQLDebug 3
-com.apple.CoreData.SQLDebug 4 // This will actually show parameter binds ("?")
Share:
38,243

Related videos on Youtube

oalders
Author by

oalders

Most of my software development time is spent writing Perl and Go.

Updated on July 08, 2022

Comments

  • oalders
    oalders almost 2 years

    I'm working on a universal iOS app and I'd like to see the raw SQL in the logs when I'm debugging. There is some info in this blog post about how to enable raw SQL logging for iOS Core Data development. The given example is for Xcode 3 and it's just not clear to me how to enable this in Xcode 4.

    I've tried "Product" -> "Edit Scheme" and added "-com.apple.CoreData.SQLDebug 1" to "Arguments Passed on Launch", but I'm still not seeing any output in the logs. Not sure if I'm looking in the wrong place or just passing the arguments incorrectly.

    • oalders
      oalders almost 13 years
      Thanks for this. My main issue is that the table I'm searching on has just over 74,000 rows and I wanted to get an idea of how long queries are running for, since it's quite slow right now. I respect the fact that there's a whole lot of abstraction going on, but I was really in the dark about what was going on under the hood. This at least helps me just a little bit.
    • TechZen
      TechZen almost 13 years
      As long as you understand the limitations, it's fine to look at the raw SQL, especially for performance tweaking. Where people get into trouble is trying to figure out how the object graph is behaving by looking at the raw SQL. Since there is no direct relationship between the two, it just lead them astray.
    • Felipe Sabino
      Felipe Sabino almost 3 years
      Does this answer your question? How to print Core Data debug values?
  • oalders
    oalders almost 13 years
    Thanks for this. Turns out, as far as the simulator goes, the format of my arguments was wrong as I see in one of the answers here stackoverflow.com/questions/822906/… I need to pass an argument of -com.apple.CoreData.SQLDebug and a second argument of 1 in order to see the SQL output.
  • Felipe Sabino
    Felipe Sabino over 11 years
    any thoughts on how to print the arguments that are passed to the database? this approach works fine to see how the query is being structured, but it print only the sql statement, like UPDATE ZTABLE SET ZCOLUMN = ? WHERE ZID = ? and it is not very useful to really see what is the data being sent
  • Felipe Sabino
    Felipe Sabino over 11 years
    Actually, I thought it would be better to add it as a real SO question ;) stackoverflow.com/questions/12306343/…
  • Bishal Ghimire
    Bishal Ghimire over 10 years
    is there any way i can log only if it inserts into database not for other case ?
  • Nicolas S
    Nicolas S over 10 years
    @BishalGhimire I'm not sure, maybe you could filter by event somewhere. I would filter the output directly using text filtering.
  • rhlnair
    rhlnair over 9 years
    Any way to print this -com.apple.CoreData.MigrationDebug 1 on string file, so that user can upload the log file