src/server/plugins/postgresql/config.c

branch
webdav
changeset 374
77506ec632a4
parent 373
f78a585e1a2f
child 376
61d481d3c2e4
equal deleted inserted replaced
373:f78a585e1a2f 374:77506ec632a4
46 46
47 // Uses a PGconn to lookup the resource id of the specified root node 47 // Uses a PGconn to lookup the resource id of the specified root node
48 // if the lookup succeeds, the resource id is written to rootid 48 // if the lookup succeeds, the resource id is written to rootid
49 // in case of an error, an error message will be logged 49 // in case of an error, an error message will be logged
50 // returns: 0 success, 1 error 50 // returns: 0 success, 1 error
51 static int pg_lookup_root(ResourceData *res, scstr_t rootnode, int64_t *rootid) { 51 int pg_lookup_root(ResourceData *res, const char *rootnode, int64_t *rootid) {
52 PGconn *connection = res->data; 52 PGconn *connection = res->data;
53 53
54 PGresult *result = PQexecParams( 54 PGresult *result = PQexecParams(
55 connection, 55 connection,
56 sql_get_repository_root, 56 sql_get_repository_root,
57 1, // number of parameters 57 1, // number of parameters
58 NULL, 58 NULL,
59 &rootnode.ptr, // parameter value 59 &rootnode, // parameter value
60 NULL, 60 NULL,
61 NULL, 61 NULL,
62 0); // 0: result in text format 62 0); // 0: result in text format
63 63
64 if(!result) { 64 if(!result) {
71 int nrows = PQntuples(result); 71 int nrows = PQntuples(result);
72 if(nrows == 1) { 72 if(nrows == 1) {
73 char *resource_id_str = PQgetvalue(result, 0, 0); 73 char *resource_id_str = PQgetvalue(result, 0, 0);
74 if(resource_id_str) { 74 if(resource_id_str) {
75 if(!util_strtoint(resource_id_str, rootid)) { 75 if(!util_strtoint(resource_id_str, rootid)) {
76 log_ereport(LOG_FAILURE, "pg: unexpected result for column resource_id", rootnode.ptr); 76 log_ereport(LOG_FAILURE, "pg: unexpected result for column resource_id", rootnode);
77 ret = 1; 77 ret = 1;
78 } 78 }
79 } 79 }
80 } else { 80 } else {
81 log_ereport(LOG_FAILURE, "pg: cannot find root resource '%s'", rootnode.ptr); 81 log_ereport(LOG_FAILURE, "pg: cannot find root resource '%s'", rootnode);
82 ret = 1; 82 ret = 1;
83 } 83 }
84 PQclear(result); 84 PQclear(result);
85 85
86 return ret; 86 return ret;
126 if(!res) { 126 if(!res) {
127 log_ereport(LOG_MISCONFIG, "pg_init_repo: resource lookup failed"); 127 log_ereport(LOG_MISCONFIG, "pg_init_repo: resource lookup failed");
128 return NULL; 128 return NULL;
129 } 129 }
130 // do lookup, if successful, root_id will be set 130 // do lookup, if successful, root_id will be set
131 int lookup_err = pg_lookup_root(res, cfg_rootnode, &root_id); 131 int lookup_err = pg_lookup_root(res, cfg_rootnode.ptr, &root_id);
132 // we don't need the connection anymore 132 // we don't need the connection anymore
133 resourcepool_free(NULL, NULL, res); 133 resourcepool_free(NULL, NULL, res);
134 if(lookup_err) { 134 if(lookup_err) {
135 // no logging required, pg_lookup_root will log the error 135 // no logging required, pg_lookup_root will log the error
136 return NULL; 136 return NULL;

mercurial