J'utilise le code suivant pour obtenir la valeur maximale dans la colonneTrouver la valeur maximale dans une colonne de base de données SQLite
colonne n ° 11 (moyens 10 non, dans le code) Nom de la colonne uniqueColumnSNo Type de données de la colonne -integer .
Je suis confondu avec la syntaxe utilisée par dbhanlder.
Voici le code. Laissez-moi savoir, COMMENT JE OBTIENDRA LA VALEUR MAXIMALE À RETOURNER de la colonne spécifiée. Aide. Merci d'avance.
+ (int) getMaxColumnSNo {
NSInteger favid;
int count=0;
sqlite3 *database;
NSString *dbpath;
dbpath = [dbhandler dataFilePath:DbName];
if (sqlite3_open([dbpath UTF8String], &database) == SQLITE_OK)
{
NSString *selectSql = [NSString stringWithFormat:@"SELECT max(uniqueColumnSNo) FROM CustomerFields"];
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, [selectSql cStringUsingEncoding:NSUTF8StringEncoding], -1, &statement, NULL) == SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
//[result addObject:[[NSMutableDictionary alloc] init]];
favid=(NSInteger)sqlite3_column_int64(statement,10);
//favid = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 10)] intValue];
count++;
}
sqlite3_finalize(statement);
}
else
{
NSLog(@"Sql Preparing Error");
}
sqlite3_close(database);
}
else
{
NSLog(@"Database not opening");
}
int i;
if (count!=0) {
i=favid ;
}
else {
i=1;
}
return i;
//return favid;
}
Acceptez d'abord des réponses à vos questions précédentes ..... – CristiC