Sqlite3_step () sigue devolviendo SQLITE_MISUSE en esta consulta. ¿Algún puntero?
Estoy tratando de abrir una base de datos sqlite en la rutina viewDidLoad e intento enviar una consulta sql a la base de datos, pero sqlite_step () falla cada vez. No estoy seguro de lo que está mal aquí. Solo intento esto como un intento de hello world en sqlite3.
#import "RootViewController.h"
#import "sqlite3.h"
static sqlite3_stmt *statement = nil;
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString *dbname = @"name.sqlite";
sqlite3 *database;
int success;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:dbname];
// Open the database. The database was prepared outside the application.
success = sqlite3_open([path UTF8String], &database);
if (success == SQLITE_OK) {
NSLog(@"database opening successful : %d", success);
} else {
// Even though the open failed, call close to properly clean up resources.
sqlite3_close(database);
NSLog(@"database opening failed : %d", success);
// Additional error handling, as appropriate...
}
if (statement == nil) {
const char *sql = "insert into name(nid, name) values(6, 'testname');";
success = sqlite3_prepare_v2(database, sql, -1, &statement, NULL);
NSLog(@"query prepare status: %d", success);
if (success != SQLITE_OK) {
}
}
success = sqlite3_step(statement); //things fail here, as all calls above return ok
NSLog(@"query step status: %d", success);
if (success != SQLITE_DONE) {
}
sqlite3_reset(statement);
sqlite3_close(database);
}
...
Sería genial si alguien pudiera señalarme dónde podría estar equivocado. Gracias por tu tiempo ya.