10 Replies - 2966 Views - Last Post: 29 May 2011 - 07:41 AM

#1 Tyre77  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-May 11

SQLite error when accessing iPhone Media Data

Posted 28 May 2011 - 04:08 PM

When running my program to query the iPod library of my iPhone, I get the following output in the console:

CPSqliteStatementPerform: attempt to write a readonly database for UPDATE ddd.ext_container SET orig_date_modified = (SELECT date_modified FROM container WHERE pid=container_pid) WHERE orig_date_modified=0


I also see these errors in the iPhone console in the Organizer:

May 27 22:11:04 unknown sandboxd[2512] <Notice>: QueryTesting(2510) deny file-write-mode /private/var/mobile/Media/iTunes_Control/iTunes/iTunes Library.itlp/Library.itdb
May 27 22:11:04 unknown sandboxd[2512] <Notice>: QueryTesting(2510) deny file-write-data /private/var/mobile/Media/iTunes_Control/iTunes/iTunes Library.itlp/Library.itdb
May 27 22:11:04 unknown sandboxd[2512] <Notice>: QueryTesting(2510) deny file-write-data /private/var/mobile/Media/iTunes_Control/iTunes/iTunes Library.itlp/Dynamic.itdb
May 27 22:11:04 unknown sandboxd[2512] <Notice>: QueryTesting(2510) deny file-write-data /private/var/mobile/Media/iTunes_Control/iTunes/iTunes Library.itlp/Extras.itdb
May 27 22:11:04 unknown sandboxd[2512] <Notice>: QueryTesting(2510) deny file-write-data /private/var/mobile/Media/iTunes_Control/iTunes/iTunes Library.itlp/DBTemp/ddd.itdbm


I have disabled everything that outputs to the console so it isn't as if I am having an error with NSLog. Here is the part that does the searching and puts it into an NSMutableDictionary object to return:

+(NSDictionary *) initWithMPMediaItem:(MPMediaItem *) song andSongNumber: (int)songCount{


//Create & initialize NSStrings for keys
//Create NSArray to hold keys

NSString *songKey = [NSString stringWithFormat: @"%i Song Title", songCount];
NSString *albumKey = [NSString stringWithFormat: @"%i Album", songCount];
NSString *artistKey = [NSString stringWithFormat: @"%i Artist", songCount];
NSString *artistIDKey = [NSString stringWithFormat: @"%i Artist Persistent ID", songCount];
NSString *lastPlayedKey = [NSString stringWithFormat: @"%i Late Played Date", songCount];
NSString *genreKey = [NSString stringWithFormat: @"%i Genre", songCount];
NSString *ratingKey = [NSString stringWithFormat: @"%i User Rating", songCount];
NSString *playCountKey = [NSString stringWithFormat: @"%i Play Count", songCount];

NSArray *propertyKeys = [[NSArray alloc] initWithObjects:songKey, albumKey, artistKey, artistIDKey, 
                        lastPlayedKey, genreKey, ratingKey, playCountKey, nil];

//Create & initialize NSStrings to hold song property information
//Create NSArray to hold the values

NSString *songTitle = [song valueForProperty:MPMediaItemPropertyTitle];
NSString *albumName = [song valueForProperty:MPMediaItemPropertyAlbumTitle];
NSString *artistName = [song valueForProperty:MPMediaItemPropertyArtist];
NSString *artistID = [song valueForProperty:MPMediaItemPropertyArtistPersistentID];
NSString *lastPlayed = [song valueForProperty:MPMediaItemPropertyLastPlayedDate];
NSString *genre = [song valueForProperty:MPMediaItemPropertyGenre];
NSString *userRating = [song valueForProperty:MPMediaItemPropertyRating];
NSString *playCount = [song valueForProperty:MPMediaItemPropertyPlayCount];

NSArray *propertyValues = [[NSArray alloc] initWithObjects:songTitle, albumName, artistName, artistID, 
                           lastPlayed, genre, userRating, playCount, nil];

//Create NSDictionary to store information, initializing it with
//above data, then returning the resulting dictionary

NSDictionary *songInfo = [[NSDictionary alloc] initWithObjects:propertyValues forKeys:propertyKeys];

return songInfo;
}



