lano
Aktives Mitglied
Moin...
Ich hab da eine Lustige funktion. Die soll mir einen Eintrag in der Datenbank updaten.
Ich hab Ints und Text und beim Text da hapert es.
Ich hab nen strucht conf mit char array[size] drin.
Jetzt will ich das in die Datenbank bekommen.
Das Übel sieht so aus...
Es gibt sqlite3_bind_text aber so ganz verstanden hab ich das nicht.
Ich hab da eine Lustige funktion. Die soll mir einen Eintrag in der Datenbank updaten.
Ich hab Ints und Text und beim Text da hapert es.
Ich hab nen strucht conf mit char array[size] drin.
Jetzt will ich das in die Datenbank bekommen.
Das Übel sieht so aus...
C:
int UpdateDevice(struct config conf,struct iconfig iconf) {
sqlite3 *db;
char *err_msg = 0;
sqlite3_stmt *res;
// struct config conf;
int rc = sqlite3_open("test.db", &db);
if (rc != SQLITE_OK) {
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return 1;
}
// update info und update url einfügen
char *sql_querry = "UPDATE Fritz SET Type = @Type, fb_name = @fb_name, fb_hw = @fb_hw, fb_major = @fb_major, fb_minor = @fb_minor, fb_patch = @fb_patch, fb_build = @fb_build, fb_type = @fb_type, fb_serial = @fb_serial, fb_oem = @fb_oem, fb_lang = @fb_lang, fb_country = @fb_country, fb_annex = @fb_annex, fb_annex = @fb_annex, fb_flags = @fb_flags, fb_updateconfig = @fb_updateconfig, fb_provider = @fb_provider, fb_provider_name = @fb_provider_name WHERE Id = @Id";
rc = sqlite3_prepare_v2(db, sql_querry, -1, &res, 0);
if (rc == SQLITE_OK) {
/* conf.Id */
int Id = sqlite3_bind_parameter_index(res, "@Id");
int Id_value = conf.Id;
sqlite3_bind_int(res, Id, Id_value);
/* conf.Type */
// int Type = sqlite3_bind_parameter_index(res, "@Type");
// int Type_value = conf.Type;
// sqlite3_bind_int(res, Type, Type_value);
/* conf.fb_name */
// int fb_name = sqlite3_bind_parameter_index(res, "@fb_name");
// int fb_name_value = conf.fb_name;
// sqlite3_bind_int(res, fb_name, fb_name_value);
/* conf.fb_hw */
// int fb_hw = sqlite3_bind_parameter_index(res, "@fb_hw");
// int fb_hw_value = conf.fb_hw;
// sqlite3_bind_int(res, fb_hw, fb_hw_value);
/* conf.fb_major */
int fb_major = sqlite3_bind_parameter_index(res, "@fb_major");
int fb_major_value = conf.fb_major;
sqlite3_bind_int(res, fb_major, fb_major_value);
/* conf.fb_minor */
int fb_minor = sqlite3_bind_parameter_index(res, "@fb_minor");
int fb_minor_value = conf.fb_minor;
sqlite3_bind_int(res, fb_minor, fb_minor_value);
/* conf.fb_patch */
int fb_patch = sqlite3_bind_parameter_index(res, "@fb_patch");
int fb_patch_value = conf.fb_patch;
sqlite3_bind_int(res, fb_patch, fb_patch_value);
/* conf.fb_build */
int fb_build = sqlite3_bind_parameter_index(res, "@fb_build");
int fb_build_value = conf.fb_build;
sqlite3_bind_int(res, fb_build, fb_build_value);
/* conf.fb_type */
// int fb_type = sqlite3_bind_parameter_index(res, "@fb_type");
// int fb_type_value = conf.fb_type;
// sqlite3_bind_int(res, fb_type, fb_type_value);
/* conf.fb_serial */
// int fb_serial = sqlite3_bind_parameter_index(res, "@fb_serial");
// int fb_serial_value = conf.fb_serial;
// sqlite3_bind_int(res, fb_serial, fb_serial_value);
/* conf.fb_oem */
// int fb_oem = sqlite3_bind_parameter_index(res, "@fb_oem");
// int fb_oem_value = conf.fb_oem;
// sqlite3_bind_int(res, fb_oem, fb_oem_value);
/* conf.fb_lang */
// int fb_lang = sqlite3_bind_parameter_index(res, "@fb_lang");
// int fb_lang_value = conf.fb_lang;
// sqlite3_bind_int(res, value, fb_lang_value);
/* conf.fb_country */
// int fb_country = sqlite3_bind_parameter_index(res, "@fb_country");
// int fb_country_value = conf.fb_country;
// sqlite3_bind_int(res, fb_country, fb_country_value);
/* conf.fb_annex */
// int fb_annex = sqlite3_bind_parameter_index(res, "@fb_annex");
// int fb_annex_value = conf.fb_annex;
// sqlite3_bind_int(res, fb_annex, fb_annex_value);
/* conf.fb_flags */
// int fb_flags = sqlite3_bind_parameter_index(res, "@fb_flags");
// int fb_flags_value = conf.fb_flags;
// sqlite3_bind_int(res, fb_flags, fb_flags_value);
/* conf.fb_updateconfig */
int fb_updateconfig = sqlite3_bind_parameter_index(res, "@fb_updateconfig");
int fb_updateconfig_value = conf.fb_updateconfig;
sqlite3_bind_int(res, fb_updateconfig, fb_updateconfig_value);
/* conf.fb_provider */
// int fb_provider = sqlite3_bind_parameter_index(res, "@fb_provider");
// int fb_provider_value = conf.fb_provider;
// sqlite3_bind_int(res, value, fb_provider_value);
/* conf.fb_provider_name */
// int fb_provider_name = sqlite3_bind_parameter_index(res, "@fb_provider_name");
// int fb_provider_name_value = conf.fb_provider_name;
// sqlite3_bind_int(res, fb_provider_name, fb_provider_name_value);
} else {
fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db));
}
int step = sqlite3_step(res);
if (step == SQLITE_ROW) {
}
sqlite3_finalize(res);
sqlite3_close(db);
return 0;
}
Es gibt sqlite3_bind_text aber so ganz verstanden hab ich das nicht.