我如何通过 iphone 项目中的 obj c 方法更改 sqlite 数据库中的表
大家好,
我需要向现有表中添加一列,那么如何通过 obj c 更改 sqlite 数据库中的表,我使用以下代码以相同的方式将数据插入表中,如何编写更新表方法
- (void) InsertRecord {
if(addStmt == nil) {
const char *sql = "insert into tbl_Users(FirstName,MiddleName) 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, [strFirstName UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 2, [strMiddleName UTF8String], -1, SQLITE_TRANSIENT);
//sqlite3_bind_text(addStmt, 3, [strLogin UTF8String], -3, SQLITE_TRANSIENT);
if(SQLITE_DONE != sqlite3_step(addStmt))
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
else
//SQLite provides a method to get the last primary key inserted by using sqlite3_last_insert_rowid
//productID = sqlite3_last_insert_rowid(database);
//Reset the add statement.
sqlite3_reset(addStmt);
}
任何人都可以帮助我吗,提前致谢
hii every one
I need to add one column to my existing table so how can i alter table in sqlite database through the obj c ,i am using the following code for inserting data into table in the same way how can i write updata table method
- (void) InsertRecord {
if(addStmt == nil) {
const char *sql = "insert into tbl_Users(FirstName,MiddleName) 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, [strFirstName UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 2, [strMiddleName UTF8String], -1, SQLITE_TRANSIENT);
//sqlite3_bind_text(addStmt, 3, [strLogin UTF8String], -3, SQLITE_TRANSIENT);
if(SQLITE_DONE != sqlite3_step(addStmt))
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
else
//SQLite provides a method to get the last primary key inserted by using sqlite3_last_insert_rowid
//productID = sqlite3_last_insert_rowid(database);
//Reset the add statement.
sqlite3_reset(addStmt);
}
can any one help me,,thanx in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能会有一些用处。
头文件
.m 文件
//调用这些方法
This might be of some use.
Header File
.m File
//Make a call to these Methods