Just realized I have some memory management to do, but any idea why it thinks I am trying to 'write' read-only data?

Is This A Good Question/Topic? 0
  • +

Replies To: SQLite error when accessing iPhone Media Data

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10364
  • View blog
  • Posts: 38,393
  • Joined: 27-December 08

Re: SQLite error when accessing iPhone Media Data

Posted 28 May 2011 - 04:08 PM

Moved to Objective-C/iPhone.
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6035
  • View blog
  • Posts: 23,418
  • Joined: 23-August 08

Re: SQLite error when accessing iPhone Media Data

Posted 28 May 2011 - 04:20 PM

Quote

CPSqliteStatementPerform: attempt to write a readonly database for UPDATE ddd.ext_container SET orig_date_modified = (SELECT date_modified FROM container WHERE pid=container_pid) WHERE orig_date_modified=0


Um...an update IS a write. Are you saying the DB should not be read-only?
Was This Post Helpful? 0
  • +
  • -

#4 Tyre77  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-May 11

Re: SQLite error when accessing iPhone Media Data

Posted 29 May 2011 - 06:49 AM

View PostJackOfAllTrades, on 28 May 2011 - 04:20 PM, said:

Quote

CPSqliteStatementPerform: attempt to write a readonly database for UPDATE ddd.ext_container SET orig_date_modified = (SELECT date_modified FROM container WHERE pid=container_pid) WHERE orig_date_modified=0


Um...an update IS a write. Are you saying the DB should not be read-only?



I don't know what I am updating is the problem. I querying for MPMediaItems, then taking the valueForProperty: (song/album/artist etc.) and storing that in a string. I even changed the code today so that I don't pass the MPMediaItem into a new class as a parameter and do it all in one class. I shouldn't be doing anything but getting information about the MPMediaItem, nothing about changing it/moving it.

Do you understand the error enough to see what it thinks I'm updating?
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6035
  • View blog
  • Posts: 23,418
  • Joined: 23-August 08

Re: SQLite error when accessing iPhone Media Data

Posted 29 May 2011 - 06:56 AM

Honestly I've never worked with Obj-C and iPhone. I don't even see where a query is occurring so I'm guessing it's happening behind the scenes. Or is the query occurring elsewhere in your code?

NSString *lastPlayedKey = [NSString stringWithFormat: @"%i Late Played Date", songCount];


Should that be

NSString *lastPlayedKey = [NSString stringWithFormat: @"%i Last Played Date", songCount];


? Maybe it's seeing that as an attempt to change the DB because the field key isn't correct?

Sorry, grasping at straws.
Was This Post Helpful? 0
  • +
  • -

#6 Tyre77  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-May 11

Re: SQLite error when accessing iPhone Media Data

Posted 29 May 2011 - 07:01 AM

View PostJackOfAllTrades, on 29 May 2011 - 06:56 AM, said:

Honestly I've never worked with Obj-C and iPhone. I don't even see where a query is occurring so I'm guessing it's happening behind the scenes. Or is the query occurring elsewhere in your code?

NSString *lastPlayedKey = [NSString stringWithFormat: @"%i Late Played Date", songCount];


Should that be

NSString *lastPlayedKey = [NSString stringWithFormat: @"%i Last Played Date", songCount];


? Maybe it's seeing that as an attempt to change the DB because the field key isn't correct?

Sorry, grasping at straws.



Oops yeah spelling error. The query happens in a class above, then for each song it encounters, it puts it in an array. Then for each song in the array, I run this code to mine it for info.

