|
|
#1 |
|
sqlite drop table command
I have a function which is supposed to drop the table I'm working on so I can start again. It looks like this :
Code:
- (void) dropData
{
sqlite3_stmt *statement;
char *errMsg;
NSString *sql_stmt = @"DROP TABLE THOUGHT_RECORD";
const char *drop_stmt = [sql_stmt UTF8String];
sqlite3_prepare_v2(thoughtDB, drop_stmt,
-1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
status = @"Didn't Drop table";
NSLog(@"Didn't Drop table");
} else
{
NSLog(@"Dropped table");
}
sqlite3_finalize(statement);
sqlite3_close(thoughtDB);
}
However, if i then print out the table it is still there and so is all the data. Any ideas? Is the above code not correct? |
|
|
|
0
|
|
|
#2 |
|
The logic of this code seems odd:
Code:
if (sqlite3_step(statement) == SQLITE_DONE)
{
status = @"Didn't Drop table";
NSLog(@"Didn't Drop table");
} else
{
NSLog(@"Dropped table");
}
What does the debugger say the value returned from sqlite3_step() really is? That may be a clue as to what's really happening. If you don't know how to use the debugger, this would be a good time to learn it. Being able to step through statements one at a time is a powerful tool for seeing what really happens in code. |
|
|
|
0
|
|
|
#3 | |
|
Quote:
edit: see status codes here http://www.sqlite.org/c3ref/c_abort.html
__________________
2012 Mac Mini, 2.6 GHz, 16GB RAM, 1TB HDD ![]() 2.4Ghz 15" Macbook Pro ![]() 32 GB iPhone 4S : 16 GB iPod nano : 16 GB iPad 3 Nikon D60 : 18-55 mm VR : 55-200 mm VR |
||
|
|
0
|
|
|
#4 | |
|
Quote:
The return value of Code:
sqlite3_step(statement) Code:
#define SQLITE_MISUSE 21 /* Library used incorrectly */ Code:
"DROP TABLE yourTableNameHere"
|
||
|
|
0
|
|
|
#5 |
|
Figured it out. It was missing :
Code:
if (sqlite3_open(dbpath, &thoughtDB) == SQLITE_OK) It should read Code:
- (void) dropData{
sqlite3_stmt *statement;
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &thoughtDB) == SQLITE_OK)
{
NSString *sql_stmt = @"DROP TABLE THOUGHT_RECORD";
const char *drop_stmt = [sql_stmt UTF8String];
sqlite3_prepare_v2(thoughtDB, drop_stmt,
-1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
NSLog(@"Dropped table");
} else
{
status = @"Didn't Drop table";
NSLog(@"Didn't Drop table");
}
sqlite3_finalize(statement);
sqlite3_close(thoughtDB);
}
}
|
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 12:13 AM.








2012 Mac Mini, 2.6 GHz, 16GB RAM, 1TB HDD
Linear Mode
