- Moved from PQsetdbLogin to PQconnectDB.

- Correctly parse connect options.
- Changed regression tests accordingly.
This commit is contained in:
Michael Meskes 2008-03-27 07:56:02 +00:00
parent 039dfbfd5d
commit 9d7b256eeb
43 changed files with 154 additions and 108 deletions

View File

@ -2336,6 +2336,11 @@ Thu, 20 Mar 2008 16:54:27 +0100
Tue, 25 Mar 2008 13:42:26 +0100
- Should list ECPGget_PGconn in exports.txt.
Wed, 26 Mar 2008 17:02:08 +0100
- Moved from PQsetdbLogin to PQconnectDB.
- Correctly parse connect options.
- Set pgtypes library version to 3.1.
- Set compat library version to 3.1.
- Set ecpg library version to 6.2.

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.49 2008/03/20 16:29:44 meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.50 2008/03/27 07:56:00 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
@ -255,6 +255,13 @@ ECPGnoticeReceiver(void *arg, const PGresult *result)
ecpg_log("raising sqlcode %d\n", sqlcode);
}
static int
strlen_or_null(const char *string)
{
if (!string)
return 0;
return (strlen(string));
}
/* this contains some quick hacks, needs to be cleaned up, but it works */
bool
@ -263,12 +270,14 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
struct sqlca_t *sqlca = ECPGget_sqlca();
enum COMPAT_MODE compat = c;
struct connection *this;
int i;
char *dbname = name ? ecpg_strdup(name, lineno) : NULL,
*host = NULL,
*tmp,
*port = NULL,
*realname = NULL,
*options = NULL;
*options = NULL,
*connect_string = NULL;
ecpg_init_sqlca(sqlca);
@ -351,6 +360,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
tmp = last_dir_separator(dbname + offset);
if (tmp != NULL) /* database name given */
{
if (tmp[1] != '\0') /* non-empty database name */
realname = ecpg_strdup(tmp + 1, lineno);
*tmp = '\0';
}
@ -467,20 +477,47 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
options ? "with options " : "", options ? options : "",
user ? "for user " : "", user ? user : "");
this->connection = PQsetdbLogin(host, port, options, NULL, realname, user, passwd);
connect_string = ecpg_alloc( strlen_or_null(host)
+ strlen_or_null(port)
+ strlen_or_null(options)
+ strlen_or_null(realname)
+ strlen_or_null(user)
+ strlen_or_null(passwd)
+ sizeof(" host = port = dbname = user = password ="), lineno);
if (options) /* replace '&' if tehre are any */
for (i = 0; options[i]; i++)
if (options[i] == '&')
options[i] = ' ';
sprintf(connect_string,"%s%s %s%s %s%s %s%s %s%s %s",
realname ? "dbname=" : "", realname ? realname : "",
host ? "host=" : "", host ? host : "",
port ? "port=" : "", port ? port : "",
user ? "user=" : "", user ? user : "",
passwd ? "password=" : "", passwd ? passwd : "",
options ? options : "");
/* this is deprecated
* this->connection = PQsetdbLogin(host, port, options, NULL, realname, user, passwd);*/
this->connection = PQconnectdb(connect_string);
ecpg_free(connect_string);
if (host)
ecpg_free(host);
if (port)
ecpg_free(port);
if (options)
ecpg_free(options);
if (dbname)
ecpg_free(dbname);
if (PQstatus(this->connection) == CONNECTION_BAD)
{
const char *errmsg = PQerrorMessage(this->connection);
const char *db = realname ? realname : "<DEFAULT>";
ecpg_log("ECPGconnect: could not open database %s on %s port %s %s%s%s%s in line %d\n\t%s\n",
db,
host ? host : "<DEFAULT>",
port ? (ecpg_internal_regression_mode ? "<REGRESSION_PORT>" : port) : "<DEFAULT>",
options ? "with options " : "", options ? options : "",
user ? "for user " : "", user ? user : "",
lineno, errmsg);
ecpg_log("ECPGconnect: could not open database: %s\n", errmsg);
ecpg_finish(this);
#ifdef ENABLE_THREAD_SAFETY
@ -488,33 +525,19 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
#endif
ecpg_raise(lineno, ECPG_CONNECT, ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION, db);
if (host)
ecpg_free(host);
if (port)
ecpg_free(port);
if (options)
ecpg_free(options);
if (realname)
ecpg_free(realname);
if (dbname)
ecpg_free(dbname);
return false;
}
if (realname)
ecpg_free(realname);
#ifdef ENABLE_THREAD_SAFETY
pthread_mutex_unlock(&connections_mutex);
#endif
if (host)
ecpg_free(host);
if (port)
ecpg_free(port);
if (options)
ecpg_free(options);
if (realname)
ecpg_free(realname);
if (dbname)
ecpg_free(dbname);
this->committed = true;
this->autocommit = autocommit;

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.362 2008/03/01 03:26:35 tgl Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.363 2008/03/27 07:56:00 meskes Exp $ */
/* Copyright comment */
%{
@ -635,10 +635,10 @@ add_typedef(char *name, char * dimension, char * length, enum ECPGttype type_enu
%type <str> connection_object opt_server opt_port c_stuff c_stuff_item
%type <str> user_name opt_user char_variable ora_user ident opt_reference
%type <str> var_type_declarations quoted_ident_stringvar ECPGKeywords_rest
%type <str> db_prefix server opt_options opt_connection_name c_list
%type <str> db_prefix server connect_options opt_options opt_connection_name c_list
%type <str> ECPGSetConnection ECPGTypedef c_args ECPGKeywords ECPGCKeywords
%type <str> enum_type civar civarind ECPGCursorStmt PreparableStmt
%type <str> ECPGFree ECPGDeclare ECPGVar at enum_definition
%type <str> ECPGFree ECPGDeclare ECPGVar at enum_definition opt_opt_value
%type <str> struct_union_type s_struct_union vt_declarations execute_rest
%type <str> var_declaration type_declaration single_vt_declaration
%type <str> ECPGSetAutocommit on_off variable_declarations ECPGDescribe
@ -5166,7 +5166,7 @@ char_variable: cvariable
}
;
opt_options: Op ColId
opt_options: Op connect_options
{
if (strlen($1) == 0)
mmerror(PARSE_ERROR, ET_ERROR, "incomplete statement");
@ -5179,6 +5179,27 @@ opt_options: Op ColId
| /*EMPTY*/ { $$ = EMPTY; }
;
connect_options: ColId opt_opt_value
{ $$ = make2_str($1, $2); }
| ColId opt_opt_value Op connect_options
{
if (strlen($3) == 0)
mmerror(PARSE_ERROR, ET_ERROR, "incomplete statement");
if (strcmp($3, "&") != 0)
mmerror(PARSE_ERROR, ET_ERROR, "unrecognised token '%s'", $3);
$$ = cat_str(3, make2_str($1, $2), $3, $4);
}
;
opt_opt_value: /*EMPTY*/
{ $$ = EMPTY; }
| '=' Iconst
{ $$ = make2_str(make_str("="), $2); }
| '=' IDENT
{ $$ = make2_str(make_str("="), $2); }
;
/*
* Declare a prepared cursor. The syntax is different from the standard
* declare statement, so we create a new rule.

View File

@ -55,7 +55,7 @@ exec sql end declare section;
exec sql connect to unix:postgresql://localhost:@TEMP_PORT@/connectdb user connectuser using "connectpw";
exec sql disconnect;
exec sql connect to unix:postgresql://localhost:@TEMP_PORT@/connectdb user connectuser;
exec sql connect to unix:postgresql://localhost:@TEMP_PORT@/connectdb?connect_timeout=14 user connectuser;
exec sql disconnect;
/* wrong db */

View File

@ -118,7 +118,7 @@ main(void)
#line 56 "test1.pgc"
{ ECPGconnect(__LINE__, 0, "unix:postgresql://localhost:@TEMP_PORT@/connectdb" , "connectuser" , NULL , NULL, 0); }
{ ECPGconnect(__LINE__, 0, "unix:postgresql://localhost:@TEMP_PORT@/connectdb?connect_timeout=14" , "connectuser" , NULL , NULL, 0); }
#line 58 "test1.pgc"
{ ECPGdisconnect(__LINE__, "CURRENT");}

View File

@ -38,9 +38,9 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_finish: Connection connectdb closed.
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGconnect: opening database on localhost port <REGRESSION_PORT> for user connectdb
[NO_PID]: ECPGconnect: opening database <DEFAULT> on localhost port <REGRESSION_PORT> for user connectdb
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_finish: Connection closed.
[NO_PID]: ecpg_finish: Connection (null) closed.
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGconnect: opening database connectdb on localhost port <REGRESSION_PORT> for user connectuser
[NO_PID]: sqlca: code: 0, state: 00000
@ -50,14 +50,13 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_finish: Connection connectdb closed.
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGconnect: opening database connectdb on <DEFAULT> port <REGRESSION_PORT> for user connectuser
[NO_PID]: ECPGconnect: opening database connectdb on <DEFAULT> port <REGRESSION_PORT> with options connect_timeout=14 for user connectuser
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_finish: Connection connectdb closed.
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGconnect: opening database nonexistant on localhost port <REGRESSION_PORT> for user connectuser
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGconnect: could not open database nonexistant on localhost port <REGRESSION_PORT> for user connectuser in line 62
FATAL: database "nonexistant" does not exist
[NO_PID]: ECPGconnect: could not open database: FATAL: database "nonexistant" does not exist
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_finish: Connection nonexistant closed.
@ -68,8 +67,7 @@
[NO_PID]: sqlca: code: -220, state: 08003
[NO_PID]: ECPGconnect: opening database connectdb on localhost port <REGRESSION_PORT> for user connectuser
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGconnect: could not open database connectdb on localhost port <REGRESSION_PORT> for user connectuser in line 66
could not connect to server: Connection refused
[NO_PID]: ECPGconnect: could not open database: could not connect to server: Connection refused
Is the server running on host "localhost" and accepting
TCP/IP connections on port 20?

View File

@ -52,7 +52,7 @@
[NO_PID]: sqlca: code: -402, state: 08001
[NO_PID]: raising sqlcode -220 in line 57, 'No such connection main in line 57.'.
[NO_PID]: sqlca: code: -220, state: 08003
[NO_PID]: ECPGconnect: opening database on <DEFAULT> port <DEFAULT> for user connectdb
[NO_PID]: ECPGconnect: opening database <DEFAULT> on <DEFAULT> port <DEFAULT> for user connectdb
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_finish: Connection main closed.
[NO_PID]: sqlca: code: 0, state: 00000

View File

@ -1 +0,0 @@
No threading enabled.

View File

@ -1 +1 @@
No threading enabled.
Success.

View File

@ -1 +1 @@
No threading enabled.
Success.