Thread: Storing NULL Character in SQLite
09-19-11, 10:12 #1Registered User
- Join Date
- Mar 2009
- New Delhi - India
Unanswered: Storing NULL Character in SQLite
I am trying to store a value containing NULL character and escape sequences in a char column in SQLite. How can store and retrieve it correclty.
I have the below insert query:
snprintf(SqlStr,size, "INSERT INTO %s (AttrName, AttrEnum, AttrType, AttrValue, eadWrite, Entity_id) VALUES('%s', %d, %d, '%s', %d, %d);", tbl_name, db[i]>attr_name, db[i]->attr_num, db[i]->attr_type, db[i]->attr_value, db[i]->atr_src, entity_id);
attr_value contains "AB34\04FE".
It may contain other escape sequence at any index. How can I handle it using SQLite C library.
09-19-11, 11:52 #2Resident Curmudgeon
Provided Answers: 54
- Join Date
- Feb 2004
- In front of the computer
There is no ASCII NUL value in the string that you posted, so I'm not sure what is the problem.
SQL-Lite can be complied a number of different ways, some of which are tolerant of NUL values and some of which very decidedly aren't tolerant of NUL values. If I was not sure that every SQL-Lite implementation that your application can/will use is tolerant of NUL values, then I would modify your code to backslash quote every suspect string for storage and dequote them on retrieval.
-PatPIn theory, theory and practice are identical. In practice, theory and practice are unrelated.