| 15 | #define TEXTOID 25 |
| 16 | |
| 17 | static bool db_postgres_setup(struct db *db, bool create) |
| 18 | { |
| 19 | size_t prefix_len = strlen("postgres://"); |
| 20 | |
| 21 | /* We attempt to parse the connection string without the `postgres://` |
| 22 | prefix first, so we can correctly handle the key-value-pair style of |
| 23 | DSN that postgresql supports. If that fails we try with the full |
| 24 | string, which matches the `scheme://user:password@host:port/dbname` |
| 25 | style of DSNs. The call to `PQconninfoParse` here is just to verify |
| 26 | `PQconnectdb` would be able to parse it correctly, that's why the |
| 27 | result is discarded again immediately. */ |
| 28 | PQconninfoOption *info = |
| 29 | PQconninfoParse(db->filename + prefix_len, NULL); |
| 30 | |
| 31 | if (info != NULL) { |
| 32 | PQconninfoFree(info); |
| 33 | db->conn = PQconnectdb(db->filename + prefix_len); |
| 34 | } else { |
| 35 | db->conn = PQconnectdb(db->filename); |
| 36 | } |
| 37 | |
| 38 | if (PQstatus(db->conn) != CONNECTION_OK) { |
| 39 | db->error = tal_fmt(db, "Could not connect to %s: %s", db->filename, PQerrorMessage(db->conn)); |
| 40 | db->conn = NULL; |
| 41 | return false; |
| 42 | } |
| 43 | return true; |
| 44 | } |
| 45 | |
| 46 | static bool db_postgres_begin_tx(struct db *db) |
| 47 | { |
nothing calls this directly
no outgoing calls
no test coverage detected