在我的数据库中有表名“Projtable”。项目名称包含 4 个字段。1. 项目 id = 自动增量(主键) 2. 项目名称 = varchar 3. 项目详细信息 = varchar 4. order_id = int
现在我插入 projctname 和 projct_detail 可以完美运行。我必须找到 orderid 列的最大值。我怎样才能找到这个?
我的代码是:
-(void)insertProject:(Project *)projobj
{
// next_orderid = next_orderid + 1;
// projobj.orderid = next_orderid;
NSLog(@" insert:: %@, %@, %d", projobj.outcome, projobj.projctname, projobj.orderid);
sqlite3 *database;
if (sqlite3_open([self.databasePath UTF8String] , &database) == SQLITE_OK)
{
const char *sql = "INSERT INTO proj_table (projctname, outcome, orderid) VALUES (?,?,?)";
sqlite3_stmt *statement;
statement = [self PrepareStatement:sql];
int a1 = sqlite3_bind_text(statement, 1, [projobj.projctname UTF8String], -1, SQLITE_TRANSIENT);
int a2 = sqlite3_bind_text(statement, 2, [projobj.outcome UTF8String], -1, SQLITE_TRANSIENT);
int a3= sqlite3_column_int( statement, 3);
NSLog(@" integer :== %d",a3);
// int a3 = sqlite3_bind_int(statement, 3, projobj.orderid);
if (statement)
{
if (a1 != SQLITE_OK || a2 != SQLITE_OK || a3 != SQLITE_OK)
{
sqlite3_finalize(statement);
return;
}
sqlite3_step(statement);
}
sqlite3_finalize(statement);
}
}
结果为 0