我试图在objective-c
中使用FMResultSet成为查询的结果集- (NSMutableArray*) buildArrayArticlesWithArticleContainer: (CSTArticleContainer*)articleContainer andSearchString:(NSString*)searchString andLanguageId:(NSString*)languageId
{
NSString* tmpSearchString = [searchString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSArray* arraySearchWords = [tmpSearchString componentsSeparatedByString:@" "];
if([arraySearchWords count] < 1)
return nil;
NSMutableString* selectStmt = [NSMutableString stringWithString:[self sqlBaseSelectSearchArticleWithMatchcode]];
[selectStmt appendString:[self createSqlWhereClauseForSearchArticleWithMatchcodeForSeachStringCount:[arraySearchWords count]]];
FMDatabase *db = [FMDatabase databaseWithPath:[Utility getDatabasePath]];
[db open];
NSMutableArray* arrayArticles = [[NSMutableArray alloc] init];
NSMutableArray* argumentsArray = [[NSMutableArray alloc] init];
[argumentsArray addObject: languageId];
for( int i=0; i<[arraySearchWords count]; i++ )
{
[argumentsArray addObject: [NSString stringWithFormat:@"%%%@%%", [[arraySearchWords objectAtIndex:i] uppercaseString]]];
}
FMResultSet *resultSet = [db executeQuery:[selectStmt description] withArgumentsInArray:argumentsArray];
CSTArticle* newArticle = nil;
NSDictionary *adict= resultSet.resultDictionary;
NSLog(adict.description);
while([resultSet next])
{
newArticle = [CSTArticleContainer buildArticleFromResultSet:resultSet];
[arrayArticles addObject:newArticle];
}
[db close];
return arrayArticles;
}
查询是:
SELECT DISTINCT
PRODUCTCATALOGROWS.ORDERNR,
ARTICLES.*,
ART_NLSDATA.DESCRIPTION AS DESCRIPTION,
ART_NLSDATA.LONGTEXT AS LONGTEXT,
ARTPICTURE.THUMBNAIL AS THUMBNAIL,
ARTPICTURE.FULLIMAGEURL AS FULLIMAGEURL
FROM
ARTICLES
JOIN ART_NLSDATA ON ARTICLES.ARTICLEID = ART_NLSDATA.ARTICLEID
JOIN PRODUCTCATALOGROWS ON ARTICLES.ARTICLEID = PRODUCTCATALOGROWS.ARTICLEID
LEFT OUTER JOIN ARTPICTURE ON ARTICLES.ARTICLEID = ARTPICTURE.ARTICLEID
WHERE
ART_NLSDATA.LANGUAGEID =2
AND(
(ART_NLSDATA.MATCHCODE LIKE '%mbr%')
AND(ART_NLSDATA.MATCHCODE LIKE '%tr%')
)
AND ARTICLES.VALIDTO >= datetime('now')
ORDER BY
ARTICLES.ARTICLEID ASC
奇怪的是,如果连接的like语句只是一个它在navigation lite中工作的sql经过的时间成为响应是0,09秒
答案 0 :(得分:0)
我解决了我的麻烦。 更改SQL查询
SELECT DISTINCT
PRODUCTCATALOGROWS.ORDERNR,
ARTICLES.*,
ART_NLSDATA.DESCRIPTION AS DESCRIPTION,
ART_NLSDATA.LONGTEXT AS LONGTEXT,
ARTPICTURE.THUMBNAIL AS THUMBNAIL,
ARTPICTURE.FULLIMAGEURL AS FULLIMAGEURL
FROM
ARTICLES , ART_NLSDATA , PRODUCTCATALOGROWS
LEFT OUTER JOIN ARTPICTURE ON ARTICLES.ARTICLEID = ARTPICTURE.ARTICLEID
WHERE
ARTICLES.ARTICLEID = ART_NLSDATA.ARTICLEID
AND ARTICLES.ARTICLEID = PRODUCTCATALOGROWS.ARTICLEID
AND ART_NLSDATA.LANGUAGEID =2
AND ( (ART_NLSDATA.MATCHCODE LIKE '%mbr%')
AND (ART_NLSDATA.MATCHCODE LIKE '%tr%'))
AND ARTICLES.VALIDTO >= datetime('now')
ORDER BY
ARTICLES.ARTICLEID ASC
我不知道如何,但确实如此。