|  | 
| 44 | 44 |  *			or a ! if session is not connected to a database; | 
| 45 | 45 |  *		in prompt2 -, *, ', or "; | 
| 46 | 46 |  *		in prompt3 nothing | 
|  | 47 | + * %i - displays "read-only" if in hot standby, or if default_transaction_read_only | 
|  | 48 | + *     	or transaction_read_only are on, "read/write" otherwise. | 
| 47 | 49 |  * %x - transaction status: empty, *, !, ? (unknown or no connection) | 
| 48 | 50 |  * %l - The line number inside the current statement, starting from 1. | 
| 49 | 51 |  * %? - the error code of the last query (not yet implemented) | 
| @@ -258,7 +260,39 @@ get_prompt(promptStatus_t status, ConditionalStack cstack) | 
| 258 | 260 | 							break; | 
| 259 | 261 | 					} | 
| 260 | 262 | 					break; | 
|  | 263 | +				case 'i': | 
|  | 264 | +					if (pset.db) | 
|  | 265 | +					{ | 
|  | 266 | +						const char *hs = PQparameterStatus(pset.db, "in_hot_standby"); | 
|  | 267 | +						const char *ro = PQparameterStatus(pset.db, "default_transaction_read_only"); | 
|  | 268 | + | 
|  | 269 | +						if (!hs || !ro) | 
|  | 270 | +							strlcpy(buf, _("unknown"), sizeof(buf)); | 
|  | 271 | +						else if (strcmp(hs, "on") == 0 || strcmp(ro, "on") == 0) | 
|  | 272 | +							strlcpy(buf, _("read-only"), sizeof(buf)); | 
|  | 273 | +						else | 
|  | 274 | +						{ | 
|  | 275 | +							const char *tr = NULL; | 
|  | 276 | +							PGresult   *res; | 
|  | 277 | + | 
|  | 278 | +							res = PQexec(pset.db, "SHOW transaction_read_only"); | 
|  | 279 | +							if (PQresultStatus(res) == PGRES_TUPLES_OK && | 
|  | 280 | +								PQntuples(res) == 1) | 
|  | 281 | +								tr = PQgetvalue(res, 0, 0); | 
|  | 282 | + | 
|  | 283 | +							if (!tr) | 
|  | 284 | +								strlcpy(buf, _("unknown"), sizeof(buf)); | 
|  | 285 | +							else if (strcmp(tr, "on") == 0) | 
|  | 286 | +								strlcpy(buf, _("read-only"), sizeof(buf)); | 
|  | 287 | +							else | 
|  | 288 | +								strlcpy(buf, _("read/write"), sizeof(buf)); | 
| 261 | 289 | 
 | 
|  | 290 | +							PQclear(res); | 
|  | 291 | +						} | 
|  | 292 | +					} | 
|  | 293 | +					else | 
|  | 294 | +						buf[0] = '\0'; | 
|  | 295 | +					break; | 
| 262 | 296 | 				case 'x': | 
| 263 | 297 | 					if (!pset.db) | 
| 264 | 298 | 						buf[0] = '?'; | 
|  | 
0 commit comments