diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..83a3edd --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# phpize stuff +.libs +Makefile* +*.m4 +autom4te.cache +build +config.* +configure* +ibm_db2.la +ibm_db2.lo +install-sh +libtool +ltmain.sh +missing +mkinstalldirs +modules +run-tests.php +tmp-php.ini + +# phpt generated files +tests/*.diff +tests/*.exp +tests/*.log +tests/*.out +tests/*.sh +tests/*.php + +# downloaded cli driver +clidriver + diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..cdaab11 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,43 @@ +language: php + +php: + - '7.2' + - '7.1' + - '7.0' + - '5.6' + +install: +- curl https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/linuxx64_odbc_cli.tar.gz | tar -xz +- docker pull ibmcom/db2express-c +- docker run --name db2 -p 60000:50000 -e DB2INST1_PASSWORD=password -e LICENSE=accept -d ibmcom/db2express-c db2start +- docker ps -as +- docker exec -it db2 su - db2inst1 -c "db2 create db sample" + +before_script: +# Ensure that DB2CLIINIPATH gets passed to the tests +- echo 'variables_order = "EGPCS"' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini + +script: +- phpize +- ./configure --with-IBM_DB2=$PWD/clidriver +- make +- | + cat < db2cli.ini + [SAMPLE] + Hostname=localhost + Protocol=TCPIP + Port=60000 + Database=sample + EOF +- cat db2cli.ini +# Ensure that tests are not skipped (false positive) due to bad configuration +- export IBM_DB2_TEST_SKIP_CONNECT_FAILURE=0 +# Ensure CLI can find the configuration +- export DB2CLIINIPATH=$PWD +# Ensure make returns non-zero when a test fails +- export REPORT_EXIT_STATUS=1 +# Save the report so we can print it if a test fails +- make test TESTS='-s report.txt' + +after_failure: +- cat report.txt diff --git a/ibm_db2.c b/ibm_db2.c index 362f8d7..6b12b96 100644 --- a/ibm_db2.c +++ b/ibm_db2.c @@ -538,7 +538,6 @@ static void _php_db2_set_symbol(char * varname, zval *var TSRMLS_DC) } zval_ptr_dtor(*bind_data); ZVAL_COPY_VALUE(*bind_data, var); - efree(var); /* 1.9.9-zs7 */ #else ZEND_SET_SYMBOL(symbol_table_used, varname, var); #endif @@ -5289,6 +5288,11 @@ PHP_FUNCTION(db2_execute) tmp_curr->value->value.lval = (long)tmp_curr->long_value; } _php_db2_set_symbol(tmp_curr->varname, tmp_curr->value TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + efree(tmp_curr->value); /* 1.9.9-zs7 */ + tmp_curr->value = NULL; +#endif + default: break; } diff --git a/tests/connection.inc b/tests/connection.inc index acddd0a..d043a61 100644 --- a/tests/connection.inc +++ b/tests/connection.inc @@ -39,9 +39,19 @@ else { date_default_timezone_set('UTC'); +$skip_on_connect_failure = getenv("IBM_DB2_TEST_SKIP_CONNECT_FAILURE") !== FALSE ? + getenv("IBM_DB2_TEST_SKIP_CONNECT_FAILURE") : true; + + // test connection ok $prepconn = db2_connect($database, $user, $password); -if (!$prepconn) die('skip'); -db2_close($prepconn); +if (!$prepconn) { + if($skip_on_connect_failure) die("skip - Couldn't connect"); +} +else { + db2_close($prepconn); +} + +unset($skip_on_connect_failure); ?> diff --git a/tests/escape.dat b/tests/escape.dat index 3de8098..110ffdb 100644 --- a/tests/escape.dat +++ b/tests/escape.dat @@ -1,10 +1,8 @@ Original: Some random special characters: - , - , \ , ' , " . + , , \ , ' , " . db2_escape_string: Some random special characters: - , - , \ , ' , " . + , , \ , ' , " . Original: Backslash (\). Single quote ('). Double quote (") db2_escape_string: Backslash (\). Single quote ('). Double quote (") diff --git a/tests/test_001_ConnDb.phpt b/tests/test_001_ConnDb.phpt index 8d6bac3..10db2df 100644 --- a/tests/test_001_ConnDb.phpt +++ b/tests/test_001_ConnDb.phpt @@ -13,7 +13,7 @@ if ($conn) { db2_close($conn); } else { - echo "Connection failed."; + echo "Connection failed: " . db2_conn_errormsg(); } ?> diff --git a/tests/test_045_FetchArrayBinaryData.phpt b/tests/test_045_FetchArrayBinaryData.phpt index 1d4a6c5..8e94456 100644 --- a/tests/test_045_FetchArrayBinaryData.phpt +++ b/tests/test_045_FetchArrayBinaryData.phpt @@ -9,19 +9,17 @@ require_once('connection.inc'); $conn = db2_connect($db,$username,$password); -$orig = fopen("pic1.jpg", "rb"); -$new = fopen("pic1_out.jpg", "wb"); +$in_file = "pic1.jpg"; +$in = file_get_contents(dirname(__FILE__)."/".$in_file); $result = db2_exec($conn, "select photo_format, picture, length(picture) from emp_photo where photo_format='jpg' and empno='000130'"); $row = db2_fetch_array($result); +$out = ""; if ($row) { - fwrite($new, $row[1]); + $out .= $row[1]; } -$file0 = file_get_contents("pic1.jpg"); -$file1 = file_get_contents("pic1_out.jpg"); - -if(strcmp($file0, $file1) == 0) { +if(strcmp($in, $out) == 0) { echo "The files are the same...good."; } else { echo "The files are not the same...bad."; @@ -37,4 +35,4 @@ echo "\nIterated over $count rows."; ?> --EXPECT-- The files are the same...good. -Iterated over 8 rows. \ No newline at end of file +Iterated over 8 rows. diff --git a/tests/test_048_FetchArrayBinaryData.phpt b/tests/test_048_FetchArrayBinaryData.phpt index 8256c03..c040f48 100644 --- a/tests/test_048_FetchArrayBinaryData.phpt +++ b/tests/test_048_FetchArrayBinaryData.phpt @@ -9,19 +9,17 @@ require_once('connection.inc'); $conn = db2_connect($db,$username,$password); -$orig = fopen("spook.png", "rb"); -$new = fopen("spook_out.png", "wb"); +$in_file = "spook.png"; +$in = file_get_contents(dirname(__FILE__)."/".$in_file); $result = db2_exec($conn, "SELECT picture, LENGTH(picture) FROM animal_pics WHERE name = 'Spook'"); $row = db2_fetch_array($result); +$out = ""; if ($row) { - fwrite($new, $row[0]); + $out .= $row[0]; } -$file0 = file_get_contents("spook.png"); -$file1 = file_get_contents("spook_out.png"); - -if(strcmp($file0, $file1) == 0) { +if(strcmp($in, $out) == 0) { echo "The files are the same...good."; } else { echo "The files are not the same...bad."; diff --git a/tests/test_080_ConnWrongDbAlias.phpt b/tests/test_080_ConnWrongDbAlias.phpt index 72dc924..336b828 100644 --- a/tests/test_080_ConnWrongDbAlias.phpt +++ b/tests/test_080_ConnWrongDbAlias.phpt @@ -13,10 +13,9 @@ if ($conn) { echo "??? No way.\n"; } else { - $err = db2_conn_error(); - echo $err."\n"; + echo var_dump(db2_conn_error()); } ?> --EXPECTF-- -0800%d +string(5) "%s" diff --git a/tests/test_090_ConnmsgWrongDbAlias.phpt b/tests/test_090_ConnmsgWrongDbAlias.phpt index e9fc479..a260991 100644 --- a/tests/test_090_ConnmsgWrongDbAlias.phpt +++ b/tests/test_090_ConnmsgWrongDbAlias.phpt @@ -19,4 +19,4 @@ else { ?> --EXPECTF-- -[IBM][CLI Driver] %s SQLSTATE=%d SQLCODE=-%d +[IBM][CLI Driver] %s SQLCODE=-%d diff --git a/tests/test_10353_MemLeak.phpt b/tests/test_10353_MemLeak.phpt index 45ae906..910dc87 100644 --- a/tests/test_10353_MemLeak.phpt +++ b/tests/test_10353_MemLeak.phpt @@ -3,6 +3,7 @@ IBM-DB2: PECL bug 10353 -- Memory leak testing --SKIPIF-- --FILE-- +=') && + version_compare(PHP_VERSION, '7.2', '<')) { + die("skip: Test fails on PHP 7.1 with ZTS (https://bugs.php.net/bug.php?id=77547)"); +} +?> --FILE-- +--XFAIL-- +SQLGetData as a CLOB locator returns conversion error for some reason. Probably a bug, but it predates the CI --EXPECT-- col 0: type:string xml value:[] false? col 1: type:string clob value:[a clob] false?