Do you think Apple doesn't want me putting songs in an array? that makes some sense for copyright/fucking up the iPod reasons.
Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6035
  • View blog
  • Posts: 23,418
  • Joined: 23-August 08

Re: SQLite error when accessing iPhone Media Data

Posted 29 May 2011 - 07:15 AM

No, I wouldn't think putting songs in the array is the issue. Why not show the class you're using that's actually doing the DB interaction?

By the way, Googling part of your error ("CPSqliteStatementPerform: attempt to write a readonly database for UPDATE ddd.ext_container SET orig_date_modified") reveals you're not the first to encounter this (including your post elsewhere on Stack Overflow).
Was This Post Helpful? 1
  • +
  • -

#8 Tyre77  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-May 11

Re: SQLite error when accessing iPhone Media Data

Posted 29 May 2011 - 07:20 AM

View PostJackOfAllTrades, on 29 May 2011 - 07:15 AM, said:

No, I wouldn't think putting songs in the array is the issue. Why not show the class you're using that's actually doing the DB interaction?

By the way, Googling part of your error ("CPSqliteStatementPerform: attempt to write a readonly database for UPDATE ddd.ext_container SET orig_date_modified") reveals you're not the first to encounter this.



Okay here is where the query is created and then the class is called to gather the information. In the if statement I now have just copied the code from that class MakeDicForSongInfo to avoid passing a media item as a parameter, but still no dice.

MPMediaQuery *query = [[MPMediaQuery alloc] init]; //query iPod library
    
NSString *facebookIDKey = @"Facebook ID";
    NSString *genericFacebookID = @"1234567890";
    NSMutableDictionary *organizedSongData = [NSMutableDictionary dictionaryWithObject:genericFacebookID forKey:facebookIDKey];
    NSArray *allSongs = [query collections];

    //only add those songs which have not
    //been played since last login

    for (MPMediaItem *song in allSongs) {
        NSDate *lastPlayed = [song valueForProperty:MPMediaItemPropertyLastPlayedDate];
        int songCounter = 1;
        BOOL uploadInfo = [[PlayedSinceLastLogin alloc] initWithLastPlayedDateOfSong:lastPlayed]; //check if song has been played since last login
        //if so, grab its info
        if (uploadInfo == YES) {
                [organizedSongData addEntriesFromDictionary: [MakeDicForSongInfo initWithMPMediaItem:recent andSongNumber:songCounter]];
}



Was This Post Helpful? 0
  • +
  • -

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6035
  • View blog
  • Posts: 23,418
  • Joined: 23-August 08

Re: SQLite error when accessing iPhone Media Data

Posted 29 May 2011 - 07:26 AM

I'm wondering if just accessing a record value is triggering the DB to update its own internal access date. I certainly don't see anything obvious there, but you wouldn't expect a simple get to trigger that.
Was This Post Helpful? 1
  • +
  • -

#10 Tyre77  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-May 11

Re: SQLite error when accessing iPhone Media Data

Posted 29 May 2011 - 07:30 AM

View PostJackOfAllTrades, on 29 May 2011 - 07:26 AM, said:

I'm wondering if just accessing a record value is triggering the DB to update its own internal access date. I certainly don't see anything obvious there, but you wouldn't expect a simple get to trigger that.


You're saying that it updates the play date when I just access it via query? That doesn't make sense, since if I did that it would make querying songs impossible.

Grrrr this is so frustrating.
Was This Post Helpful? 0
  • +
  • -

#11 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6035
  • View blog
  • Posts: 23,418
  • Joined: 23-August 08

Re: SQLite error when accessing iPhone Media Data

Posted 29 May 2011 - 07:41 AM

Yes, it seems weird. I can't find anything in the docs about it, except this:

Quote

A media item can also have user-defined properties such as rating and last-played date. These properties update according to user activity, just as they do on the desktop.


from here. But again, I would not expect what you're doing to update the internal metadata.

Sorry can't be more help here.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1