sqlite将值放入错误的字段中

时间:2012-03-07 02:42:50

标签: iphone ios sqlite insert

我正在尝试插入此

- (void)insertBlogStory:(NSString *)storyTitle link:(NSString *)link storyDescription:(NSString *)storyDescription storyHTML:(NSString *)storyHTML pubDate:(NSString *)pubDate blog:(NSString *)blog {

    NSLog(@"storyTitle %@",storyTitle);
    NSLog(@"link  %@",link);
    NSLog(@"storyDescription  %@",storyDescription);
    NSLog(@"storyHTML  %@",storyHTML);
    NSLog(@"pubDate  %@",pubDate);
    NSLog(@"blog  %@",blog);

    if(addStmt == nil) {

        const char *sql = "insert into contents (storyTitle, link, storyDescription, storyHTML, pubDate, blog, read) VALUES (?, ?, ?, ?, ?, ?, ?)";

        if(sqlite3_prepare_v2(_database, sql, -1, &addStmt, NULL) != SQLITE_OK)
            NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(_database));
    }

    sqlite3_bind_text(addStmt, 1, [storyTitle UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(addStmt, 2, [link UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(addStmt, 3, [storyDescription UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(addStmt, 4, [storyHTML UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(addStmt, 5, [pubDate UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(addStmt, 6, [blog UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_int(addStmt,  7, 0);

    if(SQLITE_DONE != sqlite3_step(addStmt))
        NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(_database));

    sqlite3_reset(addStmt);


}

打印出发送到methiod的正确值

storyTitle -> Converged Security
link -> http://...converged-security.html
storyDescription -> Cyber-crime is not new....etc
storyHTML -> <p>Cyber-crime is not new....etc
pubDate -> Thu, 01 Sep 2011 10:52:57 +0100
blog -> Business continuity

sqlite表看起来像这样

TABLE "contents" (
"id" INTEGER PRIMARY KEY,
"storyTitle" TEXT,
"link" TEXT,
"storyDescription" TEXT,
"storyHTML" TEXT,
"pubDate" DATETIME,
"blog" TEXT,
"read" INTEGER,
"storyVideo" TEXT,
"storyVideoThumb" TEXT,
"storyAudio" TEXT,
"issueA" TEXT,
"industryA" TEXT,
"serviceA" TEXT,
"contactName" TEXT,
"contactPhone" TEXT,
"contactAddress" TEXT,
"contactPhrase" TEXT,
"contactPhraseEmail" TEXT,
"contactPhraseName" TEXT
);

但这就是插入的内容

"storyTitle" correct string
"link" correct string
"storyDescription" correct string
"storyHTML" correct string
"pubDate" correct string
"blog" is always NULL
"read" is always NULL


"storyVideo" gets the blog string (Business continuity)
"storyVideoThumb" gets the read value (0)

为什么将最后两个值插入错误的字段?

TIA

1 个答案:

答案 0 :(得分:0)

为名誉和荣耀(和点):

addStmt看起来是静态的和/或全局的。我猜你在其他地方使用相同的变量名,插入语句略有不同。