[Gambas-user] create custom user functions in SQLITE3 from Gambas

Angel angelnunez123 at gmail.com
Tue Apr 4 20:51:14 CEST 2023


hello

I am trying to create custom user functions in SQLITE3 from Gambas but 
given my ignorance of C it is impossible.

Has anyone tried?The function in C is:

int sqlite3_create_function(
   sqlite3 *db,
   const char *zFunctionName,
   int nArg,
   int eTextRep,
   void *pApp,
   void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
   void (*xStep)(sqlite3_context*,int,sqlite3_value**),
   void (*xFinal)(sqlite3_context*)
);

The explanation at: https://www.sqlite.org/c3ref/create_function.html

I've done:


' Gambas module file

Library "libsqlite3"
Private Extern sqlite3_create_function(db As Pointer, name As String, 
arg As Integer, eTextRep As Integer, pApp As Pointer, xFun As Pointer, 
xStep As Pointer, xFinal As Pointer)
Private BD As Connection

Public Sub Main()

     '#define SQLITE_UTF8     1

     Dim punt1 As Pointer
     Dim punt2 As Pointer
     Dim ia As Integer

     BD = New Connection
     With BD
         .Type = "sqlite3"
         .Host = Application.Path
         'verificating if db exist
         .Name = ""
         .Open
     End With

     punt1 = VarPtr(BD)
     Debug sepTelef("666777888")
     Debug punt1

     ia = sqlite3_create_function(punt1, "sepTelef", 1, 1, Null, 
sepTelef, Null, Null)

End

Function sepTelef(telefono As String) As String

     Dim scad As String

     scad = Mid(telefono, 1, 3) & "-" & Mid(telefono, 4, 3) & "-" & 
Mid(telefono, 7, 3)
     Return scad

End


result

Segment violation 11

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230404/cf3ef497/attachment.htm>


More information about the User mailing list