00001 <?php
00002
00003
00004
00005
00012 function pgsql_is_available() {
00013 return function_exists('pg_connect');
00014 }
00015
00022 function drupal_test_pgsql($url, &$success) {
00023 if (!pgsql_is_available()) {
00024 drupal_set_message(st('PHP PostgreSQL support not enabled.'), 'error');
00025 return FALSE;
00026 }
00027
00028 $url = parse_url($url);
00029 $conn_string = '';
00030
00031
00032 if (isset($url['user'])) {
00033 $conn_string .= ' user=' . urldecode($url['user']);
00034 }
00035 if (isset($url['pass'])) {
00036 $conn_string .= ' password=' . urldecode($url['pass']);
00037 }
00038 if (isset($url['host'])) {
00039 $conn_string .= ' host=' . urldecode($url['host']);
00040 }
00041 if (isset($url['path'])) {
00042 $conn_string .= ' dbname=' . substr(urldecode($url['path']), 1);
00043 }
00044 if (isset($url['port'])) {
00045 $conn_string .= ' port=' . urldecode($url['port']);
00046 }
00047
00048
00049 $connection = @pg_connect($conn_string);
00050 if (!$connection) {
00051 drupal_set_message(st('Failed to connect to your PostgreSQL database server. PostgreSQL reports the following message: %error.<ul><li>Are you sure you have the correct username and password?</li><li>Are you sure that you have typed the correct database hostname?</li><li>Are you sure that the database server is running?</li><li>Are you sure you typed the correct database name?</li></ul>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.', array('%error' => 'Connection failed. See log file for failure reason')), 'error');
00052 return FALSE;
00053 }
00054
00055 $success = array('CONNECT');
00056
00057
00058 $query = 'CREATE TABLE drupal_install_test (id integer NOT NULL)';
00059 $result = pg_query($connection, $query);
00060 if ($error = pg_result_error($result)) {
00061 drupal_set_message(st('Failed to create a test table on your PostgreSQL database server with the command %query. PostgreSQL reports the following message: %error.<ul><li>Are you sure the configured username has the necessary PostgreSQL permissions to create tables in the database?</li></ul>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.', array('%query' => $query, '%error' => $error)), 'error');
00062 return FALSE;
00063 }
00064 $err = FALSE;
00065 $success[] = 'SELECT';
00066 $success[] = 'CREATE';
00067
00068
00069 $query = 'INSERT INTO drupal_install_test (id) VALUES (1)';
00070 $result = pg_query($connection, $query);
00071 if ($error = pg_result_error($result)) {
00072 drupal_set_message(st('Failed to insert a value into a test table on your PostgreSQL database server. We tried inserting a value with the command %query and PostgreSQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error');
00073 $err = TRUE;
00074 }
00075 else {
00076 $success[] = 'INSERT';
00077 }
00078
00079
00080 $query = 'UPDATE drupal_install_test SET id = 2';
00081 $result = pg_query($connection, $query);
00082 if ($error = pg_result_error($result)) {
00083 drupal_set_message(st('Failed to update a value in a test table on your PostgreSQL database server. We tried updating a value with the command %query and PostgreSQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error');
00084 $err = TRUE;
00085 }
00086 else {
00087 $success[] = 'UPDATE';
00088 }
00089
00090
00091 $query = 'BEGIN; LOCK drupal_install_test IN SHARE ROW EXCLUSIVE MODE';
00092 $result = pg_query($connection, $query);
00093 if ($error = pg_result_error($result)) {
00094 drupal_set_message(st('Failed to lock a test table on your PostgreSQL database server. We tried locking a table with the command %query and PostgreSQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error');
00095 $err = TRUE;
00096 }
00097 else {
00098 $success[] = 'LOCK';
00099 }
00100
00101
00102 $query = 'COMMIT';
00103 $result = pg_query($connection, $query);
00104 if ($error = pg_result_error()) {
00105 drupal_set_message(st('Failed to unlock a test table on your PostgreSQL database server. We tried unlocking a table with the command %query and PostgreSQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error');
00106 $err = TRUE;
00107 }
00108 else {
00109 $success[] = 'UNLOCK';
00110 }
00111
00112
00113 $query = 'DELETE FROM drupal_install_test';
00114 $result = pg_query($connection, $query);
00115 if ($error = pg_result_error()) {
00116 drupal_set_message(st('Failed to delete a value from a test table on your PostgreSQL database server. We tried deleting a value with the command %query and PostgreSQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error');
00117 $err = TRUE;
00118 }
00119 else {
00120 $success[] = 'DELETE';
00121 }
00122
00123
00124 $query = 'DROP TABLE drupal_install_test';
00125 $result = pg_query($connection, $query);
00126 if ($error = pg_result_error()) {
00127 drupal_set_message(st('Failed to drop a test table from your PostgreSQL database server. We tried dropping a table with the command %query and PostgreSQL reported the following error %error.', array('%query' => $query, '%error' => $error)), 'error');
00128 $err = TRUE;
00129 }
00130 else {
00131 $success[] = 'DROP';
00132 }
00133
00134 if ($err) {
00135 return FALSE;
00136 }
00137
00138 pg_close($connection);
00139 return TRUE;
00140 }