0

我有 sqlite 数据库,数据库格式是

表名 = 主项目

column 0(M_ID) column 1(M_ISSUE)
M1               i1
M1               i2
M1               i3
M2               x
M2               y 
M2               z
M3               1 
M3               2 

在上表中,我需要显示 M_ID 问题计数,(例如:- M_ID(M1)有 3 个问题(i1,i2,i3),如明智的 M2 和 M3。

这是我的源代码

for (int i = 0; i < [masterProjIDArray count]; i++)
{
    MySQLite *sqlobj = [[MySQLite alloc] initWithSQLFile:@"myDb"];
    [sqlobj openDb];
    NSString *query = [NSString stringWithFormat:@"SELECT *FROM MASTER_PRJ_DETAILS WHERE M_ID = \'%@\'", [masterProjIDArray objectAtIndex:i]];
    NSLog(@"SQL query:%@", query);
    [sqlobj readDb:query];

    while ([sqlobj hasNextRow])
    {
        NSString *mProjIssuesID = [sqlobj getColumn:1 type:@"text"];

        [masterProjIssueIDArray addObject:mProjIssuesID];
    }
    NSLog(@"issueCount:%@", masterProjIssueIDArray);

    [sqlobj closeDb];
}
[sqlobj release];

请给我一些关于显示 M_ID 问题个人计数的建议。

4

3 回答 3

0
        MySQLite *sqlobj = [[MySQLite alloc] initWithSQLFile:@"myDb"];
        [sqlobj openDb];
        NSString *query = [NSString stringWithFormat:@"SELECT *FROM MASTER_PRJ_DETAILS WHERE M_ID = '%@'",M1];

      NSLog(@"SQL query:%@", query);
     NSMutableArray *arrydata= [sqlobj readDb:query];             
       //You got 3 records...


         for (int i = 0; i < [arrydata count]; i++)
         {
               NSMUtableDisctionry *dist=[arrydata objectAtIndex:i];
               NSString *strIsuue=[dist objectforkey:@"M_ISSUE"];
               [masterProjIssueIDArray addObject:strIsuue];

               NSLog(@"issueCount:%@", masterProjIssueIDArray);


  } 
  [sqlobj closeDb];
  [sqlobj release];

我希望它的工作......

于 2013-01-10T11:49:45.987 回答
0

NSLog(@"issueCount:%d", [masterProjIssueIDArray count]);

于 2013-01-10T11:35:19.567 回答
0

有两种方法可以计数

用数组计数

[masterProjIssueIDArray count]

或计入数据库

SELECT count(*) FROM MASTER_PRJ_DETAILS

希望对你有帮助

于 2013-01-10T11:37:41.720 回答