直接从终端插入数据后,我无法从xcode插入数据

时间:2012-03-13 15:26:46

标签: sqlite insert

其实我在主题中总结了我的问题。使用下面的代码,我能够在sqlite中将数据插入到我的表中。在我直接使用终端插入数据后,现在下面的代码不起作用。

我没有做任何改动,代码没有错误,似乎它有效但是当我检查表没有时,它没有插入。

你知道吗?

-(IBAction)savemyshare:(id)sender{

                sqlite3_stmt *save_statement;
                const char *dbpath = [databasePath UTF8String];
                sqlite3_open(dbpath, &StylemeshDB);
                NSString *updateSQL = [NSString stringWithFormat:@"insert into Shares (profileid, root, date, photo, title, content) values (?,?,?,?,?,?)"];
                const char *sql_savemyshare = [updateSQL UTF8String];
                sqlite3_exec(StylemeshDB, "BEGIN", 0, 0, 0);
                sqlite3_prepare_v2(StylemeshDB, sql_savemyshare, -1, &save_statement, NULL);

                sqlite3_bind_text(save_statement, 1, [user UTF8String], -1, SQLITE_TRANSIENT);
                sqlite3_bind_text(save_statement, 2, [user UTF8String], -1, SQLITE_TRANSIENT); 
                NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
                [dateFormat setDateFormat:@"YY-MM-dd HH:MM:ss"];
                NSString *dateString = [dateFormat stringFromDate:[NSDate date]];
                sqlite3_bind_text(save_statement, 3, [dateString UTF8String], -1, SQLITE_TRANSIENT);   

                NSData *binData = UIImagePNGRepresentation(contentphoto.image);
                sqlite3_bind_blob(save_statement, 4, [binData bytes], [binData length], SQLITE_TRANSIENT);
                sqlite3_bind_text(save_statement, 5, [baslik.text UTF8String], -1, SQLITE_TRANSIENT);
                sqlite3_bind_text(save_statement, 6, [content.text UTF8String], -1, SQLITE_TRANSIENT);   

                sqlite3_step(save_statement);

                sqlite3_exec(StylemeshDB, "COMMIT", 0, 0, 0);
                sqlite3_finalize(save_statement);
                sqlite3_close(StylemeshDB);
        }

0 个答案:

没有答案