Created
August 7, 2011 08:19
-
-
Save anonymous/1130189 to your computer and use it in GitHub Desktop.
Fetch All Employees
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -(NSMutableArray *) getEmployees { | |
| sqlite3 *database = EmployeeDatabase(); | |
| NSMutableArray *employees = [[[NSMutableArray alloc] init] autorelease]; | |
| NSString *nsquery = [[NSString alloc] initWithFormat:@"SELECT * FROM EMPLOYEE ORDER BY EMPLOYEE_ID"]; | |
| const char *query = [nsquery UTF8String]; | |
| [nsquery release]; | |
| sqlite3_stmt *statement; | |
| int prepareCode = (sqlite3_prepare_v2( database, query, -1, &statement, NULL)); | |
| if(prepareCode == SQLITE_OK) { | |
| while (sqlite3_step(statement) == SQLITE_ROW) { | |
| Employee *newEmployee = [[Employee alloc] init]; | |
| newEmployee.name = sqlite3_column_int(statement, 0); | |
| newEmployee.age = sqlite3_column_int(statement, 2); | |
| [employees addObject:newEmployee]; | |
| [newEmployee release]; | |
| } | |
| sqlite3_finalize(statement); | |
| } | |
| return employees; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment