I found the solution :
I replaced this line :
configvalue = (char *) sqlite3_column_text(stmt, 0);
by
configvalue = g_strdup((gchar *) sqlite3_column_text(stmt, 0));
and the configvalue type : gchar
Now it works !!
A newbie error...
David.
David Hautbois wrote:
Hi
I have an odd issue.
My database schema :
sqlite> .schema
CREATE TABLE config (id INTEGER PRIMARY KEY, config_name TEXT ,
config_value TEXT);
CREATE TABLE waypoints (id INTEGER PRIMARY KEY, wp_date INTEGER,
wp_longitude REAL, wp_latitude REAL, wp_speed REAL);
The config table content :
sqlite> SELECT * from config;
1|version|1
2|ftpserver|A
3|ftp_remotedir|
4|ftp_login|
5|ftp_password|
My function :
****************************************************************
char * get_config_value (sqlite3 * db, char * config_name) {
int ncols;
sqlite3_stmt *stmt;
char *sql;
const char *tail;
char * configvalue = 0;
sql = g_strdup_printf("SELECT config_value FROM config WHERE
config_name='%s'\n", config_name);
printf (sql);
sqlite3_prepare(db , sql, (int)strlen(sql), &stmt, &tail);
ncols = sqlite3_column_count(stmt);
while(sqlite3_step(stmt) == SQLITE_ROW) {
printf ("gpstracer-cfg.c - get_config_value : Getting column
content\n");
configvalue = (char *) sqlite3_column_text(stmt, 0);
printf ("gpstracer-cfg.c - get_config_value : content=%s\n",
configvalue); > note this line
}
printf ("gpstracer-cfg.c - get_config_value : %s=%s\n",
config_name, configvalue); >and this one
sqlite3_finalize(stmt);
return configvalue;
}
***************************************************************
When I call this function : get_config_value (db, "version")
I get :
SELECT config_value FROM config WHERE config_name='version'
gpstracer-cfg.c - get_config_value : Getting column content
gpstracer-cfg.c - get_config_value :
content=1 > ok
gpstracer-cfg.c - get_config_value : version=ftp_password
> Why the variable content changes ??
Why the variable configvalue has not the same content ??
It's the same issue than my previous post (Callback issue - using
pointer as argument), when I used a callback.
Thanks.
David.
--
Web site : http://david.hautbois.free.fr
Tablet users map : http://david.hautbois.free.fr/maps/index.php
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------