Maybe I shouldn't make Unicode strings but keep it all in UTF8. Not sure though how to get the position then of string2 in string1, lPos.
RBS On Tue, Dec 15, 2015 at 12:42 AM, Bart Smissaert <bart.smissaert at gmail.com> wrote: > Yes, str and str2 are Unicode string, 2 bytes per character. > lPos counts per character, not byte, so if the string in the database is > abcde and I want to find the first position > of d in that string then lPos will be 4. > > > You are converting in one direction (SQLite to VB), but not in the other > I thought SQLite would handle VB Unicode strings to UTF8 strings, but I > think you may be onto something there, > because if I move VB Unicode strings to SQLite I do sqlite3_bind_text16 > and I understand sqlite3_result_text is very > similar to sqlite3_bind_text. So, it makes sense I need > sqlite3_result_text16 instead. > > Will do some further testing. > > RBS > > > > > On Tue, Dec 15, 2015 at 12:22 AM, Igor Tandetnik <igor at tandetnik.org> > wrote: > >> On 12/14/2015 5:46 PM, Bart Smissaert wrote: >> >>> OK, thanks, will have to study this carefully. >>> So, if I understand you well then the way I do it now I would need >>> sqlite3_free? >>> >> >> First, I don't know how you do it now - you've never described that. >> Second, I have not ever said you needed sqlite3_free; nothing in your >> description of the problem so far suggests you need it. >> >> 'string not found, so return original field string >>> '------------------------------------------------- >>> 140 If lPos = 0 Then >>> 150 sqlite3_result_value lPtr_ObjContext, lPtr1 >>> 160 Exit Sub >>> 170 End If >>> 180 sqlite3_result_text lPtr_ObjContext, StrPtr(str), _ >>> (lPos - 2) * 2, SQLITE_TRANSIENT >>> >> >> To the extent I understand what's going on (I'm not really familiar with >> VB, so I'm taking and educated guess for the most part), the memory >> management part looks OK to me. >> >> However, I have doubts about encoding. Comments seem to suggest str >> points to a Unicode string; also the fact that you multiply lPos by 2. But >> sqlite3_result_text expects UTF-8 string. You are converting in one >> direction (SQLite to VB), but not in the other, as far as I can tell. I >> suspect you need sqlite3_result_text16 instead. >> >> Also lPos-2 looks wrong. Can't the substring be found at lPos == 1 ? >> >> -- >> Igor Tandetnik >> >> _______________________________________________ >> sqlite-users mailing list >> sqlite-users at mailinglists.sqlite.org >> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users >> > >