| 203 | } |
| 204 | |
| 205 | bool |
| 206 | ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, |
| 207 | enum ECPGttype type, enum ECPGttype ind_type, |
| 208 | char *var, char *ind, long varcharsize, long offset, |
| 209 | long ind_offset, enum ARRAY_TYPE isarray, enum COMPAT_MODE compat, bool force_indicator) |
| 210 | { |
| 211 | struct sqlca_t *sqlca = ECPGget_sqlca(); |
| 212 | char *pval = (char *) PQgetvalue(results, act_tuple, act_field); |
| 213 | int binary = PQfformat(results, act_field); |
| 214 | int size = PQgetlength(results, act_tuple, act_field); |
| 215 | int value_for_indicator = 0; |
| 216 | long log_offset; |
| 217 | |
| 218 | if (sqlca == NULL) |
| 219 | { |
| 220 | ecpg_raise(lineno, ECPG_OUT_OF_MEMORY, |
| 221 | ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL); |
| 222 | return false; |
| 223 | } |
| 224 | |
| 225 | /* |
| 226 | * If we are running in a regression test, do not log the offset variable, |
| 227 | * it depends on the machine's alignment. |
| 228 | */ |
| 229 | if (ecpg_internal_regression_mode) |
| 230 | log_offset = -1; |
| 231 | else |
| 232 | log_offset = offset; |
| 233 | |
| 234 | ecpg_log("ecpg_get_data on line %d: RESULT: %s offset: %ld; array: %s\n", lineno, pval ? (binary ? "BINARY" : pval) : "EMPTY", log_offset, ECPG_IS_ARRAY(isarray) ? "yes" : "no"); |
| 235 | |
| 236 | /* pval is a pointer to the value */ |
| 237 | if (!pval) |
| 238 | { |
| 239 | /* |
| 240 | * This should never happen because we already checked that we found |
| 241 | * at least one tuple, but let's play it safe. |
| 242 | */ |
| 243 | ecpg_raise(lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL); |
| 244 | return false; |
| 245 | } |
| 246 | |
| 247 | /* We will have to decode the value */ |
| 248 | |
| 249 | /* |
| 250 | * check for null value and set indicator accordingly, i.e. -1 if NULL and |
| 251 | * 0 if not |
| 252 | */ |
| 253 | if (PQgetisnull(results, act_tuple, act_field)) |
| 254 | value_for_indicator = -1; |
| 255 | |
| 256 | switch (ind_type) |
| 257 | { |
| 258 | case ECPGt_short: |
| 259 | case ECPGt_unsigned_short: |
| 260 | *((short *) (ind + ind_offset * act_tuple)) = value_for_indicator; |
| 261 | break; |
| 262 | case ECPGt_int: |
no test coverage detected