| 73 | /************************************************************************/ |
| 74 | |
| 75 | int msPOSTGRESQLJoinConnect(layerObj *layer, joinObj *join) { |
| 76 | char *maskeddata, *temp, *sql, *column; |
| 77 | char *conn_decrypted; |
| 78 | int i, count, test; |
| 79 | PGresult *query_result; |
| 80 | msPOSTGRESQLJoinInfo *joininfo; |
| 81 | |
| 82 | if(join->joininfo) |
| 83 | return MS_SUCCESS; |
| 84 | |
| 85 | joininfo = (msPOSTGRESQLJoinInfo *)malloc(sizeof(msPOSTGRESQLJoinInfo)); |
| 86 | if(!joininfo) { |
| 87 | msSetError(MS_MEMERR, "Error allocating join info struct.", |
| 88 | "msPOSTGRESQLJoinConnect()"); |
| 89 | return MS_FAILURE; |
| 90 | } |
| 91 | joininfo->conn = NULL; |
| 92 | joininfo->row_num = 0; |
| 93 | joininfo->query_result = NULL; |
| 94 | joininfo->from_index = 0; |
| 95 | joininfo->to_column = join->to; |
| 96 | joininfo->from_value = NULL; |
| 97 | joininfo->layer_debug = layer->debug; |
| 98 | join->joininfo = joininfo; |
| 99 | |
| 100 | /* |
| 101 | * We need three things at a minimum, the connection string, a table |
| 102 | * name, and a column to join on. |
| 103 | */ |
| 104 | if(!join->connection) { |
| 105 | msSetError(MS_QUERYERR, "No connection information provided.", |
| 106 | "MSPOSTGRESQLJoinConnect()"); |
| 107 | return MS_FAILURE; |
| 108 | } |
| 109 | if(!join->table) { |
| 110 | msSetError(MS_QUERYERR, "No join table name found.", |
| 111 | "msPOSTGRESQLJoinConnect()"); |
| 112 | return MS_FAILURE; |
| 113 | } |
| 114 | if(!joininfo->to_column) { |
| 115 | msSetError(MS_QUERYERR, "No join to column name found.", |
| 116 | "msPOSTGRESQLJoinConnect()"); |
| 117 | return MS_FAILURE; |
| 118 | } |
| 119 | |
| 120 | /* Establish database connection */ |
| 121 | conn_decrypted = msDecryptStringTokens(layer->map, join->connection); |
| 122 | if (conn_decrypted != NULL) { |
| 123 | joininfo->conn = PQconnectdb(conn_decrypted); |
| 124 | free(conn_decrypted); |
| 125 | } |
| 126 | if(!joininfo->conn || PQstatus(joininfo->conn) == CONNECTION_BAD) { |
| 127 | maskeddata = (char *)malloc(strlen(layer->connection) + 1); |
| 128 | strcpy(maskeddata, join->connection); |
| 129 | temp = strstr(maskeddata, "password="); |
| 130 | if(!temp) { |
| 131 | temp = (char *)(temp + 9); |
| 132 | count = (int)(strstr(temp, " ") - temp); |
no test coverage detected