AcademiaAgriculture & FarmingHumanitiesSocial SciencesSTEM

Tutorial on Creating an iOS SQLite Database Application for iOS, iPhone, or iPad

Updated on May 01, 2016
klanguedoc profile image

Kevin is Software Developer with 20 years experience designing and building software applications including iOS and Android apps.

The essentials to master how to develop iOS apps  for iPhone and iPad using SQlite
The essentials to master how to develop iOS apps for iPhone and iPad using SQlite | Source

(c) klanguedoc, 2011

iOS and SQLite make a powerful combination for building data persistent iPad, iPhone or iPod Touch mobile applications. The iOS SDK provides native support for SQLite through the use of the C programming language. This tutorial will walk you through how to setup a SQLite database application and to read text and images from the database into a scene.

Create the database


To start with, you will need FireFox from Mozilla and the SQLite Database Manager plugin. If you don’t have them, they can be downloaded and installed from the FireFox web site. Once FireFox is installed, install the SQLite Manager from the Add-on Manager.

The SQLite Manager can be launched from the Firefox menu or Tools menu depending on the version you are using (see figure 1).

Figure 1: SQLite Manager in Firefox
Figure 1: SQLite Manager in Firefox

Click on the new Database button (figure 2) to create a new database. You can give any meaningful name you want. Note, the SQLite extension will be automatically appended. You will be prompted to save the file to the file system, (naturally). Take note where you are saving it because you are going to copy the file later into your project.

Next, click on the new table button (figure 3) to create a new table, again I will leave it up to you to name it something useful. For this tutorial, my named the table wineTbl and I have created four columns: id [primary, autoinc, integer], winename [varchar], winerating [varchar] and wineimage [blob].

Figure 2: Create a table
Figure 2: Create a table
Figure 3: Create the necessary columns
Figure 3: Create the necessary columns

For the sake of this tutorial, I will pre-populate the database with some wine entries and images from the web. You can add data by selecting the table and selecting the browse and data tab. To upload an image, click on the paper clip icon next to the blob field. (Figure 4 and figure 5).

Now you can close the database from the Firefox menu and Firefox as well since we won’t need anymore for the tutorial.

Figure 4: Adding a new record in the database
Figure 4: Adding a new record in the database
Figure 5: Record listing in the database
Figure 5: Record listing in the database

Create IOS 5 Project


Launch XCode 4.2 and create a Single-View IOS 5 application. Give it a meaningful name and select Storyboard and ARC. Setup your Git, or not, source control and complete the creation of your project. (figure 6).

Figure 6: The Wine List App
Figure 6: The Wine List App

Configure SQLite


Expand the Frameworks folder, right click on one of the frameworks and select Show in Finder to open Finder at the Framework location. You will need to add the libsqlite_3.0.dylib file to your project (figure 6), so move up two or three levels (see Go to Enclosing folder in the Finder menu) until you get to the usr folder. Open it and open the lib folder. Scroll down until you find the sqlite_3.0.lib. Drag the file to your Frameworks taking care to NOT copy file into the frameworks, but ONLY create a reference (Figure 7).

Next select the project root, right click and select Show in Finder. Locate your sql database you created in the first part of this tutorial and copy it into the project group where you project header and implementations files are (Figure 8).

Figure 7: Copy Reference of sqlite3.0.dylib to the Framework folder
Figure 7: Copy Reference of sqlite3.0.dylib to the Framework folder
Figure 8: Copy database file to the project folder
Figure 8: Copy database file to the project folder

Setup DAO Operations


Create a new Group (File | New Group) or from the (Context Menu | New Group). Name it “Model”. Next create two Objective-C implementation files and corresponding header files. Select the Model group and from the File menu or Context menu | select New File. Select the Objective-C node and then the Objective-C class template.

Give your file a name: WineList (if you are following this tutorial), select NSObject as the Subclass and create the file. Repeat the process for the next set of files: MyWineList, (or you can choose a name like WinesDAO). Again select the NSObject as the Subclass and create the file (Figure 9).

For the WineList class create four properties in the WineList.h (header) file, one for each column in the wineTbl (Figure 10):

  • wineId
  • wine
  • rating
  • photo


Next open the WineList.m (implementation) file to set up the getter and setter methods. So your WineList should contain four @synthesize statements, one four each property (Figure 11).

  • @synthesize wineId;
  • @synthesize wine;
  • @synthesize rating;
  • @synthesize photo;

Figure 9: Create the WineList class
Figure 9: Create the WineList class
Figure 10: Create the WineLists class
Figure 10: Create the WineLists class
Figure 11: The WineList header
Figure 11: The WineList header

Create CRUD Operations


Well CRUD is a bit of a stretch. For this tutorial it is really just a R (read) operation. Ok now the application is going to need DAO classes for the CRUD (Read) operations, so if you haven’t already done so, create a new Objective-C class: MyWineLists or whatever you want so long as the declaration and implementation works. For the MyWineLists header file, a sqlite3 object is declared and an NSMutableArray method (figure 11):

  • db
  • getMyWines



To implement these objects, open the MyWineLists.m file. In this file, the gut if the operations will take place.

To start create the NSMutableArray method getMyWines and add an array pointer variable:

  • wineArray



Next declare a NSFileManager object, a NSString object and a Bool object:

  • fileMgr
  • dbPath
  • success




NSMutableArray *wineArray = [[NSMutableArray alloc] init];
@try {
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"IOSDB.sqlite"];
BOOL success = [fileMgr fileExistsAtPath:dbPath];
...

The dbPath will contain to the filename and path of the SQLite database which will be passed to the fileMgr. If the file is located, success will be true. Next test to see if the file was located and if not log an error. The following operation will attempt to open the database, sqlite3_open before setting up the Select statement and sql3_stmt:

  • sql
  • sqlStatement




if(!success)
{
NSLog(@"Cannot locate database file '%@'.", dbPath);
}
if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
{
NSLog(@"An error has occured.");
}
const char *sql = "SELECT id, Wine, Rating, Photo FROM WineTbl";
sqlite3_stmt *sqlStatement;
if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)
{
NSLog(@"Problem with prepare statement");
}
...

If the database is successfully opened, the sqlite3_prepare will attempt to execute the sqlStatement. If the statement is successfully executed resulting in a result set being returned, then execute a while loop to traverse the result set assigning the values to the NSMutableArray fields.

...
while (sqlite3_step(sqlStatement)==SQLITE_ROW) {
WineList *MyWine = [[WineList alloc]init];
MyWine.wineId = sqlite3_column_int(sqlStatement, 0);
MyWine.wine = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,1)];
MyWine.rating = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 2)];
const char *raw = sqlite3_column_blob(sqlStatement, 3);
int rawLen = sqlite3_column_bytes(sqlStatement, 3);
NSData *data = [NSData dataWithBytes:raw length:rawLen];
MyWine.photo = [[UIImage alloc] initWithData:data];
[wineArray addObject:MyWine];
}
}
@catch (NSException *exception) {
NSLog(@"An exception occured: %@", [exception reason]);
}
@finally {
return wineArray;
}

...

This pretty much takes care of the of the cRud operations. The next step will involve setting up the UI, creating IBActions and IBOutlets connections. (See figure 12, 13).

Figure 12: The implementation of WineLists
Figure 12: The implementation of WineLists
Figure 13: The CRUD operations
Figure 13: The CRUD operations

Create UI Operations



Start by locating and opening the storyboard file. You should have a single blank scene (View Controller). For this part, four labels (UILabel) are required: one for Wine Name and the value from the database and likewise for the two others: one for Wine Rating and the corresponding value from the database that will be stored in the NSMutableArray. For the images, drag an UIImageView onto the scene. As a final step for the UI, drag a UIToolbar and place it at the bottom of the screen and rename the included button: Next Bottle (Figure 14).

Figure 14: Connecting the dots
Figure 14: Connecting the dots
Figure 15: The project structure
Figure 15: The project structure

To finish off the app, some code needs to be added to the ViewController header and implementation files. So to setup the IBAction and IBOutlet, open the header file alongside the storyboard by clicking on the Assistant Editor, the face icon in the Toolbar (Figure 14). Start by selecting the first label and dragging a connection line (Ctrl+left mouse button) to the header file between the last curly brace and the @end directive. In the Popup, select IBOutlet and enter a name like: winename. Continue with second label that will contain the rating information. This will also be an IBOutlet and the name will be: winerating. For the image, repeat the same operation as the two preceding ones. This connection will also be an IBOutlet and the name will be : wineViewer. Finally drag a connection line from the button in the Toolbar. This will be an IBAction and the name of the method: GetWineListing. Also add a NSMutableArray object:

  • wines



You should have little filled in dot in the margin indicating that connections have been made.

Next open the implementation file. Setup the getter and setters:


@synthesize wineViewer;
@synthesize winename;
@synthesize winerating;
@synthesize wines;



In the viewDidLoad, which is called when the app is finished initializing itself, add pointers to hold the initial data in the array so the app will display some information and image that is located at index 0.


- (void)viewDidLoad
{
MyWineLists * mywines =[[MyWineLists alloc] init];
self.wines = [mywines getMyWines];
[self.wineViewer setImage:((WineList *) [self.wines objectAtIndex:0]).photo];
[self.winename setText:((WineList *) [self.wines objectAtIndex:0]).wine];

[self.winerating setText:((WineList *) [self.wines objectAtIndex:0]).rating];

[super viewDidLoad];
}
...

in the viewDidUnload set your properties to nil to release them from memory


- (void)viewDidUnload
{
[self setWineViewer:nil];
[self setWinename:nil];
[self setWinerating:nil];
[super viewDidUnload];
}
...

Finally implement the GetWineListing method, so when the user clicks on the button, the index gets incremented and retrieves the data at the selected index number.


- (IBAction)GetWineListing:(id)sender {
static NSInteger currentIndex = 0;
if (++currentIndex == [self.wines count]) {
currentIndex=0;

}else{
WineList *aWine = (WineList *) [self.wines objectAtIndex: currentIndex];
[self.winename setText:aWine.wine];
[self.winerating setText:aWine.rating];
[self.wineViewer setImage:aWine.photo];
}
}

Test Your App



Ok, we are done. Click on the Run button to launch your app. After the app is finished initializing you should have from data and image on screen. Click the Next Bottle to get the next listing.

Figure 15: The running app
Figure 15: The running app

Source Code



Here is the complete source code of the various files that were created.

WineList.m

//
//  WineList.m
//  MyWineList
//
//  Created by Kevin Languedoc on 11/25/11.
//  Copyright (c) 2011 kCodebook. All rights reserved.
//

#import "WineList.h"

@implementation WineList
@synthesize wineId;
@synthesize wine;
@synthesize rating;
@synthesize photo;

//With ARC, if you selected id, you don't need to dealloc

@end

MyWineLists

//
//  MyWineLists.h
//  MyWineList
//
//  Created by Kevin Languedoc on 11/25/11.
//  Copyright (c) 2011 kCodebook. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <sqlite3.h>

@interface MyWineLists : NSObject{
    sqlite3 *db;
}

- (NSMutableArray *) getMyWines;

@end

WineList.h

//
//  WineList.h
//  MyWineList
//
//  Created by Kevin Languedoc on 11/25/11.
//  Copyright (c) 2011 kCodebook. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface WineList : NSObject{
    NSInteger wineId;
    NSString *wine;
    NSString *rating;
    UIImage *photo;
}

