Skip to content

Commit

Permalink
Mysqli integration test updates (#137)
Browse files Browse the repository at this point in the history
* * Updated to work with proper mysqli command syntax.
* Verified working with mysql server 5.7 (mysql server 8.0 will return different traces since it returns more info).
* Updated traces for latest agent trace returns.
* Updated skipif.inc, if it doesn't detect a DB (i.e., running locally on a dev machine instead of a build machine) is already setup it will set one up.
  • Loading branch information
zsistla authored and joshuabenuck committed Apr 20, 2021
1 parent 3e1cae0 commit adbdca6
Show file tree
Hide file tree
Showing 25 changed files with 256 additions and 145 deletions.
81 changes: 78 additions & 3 deletions tests/integration/mysqli/skipif.inc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,84 @@ if (!extension_loaded("mysqli")) {

mysqli_report(MYSQLI_REPORT_STRICT); // prevent warning if connect fails

/*
$link = @mysql_connect($MYSQL_SERVER, $MYSQL_USER, $MYSQL_PASSWD);
if (FALSE === $link) {
die("skip: " . mysql_error() . "\n");
}
if (!empty($MYSQL_DB)) {
if (FALSE === mysql_select_db($MYSQL_DB, $link)) {
die("skip: " . mysql_error() . "\n");
}
}
*/

try {
$link = @mysqli_connect($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWD, $MYSQL_DB, $MYSQL_PORT, $MYSQL_SOCKET);
mysqli_close($link);

$link = @mysqli_connect($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWD);

if (FALSE === $link) {
die("skip: " . mysqli_error() . "\n");
}

if (!empty($MYSQL_DB)) {
if (FALSE === mysqli_select_db($link, $MYSQL_DB)) {
/* Database doesn't exist, will try to create. */
/* Create database. */
$sql = "CREATE DATABASE " . $MYSQL_DB;
$result = mysqli_query($link, $sql);
mysqli_select_db($link, $MYSQL_DB);

$result = mysqli_query($link, $sql);
if (FALSE === $result) {
die("skip: Error with database.");
}

/* Create table `COLUMNS`. */
if (mysqli_query($link, "DESCRIBE COLUMNS ")) {
/* Already exists */
} else {
$sql = "CREATE TABLE COLUMNS(
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
code VARCHAR(30) NOT NULL
)";
mysqli_query($link, $sql);
}


/* Create table `STATISTICS`. */
if (mysqli_query($link, "DESCRIBE STATISTICS ")) {
/* Already exists */
} else {
$sql = "CREATE TABLE STATISTICS(
)";
mysqli_query($link, $sql);
}

/* Create table `TRIGGERS`. */
if (mysqli_query($link, "DESCRIBE TRIGGERS ")) {
/* Already exists */
} else {
$sql = "CREATE TABLE TRIGGERS(
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
code VARCHAR(30) NOT NULL
)";
mysqli_query($link, $sql);
}


/* commit transaction */
if (!mysqli_commit($link)) {
print("Transaction commit failed.\n");
} else {
echo "Transaction commit succeeded.\n";
}
}
}

mysqli_close($link);
} catch (Exception $e) {
die("skip: " . $e->getMessage() . "\n");
die("skip: " . $e->getMessage() . "\n");
}

