mirror of
https://github.com/php/php-src.git
synced 2026-04-13 11:02:55 +02:00
This patch adds missing newlines, trims multiple redundant final newlines into a single one, and trims redundant leading newlines in all *.phpt sections. According to POSIX, a line is a sequence of zero or more non-' <newline>' characters plus a terminating '<newline>' character. [1] Files should normally have at least one final newline character. C89 [2] and later standards [3] mention a final newline: "A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character." Although it is not mandatory for all files to have a final newline fixed, a more consistent and homogeneous approach brings less of commit differences issues and a better development experience in certain text editors and IDEs. [1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206 [2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2 [3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
399 lines
7.6 KiB
PHP
399 lines
7.6 KiB
PHP
--TEST--
|
|
PDO PgSQL pgsqlCopyFromArray and pgsqlCopyFromFile
|
|
--SKIPIF--
|
|
<?php # vim:se ft=php:
|
|
if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
|
|
require dirname(__FILE__) . '/config.inc';
|
|
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
|
|
PDOTest::skip();
|
|
?>
|
|
--FILE--
|
|
<?php
|
|
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
|
|
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
|
|
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
|
|
|
|
$db->exec('CREATE TABLE test (a integer not null primary key, b text, c integer)');
|
|
|
|
echo "Preparing test file and array for CopyFrom tests\n";
|
|
|
|
$tableRows = array();
|
|
$tableRowsWithDifferentNullValues = array();
|
|
|
|
for($i=0;$i<3;$i++) {
|
|
$firstParameter = $i;
|
|
$secondParameter = "test insert {$i}";
|
|
$tableRows[] = "{$firstParameter}\t{$secondParameter}\t\\N";
|
|
$tableRowsWithDifferentNullValues[] = "{$firstParameter};{$secondParameter};NULL";
|
|
$tableRowsWithDifferentNullValuesAndSelectedFields[] = "{$firstParameter};NULL";
|
|
}
|
|
$filename = 'test_pgsqlCopyFromFile.csv';
|
|
$filenameWithDifferentNullValues = 'test_pgsqlCopyFromFileWithDifferentNullValues.csv';
|
|
$filenameWithDifferentNullValuesAndSelectedFields = 'test_pgsqlCopyFromFileWithDifferentNullValuesAndSelectedFields.csv';
|
|
|
|
file_put_contents($filename, implode("\n",$tableRows));
|
|
file_put_contents($filenameWithDifferentNullValues, implode("\n",$tableRowsWithDifferentNullValues));
|
|
file_put_contents($filenameWithDifferentNullValuesAndSelectedFields, implode("\n",$tableRowsWithDifferentNullValuesAndSelectedFields));
|
|
|
|
echo "Testing pgsqlCopyFromArray() with default parameters\n";
|
|
$db->beginTransaction();
|
|
var_dump($db->pgsqlCopyFromArray('test',$tableRows));
|
|
|
|
$stmt = $db->query("select * from test");
|
|
foreach($stmt as $r) {
|
|
var_dump($r);
|
|
}
|
|
$db->rollback();
|
|
|
|
echo "Testing pgsqlCopyFromArray() with different field separator and not null indicator\n";
|
|
$db->beginTransaction();
|
|
var_dump($db->pgsqlCopyFromArray('test',$tableRowsWithDifferentNullValues,";","NULL"));
|
|
$stmt = $db->query("select * from test");
|
|
foreach($stmt as $r) {
|
|
var_dump($r);
|
|
}
|
|
$db->rollback();
|
|
|
|
echo "Testing pgsqlCopyFromArray() with only selected fields\n";
|
|
$db->beginTransaction();
|
|
var_dump($db->pgsqlCopyFromArray('test',$tableRowsWithDifferentNullValuesAndSelectedFields,";","NULL",'a,c'));
|
|
$stmt = $db->query("select * from test");
|
|
foreach($stmt as $r) {
|
|
var_dump($r);
|
|
}
|
|
$db->rollback();
|
|
|
|
echo "Testing pgsqlCopyFromArray() with error\n";
|
|
$db->beginTransaction();
|
|
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));
|
|
|
|
$stmt = $db->query("select * from test");
|
|
foreach($stmt as $r) {
|
|
var_dump($r);
|
|
}
|
|
$db->rollback();
|
|
|
|
echo "Testing pgsqlCopyFromFile() with different field separator and not null indicator\n";
|
|
$db->beginTransaction();
|
|
var_dump($db->pgsqlCopyFromFile('test',$filenameWithDifferentNullValues,";","NULL"));
|
|
$stmt = $db->query("select * from test");
|
|
foreach($stmt as $r) {
|
|
var_dump($r);
|
|
}
|
|
$db->rollback();
|
|
|
|
echo "Testing pgsqlCopyFromFile() with only selected fields\n";
|
|
$db->beginTransaction();
|
|
var_dump($db->pgsqlCopyFromFile('test',$filenameWithDifferentNullValuesAndSelectedFields,";","NULL",'a,c'));
|
|
$stmt = $db->query("select * from test");
|
|
foreach($stmt as $r) {
|
|
var_dump($r);
|
|
}
|
|
$db->rollback();
|
|
|
|
echo "Testing pgsqlCopyFromFile() with error\n";
|
|
$db->beginTransaction();
|
|
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) {
|
|
echo "Exception: {$e->getMessage()}\n";
|
|
}
|
|
$db->rollback();
|
|
|
|
// Clean up
|
|
foreach (array($filename, $filenameWithDifferentNullValues, $filenameWithDifferentNullValuesAndSelectedFields) as $f) {
|
|
@unlink($f);
|
|
}
|
|
?>
|
|
--EXPECTF--
|
|
Preparing test file and array for CopyFrom tests
|
|
Testing pgsqlCopyFromArray() with default parameters
|
|
bool(true)
|
|
array(6) {
|
|
["a"]=>
|
|
int(0)
|
|
[0]=>
|
|
int(0)
|
|
["b"]=>
|
|
string(13) "test insert 0"
|
|
[1]=>
|
|
string(13) "test insert 0"
|
|
["c"]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
}
|
|
array(6) {
|
|
["a"]=>
|
|
int(1)
|
|
[0]=>
|
|
int(1)
|
|
["b"]=>
|
|
string(13) "test insert 1"
|
|
[1]=>
|
|
string(13) "test insert 1"
|
|
["c"]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
}
|
|
array(6) {
|
|
["a"]=>
|
|
int(2)
|
|
[0]=>
|
|
int(2)
|
|
["b"]=>
|
|
string(13) "test insert 2"
|
|
[1]=>
|
|
string(13) "test insert 2"
|
|
["c"]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
}
|
|
Testing pgsqlCopyFromArray() with different field separator and not null indicator
|
|
bool(true)
|
|
array(6) {
|
|
["a"]=>
|
|
int(0)
|
|
[0]=>
|
|
int(0)
|
|
["b"]=>
|
|
string(13) "test insert 0"
|
|
[1]=>
|
|
string(13) "test insert 0"
|
|
["c"]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
}
|
|
array(6) {
|
|
["a"]=>
|
|
int(1)
|
|
[0]=>
|
|
int(1)
|
|
["b"]=>
|
|
string(13) "test insert 1"
|
|
[1]=>
|
|
string(13) "test insert 1"
|
|
["c"]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
}
|
|
array(6) {
|
|
["a"]=>
|
|
int(2)
|
|
[0]=>
|
|
int(2)
|
|
["b"]=>
|
|
string(13) "test insert 2"
|
|
[1]=>
|
|
string(13) "test insert 2"
|
|
["c"]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
}
|
|
Testing pgsqlCopyFromArray() with only selected fields
|
|
bool(true)
|
|
array(6) {
|
|
["a"]=>
|
|
int(0)
|
|
[0]=>
|
|
int(0)
|
|
["b"]=>
|
|
NULL
|
|
[1]=>
|
|
NULL
|
|
["c"]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
}
|
|
array(6) {
|
|
["a"]=>
|
|
int(1)
|
|
[0]=>
|
|
int(1)
|
|
["b"]=>
|
|
NULL
|
|
[1]=>
|
|
NULL
|
|
["c"]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
}
|
|
array(6) {
|
|
["a"]=>
|
|
int(2)
|
|
[0]=>
|
|
int(2)
|
|
["b"]=>
|
|
NULL
|
|
[1]=>
|
|
NULL
|
|
["c"]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
}
|
|
Testing pgsqlCopyFromArray() with error
|
|
Exception: SQLSTATE[42P01]: Undefined table: 7 %s: %s "test_error" %s
|
|
Testing pgsqlCopyFromFile() with default parameters
|
|
bool(true)
|
|
array(6) {
|
|
["a"]=>
|
|
int(0)
|
|
[0]=>
|
|
int(0)
|
|
["b"]=>
|
|
string(13) "test insert 0"
|
|
[1]=>
|
|
string(13) "test insert 0"
|
|
["c"]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
}
|
|
array(6) {
|
|
["a"]=>
|
|
int(1)
|
|
[0]=>
|
|
int(1)
|
|
["b"]=>
|
|
string(13) "test insert 1"
|
|
[1]=>
|
|
string(13) "test insert 1"
|
|
["c"]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
}
|
|
array(6) {
|
|
["a"]=>
|
|
int(2)
|
|
[0]=>
|
|
int(2)
|
|
["b"]=>
|
|
string(13) "test insert 2"
|
|
[1]=>
|
|
string(13) "test insert 2"
|
|
["c"]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
}
|
|
Testing pgsqlCopyFromFile() with different field separator and not null indicator
|
|
bool(true)
|
|
array(6) {
|
|
["a"]=>
|
|
int(0)
|
|
[0]=>
|
|
int(0)
|
|
["b"]=>
|
|
string(13) "test insert 0"
|
|
[1]=>
|
|
string(13) "test insert 0"
|
|
["c"]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
}
|
|
array(6) {
|
|
["a"]=>
|
|
int(1)
|
|
[0]=>
|
|
int(1)
|
|
["b"]=>
|
|
string(13) "test insert 1"
|
|
[1]=>
|
|
string(13) "test insert 1"
|
|
["c"]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
}
|
|
array(6) {
|
|
["a"]=>
|
|
int(2)
|
|
[0]=>
|
|
int(2)
|
|
["b"]=>
|
|
string(13) "test insert 2"
|
|
[1]=>
|
|
string(13) "test insert 2"
|
|
["c"]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
}
|
|
Testing pgsqlCopyFromFile() with only selected fields
|
|
bool(true)
|
|
array(6) {
|
|
["a"]=>
|
|
int(0)
|
|
[0]=>
|
|
int(0)
|
|
["b"]=>
|
|
NULL
|
|
[1]=>
|
|
NULL
|
|
["c"]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
}
|
|
array(6) {
|
|
["a"]=>
|
|
int(1)
|
|
[0]=>
|
|
int(1)
|
|
["b"]=>
|
|
NULL
|
|
[1]=>
|
|
NULL
|
|
["c"]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
}
|
|
array(6) {
|
|
["a"]=>
|
|
int(2)
|
|
[0]=>
|
|
int(2)
|
|
["b"]=>
|
|
NULL
|
|
[1]=>
|
|
NULL
|
|
["c"]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
}
|
|
Testing pgsqlCopyFromFile() with error
|
|
Exception: SQLSTATE[42P01]: Undefined table: 7 %s: %s "test_error" %s
|
|
Testing pgsqlCopyFromFile() with non existing file
|
|
Exception: SQLSTATE[HY000]: General error: 7 Unable to open the file
|