[Greater-commits] r317 - trunk/GREAT-ER-DB/impl/postgresql
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Jun 30 11:41:47 CEST 2011
Author: bricks
Date: 2011-06-30 11:41:46 +0200 (Thu, 30 Jun 2011)
New Revision: 317
Modified:
trunk/GREAT-ER-DB/impl/postgresql/dagreater_pg.h
trunk/GREAT-ER-DB/impl/postgresql/gdagreater_pg.pgc
Log:
Check if an connection already exists in gda_db_connect and fail if true
Introduce new define for error DA_ERR_ALREADY_CONNECTD
Set correct error information if connection couldn't be established
Fix indentation
Modified: trunk/GREAT-ER-DB/impl/postgresql/dagreater_pg.h
===================================================================
--- trunk/GREAT-ER-DB/impl/postgresql/dagreater_pg.h 2011-06-30 09:37:34 UTC (rev 316)
+++ trunk/GREAT-ER-DB/impl/postgresql/dagreater_pg.h 2011-06-30 09:41:46 UTC (rev 317)
@@ -172,6 +172,8 @@
#define DA_ERR_MOD_REF_DATA 9016 /* ERR: model mode data set which is to be deleted
is still referenced by one or more sessions */
+#define DA_ERR_ALREADY_CONNECTED 9017 /* ERR: a connection ist still established while trying
+ to creater a new connection */
/* ----------------------------------------- *
* Access right constants
Modified: trunk/GREAT-ER-DB/impl/postgresql/gdagreater_pg.pgc
===================================================================
--- trunk/GREAT-ER-DB/impl/postgresql/gdagreater_pg.pgc 2011-06-30 09:37:34 UTC (rev 316)
+++ trunk/GREAT-ER-DB/impl/postgresql/gdagreater_pg.pgc 2011-06-30 09:41:46 UTC (rev 317)
@@ -4093,7 +4093,7 @@
db_con = malloc(sizeof(DB_con));
if(!db_con)
return NULL;
-
+
lgda_set_connection_values(db_con, vp_connect_descr,
vp_userid, vp_passwd, vp_errinfo);
@@ -4117,12 +4117,22 @@
strcpy(h_con_name, db_con->con_name);
strcpy(h_dbname, db_con->connection_target);
+ errln = 5;
+ if (ECPGstatus(__LINE__, db_con->con_name))
+ {
+ vp_errinfo->err_type = DA_ERRTYP_INT;
+ vp_errinfo->err_no = DA_ERR_ALREADY_CONNECTED;
+ sprintf(vp_errinfo->err_param, "%s - connection alreay exists. please disconnect. (%s)", v_module, db_con->user_id);
+ return NULL;
+ }
+
errln = 10;
EXEC SQL CONNECT TO :h_dbname AS :h_con_name USER :h_user_id USING :h_usrid_passwd;
-
+
if (!ECPGstatus(__LINE__, db_con->con_name))
{
- return(NULL);
+ lgda_set_db_errinfo( v_module, vp_errinfo);
+ return NULL;
}
/* check if connected user is a valid GREAT-ER user and in case
@@ -4177,7 +4187,7 @@
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
db_con = NULL;
- return(db_con);
+ return NULL;
}
if(NULL){
sql_error:
@@ -4299,7 +4309,7 @@
strcpy(h_con_name, db_con->con_name);
errln = 10;
- EXEC SQL CONNECT TO :dbname AS :h_con_name USER :h_user_id USING :h_usrid_passwd;
+ EXEC SQL CONNECT TO :dbname AS :h_con_name USER :h_user_id IDENTIFIED BY :h_usrid_passwd;
if (!ECPGstatus(__LINE__, db_con->con_name))
{
@@ -4414,7 +4424,7 @@
DA_T_MODULE_NAME v_module = "gda_db_disconnect";
EXEC SQL BEGIN DECLARE SECTION;
- char h_con_name [ 31];
+ char h_con_name [ 31];
EXEC SQL END DECLARE SECTION;
/* ------------------ *
@@ -4436,13 +4446,13 @@
errln = 10;
- /* PostgreSQL does not "rollback work release" to a savepoint.*
- * The RELEASE statement in oracle terminates a user's *
- * transaction and database session. */
+ /* PostgreSQL does not "rollback work release" to a savepoint.
+ * The RELEASE statement in oracle terminates a user's
+ * transaction and database session. */
- strcpy(h_con_name, db_con->con_name);
+ strcpy(h_con_name, db_con->con_name);
- gda_db_rollback(db_con,vp_errinfo);
+ gda_db_rollback(db_con, vp_errinfo);
EXEC SQL DISCONNECT :h_con_name;
free(db_con->connection_target);
@@ -4453,6 +4463,7 @@
free(db_con->user_passwd);
free(db_con->con_name);
free(db_con);
+ db_con = NULL;
/* success fully disconnected from database */
return(DA_SUCCESS);
@@ -10017,8 +10028,8 @@
\return DA_SUCCESS \n DA_FAIL
*/
-int gda_update_bin_obj(DB_con *db_con,
- DA_T_bin_obj *vp_bin_obj,
+int gda_update_bin_obj(DB_con *db_con,
+ DA_T_bin_obj *vp_bin_obj,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_bin_obj";
@@ -10076,7 +10087,7 @@
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
-
+
/* get access right for data */
v_status = lgda_get_access_right(DA_A_BIN_OBJ_TAB, (void*) vp_bin_obj,
&v_access_right, vp_errinfo);
@@ -10096,7 +10107,7 @@
h_bin_obj.file_size = vp_bin_obj->file_size;
v_file_obj_size = vp_bin_obj->file_size;
h_bin_obj.privs = vp_bin_obj->privs;
-
+
strcpy(h_bin_obj.name, vp_bin_obj->name);
strcpy(h_bin_obj.user_id, vp_bin_obj->user_id);
strcpy(h_bin_obj.obj_type, vp_bin_obj->obj_type);
@@ -10110,39 +10121,39 @@
INTO :h_bin_obj.mod_date;
connection = PQsetdbLogin(db_con->host, db_con->port, NULL, NULL, db_con->db_name, db_con->user_id, db_con->user_passwd);
-
+
if (PQstatus(connection) == CONNECTION_BAD)
{
PQfinish(connection);
- /* Update failed */
- return(DA_FAIL);
+ /* Update failed */
+ return(DA_FAIL);
}
/* Update passed record in database including BLOB if data are available */
if (vp_bin_obj->file_obj != NULL)
{
errln = 30;
- /* delete old blob from DATABASE */
+ /* delete old blob from DATABASE */
EXEC SQL SELECT FILE_OBJ INTO :dummy FROM BIN_OBJ_TAB
- WHERE BIN_OBJ_ID = :h_bin_obj_id;
+ WHERE BIN_OBJ_ID = :h_bin_obj_id;
- lobjOid = dummy;
-
- res = PQexec(connection, "begin");
- PQclear(res);
- lo_unlink(connection, lobjOid);
-
+ lobjOid = dummy;
+
+ res = PQexec(connection, "begin");
+ PQclear(res);
+ lo_unlink(connection, lobjOid);
+
lobjOid = lo_creat(connection, INV_READ|INV_WRITE);
fd = lo_open(connection, lobjOid, INV_WRITE);
lo_write(connection, fd, vp_bin_obj->file_obj, v_file_obj_size);
lo_close(connection, fd);
res = PQexec(connection, "end");
- PQclear(res);
+ PQclear(res);
PQfinish(connection);
h_file_obj = lobjOid;
- EXEC SQL UPDATE BIN_OBJ_TAB
+ EXEC SQL UPDATE BIN_OBJ_TAB
set BIN_OBJ_ID = :h_bin_obj.bin_obj_id,
OBJECT_ID = :h_bin_obj.object_id,
NAME = :h_bin_obj.name,
More information about the Greater-commits
mailing list