Your query string is ~ 61 characters (did not count precisely), not including the key length not the value length. Are you sure the real tests you run do not overflow the fixed buffer char query[200] which can hold no more than 199 characters? You would have huge problems as soon as strlen(key) + strlen(query) > ~139.
Besides, there is still no point passing a char** to mydef_set(). You might as well have: > int mydef_set(sqlite3 *db,char *key, char *value) and call it as: > mydef_set(db,"sssi",val); And the code for mod_init() copied from your initial email can't be the code you compile along the remaining bits of the sample you provided. That function expect db to be a global, yet it returns it after changing it, it frees a query which was nowhere declared/allocated,... I sincerely think what you are looking at are weird bugs in your code, and you might be loosing precious time wondering what might go wrong in SQLite code : anything and everything if the caller plays fool. If you want some more help from the community, I suggest you should write a short self-contained sample as you tried to do, but this time check that it compiles fine (what you showed until now can't possibly even compile), and run and produces the same problem as your real program then show it. Please also tell what your platform is and how is SQLite linked to your code (static lib, dynamic lib, or compiled in along with your project code). -- Best Regards, Meilleures salutations, Met vriendelijke groeten, Olivier Mascia > sqlite3 *mod_init() { > > /* Open database */ > //rc = sqlite3_open("test.db", &dbObj->db); > lastError = sqlite3_open_v2("test.db", &db, SQLITE_OPEN_READWRITE | > SQLITE_OPEN_CREATE | SQLITE_OPEN_SHAREDCACHE|SQLITE_OPEN_NOMUTEX , NULL); > if( lastError ) { > fprintf(stderr, "Can't open database: %s\n", > sqlite3_errmsg(dbObj->db)); > free(query); > return(0); > } else { > fprintf(stdout, "Opened database successfully\n"); > } > memset(query,0,200); > strcpy(query,"CREATE TABLE IF NOT EXISTS cosmos_db(" \ > "key TEXT PRIMARY KEY NOT NULL," \ > "value VARCHAR(100));"); > > /* Execute SQL statement */ > lastError = sqlite3_exec(db, query, 0, 0, &zErrMsg); > > > if( lastError != SQLITE_OK ){ > fprintf(stderr, "SQL error: %s\n", zErrMsg); > sqlite3_free(zErrMsg); > } else { > fprintf(stdout, "Table created successfully\n"); > } > return db; > } > > Le 22 oct. 2018 à 07:15, Ratheendran R <ratheendra...@gmail.com> a écrit : > > int mydef_set(sqlite3 *db,char *key, char **value) > { > char *zErrMsg = 0; > int rc; > char query[200] > sprintf(query,"INSERT OR REPLACE INTO cosmos_db (key,value) values > ('%s', '%s');",key,*value); > /* Execute SQL statement */ > lastError = sqlite3_exec(db, query, 0, 0, &zErrMsg); > if( lastError != SQLITE_OK ) { > fprintf(stderr, "SQL error: %s\n", zErrMsg); > sqlite3_free(zErrMsg); > } else { > fprintf(stdout, "Update done successfully\n"); > } > return lastError; > } > > > int main() > { > > > sqlite3 *db; > db=mod_init(); > char *val=malloc(1000); > //strcpy(val, > char dest[]="axzchsdjzcjsdjdcfsjhgfcshgsdfgsfg h > dbhjbbssdfsdsgffjhdsgfjg"; > strcpy(val,dest); > > mydef_set(db,"sssi",&val); > > } _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users