473,797 Members | 3,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SPI question (or not): trying to read from Large Objects from within a function

What:
I'm having trouble finding out how to find the current PGconn
connection inside a C function. Looking through the documentation
didn't give this up. Could anyone suggest where to look? I didn't even
see anything similar to this in the SPI_* documentation. Perhaps I am
totally mislead here?

Why:
I am writing an wrapper around librsync, allowing differential updating
of large amounts of data (librsync wraps the clever algorithm of
rsync).

The first function I'm wrapping is the one which generates a signature
(a hash of each block of data, with some specified block-size) from a
LO. Its signature would be:

create function rsync_signature (oid /* of an Large Object */) returns
bytea

But I can't figure out how to get the current PGconn to be able to run
the lo_* functions.
On another not, would it be possible to avoid using Large Objects, and
use TOAST columns instead? Ie. is it possible to quickly read/write
partial toast columns (I know it's not possible for clients, but on the
server side?).
There may be more questions later, but I'll try to pay back by
submitting the final implementation to contrib/ (if anyone is
interested). It'll allow for really fast incremental updates of a
columns, which I'll use to make storing of huge blobs less of a pain
(although it depends on the client also speaking rsync-ese, but that'll
be included with the package).
Regards,

d.
--
David Helgason
Over the Edge Entertainments


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 12 '05 #1
4 1452
David Helgason <da***@uti.is > writes:
I'm having trouble finding out how to find the current PGconn
connection inside a C function.


What makes you think that "*the* current PGconn" is a valid concept?
libpq has always supported multiple active connections.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #2
Thank you very much,

I figured I needed to open my own using SPI_connect(). I had assumed
that there was sth like a
the-connection-this-functions-is-begin-run-through.

Now I'm having problems with

size_t inBufSize = 8192;
char* inBuffer = (char*)palloc(i nBufSize);
int bytes_read = DatumGetInt32(D irectFunctionCa ll3(loread,
Int32GetDatum(f d), CStringGetDatum (inBuffer),
UInt32GetDatum( inBufSize)));

which returns an extremely large number in bytes_read (consistently
46235672), regardless of the contents of inBufSize.

I tried using lo_lseek(fd, 0, SEEK_END) on this fd already, which
correctly returned the size of the Large Object, so it's not a question
of an invalid descriptor. Also that seek didn't effect the result at
all. I guess it's wrong usage of the DatumGet*() / *GetDatum()
functions, but I can't see where.

Any suggestions?

d.

On 7. jan 2004, at 05:40, Tom Lane wrote:
David Helgason <da***@uti.is > writes:
I'm having trouble finding out how to find the current PGconn
connection inside a C function.


What makes you think that "*the* current PGconn" is a valid concept?
libpq has always supported multiple active connections.

regards, tom lane

---------------------------(end of
broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if
your
joining column's datatypes do not match

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 12 '05 #3
Sorry for spamming.... I'm getting the hang of this, and figured this
one out myself :)

These internal functions (loread/lowrite) have quite different
signatures from their C equivalents (as opposed to lo_lseek). Found out
from the sources that I was using it very incorrectly. But discovered
lo_read with a signature different from that documented as the Large
Object client interface: ones which don't take a connection parameter
at all. This really simplifies my code, which can now be:
size_t inBufSize = 8192;
char* inBuffer = (char*)palloc(i nBufSize);
int bytes_read = DatumGetInt32(D irectFunctionCa ll3(loread,
Int32GetDatum(f d), CStringGetDatum (inBuffer),
UInt32GetDatum( inBufSize))); int bytes_read = lo_read(fd, inBuffer, inBufSize);

and all is well... just too bad there aren't similarly simple versions
of the other lo_{lseek,open, ...}.

Thanks for the audience, and keep up the good work!

d.

On 7. jan 2004, at 06:22, David Helgason wrote:
Thank you very much,

I figured I needed to open my own using SPI_connect(). I had assumed
that there was sth like a
the-connection-this-functions-is-begin-run-through.

Now I'm having problems with
which returns an extremely large number in bytes_read (consistently
46235672), regardless of the contents of inBufSize.

