Comments (6)
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.
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.
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.
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.
Original comment by fredericp (Bitbucket: fredericp, GitHub: fredericp).
Thanks a lot, that did the trick :-)
from ruby-pg.
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)
- Segmentation fault with ruby 2.7.8 and pg 1.5.3 HOT 10
- Segmentation fault HOT 28
- Sonoma: getaddrinfo segmentation fault HOT 2
- Segmentation fault in ruby:3.2.2-alpine3.18 docker image HOT 2
- Wrong binary conversion on x86 (32bit intel) arch causing test failures HOT 4
- Bad IAM Token against Amazon Aurora Postgres: Out of memory error HOT 2
- Attempting to execute a sql file with `\set ...` raises errors HOT 3
- conn.exec writing "INFO" statements to stderr instead of stdout HOT 2
- Segfault on ruby 3.2.2, pg 1.5.4 HOT 2
- Error ruby(39749,0x1e1f05300) malloc: double free for ptr 0x13c6bfa00 HOT 1
- Segmentation fault when connecting to RDS HOT 11
- Broken links in documentation HOT 3
- connection.reset don't check again DNS HOT 6
- Usage with ApacheAGE for Postgresql HOT 2
- Add BigDecimal to gemspec for Ruby 3.3/4 HOT 2
- Binary Windows gem no longer available for Ruby v3.3 since v1.5.6 HOT 2
- Test failure with modified `RUBY_PG_TEST_DIR` HOT 2
- Q: Is it possible to handle composite values like `row(123, 'str', true)` ? HOT 1
- Dereference of null in alloc_query_params HOT 1
- TypeError PG::TypeMap undefined method `key?' for nil if !type_map.key?(oid) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ruby-pg.