Button 0Button 1Button 2Button 3Button 4Button 5

Notes & Gotchas


This section is still under construction. It will summarize the most frequently asked questions, common pitfalls and hopefully, its solution or workaround.

Please join QuickLite's mailing list by visiting the QuickLite Users page and post your questions or sultions there. Share your knowledge! :-)

1. What type of license covers QuickLite?
2. Will your work become redundant when Apple releases their SQLite framework?
3. Does QuickLite support Unicode?
4. When I store and later retrieve a date, comparing them with isEqualToDate fails. Why is that?
5. I'm trying to get Quicklite working so I can build a little sample application to learn how this stuff works. I'm having a lot of problems mainly to find information on how to get the ball rolling... where do I start?



1. What type of license covers QuickLite?

QuickLite includes SQLite, each having its own license type:

2. Will your work become redundant when Apple releases their SQLite framework?

I hope not! ;-)

Apple includes the SQLite library in Mac OS X 10.4 Tiger. Based on the original SQLite distro, it includes support for locking on AFP, old school NFS, and SMB. Other than that, it is mostly identical to 3.1.3. In addition, Apple ships Core Data in Tiger, which uses SQLite internally.

Core Data isn't for everybody because it only runs on Tiger. This could be a major limitation for many developers.

On the other hand, QuickLite runs on 10.2, 10.3 and 10.4. It's comprised of only 3 classes, making it possible to get acquainted with it in no-time. I've received very good feedback from Cocoa beginners... and that is a good thing™.

I'm glad to report that Core Data has solved most of its original shortcomings. Just like QuickLite, Core Data offers these key features:

  • Multithreaded/multiprocess support.
  • BLOB support
  • Introspection methods

In addition, QuickLite offers distributed notifications when the schema or data changes.


3. Does QuickLite support Unicode?

Yes.

QuickLite includes SQLite version 3, which adds support for both UTF-8 and UTF-16 text. To know more about the changes introduced in this version, please refer to http://www.sqlite.org/version3.html


4. When I store and later retrieve a date, comparing them with isEqualToDate fails. Why is that?

The NSCalendarDate class stores sub-second information in floating-point precision. Given the nature of floating-point numbers, you can't rely on them to be 100% accurate. Even if you add the sub-second information using NSCalendarDate's:

- (id)addTimeInterval:(NSTimeInterval)seconds

the difference between the two could be negligent, but enough to fail the test using:

- (BOOL)isEqualToDate:(NSDate *)anotherDate

Therefore, if you want to compare two dates you can do something like this (let's assume you want care about second precision):

if (fabs([originalDate timeIntervalSinceDate:newDate]) < 1)
    NSLog(@"The two dates are the same.");
else
    NSLog(@"Date/Time test passed");


For more information, please refer to Apple's Cocoa page Comparing Dates.


5. I'm trying to get Quicklite working so I can build a little sample application to learn how this stuff works. I'm having a lot of problems mainly to find information on how to get the ball rolling... where do I start?

To get started, you have to know a little bit of Cocoa and SQL. Don't worry, you'll need to know how to perform SQL queries with SELECT. Pretty much everything else is handled by QuickLite, so you won't have to deal with more SQL. Download QuickLite and check the Examples folder. All of them will help you see QuickLite in action. You can start with BLOBTester since it's really simple. Check also SQLiteManagerX, it will help you introspect QuickLite datafiles and test your SQL queries.

> So my first goal is to create a new database? How do I do that?

NSString* path = [@"~/myTestDB.database" stringByExpandingTildeInPath];
QuickLiteDatabase* db = [QuickLiteDatabase databaseWithFile: path];

if ([db open]) {
    NSLog(@"The database is now open: %@", path);
} else {
    NSLog(@"Trouble when opening the data file. Make sure the path is valid.");
}

> When I open a db that does not exist does it create one automatically?

Yes.

> How do I create a new table?

- (BOOL)createTable:(NSString*)table withColumns:(NSArray*)columns
andDatatypes:(NSArray*)datatypes;

Example:

NSArray *creationColumns = [NSArray arrayWithObjects: QLRecordUID, @"first", @"last", @"zip", @"country", nil];

NSArray *creationDatatypes = [NSArray arrayWithObjects: QLRecordUIDDatatype, QLString, QLString, QLString, QLString, nil];

if (![db createTable: @"address" withColumns: creationColumns andDatatypes: creationDatatypes]) {
    NSLog(@"Error when creating 'address' table:%@", [db lastError]);
    return;
}

> How about inserting data?

- (BOOL)insertValues:(NSArray*)values forColumns:(NSArray*)columns
inTable:(NSString*)table;

Example:

NSArray *values = [NSArray arrayWithObjects: [NSNull null], @"Joe", @"Schmuck", @"Neverland", nil];

NSArray *columns = [NSArray arrayWithObjects: QLRecordUID, @"first", @"last", @"country", nil];

if (![db insertValues: values forColumns: columns inTable: @"address"]) {
    NSLog(@"Error when adding data to table 'address'. Error: %@", [db lastError]);
    return;
}

Note: for best performance, wrap all inserts around a transaction.

Example:

[myDB beginTransaction];
    ...
    <insert data here>
    ...
[myDB commitTransaction];

> Now that the database has data, how do I search for it?

QuickLiteCursor *cursor = [db performQuery: @"SELECT * FROM address;"];

Once you get the cursor, log it to the Console to see what the results are.

Example:

NSLog(@"The results are: %@", cursor);

> When I finish entering data, how do I close database?

You have two options:

- (BOOL)close;
- (BOOL)closeSavingChanges:(BOOL)flag;

There is a ton of functionality in QuickLite. QuickEdit alone, the new 'matchingRows'-family of methods, and the new cursor set-operators are extremely powerful and will take you far. Take a few minutes to look at the headers. There are only 3 classes, so it should be pretty straight-forward to grasp the concept. The headers contain useful comments and a bit of documentation as well. You can find more info here:

http://www.webbotech.com/quickliteoverview.html

Lastly, don't forget to register in the QuickLite Users mailing list. Happy coding!


© 2004 Tito Ciuro. All Rights Reserved.