Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7829723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:53:32+00:00 2026-06-02T10:53:32+00:00

I have my sqlite database. now i want syncing with icloud. I read blogs

  • 0

I have my sqlite database. now i want syncing with icloud. I read blogs saying sqlite syncing with icloud is not supported. Either go for core data OR “Do what exactly core data does”.

Now it is not posible for me to go for core data.So like second option “Do something similar to how CoreData syncs sqlite DBs: send “transaction logs” to iCloud instead and build each local sqlite file off of those.”

please can anyone share any sample code for “transaction log” of sqlite OR can expalin in detail stepwise what i need to do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:53:35+00:00Added an answer on June 2, 2026 at 10:53 am

    1) I followed this link to create xml. You can download respective api from its github.Link is – http://arashpayan.com/blog/2009/01/14/apxml-nsxmldocument-substitute-for-iphoneipod-touch/

    2) on button click:

    -(IBAction) btniCloudPressed:(id)sender
    {
        // create the document with it’s root element
        APDocument *doc = [[APDocument alloc] initWithRootElement:[APElement elementWithName:@"Properties"]];
        APElement *rootElement = [doc rootElement]; // retrieves same element we created the line above
    
        NSMutableArray *addrList = [[NSMutableArray alloc] init];
        NSString *select_query;
        const char *select_stmt;
        sqlite3_stmt *compiled_stmt;
        if (sqlite3_open([[app getDBPath] UTF8String], &dbconn) == SQLITE_OK)
        {
            select_query = [NSString stringWithFormat:@"SELECT * FROM Properties"];
            select_stmt = [select_query UTF8String];
            if(sqlite3_prepare_v2(dbconn, select_stmt, -1, &compiled_stmt, NULL) == SQLITE_OK) 
            {
                while(sqlite3_step(compiled_stmt) == SQLITE_ROW) 
                {
                    NSString *addr = [NSString stringWithFormat:@"%@",[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiled_stmt,0)]];
                    addr = [NSString stringWithFormat:@"%@#%@",addr,[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiled_stmt,1)]];
                    addr = [NSString stringWithFormat:@"%@#%@",addr,[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiled_stmt,2)]];
                    addr = [NSString stringWithFormat:@"%@#%@",addr,[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiled_stmt,3)]];
                    addr = [NSString stringWithFormat:@"%@#%@",addr,[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiled_stmt,4)]];
                    addr = [NSString stringWithFormat:@"%@#%@",addr,[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiled_stmt,5)]];
                    addr = [NSString stringWithFormat:@"%@#%@",addr,[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiled_stmt,6)]];
                    addr = [NSString stringWithFormat:@"%@#%@",addr,[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiled_stmt,7)]];
    
                    //NSLog(@"%@",addr);
                    [addrList addObject:addr];
                }
                sqlite3_finalize(compiled_stmt);
            }
            else 
            {
                NSLog(@"Error while creating detail view statement. '%s'", sqlite3_errmsg(dbconn));
            }
    
        }
    
        for(int i =0 ; i < [addrList count]; i++)
        {
            NSArray *addr = [[NSArray alloc] initWithArray:[[addrList objectAtIndex:i] componentsSeparatedByString:@"#"]];
    
            APElement *property = [APElement elementWithName:@"Property"];
            [property addAttributeNamed:@"id" withValue:[addr objectAtIndex:0]];
            [property addAttributeNamed:@"street" withValue:[addr objectAtIndex:1]];
            [property addAttributeNamed:@"city" withValue:[addr objectAtIndex:2]];
            [property addAttributeNamed:@"state" withValue:[addr objectAtIndex:3]];
            [property addAttributeNamed:@"zip" withValue:[addr objectAtIndex:4]];
            [property addAttributeNamed:@"status" withValue:[addr objectAtIndex:5]];
            [property addAttributeNamed:@"lastupdated" withValue:[addr objectAtIndex:6]];
            [property addAttributeNamed:@"deleted" withValue:[addr objectAtIndex:7]];
            [rootElement addChild:property];
            [property release];
    
            APElement *fullscore = [APElement elementWithName:@"FullScoreReport"];
            [property addChild:fullscore];
            [fullscore release];
            select_query = [NSString stringWithFormat:@"SELECT AnsNo,Answer,AnswerScore,MaxScore,AnsIndex FROM FullScoreReport WHERE Addr_ID = %@",[addr objectAtIndex:0]];
            select_stmt = [select_query UTF8String];
            if(sqlite3_prepare_v2(dbconn, select_stmt, -1, &compiled_stmt, NULL) == SQLITE_OK) 
            {
                while(sqlite3_step(compiled_stmt) == SQLITE_ROW) 
                {
                    APElement *answer = [APElement elementWithName:@"Answer"];
                    [answer addAttributeNamed:@"AnsNo" withValue:[NSString stringWithFormat:@"%@",[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiled_stmt,0)]]];
                    [answer addAttributeNamed:@"Answer" withValue:[NSString stringWithFormat:@"%@",[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiled_stmt,1)]]];
                    [answer addAttributeNamed:@"AnswerScore" withValue:[NSString stringWithFormat:@"%@",[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiled_stmt,2)]]];
                    [answer addAttributeNamed:@"MaxScore" withValue:[NSString stringWithFormat:@"%@",[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiled_stmt,3)]]];
                    [answer addAttributeNamed:@"AnsIndex" withValue:[NSString stringWithFormat:@"%@",[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiled_stmt,4)]]];
                    [fullscore addChild:answer];
                    [answer release];
                }
                sqlite3_finalize(compiled_stmt);
            }
        }
        sqlite3_close(dbconn);
    
    
        NSString *prettyXML = [doc prettyXML];
        NSLog(@"\n\n%@",prettyXML);
    
    
        //***** PARSE XML FILE *****
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Properties.xml" ];
        NSData *file = [NSData dataWithBytes:[prettyXML UTF8String] length:strlen([prettyXML UTF8String])];
        [file writeToFile:path atomically:YES];
    
    
        NSString *fileName = [NSString stringWithFormat:@"Properties.xml"];
        NSURL *ubiq = [[NSFileManager defaultManager]URLForUbiquityContainerIdentifier:nil];
        NSURL *ubiquitousPackage = [[ubiq URLByAppendingPathComponent:@"Documents"]  URLByAppendingPathComponent:fileName];
    
    
        MyDocument *mydoc = [[MyDocument alloc] initWithFileURL:ubiquitousPackage];
        mydoc.xmlContent = prettyXML;
        [mydoc saveToURL:[mydoc fileURL]forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) 
         {
    
             if (success) 
             {
                 NSLog(@"XML: Synced with icloud");
                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"iCloud Syncing" message:@"Successfully synced with iCloud." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                 [alert show];
                 [alert release];
    
    
    
             }
             else
                 NSLog(@"XML: Syncing FAILED with icloud");
    
    
         }];
    
    }
    

    3)MyDocument.h file

    #import <UIKit/UIKit.h>
    
    @interface MyDocument : UIDocument
        @property (strong) NSString *xmlContent;
    @end
    

    4)MyDocument.m file

    #import "MyDocument.h"
    
    @implementation MyDocument
    @synthesize xmlContent,zipDataContent;
    
    // Called whenever the application reads data from the file system
    - (BOOL)loadFromContents:(id)contents ofType:(NSString *)typeName error:(NSError **)outError
    {
        // NSLog(@"* ---> typename: %@",typeName);
                    self.xmlContent = [[NSString alloc] 
                                   initWithBytes:[contents bytes] 
                                   length:[contents length] 
                                   encoding:NSUTF8StringEncoding]; 
    
        [[NSNotificationCenter defaultCenter] postNotificationName:@"noteModified" object:self];
        return YES;     
    }
    
    // Called whenever the application (auto)saves the content of a note
    - (id)contentsForType:(NSString *)typeName error:(NSError **)outError 
    {
    
            return [NSData dataWithBytes:[self.xmlContent UTF8String] length:[self.xmlContent length]];
    
    }
    
    @end
    

    5) now in ur appdelegate

    - (void)loadData:(NSMetadataQuery *)queryData
     {
    
    
        for (NSMetadataItem *item in [queryData results]) 
        {    
            NSString *filename = [item valueForAttribute:NSMetadataItemDisplayNameKey];
            NSNumber *filesize = [item valueForAttribute:NSMetadataItemFSSizeKey]; 
            NSDate *updated = [item valueForAttribute:NSMetadataItemFSContentChangeDateKey];
            NSLog(@"%@ (%@ bytes, updated %@) ", filename, filesize, updated);
    
            NSURL *url = [item valueForAttribute:NSMetadataItemURLKey];
            MyDocument *doc = [[MyDocument alloc] initWithFileURL:url];
            if([filename isEqualToString:@"Properties"])
            {
                [doc openWithCompletionHandler:^(BOOL success) {
                    if (success) {
                        NSLog(@"XML: Success to open from iCloud");
                        NSData *file = [NSData dataWithContentsOfURL:url];
                        //NSString *xmlFile = [[NSString alloc] initWithData:file encoding:NSASCIIStringEncoding];
                        //NSLog(@"%@",xmlFile);
    
                        NSXMLParser *parser = [[NSXMLParser alloc] initWithData:file];
                        [parser setDelegate:self];
                        [parser parse];
                        //We hold here until the parser finishes execution
                        [parser release];
                    }
                    else 
                    {
                        NSLog(@"XML: failed to open from iCloud");
                     }
                }]; 
            }
    }
    }
    

    6) now in parser method fetch data and insert/update as needed in database.

    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)nameSpaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
    {
    if ([elementName isEqual:@"Property"])
        {
            NSLog(@"Property attributes : %@|%@|%@|%@|%@|%@|%@|%@", [attributeDict objectForKey:@"id"],[attributeDict objectForKey:@"street"], [attributeDict objectForKey:@"city"], [attributeDict objectForKey:@"state"],[attributeDict objectForKey:@"zip"],[attributeDict objectForKey:@"status"],[attributeDict objectForKey:@"lastupdated"],[attributeDict objectForKey:@"deleted"]);
    }
    //like this way fetch all data and insert in db
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sqlite database that I want to open using sqlite3.exe. Now I
I have a sqlite database. I have three columns:_id, date, value. I now want
I have created a SQLite database from Java. Now I want to know where
I have sqlite database with table of songs, now I want to get artist
I have a script file for parsing through a SQLite database. I now need
I have an sqlite database, and I would like to keep it read-only without
Simply put: I have a database design in my head and I now want
I have a little issue with upgrading my sqlite database. For now I'm using
I have made the following code to retrive data from SQLite database. public Cursor
I have a SQLite database that is displayed in a data grid view in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.