~ubuntu-branches/ubuntu/natty/postgresql-8.4/natty-security

« back to all changes in this revision

Viewing changes to src/interfaces/ecpg/ecpglib/connect.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-11 16:59:35 UTC
  • mfrom: (5.1.1 karmic)
  • Revision ID: james.westby@ubuntu.com-20090711165935-jfwin6gfrxf0gfsi
Tags: 8.4.0-2
* debian/libpq-dev.install: Ship catalog/genbki.h. (Closes: #536139)
* debian/rules: Drop --enable-cassert for final release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.53 2009/01/15 11:52:55 petere Exp $ */
 
1
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.54 2009/06/11 14:49:13 momjian Exp $ */
2
2
 
3
3
#define POSTGRES_ECPG_INTERNAL
4
4
#include "postgres_fe.h"
270
270
        struct sqlca_t *sqlca = ECPGget_sqlca();
271
271
        enum COMPAT_MODE compat = c;
272
272
        struct connection *this;
273
 
        int i;
 
273
        int                     i;
274
274
        char       *dbname = name ? ecpg_strdup(name, lineno) : NULL,
275
275
                           *host = NULL,
276
276
                           *tmp,
477
477
                         options ? "with options " : "", options ? options : "",
478
478
                         user ? "for user " : "", user ? user : "");
479
479
 
480
 
        connect_string = ecpg_alloc(      strlen_or_null(host)
481
 
                                        + strlen_or_null(port)
482
 
                                        + strlen_or_null(options)
483
 
                                        + strlen_or_null(realname)
484
 
                                        + strlen_or_null(user)
485
 
                                        + strlen_or_null(passwd)
486
 
                                        + sizeof(" host = port = dbname = user = password ="), lineno);
 
480
        connect_string = ecpg_alloc(strlen_or_null(host)
 
481
                                                                + strlen_or_null(port)
 
482
                                                                + strlen_or_null(options)
 
483
                                                                + strlen_or_null(realname)
 
484
                                                                + strlen_or_null(user)
 
485
                                                                + strlen_or_null(passwd)
 
486
                          + sizeof(" host = port = dbname = user = password ="), lineno);
487
487
 
488
 
        if (options) /* replace '&' if tehre are any */
 
488
        if (options)                            /* replace '&' if tehre are any */
489
489
                for (i = 0; options[i]; i++)
490
490
                        if (options[i] == '&')
491
491
                                options[i] = ' ';
492
492
 
493
 
        sprintf(connect_string,"%s%s %s%s %s%s %s%s %s%s %s",
494
 
                         realname ? "dbname=" : "", realname ? realname : "",
495
 
                         host ? "host=" : "", host ? host : "",
496
 
                         port ? "port=" : "", port ? port : "",
497
 
                         user ? "user=" : "", user ? user : "",
498
 
                         passwd ? "password=" : "", passwd ? passwd : "",
499
 
                         options ? options : "");
500
 
        
501
 
        /* this is deprecated
502
 
         * this->connection = PQsetdbLogin(host, port, options, NULL, realname, user, passwd);*/
 
493
        sprintf(connect_string, "%s%s %s%s %s%s %s%s %s%s %s",
 
494
                        realname ? "dbname=" : "", realname ? realname : "",
 
495
                        host ? "host=" : "", host ? host : "",
 
496
                        port ? "port=" : "", port ? port : "",
 
497
                        user ? "user=" : "", user ? user : "",
 
498
                        passwd ? "password=" : "", passwd ? passwd : "",
 
499
                        options ? options : "");
 
500
 
 
501
        /*
 
502
         * this is deprecated this->connection = PQsetdbLogin(host, port, options,
 
503
         * NULL, realname, user, passwd);
 
504
         */
503
505
        this->connection = PQconnectdb(connect_string);
504
506
 
505
507
        ecpg_free(connect_string);
589
591
        return true;
590
592
}
591
593
 
592
 
PGconn* ECPGget_PGconn(const char *connection_name)
 
594
PGconn *
 
595
ECPGget_PGconn(const char *connection_name)
593
596
{
594
 
        struct connection * con;
 
597
        struct connection *con;
595
598
 
596
 
        con=ecpg_get_connection(connection_name);
597
 
        if (con==NULL) return NULL;    
 
599
        con = ecpg_get_connection(connection_name);
 
600
        if (con == NULL)
 
601
                return NULL;
598
602
 
599
603
        return con->connection;
600
604
}