-
Quick Tips: EGODatabase
If you’re not a big fan of CoreData, or just want a simpler way to interact with your sqlite databases, EGODatabase is a simple to use, thread-safe solution for OSX & iOS projects alike. All you have to do is import the EGODatabase files into your XCode project, and include them wherever you want sqlite interaction. There aren’t that many tutorials online on how to start using EGODatabase though, so here are a few tips that should get you going in the right direction.
Initializing an instance of EGODatabase
EGODatabase *database = [EGODatabase databaseWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"dbname.db"]];
Executing a query
[database executeQuery:@"SELECT * FROM users;"];
Getting results from a query
EGODatabaseResult *result = [database executeQuery:@"SELECT * FROM users;"];
Finding out how many results you have from a query
EGODatabaseResult *result = [database executeQuery:@"SELECT * FROM users;"];
NSInteger numResults = [result count];Going through results
EGODatabaseResult *result = [database executeQuery:@"SELECT * FROM users;"];
if([result count] > 0) {
for(EGODatabaseRow *row in result) {
// To get the value of a column from the current result, you call the stringFromColumn: method for EGODatabaseRow
NSLog(@"%@", [row stringForColumn:@"username"]);
}
} else {
NSLog(@"There are no results here...");
}
-
beefdisciple liked this
-
raphaelcaixeta posted this