Thread: reg:lseek&read ..pls

reg:lseek&read ..pls

From
"sandhya"
Date:
hi......
 
I stored few files into the database and trying to open it while accessing webserver...
In that case i need to just read the contents of the large object.
So...After importing all the files into the database i am trying to read the contents of the object.
But before that i need to know the size of the object from which i am trying to get the contents.
How can i do this?
 
void
pickout(PGconn *conn, Oid lobjId, int start, int len)
I used the above sample one which is in postgres document.
Here i am mentioning the Oid and start as 0 and len as 2000.....But i am unable to get the whole contents of the file.
If i want to get entire file contents...How to do?
What len i need to specify?
Is there any thing to know the size of the object?
Please tell me..............
 
Thank you
-Sandhya

Re: reg:lseek&read ..pls

From
Tom Lane
Date:
"sandhya" <sandhyar@amiindia.co.in> writes:
> But before that i need to know the size of the object from which i am =
> trying to get the contents.
> How can i do this?

Same way you'd do it for a Unix file: seek to the end, note the end
offset, seek back to the start and read.

    ... lo_open ...
    lo_size = lo_lseek(conn, fd, 0, SEEK_END);  // where's the end?
    lo_lseek(conn, fd, 0, SEEK_SET);  // go back to start

            regards, tom lane

reg:reading files from the DB

From
"sandhya"
Date:
Hi.....

I used one function where in we can read the contents of the file from the
database.
Whenever there is a request for the specified file it should take the
contents from the database.
I have exported all my files to database....and in webserver when ever there
is a request fro the file i am opening and reading it
from the database.
I have connected to DB server remotely and executing.
Please tell me how to proceed.
When ever there is a request for the particular file i am getting the Object
id and passing it to the following function.
Is this correct?
please suggest me .........
voi d GetFiles(PGconn *conn, unsigned int lobjId, int start)
{

---------

------------

int lobj_fd;

lobj_fd = lo_open(conn, lobjId, INV_READ);

if (lobj_fd < 0)

{

MessageBox(0,"error","Cannot Object Id ",MB_OK);

}

lo_lseek(conn, lobj_fd, start, SEEK_END);

len = lo_tell(conn,lobj_fd);

lo_lseek(conn, lobj_fd, start, SEEK_SET);

buf =(char*) malloc(len + 1);

nread = 0;

while (len - nread > 0)

{

nbytes = lo_read(conn, lobj_fd, buf, len - nread);

buf[nbytes] = ' ';

nread += nbytes;

}

MessageBox(0,"Inside get","test",MB_OK);

free(buf);

lo_close(conn, lobj_fd);

}

Thank you.....
Sandhya

----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "sandhya" <sandhyar@amiindia.co.in>
Cc: "postgre" <pgsql-admin@postgresql.org>
Sent: Monday, December 26, 2005 9:08 PM
Subject: Re: [ADMIN] reg:lseek&read ..pls


> "sandhya" <sandhyar@amiindia.co.in> writes:
> > But before that i need to know the size of the object from which i am =
> > trying to get the contents.
> > How can i do this?
>
> Same way you'd do it for a Unix file: seek to the end, note the end
> offset, seek back to the start and read.
>
> ... lo_open ...
> lo_size = lo_lseek(conn, fd, 0, SEEK_END);  // where's the end?
> lo_lseek(conn, fd, 0, SEEK_SET);  // go back to start
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>




sending mail from Postgres

From
"Aftab Alam"
Date:
Hi there,

How can i send mail form postgresql.

any suggestion.

thanx & regards
aftab

Re: sending mail from Postgres

From
Michael Fuhr
Date:
On Tue, Dec 27, 2005 at 02:44:32PM +0530, Aftab Alam wrote:
> How can i send mail form postgresql.

You could write a function in a language like plperlu, pltclu, or
plpython, but a problem with functions that have effects outside
the database is that those effects can't be undone if the transaction
rolls back.  A common example is a trigger that sends email when a
table is changed: if the trigger fires and then you roll back the
transaction, it's too late to cancel the email.  Depending on what
you're doing it might be better to use LISTEN/NOTIFY and have a
client program send email when it receives a notification (notifications
are sent only when the transaction commits).

--
Michael Fuhr

Re: sending mail from Postgres

From
"Aftab Alam"
Date:
Hi Michael,

thanks for your reply.

you have mention that i can use plperlu, pltclu, or
plpython for sending mail, i am using windows version of postgres(7.3.1),

I have found that no dll in the postgres lib. for above mention language.

kindly suggest, form where i can find those language lib, & how can i
install those lib.

thanx & Regards,
aftab




7.3.1
-----Original Message-----
From: pgsql-admin-owner@postgresql.org
[mailto:pgsql-admin-owner@postgresql.org]On Behalf Of Michael Fuhr
Sent: Tuesday, December 27, 2005 11:11 PM
To: Aftab Alam
Cc: 'postgre'
Subject: Re: [ADMIN] sending mail from Postgres


On Tue, Dec 27, 2005 at 02:44:32PM +0530, Aftab Alam wrote:
> How can i send mail form postgresql.

You could write a function in a language like plperlu, pltclu, or
plpython, but a problem with functions that have effects outside
the database is that those effects can't be undone if the transaction
rolls back.  A common example is a trigger that sends email when a
table is changed: if the trigger fires and then you roll back the
transaction, it's too late to cancel the email.  Depending on what
you're doing it might be better to use LISTEN/NOTIFY and have a
client program send email when it receives a notification (notifications
are sent only when the transaction commits).

--
Michael Fuhr

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

               http://www.postgresql.org/docs/faq


Re: sending mail from Postgres

From
Jaime Casanova
Date:
On 12/27/05, Aftab Alam <aalam@tatashare.com> wrote:
> Hi Michael,
>
> thanks for your reply.
>
> you have mention that i can use plperlu, pltclu, or
> plpython for sending mail, i am using windows version of postgres(7.3.1),
>

on cygwin i guess... so you have to get a version of one  of those
languages (tcl, perl, python) for cygwin

> I have found that no dll in the postgres lib. for above mention language.
>
> kindly suggest, form where i can find those language lib, & how can i
> install those lib.
>
> thanx & Regards,
> aftab
>
>
>
>
> 7.3.1
> -----Original Message-----
> From: pgsql-admin-owner@postgresql.org
> [mailto:pgsql-admin-owner@postgresql.org]On Behalf Of Michael Fuhr
> Sent: Tuesday, December 27, 2005 11:11 PM
> To: Aftab Alam
> Cc: 'postgre'
> Subject: Re: [ADMIN] sending mail from Postgres
>
>
> On Tue, Dec 27, 2005 at 02:44:32PM +0530, Aftab Alam wrote:
> > How can i send mail form postgresql.
>
> You could write a function in a language like plperlu, pltclu, or
> plpython, but a problem with functions that have effects outside
> the database is that those effects can't be undone if the transaction
> rolls back.  A common example is a trigger that sends email when a
> table is changed: if the trigger fires and then you roll back the
> transaction, it's too late to cancel the email.  Depending on what
> you're doing it might be better to use LISTEN/NOTIFY and have a
> client program send email when it receives a notification (notifications
> are sent only when the transaction commits).
>
> --
> Michael Fuhr
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
>               http://www.postgresql.org/docs/faq
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
>       choose an index scan if your joining column's datatypes do not
>       match
>


--
Atentamente,
Jaime Casanova
(DBA: DataBase Aniquilator ;)