用数组读取sqlite数据

来源:互联网 发布:布尔矩阵的运算 编辑:程序博客网 时间:2024/05/16 06:50

- (IBAction)load:(id)sender {

    

  

    sqlite3_stmt *statement;

    NSString *databasePath=[selfdatabasePath];

    const char *dbpath = [databasePathUTF8String];

    if (sqlite3_open(dbpath, &db)==SQLITE_OK) {

        NSString *querySQL = [NSStringstringWithFormat:@"SELECT classname,name from info where num=\"%@\"",num.text];          //================这里就实现了用号码查询,其他的可以另外实现

        const char *querystatement = [querySQLUTF8String];

        

        if (sqlite3_prepare_v2(db, querystatement, -1, &statement,NULL)==SQLITE_OK) {

            

            if (sqlite3_step(statement)==SQLITE_ROW) {

             /*

                

               //做个小测试(原来版本)

                

                NSString *classnameField = [[NSString alloc] initWithUTF8String:(const char *)sqlite3_column_text(statement, 0)];

             

                NSString *nameField = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)];

              

                

               classname.text = classnameField;

                

                name.text = nameField;

                

                

               */

              

                //=======测试部分=====================

            

                

                NSMutableArray *such =[[NSMutableArrayalloc]initWithCapacity:30];

                

                for (int i=0; i<2; i++) {

                    

                   NSString  *tab=[[NSStringalloc] initWithUTF8String:(constchar *)sqlite3_column_text(statement, i)];

                    

                    [such addObject:tab];

                }

                

                classname.text=[suchobjectAtIndex:0];

                name.text=[suchobjectAtIndex:1];

                

                

                

                

                

                //=======================================

               

                //status.text = @"find~~~";

            }

                        sqlite3_finalize(statement);

        }

        sqlite3_close(db);

    }}


0 0