Giter VIP home page Giter VIP logo

Comments (6)

ged avatar ged commented on August 22, 2024

Original comment by Michael Granger (Bitbucket: ged, GitHub: ged).


Please use the 'pg' library instead of the 'postgres' one. The 'postgres' library has numerous known problems, not the least of which is its implementation of large objects.

If you're looking at 'pg.c' (which is the extension source for 'pg', not 'postgres'), you'll notice that the documentation for both [[http://bitbucket.org/ged/ruby-pg/src/tip/ext/pg.c#cl-2689|lo_creat]] and [[http://bitbucket.org/ged/ruby-pg/src/tip/ext/pg.c#cl-2716|lo_create]] document that it returns a Fixnum, which is the Oid of the created object.

You are correct about sample/losample.rb, though. Most the files in that directory are horribly out of date. I'll fix the losample ASAP to reflect pg's interface.

from ruby-pg.

ged avatar ged commented on August 22, 2024

Original comment by fredericp (Bitbucket: fredericp, GitHub: fredericp).


Sorry, wasn't clear enough in my first report. I am using the 'pg' library, and I know that these functions do return a FIXNUM from looking at the source-code. But IMHO that isn't documentation, http://bitbucket.org/ged/ruby-pg/src/tip/doc/postgres.html is. And the information in that file is clearly not up to date.

Which calling-sequence do I have to use to create and open a large object so that I can write to it? The appended example-script doesn't work.

#!ruby

farnsworth: ~/ruby$ cat -n pgtest.rb 
     1	require 'rubygems'
     2	require 'pg'
     3	
     4	mydata = 'this is my special test string'
     5	db = PGconn.open(:host => 'myhost', :user => 'myuser', :password => 'mypassword', :dbname => 'mydb', :sslmode => 'require')
     6	
     7	oid = db.locreat(PGconn::INV_READ | PGconn::INV_WRITE)
     8	lo = db.loopen(oid, PGconn::INV_READ | PGconn::INV_WRITE)
     9	lo.write(mydata)
    10	lo.close
    11	db.close

farnsworth: ~/ruby$ ruby pgtest.rb 
pgtest.rb:9: undefined method `write' for 0:Fixnum (NoMethodError)

from ruby-pg.

ged avatar ged commented on August 22, 2024

Original comment by Michael Granger (Bitbucket: ged, GitHub: ged).


Modified the large-object sample script to reflect the pg library's API (refs #35)

from ruby-pg.

ged avatar ged commented on August 22, 2024

Original comment by Michael Granger (Bitbucket: ged, GitHub: ged).


The 'postgres.html' file is documentation for the 'postgres' library, which is why I assumed you were using it. I will be removing it shortly, as it has been replaced by inline documentation which can be extracted using RDoc. I'll also post a link to the generated docs on my server so you don't need to generate them yourself.

I've replaced the large-object sample script with one that works for the 'pg' library; I'd be happy to answer questions about it.

You example code should look something like:

#!ruby

require 'rubygems'
require 'pg'

mydata = 'this is my special test string'
db = PGconn.open(:host => 'myhost', :user => 'myuser', 
	:password => 'mypassword', :dbname => 'mydb', 
	:sslmode => 'require')

db.exec("BEGIN")
oid = db.locreat(PGconn::INV_READ | PGconn::INV_WRITE)
lo = db.loopen(oid, PGconn::INV_READ | PGconn::INV_WRITE)
db.lowrite(lo, mydata)
db.loclose(lo)
db.exec("COMMIT")
db.close

from ruby-pg.

ged avatar ged commented on August 22, 2024

Original comment by fredericp (Bitbucket: fredericp, GitHub: fredericp).


Thanks a lot, that did the trick :-)

from ruby-pg.

ged avatar ged commented on August 22, 2024

Original comment by Michael Granger (Bitbucket: ged, GitHub: ged).


Happy to help. Thanks for helping to improve the documentation! :)

from ruby-pg.

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.