Code Monkey home page Code Monkey logo

Comments (4)

iamed2 avatar iamed2 commented on June 26, 2024

I'm not sure why this might happen, but I would try to gather more information:

  • Perhaps ask for status(conn) before and after calling the function
  • Set PQsetErrorVerbosity to PQERRORS_VERBOSE (typically this has little impact on connection errors but maybe it will here)

What client LibPQ.jl version and what server version do you have?

from libpq.jl.

NicholasWMRitchie avatar NicholasWMRitchie commented on June 26, 2024

Thanks! With your suggestions, I was able to answer my own question. The verbose errors pointed to the right line in the libpq C code.
It seems that I must wrap either operation (lo_import / lo_export) in a transaction. (This probably also is true of other lo_XXX operations.)

from libpq.jl.

NicholasWMRitchie avatar NicholasWMRitchie commented on June 26, 2024

For what it is worth, these functions perform basic large object import/export and deletion.

function lo_import(conn::LibPQ.Connection, filename::AbstractString)::LibPQ.Oid
    execute(conn, "BEGIN;");
    res = 0
    try
        if (res = LibPQ.libpq_c.lo_import(conn.conn, filename)) == LibPQ.Oid(0x0)
            @error LibPQ.error_message(conn)
        end
    finally
        execute(conn,"COMMIT;")
    end
    res
end

This export function creates a temporary file, writes the file to the temporary, hands
the filename to func, deletes the temporary and then returns the result of func. On
error the function returns missing.

function lo_export(func::Function, conn::LibPQ.Connection, oid::UInt32)
    res = missing
    filename=tempname(;cleanup=false)
    try
        execute(conn, "BEGIN;");
        try
            if LibPQ.libpq_c.lo_export(conn.conn, oid, filename) == 1
                try
                    res = func(filename)
                catch ex
                    @error ex
                end
            else
                @error LibPQ.error_message(conn)
            end
        finally
            execute(conn, "COMMIT;")
        end
    finally
        rm(filename; force=true)
    end
    res
end

The lo_unlink function doesn't seem to require a transaction.

function lo_unlink(conn::LibPQ.Connection, oid::UInt32)
    res = -1
    if (res=LibPQ.libpq_c.lo_unlink(conn.conn, oid)) != 1
        @error LibPQ.error_message(conn)
    end
    res
end

from libpq.jl.

iamed2 avatar iamed2 commented on June 26, 2024

I want to keep transactions out of the functions to allow users to decide on their transactions (e.g. maybe they want to do multiple operations within the transactions). But having functions that wrap the libpq_c code would definitely be useful, and this is helpful, thanks.

With your suggestions, I was able to answer my own question. The verbose errors pointed to the right line in the libpq C code.

This is a good indication I should expose the verbosity option at the Connection level.

from libpq.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.