在我的數據庫中有表名「Projtable」。項目名稱包含4個字段。 1. projct ID =自動增量(主鍵) 2. projctname = VARCHAR 3. projct_detail = 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