Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-17-2010, 12:39 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 31
pete42 is on a distinguished road
Default Download .sqlite file from my website

I have done a similar thing with text files but i dont know how to do something like it using .sqlite.

Here is what i did for the text file

Code:
NSURL *webheight2 =[NSURL URLWithString: @"http://www.peteappdesigns.com/habscal/webheight2.txt"];
	webHeight2 = [NSString stringWithContentsOfURL:webheight2 encoding:1 error:NULL];
	NSString *webHeight2File = [documentsDirectory stringByAppendingPathComponent:@"webheight2.txt"];
	[webHeight2 writeToFile:webHeight2File atomically:YES encoding:1 error:NULL];
how would i go about implementing something like this but with a .sqlite file.
I want to download the file to the documents directory and then it is used for the data of the tableview

here is where i would want to do this but instead of the local file it would be the internet file.

Code:
 BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"q1west.sqlite"];
    success = [fileManager fileExistsAtPath:writableDBPath];
    if (success) return;
    // The writable database does not exist, so copy the default to the appropriate location.
    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"q1west.sqlite"];
    success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
    if (!success) {
        NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    }
pete42 is offline   Reply With Quote
Old 12-14-2010, 02:03 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 3
monty_burns_007 is on a distinguished road
Smile

Hi,

I 'm running in the same problem. I have a binary Sqlite database file on a remote location.
I want to use the remote file in my iphone/ipod touch.
For now only for reading.
As remote connection for SQLite database isn't possible i would like to implement your way:
1. Download the remote file to the document folder
2. Open it with iphone app for reading.

Could you share your working snippet code which downloads the binary sqlite file to the document folder a can open it in iphone SDK ?

Many thanks in advance,

monty
monty_burns_007 is offline   Reply With Quote
Old 12-14-2010, 02:22 PM   #3 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 3
monty_burns_007 is on a distinguished road
Default

Would this work ?

NSData *fetchedData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.myserver.com/files/DBName.sqlite"]]];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"DBName.sqlite"];
[fetchedData writeToFile:filePath atomically:YES];

Hoping for you to share your code....

monty

monty_burns_007@hotmail.com
monty_burns_007 is offline   Reply With Quote
Old 01-10-2011, 01:14 PM   #4 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 9
bella is on a distinguished road
Default

Quote:
Originally Posted by monty_burns_007 View Post
Would this work ?

NSData *fetchedData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.myserver.com/files/DBName.sqlite"]]];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"DBName.sqlite"];
[fetchedData writeToFile:filePath atomically:YES];

Hoping for you to share your code....

monty

monty_burns_007@hotmail.com
did you successful find a solution? would be nice to hear from you. Thanks.
bella is offline   Reply With Quote
Old 01-11-2011, 12:42 AM   #5 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 3
monty_burns_007 is on a distinguished road
Default

the above code worked perfectly for me.

It is sync communication... so the app waits there until the download is complete.
If you want async comm use nsurlconnection ....
The saving to disk (iphone) part is the same.
monty_burns_007 is offline   Reply With Quote
Old 01-11-2011, 02:43 AM   #6 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

or if you prefer you can use ASIHTTPRequest
ASIHTTPRequest example code - All-Seeing Interactive
__________________
dany_dev is offline   Reply With Quote
Old 01-15-2011, 05:38 AM   #7 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 9
bella is on a distinguished road
Default

Thanks, because I want to build a function when user click the button and it will download the sqlite from the server and update the one on the phone. So I guess I could use the above code with a button function, save the sqlite to a location and replace the existing one after... is that right?


Quote:
Originally Posted by monty_burns_007 View Post
the above code worked perfectly for me.

It is sync communication... so the app waits there until the download is complete.
If you want async comm use nsurlconnection ....
The saving to disk (iphone) part is the same.
bella is offline   Reply With Quote
Old 01-15-2011, 09:46 AM   #8 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

yes, in your documents directory.
__________________
dany_dev is offline   Reply With Quote
Reply

Bookmarks

Tags
documents, documents directory, sql, sqlite, tableview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 351
11 members and 340 guests
akacaj, c2matrix, cgokey, esoteric, givensur, HemiMG, Mirotion22, mjnafjke, Pudding, SLIC, Techgirl-52
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,651
Threads: 94,115
Posts: 402,887
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Mirotion22
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:15 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0