Column numbers are zero-based, not one-based. >From http://www.sqlite.org/c3ref/column_blob.html
"The leftmost column of the result set has the index 0. " That's at least part of your problem. So should be: k.AAArticoli=sqlite3_column_int(statmentS, 0); k.MMArticoli=sqlite3_column_int(statmentS, 1); k.GGArticoli=sqlite3_column_int(statmentS, 2); And can't you run the command-line sqlite3 to see what's in your table? Michael D. Black Senior Scientist NG Information Systems Advanced Analytics Directorate ________________________________ From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on behalf of marco bianchini [informa...@gmail.com] Sent: Sunday, July 17, 2011 7:05 AM To: General Discussion of SQLite Database Subject: EXT :Re: [sqlite] year, month & day problem if can help, thats real code : -- to read -(void) readUpdateStatus{ const char *sql="select AAArticoli,MMArticoli,GGArticoli,AAFoto,MMFoto,GGFoto,AAClienti,MMClienti,GGClienti,AAOrdini,MMOrdini,GGOrdini,AA,MM,GG from settings"; sqlite3_stmt *statmentS; if (sqlite3_prepare_v2(database, sql ,-1,&statmentS, NULL)==SQLITE_OK) { if (sqlite3_step(statmentS)==SQLITE_ROW) { UserSettings *k = [UserSettings sharedUserSettings]; k.AAArticoli=sqlite3_column_int(statmentS, 1); k.MMArticoli=sqlite3_column_int(statmentS, 2); k.GGArticoli=sqlite3_column_int(statmentS, 3); k.AAFoto=sqlite3_column_int(statmentS, 4); k.MMFoto=sqlite3_column_int(statmentS, 5); k.GGFoto=sqlite3_column_int(statmentS, 6); k.AAClienti=sqlite3_column_int(statmentS, 7); k.MMClienti=sqlite3_column_int(statmentS, 8); k.GGClienti=sqlite3_column_int(statmentS, 9); k.AAOrdini=sqlite3_column_int(statmentS, 10); k.MMOrdini=sqlite3_column_int(statmentS, 11); k.GGOrdini=sqlite3_column_int(statmentS, 12); k.AA=sqlite3_column_int(statmentS, 13); k.MM=sqlite3_column_int(statmentS, 14); k.GG=sqlite3_column_int(statmentS, 15); } sqlite3_finalize(statmentS); } return; } -- to write -(int) ioSQL:(NSString*)sql{ sqlite3_stmt *statment; if (sqlite3_prepare_v2(database,[sql UTF8String],-1,&statment, NULL)==SQLITE_OK) { if (sqlite3_step(statment)==SQLITE_DONE) { sqlite3_finalize(statment); return 1; } } return 0; } -(int) setUpdated{ return [self ioSQL:@"update settings set AA=strftime('%Y', 'now'), MM=strftime('%m', 'now'), GG=strftime('%d', 'now')"]; } -(int) setArticoliUpdated{ return [self ioSQL:@"update settings set AAArticoli=strftime(\"%Y\", \"now\"), MMArticoli=strftime(\"%m\", \"now\"), GGArticoli=strftime(\"%d\", \"now\")"]; } -(int) setFotoUpdated{ return [self ioSQL:@"update settings set AAFoto=strftime(\"%Y\", \"now\"), MMFoto=strftime(\"%m\", \"now\"), GGFoto=strftime(\"%d\", \"now\")"]; } -(int) setClientiUpdated{ return [self ioSQL:@"update settings set AAClienti=strftime(\"%Y\", \"now\"), MMClienti=strftime(\"%m\", \"now\"), GGClienti=strftime(\"%d\", \"now\")"]; } -(int) setOrdiniUpdated{ return [self ioSQL:@"update settings set AAOrdini=strftime(\"%Y\", \"now\"), MMOrdini=strftime(\"%m\", \"now\"), GGOrdini=strftime(\"%d\", \"now\")"]; } 2011/7/17 marco bianchini <informa...@gmail.com> > you'r right, i made a mistake doing copy and paste writing original mail, > the real select query contains more fields and i can ensure that 1 based > indexes are correct and respected into the real code, real update query is > hardcoded, no params (0 based): 2 days checking, im sure.. > > at least, do u know a way to load the copied writable database running into > the XCode simulator, so i can understand if my problem is writing or > retriving data (in this way 50% my troubles are solved)? > > Using Mac and windows against the same database to simulate the same query > everithing works perfectly.. im really getting crazy. > i know i can close my eyes and invert that commands, but i care my software > and i really like to know what im doing wrong.. > > thx for reply, marco > > > 2011/7/17 John Deal <bassd...@yahoo.com> > >> Hello, >> >> I am new and have received much information from this list so I hope I am >> not wasting bandwidth. I don't know if it is my misunderstanding or typos >> but should your sqlite3_column_int() use indexes 0,1 and 2 instead of 1, 12 >> and 13? If this is the case, according to the docs on sqlite3_column_int() >> "...if the column index is out of range, the result is undefined." >> >> I hope I did not misunderstand the issue. >> >> --- On Sun, 7/17/11, marco bianchini <informa...@gmail.com> wrote: >> >> > From: marco bianchini <informa...@gmail.com> >> > Subject: [sqlite] year, month & day problem >> > To: sqlite-users@sqlite.org >> > Date: Sunday, July 17, 2011, 6:05 AM >> > Hi all, >> > call me stupid but after some days of try and a lot of >> > Googleing, im still >> > wondering how to solve my problem: >> > i need to execute a query that updates 3 integer fields >> > (AA, MM, GG) of a >> > table, containing respectively today year, today month and >> > today day: >> > >> > update settings set AA=strftime('%Y', 'now'), >> > MM=strftime('%m', 'now'), >> > GG=strftime('%d', 'now') >> > >> > looks working well, but later, when i read that values: >> > <xcode> >> > const char *sql="select AA,MM,GG from >> > settings"; >> > sqlite3_stmt *statmentS; >> > if (sqlite3_prepare_v2(database, sql >> > ,-1,&statmentS, NULL)==SQLITE_OK) >> > { >> > if >> > (sqlite3_step(statmentS)==SQLITE_ROW) { >> > UserSettings *k = >> > [UserSettings sharedUserSettings]; >> > >> > k.AA=sqlite3_column_int(statmentS, 1); >> > >> > k.MM=sqlite3_column_int(statmentS, 12); >> > >> > k.GG=sqlite3_column_int(statmentS, 13); >> > ... >> > </xcode> >> > >> > i obtain correct values, but in inverse order: >> > >> > AA (year) contains the day number >> > MM (month) is correct >> > GG (day) contains the year >> > >> > using SQLIte Manager addons for Firefox, this query: >> > select strftime('%Y', 'now'), strftime("%m", "now"), >> > strftime("%d", "now") >> > from settings >> > returns correct values, running or loading value into XCode >> > simulator looks >> > not working and i dont know why. :'( >> > >> > >> > does anyone can suggest me what to fix or check? >> > thx in advance, marco >> > _______________________________________________ >> > sqlite-users mailing list >> > sqlite-users@sqlite.org >> > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users >> > >> _______________________________________________ >> sqlite-users mailing list >> sqlite-users@sqlite.org >> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users >> > > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users