@property (nonatomic,retain)NSString *wine;
@property (nonatomic, assign) NSInteger wineId;
@property (nonatomic, retain)NSString *rating;
@property (nonatomic, retain) UIImage *photo;


@end

MyWineLists.m

//
//  MyWineLists.m
//  MyWineList
//
//  Created by Kevin Languedoc on 11/25/11.
//  Copyright (c) 2011 kCodebook. All rights reserved.
//

#import "MyWineLists.h"
#import "WineList.h"

@implementation MyWineLists
- (NSMutableArray *) getMyWines{
    NSMutableArray *wineArray = [[NSMutableArray alloc] init];
    @try {
        NSFileManager *fileMgr = [NSFileManager defaultManager];
        NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"IOSDB.sqlite"];
        BOOL success = [fileMgr fileExistsAtPath:dbPath];
        if(!success)
        {
            NSLog(@"Cannot locate database file '%@'.", dbPath);
        }
        if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
           {
               NSLog(@"An error has occurred.");
           }
        const char *sql = "SELECT id, Wine, Rating, Photo FROM  WineTbl";
        sqlite3_stmt *sqlStatement;
        if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)
           {
               NSLog(@"Problem with prepare statement");
           }
        
        //
        while (sqlite3_step(sqlStatement)==SQLITE_ROW) {
            WineList *MyWine = [[WineList alloc]init];
            MyWine.wineId = sqlite3_column_int(sqlStatement, 0);
            MyWine.wine = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,1)];
            MyWine.rating = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 2)];
            const char *raw = sqlite3_column_blob(sqlStatement, 3);
            int rawLen = sqlite3_column_bytes(sqlStatement, 3);
            NSData *data = [NSData dataWithBytes:raw length:rawLen];
            MyWine.photo = [[UIImage alloc] initWithData:data];
            [wineArray addObject:MyWine];
        }
    }
    @catch (NSException *exception) {
        NSLog(@"An exception occurred: %@", [exception reason]);
    }
    @finally {
        return wineArray;
    } 
    
    
}


@end

kcbViewController

//
//  kcbViewController.h
//  MyWineList
//
//  Created by Kevin Languedoc on 11/25/11.
//  Copyright (c) 2011 kCodebook. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface kcbViewController : UIViewController{
    NSMutableArray *wines;

    
}

@property(nonatomic,retain) NSMutableArray *wines;
@property (weak, nonatomic) IBOutlet UIImageView *wineViewer;
@property (weak, nonatomic) IBOutlet UILabel *winename;
@property (weak, nonatomic) IBOutlet UILabel *winerating;
- (IBAction)GetWineListing:(id)sender;


@end

kcbViewController.m

//
//  kcbViewController.m
//  MyWineList
//
//  Created by Kevin Languedoc on 11/25/11.
//  Copyright (c) 2011 kCodebook. All rights reserved.
//
#import "kcbViewController.h"
#import "WineList.h"
#import "MyWineLists.h"

@implementation kcbViewController
@synthesize wineViewer;
@synthesize winename;
@synthesize winerating;
@synthesize wines;


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    MyWineLists * mywines =[[MyWineLists alloc] init];
    self.wines = [mywines getMyWines];
    [self.wineViewer setImage:((WineList *) [self.wines objectAtIndex:0]).photo];
    [self.winename setText:((WineList *) [self.wines objectAtIndex:0]).wine];
    
    [self.winerating setText:((WineList *) [self.wines objectAtIndex:0]).rating];
     
    [super viewDidLoad];
}

- (void)viewDidUnload
{
    [self setWineViewer:nil];
    [self setWinename:nil];
    [self setWinerating:nil];
    [super viewDidUnload];
}

- (IBAction)GetWineListing:(id)sender {
    static NSInteger currentIndex = 0;
    if (++currentIndex == [self.wines count]) {
        currentIndex=0;
}else{
        WineList *aWine = (WineList *) [self.wines objectAtIndex: currentIndex];
        [self.winename setText:aWine.wine];
        [self.winerating setText:aWine.rating];
        [self.wineViewer setImage:aWine.photo];
    }
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}




@end

In summary



That pretty wraps it up. In the hindsight, implementing SQLite was very easy. The only thing missing is the operations to create records, updating and deleting them. That as they say is another story, or article in this case. If you need to know how to perform inserts, updates and deletes, check out my article: IOS 5 SDK Database: Insert, Update, Delete with SQLite and Objective-C | C | How-To

Another useful tutorial is : Tutorial on How to Display & Write SQLite Data in Table View Controller & Detail View Controller | iOS 5 App

