Обсуждение: Reg:Connection Object

Поиск
Список
Период
Сортировка

Reg:Connection Object

От
"sandhya"
Дата:
Hi,
    How to pass connection object across the functions.So that there is no need for me to connect to postgres database in each and every function.
 
For Ex:If i have say 3 functions:
 
One function i use to connect to the database.
 
In the other function, if i want to creat a table ...I need this persistant connection object which holds the details of the dbname and user etc.
 
Pls..help me in solving this.
Thank you very much
 
Regards,
Sandhya R

Re: Reg:Connection Object

От
Michael Fuhr
Дата:
On Thu, Sep 01, 2005 at 04:12:17PM +0530, sandhya wrote:
> How to pass connection object across the functions.So that there
> is no need for me to connect to postgres database in each and every
> function.

What functions?  You didn't say what language you're using, nor
whether you're writing client-side code or server-side code.

BTW, this thread seems off-topic for pgsql-admin because it doesn't
concern PostgreSQL administration.  You're more likely to get help
in pgsql-interfaces or pgsql-general, or in one of the more specific
lists like pgsql-jdbc or pgsql-php if you're using one of those
interfaces.

--
Michael Fuhr

Re: Reg:Connection Object

От
"sandhya"
Дата:
I am using normal C-Functions,In one function i will make connection with
the database.This connection object i need to get in my all other functions
where i will do the other operations like creating a table ,altering a table
in their respective functions.So..There is no need for me to ask the user to
pass the user ,password,database name in all other functions.Pls suggest me

-Sandhya

----- Original Message -----
From: "Michael Fuhr" <mike@fuhr.org>
To: "sandhya" <sandhyar@amiindia.co.in>
Cc: "postgre" <pgsql-admin@postgresql.org>
Sent: Thursday, September 01, 2005 7:16 PM
Subject: Re: [ADMIN] Reg:Connection Object


> On Thu, Sep 01, 2005 at 04:12:17PM +0530, sandhya wrote:
> > How to pass connection object across the functions.So that there
> > is no need for me to connect to postgres database in each and every
> > function.
>
> What functions?  You didn't say what language you're using, nor
> whether you're writing client-side code or server-side code.
>
> BTW, this thread seems off-topic for pgsql-admin because it doesn't
> concern PostgreSQL administration.  You're more likely to get help
> in pgsql-interfaces or pgsql-general, or in one of the more specific
> lists like pgsql-jdbc or pgsql-php if you're using one of those
> interfaces.
>
> --
> Michael Fuhr


Re: Reg:Connection Object

От
Michael Fuhr
Дата:
On Fri, Sep 02, 2005 at 09:56:19AM +0530, sandhya wrote:
> I am using normal C-Functions,In one function i will make connection with
> the database.This connection object i need to get in my all other functions
> where i will do the other operations like creating a table ,altering a table
> in their respective functions.So..There is no need for me to ask the user to
> pass the user ,password,database name in all other functions.Pls suggest me

Do you mean you're writing C code using libpq?  If so, why can't
you just pass the PGconn * as another argument to your functions?
Or use a global variable (although some programmers would consider
that bad style)?  It's not clear what difficulties you're having.

--
Michael Fuhr

Re: Reg:Connection Object

От
"sandhya"
Дата:
In case of multiple users what will happen?
Each must have different connection objects right!


----- Original Message -----
From: "Michael Fuhr" <mike@fuhr.org>
To: "sandhya" <sandhyar@amiindia.co.in>
Cc: "Askar Zaidi" <askar@mail.nplindia.ernet.in>; "postgre"
<pgsql-admin@postgresql.org>
Sent: Friday, September 02, 2005 10:46 AM
Subject: Re: [ADMIN] Reg:Connection Object


> On Fri, Sep 02, 2005 at 09:56:19AM +0530, sandhya wrote:
> > I am using normal C-Functions,In one function i will make connection
with
> > the database.This connection object i need to get in my all other
functions
> > where i will do the other operations like creating a table ,altering a
table
> > in their respective functions.So..There is no need for me to ask the
user to
> > pass the user ,password,database name in all other functions.Pls suggest
me
>
> Do you mean you're writing C code using libpq?  If so, why can't
> you just pass the PGconn * as another argument to your functions?
> Or use a global variable (although some programmers would consider
> that bad style)?  It's not clear what difficulties you're having.
>
> --
> Michael Fuhr


Re: Reg:Connection Object

От
Michael Fuhr
Дата:
On Fri, Sep 02, 2005 at 11:19:53AM +0530, sandhya wrote:
> In case of multiple users what will happen?
> Each must have different connection objects right!

That's why global variables are bad.  But what's wrong with passing
a PGconn * to various functions?  If that's a problem in your
application then please explain why; it's still not clear what
difficulties you're having.  Perhaps it would help if you posted a
simple but complete example program that shows what you're trying
to do.

As I mentioned before, this thread is off-topic for pgsql-admin;
it would be more appropriate in pgsql-interfaces or pgsql-general.

--
Michael Fuhr

Re: Reg:Connection Object

От
"Manikandan C"
Дата:
I hope, U can have a structure that have members as the "user name" and the "Connection object". Whenever a new
connectionis made, U can create instances of this structure. Based on the user name, you can pass the appropriate
instanceto the function. 

Hope this will help you.
Is this what you want?

Regards,
Mani

-----Original Message-----
From: pgsql-admin-owner@postgresql.org
[mailto:pgsql-admin-owner@postgresql.org]On Behalf Of Michael Fuhr
Sent: Friday, September 02, 2005 11:29 AM
To: sandhya
Cc: Askar Zaidi; postgre
Subject: Re: [ADMIN] Reg:Connection Object


On Fri, Sep 02, 2005 at 11:19:53AM +0530, sandhya wrote:
> In case of multiple users what will happen?
> Each must have different connection objects right!

That's why global variables are bad.  But what's wrong with passing
a PGconn * to various functions?  If that's a problem in your
application then please explain why; it's still not clear what
difficulties you're having.  Perhaps it would help if you posted a
simple but complete example program that shows what you're trying
to do.

As I mentioned before, this thread is off-topic for pgsql-admin;
it would be more appropriate in pgsql-interfaces or pgsql-general.

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster