On 7/12/05, Gotzon Astondoa <[EMAIL PROTECTED]> wrote: > Hi all: > > I need to make an IP database. They will be stored like "unsigned long" > variables, so, their size will be 4 bytes. > > The IP will be stored in the "domain" field. > The "field type" of domain is NUMERIC. > > I save the data from a C program. > This is part of the code: (Note that DomainTxt is a correct domain like > "www.google.com" or similar) > ... > struct hostent *hep; > ... > hep=gethostbyname(DomainTxt); > ... > strcpy(txtIP, inet_ntoa(*((struct in_addr *)hep->h_addr_list[i]))); > ip = inet_addr(txtIP); > ip = ntohl(ip); > strcpy(sql,"INSERT into domains (domain) VALUES ('"); > sprintf(nIP,"%u",ip); > strcat(sql,nIP); > strcat(sql, "')");
Try this: sprintf( sql, "INSERT into domains (domain) VALUES ('%u') ", ip ); instead of this: > strcpy(sql,"INSERT into domains (domain) VALUES ('"); > sprintf(nIP,"%u",ip); > strcat(sql,nIP); > strcat(sql, "')"); > rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg); > > All goes fine: when i make a select sentence i can see that all the values > are correctly saved. But if i make this sentence: > > SELECT avg(length(domain)) from domains; > > The response is 10 and not 4. > > ¿Has had someone this problem before? ¿what i´m doing bad? domain is numeric, why are you getting the length of a numeric field? length is for strings.