* PQconnectStartParams * * Begins the establishment of a connection to a postgres backend through the * postmaster using connection information in a struct. * * See comment for PQconnectdbParams for the definition of the string format. * * Returns a PGconn*. If NULL is returned, a malloc error has occurred, and * you should not attempt to proceed with this connection. If the status * f
| 826 | * See PQconnectPoll for more info. |
| 827 | */ |
| 828 | PGconn * |
| 829 | PQconnectStartParams(const char *const *keywords, |
| 830 | const char *const *values, |
| 831 | int expand_dbname) |
| 832 | { |
| 833 | PGconn *conn; |
| 834 | PQconninfoOption *connOptions; |
| 835 | |
| 836 | /* |
| 837 | * Allocate memory for the conn structure. Note that we also expect this |
| 838 | * to initialize conn->errorMessage to empty. All subsequent steps during |
| 839 | * connection initialization will only append to that buffer. |
| 840 | */ |
| 841 | conn = makeEmptyPGconn(); |
| 842 | if (conn == NULL) |
| 843 | return NULL; |
| 844 | |
| 845 | /* |
| 846 | * Parse the conninfo arrays |
| 847 | */ |
| 848 | connOptions = conninfo_array_parse(keywords, values, |
| 849 | &conn->errorMessage, |
| 850 | true, expand_dbname); |
| 851 | if (connOptions == NULL) |
| 852 | { |
| 853 | conn->status = CONNECTION_BAD; |
| 854 | /* errorMessage is already set */ |
| 855 | return conn; |
| 856 | } |
| 857 | |
| 858 | /* |
| 859 | * Move option values into conn structure |
| 860 | */ |
| 861 | if (!fillPGconn(conn, connOptions)) |
| 862 | { |
| 863 | PQconninfoFree(connOptions); |
| 864 | return conn; |
| 865 | } |
| 866 | |
| 867 | /* |
| 868 | * Free the option info - all is in conn now |
| 869 | */ |
| 870 | PQconninfoFree(connOptions); |
| 871 | |
| 872 | /* |
| 873 | * Compute derived options |
| 874 | */ |
| 875 | if (!connectOptions2(conn)) |
| 876 | return conn; |
| 877 | |
| 878 | /* |
| 879 | * Connect to the database |
| 880 | */ |
| 881 | if (!connectDBStart(conn)) |
| 882 | { |
| 883 | /* Just in case we failed to set it in connectDBStart */ |
| 884 | conn->status = CONNECTION_BAD; |
| 885 | } |
no test coverage detected