diff options
| author | Scott MacVicar <scottmac@php.net> | 2008-07-25 02:44:59 +0000 |
|---|---|---|
| committer | Scott MacVicar <scottmac@php.net> | 2008-07-25 02:44:59 +0000 |
| commit | d584ed4a0165ff9aee12d8d96e7a8ce697bbafea (patch) | |
| tree | 2e0c1e15a8063b9ddb8e9dafc7b8351b8d03089b /ext/sqlite3/tests | |
| parent | 14ce4a1d0a86efb61a13821ee90b5f124af13fff (diff) | |
| download | php-git-d584ed4a0165ff9aee12d8d96e7a8ce697bbafea.tar.gz | |
SQLite3 extension, still has 2 failing tests that will be sorted tomorrow. Will merge to head tomorrow as well.
Diffstat (limited to 'ext/sqlite3/tests')
31 files changed, 1334 insertions, 0 deletions
diff --git a/ext/sqlite3/tests/new_db.inc b/ext/sqlite3/tests/new_db.inc new file mode 100644 index 0000000000..068d7ba692 --- /dev/null +++ b/ext/sqlite3/tests/new_db.inc @@ -0,0 +1,5 @@ +<?php + +$db = new SQLite3(':memory:'); + +?> diff --git a/ext/sqlite3/tests/skipif.inc b/ext/sqlite3/tests/skipif.inc new file mode 100644 index 0000000000..c5dd877a88 --- /dev/null +++ b/ext/sqlite3/tests/skipif.inc @@ -0,0 +1,8 @@ +<?php + +if (!extension_loaded('sqlite3')) { + die("skip"); +} + + +?>
\ No newline at end of file diff --git a/ext/sqlite3/tests/sqlite3_01_open.phpt b/ext/sqlite3/tests/sqlite3_01_open.phpt new file mode 100644 index 0000000000..11c482722b --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_01_open.phpt @@ -0,0 +1,18 @@ +--TEST-- +SQLite3::open/close tests +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); + +var_dump($db); +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +object(SQLite3)#%d (0) { +} +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_02_create.phpt b/ext/sqlite3/tests/sqlite3_02_create.phpt new file mode 100644 index 0000000000..5a1aa719d3 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_02_create.phpt @@ -0,0 +1,34 @@ +--TEST-- +SQLite3::query CREATE tests +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "Creating Same Table Again\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "Dropping database\n"; +var_dump($db->exec('DROP TABLE test')); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +Creating Same Table Again + +Warning: SQLite3::exec(): table test already exists in %s on line %d +bool(false) +Dropping database +bool(true) +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_03_insert.phpt b/ext/sqlite3/tests/sqlite3_03_insert.phpt new file mode 100644 index 0000000000..7a9fedabcf --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_03_insert.phpt @@ -0,0 +1,51 @@ +--TEST-- +SQLite3::query INSERT tests +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')")); +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")); + +echo "SELECTING results\n"; +$results = $db->query("SELECT * FROM test ORDER BY id ASC"); +while ($result = $results->fetchArray(SQLITE3_NUM)) +{ + var_dump($result); +} +$results->finalize(); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +SELECTING results +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "a" +} +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "b" +} +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_04_update.phpt b/ext/sqlite3/tests/sqlite3_04_update.phpt new file mode 100644 index 0000000000..4a84fdd3f8 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_04_update.phpt @@ -0,0 +1,77 @@ +--TEST-- +SQLite3::query UPDATE tests +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')")); +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")); + +echo "SELECTING results\n"; +$results = $db->query("SELECT * FROM test ORDER BY id ASC"); +while ($result = $results->fetchArray(SQLITE3_NUM)) +{ + var_dump($result); +} +$results->finalize(); + +echo "UPDATING results\n"; +var_dump($db->exec("UPDATE test SET id = 'c' WHERE id = 'a'")); + +echo "Checking results\n"; +$results = $db->query("SELECT * FROM test ORDER BY id ASC"); +while ($result = $results->fetchArray(SQLITE3_NUM)) +{ + var_dump($result); +} +$results->finalize(); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +SELECTING results +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "a" +} +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "b" +} +UPDATING results +bool(true) +Checking results +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "b" +} +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "c" +} +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_05_delete.phpt b/ext/sqlite3/tests/sqlite3_05_delete.phpt new file mode 100644 index 0000000000..b35e7c1378 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_05_delete.phpt @@ -0,0 +1,71 @@ +--TEST-- +SQLite3::query DELETE tests +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')")); +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")); + +echo "SELECTING results\n"; +$results = $db->query("SELECT * FROM test ORDER BY id ASC"); +while ($result = $results->fetchArray(SQLITE3_NUM)) +{ + var_dump($result); +} +$results->finalize(); + +echo "DELETING a row\n"; +var_dump($db->exec("DELETE FROM test WHERE id = 'a'")); + +echo "Checking results\n"; +$results = $db->query("SELECT * FROM test ORDER BY id ASC"); +while ($result = $results->fetchArray(SQLITE3_NUM)) +{ + var_dump($result); +} +$results->finalize(); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +SELECTING results +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "a" +} +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "b" +} +DELETING a row +bool(true) +Checking results +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "b" +} +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_06_prepared_stmt.phpt b/ext/sqlite3/tests/sqlite3_06_prepared_stmt.phpt new file mode 100644 index 0000000000..403adbbf41 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_06_prepared_stmt.phpt @@ -0,0 +1,52 @@ +--TEST-- +SQLite3::prepare Bound Variable test +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')")); +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")); + +echo "SELECTING results\n"; +$stmt = $db->prepare("SELECT * FROM test WHERE id = ? ORDER BY id ASC"); +$foo = 'c'; +echo "BINDING Parameter\n"; +var_dump($stmt->bindParam(1, $foo, SQLITE3_TEXT)); +$foo = 'a'; +$results = $stmt->execute(); +while ($result = $results->fetchArray(SQLITE3_NUM)) +{ + var_dump($result); +} +$results->finalize(); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +SELECTING results +BINDING Parameter +bool(true) +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "a" +} +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_07_prepared_stmt.phpt b/ext/sqlite3/tests/sqlite3_07_prepared_stmt.phpt new file mode 100644 index 0000000000..7a3d950f55 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_07_prepared_stmt.phpt @@ -0,0 +1,51 @@ +--TEST-- +SQLite3::prepare Bound Value test +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')")); +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")); + +echo "SELECTING results\n"; +$stmt = $db->prepare("SELECT * FROM test WHERE id = ? ORDER BY id ASC"); +$foo = 'a'; +echo "BINDING Value\n"; +var_dump($stmt->bindValue(1, $foo, SQLITE3_TEXT)); +$results = $stmt->execute(); +while ($result = $results->fetchArray(SQLITE3_NUM)) +{ + var_dump($result); +} +$results->finalize(); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +SELECTING results +BINDING Value +bool(true) +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "a" +} +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_08_udf.phpt b/ext/sqlite3/tests/sqlite3_08_udf.phpt new file mode 100644 index 0000000000..d6a326cfbd --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_08_udf.phpt @@ -0,0 +1,57 @@ +--TEST-- +SQLite3::createFunction +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +function my_udf_md5($foo) +{ + return md5($foo); +} + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')")); +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")); + +echo "CREATING UDF\n"; +var_dump($db->createFunction('my_udf_md5', 'my_udf_md5')); + +echo "SELECTING results\n"; +$results = $db->query("SELECT my_udf_md5(id) FROM test ORDER BY id ASC"); +while ($result = $results->fetchArray(SQLITE3_NUM)) +{ + var_dump($result); +} +$results->finalize(); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +CREATING UDF +bool(true) +SELECTING results +array(1) { + [0]=> + string(32) "0cc175b9c0f1b6a831c399e269772661" +} +array(1) { + [0]=> + string(32) "92eb5ffee6ae2fec3ad71c777531578f" +} +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_09_blob_bound_param.phpt b/ext/sqlite3/tests/sqlite3_09_blob_bound_param.phpt new file mode 100644 index 0000000000..ccc6a8b07f --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_09_blob_bound_param.phpt @@ -0,0 +1,61 @@ +--TEST-- +SQLite3::prepare Bound Variable Blob test +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +require_once(dirname(__FILE__) . '/stream_test.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (id STRING, data BLOB)')); + +echo "PREPARING insert\n"; +$insert_stmt = $db->prepare("INSERT INTO test (id, data) VALUES (?, ?)"); + +echo "Opening blob stream\n"; +$foo = fopen('sqliteBlobTest://fooo', 'r'); +var_dump($foo); + +echo "BINDING Parameter\n"; +var_dump($insert_stmt->bindValue(1, 'a', SQLITE3_TEXT)); +var_dump($insert_stmt->bindParam(2, $foo, SQLITE3_BLOB)); +$insert_stmt->execute(); +echo "Closing statement\n"; +var_dump($insert_stmt->close()); + +echo "SELECTING results\n"; +$results = $db->query("SELECT id, quote(data) AS data FROM test ORDER BY id ASC"); +while ($result = $results->fetchArray(SQLITE3_NUM)) +{ + var_dump($result); +} +$results->finalize(); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +PREPARING insert +Opening blob stream +resource(%d) of type (stream) +BINDING Parameter +bool(true) +bool(true) +Closing statement +bool(true) +SELECTING results +array(2) { + [0]=> + string(1) "a" + [1]=> + string(23) "X'61626364656667006869'" +} +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_10_bound_value_name.phpt b/ext/sqlite3/tests/sqlite3_10_bound_value_name.phpt new file mode 100644 index 0000000000..35852ba117 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_10_bound_value_name.phpt @@ -0,0 +1,55 @@ +--TEST-- +SQLite3::prepare Bound Value test +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')")); +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")); + +echo "SELECTING results\n"; +$stmt = $db->prepare("SELECT * FROM test WHERE id = :id ORDER BY id ASC"); +$foo = 'a'; +echo "BINDING Value\n"; +var_dump($stmt->bindValue(':id', $foo, SQLITE3_TEXT)); +echo "BINDING Value Again\n"; +var_dump($stmt->bindValue('id', $foo, SQLITE3_TEXT)); +$results = $stmt->execute(); +while ($result = $results->fetchArray(SQLITE3_NUM)) +{ + var_dump($result); +} +$results->finalize(); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +SELECTING results +BINDING Value +bool(true) +BINDING Value Again +bool(true) +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "a" +} +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_11_numrows.phpt b/ext/sqlite3/tests/sqlite3_11_numrows.phpt new file mode 100644 index 0000000000..d54270b048 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_11_numrows.phpt @@ -0,0 +1,46 @@ +--TEST-- +SQLite3::prepare number of rows +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); +// Create an instance of the ReflectionMethod class +try { + $method = new ReflectionMethod('sqlite3_result', 'numRows'); +} catch (ReflectionException $e) { + die("skip"); +} +?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')")); +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")); + +echo "SELECTING results\n"; +$results = $db->query("SELECT * FROM test ORDER BY id ASC"); +echo "Number of rows\n"; +var_dump($results->numRows()); +$results->finalize(); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +SELECTING results +Number of rows +int(2) +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt b/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt new file mode 100644 index 0000000000..8211ed518e --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt @@ -0,0 +1,50 @@ +--TEST-- +SQLite3::query Unfinalized statement tests +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')")); +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")); + +echo "SELECTING results\n"; +$results = $db->query("SELECT * FROM test ORDER BY id ASC"); +while ($result = $results->fetchArray(SQLITE3_NUM)) +{ + var_dump($result); + /* Only read one row and break */ + break; +} + +echo "Closing database\n"; +var_dump($db->close()); +echo "Check result was freed\n"; +var_dump($results); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +SELECTING results +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "a" +} +Closing database +bool(true) +Check result was freed +NULL +Done diff --git a/ext/sqlite3/tests/sqlite3_13_skip_all_cleanup.phpt b/ext/sqlite3/tests/sqlite3_13_skip_all_cleanup.phpt new file mode 100644 index 0000000000..573d87fe76 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_13_skip_all_cleanup.phpt @@ -0,0 +1,45 @@ +--TEST-- +SQLite3::query Skip all cleanup +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')")); +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")); + +echo "SELECTING results\n"; +$results = $db->query("SELECT * FROM test ORDER BY id ASC"); +while ($result = $results->fetchArray(SQLITE3_NUM)) +{ + var_dump($result); +} +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +SELECTING results +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "a" +} +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "b" +} +Done diff --git a/ext/sqlite3/tests/sqlite3_14_querysingle.phpt b/ext/sqlite3/tests/sqlite3_14_querysingle.phpt new file mode 100644 index 0000000000..8cfe089f27 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_14_querysingle.phpt @@ -0,0 +1,38 @@ +--TEST-- +SQLite3::querySingle tests +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')")); +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")); + +echo "SELECTING results\n"; +var_dump($db->querySingle("SELECT id FROM test WHERE id = 'a'")); +var_dump($db->querySingle("SELECT id, time FROM test WHERE id = 'a'", true)); + +echo "Done" +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +SELECTING results +string(1) "a" +array(2) { + ["id"]=> + string(1) "a" + ["time"]=> + int(%d) +} +Done diff --git a/ext/sqlite3/tests/sqlite3_15_open_error.phpt b/ext/sqlite3/tests/sqlite3_15_open_error.phpt new file mode 100644 index 0000000000..2e5e8a9c0c --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_15_open_error.phpt @@ -0,0 +1,20 @@ +--TEST-- +SQLite3::open error test +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php +$unreadable = dirname(__FILE__) . '/unreadable.db'; +touch($unreadable); +chmod($unreadable, 0200); +$db = new SQLite3($unreadable); + +var_dump($db); +echo "Done\n"; +unlink($unreadable); +?> +--EXPECTF-- +Notice: SQLite3::__construct(): Unable to open database: unable to open database file in %s/sqlite3_15_open_error.php on line %d +object(SQLite3)#%d (0) { +} +Done diff --git a/ext/sqlite3/tests/sqlite3_16_select_no_results.phpt b/ext/sqlite3/tests/sqlite3_16_select_no_results.phpt new file mode 100644 index 0000000000..de9fdefdbf --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_16_select_no_results.phpt @@ -0,0 +1,32 @@ +--TEST-- +SQLite3::query SELECT with no results +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "SELECTING results\n"; +$results = $db->query("SELECT * FROM test ORDER BY id ASC"); +while ($result = $results->fetchArray(SQLITE3_NUM)) +{ + var_dump($result); +} +$results->finalize(); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +SELECTING results +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_17_version.phpt b/ext/sqlite3/tests/sqlite3_17_version.phpt new file mode 100644 index 0000000000..ae374efef3 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_17_version.phpt @@ -0,0 +1,16 @@ +--TEST-- +SQLite3::version() +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php +print_r(SQLite3::version()); +echo "Done\n"; +?> +--EXPECTF-- +Array +( + [versionString] => %d.%d.%d + [versionNumber] => %d +) +Done diff --git a/ext/sqlite3/tests/sqlite3_18_changes.phpt b/ext/sqlite3/tests/sqlite3_18_changes.phpt new file mode 100644 index 0000000000..6802db3e0a --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_18_changes.phpt @@ -0,0 +1,40 @@ +--TEST-- +SQLite3::changes() tests +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')")); +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")); + +echo "UPDATE query\n"; +var_dump($db->exec("UPDATE test SET id = 'c'")); + +echo "Rows Updated\n"; +var_dump($db->changes()); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +UPDATE query +bool(true) +Rows Updated +int(2) +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_19_columninfo.phpt b/ext/sqlite3/tests/sqlite3_19_columninfo.phpt new file mode 100644 index 0000000000..4451bdf716 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_19_columninfo.phpt @@ -0,0 +1,45 @@ +--TEST-- +SQLite3 columnType and columnName +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')")); +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")); + +echo "SELECTING results\n"; +$result = $db->query("SELECT * FROM test ORDER BY id ASC"); +while ($row = $result->fetchArray(SQLITE3_NUM)) { + $totalColumns = $result->numColumns(); + for ($i = 0; $i < $totalColumns; $i++) { + echo "Name: " . $result->columnName($i) . " - Type: " . $result->columnType($i) . "\n"; + } +} +$result->finalize(); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +SELECTING results +Name: time - Type: 1 +Name: id - Type: 3 +Name: time - Type: 1 +Name: id - Type: 3 +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_20_error.phpt b/ext/sqlite3/tests/sqlite3_20_error.phpt new file mode 100644 index 0000000000..d98644ab2a --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_20_error.phpt @@ -0,0 +1,28 @@ +--TEST-- +SQLite3 error functions +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); + +echo "SELECTING from invalid table\n"; +$result = $db->query("SELECT * FROM non_existent_table"); +if (!$result) { + echo "Error Code: " . $db->lastErrorCode() . "\n"; + echo "Error Msg: " . $db->lastErrorMsg() . "\n"; +} +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +SELECTING from invalid table + +Warning: SQLite3::query(): Unable to prepare statement: 1, no such table: non_existent_table in %s on line %d +Error Code: 1 +Error Msg: no such table: non_existent_table +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_21_security.phpt b/ext/sqlite3/tests/sqlite3_21_security.phpt new file mode 100644 index 0000000000..f0b8d5aeb8 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_21_security.phpt @@ -0,0 +1,34 @@ +--TEST-- +SQLite3 open_basedir / safe_mode checks +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--INI-- +open_basedir=. +--FILE-- +<?php +$directory = dirname(__FILE__) . '/'; +$file = uniqid() . '.db'; + +echo "Within test directory\n"; +$db = new SQLite3($directory . $file); +var_dump($db); +var_dump($db->close()); +unlink($directory . $file); + +echo "Above test directory\n"; +$db = new SQLite3('../bad' . $file); +var_dump($db); + +echo "Done\n"; +?> +--EXPECTF-- +Within test directory +object(SQLite3)#%d (0) { +} +bool(true) +Above test directory + +Warning: SQLite3::__construct(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d +object(SQLite3)#%d (0) { +} +Done diff --git a/ext/sqlite3/tests/sqlite3_22_loadextension.phpt b/ext/sqlite3/tests/sqlite3_22_loadextension.phpt new file mode 100644 index 0000000000..ce4a07d3b9 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_22_loadextension.phpt @@ -0,0 +1,27 @@ +--TEST-- +SQLite3 load extension +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--INI-- +open_basedir=. +sqlite3.extension_dir=. +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); + +$directory = dirname(__FILE__); + +touch($directory . '/myext.txt'); + +var_dump($db->loadExtension('myext.txt')); +var_dump($db->close()); +unlink($directory . '/myext.txt'); + +echo "Done\n"; +?> +--EXPECTF-- +Warning: SQLite3::loadExtension(): Unable to load extension at './myext.txt' in %s on line %d +bool(false) +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_23_escape_string.phpt b/ext/sqlite3/tests/sqlite3_23_escape_string.phpt new file mode 100644 index 0000000000..57fc01f834 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_23_escape_string.phpt @@ -0,0 +1,51 @@ +--TEST-- +SQLite3::escapeString +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", '" . $db->escapeString("test''%") . "')")); +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")); + +echo "SELECTING results\n"; +$results = $db->query("SELECT * FROM test ORDER BY id ASC"); +while ($result = $results->fetchArray(SQLITE3_NUM)) +{ + var_dump($result); +} +$results->finalize(); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +SELECTING results +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "b" +} +array(2) { + [0]=> + int(%d) + [1]=> + string(7) "test''%" +} +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_24_last_insert_rowid.phpt b/ext/sqlite3/tests/sqlite3_24_last_insert_rowid.phpt new file mode 100644 index 0000000000..83d0a292f8 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_24_last_insert_rowid.phpt @@ -0,0 +1,34 @@ +--TEST-- +SQLite3::lastInsertRowID tests +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')")); +var_dump($db->lastInsertRowID()); +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")); +var_dump($db->lastInsertRowID()); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +int(1) +bool(true) +int(2) +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt b/ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt new file mode 100644 index 0000000000..d11bfd739d --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt @@ -0,0 +1,56 @@ +--TEST-- +SQLite3::createAggregate() test +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); + +function sum_list_step(&$context, $string) { + if (empty($context)) + { + $context = array('total' => 0, 'values' => array()); + } + var_dump($context); + $context['total'] += intval($string); + $context['values'][] = $context['total']; + return true; +} + +function sum_list_finalize(&$context) { + var_dump($context); + return implode(',', $context['values']); +} + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (a INTEGER, b INTEGER)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (a, b) VALUES (1, -1)")); +var_dump($db->exec("INSERT INTO test (a, b) VALUES (2, -2)")); +var_dump($db->exec("INSERT INTO test (a, b) VALUES (3, -3)")); +var_dump($db->exec("INSERT INTO test (a, b) VALUES (4, -4)")); +var_dump($db->exec("INSERT INTO test (a, b) VALUES (4, -4)")); + +$db->createAggregate('S', 'sum_list_step', 'sum_list_finalize', 1); + +print_r($db->querySingle("SELECT S(a), S(b) FROM test", true)); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_26_reset_prepared_stmt.phpt b/ext/sqlite3/tests/sqlite3_26_reset_prepared_stmt.phpt new file mode 100644 index 0000000000..eda1bd5f22 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_26_reset_prepared_stmt.phpt @@ -0,0 +1,61 @@ +--TEST-- +SQLite3::reset prepared statement +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')")); +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")); + +echo "SELECTING results\n"; +$stmt = $db->prepare("SELECT * FROM test WHERE id = ? ORDER BY id ASC"); +$foo = 'c'; +echo "BINDING Parameter\n"; +var_dump($stmt->bindParam(1, $foo, SQLITE3_TEXT)); +$foo = 'a'; +$results = $stmt->execute(); +while ($result = $results->fetchArray(SQLITE3_NUM)) { + var_dump($result); +} +$stmt->reset(); +while ($result = $results->fetchArray(SQLITE3_NUM)) { + var_dump($result); +} +$results->finalize(); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +SELECTING results +BINDING Parameter +bool(true) +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "a" +} +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "a" +} +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_27_reset_prepared_stmt_result.phpt b/ext/sqlite3/tests/sqlite3_27_reset_prepared_stmt_result.phpt new file mode 100644 index 0000000000..ea7e8bfba0 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_27_reset_prepared_stmt_result.phpt @@ -0,0 +1,61 @@ +--TEST-- +SQLite3::reset prepared statement results +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')")); +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")); + +echo "SELECTING results\n"; +$stmt = $db->prepare("SELECT * FROM test WHERE id = ? ORDER BY id ASC"); +$foo = 'c'; +echo "BINDING Parameter\n"; +var_dump($stmt->bindParam(1, $foo, SQLITE3_TEXT)); +$foo = 'a'; +$results = $stmt->execute(); +while ($result = $results->fetchArray(SQLITE3_NUM)) { + var_dump($result); +} +$results->reset(); +while ($result = $results->fetchArray(SQLITE3_NUM)) { + var_dump($result); +} +$results->finalize(); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +SELECTING results +BINDING Parameter +bool(true) +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "a" +} +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "a" +} +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_28_clear_bindings.phpt b/ext/sqlite3/tests/sqlite3_28_clear_bindings.phpt new file mode 100644 index 0000000000..77a69b3114 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_28_clear_bindings.phpt @@ -0,0 +1,65 @@ +--TEST-- +SQLite3_stmt::clear prepared statement results +--SKIPIF-- +<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> +--FILE-- +<?php + +require_once(dirname(__FILE__) . '/new_db.inc'); +define('TIMENOW', time()); + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')")); +var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")); + +echo "SELECTING results\n"; +$stmt = $db->prepare("SELECT * FROM test WHERE id = ? ORDER BY id ASC"); +$foo = 'c'; +echo "BINDING Parameter\n"; +var_dump($stmt->bindParam(1, $foo, SQLITE3_TEXT)); +$foo = 'a'; +$results = $stmt->execute(); +while ($result = $results->fetchArray(SQLITE3_NUM)) { + var_dump($result); +} +$stmt->reset(); +$stmt->clear(); +var_dump($stmt->bindValue(1, 'b', SQLITE3_TEXT)); +$results = $stmt->execute(); +while ($result = $results->fetchArray(SQLITE3_NUM)) { + var_dump($result); +} +$results->finalize(); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECTF-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +SELECTING results +BINDING Parameter +bool(true) +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "a" +} +bool(true) +array(2) { + [0]=> + int(%d) + [1]=> + string(1) "b" +} +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/stream_test.inc b/ext/sqlite3/tests/stream_test.inc new file mode 100644 index 0000000000..0d07383b80 --- /dev/null +++ b/ext/sqlite3/tests/stream_test.inc @@ -0,0 +1,45 @@ +<?php + +class SQLite3_Test_Stream +{ + private $position; + public static $string_length = 10; + public static $string = "abcdefg\0hi"; + + public function stream_open($path, $mode, $options, &$opened_path) + { + $this->position = 0; + return true; + } + + public function stream_read($count) + { + $ret = substr(self::$string, $this->position, $count); + $this->position += strlen($ret); + return $ret; + } + + public function stream_write($data) + { + return 0; + } + + public function stream_stat() + { + return array('size' => self::$string_length); + } + + public function stream_tell() + { + return $this->position; + } + + public function stream_eof() + { + return ($this->position >= self::$string_length); + } +} + +stream_wrapper_register('sqliteBlobTest', "SQLite3_Test_Stream") or die("Unable to register sqliteBlobTest stream"); + +?>
\ No newline at end of file |
