I have tried about the same method and got it to work. if you included more
code in the question, it might highlight a problem or make it easier to
replicate, investigate the situation described.
- To convert function to callback I used:
precallback = function printrow(::Ptr{Void}, ncol::Cint, rescolp::Ptr{Ptr{
Uint8}}, colnmp::Ptr{Void})
println("ncol = $ncol")
for i=1:ncol
println("col$i = $(bytestring(unsafe_load(rescolp,i)))");
end
convert(Cint,0)
end
callback = cfunction(precallback,Cint,(Ptr{Void}, Cint, Ptr{Ptr{Uint8}}, Ptr
{Void}))
ccall((:sqlite3_exec,"libsqlite3.so.0"),Cint,(Ptr{Void},Ptr{Uint8},Ptr{Void
},Ptr{Void},Ptr{Ptr{Uint8}}),handle,query,callback,param,errmsg)
the output was as expected.
using really fresh version: Julia Version 0.4.0-dev+940 Commit 265f9b8*
(2014-10-04 10:37 UTC)
see anything different?
On Monday, October 6, 2014 11:55:54 AM UTC+3, Stephan Buchert wrote:
>
> The C function is
>
> int sqlite3_exec(
> sqlite3*, /* An open database */
> const char *sql, /* SQL to be evaluated */
> int (*callback)(void*,int,char**,char**), /* Callback function */
> void *, /* 1st argument to callback */
> char **errmsg /* Error msg written here */
> );
>
> and the documention says:
>
> "The 3rd argument to the sqlite3_exec() callback is an array of pointers
> to strings ...."
>
> My Julia function handed over for callback is
>
> function printrow(::Ptr{Void}, ncol::Cint, rescolp::Ptr{Ptr{Uint8}},
> colnmp::Ptr{Ptr{Uint8}})
> for k=1:ncol
> print("$(bytestring(unsafe_load(rescolp, k))) ")
> end
> println()
> cint(0)
> end
>
> When executing a test case I get "ERROR: function is not yet c-callable"
>
> function printrow(::Ptr{Void}, ncol::Cint, rescolp::Ptr{Void},
> colnmp::Ptr{Void})
> println("ncol = $ncol")
> end
>
> works, but I would of course like to print the strings themselves. Several
> of my efforts to use the Julia pointer_to_array, etc were not successful.
>
>
>
>
>