1195 |
1195 |
1196 char resource_id_str[32]; |
1196 char resource_id_str[32]; |
1197 snprintf(resource_id_str, 32, "%" PRId64, proppatch->resource_id); |
1197 snprintf(resource_id_str, 32, "%" PRId64, proppatch->resource_id); |
1198 params[0] = resource_id_str; |
1198 params[0] = resource_id_str; |
1199 |
1199 |
1200 printf("insert\n\n"); |
|
1201 printf("arg0: %s\narg1: %s\n", params[0], params[1]); |
|
1202 printf("%s\n\n", sql->space); |
|
1203 |
|
1204 |
|
1205 PGresult *result = PQexecParams( |
1200 PGresult *result = PQexecParams( |
1206 pgdav->connection, |
1201 pgdav->connection, |
1207 sql->space, |
1202 sql->space, |
1208 nparam, // number of parameters |
1203 nparam, // number of parameters |
1209 NULL, |
1204 NULL, |
1216 |
1211 |
1217 int ret = 1; |
1212 int ret = 1; |
1218 if(PQresultStatus(result) == PGRES_COMMAND_OK) { |
1213 if(PQresultStatus(result) == PGRES_COMMAND_OK) { |
1219 // command ok, check if any row was updated |
1214 // command ok, check if any row was updated |
1220 char *nrows_affected = PQcmdTuples(result); |
1215 char *nrows_affected = PQcmdTuples(result); |
1221 printf("insert nrows: %s\n", nrows_affected); |
|
1222 if(nrows_affected[0] == '1') { |
1216 if(nrows_affected[0] == '1') { |
1223 ret = 0; |
1217 ret = 0; |
1224 } else { |
1218 } else { |
1225 log_ereport(LOG_FAILURE, "pg: extension row insert failed"); |
1219 log_ereport(LOG_FAILURE, "pg: extension row insert failed"); |
1226 } |
1220 } |
1249 } |
1243 } |
1250 |
1244 |
1251 char resource_id_str[32]; |
1245 char resource_id_str[32]; |
1252 snprintf(resource_id_str, 32, "%" PRId64, proppatch->resource_id); |
1246 snprintf(resource_id_str, 32, "%" PRId64, proppatch->resource_id); |
1253 params[0] = resource_id_str; |
1247 params[0] = resource_id_str; |
1254 |
|
1255 printf("update\n"); |
|
1256 |
1248 |
1257 PGresult *result = PQexecParams( |
1249 PGresult *result = PQexecParams( |
1258 pgdav->connection, |
1250 pgdav->connection, |
1259 sql->space, |
1251 sql->space, |
1260 nparam, // number of parameters |
1252 nparam, // number of parameters |
1268 |
1260 |
1269 int ret = 1; |
1261 int ret = 1; |
1270 if(PQresultStatus(result) == PGRES_COMMAND_OK) { |
1262 if(PQresultStatus(result) == PGRES_COMMAND_OK) { |
1271 // command ok, check if any row was updated |
1263 // command ok, check if any row was updated |
1272 char *nrows_affected = PQcmdTuples(result); |
1264 char *nrows_affected = PQcmdTuples(result); |
1273 printf("nrows: %s\n", nrows_affected); |
|
1274 if(nrows_affected[0] == '1') { |
1265 if(nrows_affected[0] == '1') { |
1275 ret = 0; |
1266 ret = 0; |
1276 } else if(nrows_affected[0] == '0') { |
1267 } else if(nrows_affected[0] == '0') { |
1277 // no rows affected, that means we have to insert a new row |
1268 // no rows affected, that means we have to insert a new row |
1278 // in the extension table for this resource |
1269 // in the extension table for this resource |