I tried using lo_lseek(fd, 0, SEEK_END) on this fd already, which
correctly returned the size of the Large Object, so it's not a
question of an invalid descriptor. Also that seek didn't effect the
result at all. I guess it's wrong usage of the DatumGet*() /
*GetDatum() functions, but I can't see where.

Any suggestions?

d.

On 7. jan 2004, at 05:40, Tom Lane wrote:
David Helgason <da***@uti.is > writes:
I'm having trouble finding out how to find the current PGconn
connection inside a C function.


What makes you think that "*the* current PGconn" is a valid concept?
libpq has always supported multiple active connections.

regards, tom lane

---------------------------(end of
broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if
your
joining column's datatypes do not match

---------------------------(end of
broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to
ma*******@postg resql.org

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #4
David Helgason <da***@uti.is > writes:
These internal functions (loread/lowrite) have quite different
signatures from their C equivalents (as opposed to lo_lseek). Found out
from the sources that I was using it very incorrectly.


I had just realized from reading your last message that you were trying
to write server-side functions, and reading the client-side
documentation to do so :-(. The server-side stuff is really not the
same API at all, though it tends to use the same function names.
In general, you have to be prepared to read the source code when writing
server-side stuff.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1552
by: Jon Perez | last post by:
Is it safe to not put a lock on an object if it will always be read-only in other threads and will only ever be written to in just one and always the same one thread?
0
1207
by: cal_2pac | last post by:
Resurrecting a month old thread.. (listed at http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/2f4e50e1e316eef4/5924203f822f7f4b?q=cal_2pac&rnum=3#5924203f822f7f4b) Somehow - responses to that thread are not being brought up in chronological order. Thus the creation of another thread. The thread listed above proposed a solution to receive events from user events on the document in a webpage. However, it seems that...
3
4454
by: WinstonSmith | last post by:
Hello everyone, I got a problem about GC when creating large fields (some MB), set reference to null and call GC.Collect. Not all virtual mem is released. Situation improved in .net 1.1 but not in a full satisfying way. Has anyone a solution to handle large object in safe code? (Unsafe mem management works, but has serious disadvantages on serialization.)
1
1440
by: sibusiso xolo | last post by:
Greetings, I am trying to create a database to store imges as large objects. I am using postgres7.3.4 on a SuSE8.2 machine. I read the PostgreSQL documentation on lage objects. There are some new fnctions which I am unfamilar with. I have books on postgresql but I am not aware of any current book with example usage of these functions. I previously used up to 7.2 which had lo_import, lo_export and lo_unlink. I would be grateful...
11
5893
by: CSN | last post by:
Is it possible to iterate over an array in plpgsql? Something like: function insert_stuff (rel_ids int) .... foreach rel_ids as id insert into table (rel_id, val) values (id, 5);
0
980
by: David Helgason | last post by:
What: I'm having trouble finding out how to find the current PGconn connection inside a C function. Looking through the documentation didn't give this up. Could anyone suggest where to look? Why: I am writing an wrapper around librsync, allowing differential updating of large amounts of data (librsync wraps the clever algorithm of rsync).
0
793
by: David Helgason | last post by:
I think those best practices threads are a treat to follow (might even consider archiving some of them in a sort of best-practices faq), so here's one more. In coding an game asset server I want to keep a large number of file revisions of varying sizes (1Kb-50Mb) inside the database. Naturally I want to avoid having to allocate whole buffers of 50Mb too often.
14
1960
by: Bryan Parkoff | last post by:
Do you know that current C++ Compiler limits to 64KB segments in source code? It is good news that Microsoft Visual C++ 2005 has expanded to 4GB segments in source code. 4GB segment is ideal for large object using pointer to function and switch. Please list other C++ Compilers if they have added a support of 4GB segments. I am able to write 65,536 functions and 65,536 function's memory address is stored into pointer to function list. ...
14
2155
by: JoeC | last post by:
I have been writing games and I also read about good programming techniques. I tend to create large objects that do lots of things. A good example I have is a unit object. The object controls and holds everything a unit in my game is supposed to do. What are some some cures for this kind of large object or are they OK because they represent one thing. If not what are better ways to design objects that behave the same way. Would it be...
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9537
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10469
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10246
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10209
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10023
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9066
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4135
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3750
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.