I'm quiet new with the use of Sqlite and i would like to use the callback in the exec function to populate a structure (using the 4th parameter as pointer to the structure)
I've tried this :
static int buildHost(void * pHost, int argc, char **argv, char **azColName){
int i;
struct host* host = malloc(sizeof(struct host));
struct snmp_info* inf = malloc(sizeof(struct snmp_info));
host->info = inf;
for(i=0; i<argc; i++){
if(strcmp(azColName[i], "ip") == 0)
host->ip = argv[i] ? argv[i] : NULL;
else if (strcmp(azColName[i], "port") == 0)
host->info->port = argv[i] ? argv[i] : NULL;
else if (strcmp(azColName[i], "community") == 0)
host->info->community = argv[i] ? argv[i] : NULL;
else if (strcmp(azColName[i], "SNMPv") == 0)
host->info->SNMPv = argv[i] ?atoi( argv[i] ) : 0;
else if (strcmp(azColName[i], "auth_protocol") == 0)
host->info->auth_protocol = argv[i] ? argv[i] : NULL;
else if (strcmp(azColName[i], "password") == 0)
host->info->password = argv[i] ? argv[i] : NULL;
else if (strcmp(azColName[i], "encryption") == 0)
host->info->encryption = argv[i] ? argv[i] : NULL;
else if (strcmp(azColName[i], "encryption_passwd") == 0)
host->info->encryption_passwd = argv[i] ? argv[i] : NULL;
}
pHost = &host; //Seems to be the problem line
printf("\n");
return 0;
}
And i call the function like that :
struct host* toRet;
sqlite3_exec(db, request, buildHost, &toRet,0);
I would add that my code compile and that if i do some printf in the callback function i have the good data (i made the select on a key so i can only have one answer or none)
Thanks in advance, it's probably easy for someone who is used with the library but i'm not and every tutorial that i've found don't use the first argument of the callback
Have a nice day
Aucun commentaire:
Enregistrer un commentaire