19 changes: 12 additions & 7 deletions tests/integration/mysqli/test_bind_param_object_oo.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
[{"name":"Datastore/MySQL/all"}, [10, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/MySQL/allOther"}, [10, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/operation/MySQL/select"}, [10, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/TABLES/select"}, [10, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/TABLES/select",
[{"name":"Datastore/statement/MySQL/tables/select"}, [10, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/tables/select",
"scope":"OtherTransaction/php__FILE__"}, [10, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransaction/all"}, [ 1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransaction/php__FILE__"}, [ 1, "??", "??", "??", "??", "??"]],
Expand All @@ -62,8 +62,8 @@
"OtherTransaction/php__FILE__",
"<unknown>",
"?? SQL ID",
"SELECT TABLE_NAME FROM TABLES WHERE TABLE_NAME = ?",
"Datastore/statement/MySQL/TABLES/select",
"SELECT TABLE_NAME FROM information_schema.tables WHERE table_name=?",
"Datastore/statement/MySQL/tables/select",
10,
"?? total time",
"?? min time",
Expand All @@ -86,7 +86,7 @@
[
1,
"SIMPLE",
"TABLES",
"tables",
"ALL",
null,
"TABLE_NAME",
Expand Down Expand Up @@ -125,9 +125,14 @@ public function __toString() {

function test_stmt_prepare($link, $name)
{
$query = "SELECT TABLE_NAME FROM TABLES WHERE TABLE_NAME = ?";
$stmt = $link->prepare($query);

$query = "SELECT TABLE_NAME FROM information_schema.tables WHERE table_name=?";

$stmt = $link->prepare($query);
if (FALSE === $stmt) {
echo mysqli_error($link) . "\n";
return;
}
if (FALSE === $stmt->bind_param('s', $name) ||
FALSE === $stmt->execute() ||
FALSE === $stmt->bind_result($output)) {
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/mysqli/test_bind_param_oo.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
[{"name":"Datastore/MySQL/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/MySQL/allOther"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/operation/MySQL/select"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/TABLES/select"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/TABLES/select",
[{"name":"Datastore/statement/MySQL/tables/select"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/tables/select",
"scope":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransaction/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
Expand All @@ -54,8 +54,8 @@
"OtherTransaction/php__FILE__",
"<unknown>",
"?? SQL ID",
"SELECT TABLE_NAME FROM TABLES WHERE TABLE_NAME = ?",
"Datastore/statement/MySQL/TABLES/select",
"SELECT TABLE_NAME FROM information_schema.tables WHERE table_name=?",
"Datastore/statement/MySQL/tables/select",
1,
"?? total time",
"?? min time",
Expand All @@ -78,7 +78,7 @@
[
1,
"SIMPLE",
"TABLES",
"tables",
"ALL",
null,
"TABLE_NAME",
Expand Down Expand Up @@ -109,8 +109,8 @@ function test_stmt_prepare($link)
{
$stmt = $link->stmt_init();
$name = 'STATISTICS';
$query = "SELECT TABLE_NAME FROM TABLES WHERE TABLE_NAME = ?";

$query = "SELECT TABLE_NAME FROM information_schema.tables WHERE table_name=?";
if (FALSE === $stmt->prepare($query) ||
FALSE === $stmt->bind_param('s', $name) ||
FALSE === $stmt->execute() ||
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/mysqli/test_bind_param_proc.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
[{"name":"Datastore/MySQL/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/MySQL/allOther"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/operation/MySQL/select"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/TABLES/select"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/TABLES/select",
[{"name":"Datastore/statement/MySQL/tables/select"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/tables/select",
"scope":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransaction/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
Expand All @@ -53,8 +53,8 @@
"OtherTransaction/php__FILE__",
"<unknown>",
"?? SQL ID",
"SELECT TABLE_NAME FROM TABLES WHERE TABLE_NAME = ?",
"Datastore/statement/MySQL/TABLES/select",
"SELECT TABLE_NAME FROM information_schema.tables WHERE table_name=?",
"Datastore/statement/MySQL/tables/select",
1,
"?? total time",
"?? min time",
Expand All @@ -77,7 +77,7 @@
[
1,
"SIMPLE",
"TABLES",
"tables",
"ALL",
null,
"TABLE_NAME",
Expand Down Expand Up @@ -108,7 +108,7 @@ function test_stmt_prepare($link)
{
$stmt = mysqli_stmt_init($link);
$name = 'STATISTICS';
$query = "SELECT TABLE_NAME FROM TABLES WHERE TABLE_NAME = ?";
$query = "SELECT TABLE_NAME FROM information_schema.tables WHERE table_name=?";

if (FALSE === mysqli_stmt_prepare($stmt, $query) ||
FALSE === mysqli_stmt_bind_param($stmt, 's', $name) ||
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/mysqli/test_explain_connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
[{"name":"Datastore/allOther"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/MySQL/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/MySQL/allOther"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/TABLES/select"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/TABLES/select",
[{"name":"Datastore/statement/MySQL/tables/select"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/tables/select",
"scope":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/operation/MySQL/select"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransaction/all"}, [1, "??", "??", "??", "??", "??"]],
Expand All @@ -52,8 +52,8 @@
"OtherTransaction/php__FILE__",
"<unknown>",
"?? SQL ID",
"SELECT TABLE_NAME FROM TABLES WHERE TABLE_NAME = ?",
"Datastore/statement/MySQL/TABLES/select",
"SELECT TABLE_NAME FROM information_schema.tables WHERE table_name=?",
"Datastore/statement/MySQL/tables/select",
1,
"?? total time",
"?? min time",
Expand All @@ -76,7 +76,7 @@
[
1,
"SIMPLE",
"TABLES",
"tables",
"ALL",
null,
"TABLE_NAME",
Expand Down Expand Up @@ -105,7 +105,7 @@

function test_prepare($link)
{
$query = "SELECT TABLE_NAME FROM TABLES WHERE TABLE_NAME = 'STATISTICS'";
$query = "SELECT TABLE_NAME FROM information_schema.tables WHERE table_name='STATISTICS'";

$stmt = mysqli_prepare($link, $query);
if (FALSE === $stmt) {
Expand Down
13 changes: 7 additions & 6 deletions tests/integration/mysqli/test_explain_construct.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
[{"name":"Datastore/allOther"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/MySQL/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/MySQL/allOther"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/TABLES/select"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/TABLES/select",
[{"name":"Datastore/statement/MySQL/tables/select"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/tables/select",
"scope":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/operation/MySQL/select"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransaction/all"}, [1, "??", "??", "??", "??", "??"]],
Expand All @@ -53,8 +53,8 @@
"OtherTransaction/php__FILE__",
"<unknown>",
"?? SQL ID",
"SELECT TABLE_NAME FROM TABLES WHERE TABLE_NAME = ?",
"Datastore/statement/MySQL/TABLES/select",
"SELECT TABLE_NAME FROM information_schema.tables WHERE table_name=?",
"Datastore/statement/MySQL/tables/select",
1,
"?? total time",
"?? min time",
Expand All @@ -77,7 +77,7 @@
[
1,
"SIMPLE",
"TABLES",
"tables",
"ALL",
null,
"TABLE_NAME",
Expand Down Expand Up @@ -106,7 +106,8 @@

function test_prepare($link)
{
$query = "SELECT TABLE_NAME FROM TABLES WHERE TABLE_NAME = 'STATISTICS'";

$query = "SELECT TABLE_NAME FROM information_schema.tables WHERE table_name='STATISTICS'";

$stmt = mysqli_prepare($link, $query);
if (FALSE === $stmt) {
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/mysqli/test_explain_database_no_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
[{"name":"Datastore/allOther"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/MySQL/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/MySQL/allOther"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/TABLES/select"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/TABLES/select",
[{"name":"Datastore/statement/MySQL/tables/select"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/tables/select",
"scope":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/operation/MySQL/select"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransaction/all"}, [1, "??", "??", "??", "??", "??"]],
Expand All @@ -52,8 +52,8 @@
"OtherTransaction/php__FILE__",
"<unknown>",
"?? SQL ID",
"SELECT TABLE_NAME FROM TABLES WHERE TABLE_NAME = ?",
"Datastore/statement/MySQL/TABLES/select",
"SELECT TABLE_NAME FROM information_schema.tables WHERE table_name=?",
"Datastore/statement/MySQL/tables/select",
1,
"?? total time",
"?? min time",
Expand All @@ -76,7 +76,7 @@
[
1,
"SIMPLE",
"TABLES",
"tables",
"ALL",
null,
"TABLE_NAME",
Expand Down Expand Up @@ -105,7 +105,7 @@

function test_prepare($link)
{
$query = "SELECT TABLE_NAME FROM TABLES WHERE TABLE_NAME = 'STATISTICS'";
$query = "SELECT TABLE_NAME FROM information_schema.tables WHERE table_name='STATISTICS'";

$stmt = mysqli_prepare($link, $query);
if (FALSE === $stmt) {
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/mysqli/test_explain_init_oo.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
[{"name":"Datastore/allOther"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/MySQL/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/MySQL/allOther"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/TABLES/select"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/TABLES/select",
[{"name":"Datastore/statement/MySQL/tables/select"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/statement/MySQL/tables/select",
"scope":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Datastore/operation/MySQL/select"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransaction/all"}, [1, "??", "??", "??", "??", "??"]],
Expand All @@ -52,8 +52,8 @@
"OtherTransaction/php__FILE__",
"<unknown>",
"?? SQL ID",
"SELECT TABLE_NAME FROM TABLES WHERE TABLE_NAME = ?",
"Datastore/statement/MySQL/TABLES/select",
"SELECT TABLE_NAME FROM information_schema.tables WHERE table_name=?",
"Datastore/statement/MySQL/tables/select",
1,
"?? total time",
"?? min time",
Expand All @@ -76,7 +76,7 @@
[
1,
"SIMPLE",
"TABLES",
"tables",
"ALL",
null,
"TABLE_NAME",
Expand Down Expand Up @@ -105,7 +105,7 @@

function test_prepare($link)
{
$query = "SELECT TABLE_NAME FROM TABLES WHERE TABLE_NAME = 'STATISTICS'";
$query = "SELECT TABLE_NAME FROM information_schema.tables WHERE table_name='STATISTICS'";

$stmt = mysqli_prepare($link, $query);
if (FALSE === $stmt) {
Expand Down
Loading

0 comments on commit adbdca6

Please sign in to comment.