summaryrefslogtreecommitdiff
path: root/ext/pdo_pgsql/tests/copy_from.phpt
diff options
context:
space:
mode:
Diffstat (limited to 'ext/pdo_pgsql/tests/copy_from.phpt')
-rw-r--r--ext/pdo_pgsql/tests/copy_from.phpt31
1 files changed, 21 insertions, 10 deletions
diff --git a/ext/pdo_pgsql/tests/copy_from.phpt b/ext/pdo_pgsql/tests/copy_from.phpt
index 10967b0fe9..de1140dfea 100644
--- a/ext/pdo_pgsql/tests/copy_from.phpt
+++ b/ext/pdo_pgsql/tests/copy_from.phpt
@@ -16,8 +16,6 @@ $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
$db->exec('CREATE TABLE test (a integer not null primary key, b text, c integer)');
-try {
-
echo "Preparing test file and array for CopyFrom tests\n";
$tableRows = array();
@@ -68,10 +66,13 @@ $db->rollback();
echo "Testing pgsqlCopyFromArray() with error\n";
$db->beginTransaction();
-var_dump($db->pgsqlCopyFromArray('test_error',$tableRowsWithDifferentNullValuesAndSelectedFields,";","NULL",'a,c'));
+try {
+ var_dump($db->pgsqlCopyFromArray('test_error',$tableRowsWithDifferentNullValuesAndSelectedFields,";","NULL",'a,c'));
+} catch (Exception $e) {
+ echo "Exception: {$e->getMessage()}\n";
+}
$db->rollback();
-
echo "Testing pgsqlCopyFromFile() with default parameters\n";
$db->beginTransaction();
var_dump($db->pgsqlCopyFromFile('test',$filename));
@@ -102,14 +103,21 @@ $db->rollback();
echo "Testing pgsqlCopyFromFile() with error\n";
$db->beginTransaction();
-var_dump($db->pgsqlCopyFromFile('test_error',$filenameWithDifferentNullValuesAndSelectedFields,";","NULL",'a,c'));
+try {
+ var_dump($db->pgsqlCopyFromFile('test_error',$filenameWithDifferentNullValuesAndSelectedFields,";","NULL",'a,c'));
+} catch (Exception $e) {
+ echo "Exception: {$e->getMessage()}\n";
+}
$db->rollback();
+echo "Testing pgsqlCopyFromFile() with non existing file\n";
+$db->beginTransaction();
+try {
+ var_dump($db->pgsqlCopyFromFile('test',"nonexisting/foo.csv",";","NULL",'a,c'));
} catch (Exception $e) {
- /* catch exceptions so that we can show the relative error */
- echo "Exception! at line ", $e->getLine(), "\n";
- var_dump($e->getMessage());
+ echo "Exception: {$e->getMessage()}\n";
}
+$db->rollback();
// Clean up
foreach (array($filename, $filenameWithDifferentNullValues, $filenameWithDifferentNullValuesAndSelectedFields) as $f) {
@@ -251,7 +259,7 @@ array(6) {
NULL
}
Testing pgsqlCopyFromArray() with error
-bool(false)
+Exception: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "test_error" does not exist
Testing pgsqlCopyFromFile() with default parameters
bool(true)
array(6) {
@@ -385,4 +393,7 @@ array(6) {
NULL
}
Testing pgsqlCopyFromFile() with error
-bool(false)
+Exception: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "test_error" does not exist
+Testing pgsqlCopyFromFile() with non existing file
+Exception: SQLSTATE[HY000]: General error: 7 Unable to open the file
+