-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
461 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
|
||
dependencies { | ||
compile project(':jphp-runtime') | ||
compile 'org.apache.commons:commons-lang3:3.4' | ||
|
||
testCompile 'org.xerial:sqlite-jdbc:3.8.7' | ||
testCompile 'junit:junit:4.+' | ||
testCompile project(':jphp-zend-ext') | ||
testCompile project(':jphp-core').sourceSets.test.output | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
jphp-sql-ext/src/main/tests/resources/sql/SqlDriverManager_001.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--TEST-- | ||
SqlDriverManager test connection #1 | ||
--FILE-- | ||
<?php | ||
|
||
use php\sql\SqlDriverManager; | ||
|
||
SqlDriverManager::install('sqlite'); | ||
|
||
$conn = SqlDriverManager::getConnection('sqlite::memory:'); | ||
|
||
var_dump("readonly", $conn->readOnly); | ||
var_dump("catalog", $conn->catalog); | ||
var_dump("autoCommit", $conn->autoCommit); | ||
var_dump("transactionIsolation", $conn->transactionIsolation); | ||
|
||
?> | ||
--EXPECTF-- | ||
string(8) "readonly" | ||
bool(false) | ||
string(7) "catalog" | ||
NULL | ||
string(10) "autoCommit" | ||
bool(true) | ||
string(20) "transactionIsolation" | ||
int(8) |
17 changes: 17 additions & 0 deletions
17
jphp-sql-ext/src/main/tests/resources/sql/SqlDriverManager_002.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--TEST-- | ||
SqlDriverManager test install invalid #2 | ||
--FILE-- | ||
<?php | ||
|
||
use php\sql\SqlDriverManager; | ||
use php\sql\SqlException; | ||
|
||
try { | ||
SqlDriverManager::install('foobar'); | ||
} catch (SqlException $e) { | ||
echo $e->getMessage(); | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
java.sql.SQLException: Driver class 'foobar' is not found in classpath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--TEST-- | ||
Test create table #1 | ||
--FILE-- | ||
<?php | ||
use php\sql\SqlDriverManager; | ||
SqlDriverManager::install('sqlite'); | ||
|
||
$conn = SqlDriverManager::getConnection('sqlite::memory:'); | ||
|
||
$statement = $conn->query('create table person (id integer, name string)'); | ||
var_dump($statement->update()); | ||
|
||
$result = $conn->query('select COUNT(*) from person')->fetch(); | ||
var_dump($result->toArray()); | ||
|
||
?> | ||
--EXPECTF-- | ||
int(0) | ||
array(1) { | ||
["COUNT(*)"]=> | ||
int(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--TEST-- | ||
SqlDriverManager test insert into table #2 | ||
--FILE-- | ||
<?php | ||
use php\sql\SqlDriverManager; | ||
use php\sql\SqlResult; | ||
use php\util\Flow; | ||
|
||
SqlDriverManager::install('sqlite'); | ||
|
||
$conn = SqlDriverManager::getConnection('sqlite::memory:'); | ||
|
||
$conn->query('create table person (id integer, name string)')->update(); | ||
$result = $conn->query("insert into person values(?, ?)", [1, 'leo'])->update(); | ||
$result += $conn->query("insert into person values(?, ?)", [2, 'yui'])->update(); | ||
|
||
var_dump($result); | ||
|
||
$array = Flow::of($conn->query('select * from person')) | ||
->map(function (SqlResult $result) { return $result->toArray(); }) | ||
->toArray(); | ||
var_dump($array); | ||
|
||
?> | ||
--EXPECTF-- | ||
int(2) | ||
array(2) { | ||
[0]=> | ||
array(2) { | ||
["id"]=> | ||
int(1) | ||
["name"]=> | ||
string(3) "leo" | ||
} | ||
[1]=> | ||
array(2) { | ||
["id"]=> | ||
int(2) | ||
["name"]=> | ||
string(3) "yui" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--TEST-- | ||
SqlDriverManager test transactions #2 | ||
--FILE-- | ||
<?php | ||
use php\sql\SqlDriverManager; | ||
use php\sql\SqlResult; | ||
use php\util\Flow; | ||
|
||
SqlDriverManager::install('sqlite'); | ||
|
||
$conn = SqlDriverManager::getConnection('sqlite::memory:'); | ||
|
||
$conn->autoCommit = false; | ||
|
||
$conn->query('create table person (id integer)')->update(); | ||
$conn->commit(); | ||
|
||
$count = $conn->query('insert into person values(?)', [1])->update(); | ||
|
||
var_dump($count); | ||
|
||
$conn->rollback(); | ||
|
||
var_dump($conn->query('select COUNT(*) from person')->fetch()->toArray(false)); | ||
|
||
?> | ||
--EXPECTF-- | ||
int(1) | ||
array(1) { | ||
[0]=> | ||
int(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--TEST-- | ||
SqlDriverManager test blobs #2 | ||
--FILE-- | ||
<?php | ||
use php\sql\SqlDriverManager; | ||
|
||
SqlDriverManager::install('sqlite'); | ||
|
||
$conn = SqlDriverManager::getConnection('sqlite::memory:'); | ||
|
||
$conn->query('create table person (id integer, file blob)')->update(); | ||
|
||
$count = $conn->query('insert into person values(?, ?)', [1, 'foobar'])->update(); | ||
|
||
var_dump($count); | ||
|
||
var_dump($conn->query('select * from person')->fetch()->toArray()); | ||
|
||
?> | ||
--EXPECT-- | ||
int(1) | ||
array(2) { | ||
["id"]=> | ||
int(1) | ||
["file"]=> | ||
string(6) "foobar" | ||
} |
Oops, something went wrong.