OK, thanks, will have to study this carefully.
So, if I understand you well then the way I do it now I would need

Not sure it is helpful, but this is the callback procedure as I have it. It
will find a specified string (second argument in SQL)
in the supplied field value (first argument) and produce a string as in the
first argument string, but leaving out all starting
at the start of the second argument string. I know all this can be done
quite simple with the built-in function substr and instr
and that is probably faster, but I just use this as test code:

Sub ClearStartAtStringX(ByVal lPtr_ObjContext As Long, _
                        ByVal lArgCount As Long, _
                        ByVal lPtr_ObjSQLite3_Value As Long)

        Dim lPtr1 As Long
        Dim lPtr2 As Long
        Dim lPtr3 As Long
        Dim lPtr4 As Long
        Dim str As String
        Dim str2 As String
        Dim lPos As Long
        Dim lBytes As Long

        'field value to alter
10      lPtr1 = MemLong(lPtr_ObjSQLite3_Value) 'copy pointer
20      lPtr2 = sqlite3_value_text(lPtr1)
30      lBytes = sqlite3_value_bytes(lPtr1)
40      If lBytes = 0 Then
50        sqlite3_result_null lPtr_ObjContext
60        Exit Sub
70      End If
 'produce normal VB Unicode string
80      str = cSQL.PointerToString(lPtr2, CP_UTF8, lBytes, lBytes)

        'clear after finding this string
90      lPtr3 = MemLong(lPtr_ObjSQLite3_Value + 4) 'copy pointer
100     lPtr4 = sqlite3_value_text(lPtr3)
110     lBytes = sqlite3_value_bytes(lPtr3)
 'produce normal VB Unicode string
120     str2 = cSQL.PointerToString(lPtr4, CP_UTF8, lBytes, lBytes)
130     lPos = InStr(1, str, str2, vbBinaryCompare) 'VB instr function

        '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

End Sub


On Mon, Dec 14, 2015 at 9:00 PM, Igor Tandetnik <igor at tandetnik.org> wrote:

> On 12/14/2015 3:09 PM, Bart Smissaert wrote:
>> It could be either a pointer to sqlite3_value_text of sqlite3_value*
> No it can't be. sqlite3_result_text takes a char*, not a sqlite3_value* or
> a const unsigned char*(*)(sqlite3_value*)
> If you are saying that you plan to obtain the character pointer by calling
> sqlite3_value_text, then pass that exact pointer to sqlite3_result_text,
> then I would suggest you use sqlite3_result_value instead: it takes
> sqlite3_value* directly. If you insist on round-tripping through
> sqlite3_value_text, then you must pass SQLITE_TRANSIENT for the last
> parameter - the pointer returned by sqlite3_value_text is only guaranteed
> to be valid until the custom function returns.
> or it could be a pointer to a locally declared variable
> In this case, you would also use SQLITE_TRANSIENT.
> --
> Igor Tandetnik
> _______________________________________________
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to