gpt4 book ai didi

iphone - 从数据库获取第一条记录时选择查询出现问题

转载 作者:行者123 更新时间:2023-12-03 21:18:48 25 4
gpt4 key购买 nike

当我尝试从数据库中选择数据并且它们没有记录时应用程序崩溃

错误:

 "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSString stringWithUTF8String:]: NULL cString'".

查询:arrList = [app.sk LookupAllForSQL:@"select * from tblFriendDetail"];

lookupAllForSQL 代码:

 - (NSArray *)lookupAllForSQL:(NSString *)sql {
sqlite3_stmt *statement;
id result;
NSMutableArray *thisArray = [NSMutableArray arrayWithCapacity:4];
if ((statement = [self prepare:sql])) {
while (sqlite3_step(statement) == SQLITE_ROW) {
NSMutableDictionary *thisDict = [NSMutableDictionary dictionaryWithCapacity:4];
for (int i = 0 ; i < sqlite3_column_count(statement) ; i++) {
if (sqlite3_column_decltype(statement,i) != NULL &&
strcasecmp(sqlite3_column_decltype(statement,i),"Boolean") == 0) {
result = [NSNumber numberWithBool:(BOOL)sqlite3_column_int(statement,i)];
} else if (sqlite3_column_type(statement, i) == SQLITE_TEXT) {
result = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement,i)];
} else if (sqlite3_column_type(statement,i) == SQLITE_INTEGER) {
result = [NSNumber numberWithInt:(int)sqlite3_column_int(statement,i)];
} else if (sqlite3_column_type(statement,i) == SQLITE_FLOAT) {
result = [NSNumber numberWithFloat:(float)sqlite3_column_double(statement,i)];
} else {
result = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement,i)];
}
if (result) {
[thisDict setObject:result
forKey:[NSString stringWithUTF8String:sqlite3_column_name(statement,i)]];
}
}
[thisArray addObject:[NSDictionary dictionaryWithDictionary:thisDict]];
}
}
sqlite3_finalize(statement);
return thisArray;
}

崩溃日志

#0  0x9599d176 in __kill ()
#1 0x9599d168 in kill$UNIX2003 ()
#2 0x95a2f89d in raise ()
#3 0x95a459bc in abort ()
#4 0x93311fda in __gnu_cxx::__verbose_terminate_handler ()
#5 0x011a823b in _objc_terminate ()
#6 0x9331017a in __cxxabiv1::__terminate ()
#7 0x933101ba in std::terminate ()
#8 0x933102b8 in __cxa_throw ()
#9 0x011a8416 in objc_exception_throw ()
#10 0x0100cef8 in +[NSException raise:format:arguments:] ()
#11 0x0100ce6a in +[NSException raise:format:] ()
#12 0x00a06e35 in +[NSString stringWithUTF8String:] ()
#13 0x0000b6ab in -[SKDatabase lookupAllForSQL:] (self=0x59393e0, _cmd=0xf9ac, sql=0x13564) at SKDatabase.m:97
#14 0x000052f9 in -[addGroupMembers viewWillAppear:] (self=0x4f2ce40, _cmd=0xe194, animated=1 '\001') at addGroupMembers.m:34
#15 0x003649be in -[UINavigationController _startTransition:fromViewController:toViewController:] ()
#16 0x0035f32a in -[UINavigationController _startDeferredTransitionIfNeeded] ()
#17 0x00366562 in -[UINavigationController pushViewController:transition:forceImmediate:] ()
#18 0x0035f1c4 in -[UINavigationController pushViewController:animated:] ()
#19 0x00002d68 in -[GroupSelection editFriendListClicked:] (self=0x4f34da0, _cmd=0xdf58, sender=0x4f3a400) at GroupSelection.m:80
#20 0x002a64fd in -[UIApplication sendAction:to:from:forEvent:] ()
#21 0x00336799 in -[UIControl sendAction:to:forEvent:] ()
#22 0x00338c2b in -[UIControl(Internal) _sendActionsForEvents:withEvent:] ()
#23 0x003377d8 in -[UIControl touchesEnded:withEvent:] ()
#24 0x002caded in -[UIWindow _sendTouchesForEvent:] ()
#25 0x002abc37 in -[UIApplication sendEvent:] ()
#26 0x002b0f2e in _UIApplicationHandleEvent ()
#27 0x012ff992 in PurpleEventCallback ()
#28 0x01035944 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#29 0x00f95cf7 in __CFRunLoopDoSource1 ()
#30 0x00f92f83 in __CFRunLoopRun ()
#31 0x00f92840 in CFRunLoopRunSpecific ()
#32 0x00f92761 in CFRunLoopRunInMode ()
#33 0x012fe1c4 in GSEventRunModal ()
#34 0x012fe289 in GSEventRun ()
#35 0x002b4c93 in UIApplicationMain ()
#36 0x00002199 in main (argc=1, argv=0xbffff084) at main.m:14

最佳答案

我找到了解决方案。这是因为它从 sqlite 表中获取空值。因此,现在当我输入数据时,我会注意为所有字段输入数据,尽管我在没有条目的字段中输入空白字符串。

关于iphone - 从数据库获取第一条记录时选择查询出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6964952/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com