Sqlite3绑定文本:在字符串中传递两个值并不起作用。

时间:2011-12-06 12:06:47

标签: iphone objective-c ios sqlite

    productName = @"'Fidelity Bonds',Property'";
    regionName = @"'London',Paris',Tokyo'";
    yearName = @"'2007',2010'";

    sqlite3 *database;
    const char *sqlStatement;
    sqlite3_stmt *compiledStatement;
    [self setPathForDatabase];

    if(sqlite3_open([storePath UTF8String], &database) == SQLITE_OK) 
    {         

       sqlStatement = "Select * from PorfolioPerformanceCPR where product_name IN (?) and region_name IN (?) and year_name IN (?)  group by channel_name";

        if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) 
       {        
                 sqlite3_bind_text(compiledStatement, 1, [productName UTF8String], -1, SQLITE_TRANSIENT);
                 sqlite3_bind_text(compiledStatement, 2, [regionName UTF8String], -1, SQLITE_TRANSIENT);
                 sqlite3_bind_text(compiledStatement, 3, [yearName UTF8String], -1, SQLITE_TRANSIENT);
        }

问题:当我在字符串productName,regionName和yearName中插入多个值时,代码不起作用。需要帮助。

1 个答案:

答案 0 :(得分:0)

在我看来,productNameregionNameyearName字符串中的单引号可能存在​​问题:

productName = @"'Fidelity Bonds',Property'";
regionName = @"'London',Paris',Tokyo'";
yearName = @"'2007',2010'";

你试过了吗?

productName = @"'Fidelity Bonds','Property'";
regionName = @"'London','Paris','Tokyo'";
yearName = @"'2007','2010'";