Comments

    0 of 8192 characters used
    Post Comment

    • vomr 5 years ago

      Thanks very helpful!

    • Mike 5 years ago

      this is a great tutorial! I am curious - can you add a search function to this?

    • klanguedoc profile image
      Author

      Kevin Languedoc 5 years ago from Canada

      Hi Mike. Thanks for your kind comment. Yes you can if it follows standard SQL syntax. You could have a search field that converts the search term(s) into individual tokens and and store those individual terms into an Array (NSArray) and then build your WHERE clause based on the elements of the array. It is not straightforward but it can be done.

      Hope this helps and let me know how it works out for you.

      klanguedoc

    • Pang 5 years ago

      Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'

      Getting this error.. any fix?

    • klanguedoc profile image
      Author

      Kevin Languedoc 5 years ago from Canada

      This error simply means that your array is empty, so your program is trying to read data at the first position, 0, and there is nothing to read. Check to make sure the array you are using is indeed populated with data from the database.

    • Mike 5 years ago

      unfortunately I am new to xcode, objective-c and coding in general. you wouldn't happen to know of a tutorial that explains what you suggested in more detail?

    • klanguedoc profile image
      Author

      Kevin Languedoc 5 years ago from Canada

      I would suggest you read The C Programming Language by Dennis Ritchie. It is base of all things Objective-C and even many of the libraries in Apple SDK are in C. Next you could buy/read a book on Objective-C like the Big Nerd Ranch.

      Hope this helps

    • SirJko 5 years ago

      I have the same problem of the guy's comment above. I'va experience with C programming, etc etc. But I can't figure out that problem. I know my array is not being populated; you know why? Im following your code... can you give us a clue?

    • klanguedoc profile image
      Author

      Kevin Languedoc 5 years ago from Canada

      Hi SirJko,

      Can you post your code in the comments so that I can have a look at it and maybe I can spot where the issue is. I would love to help you out.

      klanguedoc

    • SirJko 5 years ago

      Thanks! I finally could fix the error. It was something about the SQL statement.

      I would be pretty good to have an entry about merging this tuto with the uitableview's one.

      Thanks for your answer and time.

    • klanguedoc profile image
      Author

      Kevin Languedoc 5 years ago from Canada

      Thanks for the suggestion. I will gladly write a new hub showing how to display contents from a database in an UITableView. I also glad that you were able to get your app working.

      Klanguedoc

    • ratunolan 5 years ago from Dunedin, New Zealand

      Nice tutorial, I have followed your tutorial and have got it going. However, when i click the next bottle button it doesn't show the next bottle. Any ideas?

      Thanks

    • klanguedoc profile image
      Author

      Kevin Languedoc 5 years ago from Canada

      Hi ratunolan

      Thanks for the kind words.

      Did you add a connection and a delegate for the button. You must do this from the Storyboard by opening the header file alongside the storyboard and drag a connection from the button to the header file.

    • maxravi profile image

      Ravi Singh 5 years ago from India

      Thanks for your hub.keep adding such content.

    • klanguedoc profile image
      Author

      Kevin Languedoc 5 years ago from Canada

      Thanks for the support and kind words Maxravi. I am currently working on a couple related Hubs that are similar to this one. Hope to have them published within a week.

    • Viji 5 years ago

      Thanks for a good Tutorial.

      One bug in the GetWineListing method.

      Code should go into IF statement

      (if ++currentIndex != [self.wines count])

      {

      }

      Also there should be an ELSE }

      currentIndex =0;

      }

      otherwise "Next Wine" button does not do anything..

    • klanguedoc profile image
      Author

      Kevin Languedoc 5 years ago from Canada

      Thanks Viji for catching that. Actually there are two ways to write back bit of code; as stated above or remove the first curly brace (see below) so only the first statement will evaluate. Anyway I added an ELSE statement since it make the code easier to read.

      if (++currentIndex == [self.wines count]) currentIndex=0;

      WineList *aWine = (WineList *) [self.wines objectAtIndex: currentIndex];

      [self.winename setText:aWine.wine];

      [self.winerating setText:aWine.rating];

      [self.wineViewer setImage:aWine.photo];

      Thanks again.

    • Mark 5 years ago

      This is a great help, any chance you explain how to put all the wine names in a table view then go to a detailed when pressed?

    • klanguedoc profile image
      Author

      Kevin Languedoc 5 years ago from Canada

      Thanks Mark, you can check out my other tutorial on UITableViews: http://hubpages.com/education/IOS-5-How-To-Create-...

      It will get you going in the direction.

      Hope this helps

      Klanguedoc

    • Zack Depp 5 years ago

      Is there something special I need to do with "Count" or "Group By" sql commands? because I'm missing some records here...

      This sql query gives only 1 record while there should be 2: "SELECT Name, COUNT(*) FROM Items, Groups WHERE Groups.Id=Items.GroupId GROUP BY Items.GroupId"

      Note: Each group can contain many items.

      Ps: Running the same sql query in Firefox's SQL Manager gives 2 results.

      Anyone got a clue?

    • klanguedoc profile image
      Author

      Kevin Languedoc 5 years ago from Canada

      Try taking out the name entity and the group by clause for testing purposes

    • Eric 5 years ago

      Hey mate, thanks for the tutorial.

      I followed it as it is and in the end, I ran this problem while building the app:

      "Thread 1: Program received signal: "SIGABRT"."

      What should I do to take care of this problem? Thanks!

    • klanguedoc profile image
      Author

      Kevin Languedoc 5 years ago from Canada

      Hi Eric,

      Thanks for the kind words...

      Yes this is one of the GDB infamous messages. A couple of solutions are at hand: First run your app and open the console. There will be a lot of verbose text, but information that is important to you will be in bold. Scroll to the start of the bold text and you should get the exact reason why you are getting this message.

      Second: If no apparent reason that make sense is available in step one, the SIGABRT signal will be triggered when there is multiple instances of your app that is running in memory,if if you have exited the Simulator. To fix you can reset Simulator (see menu), you can also close all projects and restart Xcode or restart your computer.

      However, for the most part, the first option, check the bold text in the Console, will point to the error message and how to fix it.

      Hope this helps and let me know if I can help further.

      Kevin

    • Eric 5 years ago

      2012-01-19 16:39:39.309 ProjectWine[76694:f803] Problem with prepare statement

      2012-01-19 16:39:39.392 ProjectWine[76694:f803] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'

      *** First throw call stack:

      (0x147d052 0x160ed0a 0x1469db8 0x286a 0xd964e 0x39a73 0x39ce2 0x39ea8 0x40d9a 0x11be6 0x128a6 0x21743 0x221f8 0x15aa9 0x1367fa9 0x14511c5 0x13b6022 0x13b490a 0x13b3db4 0x13b3ccb 0x122a7 0x13a9b 0x2488 0x23e5)

      terminate called throwing an exception

      That's what I got, is objectAtIndex error caused because I have an empty field in the db? Not sure about the prepare statement one...

    • klanguedoc profile image
      Author

      Kevin Languedoc 5 years ago from Canada

      Hi Eric,

      This simply means that your array that points to the NSMutableArray, is empty. check your code where the array is being populated from the Select statement.

    • mikeydcarroll67 4 years ago

      I think this was informative! I bookmarked it since I am starting to develop iOS apps!

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Thanks for your kind words. Best of luck and success with your apps, mikeydcarroll67.

    • Guest 2 4 years ago

      I do not have a file named "sqlite_3.0.lib", but I do have a file named "libsqlite_3.0.dylib". Same thing?

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Actually, you are supposed to use the "libsqlite_3.0.dylib" file. Thanks for bringing that to my attention. I will correct the text.

    • Guest 2 4 years ago

      Thanks for quick response, klanguedoc!

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Glad to help! Enjoy your coding

    • mikeydcarroll67 4 years ago

      OK I figured out the databases (I had two separate databases but wanted to read and write to them separately, not through a join function). However, I do get an incomplete implementation, even though it looks like everything is in order.

    • mikeydcarroll67 4 years ago

      Also, how did you set up your labels? I am having trouble loading the information into a single view controller.

    • ratunolan 4 years ago from Dunedin, New Zealand

      I finally got it going, which was awesome. I want to be able to read from a sqliteDB to a customed TableViewCell and then a DetailView with images,text,scrollViews do you have a tutorial for that.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      I have a couple of tutorials here for that. I am currently finishing a tutorial on DetailTableController. Basically how to display content in a static UITableView.

      I have these tutorials that may help you out in the meantime:

      http://hubpages.com/technology/IOS-5-Storyboarding...

      or

      http://hubpages.com/technology/IOS-5-How-To-Displa...

      or

      http://hubpages.com/education/IOS-5-How-To-Create-...

      To push data to a DetailViewController, you need to implement a segue and the prepareForSegue method. Something like this code snippet.

      (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

      if ([segue.identifier isEqualToString:@"NameOfSegueBetweenTableViewControllerAndDetailViewController"])

      // Get the detail view controller.

      PhraseDetailViewController* destVC =

      (PhraseDetailViewController*)segue.destinationViewController;

      // Find the correct dictionary from the documents array.

      NSIndexPath *cellPath = [self.tableView indexPathForSelectedRow];

      UITableViewCell *theCell = [self.tableView cellForRowAtIndexPath:cellPath];

      // Assign the URL to the detail view controller and

      // set the title of the view controller to the doc name.

      destVC.detailItem = theCell.textLabel.text;

      destVC.navigationItem.title = theCell.detailTextLabel.text;

    • drgipatel 4 years ago

      i copied the same codes as given and made the same files but i get "Thread 1: Program received signal: "SIGABRT"."

      each time i run it i tried all what was given above but can't solve it, am i missing something ? how do i check ? error is like

      2012-02-12 22:09:35.847 MyWineList[2183:f803] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[kcbViewController 0x6854be0 setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key wineviewer.'

      *** First throw call stack:

      (0x1586052 0x1717d0a 0x1585f11 0xa74032 0x9e5f7b 0x9e5eeb 0xa00d60 0x2f391a 0x1587e1a 0x14f1821 0x2f246e 0x199e2c 0x19a3a9 0x19a5cb 0xfaa73 0xface2 0xfaea8 0x101d9a 0xd2be6 0xd38a6 0xe2743 0xe31f8 0xd6aa9 0x1470fa9 0x155a1c5 0x14bf022 0x14bd90a 0x14bcdb4 0x14bcccb 0xd32a7 0xd4a9b 0x2488 0x23e5)

      terminate called throwing an exceptionsharedlibrary

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      I would have to see more of your code because the code has been fully tested and many more have implemented the code as is and works fine. From the error it looks like you are trying to set a key-pair value for a dictionary object. I am more than willing to help if you could poste your code in the comments. Maybe I can see something.

    • drgipatel 4 years ago

      can i have your email id as can't post the signs great and less then or html here , it show an error,

      or if possible i will send the full folder ,

      is there any chance i made a mistake in the storyboard in giving the values? this is my first sqlite tutorial and its been over 10 hrs figuring it out i entered the exact guideline over 4-5 times but still get that error, and i can't stop unless i find out what's wrong. regards, my email id is drgipatel@gmail.com

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Sure, in the sidebar above, just below the advertisement, there is an e-mail link so you can send me an e-mail. It might take me a day or two to get back because I am working on a book, besides my job so my time is a bit stretched, but I will gladly have a look to see where things are not working. It could be the storyboard. You could try deleting it and creating a new one with the same name otherwise you will have to edit the info-plist file and change the name of the storyboard.

    • Gopal Patel profile image

      Gopal Patel 4 years ago from Vadodara, Gujarat, India

      Hello I finally found the problem it was in the Storyboard and adding the controls , after i run i saw the data but when i pressed the next button again some error will check it out tommorow, 2012-02-13 22:41:52.984 MyWineList[2798:f803] Applications are expected to have a root view controller at the end of application launch

      also if i wanted to search for all rating = good how do i get it from the database as present in a list form?

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Excellent

    • Ed 4 years ago

      Hi Klanguedoc

      Does SQLite work with Xcode 3? I am writing iOS Apps but I don't have a developer account to dl Xcode 4.

      Thanks!

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Since SQLite is a C based API it should work any version of Xcode. Before the arrival of Core Data, SQLite was the standard storage facility for iPhone & iPad apps. As long as the lib is available, you shouldn't have any problems.

    • barrowclough 4 years ago

      Great Tutorial, thanks. However I have one question, the get wines button will bring up the next in the sequence, but I also want to implement a previous button. I have tried experimenting with this but I'm stumped by the code to make it go to the previous. Any help please!?

    • barrowclough 4 years ago

      One other question, I need to retrieve one of the items in the table as an NSString. I have an IBAction button and when I press that button I need to retrieve one of the row entries as an NSString.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Thanks for the kind words...

      For the previous button, try using rowIndex-1. I haven't tested this but should work.

      I am assuming here that when you say retrieve a row from table, you are talking about the database, otherwise please redirect me.

      for converting value to NSString, the NSString class many methods available for taking a value as input and converting it to NSString.

      Instead of using something like this

      NSString * string = [[NSString alloc] init];

      you could use this:

      NSString * string = [[NSString alloc] initWithFormat:FormatValue from Database column];

      Please see this url:

      https://developer.apple.com/library/mac/#documenta.../Cocoa/Conceptual/Strings/Articles/FormatStrings.html#//apple_ref/doc/uid/20000943

    • Barrowclough 4 years ago

      I got it figured out, thanks for the pointers every things working now :-) great! Thanks, I've been trying to get this working for hours!

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Great Barrowclough,

      Glad to hear that you were able to breakthrough to roadblock. I wish you lots of success with your app.

      Kevin

    • pavan 4 years ago

      Thanks for ur tutorial.......

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Your very welcome pavan.

    • Todd Hugie 4 years ago

      Thanks for the tutorial. Very helpful. I have a program that involves uiviews, uiviewcontrollers, navigation controls, among other things. I have built a large array within these programs and I'm using your example to put the data in these arrays into a sqlite database. It will make my program much more flexible in the long run.

      Thanks for your help. I got a small portion of my program running last night reading the database. I will convert the rest of my program during the week and may have questions.

    • Todd Hugie 4 years ago

      One question I wanted to ask in my last entry before I hit enter. Here it is.

      I've been a database programmer for over 20 years and know SQL quit well. I'm leaning to using SQlite but do you see any advantage of using Core Data? I know I can use SQlite as the storage for Core Data but I know and like to use SQL. My program will mostly be doing reads from a database that has about 130 rows and will have about 5 tables that will link to each other. I may have one small bit of functionality where I will need to let the user add data and delete data.

      So what do you think? SQLite or Core Data? I don't know Core Data at all. Thanks.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Hi Todd,

      That is a good question which i will try answer truthfully. If you are well versed in SQL as you say, then you could simply SQLite as is and embed your SQL query directly in the code. However for more strenuous query and data models as you well know can become quite complex, I would opt for Core Data.

      In SQLite instead of having sprocs, you would need to develop functions and add them to them database. what Core Data brings to the table is a sophisticated E/R designer with full ORM capabilities which makes complex data modeling a breeze. In addition using Predicates (NSPredicate),which compares to other on the market like Hibernate, EJB3, or TopLink form Oracle to name a few, you can map your data entities to objects very easily and build very complex queries.

      I use both; for light lifting, i use SQLite, but more complex or enterprise class apps, I use Core Data.

      I hope this makes things a little clearer.

      Kevin

    • Todd Hugie 4 years ago

      Thanks Kevin. Very helpful. I think for the future features I want to add to my app that I will learn Core Data and use it.

    • Harry Blackmore 4 years ago

      Is there a way I could possible download the source code for this app?

      Harry Blackmore

    • mra59 4 years ago

      Helle and thank you for this tutorial

      I am working on a project and i tried to use your method to get informations from a table, but i have a litte problem that he can't find my Table.

      I used sqliteManager for firefox to create the database and i put it into my project !

      Can you help me please ?

      thank you

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Hi mra59,

      Does your code open the database properly? Can you see if the database variable is set from the Console window?

      Kevin

      Hi Harry Blackmore,

      If you send me an e-mail, see link on this page (near top on the righthand) I can send you a zip of the project.

      Kevin

    • mra59 4 years ago

      Thank you for your message.

      I resolved my problem :

      1- i put "NSString *dbPath = [[NSBundle mainBundle]pathForResource:@"IOSDB"ofType:@"sqlite"];" instead of "NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"IOSDB.sqlite"];"

      2- To add the database sqlite file, i used the "add files to " and not the drag and drop method

      Best regards.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      I am glad you were able to find the problem. Thanks for your kind words

    • Nick 4 years ago

      Hi, thanks again for the tutorial. I'm trying to implement a previous button. I looked through the messages here and saw one person asking for that. you said try "rowIndex-1" i can't see where to implement that?? I tried changing the currentIndex like this :-

      - (IBAction)last:(id)sender {

      static NSInteger currentIndex = 0;

      if (currentIndex-1 == [self.products count]) {

      currentIndex=0;

      }else{

      productList *aProduct = (productList *) [self.products objectAtIndex: currentIndex];

      [self.productName setText:aProduct.title];

      [self.productDetail setText:aProduct.detail];

      [self.productMovie setText:aProduct.movie];

      [self.productPDF setText:aProduct.pdf];

      [self.image setImage:aProduct.image];

      directory = aProduct.title;

      filename = aProduct.movie;

      }

      }

      But that doesn't work properly. I can scroll through next, but when I press the previous button it just returns me to the beginning of the array, not the last entry. Any help would be appreciated! Thanks!

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      It seems form your code that everything you call the last method, you are setting your row index to 0. The rowIndex that I am referring to is the index of the UITableCell that the user has selected. You would need to get the last rowIndex, maybe set a global variable, so that you button can do a currentIndex = rowIndexGlobalVariable -1. Also I wouldn't declare the currentIndex as static in the method since every time you call the method the variable gets reset to 0. Try implementing in the header

      @property(nonatomic, strong) NSNumber * currentIndex;

      In the implementation

      @synthesize currentIndex;

      then you could initialize it in the viewDidLoad or somewhere else like

      currentIndex = [[NSNumber alloc] initWithInteger:0];

      or

      currentIndex = [[NSNumber alloc] initWithInt:0];

      Hope this helps

      K

    • Nick 4 years ago

      Thanks, I think I follow what you mean. Just not 100% sure how to set the global variable and have it retain the last row that was selected.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      when app is loaded, in the viewDidLoad method

      currentIndex = 0;

      .....

      Say you have two buttons on your Scene; one to go forward and one to go back. Since your data is stored in a NSMutableArray, if you are following my code, when you click on the forward or button button, you can use something like

      Forward button:

      currentIndex += 1;

      [[ProductsArray objectAtIndex:currentIndex] doSomethingWithReturnObject];

      Back button:

      currentIndex -= 1;

      [[ProductsArray objectAtIndex:currentIndex] doSomethingWithReturnObject];

      The objectAtIndex returns the object (or value) at index n. You just need to assign the object to another variable , etc.

      K

    • Todd Hugie 4 years ago

      Hi Kevin,

      This question has nothing to do with database programming on the iPhone but I've asked this question other places and I'm not getting an answer. Please help.

      My app will show a lot of pictures. I will have a screen showing small thumb nails of the pictures and then going to a detail screen showing a full screen of the picture.

      So my question, should I scan and store two pictures, a small one of the thumbnail and a large one for the full screen? It seems logical to only scan and store one picture, a large one, to use in both places to save disk space. What do you suggest? Also, I plan on creating an iPad version so I need even a larger picture. So, how many pictures do I store? One for everything or one for thumbnails, one for old iPhone, one for high resolution iPhone, one for iPad and then one for the new iPad 3 coming out which will probably have a very high resolution screen?

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      I would scan and store one picture of each and just resize as needed. This is relativity easy; either with a web/native hybrid (ObjC with WebView and Javascript bridge) or with ObjC using UIImage or use the UIImageView. So , yes definitely resize.

      I am glad you asked the question.

      K

    • Nick 4 years ago

      Kevin,

      Thanks, I tried to implement this but I got errors. When I added the currentIndex=0 in the view did load method I got errors in the action for the next button saying that a local declaration of currentIndex is hiding the instance variable. and when I add currentIndex+=1 to the action I get an error saying "Arithmetic on pointer to interface NSNumber which is not a content size in none fragile ABI".

      - (IBAction)getProduct:(id)sender {

      currentIndex += 1;

      if (currentIndex == [self.products count]) {

      currentIndex=0;

      }else{

      productList *aProduct = (productList *) [self.products objectAtIndex: currentIndex];

      [self.productID setText:aProduct.productID];

      [self.prodName setText:aProduct.title];

      [self.description setText:aProduct.description];

      [self.image setImage:aProduct.image];

      directory = aProduct.productID;

      }

      }

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Nick

      Try something like this:

      add to header:

      int nbr;

      in implementation:

      in viewDidLoad:

      //if NSNumber is needed

      number = [[NSNumber alloc] initWithInt:0];

      nbr = 0;

      NSString * nbrStr=[NSString stringWithFormat:@"%d",nbr];

      [labelOutput setText:nbrStr];

      ===============================

      in buttons:

      nbr ++;

      //or Nbr --;

      //if you want to store in a number

      number = [NSNumber numberWithInt:nbr];

      NSString * nbrStr=[NSString stringWithFormat:@"%d",nbr];

      [labelOutput setText:nbrStr];

      I will write up a proper tutorial to fully demonstrate

      I repost the link here later

      kevin

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

    • Nick 4 years ago

      Great, thanks very much for your help with this I have got everything working correctly, here's my final code that is tested and works :-

      //Skip to next product

      - (IBAction)getProduct:(id)sender {

      nbr++;

      if (nbr == [self.products count]) {

      nbr=0;

      productList *aProduct = (productList *) [self.products objectAtIndex: 0];

      [self.productID setText:aProduct.productID];

      [self.prodName setText:aProduct.title];

      [self.description setText:aProduct.description];

      [self.image setImage:aProduct.image];

      directory = aProduct.productID;

      NSLog(@"number is %d",nbr);

      }else{

      productList *aProduct = (productList *) [self.products objectAtIndex: nbr];

      [self.productID setText:aProduct.productID];

      [self.prodName setText:aProduct.title];

      [self.description setText:aProduct.description];

      [self.image setImage:aProduct.image];

      directory = aProduct.productID;

      NSLog(@"number is %d",nbr);

      }

      }

      //Skip to previous product

      - (IBAction)previous:(id)sender {

      //nbr--;

      if (nbr-- == 0) {

      nbr = ([self.products count] -1);

      productList *aProduct = (productList *) [self.products objectAtIndex: nbr];

      [self.productID setText:aProduct.productID];

      [self.prodName setText:aProduct.title];

      [self.description setText:aProduct.description];

      [self.image setImage:aProduct.image];

      directory = aProduct.productID;

      NSLog(@"number is %d",nbr);

      }else{

      productList *aProduct = (productList *) [self.products objectAtIndex: nbr];

      [self.productID setText:aProduct.productID];

      [self.prodName setText:aProduct.title];

      [self.description setText:aProduct.description];

      [self.image setImage:aProduct.image];

      directory = aProduct.productID;

      NSLog(@"number is %d",nbr);

      }

      }

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Cool. I am really happy you got everything working.

      Have a good one!

      Kevin

    • Diogo 4 years ago

      Thanks for the great tutorial.

      It's possible update the data in this way?

      Because i need a pre populated database and update or insert more data.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Yes, actually I also wrote a tutorial to perform CRUD ops. Please check out this one :

      http://hubpages.com/technology/IOS-5-SDK-Database-...

    • Jon 4 years ago

      Thanks so much for the tutorial! Very clear, and it helped me fix a couple of bugs I had. I've been porting a C# program to the iPAD, and you really helped me make a breakthrough.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      I am really glad I was able to help... thanks for the feedback.

    • bichitojona 4 years ago

      Hi is a really nice tuto, i follow the steps and when i run, the app doesn't show the images, do you have any idea what's happening? should I positioning the images in project folder??

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Thanks for the feedback...

      When you run the app on debug, is the blob variable returning binary data. In other words, is the UIImage being properly assigned?

    • Ric 4 years ago

      Hi klanguedoc,

      This is a great tutorial. I got thru it this week and it is very straightforward and well explained. Can't wait for your book to come out!

      Ric

    • Ric 4 years ago

      One question though, I'm looking to do an app with an SQLite database, but with multiple views to the data in a tab view format. are there any special considerations in doing this and can you suggest any tutorials on this?

      So sticking with the wine app theme, one tab could list all the wines in alphabetical order, the second tab consists of all wines ordered by rating.

      Thanks again!, ric

    • Ricardo 4 years ago

      Hello!

      Thanks for the tutorial!

      I'm getting an error message: Problem with prepare statement

      That means that something is wrong with my database?

      Thanks

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Thanks.

      Yes probably the prepare statement wasn't added properly to the database. Is the database properly initialized?

      Kevin

    • Ricardo 4 years ago

      I'm dong the debugging and that's the only thing that "fails" so I'm thinking that the DB is initialize because if not I would get "An error has occurred" right?

      someone else had that problem from what I read in the comments and was able to fix it but didn't post the solution.

      i'm thinking that the problem is either in:

      "const char *sql = "SELECT id, Wine, Rating, Photo FROM WineTbl";"

      or

      "if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)"

      Thanks

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Hi Ricardo,

      I am running the app with the above code and it runs ok. Is sqlite3_stmt *sqlStatement; properly initialized in debugger?

    • Ricardo 4 years ago

      I somehow got it to work! Thank you so much for this tutorial!!

      I have a question, this line:

      [self.winename setText:((WineList *) [self.wines objectAtIndex:0]).wine];

      prints the object in one UILabel, how about if I want several wines in that one label (I just make the label use multiple lines). Instead of using different labels.

      I tried replacing objectAtIndex for objectAtIndexes but that didn't work. any ideas?

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      You're welcome Ricardo, I appreciate the feedback and the discussions.

      Try loading the values in a string with stringByAppendingString. You can use in a loop.

      Hi Ric,

      Sorry I missed you comment... I didn't get a notification...strange. I supposed to you could load two arrays; one a for one list and the other for wine ratings. The second one you could assign to an id object and pass it to another UITableViewcontroller.

      Hope this helps

      K

    • manojglobal profile image

      manojglobal 4 years ago from Kolkata

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      You are a Data Extraction specialist?

    • manojglobal profile image

      manojglobal 4 years ago from Kolkata

      yes.. have any data extraction project plz send me

    • bhjakobsen 4 years ago

      Simply nice and very helpful

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      I am glad you approve

    • ike 4 years ago

      Hey klanguedoc ...Thanks for the tutorial! this is really amazing stuff! I've been trying to get this to work on xcode 4.2. Can you help me? It keeps showing me the main.m and says SIGABRT when I try to run it. (there's a "problem with the prepare statement" I've included the page it keeps showing me below.

      //

      // main.m

      // MyWineList4

      //

      // Created by me

      // Copyright (c) 2012 __MyCompanyName__. All rights reserved.

      //

      #import "kcbAppDelegate.h"

      int main(int argc, char *argv[])

      {

      @autoreleasepool {

      return UIApplicationMain(argc, argv, nil, NSStringFromClass([kcbAppDelegate c

      This is what is in the output box apparently there's a "problem with the prepare statement":

      GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug 15 16:03:10 UTC 2011)

      Copyright 2004 Free Software Foundation, Inc.

      GDB is free software, covered by the GNU General Public License, and you are

      welcome to change it and/or distribute copies of it under certain conditions.

      Type "show copying" to see the conditions.

      There is absolutely no warranty for GDB. Type "show warranty" for details.

      This GDB was configured as "x86_64-apple-darwin".Attaching to process 3428.

      2012-04-21 19:12:42.796 MyWineList4[3428:207] Problem with prepare statement

      sharedlibrary apply-load-rules all

      Current language: auto; currently objective-c

      (gdb)

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Hi, thanks for kind comments, I am glad you find my tutorial useful.

      Problem with prepare statement

      This means your query string, like:

      const char *sql = "SELECT id, Wine, Rating, Photo FROM WineTbl";

      sqlite can't parse the your query string. There might be a typo somewhere, maybe missing a comma. Anyway your query string is not well formulated. It occasionally happens to me since there is no syntax checker for the string itself but the string needs to match sqlite syntax requirements.

      Hope this helps

      Kevin

    • venkat duvvuri 4 years ago

      Thanks for this tutorial

      i'm getting an exception while running the code like this

      Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'

      but it's working for some rows

      plz help me i'm new for this obj-c

    • Ike 4 years ago

      Hey Klanguedoc,

      Thanks for getting back to me. Can you tell me where to look to find this error?

      thanks,

      Isaac

      This is what you said before:

      Hi, thanks for kind comments, I am glad you find my tutorial useful.

      Problem with prepare statement

      This means your query string, like:

      const char *sql = "SELECT id, Wine, Rating, Photo FROM WineTbl";

      sqlite can't parse the your query string. There might be a typo somewhere, maybe missing a comma. Anyway your query string is not well formulated. It occasionally happens to me since there is no syntax checker for the string itself but the string needs to match sqlite syntax requirements.

      Hope this helps

      Kevin

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      venkat duvvuri

      You are probably looping pass the bounds of the array

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Hi Isaac,

      Are you using a where clause, or are you doing something like "Select * from table"

      For the first

      "select cola, colb from table where colc = ?"

      Don't try replacing the interrogation with a string value, like appending a NSString value because this will cause an error.

      For the second possibility, always use column names instead of the wild card

      Otherwise can you post your code in the comments

      Kevin

    • Klaws 4 years ago

      The sqlite3_prepare is returning 1 and not SQLITE_OK, which will be a problem with prepare statement, how to debug such error?

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Hi Klaws,

      A return code = 1 means SQLITE_ERROR. SQLITE_OK is equal to 0. It is hard to provide advice without seeing the code.

      There is something wrong (I know this sounds lame) with the syntax of your query string. You could try running the query from the SQLite command line.

      From the SQLite web site, an error code = 0 usually means /* SQL error or missing database */

      Is your db properly set?

      Kevin

    • arotob 4 years ago

      change the wine to winename in the sql query

    • arotob 4 years ago

      change the sql query "SELECT id, wine,rating, photo from WineTbi" to "SELECT id, winename, rating,photo from WineTbi" change the wine to winename and it will work

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      SQLite is not made to be used form a network location. It is strictly a local database engine. For network io database access you would need to use NSUrlConnection and related methods like + sendSynchronousRequest:returningResponse:error: or – initWithRequest:delegate:

    • kfuller002 4 years ago

      hi i'm having the same issue as a few people above with the prepare statement. I tried to follow this tutorial as closely as possible and i even tested my select statement in SQLite manager and it worked fine. I'm using, "SELECT id, Wine, Rating, Photo FROM WineTbl"

      i tried copy paste and i tried typing it out and it still doest work so im not sure what the issue is.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Does the database open correctly? Can you paste your code here, maybe I can spot something?

      Kevin

    • jasonb2020 4 years ago

      hey kfuller002, same issue here.

      I execute my SQL in the SQLite Manager - all good.

      un the app and get the prepare statement "index 0 beyond bounds for empty array" error,

      When I NSLog the count of wineArray I get zero (0).

      I know the db is in the correct location and being accessed, I just can't seem to get any results returned - even tried NSLogging the result of "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"

      Same error!

      Anyone have any hints?

    • jasonb2020 4 years ago

      "SELECT id, winename, winerating, wineimage FROM wine"

      from SQLite Manager returns 6 records.

      Here's the MyWineList.m source ...

      ---------------------------------------------------------------

      #import "MyWineList.h"

      #import "WineList.h"

      @implementation MyWineList

      - (NSMutableArray *) getMyWines{

      NSMutableArray *wineArray = [[NSMutableArray alloc] init];

      @try {

      NSFileManager *fileMgr = [NSFileManager defaultManager];

      NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"IOSDB.sqlite"];

      BOOL success = [fileMgr fileExistsAtPath:dbPath];

      if(!success)

      {

      NSLog(@"Cannot locate database file '%@'.", dbPath);

      }

      NSLog(@"Successfully connected to the DB.");

      if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))

      {

      NSLog(@"An error has occurred.");

      }

      //

      NSLog(@"About to enter the loop");

      const char *sql = "SELECT id, winename, winerating, wineimage FROM wine";

      sqlite3_stmt *sqlStatement;

      if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)

      {

      NSLog(@"Umm ... there was a problem with prepare statement");

      NSLog (@"Number of elements in array = %u", [wineArray count]);

      }

      //

      while (sqlite3_step(sqlStatement)==SQLITE_ROW) {

      WineList *MyWine = [[WineList alloc]init];

      MyWine.wineId = sqlite3_column_int(sqlStatement, 0);

      MyWine.wine = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,1)];

      MyWine.rating = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 2)];

      const char *raw = sqlite3_column_blob(sqlStatement, 3);

      int rawLen = sqlite3_column_bytes(sqlStatement, 3);

      NSData *data = [NSData dataWithBytes:raw length:rawLen];

      MyWine.photo = [[UIImage alloc] initWithData:data];

      [wineArray addObject:MyWine];

      }

      }

      @catch (NSException *exception) {

      NSLog(@"An exception occurred: %@", [exception reason]);

      }

      @finally {

      return wineArray;

      }

      }

      @end

    • Karol 4 years ago

      Having the same problem here :/ i ve read all of the comments above but none of them were able to provide solution. Every time people said "I somehow got it to work". Please help us what does that "somehow" mean.

    • jasonb2020 4 years ago

      so ... I checked the file size of main.sqlite in the iPhone Simulator/5.0/Applications directory and it was zero (0).

      Went back to xcode removed the reference to the db in the project, then deleted the main.sqlite db file from the Simulator directory, repeated the import process, checked the file size (now 819200kb) re-ran the app in Simulator and still getting the same error: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'

      :(

    • kfuller002 4 years ago

      Is there anyway to get a more accurate error besides "Problem with prepare statement"??

    • kfuller002 4 years ago

      Alright i figured out the real problem everyone is having with the prepare statement. The issue is not with the select statement it's with adding the db to the project. when you click and drag under add to targets, only the test program was selected and not the main one, make sure both are selected and it will work.

    • kfuller002 4 years ago

      sorry if the above is unclear, when dragging the db into your project folder the option screen pops up and look at the last set of options which is "add to targets" and make sure the main project is selected.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Hello json2020 & kfuller002

      Sorry for not responding sooner, I have been away. The index out of bounds simply means that there is nothing in the array. :/ Did the db initialize properly? Can you do a select in the SQLManager? If it helps I can send you the source code. Simply send me an e-mail at

      kevinlanguedoc[at]gmail.com

    • CrystalGravois profile image

      CrystalGravois 4 years ago

      Hi Kevin,

      I am new to writing iPhone apps and am trying to complete your tutorial. It seems I am having the same issue as a few people above with the "Problem with prepare statement

      ... *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'" message because my array isn't getting populated.

      To investigate I opened SQLite Manager & I ran the SQL query from the MyWineList.m file and it returned the results just fine. The MyWineList.m file is a copy & paste of yours (except naming lists vs list) so the code should be okay.

      So I'm at a loss for how to troubleshoot where the problem is? My one guess is maybe somehow my DB wasn't added to the project correctly? And that is why the array is empty?

      Any help would be greatly appreciated! Thanks!!

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      You are right, you have to make sure that the database is added to the project. You can try to use the "Add Files to the project" from the Xcode the context menu (right click on the project root). Navigate to the place where you saved your database file and copy it to the project. When you run your project, make sure the database is open. the out of range error is simply an empty array. If you want I can send you the source code to the project. Just send me an e-mail at kevinlanguedoc[at]gmail.com and I will send it to you.

      Kevin

    • Rafael 4 years ago

      Hi, I follow your tuturial but don't work. I debug the code and in this line:

      if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)

      {

      NSLog(@"Problem with prepare statement");

      }

      enter the if case and thing go wrong...

      If you could, how can I make it work right? Thanks.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Hi Thanks for the feedback sorry you are having problems. Could you post the error message or give me more details?

    • Rafael 4 years ago

      The Debug Output:

      "2012-06-20 10:06:16.780 MyWineList[99757:f803] Problem with prepare statement

      2012-06-20 10:06:48.620 MyWineList[99757:f803] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'

      *** First throw call stack:

      (0x1594022 0x1725cd6 0x1580d88 0x26fa 0x19ca1e 0xfb401 0xfb670 0xfb836 0xc881dd8 0x10272a 0xd3596 0xd4274 0xe3183 0xe3c38 0xd7634 0x147eef5 0x1568195 0x14ccff2 0x14cb8da 0x14cad84 0x14cac9b 0xd3c65 0xd5626 0x235d 0x22c5)

      terminate called throwing an exception(lldb) "

      I don't know why the sqlStatement goes wrong so don't execute while and the array become empty...

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Is the database properly initialized? This message indicates that the array is empty, so the select statement is not reading from the database correctly.

      Can I see your select statement?

    • Tony 4 years ago

      I followed your tutorial. I would like to expand on it by using a table view controller as an initial screen listing the wine names, then navigating to the details screen. I am having trouble getting the "name" column extracted out of the sqliteDB. getting an "unrecognized selector sent to instance 0x6869910" error.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      This error usually means that the object you are trying to use is not properly set or is null. If you need help setting up the table, check out this tutorial

      http://hubpages.com/technology/IOS-5-How-To-Displa...

      or

      http://hubpages.com/technology/iOS-5-How-To-Displa...

      Hope this helps

    • Tyler 4 years ago

      I am having the same problem as a couple of the last people to comment. It appears that my array is not loading properly. The select statement I am using works perfectly in SQLite Manager and is as follows:

      "SELECT id, Wine, Rating, Photo FROM WineTbl"

      Any suggestions?

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      It is probably because the database is not properly opened or properly set.

    • deselma profile image

      deselma 4 years ago from Germany

      I build app with my own table following your tutorial. I add framework for sqlite from my project file. All works. Thanks. It's very helpful.

      FYI: I found it on the first page of my google search ... ;)

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Great thanks. I am grateful for the excellent ranking by Google.

    • cathi 4 years ago

      Hi, Great tutorial. Thank you for ur great work. We are benefited by it. Hope it helped me. Can u post tutorials based on master view and the way it works.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Hi Cathi,

      Always glad to help. Can you give me a bit more detail about which aspect about working with Master View Controllers that you would like to see.

      Kevin

    • tomtso 4 years ago

      Hi. Thanks for a great tutorial. I have learned a lot from it.

      However, I am facing a problem. When I am running your source code, I am getting som error and warning messages:

      "

      ld: warning: ignoring file /Developer/Platforms/iPhoneOS.platform/DeviceSupport/5.1 (9B176)/Symbols/usr/lib/libSystem.dylib, missing required architecture i386 in file

      ld: warning: ignoring file /Developer/Platforms/iPhoneOS.platform/DeviceSupport/5.1 (9B176)/Symbols/usr/lib/libsqlite3.dylib, missing required architecture i386 in file

      ld: in /Developer/Platforms/iPhoneOS.platform/DeviceSupport/5.1 (9B176)/Symbols/usr/lib/libobjc.A.dylib, missing required architecture i386 in file for architecture i386

      clang: error: linker command failed with exit code 1 (use -v to see invocation) "

      I suspect these warnings are related to the libsqlite3.dylib file. I am not successful in fixing this problem, looking and looking for the correct libsqlite3.dylib file. I can assure you that I have included the reference in xcode.

      Can you please help?

      Best regards, Tom

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      I am not sure what this error message is about. Did you the proper sqlite library file. If you continue to have problems I can send you project files.

      let me know

    • tomtso 4 years ago

      The problem solved itself after restarting the computer. Thank you so much for your help anyway :-)

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Great, it is always gratifying to fix a problem by re booting the computer. It would be nice if it was always like this :-)

    • andres 4 years ago

      hello I want to thank you in advance for sharing your knowledge I have been very helpful

      I have a question is that using NSLog I realized that if I take the data from the database but are not reflected in the GUI you could help me please there is additional configuration interface should I do in addition to linking the actions to the buttons for example change the class which controls the light thank you very much and sorry for my bad English

    • VIgnesh 4 years ago

      I followed your tutorial. Thanks btw for the excellent details. I wanted to know if there is anyway to view the database that is created ?

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Hi Vignesh, thanks for the feedback. You can send me an e-mail or provide an e-mail address and I can send you the code.

    • daskittlez69 profile image

      daskittlez69 4 years ago from midwest

      This is a cool hub. I have coded my own websites before but I have never attempted to do an app. Here is your up!

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Thanks daskittlez69. You should try, it is not much harder. Actually web sites (application) can be even more complex if you are dealing with transaction data.

    • srihot 4 years ago

      I'm new to MAC , This is excellent tutorial.

      Thank you very much. Is there any way to contact you for any future questions?

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Hi srihot

      Thanks for the positive feedback. You sure can and I will try my best to help you if I can.

    • ppillay 4 years ago

      Hello, I have just stepped into Objective C development world, this tutorial is very interesting and helpful.

      But once I started porting this tutorial...getting wired error mentioned above by Tom..I restarted my mac but no resolution, please help me...

      Error & Warning details:

      ============================

      ld: warning: ignoring file /Developer/Platforms/iPhoneOS.platform/DeviceSupport/5.0.1 (9A405)/Symbols/usr/lib/libsqlite3.0.dylib, missing required architecture i386 in file /Developer/Platforms/iPhoneOS.platform/DeviceSupport/5.0.1 (9A405)/Symbols/usr/lib/libsqlite3.0.dylib (1 slices)

      ld: warning: ignoring file /Developer/Platforms/iPhoneOS.platform/DeviceSupport/5.0.1 (9A405)/Symbols/usr/lib/libobjc.dylib, missing required architecture i386 in file /Developer/Platforms/iPhoneOS.platform/DeviceSupport/5.0.1 (9A405)/Symbols/usr/lib/libobjc.dylib (1 slices)

      ld: warning: ignoring file /Developer/Platforms/iPhoneOS.platform/DeviceSupport/5.0.1 (9A405)/Symbols/usr/lib/libSystem.dylib, missing required architecture i386 in file /Developer/Platforms/iPhoneOS.platform/DeviceSupport/5.0.1 (9A405)/Symbols/usr/lib/libSystem.dylib (1 slices)

      ld: in /Developer/Platforms/iPhoneOS.platform/DeviceSupport/5.0.1 (9A405)/Symbols/usr/lib/libobjc.A.dylib, missing required architecture i386 in file /Developer/Platforms/iPhoneOS.platform/DeviceSupport/5.0.1 (9A405)/Symbols/usr/lib/libobjc.A.dylib (1 slices) for architecture i386

      clang: error: linker command failed with exit code 1 (use -v to see invocation)

      Thanks,

      Prakash Pillay

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Hi Prakash,

      You need to target 5.0 to 5.1 sdk. i haven't tested the code on 6 if this is what you are using. You can add the additional support under Xcode preferences

    • gleutar 4 years ago

      Hi, this is a GREAT tutorial! I only used plists until now and was looking to find a tutorial on sql lite. This is great! I'll try the next one tomorrow (UITableView and sql lite).

      Btw, I have the same problem like four or five people before me. It seems, like you said several times, that my db is not loaded correctly. The select works fine, but I get the 'prepare statement' problem. How can I solve this? I removed the db from the project and added it again (now several times) but the error remains. Does the '@IOSDB.sqlite' statement have something to do with the name of the db or is this a standard command?

      Would you please send me the project files if you still have them? I saw you mail above. Is it ok if I sent you a mail?

      Thank anyway for the great tutorials! They are really great :)

      Regards, Goran

    • gleutar 4 years ago

      hi Kevin,

      yeah, since I'm new to sqlite I guess that I made a mistake that many newcomers made. It was the name of the db. Like I asked in the previous post, I didn't change the '@IOSDB.sqlite' statement to the name of my db. It works now like a charm!

      Thanks again for this tutorial!

    • ppillay 4 years ago

      Actually I have targeted for 5.1 sdk

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Hi gleutar,

      First I want to apologize for not answering sooner. I am also glad that you have fixed the issue. I guess a lot of programmers create their own db but use the name in the code, thus making the actual db file impossible to find. You can name the db anything you like as long as the sqlite or db extension is used, however I prefer sqlite because it is the native extension.

      ppillay,

      Notice in the error code message, you are missing the 5.0.1 sdk. Try downloading and the version it is requesting.

    • Frajedo 4 years ago

      Hello, and s first of all, GREAT POST, very useful for starting playing with SQLite... But... I'm having a problem... It's the same than many users had:

      Problem with prepare statement (blablablabla).

      I read all the comments and tried to repair the problem

      1º) Your anser to a user: "Is the database properly initialized? This message indicates that the array is empty, so the select statement is not reading from the database correctly." Well... I declared it in the MyWineList.h, the code is: sqlite3 *db;

      2º) And the other question was from the user gleutar: "Like I asked in the previous post, I didn't change the '@IOSDB.sqlite' statement to the name of my db. It works now like a charm!" . I just don't understand what he did there... Can you please explain it a little bit more? :)

      But again, thank you for this tutorial, it is awesome!

    • MinMin 4 years ago

      Hi can I have the source code for this, I can't get it to work. I have the empty array issue as well.

    • MinMin 4 years ago

      NVM, it worked! I'd like to create a back button though. I am creating a reader, so it would be easy to navigate. Your tableview tutorial doesn't include this detail view. Do you think you could make one like that.

      Thanks so much!

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Frajedo,

      Sorry for the long delay, your comment was flagged as spam for some reason. Anyway, make sure the name of the database file is the same as the name in the code, or vice versus, change the name of the database file in the code to match yours.

      MinMin,

      I am you got it to work. And yes I can create a forward and backward nav button tutorial. Give a day or two.

    • Nardine 4 years ago

      Hi! I am a beginner to developing iOS apps. I just finished trying out this tutorial and it works 90%. Want to attempt locating the errors before jumping in for help.

      (I also had the NSRangeException but I got it fixed. Forgot to include the line that actually adds the sql query results into the array. Hopefully this helps someone else)

      My question is this: comparing the various methods data can be stored in an iOS app (Core Data, Property Lists, SQLite etc) which of the various methods would be suitable for storing large amounts of data for an app. For example, a Bible app or say an app for carols where the content isn't so small & needs to be saved somewhere. What kind of storage method(s) would you recommend & why. I have been trying to get familiar with the various data storage methods but would also like some advise from someone more experienced and has probably worked with such things.

      Thanks a lot! and great blog.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Thanks Nardine.

      For large storage, SQLite or Core Data both have the same capabilities since Core Data uses SQLite for storage. What Core Data provides is ORM (like Microsoft Linq or Hibernate). But in terms of ease of use, Core Data is better than the two others because in addition to the ORM part, Core Data can also allow you create tables and relationships in a visual editor (or designer) which are created in the SQLite database

      But for large amounts of data, you might be better off storing it on a database server reachable by web service, but for a book, even a bible, either SQLite or Core Data will be ok. Remember that HDDs on iOS devices are getter bigger or will get bigger as time passes.

    • Nardine 4 years ago

      Thanks Klanguedoc! I was also able to fix my other errors so the tutorial try out works perfectly now.

      I was wondering, could you please do a tutorial on building a calendar based app that isn't connected in anyway (if possible) to the inbuilt calendar app created by Apple and built without 3rd party libs?

      Thanks :)

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Hi Nardine,

      You have read my mind because I am currently in the process of laying the groundwork for such an app...stay tuned :)

      I am glad to hear that you were able to work out the kinks.

    • Nardine 4 years ago

      That is great! Looking forward to the post :-)

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      I am working on it

    • tinkerer 4 years ago

      hi, this is great. one question - when I try to do Ctrl+drag for IBOutlet connections, I get nothing on the .h file; any idea what's going on?

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      When the connection line reaches the header file, there should be a line (blue?) appear in the header file where the code will be written. Does it happen or is there some other response from the header or connection operation? I have never seen that before, but have you tried restarting Xcode and/or your Mac?

    • tinkerer 4 years ago

      hi, no line appears (I am pretty new to iOS programming but I know what yo are refering to, from Apples's Hello World tutorial). Restarting Mac/Xcode doesn't help.

      I did have original storyboard file deleted by mistake, so i created a new one with a different name than original. I can run simulator and see background color changes happening so I know it is somewhat working. Is this something to do with "delegate setting", in your code list, you don't show delegate.h/.m files.

      thanks in advance, I am trying to build a fun app of my pics.

    • srihot 4 years ago

      Hi,

      I have one local SQLITE database, and two apps required to access the local database. First app post records and another retrieve records. (Each time I am running the app it is copying database to different simulator location)

      Can please guide me this?

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      tinkerer

      For the new storyboard name, did you update the plist file for the new storyboard name and also set the storyboard name in the Main Storyboard setting in the Project Summary page. You can also drag a connection from the table to the proxy object at the bottom of the view controller and select "delegate". Also select the view controller in the storyboard and in the Atributes set the view controller custom class to your view controller h/m class.

      srihot,

      When you run an app with SQlite database, the app runs in its own sandbox. One app cannot access another app's sandbox. You would need two databases, one for each app.

    • Ray 4 years ago

      Great tutorial! Simply and very helpful. It is a tutorial that I actually understand all the content and steps. Thanks again.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Thanks Router Mill & Ray

    • tinkerer 4 years ago

      I didn't get storyboard connections to work; so re-did the whole app from scratch and it worked well. I just tested in iOS6 iPad simulator, seems to work ok, except the 1st image is not getting repeated after flashing once, as I do next/next/next. I am trying to figure it out,

      a great tutorial overall, thanks.

    • lu 4 years ago

      Hi,

      This is a really great tutoril, but it only stores data in the phone.

      what if the database gets larger, how can I put the data base in a different server and still access it? Do you have a tutorial for that?

    • siad 4 years ago

      Hi , thanks for all the tutorials

      Can you make a tutorial with SQlite database. I want to Select and Insert data from three tables, not only one tables

      Can please guide me this?

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Thanks for the great feedback.

      Hi tinkerer,

      I haven't done any testing so far with iOS 6. I will check out the image browsing issue and post an update if needed.

      Hi Lu,

      I don't have a tutorial for off device databases. But what i have done in the past is use the NSURLConnection which can handle asynchronous connections like web services and Ajax to interface with a web service on a network database. I could prepare a little tutorial if you want.

      Hi slad,

      Thanks also. You can either use multiple databases with a single table or create multiple tables in a single database. The is simple, in the example below, instead of creating one table, just have three create table queries and execute them. To write a select, it is standard SQL: use an inner join on the table like any other SQL statement.

      char *emsg;

      BOOL fileExist;

      //Get list of directories in Document path

      NSArray * dirPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

      //Define new path for database in the documents directory because data cannot be written in the resource folder.

      NSString * documentPath = [[dirPath objectAtIndex:0] stringByAppendingPathComponent:@"binaryDb.db"];

      fileExist = [[NSFileManager alloc] fileExistsAtPath:documentPath];

      if(fileExist){

      if(!(sqlite3_open([documentPath UTF8String], &db) == SQLITE_OK))

      {

      NSLog(@"An error has occurred.");

      }else{

      const char *sqlTable = "create table if not exists binaryTbl(fileName varchar, binaryData blob)";

      if(sqlite3_exec(db, sqlTable, NULL, NULL, &emsg) != SQLITE_OK)

      {

      NSLog(@"There is a problem with statement");

      }

      }

      }

    • srihot 4 years ago

      Hi,

      I created a prototype app using this code and working, But last minute , I have to update few of these fetched records. Can you please guide me,

      I created a new App for Find a record and update the same and Insert a new record. All these are working.

      BUT I want to use the above code and update method also

      Can you please help me. Thanks in advance

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Hi srihot,

      I will post later today.

    • srihot 4 years ago

      Thanks Kevin,

      Could please make sure It should have model group with 4 classes and Update button code in the viewcontroler.m

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Hi srihot,

      Please take a look at this tutorial I wrote. It demonstrates how to update records in a SQLite database.

      http://hubpages.com/technology/IOS-5-SDK-Database-...

    • Haider Ali 4 years ago

      Very good tutorial for the newcomer in iPhone, but i have a problem, i have followed each and every instructions u made in ur tutorial but i put the records more than two in the sqlite db,and run my app, i just watch the first two,how can i see the all records in my app on next bottal button click

      Thanks a lot Sir,

      waiting for ur reply

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Thanks Haider Ali, does your NSMutableArray contain all the records in the database?

    • srihot 4 years ago

      Dear Kevin,

      I ran the app on iPad . It was running in simulator with out any problem.

      But when I ran this app on iPad , Find fetching records , but update is not working,

      Is there any special access required for write to database. I created DB and table as you explained in the above

    • srihot 4 years ago

      Error:

      2012-10-14 12:58:55.882 AppName[1842:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error: failed to insert into the database with message 'attempt to write a readonly database'.'

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      The database has to be in the Documents directory. In this tutorial it is in the Resource folder which is read-only. The Documents folder is read-write.

    • omid 4 years ago

      hi klanguedoc ... first of all i want to thank you for this great tutorial...

      i have 1 confusion since i just started out working with objective c... after i create the database and the table inside the Sqlite manager, do i need to export it and drag it to my project? if yes why is the extension .sql not .sqlite when i export it? thanks in advance ...

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Iva

      You need to use the NSNumber instead of double and the stringValue property.

    • Iva 4 years ago

      Hallo klanguedoc,

      thank you very much for your answer. I´m a newbie and I don´t know what to do exactly.

      I made now i SQLite Manager a new field price - REAL,

      Than in WineList.h - NSNumber *preis; and @property (nonatomic, retain) NSNumber *preis;

      kcbViewController.h - @property (weak, nonatomic) IBOutlet UILabel *preis;

      But now I don´t know what to do in kcbViewController.m.

      Can you please help me once again?

    • tinkerer 4 years ago

      hi,

      Where in the code do you specify the path to database? I am trying to change the database, but somehow the simulator keeps showing me the original database.

      I simply want to replace the old database with new one.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      It is here

      NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"IOSDB.sqlite"];

      iva,

      in the method where you want to set the number to the label do this (you should not have a instance variable preis and a UILabel preis

      preis.text = [preis stringValue];

    • Iva 4 years ago

      Thank you very much:)

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      glad to help

    • Iva 4 years ago

      Dear Kevin,

      I have one more question... :)

      Is it possible to make -IBAction GetWineListing method, that when the user clicks on this button next wine will be shown in another View Controller?

      Finally implement the GetWineListing method, so when the user clicks on the button, the index gets incremented and retrieves the data at the selected index number.

      - (IBAction)GetWineListing:(id)sender {

      static NSInteger currentIndex = 0;

      if (++currentIndex == [self.wines count]) {

      currentIndex=0;

      }else{

      WineList *aWine = (WineList *) [self.wines objectAtIndex: currentIndex];

      [self.winename setText:aWine.wine];

      [self.winerating setText:aWine.rating];

      [self.wineViewer setImage:aWine.photo];

      }

      }

      This functions only in the same View Controller...

      Thank you very very much for your help!!!

      Iva

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Hi Iva,

      Yes it is possible. After defining a segue from the button to the other view controller and adding the button t the view controller proxy at the bottom of the scene where the button is located, add a prepareForSegue method to the implementation file in the prepareForSegue method get the row index from either the array using the objectAtIndex and then follow my other tutorials to send the data to the view controller.

      Also UITableViewDelegate has a method – tableView:didSelectRowAtIndexPath: that will retrieve the row selected which can be added to a variable so when the you clicks on the button will send the selected object to the next view controller. You will need to add the protocol to the header file and add the delegate to the scene proxy.

      Hope this helps

      Kevin

    • Iva 4 years ago

      Kevin,

      thank you, it helped me again!!! :)

      Iva

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Great I'm happy :)

      Kevin

    • SPT 4 years ago

      Hello Kevin,

      Thank you so much for posting the tutorials, I greatly appreciate. I went through both of the Tutorials on SQLITE and they both helped me a lot... Since I am very GREEN in programming and SQLITE is completely new subject, I have a question that had been on my mind since I started learning SQLITE and if you could help me with my Paranoia or point me in the right direction I would greatly appreciate it (my apology if this was already asked by someone). Let me explain the Scenario here:

      1. Let's say I post an APP, that saves everything into the DB, in the STORE today.

      2. The Customer that downloads APP will use the APP for a while, which will cause for him/her to have lots of Data Saved in the DB.

      3. Let's say, after a while I need to make updates to the APP.

      The question is, how can I Prevent the loss of data in the DB that the customer saved for a while? Please let me know.

      Thank you,

      SPT

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      HI SPT,

      I am glad the tuts have help you out. What I do in the production environment is create a backup directory in the Library directory. I then make a copy of the current database in this directory before upgrading or replacing the current database. Once the database is upgraded or replaced, I then move the data back using SQL or update the data as needed.

      Once thing you mentioned that you need to manage is backups since SQLite databases can grow very large over time and you will need to backup strategy.

      Here I use two different strategies, sometimes I provide a means to let the user backup his or hers data to iCloud, Dropbox or a corporate network or computer, otherwise I simply make a copy of the database to one of the abovementioned places.

      Hope this helps

      Kevin

    • Appdev 4 years ago

      Thank you for the fantastic tutorial ! Do you have any related to Push Application that use APNs?

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      thanks for your kind words however I don't have any code or tutorials on APN at the moment

    • AramDIV 4 years ago

      Hello klanguedoc .. I just want to say many thanks to you ... YOU ARE BRILLIANT TEACHER !

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Wow AramDiv. Thank you very much.

    • ty 4 years ago

      hey klanguedoc,

      Thank you so much for the tutorial. I followed any other tutorial on sqlite but none of them worked. so, i would like to know if you have another tutorial where database creation is hardcoded instead of creating it at some other place first? because those are the tutorials i've tried so far and always failed.

      Thanks once again.

      Cheers!

      Ty

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

    • bkasmai 3 years ago

      Hi klanguedoc

      This is one of the best tutorial on iOs+sqlite i have come across. I would be really grateful if you could please shed some light on the error below. I am really struggling to get to the bottom of this as I have checked the code on GetWineLising over and over again without much luck.

      *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[kcbViewController 0x748d530 setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key GetWineListing. '

      PS I have to remove inequality signs from the error message to make the posting possible

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

      Hi bkasmai,

      Sorry for the late reply. I would say that your view controller kcbViewController is not properly setup in the Storyboard. Or is this class added to the corresponding view controller in the Storyboard (see custom class in identity inspector). Thanks for kind words.

    • LegaultMD 3 years ago

      Great tutorial! I just have one question.

      If I want to change my database, or add more entries in it, do I have to do this entire process again? Or I just add the necessary lines of code?

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

      Hi LegaultMD,

      If you are updating your database, all you need to change the db file and update the code if you change the database schema.

      Kevin

    • iMx 3 years ago

      Thanks for this tutorial!

      I want to extend the LegaultMD's question: assuming an user adds some entries in a table, and than I want to change the structure of this table. Will this overwrite the users data if the user installs the new version of the app (because he gets a new sqlite file with my entries)?

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

      Hi IMx,

      If the table maintains the original columns and data types, yes your data will be maintained. If you remove the original columns, you will need some kind of script to migrate the data already in the database. In other words you can change the schema as muh as you want as long as the original columns are maintained otherwise you will get errors or lost of data

    • Almas 3 years ago

      Hi everyone. I had the same issue with "problem with prepare statement". I fixed it by adding my database file into "target - build phases - copy bundle resources".

      I hope that helps..

    • Junior Programmer 3 years ago

      Hi thanks for this tutorial. However i'm getting an error while doing so. Also you have said "Now you can close the database from the Firefox menu and Firefox as well since we won’t need anymore for the tutorial".

      How am i suppose to read your tutorial and work it out then ? :P

    • milon 3 years ago

      The following error arise when i build my project where is the problem can anyone explain plz......

      Undefined symbols for architecture i386:

      "_sqlite3_column_int", referenced from:

      -[DBList getUser] in DBList.o

      "_sqlite3_column_text", referenced from:

      -[DBList getUser] in DBList.o

      "_sqlite3_open", referenced from:

      -[DBList getUser] in DBList.o

      "_sqlite3_prepare", referenced from:

      -[DBList getUser] in DBList.o

      "_sqlite3_step", referenced from:

      -[DBList getUser] in DBList.o

      ld: symbol(s) not found for architecture i386

      clang: error: linker command failed with exit code 1 (use -v to see invocation)

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

      Junior Programmer,

      I was referring to the SQLite Mgr in Firefox

      milon,

      is the sqlite library properly added to the frameworks?

    • Jung-su Kim 3 years ago

      Thank you for your good tutorial!

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

      Thanks

    • Russell Crow profile image

      Russell Crow 3 years ago from Flower Mound, Texas

      I built this and got the same error

      "Problem with prepare statement" and the follow up crash which looks like *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds for empty array'

      So I found my problem, it is the SELECT STATEMENT doesn't match the DATABASE COLUMNS. The 4 items you call in the statement have to match the columns in your database EXACTLY, otherwise the sqlite_prepare statement will fail.

      The following statement works:

      const char *sql = "SELECT id, winename, winerating, wineimage from WineTbl";

      IF AND ONLY IF the columns in your IOSDB.sqlite database are:

      id winename winerating wineimage

      ANY variance in ANY name causes a problem. Also, if you named this table WineTbi or winetable or anything else, it will fail.

      That's the problem with computers, they do exactly what you tell them to.

      Many thanks to Klanguedoc! This is one of the most straightforward iOS SQLITE tutorials on the web.

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

      Great I am glad you figured it out.

    • vijaynedra 3 years ago

      Nice tutorial I have one question h0w to set id into label?

    • vijayendra 3 years ago

      How to set Id with integer value and date with varchar in viewdidload?

    • karthi 3 years ago

      I stored images in my server. But images are not fetching from database. Can you give me some link?

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

      Hi Vijayendra,

      You can cast the UILabel to the id like (UILabel *) id. then you can use the UILabel properties and attributes.

      Karthi

      You can download the code from www.iosdev101.com

    • AMAN 3 years ago

      if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)

      {

      NSLog(@"Problem with prepare statement");

      }

      It print only "Problem with prepare statement".

      How can i solve this...?

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

      You have a typo in your query string

    • jd 3 years ago

      when i click on next button it doesn't work and i have msg Application windows are expected to have a root view controller at the end of application launch plz help me out

    • hahahahah 3 years ago

      lol :)-

    • Jason 3 years ago

      Its working thanks. I think, you does not need to write else{} in "- (IBAction)GetWineListing:(id)sender {

      static NSInteger currentIndex = 0;

      if (++currentIndex == [self.wines count]) {

      currentIndex=0;

      }else{

      WineList *aWine = (WineList *) [self.wines objectAtIndex: currentIndex];

      [self.winename setText:aWine.wine];

      [self.winerating setText:aWine.rating];

      [self.wineViewer setImage:aWine.photo];

      }

      }"

      Instead :-"- (IBAction)GetWineListing:(id)sender {

      static NSInteger currentIndex = 0;

      if (++currentIndex == [self.wines count]) {

      currentIndex=0;

      }

      WineList *aWine = (WineList *) [self.wines objectAtIndex: currentIndex];

      [self.winename setText:aWine.wine];

      [self.winerating setText:aWine.rating];

      [self.wineViewer setImage:aWine.photo];

      }" .

    • ThienHaoLe 3 years ago

      can you sent me your code?

      my email : thienhaole92@gmail.com

    • jd 3 years ago

      it working good love u kevin

      and i have one problem can u help me in my aplllication how we can match textfeild value with sqlite field value something like password field when user input wrong pass then alert them by wrong password please help me i am beginner in iphone developing

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

      ThienHaoLe

      All code can dowmloaded from my site : www.iosdev101.com

      jd

      you can create a method with a bool return value

      in header

      -(bool)checkPassword:(NSString *)input;

      implementation

      -(bool)checkPassword:(NSString *)inputValue{

      bool passwordOk = true;

      // do a simple select using similar as in example code above and other sample in my other tutorials. If the value matches inputValue, return passwordOk as is, otherwise set passwordOk = false

      return passwordFalse;

      }

    • Joe Morgan 2 years ago

      How much data can an iPad onboard SQLite database handle (Not web served)? I know that's a bit like asking how long is a piece of string but our developer is saying the queries are too large for the db to handle and slows down or returns unreliable data.

      I have a feeling that it's the way they've structured it, such as poorly built tables, indexes and queries.

      Any thoughts?

      Cheers Joe

    • klanguedoc profile image
      Author

      Kevin Languedoc 2 years ago from Canada

      Hi Joe,

      In theory, you can use all the available space on the iPad HDD. SQLite is a powerful database and can easily handle a 1 GB of data. As you mentioned, the table structures and index are very important in SQlite like in any database. I would start there, even testing your database outside of the iPad app using the SQLite CLI (CommandLine) to see if the issue is actually SQLite or the design of the app itself.

      Please let me know if you need more info or help

      Cheers

      Kevin

    • umr 2 years ago

      hello,

      thank you for tutorial. can i use some part of your code in my app?

    • klanguedoc profile image
      Author

      Kevin Languedoc 2 years ago from Canada

      yes, you can download the code from www.iosdev101.com

      Thanks

    • Mannan1994 2 years ago

      Hey klanguedoc ! this tutorial was awesome thanks for this tutorial .. :D

      I want to ask a simple question ,as in this tutorial we have taken the .sqlite file from our computer, how to get that file through the website or network

      Thanks

    • klanguedoc profile image
      Author

      Kevin Languedoc 2 years ago from Canada

      Hi Mannan1994

      Thanks fort the kind words. Aways appreciated :)

      SQLite is strictly a local database engine, meaning that you can't use on a network or a web site unless that web site is standalone. If you develop a mobile app, a desktop app either using native programming languages or web technology, you can use SQLite.

    • Mannan1994 2 years ago

      Ohh okay ! one last question , I have an database in .sqlite format , which contains more than 2000 rows in it , so I want my program to print all the text in an textview which is in its last column of database (by appending the previous string )

      and is there any way to print a arabic text file in our app through UITextView, when I tried to print it gets an error in console and my app stucks

      Thanks !

    • farmNXT 2 years ago

      Very nice and helpful article..!

      http://www.farmnxt.com/

    • klanguedoc profile image
      Author

      Kevin Languedoc 2 years ago from Canada

      I am glad I was able to help...

    • shahpratik profile image

      Pratik Shah 2 years ago from Mumbai

      I have been following this tutorial of yours and have been successful in taking it forward with search bar implementation & TabBar interface.

      However, I am stuck at one point if you can refer to some similar tutorial or guide on how to get it working...

      Instead of present logic that displays sqlite data in first tableview and than on select, show detailview, I need something like this...

      Load sqlite data in first TableView, than on selection, filter data to another tableview and then finally on select, show detail view.

      For e.g. in first tableview I load list of countries from sqlite, when I select a country, it loads list of states for that country in second tableview and than finally when I select a state, it shows details view of that state.

      Thanks in advance.

    • klanguedoc profile image
      Author

      Kevin Languedoc 2 years ago from Canada

      In your first tableviewcontroller, you need to implement a db search like :

      http://hubpages.com/technology/Develop-a-UISearchB...

      When you return the search results, store this in a new NSMutableArray and pass this to the next using the id object which will be the dataset for the second tableviewcontroller. You transfer the array the same way as the detailvewcontroller. Then on the second tableviewcontroller, you can do another select and display the state information in a detailviewcontroller.

      If you are stuck, let me know and I will write some code for you.

      Kevin

    • shahpratik profile image

      Pratik Shah 2 years ago from Mumbai

      Hi Kevin,

      Thanks for your reply.

      I am still struggling to get this working. Kindly suggest at your convenience.

      Many thanks.

      Pratik

    • klanguedoc profile image
      Author

      Kevin Languedoc 2 years ago from Canada

      Hi shahpratik

      I will put together some code for you to rudiment-ally illustrate what I mean.

      Kevin

    • shahpratik profile image

      Pratik Shah 2 years ago from Mumbai

      Hello Kevin,

      Sorry to bother you again, but by any chance do you have any step-by-step tutorial to add sections in uitableview that loads data from sqlite like in this same wine tutorial?

      I am trying to create section titles with country names and in that section will populate list of states for that country and clicking on state would bring up detail view of state. This will eliminate one extra view altogether.

      Many thanks in advance.

    • klanguedoc profile image
      Author

      Kevin Languedoc 2 years ago from Canada

      Sorry for the delay. I am working on it but I am on the tail end of a project and it is taking a lot of my time. Please give a few more days.

    • shahpratik profile image

      Pratik Shah 2 years ago from Mumbai

      Never mind. At your convenience please. Many thanks.

    • klanguedoc profile image
      Author

      Kevin Languedoc 2 years ago from Canada

      First download the FirtsTableProject from the iosdev101.com/downloads web site

      For both TableViwControllers, add the TableViewController delegate and DataSource proxies

      in the designer by dragging a connection from the view to the proxy icon at the top

      of the scene in the IB and select data source and then delegate. Do this for for both

      TableViewControllers.

      Next create a segue from table 1 to table 2 and name the segue showStates or something

      like this. Create a segue from table 2 to detail controller as well and name it in

      attributes.

      Add the TableViewController delegate and data source protocols to header files of

      TableVirewController

      1) First TableViewController

      header

      #import "CountryStates.h"

      #import "StateTableViewController.h"

      @interface TableViewController : UITableViewController[angle bracket]UITableViewDelegate,UITableViewDataSource[angle bracket]

      @property(nonatomic, strong) CountryStates * cs;

      @property(nonatomic, strong) NSMutableArray * countryList;

      @property(nonatomic, strong) StateTableViewController * statesv;

      @property(nonatomic, readwrite)NSInteger rowNbr ;

      @end

      implementation

      - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

      // Get the new view controller using [segue destinationViewController].

      // Pass the selected object to the new view controller.

      if([[segue identifier] isEqualToString:@"showStates"]){

      NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];

      statesv = [segue destinationViewController];

      //This is our data source that we are passing to the second TableViewController

      statesv.stateList = [[NSMutableArray alloc] initWithArray:(NSArray*)countryList];

      //We are passing the selected country to the second TableViewcontroller

      statesv.states = [self.countryList objectAtIndex:selectedIndexPath.row];

      }

      }

      2- Second TableViewController

      header:

      #import "CountryStates.h"

      @interface StateTableViewController : UITableViewController

      @property(nonatomic, strong) CountryStates * states;

      @property(nonatomic, strong) NSMutableArray * stateList;

      @property(nonatomic, strong) NSArray *filterValue;

      @end

      implementation:

      @implementation StateTableViewController

      @synthesize states,stateList, filterValue;

      - (void)viewDidLoad {

      [super viewDidLoad];

      //we need to de-reference the passed value

      states = (CountryStates*)self.states;

      stateList = (NSMutableArray*)self.stateList;

      // Uncomment the following line to preserve selection between presentations.

      self.clearsSelectionOnViewWillAppear = YES;

      NSPredicate * predicate = [NSPredicate predicateWithFormat:@"country contains %@",states.countryName];

      filterValue = [self.stateList filteredArrayUsingPredicate:predicate];

      }

      Setup the tableView methods like in sample app FirstTableProject. FilterValue is the new data source

      with the filtered list of states.

      For the prepareForSeque in second TableViewcontroller, use the sample code from the FirstTableProject

      to transfer selected value to detailViewController.

    • shahpratik profile image

      Pratik Shah 2 years ago from Mumbai

      Hello Kevin,

      Thanks for your efforts. I tried downloading the file, but it seems the link to FirstTableProject.zip is not working. Can you please check if the link is working at your end.

    • klanguedoc profile image
      Author

      Kevin Languedoc 2 years ago from Canada

      I will check. Sorry about that

    • klanguedoc profile image
      Author

      Kevin Languedoc 2 years ago from Canada

      shahpratik please send me an e-mail and I will send you the FirstTableProject directly to you.

    • klanguedoc profile image
      Author

      Kevin Languedoc 2 years ago from Canada

      you can download the FirstTableProject here:

      https://github.com/kevlangdo/iosdev101

    • shahpratik profile image

      Pratik Shah 2 years ago from Mumbai

      Hello Kevin,

      Thanks for the link. I did download the files. But unfortunately, I am not getting the filtered results on my second table view, instead I get blank tableview.

      Will keep trying as I learn to xcode :).

      Many thanks.

    • sam 20 months ago

      i m new to ios

      i want to establish connection b/w xcode and sqlite db.

      but i m nt getting connected

    • klanguedoc profile image
      Author

      Kevin Languedoc 20 months ago from Canada

      Are you getting an error message?

      Are you initializing the sqlite object?

    • Emmanuel 18 months ago

      Thanks a lot for this tutorial it solved a problem I have battling with for nearly two weeks

    • Segovia 18 months ago

      If I create this app and put it in AppStore, could all the users connect to the same database?

      It might be a silly question but I am really new to iOS.

    • M. Harbi 16 months ago

      Thanks a lot for this tutorial...

    • klanguedoc profile image
      Author

      Kevin Languedoc 16 months ago from Canada

      Segovia

      Only if you create a web based RESTful web service connected to a database like mongodb for instance or a RBMS like MySQL.

      Emmanuel

      Glad you figured it out

      Harbi

      Thanks for the feedback. I am glad the tutorial was helpful

    Click to Rate This Article