I’m trying to insert this
- (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);
}
Which prints out correct values being sent to the 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
The sqlite table looks like this
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
);
But this is what is inserted
"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)
Why is it inserting the last two values into the wrong fields?
TIA
for the fame and glory (and points):
addStmt looks to be static and/or global. i would guess you are using the same variable name elsewhere with a slightly different insert statement.