【发布时间】:2016-01-01 00:49:42
【问题描述】:
我在 SQLITE 中的表格式如下。
id name date height
1 tt 12-2-15 120
2 ss 15-3-15 110
3 tt 14-5-15 120
....
10 tt 19-6-15 130
(1)我喜欢在一条指令中获取名称为 tt 的所有行,然后放入二维数组。如何实现?
(2)如何在一条指令中删除名称为tt的所有行?
我的代码在 iOS 中。我无法轻易找到解决方案。
编辑: 只是为了分享我的实现。
NSString *databasePath;
NSString *docsDir;
NSArray *dirPaths;
//Database
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
// Build the path to the database file
databasePath = [[NSString alloc]initWithString:[docsDir stringByAppendingPathComponent: @"RECORDS.db"]];
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath,& RECORDS) == SQLITE_OK)
{
retval = [[NSMutableArray alloc] init];
NSString *query = [NSString stringWithFormat:@"SELECT id, nameid, date, height FROM RECORD WHERE nameid=\"%@\"", currentNameID];
const char *query_stmt = [query UTF8String];
if (sqlite3_prepare_v2(RECORDS, query_stmt, -1, &statement, nil) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
char *date = (char *) sqlite3_column_text(statement, 1);
int height = (int) sqlite3_column_text(statement, 2);
NSString *name = [[NSString alloc] initWithUTF8String:date];
HeightInfo *info = [[HeightInfo alloc] initWithInfos:name withheight:(int)height];
[retval addObject:info];
}
sqlite3_finalize(statement);
sqlite3_close(RECORDS);
}
}
谢谢
【问题讨论】:
-
这里有很多涉及 SQLite 的主题。如果它们都不能帮助您,那么还有什么可以帮助您?
-
对不起兄弟。我只是无法轻松找到信息。现在我明白了。
标签: ios objective-c xcode sqlite